HighLAND
ConfigTreeTools.cxx
1 #include "ConfigTreeTools.hxx"
2 
3 //********************************************************************
4 ConfigTreeTools::ConfigTreeTools(const std::string& file){
5 //********************************************************************
6 
7  Initialize(file);
8 }
9 
10 //********************************************************************
11 ConfigTreeTools::ConfigTreeTools(SystematicManager& syst, ConfigurationManager& conf){
12 //********************************************************************
13 
14  Initialize(syst,conf);
15 }
16 
17 //********************************************************************
18 void ConfigTreeTools::Initialize(SystematicManager& syst, ConfigurationManager& conf){
19 //********************************************************************
20 
21  _fileName="";
22  _fromFile=false;
23  _syst = &syst;
24  _conf = &conf;
25 }
26 
27 //********************************************************************
28 void ConfigTreeTools::Initialize(const std::string& file){
29 //********************************************************************
30 
31  _fromFile=true;
32  _fileName = file;
33 
34  _syst = new SystematicManager();
35  _conf = new ConfigurationManager();
36 
37  _syst->ReadSystematics(file);
38  _conf->ReadConfigurations(file);
39 }
40 
41 //********************************************************************
42 Int_t ConfigTreeTools::GetWeightIndex(const std::string& conf, const std::string& name) const{
43 //********************************************************************
44 
45  if (!_conf->GetConfiguration(conf)) return -1;
46  if (_conf->GetConfiguration(conf)->GetEnabledSystematics().size()==0) return -1;
47 
48  _syst->DisableAllSystematics();
50 
51  Int_t nSyst;
52  EventWeightBase** systs = _syst->GetWeightSystematics(nSyst);
53  Int_t j=0;
54  for (int it = 0; it < nSyst; it++) {
55  if (systs[it]->IsEnabled()){
56  if (systs[it]->Name() == name) return j;
57  j++;
58  }
59  }
60  return -1;
61 }
62 
63 //********************************************************************
64 Int_t ConfigTreeTools::GetWeightIndex(Int_t conf, Int_t weight) const{
65 //********************************************************************
66 
67  if (!_conf->GetConfiguration(conf)) return -1;
68  if (_conf->GetConfiguration(conf)->GetEnabledSystematics().size()==0) return -1;
69 
70  _syst->DisableAllSystematics();
72 
73  Int_t nSyst;
74  EventWeightBase** systs = _syst->GetWeightSystematics(nSyst);
75  Int_t j=0;
76  for (int it = 0; it < nSyst; it++) {
77  if (systs[it]->IsEnabled()){
78  if (systs[it]->GetIndex() == weight) return j;
79  j++;
80  }
81  }
82  return -1;
83 }
84 
85 
86 //********************************************************************
87 Int_t ConfigTreeTools::GetVarValueI(const std::string& name) const{
88 //********************************************************************
89 
90  if (_fileName==""){
91  std::cout << "no file and tree associated yet !!!" << std::endl;
92  return -999;
93  }
94 
95 
96  TChain* chain = new TChain("config");
97  chain->AddFile(_fileName.c_str());
98  Int_t var=0;
99  if (chain->FindLeaf(name.c_str())){
100  chain->SetBranchAddress(name.c_str(), &var);
101  Long64_t centry = chain->LoadTree(0);
102  Int_t nb = chain->GetEntry(0);
103  (void) centry;
104  (void) nb;
105  }
106  return var;
107 
108 }
109 
110 //********************************************************************
111 Float_t ConfigTreeTools::GetVarValueF(const std::string& name) const{
112 //********************************************************************
113 
114  if (_fileName==""){
115  std::cout << "no file and tree associated yet !!!" << std::endl;
116  return -999;
117  }
118 
119  TChain* chain = new TChain("config");
120  chain->AddFile(_fileName.c_str());
121  Float_t var=0;
122  if (chain->FindLeaf(name.c_str())){
123  chain->SetBranchAddress(name.c_str(), &var);
124  Long64_t centry = chain->LoadTree(0);
125  Int_t nb = chain->GetEntry(0);
126  (void) centry;
127  (void) nb;
128  }
129  return var;
130 
131 
132 }
133 
134 //********************************************************************
135 Double_t ConfigTreeTools::GetVarValueD(const std::string& name) const{
136 //********************************************************************
137 
138  if (_fileName==""){
139  std::cout << "no file and tree associated yet !!!" << std::endl;
140  return -999;
141  }
142 
143 
144  TChain* chain = new TChain("config");
145  chain->AddFile(_fileName.c_str());
146  Double_t var=0;
147  if (chain->FindLeaf(name.c_str())){
148  chain->SetBranchAddress(name.c_str(), &var);
149  Long64_t centry = chain->LoadTree(0);
150  Int_t nb = chain->GetEntry(0);
151  (void) centry;
152  (void) nb;
153  }
154  return var;
155 }
156 
157 //********************************************************************
158 std::string ConfigTreeTools::GetVarValueC(const std::string& name) const{
159 //********************************************************************
160 
161  if (_fileName==""){
162  std::cout << "no file and tree associated yet !!!" << std::endl;
163  return "";
164  }
165 
166  TChain* chain = new TChain("config");
167  chain->AddFile(_fileName.c_str());
168  char var[200]="";
169  if (chain->FindLeaf(name.c_str())){
170  chain->SetBranchAddress(name.c_str(), var);
171  Long64_t centry = chain->LoadTree(0);
172  Int_t nb = chain->GetEntry(0);
173  (void) centry;
174  (void) nb;
175  }
176 
177  return std::string(var);
178 }
179 
Double_t GetVarValueD(const std::string &name) const
Get the value of a Double variable stored in the tree.
Float_t GetVarValueF(const std::string &name) const
Get the value of a Float variable stored in the tree.
Int_t GetVarValueI(const std::string &name) const
Get the value of a Int variable stored in the tree.
The maximum number of systematics that is supported.
void DisableAllSystematics()
Disable all Systematics.
std::string GetVarValueC(const std::string &name) const
Get the value of a Char variable stored in the tree.
EventWeightBase ** GetWeightSystematics(int &nSys)
Get the vector of weightsSystematics.
Int_t GetWeightIndex(const std::string &conf, const std::string &name) const
void EnableSystematics(const std::vector< Int_t > &systs)
Enable the systematics registered with the given indices.
const std::vector< Int_t > & GetEnabledSystematics()
Get the systematics enabled for this configuration.
void ReadConfigurations(const std::string &file)
Read configurations from a file.
void ReadSystematics(const std::string &file)
Read the systematics from a file.
ConfigurationBase * GetConfiguration(Int_t index) const
return the configuration with a given index