1#ifndef ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP
2#define ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP
4#include "SimpleCut.hpp"
10namespace HelperFunctions {
13inline std::string ToStringWithPrecision(
const T a_value,
const int n) {
14 std::ostringstream out;
16 out << std::fixed << a_value;
21inline std::string ToStringWithSignificantFigures(
const T a_value,
const int n) {
22 if(a_value == 0)
return "0";
24 const double dMag = std::log10(std::abs(a_value));
25 const int iMag =
static_cast<int>(dMag-n+1 > 0 ? dMag-n+1 : dMag-n);
26 const T shifted_value = a_value/std::pow(10, iMag);
27 const T rounded_value =
static_cast<T
>(std::round(shifted_value));
28 const T reshifted_value = rounded_value*std::pow(10, iMag);
29 const int precision = iMag < 0 ? -iMag : 0;
30 return ToStringWithPrecision(reshifted_value, precision);
33inline std::vector<AnalysisTree::SimpleCut> CreateRangeCuts(
const std::vector<float>& ranges,
const std::string& cutNamePrefix,
const std::string& branchFieldName,
int precision=2) {
34 std::vector<AnalysisTree::SimpleCut> sliceCuts;
35 for (
int iRange = 0; iRange < ranges.size() - 1; iRange++) {
36 const std::string cutName = cutNamePrefix + ToStringWithPrecision(ranges.at(iRange), 2) +
"_" + ToStringWithPrecision(ranges.at(iRange + 1), precision);
37 sliceCuts.emplace_back(
AnalysisTree::RangeCut(branchFieldName, ranges.at(iRange), ranges.at(iRange + 1), cutName));
43inline std::vector<AnalysisTree::SimpleCut> CreateEqualCuts(
const std::vector<float>& values,
const std::string& cutNamePrefix,
const std::string& branchFieldName,
int precision=2) {
44 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);
SimpleCut EqualsCut(const std::string &variable_name, int value, const std::string &title)
Definition SimpleCut.cpp:36
SimpleCut RangeCut(const std::string &variable_name, double lo, double hi, const std::string &title)
Definition SimpleCut.cpp:32