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.7 by buchmann, Wed May 23 15:13:17 2012 UTC vs.
Revision 1.14 by fronga, Thu Aug 23 16:05:40 2012 UTC

# Line 45 | Line 45 | public:
45    bool is_data;
46    bool is_signal;
47    bool is_active;
48 +  float weightrenormalization;
49    int groupindex;
50    Color_t samplecolor;
51    
# Line 72 | Line 73 | sample::sample(string m_filename, string
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.";
# Line 97 | 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      }
109    this->weight=(xs/(float)Nentries);
110    TH1F *weight_histo = (TH1F*)(this->tfile)->Get("weight_histo");
111    this->weight/=average_weight;
126    }
127    else {
128      this->is_active=false;
# Line 147 | 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 217 | Line 232 | void samplecollection::ListSamples()
232      dout << "MC sample(s): " << endl;
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;
# Line 270 | Line 285 | TH1F* samplecollection::Draw(string m_hi
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) {
# Line 306 | Line 322 | TH1F* samplecollection::Draw(string m_hi
322      TH1F *tempdrawhisto = new TH1F("tempdrawhisto","tempdrawhisto",binning.size()-1,binningarray);
323      tempdrawhisto->Sumw2();
324      if(use_this_sample) {
309      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()));
# Line 317 | Line 333 | TH1F* samplecollection::Draw(string m_hi
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();
# Line 360 | Line 377 | TH2F* samplecollection::Draw(string m_hi
377    float binningarray[binningx.size()+1];
378    float binningyarray[binningy.size()+1];
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(),binningyarray);
380 >  TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size()-1,binningyarray);
381    histo->Sumw2();
382    
383    stringstream drawthis;
# Line 381 | Line 398 | TH2F* samplecollection::Draw(string m_hi
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()));
# Line 411 | Line 429 | TH1F* samplecollection::Draw(string m_hi
429    {
430      binning.push_back(((float)(m_maxx-m_minx)/((float)m_nbins))*i+m_minx);
431    }
432 <  
432 >
433    TH1F *histo = this->Draw(m_histoname,m_var, binning, m_xlabel, m_ylabel, Cut, m_is_data, luminosity, onlyindex,drawsignal);
434    return histo;
435    }
# Line 543 | Line 561 | TLegend* samplecollection::allbglegend(s
561   //  TLegend *leg = new TLegend(0.65,0.60,0.89,0.77);
562    TLegend *leg = new TLegend(posx,posy,0.89,0.89);
563    if(title!="") leg->SetHeader(title.c_str());
564 <  if(data->GetName()!="nothing") leg->AddEntry(data,"Data","p");
564 >  if(data->GetName()!="nothing") leg->AddEntry(data,"Data","lp");
565    leg->SetFillColor(kWhite);
566    leg->SetBorderSize(0);
567    leg->SetLineColor(kWhite);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines