Skip to content

Commit e0bc82c

Browse files
committed
extend possible ways of Cuts construction: AddCut(s), variadic in constructor...
1 parent 33be63b commit e0bc82c

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

infra/Cuts.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,27 @@ bool Cuts::Apply(const BranchChannel& ob) const {
7777
return true;
7878
}
7979

80+
void Cuts::AddCut(const SimpleCut& cut) {
81+
cuts_.emplace_back(cut);
82+
branch_names_.insert(cut.GetBranches().begin(), cut.GetBranches().end());
83+
}
84+
85+
void Cuts::AddCuts(const std::vector<SimpleCut>& cuts) {
86+
for(auto& cut : cuts) {
87+
AddCut(cut);
88+
}
89+
}
90+
91+
template<typename... Args>
92+
Cuts::Cuts(std::string name, Args... args) : name_(std::move(name)) {
93+
// AddCuts(std::forward<Args>(args)...);
94+
AddCuts(args...);
95+
}
96+
97+
template<typename T, typename... Args>
98+
void Cuts::AddCuts(const T& t, const Args&... args) {
99+
AddCuts(t);
100+
AddCuts(args...);
101+
}
102+
80103
}// namespace AnalysisTree

infra/Cuts.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ class Cuts {
4848
}
4949
}
5050

51+
template<typename... Args>
52+
explicit Cuts(std::string name, Args... args);
53+
54+
void AddCut(const SimpleCut& cut);
55+
56+
void AddCuts(const std::vector<SimpleCut>& cuts);
57+
58+
template<typename T, typename... Args>
59+
void AddCuts(const T& t, const Args&... args);
60+
5161
/**
5262
* @brief Evaluates all SimpleCuts
5363
* @tparam T type of data-object associated with TTree

infra/SimpleCut.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class SimpleCut {
4343
FillBranchNames();
4444
}
4545

46+
SimpleCut(const std::vector<Variable>& vars, std::function<bool(std::vector<double>&)> lambda, std::string title = "") : title_(std::move(title)),
47+
lambda_(std::move(lambda)) {
48+
for(auto& var : vars) {
49+
vars_.emplace_back(var);
50+
}
51+
FillBranchNames();
52+
}
53+
4654
/**
4755
* Constructor for range cut: min <= field <= max
4856
* @param variable_name name of the variable in format "branch.field"

0 commit comments

Comments
 (0)