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> |
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(); |
150 |
|
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); |
151 |
|
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); |
152 |
|
|
153 |
+ |
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); |
154 |
+ |
|
155 |
|
vector<float> get_optimal_binsize(string variable, TCut cut,int nbins, float low, float high); |
156 |
|
|
157 |
|
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); |
158 |
+ |
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); |
159 |
|
vector<int> FindSample(string what); |
160 |
|
void ListSamples(); |
161 |
|
bool do_sample(int thissample, vector<int> &selected_samples); |
172 |
|
samplecollection::samplecollection(string m_name) |
173 |
|
{ |
174 |
|
this->name=m_name; |
175 |
< |
if(Verbosity>0) cout << "Initiated sample collection " << this->name << " " << endl; |
175 |
> |
if(Verbosity>0) dout << "Initiated sample collection " << this->name << " " << endl; |
176 |
|
} |
177 |
|
|
178 |
|
void samplecollection::ListSamples() |
179 |
|
{ |
180 |
< |
cout << "---------------------------------------------------------------------------------------------------" << endl; |
181 |
< |
cout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl; |
180 |
> |
dout << "---------------------------------------------------------------------------------------------------" << endl; |
181 |
> |
dout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl; |
182 |
|
if(this->ndatasamples>0) { |
183 |
< |
cout << "Data sample(s): " << endl; |
183 |
> |
dout << "Data sample(s): " << endl; |
184 |
|
for (int isamp=0;isamp<this->collection.size();isamp++) |
185 |
|
{ |
186 |
< |
if((this->collection)[isamp].is_data) cout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl; |
186 |
> |
if((this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl; |
187 |
|
} |
188 |
|
} |
189 |
|
if(this->nmcsamples>0) { |
190 |
< |
cout << "MC sample(s): " << endl; |
190 |
> |
dout << "MC sample(s): " << endl; |
191 |
|
for (int isamp=0;isamp<this->collection.size();isamp++) |
192 |
|
{ |
193 |
< |
if(!(this->collection)[isamp].is_data) cout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl; |
193 |
> |
if(!(this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl; |
194 |
|
} |
195 |
|
} |
196 |
< |
cout << "---------------------------------------------------------------------------------------------------" << endl; |
196 |
> |
dout << "---------------------------------------------------------------------------------------------------" << endl; |
197 |
|
} |
198 |
|
|
199 |
|
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) |
240 |
|
} |
241 |
|
|
242 |
|
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) { |
243 |
< |
if(Verbosity>0) cout << endl << endl; |
244 |
< |
if(Verbosity>0) cout << "-------------------------------------------------------------------------------------" << endl; |
245 |
< |
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; |
246 |
< |
if(HUSH==0) cout << "Drawing histo called " << m_histoname << "... " << endl; |
243 |
> |
if(Verbosity>0) dout << endl << endl; |
244 |
> |
if(Verbosity>0) dout << "-------------------------------------------------------------------------------------" << endl; |
245 |
> |
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; |
246 |
> |
if(HUSH==0) dout << "Drawing histo called " << m_histoname << "... " << endl; |
247 |
|
bool do_only_selected_samples=false; |
248 |
|
if(onlyindex.size()>0&&onlyindex[0]!=-1) { |
249 |
< |
if(Verbosity>0) {cout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;} |
249 |
> |
if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;} |
250 |
|
for(int is=0;is<onlyindex.size();is++) { |
251 |
< |
if(Verbosity>0) cout << " - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl; |
251 |
> |
if(Verbosity>0) dout << " - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl; |
252 |
|
} |
253 |
|
do_only_selected_samples=true; |
254 |
|
} |
279 |
|
TH1F *tempdrawhisto = new TH1F("tempdrawhisto","tempdrawhisto",binning.size()-1,binningarray); |
280 |
|
tempdrawhisto->Sumw2(); |
281 |
|
if(use_this_sample) { |
282 |
< |
if(Verbosity>0) cout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
282 |
> |
if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
283 |
|
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");//this weight is based on PU etc. not XS |
284 |
|
if(addoverunderflowbins) { |
285 |
|
//now also adding the overflow & underflow bins: |
294 |
|
} |
295 |
|
tempdrawhisto->Delete(); |
296 |
|
}//end of loop over isample |
297 |
< |
if(Verbosity>0) cout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl; |
297 |
> |
if(Verbosity>0) dout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl; |
298 |
> |
histo->GetXaxis()->SetTitle(m_xlabel.c_str()); |
299 |
> |
histo->GetYaxis()->SetTitle(m_ylabel.c_str()); |
300 |
> |
histo->GetXaxis()->CenterTitle(); |
301 |
> |
histo->GetYaxis()->CenterTitle(); |
302 |
> |
if(do_only_selected_samples) histo->SetLineColor(this->GetColor(onlyindex[0])); |
303 |
> |
return histo; |
304 |
> |
} |
305 |
> |
|
306 |
> |
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) { |
307 |
> |
if(Verbosity>0) dout << endl << endl; |
308 |
> |
if(Verbosity>0) dout << "-------------------------------------------------------------------------------------" << endl; |
309 |
> |
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; |
310 |
> |
if(HUSH==0) dout << "Drawing histo called " << m_histoname << "... " << endl; |
311 |
> |
bool do_only_selected_samples=false; |
312 |
> |
if(onlyindex.size()>0&&onlyindex[0]!=-1) { |
313 |
> |
if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;} |
314 |
> |
for(int is=0;is<onlyindex.size();is++) { |
315 |
> |
if(Verbosity>0) dout << " - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl; |
316 |
> |
} |
317 |
> |
do_only_selected_samples=true; |
318 |
> |
} |
319 |
> |
if(onlyindex.size()==1&&onlyindex[0]==-1) { |
320 |
> |
do_only_selected_samples=true; // this is the special case when we request a non-existing sample - we shouldn't draw anything then. |
321 |
> |
onlyindex.clear(); |
322 |
> |
} |
323 |
> |
stringstream h_histoname; |
324 |
> |
h_histoname<<"h_"<<m_histoname; |
325 |
> |
float binningarray[binningx.size()+1]; |
326 |
> |
float binningyarray[binningy.size()+1]; |
327 |
> |
for(int i=0;i<binningx.size();i++) {binningarray[i]=binningx[i];binningyarray[i]=binningy[i];} |
328 |
> |
TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size(),binningyarray); |
329 |
> |
histo->Sumw2(); |
330 |
> |
|
331 |
> |
stringstream drawthis; |
332 |
> |
drawthis<<m_var<<">>tempdrawhisto"; |
333 |
> |
|
334 |
> |
for (unsigned int isample=0;isample<(this->collection).size();isample++) { |
335 |
> |
bool use_this_sample=false; |
336 |
> |
if(!(this->collection)[isample].is_active) continue; // skip inactive samples right away |
337 |
> |
if(((this->collection)[isample].is_data==m_is_data)&&(!do_only_selected_samples)) { |
338 |
> |
if(drawsignal==false&&(this->collection)[isample].is_signal==true) continue; |
339 |
> |
use_this_sample=true; |
340 |
> |
} |
341 |
> |
if(do_only_selected_samples&&this->do_sample(isample,onlyindex)) { |
342 |
> |
use_this_sample=true; |
343 |
> |
} |
344 |
> |
TH2F *tempdrawhisto = new TH2F("tempdrawhisto","tempdrawhisto",binningx.size()-1,binningarray,binningy.size()-1,binningyarray); |
345 |
> |
tempdrawhisto->Sumw2(); |
346 |
> |
if(use_this_sample) { |
347 |
> |
if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
348 |
> |
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");//this weight is based on PU etc. not XS |
349 |
> |
if(addoverunderflowbins) { |
350 |
> |
//now also adding the overflow & underflow bins: |
351 |
> |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)); |
352 |
> |
tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()))); |
353 |
> |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)); |
354 |
> |
tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
355 |
> |
} |
356 |
> |
|
357 |
> |
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));//weight applied here is XS & N(entries) |
358 |
> |
histo->Add(tempdrawhisto); |
359 |
> |
} |
360 |
> |
tempdrawhisto->Delete(); |
361 |
> |
}//end of loop over isample |
362 |
> |
if(Verbosity>0) dout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl; |
363 |
|
histo->GetXaxis()->SetTitle(m_xlabel.c_str()); |
364 |
|
histo->GetYaxis()->SetTitle(m_ylabel.c_str()); |
365 |
|
histo->GetXaxis()->CenterTitle(); |
380 |
|
TH1F *histo = this->Draw(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, onlyindex,drawsignal); |
381 |
|
return histo; |
382 |
|
} |
383 |
< |
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) |
384 |
< |
{ |
383 |
> |
|
384 |
> |
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) { |
385 |
|
stringstream h_histoname; |
386 |
|
h_histoname<<"h_"<<m_histoname; |
387 |
|
THStack thestack("thestack",m_histoname.c_str()); |
393 |
|
int bookedhistos[this->ngroups+1]; |
394 |
|
for(int ih=0;ih<=this->ngroups;ih++) bookedhistos[ih]=0; |
395 |
|
|
396 |
+ |
float binningarray[binning.size()+1]; |
397 |
+ |
for(int i=0;i<binning.size();i++) {binningarray[i]=binning[i];} |
398 |
+ |
|
399 |
|
for (unsigned int isample=0;isample<(this->collection).size();isample++) { |
400 |
|
if(!drawsignal&&(this->collection)[isample].is_signal) continue; |
401 |
|
if((this->collection)[isample].is_active&&(this->collection)[isample].is_data==m_is_data) {//fills mc if we want mc, else fills data. |
402 |
< |
TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",m_nbins,m_minx,m_maxx); |
402 |
> |
TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",binning.size()-1,binningarray); |
403 |
|
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight"); |
404 |
|
|
405 |
|
if(addoverunderflowbins) { |
448 |
|
return thestack; |
449 |
|
} |
450 |
|
|
451 |
+ |
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 |
452 |
+ |
drawsignal=false) |
453 |
+ |
{ |
454 |
+ |
vector<float> binning; |
455 |
+ |
for(int i=0;i<=m_nbins;i++) |
456 |
+ |
{ |
457 |
+ |
binning.push_back(((float)(m_maxx-m_minx)/((float)m_nbins))*i+m_minx); |
458 |
+ |
} |
459 |
+ |
return this->DrawStack(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, drawsignal); |
460 |
+ |
} |
461 |
+ |
|
462 |
|
|
463 |
|
vector<int> samplecollection::FindSample(string what) |
464 |
|
{ |
487 |
|
|
488 |
|
TLegend* samplecollection::allbglegend(string title, TH1F *data,float posx=0.65, float posy=0.60) { |
489 |
|
// TLegend *leg = new TLegend(0.65,0.60,0.89,0.77); |
490 |
< |
TLegend *leg = new TLegend(posx,posy,0.89,0.77); |
490 |
> |
TLegend *leg = new TLegend(posx,posy,0.89,0.89); |
491 |
|
if(title!="") leg->SetHeader(title.c_str()); |
492 |
|
if(data->GetName()!="nothing") leg->AddEntry(data,"Data","p"); |
493 |
|
leg->SetFillColor(kWhite); |
523 |
|
|
524 |
|
|
525 |
|
void set_treename(string treen="events") { |
526 |
< |
cout << "Treename has been set to " << treen << endl; |
526 |
> |
dout << "Treename has been set to " << treen << endl; |
527 |
|
if(treen=="PFevents"||treen=="events") treename=treen; |
528 |
|
else write_error("sample::set_treename","Setting the treename failed as you provided an invalid tree name."); |
529 |
|
} |
561 |
|
(this->collection)[isamp].events->SetBranchAddress("lumi",&lumi); |
562 |
|
(this->collection)[isamp].events->SetBranchAddress("runNum",&runNum); |
563 |
|
|
564 |
< |
TTreeFormula *select = new TTreeFormula("select", "pfJetGoodNum>=3&&jzb[1]>100&&jzb[1]<150&&id1==id2", (this->collection)[isamp].events); |
564 |
> |
TTreeFormula *select = new TTreeFormula("select", cut.c_str()&&essentialcut, (this->collection)[isamp].events); |
565 |
> |
int npickedup=0; |
566 |
|
for (Int_t entry = 0 ; entry < (this->collection)[isamp].events->GetEntries() ; entry++) { |
567 |
|
(this->collection)[isamp].events->LoadTree(entry); |
568 |
|
if (select->EvalInstance()) { |
569 |
|
(this->collection)[isamp].events->GetEntry(entry); |
570 |
< |
cout << runNum << ":" << lumi << ":" << eventNum << endl; |
570 |
> |
dout << runNum << ":" << lumi << ":" << eventNum << endl; |
571 |
> |
npickedup++; |
572 |
|
} |
573 |
|
} |
574 |
+ |
dout << "Printed out a total of " << npickedup << " events" << endl; |
575 |
|
} |
576 |
|
|
577 |
|
|