Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions infra/HelperFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,49 @@ inline std::string ToStringWithSignificantFigures(const T a_value, const int n)
return ToStringWithPrecision(reshifted_value, precision);
}

inline std::vector<AnalysisTree::SimpleCut> CreateRangeCuts(const std::vector<float>& ranges, const std::string& cutNamePrefix, const std::string& branchFieldName, int precision = 2) {
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) {
auto checkHasFractionalPart = [](float value) {
float fracPart = std::round(value) - value;
return std::abs(fracPart) > 1e-4;
};

auto countDigisAfterComma = [&](float value) {
int nDigis{0};
while (checkHasFractionalPart(value)) {
value *= 10;
++nDigis;
}

return nDigis;
};

auto evaluateMaxDigisAfterComma = [&](const std::vector<float>& vec) {
int result = 0;
for (const auto& v : vec) {
result = std::max(result, countDigisAfterComma(v));
}

return result;
};

if (precision < 0) precision = evaluateMaxDigisAfterComma(ranges);

std::vector<AnalysisTree::SimpleCut> sliceCuts;
for (int iRange = 0; iRange < ranges.size() - 1; iRange++) {
const std::string cutName = cutNamePrefix + ToStringWithPrecision(ranges.at(iRange), precision) + "_" + ToStringWithPrecision(ranges.at(iRange + 1), precision);
sliceCuts.emplace_back(AnalysisTree::RangeCut(branchFieldName, ranges.at(iRange), ranges.at(iRange + 1), cutName));
}

if (isAppendWithOpenCut) sliceCuts.emplace_back(AnalysisTree::OpenCut(branchFieldName.substr(0, branchFieldName.find('.'))));

return sliceCuts;
}

inline std::vector<AnalysisTree::SimpleCut> CreateEqualCuts(const std::vector<float>& values, const std::string& cutNamePrefix, const std::string& branchFieldName, int precision = 2) {
inline std::vector<AnalysisTree::SimpleCut> CreateEqualCuts(const std::vector<int>& values, const std::string& cutNamePrefix, const std::string& branchFieldName) {
std::vector<AnalysisTree::SimpleCut> sliceCuts;
for (int iValue = 0; iValue < values.size(); iValue++) {
const std::string cutName = cutNamePrefix + ToStringWithPrecision(values.at(iValue), precision);
sliceCuts.emplace_back(AnalysisTree::EqualsCut(branchFieldName, values.at(iValue), cutName));
for (const auto& value : values) {
const std::string cutName = cutNamePrefix + std::to_string(value);
sliceCuts.emplace_back(AnalysisTree::EqualsCut(branchFieldName, value, cutName));
}

return sliceCuts;
Expand All @@ -58,5 +86,20 @@ inline bool StringToBool(const std::string& str) {
throw std::runtime_error("HelperFunctions::StringToBool(): argument must be either true or false");
}

template<typename T>
inline std::vector<T> MergeVectors(const std::vector<T>& vec1, const std::vector<T>& vec2) {
std::vector<T> result;
result.reserve(vec1.size() + vec2.size());
result.insert(result.end(), vec1.begin(), vec1.end());
result.insert(result.end(), vec2.begin(), vec2.end());

return result;
}

template<typename T, typename... Args>
inline std::vector<T> MergeVectors(const std::vector<T>& vec1, const std::vector<T>& vec2, const Args&... args) {
return MergeVectors(vec1, MergeVectors(vec2, args...));
}

}// namespace HelperFunctions
#endif// ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP
4 changes: 4 additions & 0 deletions infra/SimpleCut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ SimpleCut EqualsCut(const Variable& var, int value, const std::string& title) {
return SimpleCut(var, value, title);
}

SimpleCut OpenCut(const std::string& branchName, const std::string& title) {
return SimpleCut({branchName + ".ones"}, [](const std::vector<double>& par) { return true; });
}

SimpleCut::SimpleCut(const Variable& var, int value, std::string title) : title_(std::move(title)) {
vars_.emplace_back(var);
lambda_ = [value](std::vector<double>& vars) { return vars[0] <= value + SmallNumber && vars[0] >= value - SmallNumber; };
Expand Down
9 changes: 9 additions & 0 deletions infra/SimpleCut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ class SimpleCut {
*/
friend SimpleCut EqualsCut(const Variable& var, int value, const std::string& title);

/**
* Constructor for a cut which is always passed
* (needed for keeping generality of the user's code, when a set of cuts
* is iterated and an iteration with no-cut is needed)
* @param branchName name of the branch, which is present in other cuts
*/
friend SimpleCut OpenCut(const std::string& branchName, const std::string& title);

/**
* @brief Evaluates cut
* @tparam T type of data-object associated with TTree
Expand Down Expand Up @@ -131,6 +139,7 @@ SimpleCut RangeCut(const std::string& variable_name, double lo, double hi, const
SimpleCut EqualsCut(const std::string& variable_name, int value, const std::string& title = "");
SimpleCut RangeCut(const Variable& var, double lo, double hi, const std::string& title = "");
SimpleCut EqualsCut(const Variable& var, int value, const std::string& title = "");
SimpleCut OpenCut(const std::string& branchName, const std::string& title = "alwaysTrue");

}// namespace AnalysisTree
#endif//ANALYSISTREE_SIMPLECUT_H
6 changes: 6 additions & 0 deletions infra/TaskManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ void TaskManager::Run(long long nEvents) {
nEvents = nEvents < 0 || nEvents > chain_->GetEntries() ? chain_->GetEntries() : nEvents;
}

if (verbosity_frequency_ > 0) {
const int verbosityPeriod = nEvents / verbosity_frequency_;
const int vPlog = static_cast<int>(std::round(std::log10(verbosityPeriod)));
verbosity_period_ = static_cast<int>(std::pow(10, vPlog));
}

for (long long iEvent = 0; iEvent < nEvents; ++iEvent) {
if (verbosity_period_ > 0 && iEvent % verbosity_period_ == 0) {
std::cout << "Event no " << iEvent << "\n";
Expand Down
2 changes: 2 additions & 0 deletions infra/TaskManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class TaskManager {
void SetWriteMode(eBranchWriteMode mode) { write_mode_ = mode; }
void SetBranchesExclude(std::vector<std::string> brex) { branches_exclude_ = std::move(brex); }
void SetVerbosityPeriod(int value) { verbosity_period_ = value; }
void SetVerbosityFrequency(int value) { verbosity_frequency_ = value; }
void SetIsWriteHashInfo(bool is = true) { is_write_hash_info_ = is; }
void SetIsUpdateEntryInExec(bool is = true) { is_update_entry_in_exec_ = is; }

Expand Down Expand Up @@ -187,6 +188,7 @@ class TaskManager {
std::vector<std::string> branches_exclude_{};

int verbosity_period_{-1};
int verbosity_frequency_{-1};

// configuration parameters
eBranchWriteMode write_mode_{eBranchWriteMode::kCreateNewTree};
Expand Down