@@ -16,15 +16,38 @@ inline std::string ToStringWithPrecision(const T a_value, const int n) {
16
16
return out.str ();
17
17
}
18
18
19
- inline std::vector<AnalysisTree::SimpleCut> CreateSliceCuts (const std::vector<float >& ranges, const std::string& cutNamePrefix, const std::string& branchFieldName) {
19
+ template <typename T>
20
+ inline std::string ToStringWithSignificantFigures (const T a_value, const int n) {
21
+ if (a_value == 0 ) return " 0" ;
22
+
23
+ const double dMag = std::log10 (std::abs (a_value)); // scale of the a_value (e.g 1.* for 1.2345, 2.* for 12.345 etc)
24
+ const int iMag = static_cast <int >(dMag-n+1 > 0 ? dMag-n+1 : dMag-n);
25
+ const T shifted_value = a_value/std::pow (10 , iMag); // shift decimal point to have all required digits to l.h.s. from it
26
+ const T rounded_value = static_cast <T>(std::round (shifted_value)); // get rid of r.h.s. from decimal point
27
+ const T reshifted_value = rounded_value*std::pow (10 , iMag); // return decimal point to its original place
28
+ const int precision = iMag < 0 ? -iMag : 0 ; // determine how many digits after decimal point one needs
29
+ return ToStringWithPrecision (reshifted_value, precision);
30
+ }
31
+
32
+ inline std::vector<AnalysisTree::SimpleCut> CreateRangeCuts (const std::vector<float >& ranges, const std::string& cutNamePrefix, const std::string& branchFieldName, int precision=2 ) {
20
33
std::vector<AnalysisTree::SimpleCut> sliceCuts;
21
34
for (int iRange = 0 ; iRange < ranges.size () - 1 ; iRange++) {
22
- const std::string cutName = cutNamePrefix + ToStringWithPrecision (ranges.at (iRange), 2 ) + " _" + ToStringWithPrecision (ranges.at (iRange + 1 ), 2 );
35
+ const std::string cutName = cutNamePrefix + ToStringWithPrecision (ranges.at (iRange), 2 ) + " _" + ToStringWithPrecision (ranges.at (iRange + 1 ), precision );
23
36
sliceCuts.emplace_back (AnalysisTree::RangeCut (branchFieldName, ranges.at (iRange), ranges.at (iRange + 1 ), cutName));
24
37
}
25
38
26
39
return sliceCuts;
27
40
}
28
41
42
+ inline std::vector<AnalysisTree::SimpleCut> CreateEqualCuts (const std::vector<float >& values, const std::string& cutNamePrefix, const std::string& branchFieldName, int precision=2 ) {
43
+ std::vector<AnalysisTree::SimpleCut> sliceCuts;
44
+ for (int iValue = 0 ; iValue < values.size (); iValue++) {
45
+ const std::string cutName = cutNamePrefix + ToStringWithPrecision (values.at (iValue), precision);
46
+ sliceCuts.emplace_back (AnalysisTree::EqualsCut (branchFieldName, values.at (iValue), cutName));
47
+ }
48
+
49
+ return sliceCuts;
50
+ }
51
+
29
52
}// namespace HelperFunctions
30
53
#endif // ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP
0 commit comments