45 |
|
bool is_data; |
46 |
|
bool is_signal; |
47 |
|
bool is_active; |
48 |
+ |
float weightrenormalization; |
49 |
|
int groupindex; |
50 |
|
Color_t samplecolor; |
51 |
|
|
73 |
|
this->groupindex=m_groupindex; |
74 |
|
this->is_active=true; |
75 |
|
this->samplecolor=mycolor; |
76 |
+ |
this->weightrenormalization=1.0; |
77 |
|
if(!doesROOTFileExist(this->filename)) { |
78 |
|
stringstream message; |
79 |
|
message << "The " << write_mc_or_data(is_data) << " sample " << this->samplename << " is invalid because the associated file path, " << this->filename << " is incorrect."; |
89 |
|
gErrorIgnoreLevel=currlevel; |
90 |
|
this->events=(TTree*)(this->tfile)->Get(treename.c_str()); |
91 |
|
if(Verbosity>0) dout << "The " << write_mc_or_data(is_data) << " file " << this->filename << " has been added successfully to the list of samples. " << endl; |
92 |
< |
long long measured_nevents=(this->events)->GetEntries(); |
93 |
< |
if(((this->Nentries>1)||(this->Nentries==0))&measured_nevents!=this->Nentries) { |
92 |
> |
long long measured_nevents=(long)1; |
93 |
> |
TH1F *weight_histo = (TH1F*)(this->tfile)->Get("weight_histo"); |
94 |
> |
float average_weight = 1.0; |
95 |
> |
if(weight_histo) { |
96 |
> |
average_weight = weight_histo->Integral()/weight_histo->GetEntries(); |
97 |
> |
measured_nevents = (long)weight_histo->GetEntries(); |
98 |
> |
} else { |
99 |
> |
measured_nevents=(this->events)->GetEntries(); |
100 |
> |
} |
101 |
> |
|
102 |
> |
if(((this->Nentries>1)||(this->Nentries==0))&&measured_nevents!=this->Nentries) { |
103 |
|
//special cases: m_Nentries=1 : we want to give each event the full weight (->scans!) |
104 |
|
// m_Nentries=0: detect the number of events and set the nevents automatically |
105 |
+ |
// m_Nentries<0: set manually (see below) |
106 |
|
|
107 |
|
stringstream warning; |
108 |
|
warning << "Detected incorrect number of events in sample initialization of sample " << m_filename << " (detected Nevents: " << measured_nevents << " , definition claims: " << this->Nentries << "; will use measured number of events. If you want to use this algorithm to set the number of events anyway, set the number of events to 0."; |
109 |
|
if(m_Nentries>1) write_warning(__FUNCTION__,warning.str()); |
110 |
|
this->Nentries=measured_nevents; |
111 |
+ |
} else if ( this->Nentries<0 ) { |
112 |
+ |
this->Nentries = -this->Nentries; |
113 |
+ |
} |
114 |
+ |
if ( average_weight>0 ) { |
115 |
+ |
this->weight=(xs/(float)Nentries)/average_weight; |
116 |
+ |
this->weightrenormalization=(1.0/average_weight); |
117 |
+ |
} else { |
118 |
+ |
if(average_weight>0) { |
119 |
+ |
this->weight=(xs/(float)Nentries)/average_weight; |
120 |
+ |
this->weightrenormalization=(1.0/average_weight); |
121 |
+ |
} else { |
122 |
+ |
this->weight = (xs/(float)Nentries); |
123 |
+ |
this->weightrenormalization=1; |
124 |
+ |
} |
125 |
|
} |
100 |
– |
this->weight=(xs/(float)Nentries); |
126 |
|
} |
127 |
|
else { |
128 |
|
this->is_active=false; |
161 |
|
TCut essentialcut("mll>0"); |
162 |
|
// The following cut (cutWeight) will reweight all the events: use "weight" to correct MC for pileUP, "1.0" otherwise |
163 |
|
TCut cutWeight("weight"); |
164 |
+ |
//TCut cutWeight("(weight*(((id1==id2&&id1==0)*1.2)+((id1==id2&&id1==1)/1.2)+(id1!=id2)))"); |
165 |
|
|
166 |
|
void setessentialcut(TCut ess) { |
167 |
|
essentialcut=ess; |
223 |
|
dout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl; |
224 |
|
if(this->ndatasamples>0) { |
225 |
|
dout << "Data sample(s): " << endl; |
226 |
< |
for (int isamp=0;isamp<this->collection.size();isamp++) |
226 |
> |
for (int isamp=0;isamp<(int)this->collection.size();isamp++) |
227 |
|
{ |
228 |
|
if((this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl; |
229 |
|
} |
230 |
|
} |
231 |
|
if(this->nmcsamples>0) { |
232 |
|
dout << "MC sample(s): " << endl; |
233 |
< |
for (int isamp=0;isamp<this->collection.size();isamp++) |
233 |
> |
for (int isamp=0;isamp<(int)this->collection.size();isamp++) |
234 |
|
{ |
235 |
< |
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; |
235 |
> |
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; |
236 |
|
} |
237 |
|
} |
238 |
|
dout << "---------------------------------------------------------------------------------------------------" << endl; |
257 |
|
bool samplecollection::do_sample(int thissample, vector<int> &selected_samples) |
258 |
|
{ |
259 |
|
bool drawit=false; |
260 |
< |
for(int isel=0;isel<selected_samples.size();isel++) |
260 |
> |
for(int isel=0;isel<(int)selected_samples.size();isel++) |
261 |
|
{ |
262 |
|
if(selected_samples[isel]==thissample) { |
263 |
|
drawit=true; |
285 |
|
if(Verbosity>0) dout << endl << endl; |
286 |
|
if(Verbosity>0) dout << "-------------------------------------------------------------------------------------" << endl; |
287 |
|
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; |
288 |
+ |
|
289 |
|
if(HUSH==0) dout << "Drawing histo called " << m_histoname << "... " << endl; |
290 |
|
bool do_only_selected_samples=false; |
291 |
|
if(onlyindex.size()>0&&onlyindex[0]!=-1) { |
292 |
|
if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;} |
293 |
< |
for(int is=0;is<onlyindex.size();is++) { |
293 |
> |
for(int is=0;is<(int)onlyindex.size();is++) { |
294 |
|
if(Verbosity>0) dout << " - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl; |
295 |
|
} |
296 |
|
do_only_selected_samples=true; |
302 |
|
stringstream h_histoname; |
303 |
|
h_histoname<<"h_"<<m_histoname; |
304 |
|
float binningarray[binning.size()+1]; |
305 |
< |
for(int i=0;i<binning.size();i++) {binningarray[i]=binning[i];} |
305 |
> |
for(int i=0;i<(int)binning.size();i++) {binningarray[i]=binning[i];} |
306 |
|
TH1F *histo = new TH1F(m_histoname.c_str(),"",binning.size()-1,binningarray); |
307 |
|
histo->Sumw2(); |
308 |
|
|
322 |
|
TH1F *tempdrawhisto = new TH1F("tempdrawhisto","tempdrawhisto",binning.size()-1,binningarray); |
323 |
|
tempdrawhisto->Sumw2(); |
324 |
|
if(use_this_sample) { |
298 |
– |
if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
325 |
|
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS |
326 |
+ |
//cout << "Drawing " << drawthis.str() << " with cut " << (const char*) (essentialcut&&Cut)*cutWeight << endl; |
327 |
|
if(addoverunderflowbins) { |
328 |
|
//now also adding the overflow & underflow bins: |
329 |
|
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())); |
333 |
|
} |
334 |
|
|
335 |
|
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));//weight applied here is XS & N(entries) |
336 |
+ |
if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << ": " <<tempdrawhisto->Integral() << endl; |
337 |
|
histo->Add(tempdrawhisto); |
338 |
|
} |
339 |
|
tempdrawhisto->Delete(); |
363 |
|
bool do_only_selected_samples=false; |
364 |
|
if(onlyindex.size()>0&&onlyindex[0]!=-1) { |
365 |
|
if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;} |
366 |
< |
for(int is=0;is<onlyindex.size();is++) { |
366 |
> |
for(int is=0;is<(int)onlyindex.size();is++) { |
367 |
|
if(Verbosity>0) dout << " - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl; |
368 |
|
} |
369 |
|
do_only_selected_samples=true; |
376 |
|
h_histoname<<"h_"<<m_histoname; |
377 |
|
float binningarray[binningx.size()+1]; |
378 |
|
float binningyarray[binningy.size()+1]; |
379 |
< |
for(int i=0;i<binningx.size();i++) {binningarray[i]=binningx[i];binningyarray[i]=binningy[i];} |
380 |
< |
TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size(),binningyarray); |
379 |
> |
for(int i=0;i<(int)binningx.size();i++) {binningarray[i]=binningx[i];binningyarray[i]=binningy[i];} |
380 |
> |
TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size()-1,binningyarray); |
381 |
|
histo->Sumw2(); |
382 |
|
|
383 |
|
stringstream drawthis; |
398 |
|
if(use_this_sample) { |
399 |
|
if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl; |
400 |
|
(this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS |
401 |
+ |
cout << "About to draw : " << drawthis.str() << " with cut " << (const char*) (essentialcut&&Cut)*cutWeight << endl; |
402 |
|
if(addoverunderflowbins) { |
403 |
|
//now also adding the overflow & underflow bins: |
404 |
|
tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())); |
447 |
|
for(int ih=0;ih<=this->ngroups;ih++) bookedhistos[ih]=0; |
448 |
|
|
449 |
|
float binningarray[binning.size()+1]; |
450 |
< |
for(int i=0;i<binning.size();i++) {binningarray[i]=binning[i];} |
450 |
> |
for(int i=0;i<(int)binning.size();i++) {binningarray[i]=binning[i];} |
451 |
|
|
452 |
|
for (unsigned int isample=0;isample<(this->collection).size();isample++) { |
453 |
|
if(!drawsignal&&(this->collection)[isample].is_signal) continue; |
466 |
|
if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight)); |
467 |
|
tempdrawhisto->SetFillColor(this->GetColor(isample)); |
468 |
|
if(bookedhistos[(this->collection)[isample].groupindex]==0) { |
469 |
< |
tempdrawhisto->SetName(GetNumericHistoName().c_str()); |
469 |
> |
tempdrawhisto->SetName((removefunnystring((this->collection)[isample].samplename)+"__"+GetNumericHistoName()).c_str()); |
470 |
|
histogroups[(this->collection)[isample].groupindex]=(TH1F*)tempdrawhisto->Clone(); |
471 |
|
bookedhistos[(this->collection)[isample].groupindex]=1; |
472 |
|
} |
495 |
|
thestack.Add(histogroups[ordered_indices[index]]); |
496 |
|
} |
497 |
|
*/ |
498 |
< |
for(int index=0;index<ordered_indices.size();index++) { |
498 |
> |
for(int index=0;index<(int)ordered_indices.size();index++) { |
499 |
|
thestack.Add(histogroups[ordered_indices[index]]); |
500 |
|
} |
501 |
|
return thestack; |
568 |
|
|
569 |
|
TH1F *fakehistos[(this->collection).size()]; |
570 |
|
bool donealready[(this->collection).size()]; |
571 |
< |
for(int i=0;i<(this->collection).size();i++) donealready[i]=false; |
572 |
< |
for(int isample=0;isample<(this->collection).size();isample++) { |
571 |
> |
for(int i=0;i<(int)(this->collection).size();i++) donealready[i]=false; |
572 |
> |
for(int isample=0;isample<(int)(this->collection).size();isample++) { |
573 |
|
if((this->collection)[isample].is_data||(this->collection)[isample].is_signal) continue; |
574 |
|
|
575 |
|
if(!donealready[(this->collection)[isample].groupindex]) { |
652 |
|
void samplecollection::PickUpEvents(string cut) { |
653 |
|
vector<string> output; |
654 |
|
vector<string> pickupfile; |
655 |
< |
for (int isamp=0;isamp<this->collection.size();isamp++) |
655 |
> |
for (int isamp=0;isamp<(int)this->collection.size();isamp++) |
656 |
|
{ |
657 |
|
if((this->collection)[isamp].is_data) { |
658 |
|
//we have a data sample ! |