ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
bin.cpp
Go to the documentation of this file.
1 #include "bin.hpp"
2 
3 #include <algorithm>
4 
5 #include "systematic.hpp"
6 #include "utilities.hpp"
7 
8 using namespace std;
9 
10 Bin::Bin(const string &name, const class Cut &cut,
11  bool is_blind, const SystCollection &systematics):
12  cut_(cut),
13  name_(name),
14  systematics_(systematics),
15  is_blind_(is_blind){
16  ReplaceAll(name_, " ", "");
17  }
18 
19 const string & Bin::Name() const{
20  return name_;
21 }
22 
23 Bin & Bin::Name(const string &name){
24  name_ = name;
25  return *this;
26 }
27 
28 const class Cut & Bin::Cut() const{
29  return cut_;
30 }
31 
32 class Cut & Bin::Cut(){
33  return cut_;
34 }
35 
36 bool Bin::Blind() const{
37  return is_blind_;
38 }
39 
40 bool & Bin::Blind(){
41  return is_blind_;
42 }
43 
45  return systematics_;
46 }
47 
48 Bin & Bin::Systematics(const SystCollection &systematics){
49  systematics_ = systematics;
50  return *this;
51 }
52 
53 Bin & Bin::AddSystematic(const Systematic &systematic){
54  if(!HasSystematic(systematic)){
55  systematics_.insert(systematics_.end(), systematic);
56  }
57  return *this;
58 }
59 
60 Bin & Bin::AddSystematics(const SystCollection &systematics){
61  for(const auto& systematic: systematics){
62  AddSystematic(systematic);
63  }
64  return *this;
65 }
66 
67 bool Bin::HasSystematic(const Systematic &systematic) const{
68  return find(systematics_.cbegin(), systematics_.cend(), systematic) != systematics_.cend();
69 }
70 
71 Bin & Bin::RemoveSystematic(const Systematic &systematic){
72  try{
73  systematics_.erase(find(systematics_.begin(), systematics_.end(), systematic));
74  }catch(const out_of_range &e){
75  ERROR(string(e.what())+": bin "+name_+" does not contain systematic "+systematic.Name()+".");
76  }
77  return *this;
78 }
79 
81  systematics_.clear();
82  return *this;
83 }
84 
85 Bin & Bin::SetSystematicStrength(const std::string &name, double strength){
86  bool found_it = false;
87  for(auto systematic = systematics_.cbegin(); systematic != systematics_.cend(); ++systematic){
88  if(systematic->Name() == name){
89  Systematic new_syst = *systematic;
90  new_syst.Strength() = strength;
91  found_it = true;
92  systematics_.erase(systematic);
93  systematics_.insert(systematics_.end(), new_syst);
94  }
95  }
96  if(!found_it){
97  ERROR("Bin "+name_+" does not contain systematic "+name);
98  }
99  return *this;
100 }
101 
102 bool Bin::operator<(const Bin &b) const{
103  return tie(cut_, systematics_, is_blind_) < tie(b.cut_, b.systematics_, b.is_blind_);
104 }
105 
106 bool Bin::operator==(const Bin &b) const{
107  return tie(cut_, systematics_, is_blind_) == tie(b.cut_, b.systematics_, b.is_blind_);
108 }
109 
110 ostream & operator<<(ostream &stream, const Bin &bin){
111  stream << "Bin::" << bin.Name()
112  << "(cut=" << bin.Cut()
113  << ",blind=" << bin.Blind()
114  << ")";
115  return stream;
116 }
class Cut cut_
Definition: bin.hpp:41
Definition: bin.hpp:12
SystCollection systematics_
Definition: bin.hpp:43
Bin(const std::string &name, const class Cut &cut, bool is_blind=true, const SystCollection &systematics=SystCollection())
Definition: bin.cpp:10
Definition: cut.hpp:8
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
Definition: utilities.cpp:34
STL namespace.
std::string name_
Definition: bin.hpp:42
Bin & RemoveSystematics()
Definition: bin.cpp:80
std::set< Systematic > SystCollection
Definition: bin.hpp:13
Bin & SetSystematicStrength(const std::string &name, double strength)
Definition: bin.cpp:85
const double & Strength() const
Definition: systematic.cpp:22
const class Cut & Cut() const
Definition: bin.cpp:28
#define ERROR(x)
Definition: utilities.hpp:15
bool is_blind_
Definition: bin.hpp:44
Bin & AddSystematic(const Systematic &systematic)
Definition: bin.cpp:53
bool HasSystematic(const Systematic &systematic) const
Definition: bin.cpp:67
bool operator==(const Bin &b) const
Definition: bin.cpp:106
Bin & AddSystematics(const SystCollection &systematic)
Definition: bin.cpp:60
bool operator<(const Bin &b) const
Definition: bin.cpp:102
const SystCollection & Systematics() const
Definition: bin.cpp:44
const std::string & Name() const
Definition: bin.cpp:19
ostream & operator<<(ostream &stream, const Bin &bin)
Definition: bin.cpp:110
bool Blind() const
Definition: bin.cpp:36
Bin & RemoveSystematic(const Systematic &systematic)
Definition: bin.cpp:71
const std::string & Name() const
Definition: systematic.cpp:13