3
3
Authors: Viktor Klochkov, Ilya Selyuzhenkov */
4
4
#include " SimpleCut.hpp"
5
5
6
+ #include " HelperFunctions.hpp"
7
+
6
8
#include < iostream>
7
9
8
10
namespace AnalysisTree {
@@ -22,7 +24,9 @@ bool operator==(const SimpleCut& that, const SimpleCut& other) {
22
24
if (&that == &other) {
23
25
return true ;
24
26
}
25
- return that.vars_ == other.vars_ && that.title_ == other.title_ ;
27
+ // if both SimpleCuts were defined via lambda, they're assumed not equal (unless they're in the same memory place)
28
+ if (that.hash_ == 1 && other.hash_ == 1 ) return false ;
29
+ return that.vars_ == other.vars_ && that.title_ == other.title_ && that.hash_ == other.hash_ ;
26
30
}
27
31
28
32
SimpleCut RangeCut (const std::string& variable_name, double lo, double hi, const std::string& title) {
@@ -45,12 +49,18 @@ SimpleCut::SimpleCut(const Variable& var, int value, std::string title) : title_
45
49
vars_.emplace_back (var);
46
50
lambda_ = [value](std::vector<double >& vars) { return vars[0 ] <= value + SmallNumber && vars[0 ] >= value - SmallNumber; };
47
51
FillBranchNames ();
52
+ const std::string stringForHash = var.GetName () + HelperFunctions::ToStringWithPrecision (value, 6 ) + title_;
53
+ std::hash<std::string> hasher;
54
+ hash_ = hasher (stringForHash);
48
55
}
49
56
50
57
SimpleCut::SimpleCut (const Variable& var, double min, double max, std::string title) : title_(std::move(title)) {
51
58
vars_.emplace_back (var);
52
59
lambda_ = [max, min](std::vector<double >& vars) { return vars[0 ] <= max && vars[0 ] >= min; };
53
60
FillBranchNames ();
61
+ const std::string stringForHash = var.GetName () + HelperFunctions::ToStringWithPrecision (min, 6 ) + HelperFunctions::ToStringWithPrecision (max, 6 ) + title_;
62
+ std::hash<std::string> hasher;
63
+ hash_ = hasher (stringForHash);
54
64
}
55
65
56
66
bool SimpleCut::Apply (std::vector<const BranchChannel*>& bch, std::vector<size_t >& id) const {
0 commit comments