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

Comparing UserCode/cbrown/Development/Plotting/Modules/SampleClass.C (file contents):
Revision 1.9 by buchmann, Tue Jun 5 09:18:29 2012 UTC vs.
Revision 1.19 by buchmann, Mon Dec 3 16:01:11 2012 UTC

# Line 83 | Line 83 | sample::sample(string m_filename, string
83      
84    if(doesROOTFileExist(this->filename)) {
85      //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)
86 <    Int_t currlevel=gErrorIgnoreLevel;
87 <    gErrorIgnoreLevel=5000;
86 > //    Int_t currlevel=gErrorIgnoreLevel;
87 > //     gErrorIgnoreLevel=5000;
88      this->tfile = new TFile(m_filename.c_str());
89 <    gErrorIgnoreLevel=currlevel;
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=(long)1;
# Line 99 | Line 99 | sample::sample(string m_filename, string
99        measured_nevents=(this->events)->GetEntries();
100      }
101  
102 <    if(((this->Nentries>1)||(this->Nentries==0))&measured_nevents!=this->Nentries) {
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      }
111    this->weight=(xs/(float)Nentries)/average_weight;
112    this->weightrenormalization=(1.0/average_weight);
126    }
127    else {
128      this->is_active=false;
# Line 131 | Line 144 | void sample::closeFile()
144   bool doesROOTFileExist(string filename)
145   {
146    //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)
147 <  Int_t currlevel=gErrorIgnoreLevel;
148 <  gErrorIgnoreLevel=5000;
147 > //   Int_t currlevel=gErrorIgnoreLevel;
148 > //   gErrorIgnoreLevel=5000;
149    TFile *f = new TFile(filename.c_str());
150    
151    if (f->IsZombie()) {
# Line 140 | Line 153 | bool doesROOTFileExist(string filename)
153      return 0;
154    }
155    f->Close();
156 <  gErrorIgnoreLevel=currlevel;
156 > //   gErrorIgnoreLevel=currlevel;
157    return 1;
158   }
159   //********************************************************
# Line 148 | Line 161 | bool doesROOTFileExist(string filename)
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;
# Line 227 | Line 241 | void samplecollection::ListSamples()
241   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)
242   {
243    sample NewSample(m_filename,m_samplename,m_Nentries,m_xs,is_data,m_is_signal,groupindex,newcolor);
244 +  if (!NewSample.is_active) {
245 +    write_warning(__FUNCTION__,"Not adding this sample ("+m_filename+") as it has been declared inactive");
246 +    return;
247 +  }
248    (this->collection).push_back(NewSample);
249    if((this->collection).size()==1) {
250      this->nmcsamples=0;
# Line 308 | Line 326 | TH1F* samplecollection::Draw(string m_hi
326      TH1F *tempdrawhisto = new TH1F("tempdrawhisto","tempdrawhisto",binning.size()-1,binningarray);
327      tempdrawhisto->Sumw2();
328      if(use_this_sample) {
311      if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl;
329        (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS
330 + //        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;
331        if(addoverunderflowbins) {
332          //now also adding the overflow & underflow bins:
333          tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()));
334          tempdrawhisto->SetBinError(tempdrawhisto->GetNbinsX(),TMath::Sqrt(tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX())));
335 <        tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1));
336 <        tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1)));
335 > //      tempdrawhisto->SetBinContent(1,tempdrawhisto->GetBinContent(0)+tempdrawhisto->GetBinContent(1));
336 > //      tempdrawhisto->SetBinError(1,TMath::Sqrt(tempdrawhisto->GetBinContent(1)));
337 >        // Delete over- and under-flow bins
338 >        tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX()+1,0);
339 > //        tempdrawhisto->SetBinContent(0,0);
340        }
341  
342        if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));//weight applied here is XS & N(entries)
343 +      if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << ": " <<tempdrawhisto->Integral() << endl;
344        histo->Add(tempdrawhisto);
345      }
346      tempdrawhisto->Delete();
# Line 362 | Line 384 | TH2F* samplecollection::Draw(string m_hi
384    float binningarray[binningx.size()+1];
385    float binningyarray[binningy.size()+1];
386    for(int i=0;i<(int)binningx.size();i++) {binningarray[i]=binningx[i];binningyarray[i]=binningy[i];}
387 <  TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size(),binningyarray);
387 >  TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size()-1,binningyarray);
388    histo->Sumw2();
389    
390    stringstream drawthis;
# Line 383 | Line 405 | TH2F* samplecollection::Draw(string m_hi
405      if(use_this_sample) {
406        if(Verbosity>0) dout << "[samplecollection::Draw] : Added contribution from sample " << (this->collection)[isample].samplename << endl;
407        (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);//this weight is based on PU etc. not XS
408 + //       cout << "About to draw : " << drawthis.str() << "  with cut   " << (const char*) (essentialcut&&Cut)*cutWeight << endl;
409        if(addoverunderflowbins) {
410          //now also adding the overflow & underflow bins:
411          tempdrawhisto->SetBinContent(tempdrawhisto->GetNbinsX(),tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()+1)+tempdrawhisto->GetBinContent(tempdrawhisto->GetNbinsX()));
# Line 413 | Line 436 | TH1F* samplecollection::Draw(string m_hi
436    {
437      binning.push_back(((float)(m_maxx-m_minx)/((float)m_nbins))*i+m_minx);
438    }
439 <  
439 >
440    TH1F *histo = this->Draw(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, onlyindex,drawsignal);
441    return histo;
442    }
# Line 437 | Line 460 | THStack samplecollection::DrawStack(stri
460      if(!drawsignal&&(this->collection)[isample].is_signal) continue;
461      if((this->collection)[isample].is_active&&(this->collection)[isample].is_data==m_is_data) {//fills mc if we want mc, else fills data.
462        TH1F *tempdrawhisto = new TH1F("tempdrawhisto","",binning.size()-1,binningarray);
463 +      tempdrawhisto->Sumw2();
464        (this->collection)[isample].events->Draw(drawthis.str().c_str(),(essentialcut&&Cut)*cutWeight);
465        
466        if(addoverunderflowbins) {
# Line 545 | Line 569 | TLegend* samplecollection::allbglegend(s
569   //  TLegend *leg = new TLegend(0.65,0.60,0.89,0.77);
570    TLegend *leg = new TLegend(posx,posy,0.89,0.89);
571    if(title!="") leg->SetHeader(title.c_str());
572 <  if(data->GetName()!="nothing") leg->AddEntry(data,"Data","p");
572 >  if(data->GetName()!="nothing") leg->AddEntry(data,"Data","lp");
573    leg->SetFillColor(kWhite);
574    leg->SetBorderSize(0);
575    leg->SetLineColor(kWhite);
# Line 570 | Line 594 | TLegend* samplecollection::allbglegend(s
594   }
595  
596   TLegend* samplecollection::allbglegend(string title="",float posx=0.65, float posy=0.60) {
597 <  Int_t currlevel=gErrorIgnoreLevel;
598 <  gErrorIgnoreLevel=5000;
597 > //   Int_t currlevel=gErrorIgnoreLevel;
598 > //   gErrorIgnoreLevel=5000;
599    TH1F *blub = new TH1F("nothing","nothing",1,0,1);
600 <  gErrorIgnoreLevel=currlevel;//we know this possibly replaces a previous histo, but we don't care since it's fake anyway.
600 > //   gErrorIgnoreLevel=currlevel;//we know this possibly replaces a previous histo, but we don't care since it's fake anyway.
601    return this->allbglegend(title,blub,posx,posy);
602   }
603  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines