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> |
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); |
279 |
|
tempdrawhisto->Sumw2(); |
280 |
|
if(use_this_sample) { |
281 |
|
if(Verbosity>0) cout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
282 |
+ |
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");//this weight is based on PU etc. not XS |
283 |
+ |
if(addoverunderflowbins) { |
284 |
+ |
//now also adding the overflow & underflow bins: |
285 |
+ |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)); |
286 |
+ |
tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()))); |
287 |
+ |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)); |
288 |
+ |
tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
289 |
+ |
} |
290 |
+ |
|
291 |
+ |
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));//weight applied here is XS & N(entries) |
292 |
+ |
histo->Add(tempdrawhisto); |
293 |
+ |
} |
294 |
+ |
tempdrawhisto->Delete(); |
295 |
+ |
}//end of loop over isample |
296 |
+ |
if(Verbosity>0) cout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl; |
297 |
+ |
histo->GetXaxis()->SetTitle(m_xlabel.c_str()); |
298 |
+ |
histo->GetYaxis()->SetTitle(m_ylabel.c_str()); |
299 |
+ |
histo->GetXaxis()->CenterTitle(); |
300 |
+ |
histo->GetYaxis()->CenterTitle(); |
301 |
+ |
if(do_only_selected_samples) histo->SetLineColor(this->GetColor(onlyindex[0])); |
302 |
+ |
return histo; |
303 |
+ |
} |
304 |
+ |
|
305 |
+ |
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) { |
306 |
+ |
if(Verbosity>0) cout << endl << endl; |
307 |
+ |
if(Verbosity>0) cout << "-------------------------------------------------------------------------------------" << endl; |
308 |
+ |
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; |
309 |
+ |
if(HUSH==0) cout << "Drawing histo called " << m_histoname << "... " << endl; |
310 |
+ |
bool do_only_selected_samples=false; |
311 |
+ |
if(onlyindex.size()>0&&onlyindex[0]!=-1) { |
312 |
+ |
if(Verbosity>0) {cout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;} |
313 |
+ |
for(int is=0;is<onlyindex.size();is++) { |
314 |
+ |
if(Verbosity>0) cout << " - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl; |
315 |
+ |
} |
316 |
+ |
do_only_selected_samples=true; |
317 |
+ |
} |
318 |
+ |
if(onlyindex.size()==1&&onlyindex[0]==-1) { |
319 |
+ |
do_only_selected_samples=true; // this is the special case when we request a non-existing sample - we shouldn't draw anything then. |
320 |
+ |
onlyindex.clear(); |
321 |
+ |
} |
322 |
+ |
stringstream h_histoname; |
323 |
+ |
h_histoname<<"h_"<<m_histoname; |
324 |
+ |
float binningarray[binningx.size()+1]; |
325 |
+ |
float binningyarray[binningy.size()+1]; |
326 |
+ |
for(int i=0;i<binningx.size();i++) {binningarray[i]=binningx[i];binningyarray[i]=binningy[i];} |
327 |
+ |
TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size(),binningyarray); |
328 |
+ |
histo->Sumw2(); |
329 |
+ |
|
330 |
+ |
stringstream drawthis; |
331 |
+ |
drawthis<<m_var<<">>tempdrawhisto"; |
332 |
+ |
|
333 |
+ |
for (unsigned int isample=0;isample<(this->collection).size();isample++) { |
334 |
+ |
bool use_this_sample=false; |
335 |
+ |
if(!(this->collection)[isample].is_active) continue; // skip inactive samples right away |
336 |
+ |
if(((this->collection)[isample].is_data==m_is_data)&&(!do_only_selected_samples)) { |
337 |
+ |
if(drawsignal==false&&(this->collection)[isample].is_signal==true) continue; |
338 |
+ |
use_this_sample=true; |
339 |
+ |
} |
340 |
+ |
if(do_only_selected_samples&&this->do_sample(isample,onlyindex)) { |
341 |
+ |
use_this_sample=true; |
342 |
+ |
} |
343 |
+ |
TH2F *tempdrawhisto = new TH2F("tempdrawhisto","tempdrawhisto",binningx.size()-1,binningarray,binningy.size()-1,binningyarray); |
344 |
+ |
tempdrawhisto->Sumw2(); |
345 |
+ |
if(use_this_sample) { |
346 |
+ |
if(Verbosity>0) cout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
347 |
|
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");//this weight is based on PU etc. not XS |
348 |
|
if(addoverunderflowbins) { |
349 |
|
//now also adding the overflow & underflow bins: |