forked from HeavyIonAnalysis/AnalysisTree
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add HelperFunctions.hpp and place some oftenly used functions
- Loading branch information
Showing
3 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP | ||
#define ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP | ||
|
||
#include "SimpleCut.hpp" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace HelperFunctions { | ||
|
||
template<typename T> | ||
inline std::string ToStringWithPrecision(const T a_value, const int n) { | ||
std::ostringstream out; | ||
out.precision(n); | ||
out << std::fixed << a_value; | ||
return out.str(); | ||
} | ||
|
||
inline std::vector<AnalysisTree::SimpleCut> CreateSliceCuts(const std::vector<float>& ranges, const std::string& cutNamePrefix, const std::string& branchFieldName) { | ||
std::vector<AnalysisTree::SimpleCut> sliceCuts; | ||
for(int iRange=0; iRange<ranges.size()-1; iRange++) { | ||
const std::string cutName = cutNamePrefix + ToStringWithPrecision(ranges.at(iRange), 2) + "_" + ToStringWithPrecision(ranges.at(iRange+1), 2); | ||
sliceCuts.emplace_back(AnalysisTree::RangeCut(branchFieldName, ranges.at(iRange), ranges.at(iRange+1), cutName)); | ||
} | ||
|
||
return sliceCuts; | ||
} | ||
|
||
} | ||
#endif // ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP |