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.5 by buchmann, Tue Jul 12 12:57:10 2011 UTC vs.
Revision 1.12 by buchmann, Mon Aug 15 09:31:23 2011 UTC

# Line 87 | Line 87 | sample::sample(string m_filename, string
87      this->tfile = new TFile(m_filename.c_str());
88      gErrorIgnoreLevel=currlevel;
89      this->events=(TTree*)(this->tfile)->Get(treename.c_str());
90 <    if(Verbosity>0) cout << "The " << write_mc_or_data(is_data) << " file " << this->filename << " has been added successfully to the list of samples. " << endl;
90 >    if(Verbosity>0) dout << "The " << write_mc_or_data(is_data) << " file " << this->filename << " has been added successfully to the list of samples. " << endl;
91    }
92    else {
93      this->is_active=false;
# Line 101 | Line 101 | void sample::closeFile()
101      (this->tfile)->Close();
102    }
103    else {
104 <    cout << "SAMPLE " << this->samplename << " cannot be closed as the underlying file (" << this->filename << ") does not exist!" << endl;
104 >    dout << "SAMPLE " << this->samplename << " cannot be closed as the underlying file (" << this->filename << ") does not exist!" << endl;
105      this->is_active=false;
106    }
107   }
# Line 114 | Line 114 | bool doesROOTFileExist(string filename)
114    TFile *f = new TFile(filename.c_str());
115    
116    if (f->IsZombie()) {
117 <    cout << "Error opening file" << filename << endl;
117 >    dout << "Error opening file" << filename << endl;
118      return 0;
119    }
120    f->Close();
# Line 124 | Line 124 | bool doesROOTFileExist(string filename)
124   //********************************************************
125  
126   TCut essentialcut("mll>0");
127 + // This will reweight all the events: use "weight" to correct MC for pileUP
128 + TCut cutWeight("weight");
129  
130   void setessentialcut(TCut ess) {
131    essentialcut=ess;
# Line 155 | Line 157 | public:
157    vector<float> get_optimal_binsize(string variable, TCut cut,int nbins, float low, float high);
158      
159    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);
160 +  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);
161    vector<int> FindSample(string what);
162    void ListSamples();
163    bool do_sample(int thissample, vector<int> &selected_samples);
# Line 171 | Line 174 | public:
174   samplecollection::samplecollection(string m_name)
175   {
176    this->name=m_name;
177 <  if(Verbosity>0) cout << "Initiated sample collection " << this->name << " " << endl;
177 >  if(Verbosity>0) dout << "Initiated sample collection " << this->name << " " << endl;
178   }
179  
180   void samplecollection::ListSamples()
181   {
182 <  cout << "---------------------------------------------------------------------------------------------------" << endl;
183 <  cout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl;
182 >  dout << "---------------------------------------------------------------------------------------------------" << endl;
183 >  dout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl;
184    if(this->ndatasamples>0) {
185 <    cout << "Data sample(s): " << endl;
185 >    dout << "Data sample(s): " << endl;
186      for (int isamp=0;isamp<this->collection.size();isamp++)
187        {
188 <        if((this->collection)[isamp].is_data) cout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl;
188 >        if((this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl;
189        }
190    }
191    if(this->nmcsamples>0) {
192 <    cout << "MC sample(s): " << endl;
192 >    dout << "MC sample(s): " << endl;
193      for (int isamp=0;isamp<this->collection.size();isamp++)
194        {
195 <        if(!(this->collection)[isamp].is_data) cout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl;
195 >        if(!(this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl;
196        }
197    }
198 <  cout << "---------------------------------------------------------------------------------------------------" << endl;
198 >  dout << "---------------------------------------------------------------------------------------------------" << endl;
199   }
200      
201   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)
# Line 239 | Line 242 | TH1F* samplecollection::Draw(string m_hi
242   }
243    
244   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) {
245 <  if(Verbosity>0) cout << endl << endl;
246 <  if(Verbosity>0) cout << "-------------------------------------------------------------------------------------" << endl;
247 <  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;
248 <  if(HUSH==0) cout << "Drawing histo called " << m_histoname << "... " << endl;
245 >  if(Verbosity>0) dout << endl << endl;
246 >  if(Verbosity>0) dout << "-------------------------------------------------------------------------------------" << endl;
247 >  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;
248 >  if(HUSH==0) dout << "Drawing histo called " << m_histoname << "... " << endl;
249    bool do_only_selected_samples=false;
250    if(onlyindex.size()>0&&onlyindex[0]!=-1) {
251 <    if(Verbosity>0) {cout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;}
251 >    if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;}
252      for(int is=0;is<onlyindex.size();is++) {
253 <      if(Verbosity>0) cout << "   - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl;
253 >      if(Verbosity>0) dout << "   - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl;
254      }
255      do_only_selected_samples=true;
256    }
# Line 278 | Line 281 | TH1F* samplecollection::Draw(string m_hi
281      TH1F *tempdrawhisto = new TH1F("tempdrawhisto","tempdrawhisto",binning.size()-1,binningarray);
282      tempdrawhisto->Sumw2();
283      if(use_this_sample) {
284 <      if(Verbosity>0) cout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl;
285 <      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");//this weight is based on PU etc. not XS
284 >      if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl;
285 >      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS
286        if(addoverunderflowbins) {
287          //now also adding the overflow & underflow bins:
288          tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1));
# Line 293 | Line 296 | TH1F* samplecollection::Draw(string m_hi
296      }
297      tempdrawhisto->Delete();
298    }//end of loop over isample
299 <  if(Verbosity>0) cout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl;
299 >  if(Verbosity>0) dout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl;
300    histo->GetXaxis()->SetTitle(m_xlabel.c_str());
301    histo->GetYaxis()->SetTitle(m_ylabel.c_str());
302    histo->GetXaxis()->CenterTitle();
# Line 303 | Line 306 | TH1F* samplecollection::Draw(string m_hi
306   }
307  
308   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) {
309 <  if(Verbosity>0) cout << endl << endl;
310 <  if(Verbosity>0) cout << "-------------------------------------------------------------------------------------" << endl;
311 <  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;
312 <  if(HUSH==0) cout << "Drawing histo called " << m_histoname << "... " << endl;
309 >  if(Verbosity>0) dout << endl << endl;
310 >  if(Verbosity>0) dout << "-------------------------------------------------------------------------------------" << endl;
311 >  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;
312 >  if(HUSH==0) dout << "Drawing histo called " << m_histoname << "... " << endl;
313    bool do_only_selected_samples=false;
314    if(onlyindex.size()>0&&onlyindex[0]!=-1) {
315 <    if(Verbosity>0) {cout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;}
315 >    if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;}
316      for(int is=0;is<onlyindex.size();is++) {
317 <      if(Verbosity>0) cout << "   - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl;
317 >      if(Verbosity>0) dout << "   - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl;
318      }
319      do_only_selected_samples=true;
320    }
# Line 343 | Line 346 | TH2F* samplecollection::Draw(string m_hi
346      TH2F *tempdrawhisto = new TH2F("tempdrawhisto","tempdrawhisto",binningx.size()-1,binningarray,binningy.size()-1,binningyarray);
347      tempdrawhisto->Sumw2();
348      if(use_this_sample) {
349 <      if(Verbosity>0) cout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl;
350 <      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");//this weight is based on PU etc. not XS
349 >      if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl;
350 >      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS
351        if(addoverunderflowbins) {
352          //now also adding the overflow & underflow bins:
353          tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1));
# Line 358 | Line 361 | TH2F* samplecollection::Draw(string m_hi
361      }
362      tempdrawhisto->Delete();
363    }//end of loop over isample
364 <  if(Verbosity>0) cout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl;
364 >  if(Verbosity>0) dout << "Histo has been filled and now contains " << histo->Integral() << " points (integral)" << endl;
365    histo->GetXaxis()->SetTitle(m_xlabel.c_str());
366    histo->GetYaxis()->SetTitle(m_ylabel.c_str());
367    histo->GetXaxis()->CenterTitle();
# Line 379 | Line 382 | TH1F* samplecollection::Draw(string m_hi
382    TH1F *histo = this->Draw(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, onlyindex,drawsignal);
383    return histo;
384    }
385 < 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)
386 < {
385 >
386 > 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) {
387    stringstream h_histoname;
388    h_histoname<<"h_"<<m_histoname;
389    THStack thestack("thestack",m_histoname.c_str());
# Line 392 | Line 395 | THStack samplecollection::DrawStack(stri
395    int bookedhistos[this->ngroups+1];
396    for(int ih=0;ih<=this->ngroups;ih++) bookedhistos[ih]=0;
397    
398 +  float binningarray[binning.size()+1];
399 +  for(int i=0;i<binning.size();i++) {binningarray[i]=binning[i];}
400 +  
401    for (unsigned int isample=0;isample<(this->collection).size();isample++) {
402      if(!drawsignal&&(this->collection)[isample].is_signal) continue;
403      if((this->collection)[isample].is_active&&(this->collection)[isample].is_data==m_is_data) {//fills mc if we want mc, else fills data.
404 <      TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",m_nbins,m_minx,m_maxx);
405 <      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*"weight");
404 >      TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",binning.size()-1,binningarray);
405 >      (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);
406        
407        if(addoverunderflowbins) {
408          //now also adding the overflow & underflow bins:
# Line 444 | Line 450 | THStack samplecollection::DrawStack(stri
450    return thestack;
451   }
452  
453 + 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
454 + drawsignal=false)
455 + {
456 +  vector<float> binning;
457 +  for(int i=0;i<=m_nbins;i++)
458 +  {
459 +    binning.push_back(((float)(m_maxx-m_minx)/((float)m_nbins))*i+m_minx);
460 +  }
461 +  return this->DrawStack(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, drawsignal);
462 +  }
463 +
464  
465   vector<int> samplecollection::FindSample(string what)
466   {
# Line 452 | Line 469 | vector<int> samplecollection::FindSample
469    {
470      if(((this->collection)[isam].filename).find(what)!=string::npos) {
471        hitcollection.push_back(isam);
472 +    } else {
473      }
456    else {
457    }
474    }
475 <  if(hitcollection.size()==0) hitcollection.push_back(-1);
475 >  if(hitcollection.size()==0) {
476 >    hitcollection.push_back(-1);
477 >    write_warning(__FUNCTION__,"Couldn't find sample "+string(what)+": using sample collection \""+string(this->name)+"\"");
478 >  }
479    return hitcollection;
480   }
481  
# Line 472 | Line 491 | Color_t samplecollection::GetColor(int s
491  
492   TLegend* samplecollection::allbglegend(string title, TH1F *data,float posx=0.65, float posy=0.60) {
493   //  TLegend *leg = new TLegend(0.65,0.60,0.89,0.77);
494 <  TLegend *leg = new TLegend(posx,posy,0.89,0.77);
494 >  TLegend *leg = new TLegend(posx,posy,0.89,0.89);
495    if(title!="") leg->SetHeader(title.c_str());
496    if(data->GetName()!="nothing") leg->AddEntry(data,"Data","p");
497    leg->SetFillColor(kWhite);
# Line 508 | Line 527 | TLegend* samplecollection::allbglegend(s
527  
528  
529   void set_treename(string treen="events") {
530 <  cout << "Treename has been set to " << treen << endl;
530 >  dout << "Treename has been set to " << treen << endl;
531    if(treen=="PFevents"||treen=="events") treename=treen;
532    else write_error("sample::set_treename","Setting the treename failed as you provided an invalid tree name.");
533   }
# Line 545 | Line 564 | void samplecollection::PickUpFromThisFil
564    (this->collection)[isamp].events->SetBranchAddress("eventNum",&eventNum);
565    (this->collection)[isamp].events->SetBranchAddress("lumi",&lumi);
566    (this->collection)[isamp].events->SetBranchAddress("runNum",&runNum);
567 +
568    
569 <  TTreeFormula *select = new TTreeFormula("select", "pfJetGoodNum>=3&&jzb[1]>100&&jzb[1]<150&&id1==id2", (this->collection)[isamp].events);
569 >  TTreeFormula *select = new TTreeFormula("select", cut.c_str()&&essentialcut, (this->collection)[isamp].events);
570 >  int npickedup=0;
571    for (Int_t entry = 0 ; entry < (this->collection)[isamp].events->GetEntries() ; entry++) {
572     (this->collection)[isamp].events->LoadTree(entry);
573     if (select->EvalInstance()) {
574       (this->collection)[isamp].events->GetEntry(entry);
575 <     cout << runNum << ":" << lumi << ":" << eventNum << endl;
575 >     dout << runNum << ":" << lumi << ":" << eventNum << endl;
576 >     npickedup++;
577     }
578    }
579 +  dout << "Printed out a total of " << npickedup << " events" << endl;
580   }
581  
582    
# Line 574 | Line 597 | void samplecollection::PickUpEvents(stri
597  
598   void switch_overunderflow(bool newpos=false) {
599    addoverunderflowbins=newpos;
600 < }
600 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines