ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/src/PUWeight.cc
Revision: 1.4
Committed: Wed Mar 20 16:13:08 2013 UTC (12 years, 1 month ago) by wulsin
Content type: text/plain
Branch: MAIN
CVS Tags: V02-03-02, V02-03-01, V02-03-00, V02-02-00, V02-01-01, V02-01-00, V01-01-00, V01-00-01, V01-00-00, V00-01-00, HEAD
Changes since 1.3: +21 -3 lines
Log Message:
Added error protection, in case the file cannot be opened or the histograms cannot be found.

File Contents

# User Rev Content
1 ahart 1.1 #include "OSUT3Analysis/AnaTools/interface/PUWeight.h"
2    
3     PUWeight::PUWeight (const string &puFile, const string &dataPU, const string &mcPU)
4     {
5     TFile *fin = TFile::Open (puFile.c_str ());
6 wulsin 1.4 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 ahart 1.1 mc->SetDirectory (0);
27     puWeight_->SetDirectory (0);
28     mc->Scale (puWeight_->Integral () / mc->Integral ());
29 ahart 1.3 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 lantonel 1.2 puWeight_->Divide (trimmedMC);
33 ahart 1.1 fin->Close ();
34     delete mc;
35     }
36 wulsin 1.4
37 ahart 1.1 PUWeight::~PUWeight ()
38     {
39     delete puWeight_;
40     }