ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
process.cpp
Go to the documentation of this file.
1 #include "process.hpp"
2 
3 #include <string>
4 #include <set>
5 #include <initializer_list>
6 #include <algorithm>
7 
8 #include "TChain.h"
9 
10 #include "utilities.hpp"
11 
12 using namespace std;
13 
14 Process::Process(const string &name,
15  const set<string> &file_names,
16  const class Cut &cut,
17  bool is_data,
18  bool is_signal,
19  bool count_zeros,
20  const SystCollection &systematics):
21  file_names_(file_names),
22  chain_(make_shared<TChain>("tree", "tree")),
23  cut_(cut),
24  name_(name),
25  is_data_(is_data),
26  is_signal_(is_signal),
27  count_zeros_(count_zeros),
28  systematics_(systematics){
29  CleanName();
30  AddFiles();
31  }
32 
33 Process::Process(const string &name,
34  initializer_list<string> file_names,
35  const class Cut &cut,
36  bool is_data,
37  bool is_signal,
38  bool count_zeros,
39  const SystCollection &systematics):
40  file_names_(file_names),
41  chain_(make_shared<TChain>("tree", "tree")),
42  cut_(cut),
43  name_(name),
44  is_data_(is_data),
45  is_signal_(is_signal),
46  count_zeros_(count_zeros),
47  systematics_(systematics){
48  CleanName();
49  AddFiles();
50  }
51 
52 const string & Process::Name() const{
53  return name_;
54 }
55 
56 Process & Process::Name(const string &name){
57  name_ = name;
58  CleanName();
59  return *this;
60 }
61 
62 const class Cut & Process::Cut() const{
63  return cut_;
64 }
65 
66 class Cut & Process::Cut(){
67  return cut_;
68 }
69 
70 const set<string> & Process::FileNames() const{
71  return file_names_;
72 }
73 
74 long Process::GetEntries() const{
75  return chain_->GetEntries();
76 }
77 
78 GammaParams Process::GetYield(const class Cut &cut) const{
79  double count, uncertainty;
80  ::GetCountAndUncertainty(*chain_, cut*cut_, count, uncertainty);
81  GammaParams gps;
82  gps.SetYieldAndUncertainty(count, uncertainty);
83  return gps;
84 }
85 
86 const bool & Process::IsData() const{
87  return is_data_;
88 }
89 
90 bool & Process::IsData(){
91  return is_data_;
92 }
93 
94 const bool & Process::IsSignal() const{
95  return is_signal_;
96 }
97 
99  return is_signal_;
100 }
101 
102 const bool & Process::CountZeros() const{
103  return count_zeros_;
104 }
105 
107  return count_zeros_;
108 }
109 
111  return systematics_;
112 }
113 
115  systematics_ = systematics;
116  return *this;
117 }
118 
120  if(!HasSystematic(systematic)){
121  systematics_.insert(systematics_.end(), systematic);
122  }
123  return *this;
124 }
125 
127  for(const auto& systematic: systematics){
128  AddSystematic(systematic);
129  }
130  return *this;
131 }
132 
133 bool Process::HasSystematic(const Systematic &systematic) const{
134  return find(systematics_.cbegin(), systematics_.cend(), systematic) != systematics_.cend();
135 }
136 
138  try{
139  systematics_.erase(find(systematics_.begin(), systematics_.end(), systematic));
140  }catch(const out_of_range &e){
141  ERROR(string(e.what())+": bin "+name_+" does not contain systematic "+systematic.Name()+".");
142  }
143  return *this;
144 }
145 
147  systematics_.clear();
148  return *this;
149 }
150 
151 Process & Process::SetSystematicStrength(const std::string &name, double strength){
152  bool found_it = false;
153  for(auto systematic = systematics_.cbegin(); systematic != systematics_.cend(); ++systematic){
154  if(systematic->Name() == name){
155  Systematic new_syst = *systematic;
156  new_syst.Strength() = strength;
157  found_it = true;
158  systematics_.erase(systematic);
159  systematics_.insert(systematics_.end(), new_syst);
160  }
161  }
162  if(!found_it){
163  ERROR("Process "+name_+" does not contain systematic "+name);
164  }
165  return *this;
166 }
167 
168 bool Process::operator<(const Process &p) const{
170  < tie(p.cut_, p.file_names_, p.count_zeros_, p.systematics_);
171 }
172 
173 bool Process::operator==(const Process &p) const{
175  == tie(p.cut_, p.file_names_, p.count_zeros_, p.systematics_);
176 }
177 
179  ReplaceAll(name_, " ", "");
180 }
181 
183  for(const auto &file_name: file_names_){
184  chain_->Add(file_name.c_str());
185  }
186 }
187 
188 ostream & operator<<(ostream &stream, const Process &proc){
189  stream << "Process::" << proc.Name()
190  << "(cut=" << proc.Cut()
191  << ",count_zeros=" << proc.CountZeros()
192  << ",is_data=" << proc.IsData()
193  << ",is_signal=" << proc.IsSignal()
194  << ")";
195  return stream;
196 }
std::shared_ptr< TChain > chain_
Definition: process.hpp:70
bool HasSystematic(const Systematic &systematic) const
Definition: process.cpp:133
const std::string & Name() const
Definition: process.cpp:52
bool count_zeros_
Definition: process.hpp:75
const SystCollection & Systematics() const
Definition: process.cpp:110
ostream & operator<<(ostream &stream, const Process &proc)
Definition: process.cpp:188
void CleanName()
Definition: process.cpp:178
std::set< std::string > file_names_
Definition: process.hpp:69
void SetYieldAndUncertainty(double yield, double uncertainty)
Definition: cut.hpp:8
void ReplaceAll(std::string &str, const std::string &orig, const std::string &rep)
Definition: utilities.cpp:34
const std::set< std::string > & FileNames() const
Definition: process.cpp:70
STL namespace.
long GetEntries() const
Definition: process.cpp:74
const bool & IsData() const
Definition: process.cpp:86
Process & AddSystematic(const Systematic &systematic)
Definition: process.cpp:119
const bool & CountZeros() const
Definition: process.cpp:102
GammaParams GetYield(const class Cut &cut=::Cut("1")) const
Definition: process.cpp:78
const double & Strength() const
Definition: systematic.cpp:22
bool operator<(const Process &p) const
Definition: process.cpp:168
Process & RemoveSystematics()
Definition: process.cpp:146
#define ERROR(x)
Definition: utilities.hpp:15
Process & SetSystematicStrength(const std::string &name, double strength)
Definition: process.cpp:151
class Cut cut_
Definition: process.hpp:71
bool is_data_
Definition: process.hpp:73
bool operator==(const Process &p) const
Definition: process.cpp:173
bool is_signal_
Definition: process.hpp:74
const class Cut & Cut() const
Definition: process.cpp:62
const bool & IsSignal() const
Definition: process.cpp:94
std::string name_
Definition: process.hpp:72
Process()=default
void AddFiles()
Definition: process.cpp:182
void GetCountAndUncertainty(TTree &tree, const Cut &cut, double &count, double &uncertainty)
Definition: utilities.cpp:76
Process & RemoveSystematic(const Systematic &systematic)
Definition: process.cpp:137
std::set< Systematic > SystCollection
Definition: process.hpp:18
SystCollection systematics_
Definition: process.hpp:76
Process & AddSystematics(const SystCollection &systematic)
Definition: process.cpp:126
const std::string & Name() const
Definition: systematic.cpp:13