6 |
|
#include <TFile.h> |
7 |
|
#include <TTree.h> |
8 |
|
#include <TH1.h> |
9 |
+ |
#include <TH2.h> |
10 |
|
#include <TCut.h> |
11 |
|
#include <THStack.h> |
12 |
|
#include <TColor.h> |
39 |
|
public: |
40 |
|
string filename; |
41 |
|
string samplename; |
42 |
< |
int Nentries; |
42 |
> |
long Nentries; |
43 |
|
float xs;//cross section |
44 |
|
float weight; |
45 |
|
bool is_data; |
51 |
|
TFile *tfile; |
52 |
|
TTree *events; |
53 |
|
|
54 |
< |
sample(string m_filename,string m_samplename,int m_Nentries, float m_xs,bool is_data, bool m_is_signal, int m_groupindex, Color_t color); |
54 |
> |
sample(string m_filename,string m_samplename,long m_Nentries, float m_xs,bool is_data, bool m_is_signal, int m_groupindex, Color_t color); |
55 |
|
void closeFile(); |
56 |
|
}; |
57 |
|
|
61 |
|
return "MC"; |
62 |
|
} |
63 |
|
|
64 |
< |
sample::sample(string m_filename, string m_samplename, int m_Nentries, float m_xs,bool m_is_data, bool m_is_signal, int m_groupindex, Color_t mycolor) |
64 |
> |
sample::sample(string m_filename, string m_samplename, long m_Nentries, float m_xs,bool m_is_data, bool m_is_signal, int m_groupindex, Color_t mycolor) |
65 |
|
{ |
66 |
|
this->filename=m_filename; |
67 |
|
this->samplename=m_samplename; |
87 |
|
this->tfile = new TFile(m_filename.c_str()); |
88 |
|
gErrorIgnoreLevel=currlevel; |
89 |
|
this->events=(TTree*)(this->tfile)->Get(treename.c_str()); |
90 |
< |
if(Verbosity>0) cout << "The " << write_mc_or_data(is_data) << " file " << this->filename << " has been added successfully to the list of samples. " << endl; |
90 |
> |
if(Verbosity>0) dout << "The " << write_mc_or_data(is_data) << " file " << this->filename << " has been added successfully to the list of samples. " << endl; |
91 |
|
} |
92 |
|
else { |
93 |
|
this->is_active=false; |
101 |
|
(this->tfile)->Close(); |
102 |
|
} |
103 |
|
else { |
104 |
< |
cout << "SAMPLE " << this->samplename << " cannot be closed as the underlying file (" << this->filename << ") does not exist!" << endl; |
104 |
> |
dout << "SAMPLE " << this->samplename << " cannot be closed as the underlying file (" << this->filename << ") does not exist!" << endl; |
105 |
|
this->is_active=false; |
106 |
|
} |
107 |
|
} |
114 |
|
TFile *f = new TFile(filename.c_str()); |
115 |
|
|
116 |
|
if (f->IsZombie()) { |
117 |
< |
cout << "Error opening file" << filename << endl; |
117 |
> |
dout << "Error opening file" << filename << endl; |
118 |
|
return 0; |
119 |
|
} |
120 |
|
f->Close(); |
124 |
|
//******************************************************** |
125 |
|
|
126 |
|
TCut essentialcut("mll>0"); |
127 |
+ |
// This will reweight all the events: use "weight" to correct MC for pileUP, "1.0" otherwise |
128 |
+ |
TCut cutWeight("weight"); |
129 |
|
|
130 |
|
void setessentialcut(TCut ess) { |
131 |
|
essentialcut=ess; |
142 |
|
int ngroups; |
143 |
|
|
144 |
|
samplecollection(string m_name); |
145 |
< |
void AddSample(string m_filename,string m_samplename,int m_Nentries, float m_xs,bool is_data, bool m_is_signal, int groupindex, Color_t color); |
145 |
> |
void AddSample(string m_filename,string m_samplename,long m_Nentries, float m_xs,bool is_data, bool m_is_signal, int groupindex, Color_t color); |
146 |
|
|
147 |
|
//vector quantities |
148 |
|
TH1F* Draw(string m_histoname,string m_var, vector<float> binning, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, vector<int> onlyindex, bool drawsignal); |
152 |
|
TH1F* Draw(string m_histoname,string m_var, int m_nbins, float m_minx, float m_maxx, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, bool drawsignal); |
153 |
|
TH1F* Draw(string m_histoname,string m_var, int m_nbins, float m_minx, float m_maxx, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, vector<int> onlyindex, bool drawsignal); |
154 |
|
|
155 |
+ |
TH2F* Draw(string m_histoname,string m_var, vector<float> binningx, vector<float> binningy, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, vector<int> onlyindex, bool drawsignal); |
156 |
+ |
|
157 |
|
vector<float> get_optimal_binsize(string variable, TCut cut,int nbins, float low, float high); |
158 |
|
|
159 |
|
THStack DrawStack(string m_histoname,string m_var, int m_nbins, float m_minx, float m_maxx, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, bool drawsignal); |
160 |
+ |
THStack DrawStack(string m_histoname,string m_var, vector<float> binning, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, bool drawsignal); |
161 |
|
vector<int> FindSample(string what); |
162 |
|
void ListSamples(); |
163 |
|
bool do_sample(int thissample, vector<int> &selected_samples); |
169 |
|
|
170 |
|
void PickUpFromThisFile(int isamp, string cut, vector<string> &output, vector<string> &pickupfile); |
171 |
|
void PickUpEvents(string cut); |
172 |
+ |
string find_units(string&); |
173 |
+ |
|
174 |
+ |
void RemoveLastSample(); |
175 |
|
}; |
176 |
|
|
177 |
|
samplecollection::samplecollection(string m_name) |
178 |
|
{ |
179 |
|
this->name=m_name; |
180 |
< |
if(Verbosity>0) cout << "Initiated sample collection " << this->name << " " << endl; |
180 |
> |
if(Verbosity>0) dout << "Initiated sample collection " << this->name << " " << endl; |
181 |
|
} |
182 |
|
|
183 |
|
void samplecollection::ListSamples() |
184 |
|
{ |
185 |
< |
cout << "---------------------------------------------------------------------------------------------------" << endl; |
186 |
< |
cout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl; |
185 |
> |
dout << "---------------------------------------------------------------------------------------------------" << endl; |
186 |
> |
dout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl; |
187 |
|
if(this->ndatasamples>0) { |
188 |
< |
cout << "Data sample(s): " << endl; |
188 |
> |
dout << "Data sample(s): " << endl; |
189 |
|
for (int isamp=0;isamp<this->collection.size();isamp++) |
190 |
|
{ |
191 |
< |
if((this->collection)[isamp].is_data) cout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl; |
191 |
> |
if((this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl; |
192 |
|
} |
193 |
|
} |
194 |
|
if(this->nmcsamples>0) { |
195 |
< |
cout << "MC sample(s): " << endl; |
195 |
> |
dout << "MC sample(s): " << endl; |
196 |
|
for (int isamp=0;isamp<this->collection.size();isamp++) |
197 |
|
{ |
198 |
< |
if(!(this->collection)[isamp].is_data) cout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl; |
198 |
> |
if(!(this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl; |
199 |
|
} |
200 |
|
} |
201 |
< |
cout << "---------------------------------------------------------------------------------------------------" << endl; |
201 |
> |
dout << "---------------------------------------------------------------------------------------------------" << endl; |
202 |
|
} |
203 |
|
|
204 |
< |
void samplecollection::AddSample(string m_filename,string m_samplename,int m_Nentries, float m_xs,bool is_data, bool m_is_signal, int groupindex, Color_t newcolor) |
204 |
> |
void samplecollection::AddSample(string m_filename,string m_samplename,long m_Nentries, float m_xs,bool is_data, bool m_is_signal, int groupindex, Color_t newcolor) |
205 |
|
{ |
206 |
|
sample NewSample(m_filename,m_samplename,m_Nentries,m_xs,is_data,m_is_signal,groupindex,newcolor); |
207 |
|
(this->collection).push_back(NewSample); |
245 |
|
} |
246 |
|
|
247 |
|
TH1F* samplecollection::Draw(string m_histoname,string m_var, vector<float> binning, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, vector<int> onlyindex, bool drawsignal=false) { |
248 |
< |
if(Verbosity>0) cout << endl << endl; |
249 |
< |
if(Verbosity>0) cout << "-------------------------------------------------------------------------------------" << endl; |
250 |
< |
if(Verbosity>0) cout << "histoname : " << m_histoname << " , m_var = " << m_var << ", m_xlabel=" << m_xlabel << " m_ylabel=" << m_ylabel << " m_is_data = " << m_is_data << " lumi = " << luminosity << " onlyindex size: " << onlyindex.size() << endl; |
251 |
< |
if(HUSH==0) cout << "Drawing histo called " << m_histoname << "... " << endl; |
248 |
> |
if(Verbosity>0) dout << endl << endl; |
249 |
> |
if(Verbosity>0) dout << "-------------------------------------------------------------------------------------" << endl; |
250 |
> |
if(Verbosity>0) dout << "histoname : " << m_histoname << " , m_var = " << m_var << ", m_xlabel=" << m_xlabel << " m_ylabel=" << m_ylabel << " m_is_data = " << m_is_data << " lumi = " << luminosity << " onlyindex size: " << onlyindex.size() << endl; |
251 |
> |
if(HUSH==0) dout << "Drawing histo called " << m_histoname << "... " << endl; |
252 |
|
bool do_only_selected_samples=false; |
253 |
|
if(onlyindex.size()>0&&onlyindex[0]!=-1) { |
254 |
< |
if(Verbosity>0) {cout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;} |
254 |
> |
if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;} |
255 |
|
for(int is=0;is<onlyindex.size();is++) { |
256 |
< |
if(Verbosity>0) cout << " - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl; |
256 |
> |
if(Verbosity>0) dout << " - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl; |
257 |
|
} |
258 |
|
do_only_selected_samples=true; |
259 |
|
} |
284 |
|
TH1F *tempdrawhisto = new TH1F("tempdrawhisto","tempdrawhisto",binning.size()-1,binningarray); |
285 |
|
tempdrawhisto->Sumw2(); |
286 |
|
if(use_this_sample) { |
287 |
< |
if(Verbosity>0) cout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
288 |
< |
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");//this weight is based on PU etc. not XS |
287 |
> |
if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
288 |
> |
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS |
289 |
> |
if(addoverunderflowbins) { |
290 |
> |
//now also adding the overflow & underflow bins: |
291 |
> |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())); |
292 |
> |
tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()))); |
293 |
> |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1)); |
294 |
> |
tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
295 |
> |
} |
296 |
> |
|
297 |
> |
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));//weight applied here is XS & N(entries) |
298 |
> |
histo->Add(tempdrawhisto); |
299 |
> |
} |
300 |
> |
tempdrawhisto->Delete(); |
301 |
> |
}//end of loop over isample |
302 |
> |
if(Verbosity>0) dout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl; |
303 |
> |
histo->GetXaxis()->SetTitle(m_xlabel.c_str()); |
304 |
> |
// Try to add bin width information: look for units in m_xlabel |
305 |
> |
string units = find_units(m_xlabel); |
306 |
> |
if ( units.length()>0 ) { |
307 |
> |
stringstream ylabel; |
308 |
> |
ylabel << m_ylabel << " / " << histo->GetBinWidth(1) << " " << units; |
309 |
> |
histo->GetYaxis()->SetTitle( ylabel.str().c_str() ); |
310 |
> |
} else { |
311 |
> |
histo->GetYaxis()->SetTitle(m_ylabel.c_str()); |
312 |
> |
} |
313 |
> |
histo->GetXaxis()->CenterTitle(); |
314 |
> |
histo->GetYaxis()->CenterTitle(); |
315 |
> |
if(do_only_selected_samples) histo->SetLineColor(this->GetColor(onlyindex[0])); |
316 |
> |
return histo; |
317 |
> |
} |
318 |
> |
|
319 |
> |
TH2F* samplecollection::Draw(string m_histoname,string m_var, vector<float> binningx, vector<float> binningy, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, vector<int> onlyindex, bool drawsignal=false) { |
320 |
> |
if(Verbosity>0) dout << endl << endl; |
321 |
> |
if(Verbosity>0) dout << "-------------------------------------------------------------------------------------" << endl; |
322 |
> |
if(Verbosity>0) dout << "histoname : " << m_histoname << " , m_var = " << m_var << ", m_xlabel=" << m_xlabel << " m_ylabel=" << m_ylabel << " m_is_data = " << m_is_data << " lumi = " << luminosity << " onlyindex size: " << onlyindex.size() << endl; |
323 |
> |
if(HUSH==0) dout << "Drawing histo called " << m_histoname << "... " << endl; |
324 |
> |
bool do_only_selected_samples=false; |
325 |
> |
if(onlyindex.size()>0&&onlyindex[0]!=-1) { |
326 |
> |
if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;} |
327 |
> |
for(int is=0;is<onlyindex.size();is++) { |
328 |
> |
if(Verbosity>0) dout << " - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl; |
329 |
> |
} |
330 |
> |
do_only_selected_samples=true; |
331 |
> |
} |
332 |
> |
if(onlyindex.size()==1&&onlyindex[0]==-1) { |
333 |
> |
do_only_selected_samples=true; // this is the special case when we request a non-existing sample - we shouldn't draw anything then. |
334 |
> |
onlyindex.clear(); |
335 |
> |
} |
336 |
> |
stringstream h_histoname; |
337 |
> |
h_histoname<<"h_"<<m_histoname; |
338 |
> |
float binningarray[binningx.size()+1]; |
339 |
> |
float binningyarray[binningy.size()+1]; |
340 |
> |
for(int i=0;i<binningx.size();i++) {binningarray[i]=binningx[i];binningyarray[i]=binningy[i];} |
341 |
> |
TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size(),binningyarray); |
342 |
> |
histo->Sumw2(); |
343 |
> |
|
344 |
> |
stringstream drawthis; |
345 |
> |
drawthis<<m_var<<">>tempdrawhisto"; |
346 |
> |
|
347 |
> |
for (unsigned int isample=0;isample<(this->collection).size();isample++) { |
348 |
> |
bool use_this_sample=false; |
349 |
> |
if(!(this->collection)[isample].is_active) continue; // skip inactive samples right away |
350 |
> |
if(((this->collection)[isample].is_data==m_is_data)&&(!do_only_selected_samples)) { |
351 |
> |
if(drawsignal==false&&(this->collection)[isample].is_signal==true) continue; |
352 |
> |
use_this_sample=true; |
353 |
> |
} |
354 |
> |
if(do_only_selected_samples&&this->do_sample(isample,onlyindex)) { |
355 |
> |
use_this_sample=true; |
356 |
> |
} |
357 |
> |
TH2F *tempdrawhisto = new TH2F("tempdrawhisto","tempdrawhisto",binningx.size()-1,binningarray,binningy.size()-1,binningyarray); |
358 |
> |
tempdrawhisto->Sumw2(); |
359 |
> |
if(use_this_sample) { |
360 |
> |
if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
361 |
> |
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS |
362 |
|
if(addoverunderflowbins) { |
363 |
|
//now also adding the overflow & underflow bins: |
364 |
< |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)); |
364 |
> |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())); |
365 |
|
tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()))); |
366 |
< |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)); |
366 |
> |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1)); |
367 |
|
tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
368 |
|
} |
369 |
|
|
372 |
|
} |
373 |
|
tempdrawhisto->Delete(); |
374 |
|
}//end of loop over isample |
375 |
< |
if(Verbosity>0) cout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl; |
375 |
> |
if(Verbosity>0) dout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl; |
376 |
|
histo->GetXaxis()->SetTitle(m_xlabel.c_str()); |
377 |
|
histo->GetYaxis()->SetTitle(m_ylabel.c_str()); |
378 |
|
histo->GetXaxis()->CenterTitle(); |
393 |
|
TH1F *histo = this->Draw(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, onlyindex,drawsignal); |
394 |
|
return histo; |
395 |
|
} |
396 |
< |
THStack samplecollection::DrawStack(string m_histoname,string m_var, int m_nbins, float m_minx, float m_maxx, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, bool drawsignal=false) |
397 |
< |
{ |
396 |
> |
|
397 |
> |
THStack samplecollection::DrawStack(string m_histoname,string m_var, vector<float> binning, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, bool drawsignal=false) { |
398 |
|
stringstream h_histoname; |
399 |
|
h_histoname<<"h_"<<m_histoname; |
400 |
|
THStack thestack("thestack",m_histoname.c_str()); |
406 |
|
int bookedhistos[this->ngroups+1]; |
407 |
|
for(int ih=0;ih<=this->ngroups;ih++) bookedhistos[ih]=0; |
408 |
|
|
409 |
+ |
float binningarray[binning.size()+1]; |
410 |
+ |
for(int i=0;i<binning.size();i++) {binningarray[i]=binning[i];} |
411 |
+ |
|
412 |
|
for (unsigned int isample=0;isample<(this->collection).size();isample++) { |
413 |
|
if(!drawsignal&&(this->collection)[isample].is_signal) continue; |
414 |
|
if((this->collection)[isample].is_active&&(this->collection)[isample].is_data==m_is_data) {//fills mc if we want mc, else fills data. |
415 |
< |
TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",m_nbins,m_minx,m_maxx); |
416 |
< |
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight"); |
415 |
> |
TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",binning.size()-1,binningarray); |
416 |
> |
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight); |
417 |
|
|
418 |
|
if(addoverunderflowbins) { |
419 |
|
//now also adding the overflow & underflow bins: |
420 |
< |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)); |
421 |
< |
tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()))); |
422 |
< |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)); |
423 |
< |
tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
420 |
> |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())); |
421 |
> |
// tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()))); // errors not necessary for stack! |
422 |
> |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1)); |
423 |
> |
// tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); // errors not necessary for stack! |
424 |
|
} |
425 |
|
|
426 |
|
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight)); |
461 |
|
return thestack; |
462 |
|
} |
463 |
|
|
464 |
+ |
THStack samplecollection::DrawStack(string m_histoname,string m_var, int m_nbins, float m_minx, float m_maxx, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, bool |
465 |
+ |
drawsignal=false) |
466 |
+ |
{ |
467 |
+ |
vector<float> binning; |
468 |
+ |
for(int i=0;i<=m_nbins;i++) |
469 |
+ |
{ |
470 |
+ |
binning.push_back(((float)(m_maxx-m_minx)/((float)m_nbins))*i+m_minx); |
471 |
+ |
} |
472 |
+ |
return this->DrawStack(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, drawsignal); |
473 |
+ |
} |
474 |
+ |
|
475 |
|
|
476 |
|
vector<int> samplecollection::FindSample(string what) |
477 |
|
{ |
480 |
|
{ |
481 |
|
if(((this->collection)[isam].filename).find(what)!=string::npos) { |
482 |
|
hitcollection.push_back(isam); |
483 |
+ |
} else { |
484 |
|
} |
388 |
– |
else { |
389 |
– |
} |
485 |
|
} |
486 |
< |
if(hitcollection.size()==0) hitcollection.push_back(-1); |
486 |
> |
if(hitcollection.size()==0) { |
487 |
> |
hitcollection.push_back(-1); |
488 |
> |
write_warning(__FUNCTION__,"Couldn't find sample "+string(what)+" using sample collection \""+string(this->name)+"\""); |
489 |
> |
} |
490 |
|
return hitcollection; |
491 |
|
} |
492 |
|
|
502 |
|
|
503 |
|
TLegend* samplecollection::allbglegend(string title, TH1F *data,float posx=0.65, float posy=0.60) { |
504 |
|
// TLegend *leg = new TLegend(0.65,0.60,0.89,0.77); |
505 |
< |
TLegend *leg = new TLegend(posx,posy,0.89,0.77); |
505 |
> |
TLegend *leg = new TLegend(posx,posy,0.89,0.89); |
506 |
|
if(title!="") leg->SetHeader(title.c_str()); |
507 |
|
if(data->GetName()!="nothing") leg->AddEntry(data,"Data","p"); |
508 |
|
leg->SetFillColor(kWhite); |
538 |
|
|
539 |
|
|
540 |
|
void set_treename(string treen="events") { |
541 |
< |
cout << "Treename has been set to " << treen << endl; |
541 |
> |
dout << "Treename has been set to " << treen << endl; |
542 |
|
if(treen=="PFevents"||treen=="events") treename=treen; |
543 |
|
else write_error("sample::set_treename","Setting the treename failed as you provided an invalid tree name."); |
544 |
|
} |
575 |
|
(this->collection)[isamp].events->SetBranchAddress("eventNum",&eventNum); |
576 |
|
(this->collection)[isamp].events->SetBranchAddress("lumi",&lumi); |
577 |
|
(this->collection)[isamp].events->SetBranchAddress("runNum",&runNum); |
578 |
+ |
|
579 |
|
|
580 |
< |
TTreeFormula *select = new TTreeFormula("select", "pfJetGoodNum>=3&&jzb[1]>100&&jzb[1]<150&&id1==id2", (this->collection)[isamp].events); |
580 |
> |
TTreeFormula *select = new TTreeFormula("select", cut.c_str()&&essentialcut, (this->collection)[isamp].events); |
581 |
> |
int npickedup=0; |
582 |
|
for (Int_t entry = 0 ; entry < (this->collection)[isamp].events->GetEntries() ; entry++) { |
583 |
|
(this->collection)[isamp].events->LoadTree(entry); |
584 |
|
if (select->EvalInstance()) { |
585 |
|
(this->collection)[isamp].events->GetEntry(entry); |
586 |
< |
cout << runNum << ":" << lumi << ":" << eventNum << endl; |
586 |
> |
dout << runNum << ":" << lumi << ":" << eventNum << endl; |
587 |
> |
npickedup++; |
588 |
|
} |
589 |
|
} |
590 |
+ |
dout << "Printed out a total of " << npickedup << " events" << endl; |
591 |
|
} |
592 |
|
|
593 |
|
|
605 |
|
//do something with output and of course the pickup file! |
606 |
|
} |
607 |
|
|
608 |
+ |
//________________________________________________________________________________________ |
609 |
+ |
// Find units from histogram x-label (looks for '[...]') |
610 |
+ |
string samplecollection::find_units(string& xlabel) { |
611 |
+ |
|
612 |
+ |
string units; |
613 |
+ |
size_t pos1 = xlabel.find("["); |
614 |
+ |
if ( pos1 != string::npos ) { |
615 |
+ |
size_t pos2 = xlabel.find("]"); |
616 |
+ |
units = xlabel.substr(pos1+1,pos2-pos1-1); |
617 |
+ |
}// else { |
618 |
+ |
// size_t pos1 = xlabel.find("("); |
619 |
+ |
// if ( pos1 != string::npos ) { |
620 |
+ |
// size_t pos2 = xlabel.find(")"); |
621 |
+ |
// units = xlabel.substr(pos1+1,pos2-pos1-1); |
622 |
+ |
// } |
623 |
+ |
// } |
624 |
+ |
return units; |
625 |
+ |
|
626 |
+ |
} |
627 |
+ |
|
628 |
+ |
void samplecollection::RemoveLastSample() { |
629 |
+ |
dout << "Removing last sample: " << ((this->collection)[(this->collection).size()-1]).filename << std::endl; |
630 |
+ |
if(((this->collection)[(this->collection).size()-1]).is_data) this->ndatasamples--; |
631 |
+ |
else this->nmcsamples--; |
632 |
+ |
this->nsamples--; |
633 |
+ |
((this->collection)[(this->collection).size()-1]).closeFile(); |
634 |
+ |
(this->collection).pop_back(); |
635 |
+ |
} |
636 |
|
|
637 |
|
void switch_overunderflow(bool newpos=false) { |
638 |
|
addoverunderflowbins=newpos; |
639 |
< |
} |
639 |
> |
} |
640 |
> |
|
641 |
> |
|