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.3 by buchmann, Wed Apr 18 09:21:03 2012 UTC vs.
Revision 1.7 by buchmann, Wed May 23 15:13:17 2012 UTC

# Line 87 | Line 87 | sample::sample(string m_filename, string
87      gErrorIgnoreLevel=currlevel;
88      this->events=(TTree*)(this->tfile)->Get(treename.c_str());
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();
90 >    long long measured_nevents=(long)1;
91 >    TH1F *weight_histo = (TH1F*)(this->tfile)->Get("weight_histo");
92 >    float average_weight = 1.0;
93 >    if(weight_histo) {
94 >      average_weight = weight_histo->Integral()/weight_histo->GetEntries();
95 >      measured_nevents = (long)weight_histo->GetEntries();
96 >    } else {
97 >      measured_nevents=(this->events)->GetEntries();
98 >    }
99 >
100      if(((this->Nentries>1)||(this->Nentries==0))&measured_nevents!=this->Nentries) {
101        //special cases: m_Nentries=1 : we want to give each event the full weight (->scans!)
102        //               m_Nentries=0: detect the number of events and set the nevents automatically
# Line 98 | Line 107 | sample::sample(string m_filename, string
107        this->Nentries=measured_nevents;
108      }
109      this->weight=(xs/(float)Nentries);
110 +    TH1F *weight_histo = (TH1F*)(this->tfile)->Get("weight_histo");
111 +    this->weight/=average_weight;
112    }
113    else {
114      this->is_active=false;
# Line 197 | Line 208 | void samplecollection::ListSamples()
208    dout << "Listing all " << this->nsamples << " sample(s) of the sample collection called " << this->name << " : " << endl;
209    if(this->ndatasamples>0) {
210      dout << "Data sample(s): " << endl;
211 <    for (int isamp=0;isamp<this->collection.size();isamp++)
211 >    for (int isamp=0;isamp<(int)this->collection.size();isamp++)
212        {
213          if((this->collection)[isamp].is_data) dout << " - " << (this->collection)[isamp].samplename << " from " << (this->collection)[isamp].filename << endl;
214        }
215    }
216    if(this->nmcsamples>0) {
217      dout << "MC sample(s): " << endl;
218 <    for (int isamp=0;isamp<this->collection.size();isamp++)
218 >    for (int isamp=0;isamp<(int)this->collection.size();isamp++)
219        {
220          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;
221        }
# Line 231 | Line 242 | void samplecollection::AddSample(string
242   bool samplecollection::do_sample(int thissample, vector<int> &selected_samples)
243   {
244    bool drawit=false;
245 <  for(int isel=0;isel<selected_samples.size();isel++)
245 >  for(int isel=0;isel<(int)selected_samples.size();isel++)
246    {
247      if(selected_samples[isel]==thissample) {
248        drawit=true;
# Line 263 | Line 274 | TH1F* samplecollection::Draw(string m_hi
274    bool do_only_selected_samples=false;
275    if(onlyindex.size()>0&&onlyindex[0]!=-1) {
276      if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;}
277 <    for(int is=0;is<onlyindex.size();is++) {
277 >    for(int is=0;is<(int)onlyindex.size();is++) {
278        if(Verbosity>0) dout << "   - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl;
279      }
280      do_only_selected_samples=true;
# Line 275 | Line 286 | TH1F* samplecollection::Draw(string m_hi
286    stringstream h_histoname;
287    h_histoname<<"h_"<<m_histoname;
288    float binningarray[binning.size()+1];
289 <  for(int i=0;i<binning.size();i++) {binningarray[i]=binning[i];}
289 >  for(int i=0;i<(int)binning.size();i++) {binningarray[i]=binning[i];}
290    TH1F *histo = new TH1F(m_histoname.c_str(),"",binning.size()-1,binningarray);
291    histo->Sumw2();
292    
# Line 335 | Line 346 | TH2F* samplecollection::Draw(string m_hi
346    bool do_only_selected_samples=false;
347    if(onlyindex.size()>0&&onlyindex[0]!=-1) {
348      if(Verbosity>0) {dout << "Requested to only draw sample corresponding to the following sample(s) : " << endl;}
349 <    for(int is=0;is<onlyindex.size();is++) {
349 >    for(int is=0;is<(int)onlyindex.size();is++) {
350        if(Verbosity>0) dout << "   - " << (this->collection)[onlyindex[is]].filename << " (sample index: " << onlyindex[is] << ")" << endl;
351      }
352      do_only_selected_samples=true;
# Line 348 | Line 359 | TH2F* samplecollection::Draw(string m_hi
359    h_histoname<<"h_"<<m_histoname;
360    float binningarray[binningx.size()+1];
361    float binningyarray[binningy.size()+1];
362 <  for(int i=0;i<binningx.size();i++) {binningarray[i]=binningx[i];binningyarray[i]=binningy[i];}
362 >  for(int i=0;i<(int)binningx.size();i++) {binningarray[i]=binningx[i];binningyarray[i]=binningy[i];}
363    TH2F *histo = new TH2F(m_histoname.c_str(),"",binningx.size()-1,binningarray,binningy.size(),binningyarray);
364    histo->Sumw2();
365    
# Line 418 | Line 429 | THStack samplecollection::DrawStack(stri
429    for(int ih=0;ih<=this->ngroups;ih++) bookedhistos[ih]=0;
430    
431    float binningarray[binning.size()+1];
432 <  for(int i=0;i<binning.size();i++) {binningarray[i]=binning[i];}
432 >  for(int i=0;i<(int)binning.size();i++) {binningarray[i]=binning[i];}
433    
434    for (unsigned int isample=0;isample<(this->collection).size();isample++) {
435      if(!drawsignal&&(this->collection)[isample].is_signal) continue;
# Line 437 | Line 448 | THStack samplecollection::DrawStack(stri
448        if(!(this->collection)[isample].is_data) tempdrawhisto->Scale(luminosity*((this->collection)[isample].weight));
449        tempdrawhisto->SetFillColor(this->GetColor(isample));
450        if(bookedhistos[(this->collection)[isample].groupindex]==0) {
451 <        tempdrawhisto->SetName(GetNumericHistoName().c_str());
451 >        tempdrawhisto->SetName((removefunnystring((this->collection)[isample].samplename)+"__"+GetNumericHistoName()).c_str());
452          histogroups[(this->collection)[isample].groupindex]=(TH1F*)tempdrawhisto->Clone();
453          bookedhistos[(this->collection)[isample].groupindex]=1;
454        }
# Line 466 | Line 477 | THStack samplecollection::DrawStack(stri
477      thestack.Add(histogroups[ordered_indices[index]]);
478    }
479    */
480 <  for(int index=0;index<ordered_indices.size();index++) {
480 >  for(int index=0;index<(int)ordered_indices.size();index++) {
481      thestack.Add(histogroups[ordered_indices[index]]);
482    }
483    return thestack;
# Line 539 | Line 550 | TLegend* samplecollection::allbglegend(s
550    
551    TH1F *fakehistos[(this->collection).size()];
552    bool donealready[(this->collection).size()];
553 <  for(int i=0;i<(this->collection).size();i++) donealready[i]=false;
554 <  for(int isample=0;isample<(this->collection).size();isample++) {
553 >  for(int i=0;i<(int)(this->collection).size();i++) donealready[i]=false;
554 >  for(int isample=0;isample<(int)(this->collection).size();isample++) {
555      if((this->collection)[isample].is_data||(this->collection)[isample].is_signal) continue;
556  
557      if(!donealready[(this->collection)[isample].groupindex]) {
# Line 623 | Line 634 | void samplecollection::PickUpFromThisFil
634   void samplecollection::PickUpEvents(string cut) {
635    vector<string> output;
636    vector<string> pickupfile;
637 <  for (int isamp=0;isamp<this->collection.size();isamp++)
637 >  for (int isamp=0;isamp<(int)this->collection.size();isamp++)
638    {
639      if((this->collection)[isamp].is_data) {
640        //we have a data sample !

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines