@@ -30,21 +30,49 @@ inline std::string ToStringWithSignificantFigures(const T a_value, const int n)
3030 return ToStringWithPrecision (reshifted_value, precision);
3131}
3232
33- inline std::vector<AnalysisTree::SimpleCut> CreateRangeCuts (const std::vector<float >& ranges, const std::string& cutNamePrefix, const std::string& branchFieldName, int precision = 2 ) {
33+ inline std::vector<AnalysisTree::SimpleCut> CreateRangeCuts (const std::vector<float >& ranges, const std::string& cutNamePrefix, const std::string& branchFieldName, bool isAppendWithOpenCut = false , int precision = -1 ) {
34+ auto checkHasFractionalPart = [](float value) {
35+ float fracPart = std::round (value) - value;
36+ return std::abs (fracPart) > 1e-4 ;
37+ };
38+
39+ auto countDigisAfterComma = [&](float value) {
40+ int nDigis{0 };
41+ while (checkHasFractionalPart (value)) {
42+ value *= 10 ;
43+ ++nDigis;
44+ }
45+
46+ return nDigis;
47+ };
48+
49+ auto evaluateMaxDigisAfterComma = [&](const std::vector<float >& vec) {
50+ int result = 0 ;
51+ for (const auto & v : vec) {
52+ result = std::max (result, countDigisAfterComma (v));
53+ }
54+
55+ return result;
56+ };
57+
58+ if (precision < 0 ) precision = evaluateMaxDigisAfterComma (ranges);
59+
3460 std::vector<AnalysisTree::SimpleCut> sliceCuts;
3561 for (int iRange = 0 ; iRange < ranges.size () - 1 ; iRange++) {
3662 const std::string cutName = cutNamePrefix + ToStringWithPrecision (ranges.at (iRange), precision) + " _" + ToStringWithPrecision (ranges.at (iRange + 1 ), precision);
3763 sliceCuts.emplace_back (AnalysisTree::RangeCut (branchFieldName, ranges.at (iRange), ranges.at (iRange + 1 ), cutName));
3864 }
3965
66+ if (isAppendWithOpenCut) sliceCuts.emplace_back (AnalysisTree::OpenCut (branchFieldName.substr (0 , branchFieldName.find (' .' ))));
67+
4068 return sliceCuts;
4169}
4270
43- inline std::vector<AnalysisTree::SimpleCut> CreateEqualCuts (const std::vector<float >& values, const std::string& cutNamePrefix, const std::string& branchFieldName, int precision = 2 ) {
71+ inline std::vector<AnalysisTree::SimpleCut> CreateEqualCuts (const std::vector<int >& values, const std::string& cutNamePrefix, const std::string& branchFieldName) {
4472 std::vector<AnalysisTree::SimpleCut> sliceCuts;
45- for (int iValue = 0 ; iValue < values. size (); iValue++ ) {
46- const std::string cutName = cutNamePrefix + ToStringWithPrecision (values. at (iValue), precision );
47- sliceCuts.emplace_back (AnalysisTree::EqualsCut (branchFieldName, values. at (iValue) , cutName));
73+ for (const auto & value : values) {
74+ const std::string cutName = cutNamePrefix + std::to_string (value );
75+ sliceCuts.emplace_back (AnalysisTree::EqualsCut (branchFieldName, value , cutName));
4876 }
4977
5078 return sliceCuts;
@@ -58,5 +86,20 @@ inline bool StringToBool(const std::string& str) {
5886 throw std::runtime_error (" HelperFunctions::StringToBool(): argument must be either true or false" );
5987}
6088
89+ template <typename T>
90+ inline std::vector<T> MergeVectors (const std::vector<T>& vec1, const std::vector<T>& vec2) {
91+ std::vector<T> result;
92+ result.reserve (vec1.size () + vec2.size ());
93+ result.insert (result.end (), vec1.begin (), vec1.end ());
94+ result.insert (result.end (), vec2.begin (), vec2.end ());
95+
96+ return result;
97+ }
98+
99+ template <typename T, typename ... Args>
100+ inline std::vector<T> MergeVectors (const std::vector<T>& vec1, const std::vector<T>& vec2, const Args&... args) {
101+ return MergeVectors (vec1, MergeVectors (vec2, args...));
102+ }
103+
61104}// namespace HelperFunctions
62105#endif // ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP
0 commit comments