Skip to content

Commit

Permalink
extend possible ways of Cuts construction: AddCut(s), variadic in con…
Browse files Browse the repository at this point in the history
…structor...
  • Loading branch information
lubynets committed Feb 10, 2025
1 parent 33be63b commit e0bc82c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
23 changes: 23 additions & 0 deletions infra/Cuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,27 @@ bool Cuts::Apply(const BranchChannel& ob) const {
return true;
}

void Cuts::AddCut(const SimpleCut& cut) {
cuts_.emplace_back(cut);
branch_names_.insert(cut.GetBranches().begin(), cut.GetBranches().end());
}

void Cuts::AddCuts(const std::vector<SimpleCut>& cuts) {
for(auto& cut : cuts) {
AddCut(cut);
}
}

template<typename... Args>
Cuts::Cuts(std::string name, Args... args) : name_(std::move(name)) {
// AddCuts(std::forward<Args>(args)...);
AddCuts(args...);
}

template<typename T, typename... Args>
void Cuts::AddCuts(const T& t, const Args&... args) {
AddCuts(t);
AddCuts(args...);
}

}// namespace AnalysisTree
10 changes: 10 additions & 0 deletions infra/Cuts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ class Cuts {
}
}

template<typename... Args>
explicit Cuts(std::string name, Args... args);

void AddCut(const SimpleCut& cut);

void AddCuts(const std::vector<SimpleCut>& cuts);

template<typename T, typename... Args>
void AddCuts(const T& t, const Args&... args);

/**
* @brief Evaluates all SimpleCuts
* @tparam T type of data-object associated with TTree
Expand Down
8 changes: 8 additions & 0 deletions infra/SimpleCut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class SimpleCut {
FillBranchNames();
}

SimpleCut(const std::vector<Variable>& vars, std::function<bool(std::vector<double>&)> lambda, std::string title = "") : title_(std::move(title)),
lambda_(std::move(lambda)) {
for(auto& var : vars) {
vars_.emplace_back(var);
}
FillBranchNames();
}

/**
* Constructor for range cut: min <= field <= max
* @param variable_name name of the variable in format "branch.field"
Expand Down

0 comments on commit e0bc82c

Please sign in to comment.