ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/Plotting/Modules/SampleClass.C
(Generate patch)

Comparing UserCode/cbrown/AnalysisFramework/Plotting/Modules/SampleClass.C (file contents):
Revision 1.4 by buchmann, Fri Jul 8 14:33:58 2011 UTC vs.
Revision 1.21 by buchmann, Mon Oct 24 15:05:37 2011 UTC

# Line 6 | Line 6
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>
# Line 38 | Line 39 | class sample
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;
# Line 50 | Line 51 | public:
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  
# Line 60 | Line 61 | string write_mc_or_data(bool is_data)
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;
# Line 68 | Line 69 | sample::sample(string m_filename, string
69    this->xs=m_xs;
70    this->is_data=m_is_data;
71    this->is_signal=m_is_signal;
71  this->weight=(xs/(float)Nentries);
72    this->groupindex=m_groupindex;
73    this->is_active=true;
74    this->samplecolor=mycolor;
# Line 86 | Line 86 | sample::sample(string m_filename, string
86      this->tfile = new TFile(m_filename.c_str());
87      gErrorIgnoreLevel=currlevel;
88      this->events=(TTree*)(this->tfile)->Get(treename.c_str());
89 <    if(Verbosity>0) cout << "The " << write_mc_or_data(is_data) << " file " << this->filename << " has been added successfully to the list of samples. " << endl;
89 >    if(Verbosity>0) dout << "The " << write_mc_or_data(is_data) << " file " << this->filename << " has been added successfully to the list of samples. " << endl;
90 >    long long measured_nevents=(this->events)->GetEntries();
91 >    if(((this->Nentries>1)||(this->Nentries==0))&measured_nevents!=this->Nentries) {
92 >      //special cases: m_Nentries=1 : we want to give each event the full weight (->scans!)
93 >      //               m_Nentries=0: detect the number of events and set the nevents automatically
94 >
95 >      stringstream warning;
96 >      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.";
97 >      if(m_Nentries>1) write_warning(__FUNCTION__,warning.str());
98 >      this->Nentries=measured_nevents;
99 >    }
100 >    this->weight=(xs/(float)Nentries);
101    }
102    else {
103      this->is_active=false;
# Line 100 | Line 111 | void sample::closeFile()
111      (this->tfile)->Close();
112    }
113    else {
114 <    cout << "SAMPLE " << this->samplename << " cannot be closed as the underlying file (" << this->filename << ") does not exist!" << endl;
114 >    dout << "SAMPLE " << this->samplename << " cannot be closed as the underlying file (" << this->filename << ") does not exist!" << endl;
115      this->is_active=false;
116    }
117   }
# Line 113 | Line 124 | bool doesROOTFileExist(string filename)
124    TFile *f = new TFile(filename.c_str());
125    
126    if (f->IsZombie()) {
127 <    cout << "Error opening file" << filename << endl;
127 >    dout << "Error opening file" << filename << endl;
128      return 0;
129    }
130    f->Close();
# Line 123 | Line 134 | bool doesROOTFileExist(string filename)
134   //********************************************************
135  
136   TCut essentialcut("mll>0");
137 + // The following cut (cutWeight) will reweight all the events: use "weight" to correct MC for pileUP, "1.0" otherwise
138 + TCut cutWeight("weight");
139  
140   void setessentialcut(TCut ess) {
141    essentialcut=ess;
# Line 139 | Line 152 | public:
152    int ngroups;
153    
154    samplecollection(string m_name);
155 <  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);
155 >  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);
156  
157    //vector quantities
158    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);
# Line 149 | Line 162 | public:
162    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);
163    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);
164    
165 +  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);
166 +  
167    vector<float> get_optimal_binsize(string variable, TCut cut,int nbins, float low, float high);
168      
169    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);
170 +  THStack DrawStack(string m_histoname,string m_var, vector<float> binning, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, bool drawsignal);
171    vector<int> FindSample(string what);
172    void ListSamples();
173    bool do_sample(int thissample, vector<int> &selected_samples);
# Line 163 | Line 179 | public:
179    
180    void PickUpFromThisFile(int isamp, string cut, vector<string> &output, vector<string> &pickupfile);
181    void PickUpEvents(string cut);
182 +  string find_units(string&);
183 +
184 +  void RemoveLastSample();
185   };
186  
187   samplecollection::samplecollection(string m_name)
188   {
189    this->name=m_name;
190 <  if(Verbosity>0) cout << "Initiated sample collection " << this->name << " " << endl;
190 >  if(Verbosity>0) dout << "Initiated sample collection " << this->name << " " << endl;
191   }
192  
193   void samplecollection::ListSamples()
194   {
195 <  cout << "---------------------------------------------------------------------------------------------------" << endl;
196 <  cout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl;
195 >  dout << "---------------------------------------------------------------------------------------------------" << endl;
196 >  dout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl;
197    if(this->ndatasamples>0) {
198 <    cout << "Data sample(s): " << endl;
198 >    dout << "Data sample(s): " << endl;
199      for (int isamp=0;isamp<this->collection.size();isamp++)
200        {
201 <        if((this->collection)[isamp].is_data) cout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl;
201 >        if((this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl;
202        }
203    }
204    if(this->nmcsamples>0) {
205 <    cout << "MC sample(s): " << endl;
205 >    dout << "MC sample(s): " << endl;
206      for (int isamp=0;isamp<this->collection.size();isamp++)
207        {
208 <        if(!(this->collection)[isamp].is_data) cout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl;
208 >        if(!(this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl;
209        }
210    }
211 <  cout << "---------------------------------------------------------------------------------------------------" << endl;
211 >  dout << "---------------------------------------------------------------------------------------------------" << endl;
212   }
213      
214 < 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)
214 > 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)
215   {
216    sample NewSample(m_filename,m_samplename,m_Nentries,m_xs,is_data,m_is_signal,groupindex,newcolor);
217    (this->collection).push_back(NewSample);
# Line 236 | Line 255 | TH1F* samplecollection::Draw(string m_hi
255   }
256    
257   TH1F* samplecollection::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=false) {
258 <  if(Verbosity>0) cout << endl << endl;
259 <  if(Verbosity>0) cout << "-------------------------------------------------------------------------------------" << endl;
260 <  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;
261 <  if(HUSH==0) cout << "Drawing histo called " << m_histoname << "... " << endl;
258 >  if(Verbosity>0) dout << endl << endl;
259 >  if(Verbosity>0) dout << "-------------------------------------------------------------------------------------" << endl;
260 >  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;
261 >  if(HUSH==0) dout << "Drawing histo called " << m_histoname << "... " << endl;
262    bool do_only_selected_samples=false;
263    if(onlyindex.size()>0&&onlyindex[0]!=-1) {
264 <    if(Verbosity>0) {cout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;}
264 >    if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;}
265      for(int is=0;is<onlyindex.size();is++) {
266 <      if(Verbosity>0) cout << "   - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl;
266 >      if(Verbosity>0) dout << "   - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl;
267      }
268      do_only_selected_samples=true;
269    }
# Line 275 | Line 294 | TH1F* samplecollection::Draw(string m_hi
294      TH1F *tempdrawhisto = new TH1F("tempdrawhisto","tempdrawhisto",binning.size()-1,binningarray);
295      tempdrawhisto->Sumw2();
296      if(use_this_sample) {
297 <      if(Verbosity>0) cout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl;
298 <      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");//this weight is based on PU etc. not XS
297 >      if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl;
298 >      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS
299        if(addoverunderflowbins) {
300          //now also adding the overflow & underflow bins:
301 <        tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1));
301 >        tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()));
302          tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())));
303 <        tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0));
303 >        tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1));
304          tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1)));
305        }
306  
# Line 290 | Line 309 | TH1F* samplecollection::Draw(string m_hi
309      }
310      tempdrawhisto->Delete();
311    }//end of loop over isample
312 <  if(Verbosity>0) cout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl;
312 >  if(Verbosity>0) dout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl;
313 >  histo->GetXaxis()->SetTitle(m_xlabel.c_str());
314 >  // Try to add bin width information: look for units in m_xlabel
315 >  string units = find_units(m_xlabel);
316 >  if ( units.length()>0 ) {
317 >    stringstream ylabel;
318 >    ylabel << m_ylabel << " / " << histo->GetBinWidth(1) << " " << units;
319 >    histo->GetYaxis()->SetTitle( ylabel.str().c_str() );
320 >  } else {
321 >    histo->GetYaxis()->SetTitle(m_ylabel.c_str());
322 >  }
323 >  histo->GetXaxis()->CenterTitle();
324 >  histo->GetYaxis()->CenterTitle();
325 >  if(do_only_selected_samples) histo->SetLineColor(this->GetColor(onlyindex[0]));
326 >  return histo;
327 > }
328 >
329 > 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) {
330 >  if(Verbosity>0) dout << endl << endl;
331 >  if(Verbosity>0) dout << "-------------------------------------------------------------------------------------" << endl;
332 >  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;
333 >  if(HUSH==0) dout << "Drawing histo called " << m_histoname << "... " << endl;
334 >  bool do_only_selected_samples=false;
335 >  if(onlyindex.size()>0&&onlyindex[0]!=-1) {
336 >    if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;}
337 >    for(int is=0;is<onlyindex.size();is++) {
338 >      if(Verbosity>0) dout << "   - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl;
339 >    }
340 >    do_only_selected_samples=true;
341 >  }
342 >  if(onlyindex.size()==1&&onlyindex[0]==-1) {
343 >    do_only_selected_samples=true; // this is the special case when we request a non-existing sample - we shouldn't draw anything then.
344 >    onlyindex.clear();
345 >  }
346 >  stringstream h_histoname;
347 >  h_histoname<<"h_"<<m_histoname;
348 >  float binningarray[binningx.size()+1];
349 >  float binningyarray[binningy.size()+1];
350 >  for(int i=0;i<binningx.size();i++) {binningarray[i]=binningx[i];binningyarray[i]=binningy[i];}
351 >  TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size(),binningyarray);
352 >  histo->Sumw2();
353 >  
354 >  stringstream drawthis;
355 >  drawthis<<m_var<<">>tempdrawhisto";
356 >  
357 >  for (unsigned int isample=0;isample<(this->collection).size();isample++) {
358 >    bool use_this_sample=false;
359 >    if(!(this->collection)[isample].is_active) continue; // skip inactive samples right away
360 >    if(((this->collection)[isample].is_data==m_is_data)&&(!do_only_selected_samples)) {
361 >      if(drawsignal==false&&(this->collection)[isample].is_signal==true) continue;
362 >      use_this_sample=true;
363 >    }
364 >    if(do_only_selected_samples&&this->do_sample(isample,onlyindex)) {
365 >      use_this_sample=true;
366 >    }
367 >    TH2F *tempdrawhisto = new TH2F("tempdrawhisto","tempdrawhisto",binningx.size()-1,binningarray,binningy.size()-1,binningyarray);
368 >    tempdrawhisto->Sumw2();
369 >    if(use_this_sample) {
370 >      if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl;
371 >      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS
372 >      if(addoverunderflowbins) {
373 >        //now also adding the overflow & underflow bins:
374 >        tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()));
375 >        tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())));
376 >        tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1));
377 >        tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1)));
378 >      }
379 >
380 >      if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));//weight applied here is XS & N(entries)
381 >      histo->Add(tempdrawhisto);
382 >    }
383 >    tempdrawhisto->Delete();
384 >  }//end of loop over isample
385 >  if(Verbosity>0) dout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl;
386    histo->GetXaxis()->SetTitle(m_xlabel.c_str());
387    histo->GetYaxis()->SetTitle(m_ylabel.c_str());
388    histo->GetXaxis()->CenterTitle();
# Line 311 | Line 403 | TH1F* samplecollection::Draw(string m_hi
403    TH1F *histo = this->Draw(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, onlyindex,drawsignal);
404    return histo;
405    }
406 < THStack samplecollection::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=false)
407 < {
406 >
407 > THStack samplecollection::DrawStack(string m_histoname,string m_var, vector<float> binning, string m_xlabel, string m_ylabel, TCut Cut, bool m_is_data, float luminosity, bool drawsignal=false) {
408    stringstream h_histoname;
409    h_histoname<<"h_"<<m_histoname;
410    THStack thestack("thestack",m_histoname.c_str());
# Line 324 | Line 416 | THStack samplecollection::DrawStack(stri
416    int bookedhistos[this->ngroups+1];
417    for(int ih=0;ih<=this->ngroups;ih++) bookedhistos[ih]=0;
418    
419 +  float binningarray[binning.size()+1];
420 +  for(int i=0;i<binning.size();i++) {binningarray[i]=binning[i];}
421 +  
422    for (unsigned int isample=0;isample<(this->collection).size();isample++) {
423      if(!drawsignal&&(this->collection)[isample].is_signal) continue;
424      if((this->collection)[isample].is_active&&(this->collection)[isample].is_data==m_is_data) {//fills mc if we want mc, else fills data.
425 <      TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",m_nbins,m_minx,m_maxx);
426 <      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");
425 >      TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",binning.size()-1,binningarray);
426 >      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);
427        
428        if(addoverunderflowbins) {
429          //now also adding the overflow & underflow bins:
430 <        tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1));
431 <        tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())));
432 <        tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0));
433 <        tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1)));
430 >        tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()));
431 > //      tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())));  // errors not necessary for stack!
432 >        tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1));
433 > //      tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1)));  // errors not necessary for stack!
434        }
435  
436        if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));
# Line 376 | Line 471 | THStack samplecollection::DrawStack(stri
471    return thestack;
472   }
473  
474 + THStack samplecollection::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
475 + drawsignal=false)
476 + {
477 +  vector<float> binning;
478 +  for(int i=0;i<=m_nbins;i++)
479 +  {
480 +    binning.push_back(((float)(m_maxx-m_minx)/((float)m_nbins))*i+m_minx);
481 +  }
482 +  return this->DrawStack(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, drawsignal);
483 +  }
484 +
485  
486   vector<int> samplecollection::FindSample(string what)
487   {
# Line 384 | Line 490 | vector<int> samplecollection::FindSample
490    {
491      if(((this->collection)[isam].filename).find(what)!=string::npos) {
492        hitcollection.push_back(isam);
493 +    } else {
494      }
388    else {
389    }
495    }
496 <  if(hitcollection.size()==0) hitcollection.push_back(-1);
496 >  if(hitcollection.size()==0) {
497 >    hitcollection.push_back(-1);
498 >    write_warning(__FUNCTION__,"Couldn't find sample "+string(what)+" using sample collection \""+string(this->name)+"\"");
499 >  }
500    return hitcollection;
501   }
502  
# Line 404 | Line 512 | Color_t samplecollection::GetColor(int s
512  
513   TLegend* samplecollection::allbglegend(string title, TH1F *data,float posx=0.65, float posy=0.60) {
514   //  TLegend *leg = new TLegend(0.65,0.60,0.89,0.77);
515 <  TLegend *leg = new TLegend(posx,posy,0.89,0.77);
515 >  TLegend *leg = new TLegend(posx,posy,0.89,0.89);
516    if(title!="") leg->SetHeader(title.c_str());
517    if(data->GetName()!="nothing") leg->AddEntry(data,"Data","p");
518    leg->SetFillColor(kWhite);
# Line 440 | Line 548 | TLegend* samplecollection::allbglegend(s
548  
549  
550   void set_treename(string treen="events") {
551 <  cout << "Treename has been set to " << treen << endl;
551 >  dout << "Treename has been set to " << treen << endl;
552    if(treen=="PFevents"||treen=="events") treename=treen;
553    else write_error("sample::set_treename","Setting the treename failed as you provided an invalid tree name.");
554   }
# Line 477 | Line 585 | void samplecollection::PickUpFromThisFil
585    (this->collection)[isamp].events->SetBranchAddress("eventNum",&eventNum);
586    (this->collection)[isamp].events->SetBranchAddress("lumi",&lumi);
587    (this->collection)[isamp].events->SetBranchAddress("runNum",&runNum);
588 +
589    
590 <  TTreeFormula *select = new TTreeFormula("select", "pfJetGoodNum>=3&&jzb[1]>100&&jzb[1]<150&&id1==id2", (this->collection)[isamp].events);
590 >  TTreeFormula *select = new TTreeFormula("select", cut.c_str()&&essentialcut, (this->collection)[isamp].events);
591 >  int npickedup=0;
592    for (Int_t entry = 0 ; entry < (this->collection)[isamp].events->GetEntries() ; entry++) {
593     (this->collection)[isamp].events->LoadTree(entry);
594     if (select->EvalInstance()) {
595       (this->collection)[isamp].events->GetEntry(entry);
596 <     cout << runNum << ":" << lumi << ":" << eventNum << endl;
596 >     dout << runNum << ":" << lumi << ":" << eventNum << endl;
597 >     npickedup++;
598     }
599    }
600 +  dout << "Printed out a total of " << npickedup << " events" << endl;
601   }
602  
603    
# Line 503 | Line 615 | void samplecollection::PickUpEvents(stri
615    //do something with output and of course the pickup file!
616   }
617  
618 + //________________________________________________________________________________________
619 + // Find units from histogram x-label (looks for '[...]')
620 + string samplecollection::find_units(string& xlabel) {
621 +  
622 +  string units;
623 +  size_t pos1 = xlabel.find("[");
624 +  if ( pos1 != string::npos ) {
625 +    size_t pos2 = xlabel.find("]");
626 +    units = xlabel.substr(pos1+1,pos2-pos1-1);
627 +  }//  else {
628 + //     size_t pos1 = xlabel.find("(");
629 + //     if ( pos1 != string::npos ) {
630 + //       size_t pos2 = xlabel.find(")");
631 + //       units = xlabel.substr(pos1+1,pos2-pos1-1);
632 + //     }
633 + //   }
634 +  return units;
635 +  
636 + }
637 +
638 + void samplecollection::RemoveLastSample() {
639 +  dout << "Removing last sample: " << ((this->collection)[(this->collection).size()-1]).filename << std::endl;
640 +  if(((this->collection)[(this->collection).size()-1]).is_data) this->ndatasamples--;
641 +  else this->nmcsamples--;
642 +  this->nsamples--;
643 +  ((this->collection)[(this->collection).size()-1]).closeFile();
644 +  (this->collection).pop_back();
645 + }
646  
647   void switch_overunderflow(bool newpos=false) {
648    addoverunderflowbins=newpos;
649 < }
649 > }
650 >
651 >  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines