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; |
124 |
|
//******************************************************** |
125 |
|
|
126 |
|
TCut essentialcut("mll>0"); |
127 |
< |
// This will reweight all the events: use "weight" to correct MC for pileUP |
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) { |
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); |
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) |
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); |
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)); |
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)); |
293 |
> |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1)); |
294 |
|
tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
295 |
|
} |
296 |
|
|
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 |
< |
histo->GetYaxis()->SetTitle(m_ylabel.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])); |
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 |
|
|
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)); |
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 |
|
} |
640 |
+ |
|
641 |
+ |
|