3 |
|
PUWeight::PUWeight (const string &puFile, const string &dataPU, const string &mcPU) |
4 |
|
{ |
5 |
|
TFile *fin = TFile::Open (puFile.c_str ()); |
6 |
< |
TH1D *mc = (TH1D *) fin->Get (mcPU.c_str ()); |
7 |
< |
puWeight_ = (TH1D *) fin->Get (dataPU.c_str ()); |
6 |
> |
if (!fin || fin->IsZombie()) { |
7 |
> |
cout << "ERROR [PUWeight]: Could not find file: " << puFile |
8 |
> |
<< "; will cause a seg fault." << endl; |
9 |
> |
exit(1); |
10 |
> |
} |
11 |
> |
|
12 |
> |
TH1D *mc; |
13 |
> |
fin->GetObject(mcPU.c_str(), mc); |
14 |
> |
fin->GetObject(dataPU.c_str(), puWeight_); |
15 |
> |
if (!mc) { |
16 |
> |
cout << "ERROR [PUWeight]: Could not find histogram: " << mcPU |
17 |
> |
<< "; will cause a seg fault." << endl; |
18 |
> |
exit(1); |
19 |
> |
} |
20 |
> |
if (!puWeight_) { |
21 |
> |
cout << "ERROR [PUWeight]: Could not find histogram: " << dataPU |
22 |
> |
<< "; will cause a seg fault." << endl; |
23 |
> |
exit(1); |
24 |
> |
} |
25 |
> |
|
26 |
|
mc->SetDirectory (0); |
27 |
|
puWeight_->SetDirectory (0); |
28 |
|
mc->Scale (puWeight_->Integral () / mc->Integral ()); |
29 |
< |
puWeight_->Divide (mc); |
29 |
> |
TH1D *trimmedMC = new TH1D ("bla", "bla", puWeight_->GetNbinsX(), 0, puWeight_->GetNbinsX()); |
30 |
> |
for (int bin = 1; bin <= puWeight_->GetNbinsX(); bin++) |
31 |
> |
trimmedMC->SetBinContent (bin, mc->GetBinContent (bin)); |
32 |
> |
puWeight_->Divide (trimmedMC); |
33 |
|
fin->Close (); |
34 |
|
delete mc; |
35 |
|
} |
36 |
< |
|
36 |
> |
|
37 |
|
PUWeight::~PUWeight () |
38 |
|
{ |
39 |
|
delete puWeight_; |