Skip to content

Commit 75f4401

Browse files
authored
Extend possible ways of Cuts construction: AddCut(s) (#139)
* extend possible ways of Cuts construction: AddCut(s), variadic in constructor... * bugfix of variadic in Cuts constructor * comment not working (yet) constructor * apply clang-format
1 parent 88db1ee commit 75f4401

5 files changed

Lines changed: 48 additions & 5 deletions

File tree

infra/Cuts.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,15 @@ 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+
8091
}// namespace AnalysisTree

infra/Cuts.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ class Cuts {
4848
}
4949
}
5050

51+
void AddCut(const SimpleCut& cut);
52+
53+
void AddCuts(const std::vector<SimpleCut>& cuts);
54+
55+
// // Base case for variadic recursion (handles when there's just one argument left)
56+
// template<typename T>
57+
// void AddCuts(const T& t) {
58+
// AddCuts(t); // Call the appropriate overload for a single argument (like std::vector<SimpleCut>)
59+
// }
60+
//
61+
// // Recursive case for variadic template (multiple arguments)
62+
// template<typename T, typename... Args>
63+
// void AddCuts(const T& t, const Args&... args) {
64+
// AddCuts(t);
65+
// AddCuts(args...);
66+
// }
67+
//
68+
// template<typename... Args> // TODO this constructor hangs. Needs debugging
69+
// Cuts(std::string name, Args... args) : name_(std::move(name)) {
70+
// AddCuts(args...);
71+
// }
72+
5173
/**
5274
* @brief Evaluates all SimpleCuts
5375
* @tparam T type of data-object associated with TTree

infra/HelperFunctions.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ inline std::string ToStringWithPrecision(const T a_value, const int n) {
1818

1919
inline std::vector<AnalysisTree::SimpleCut> CreateSliceCuts(const std::vector<float>& ranges, const std::string& cutNamePrefix, const std::string& branchFieldName) {
2020
std::vector<AnalysisTree::SimpleCut> sliceCuts;
21-
for(int iRange=0; iRange<ranges.size()-1; iRange++) {
22-
const std::string cutName = cutNamePrefix + ToStringWithPrecision(ranges.at(iRange), 2) + "_" + ToStringWithPrecision(ranges.at(iRange+1), 2);
23-
sliceCuts.emplace_back(AnalysisTree::RangeCut(branchFieldName, ranges.at(iRange), ranges.at(iRange+1), cutName));
21+
for (int iRange = 0; iRange < ranges.size() - 1; iRange++) {
22+
const std::string cutName = cutNamePrefix + ToStringWithPrecision(ranges.at(iRange), 2) + "_" + ToStringWithPrecision(ranges.at(iRange + 1), 2);
23+
sliceCuts.emplace_back(AnalysisTree::RangeCut(branchFieldName, ranges.at(iRange), ranges.at(iRange + 1), cutName));
2424
}
2525

2626
return sliceCuts;
2727
}
2828

29-
}
30-
#endif // ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP
29+
}// namespace HelperFunctions
30+
#endif// ANALYSISTREE_INFRA_HELPER_FUNCTIONS_HPP

infra/SimpleCut.hpp

Lines changed: 8 additions & 0 deletions
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"

infra/TaskManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ TaskManager* TaskManager::GetInstance() {
2222

2323
void TaskManager::Init(const std::vector<std::string>& filelists, const std::vector<std::string>& in_trees) {
2424
assert(!is_init_);
25+
std::cout << "TaskManager::Init()\n";
2526
is_init_ = true;
2627
read_in_tree_ = true;
2728
chain_ = new Chain(filelists, in_trees);
@@ -51,6 +52,7 @@ void TaskManager::InitTasks() {
5152

5253
void TaskManager::Init() {
5354
assert(!is_init_);
55+
std::cout << "TaskManager::Init()\n";
5456
is_init_ = true;
5557
fill_out_tree_ = true;
5658

0 commit comments

Comments
 (0)