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 |
|
|
}
|