14 |
|
#include <TText.h> |
15 |
|
#include <TLegend.h> |
16 |
|
#include <TError.h> |
17 |
+ |
#include <TTreeFormula.h> |
18 |
|
|
19 |
|
#define SampleClassLoaded |
20 |
+ |
|
21 |
|
#ifndef Verbosity |
22 |
|
#define Verbosity 0 |
23 |
|
#endif |
30 |
|
using namespace std; |
31 |
|
|
32 |
|
bool doesROOTFileExist(string filename); |
33 |
< |
|
33 |
> |
bool addoverunderflowbins=false; |
34 |
|
string treename="PFevents"; |
35 |
|
|
36 |
|
class sample |
149 |
|
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); |
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, vector<int> onlyindex, bool drawsignal); |
151 |
|
|
152 |
+ |
vector<float> get_optimal_binsize(string variable, TCut cut,int nbins, float low, float high); |
153 |
+ |
|
154 |
|
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); |
155 |
|
vector<int> FindSample(string what); |
156 |
|
void ListSamples(); |
158 |
|
Color_t GetColor(string filename); |
159 |
|
Color_t GetColor(int sampleindex); |
160 |
|
|
161 |
< |
TLegend* allbglegend(string title); |
162 |
< |
TLegend* allbglegend(string title, TH1F *data); |
161 |
> |
TLegend* allbglegend(string title,float x, float y); |
162 |
> |
TLegend* allbglegend(string title, TH1F *data, float x, float y); |
163 |
> |
|
164 |
> |
void PickUpFromThisFile(int isamp, string cut, vector<string> &output, vector<string> &pickupfile); |
165 |
> |
void PickUpEvents(string cut); |
166 |
|
}; |
167 |
|
|
168 |
|
samplecollection::samplecollection(string m_name) |
276 |
|
tempdrawhisto->Sumw2(); |
277 |
|
if(use_this_sample) { |
278 |
|
if(Verbosity>0) cout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
279 |
< |
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight"); |
280 |
< |
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight)); |
279 |
> |
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");//this weight is based on PU etc. not XS |
280 |
> |
if(addoverunderflowbins) { |
281 |
> |
//now also adding the overflow & underflow bins: |
282 |
> |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)); |
283 |
> |
tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()))); |
284 |
> |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)); |
285 |
> |
tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
286 |
> |
} |
287 |
> |
|
288 |
> |
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));//weight applied here is XS & N(entries) |
289 |
|
histo->Add(tempdrawhisto); |
290 |
|
} |
291 |
|
tempdrawhisto->Delete(); |
329 |
|
if((this->collection)[isample].is_active&&(this->collection)[isample].is_data==m_is_data) {//fills mc if we want mc, else fills data. |
330 |
|
TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",m_nbins,m_minx,m_maxx); |
331 |
|
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight"); |
332 |
+ |
|
333 |
+ |
if(addoverunderflowbins) { |
334 |
+ |
//now also adding the overflow & underflow bins: |
335 |
+ |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)); |
336 |
+ |
tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()))); |
337 |
+ |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)); |
338 |
+ |
tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
339 |
+ |
} |
340 |
+ |
|
341 |
|
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight)); |
342 |
|
tempdrawhisto->SetFillColor(this->GetColor(isample)); |
343 |
|
if(bookedhistos[(this->collection)[isample].groupindex]==0) { |
402 |
|
return this->collection[sampleindex].samplecolor; |
403 |
|
} |
404 |
|
|
405 |
< |
TLegend* samplecollection::allbglegend(string title, TH1F *data) { |
406 |
< |
TLegend *leg = new TLegend(0.65,0.60,0.89,0.77); |
405 |
> |
TLegend* samplecollection::allbglegend(string title, TH1F *data,float posx=0.65, float posy=0.60) { |
406 |
> |
// TLegend *leg = new TLegend(0.65,0.60,0.89,0.77); |
407 |
> |
TLegend *leg = new TLegend(posx,posy,0.89,0.77); |
408 |
|
if(title!="") leg->SetHeader(title.c_str()); |
409 |
|
if(data->GetName()!="nothing") leg->AddEntry(data,"Data","p"); |
410 |
|
leg->SetFillColor(kWhite); |
425 |
|
donealready[(this->collection)[isample].groupindex]=true; |
426 |
|
} |
427 |
|
} |
428 |
< |
TText *writeline1 = write_text(0.77,0.87,"CMS Preliminary 2011"); |
404 |
< |
stringstream lumitext; |
405 |
< |
lumitext<<"#sqrt{s}=7, L="<<lumi<<" pb^{-1}"; |
406 |
< |
TText *writeline2 = write_text(0.77,0.83,lumitext.str().c_str()); |
407 |
< |
writeline1->SetTextSize(0.03); |
408 |
< |
writeline2->SetTextSize(0.03); |
409 |
< |
writeline1->Draw(); |
410 |
< |
writeline2->Draw(); |
428 |
> |
DrawPrelim(); |
429 |
|
leg->SetTextFont(42); |
430 |
|
return leg; |
431 |
|
} |
432 |
|
|
433 |
< |
TLegend* samplecollection::allbglegend(string title="") { |
433 |
> |
TLegend* samplecollection::allbglegend(string title="",float posx=0.65, float posy=0.60) { |
434 |
|
Int_t currlevel=gErrorIgnoreLevel; |
435 |
|
gErrorIgnoreLevel=5000; |
436 |
|
TH1F *blub = new TH1F("nothing","nothing",1,0,1); |
437 |
|
gErrorIgnoreLevel=currlevel;//we know this possibly replaces a previous histo, but we don't care since it's fake anyway. |
438 |
< |
return this->allbglegend(title,blub); |
438 |
> |
return this->allbglegend(title,blub,posx,posy); |
439 |
|
} |
440 |
|
|
441 |
+ |
|
442 |
|
void set_treename(string treen="events") { |
443 |
|
cout << "Treename has been set to " << treen << endl; |
444 |
|
if(treen=="PFevents"||treen=="events") treename=treen; |
445 |
|
else write_error("sample::set_treename","Setting the treename failed as you provided an invalid tree name."); |
446 |
|
} |
447 |
< |
|
447 |
> |
|
448 |
> |
vector<float> samplecollection::get_optimal_binsize(string variable, TCut cut,int nbins, float low, float high) { |
449 |
> |
TH1F *histo = this->Draw("histo",variable,5000,low,high, "finding_optimal_binsize", "events", cut,0,1000); |
450 |
> |
float eventsperbin=histo->Integral()/nbins; |
451 |
> |
vector<float> binning; |
452 |
> |
binning.push_back(high); |
453 |
> |
float runningsum=0; |
454 |
> |
for(int i=histo->GetNbinsX();i>0;i--) { |
455 |
> |
runningsum+=histo->GetBinContent(i); |
456 |
> |
if(TMath::Abs(runningsum-eventsperbin)<0.05*eventsperbin||runningsum>eventsperbin) { |
457 |
> |
binning.push_back(histo->GetBinLowEdge(i)); |
458 |
> |
runningsum=0; |
459 |
> |
} |
460 |
> |
} |
461 |
> |
if(runningsum>0) binning.push_back(low); |
462 |
> |
for(int i=0;i<int(binning.size()/2);i++) { |
463 |
> |
float temp=binning[i]; |
464 |
> |
binning[i]=binning[binning.size()-1-i]; |
465 |
> |
binning[binning.size()-1-i]=temp; |
466 |
> |
} |
467 |
> |
|
468 |
> |
return binning; |
469 |
> |
|
470 |
> |
} |
471 |
> |
|
472 |
> |
void samplecollection::PickUpFromThisFile(int isamp, string cut, vector<string> &output, vector<string> &pickupfile) { |
473 |
> |
int lumi,eventNum,runNum; |
474 |
> |
float jzb[30]; |
475 |
> |
(this->collection)[isamp].events->SetBranchAddress("jzb",&jzb); |
476 |
> |
(this->collection)[isamp].events->SetBranchAddress("lumi",&runNum); |
477 |
> |
(this->collection)[isamp].events->SetBranchAddress("eventNum",&eventNum); |
478 |
> |
(this->collection)[isamp].events->SetBranchAddress("lumi",&lumi); |
479 |
> |
(this->collection)[isamp].events->SetBranchAddress("runNum",&runNum); |
480 |
> |
|
481 |
> |
TTreeFormula *select = new TTreeFormula("select", "pfJetGoodNum>=3&&jzb[1]>100&&jzb[1]<150&&id1==id2", (this->collection)[isamp].events); |
482 |
> |
for (Int_t entry = 0 ; entry < (this->collection)[isamp].events->GetEntries() ; entry++) { |
483 |
> |
(this->collection)[isamp].events->LoadTree(entry); |
484 |
> |
if (select->EvalInstance()) { |
485 |
> |
(this->collection)[isamp].events->GetEntry(entry); |
486 |
> |
cout << runNum << ":" << lumi << ":" << eventNum << endl; |
487 |
> |
} |
488 |
> |
} |
489 |
> |
} |
490 |
> |
|
491 |
> |
|
492 |
> |
|
493 |
> |
void samplecollection::PickUpEvents(string cut) { |
494 |
> |
vector<string> output; |
495 |
> |
vector<string> pickupfile; |
496 |
> |
for (int isamp=0;isamp<this->collection.size();isamp++) |
497 |
> |
{ |
498 |
> |
if((this->collection)[isamp].is_data) { |
499 |
> |
//we have a data sample ! |
500 |
> |
this->PickUpFromThisFile(isamp,cut,output,pickupfile); |
501 |
> |
} |
502 |
> |
} |
503 |
> |
//do something with output and of course the pickup file! |
504 |
> |
} |
505 |
> |
|
506 |
> |
|
507 |
> |
void switch_overunderflow(bool newpos=false) { |
508 |
> |
addoverunderflowbins=newpos; |
509 |
> |
} |