ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/UHHAnalysis/SFrameTools/src/PUWeightProducer.cxx
Revision: 1.2
Committed: Wed Aug 22 15:29:26 2012 UTC (12 years, 8 months ago) by peiffer
Content type: text/plain
Branch: MAIN
CVS Tags: Makefile, v1-00, Feb-15-2013-v1, Feb-14-2013, Feb-07-2013-v1, Jan-17-2013-v2, Jan-17-2013-v1, Jan-16-2012-v1, Jan-09-2012-v2, Jan-09-2012-v1, Dec-26-2012-v1, Dec-20-2012-v1, Dec-17-2012-v1, Nov-30-2012-v2, Nov-30-2012-v1, HEAD
Changes since 1.1: +2 -2 lines
Log Message:
bugfix in PU re-weighting

File Contents

# User Rev Content
1 peiffer 1.1 #include "../include/PUWeightProducer.h"
2    
3    
4     PUWeightProducer::PUWeightProducer(TString filename_mc, TString filename_data, TString histname_mc, TString histname_data){
5    
6     TFile *file_mc = new TFile(filename_mc);
7     TFile *file_data = new TFile(filename_data);
8    
9     h_npu_mc=(TH1F*) file_mc->Get(histname_mc);
10     h_npu_data=(TH1F*) file_data->Get(histname_data);
11    
12    
13     if(h_npu_mc->GetNbinsX() != h_npu_data->GetNbinsX()){
14     std::cerr << "ERROR: pile-up histograms for data and MC have different numbers of bins" <<std::endl;
15     exit(-1);
16     }
17     if( (h_npu_mc->GetXaxis()->GetXmax() != h_npu_data->GetXaxis()->GetXmax()) || (h_npu_mc->GetXaxis()->GetXmin() != h_npu_data->GetXaxis()->GetXmin())){
18     std::cerr << "ERROR: pile-up histograms for data and MC have different axis ranges" <<std::endl;
19     exit(-1);
20     }
21    
22     h_npu_mc->Scale(1./h_npu_mc->Integral());
23     h_npu_data->Scale(1./h_npu_data->Integral());
24    
25    
26     }
27    
28     double PUWeightProducer::produceWeight(GenInfo* genInfo){
29    
30     double weight =0;
31    
32     int binnumber = h_npu_mc->GetXaxis()->FindBin(genInfo->pileup_TrueNumInteractions());
33    
34 peiffer 1.2 if(h_npu_mc->GetBinContent(binnumber)!=0){
35 peiffer 1.1
36 peiffer 1.2 weight = h_npu_data->GetBinContent(binnumber)/h_npu_mc->GetBinContent(binnumber);
37 peiffer 1.1
38     }
39    
40     return weight;
41     }