53 |
|
TTree *events; |
54 |
|
|
55 |
|
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); |
56 |
+ |
string ExtractVersion(string FullVersionString); |
57 |
|
void closeFile(); |
58 |
|
}; |
59 |
|
|
63 |
|
return "MC"; |
64 |
|
} |
65 |
|
|
66 |
+ |
string sample::ExtractVersion(string FullVersionString) { |
67 |
+ |
string Result=FullVersionString.substr(FullVersionString.find(" ")+1,FullVersionString.length()); |
68 |
+ |
Result=Result.substr(0,Result.find(" ")); |
69 |
+ |
return Result; |
70 |
+ |
} |
71 |
+ |
|
72 |
|
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) |
73 |
|
{ |
74 |
|
this->filename=m_filename; |
90 |
|
|
91 |
|
if(doesROOTFileExist(this->filename)) { |
92 |
|
//suppressing stupid 64/32 errors here (Warning in <TFile::ReadStreamerInfo>: /scratch/buchmann/MC_Spring11_PU_PF/TToBLNu_TuneZ2_t-channel_7TeV-madgraph.root: not a TStreamerInfo object) |
93 |
< |
Int_t currlevel=gErrorIgnoreLevel; |
94 |
< |
gErrorIgnoreLevel=5000; |
93 |
> |
// Int_t currlevel=gErrorIgnoreLevel; |
94 |
> |
// gErrorIgnoreLevel=5000; |
95 |
|
this->tfile = new TFile(m_filename.c_str()); |
96 |
< |
gErrorIgnoreLevel=currlevel; |
96 |
> |
// gErrorIgnoreLevel=currlevel; |
97 |
|
this->events=(TTree*)(this->tfile)->Get(treename.c_str()); |
98 |
|
if(Verbosity>0) dout << "The " << write_mc_or_data(is_data) << " file " << this->filename << " has been added successfully to the list of samples. " << endl; |
99 |
|
long long measured_nevents=(long)1; |
100 |
|
TH1F *weight_histo = (TH1F*)(this->tfile)->Get("weight_histo"); |
101 |
|
float average_weight = 1.0; |
102 |
|
if(weight_histo) { |
103 |
< |
average_weight = weight_histo->Integral()/weight_histo->GetEntries(); |
103 |
> |
//average_weight = weight_histo->Integral()/weight_histo->GetEntries(); |
104 |
|
measured_nevents = (long)weight_histo->GetEntries(); |
105 |
|
} else { |
106 |
|
measured_nevents=(this->events)->GetEntries(); |
130 |
|
this->weightrenormalization=1; |
131 |
|
} |
132 |
|
} |
133 |
+ |
|
134 |
|
} |
135 |
|
else { |
136 |
|
this->is_active=false; |
152 |
|
bool doesROOTFileExist(string filename) |
153 |
|
{ |
154 |
|
//suppressing stupid 64/32 errors here (Warning in <TFile::ReadStreamerInfo>: /scratch/buchmann/MC_Spring11_PU_PF/TToBLNu_TuneZ2_t-channel_7TeV-madgraph.root: not a TStreamerInfo object) |
155 |
< |
Int_t currlevel=gErrorIgnoreLevel; |
156 |
< |
gErrorIgnoreLevel=5000; |
155 |
> |
// Int_t currlevel=gErrorIgnoreLevel; |
156 |
> |
// gErrorIgnoreLevel=5000; |
157 |
|
TFile *f = new TFile(filename.c_str()); |
158 |
|
|
159 |
|
if (f->IsZombie()) { |
161 |
|
return 0; |
162 |
|
} |
163 |
|
f->Close(); |
164 |
< |
gErrorIgnoreLevel=currlevel; |
164 |
> |
// gErrorIgnoreLevel=currlevel; |
165 |
|
return 1; |
166 |
|
} |
167 |
|
//******************************************************** |
213 |
|
TLegend* allbglegend(string title, TH1F *data, float x, float y); |
214 |
|
|
215 |
|
void PickUpFromThisFile(int isamp, string cut, vector<string> &output, vector<string> &pickupfile); |
216 |
< |
void PickUpEvents(string cut); |
216 |
> |
void PickUpEvents(string cut,string filename); |
217 |
|
string find_units(string&); |
218 |
|
|
219 |
|
void RemoveLastSample(); |
240 |
|
dout << "MC sample(s): " << endl; |
241 |
|
for (int isamp=0;isamp<(int)this->collection.size();isamp++) |
242 |
|
{ |
243 |
< |
if(!(this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " (" << (this->collection)[isamp].filename << ") xs=" << (this->collection)[isamp].xs << " pb, N(events)=" << (this->collection)[isamp].Nentries << " , RN = " << (this->collection)[isamp].weightrenormalization << endl; |
243 |
> |
if(!(this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " (" << (this->collection)[isamp].filename << ") xs=" << (this->collection)[isamp].xs << " pb, N(events)=" << (this->collection)[isamp].Nentries << endl; |
244 |
|
} |
245 |
|
} |
246 |
|
dout << "---------------------------------------------------------------------------------------------------" << endl; |
249 |
|
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) |
250 |
|
{ |
251 |
|
sample NewSample(m_filename,m_samplename,m_Nentries,m_xs,is_data,m_is_signal,groupindex,newcolor); |
252 |
+ |
if (!NewSample.is_active) { |
253 |
+ |
write_warning(__FUNCTION__,"Not adding this sample ("+m_filename+") as it has been declared inactive"); |
254 |
+ |
return; |
255 |
+ |
} |
256 |
|
(this->collection).push_back(NewSample); |
257 |
|
if((this->collection).size()==1) { |
258 |
|
this->nmcsamples=0; |
335 |
|
tempdrawhisto->Sumw2(); |
336 |
|
if(use_this_sample) { |
337 |
|
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS |
338 |
< |
//cout << "Drawing " << drawthis.str() << " with cut " << (const char*) (essentialcut&&Cut)*cutWeight << endl; |
338 |
> |
// cout << "\033[1;33m Drawing " << drawthis.str() << " with cut " << (const char*) (essentialcut&&Cut)*cutWeight << " for sample " << (this->collection)[isample].filename << "\033[0m (overflow: " << addoverunderflowbins << ")" << endl; |
339 |
|
if(addoverunderflowbins) { |
340 |
|
//now also adding the overflow & underflow bins: |
341 |
|
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())); |
342 |
|
tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()))); |
343 |
< |
tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1)); |
344 |
< |
tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
343 |
> |
// tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1)); |
344 |
> |
// tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1))); |
345 |
> |
// Delete over- and under-flow bins |
346 |
> |
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX()+1,0); |
347 |
> |
// tempdrawhisto->SetBinContent(0,0); |
348 |
|
} |
349 |
|
|
350 |
|
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));//weight applied here is XS & N(entries) |
413 |
|
if(use_this_sample) { |
414 |
|
if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
415 |
|
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS |
416 |
< |
cout << "About to draw : " << drawthis.str() << " with cut " << (const char*) (essentialcut&&Cut)*cutWeight << endl; |
416 |
> |
// cout << "About to draw : " << drawthis.str() << " with cut " << (const char*) (essentialcut&&Cut)*cutWeight << endl; |
417 |
|
if(addoverunderflowbins) { |
418 |
|
//now also adding the overflow & underflow bins: |
419 |
|
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())); |
444 |
|
{ |
445 |
|
binning.push_back(((float)(m_maxx-m_minx)/((float)m_nbins))*i+m_minx); |
446 |
|
} |
447 |
< |
|
447 |
> |
|
448 |
|
TH1F *histo = this->Draw(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, onlyindex,drawsignal); |
449 |
|
return histo; |
450 |
|
} |
468 |
|
if(!drawsignal&&(this->collection)[isample].is_signal) continue; |
469 |
|
if((this->collection)[isample].is_active&&(this->collection)[isample].is_data==m_is_data) {//fills mc if we want mc, else fills data. |
470 |
|
TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",binning.size()-1,binningarray); |
471 |
+ |
tempdrawhisto->Sumw2(); |
472 |
|
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight); |
473 |
|
|
474 |
|
if(addoverunderflowbins) { |
577 |
|
// TLegend *leg = new TLegend(0.65,0.60,0.89,0.77); |
578 |
|
TLegend *leg = new TLegend(posx,posy,0.89,0.89); |
579 |
|
if(title!="") leg->SetHeader(title.c_str()); |
580 |
< |
if(data->GetName()!="nothing") leg->AddEntry(data,"Data","p"); |
580 |
> |
if(data->GetName()!="nothing") leg->AddEntry(data,"Data","lp"); |
581 |
|
leg->SetFillColor(kWhite); |
582 |
|
leg->SetBorderSize(0); |
583 |
|
leg->SetLineColor(kWhite); |
584 |
|
|
585 |
< |
TH1F *fakehistos[(this->collection).size()]; |
586 |
< |
bool donealready[(this->collection).size()]; |
587 |
< |
for(int i=0;i<(int)(this->collection).size();i++) donealready[i]=false; |
585 |
> |
int maxIgroup=0; |
586 |
> |
for(int isample=0;isample<(int)(this->collection).size();isample++) { |
587 |
> |
if((this->collection)[isample].groupindex>maxIgroup) maxIgroup=(this->collection)[isample].groupindex; |
588 |
> |
} |
589 |
> |
maxIgroup++; |
590 |
> |
|
591 |
> |
TH1F *fakehistos[maxIgroup]; |
592 |
> |
bool donealready[maxIgroup]; |
593 |
> |
|
594 |
> |
for(int i=0;i<maxIgroup;i++) donealready[i]=false; |
595 |
> |
|
596 |
|
for(int isample=0;isample<(int)(this->collection).size();isample++) { |
597 |
|
if((this->collection)[isample].is_data||(this->collection)[isample].is_signal) continue; |
574 |
– |
|
598 |
|
if(!donealready[(this->collection)[isample].groupindex]) { |
599 |
+ |
assert((this->collection)[isample].groupindex<maxIgroup); |
600 |
|
fakehistos[(this->collection)[isample].groupindex] = new TH1F(GetNumericHistoName().c_str(),"",1,0,1); |
601 |
|
fakehistos[(this->collection)[isample].groupindex]->Fill(1); |
602 |
|
fakehistos[(this->collection)[isample].groupindex]->SetFillColor(this->GetColor(isample)); |
603 |
|
leg->AddEntry(fakehistos[(this->collection)[isample].groupindex],((this->collection)[isample].samplename).c_str(),"f"); |
604 |
|
donealready[(this->collection)[isample].groupindex]=true; |
605 |
+ |
PlottingSetup::FakeHistoHeap.push_back(fakehistos[(this->collection)[isample].groupindex]); |
606 |
|
} |
607 |
|
} |
608 |
|
DrawPrelim(); |
611 |
|
} |
612 |
|
|
613 |
|
TLegend* samplecollection::allbglegend(string title="",float posx=0.65, float posy=0.60) { |
589 |
– |
Int_t currlevel=gErrorIgnoreLevel; |
590 |
– |
gErrorIgnoreLevel=5000; |
614 |
|
TH1F *blub = new TH1F("nothing","nothing",1,0,1); |
615 |
< |
gErrorIgnoreLevel=currlevel;//we know this possibly replaces a previous histo, but we don't care since it's fake anyway. |
616 |
< |
return this->allbglegend(title,blub,posx,posy); |
615 |
> |
TLegend *leg = this->allbglegend(title,blub,posx,posy); |
616 |
> |
PlottingSetup::FakeHistoHeap.push_back(blub); |
617 |
> |
return leg; |
618 |
|
} |
619 |
|
|
620 |
|
|
649 |
|
} |
650 |
|
|
651 |
|
void samplecollection::PickUpFromThisFile(int isamp, string cut, vector<string> &output, vector<string> &pickupfile) { |
652 |
< |
int lumi,eventNum,runNum; |
652 |
> |
int lumi,runNum; |
653 |
> |
ULong64_t eventNum; |
654 |
> |
|
655 |
|
float jzb[30]; |
656 |
|
(this->collection)[isamp].events->SetBranchAddress("jzb",&jzb); |
657 |
|
(this->collection)[isamp].events->SetBranchAddress("lumi",&runNum); |
662 |
|
|
663 |
|
TTreeFormula *select = new TTreeFormula("select", cut.c_str()&&essentialcut, (this->collection)[isamp].events); |
664 |
|
int npickedup=0; |
665 |
+ |
stringstream filetext; |
666 |
|
for (Int_t entry = 0 ; entry < (this->collection)[isamp].events->GetEntries() ; entry++) { |
667 |
|
(this->collection)[isamp].events->LoadTree(entry); |
668 |
|
if (select->EvalInstance()) { |
669 |
|
(this->collection)[isamp].events->GetEntry(entry); |
670 |
|
dout << runNum << ":" << lumi << ":" << eventNum << endl; |
671 |
+ |
filetext.str(""); |
672 |
+ |
filetext << runNum << ":" << lumi << ":" << eventNum << endl; |
673 |
+ |
output.push_back(filetext.str()); |
674 |
|
npickedup++; |
675 |
|
} |
676 |
|
} |
679 |
|
|
680 |
|
|
681 |
|
|
682 |
< |
void samplecollection::PickUpEvents(string cut) { |
682 |
> |
void samplecollection::PickUpEvents(string cut, string filename) { |
683 |
|
vector<string> output; |
684 |
|
vector<string> pickupfile; |
685 |
< |
for (int isamp=0;isamp<(int)this->collection.size();isamp++) |
685 |
> |
for (unsigned int isamp=0;isamp<this->collection.size();isamp++) |
686 |
|
{ |
687 |
|
if((this->collection)[isamp].is_data) { |
688 |
|
//we have a data sample ! |
689 |
|
this->PickUpFromThisFile(isamp,cut,output,pickupfile); |
690 |
|
} |
691 |
|
} |
692 |
+ |
|
693 |
|
//do something with output and of course the pickup file! |
694 |
+ |
ofstream myfile(filename.c_str()); |
695 |
+ |
for(unsigned int ievent=0;ievent<output.size();ievent++) myfile << output[ievent]; |
696 |
+ |
myfile.close(); |
697 |
+ |
|
698 |
|
} |
699 |
|
|
700 |
|
//________________________________________________________________________________________ |