This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| users:ngadiuba:tools:puweightrecipe:puweighth [2014/04/15 14:27] – created ngadiuba | users:ngadiuba:tools:puweightrecipe:puweighth [2014/04/15 14:34] (current) – ngadiuba | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | # | + | #ifndef PUWeight_H |
| - | + | #define PUWeight_H | |
| - | #include "TFile.h" | + | |
| - | + | | |
| - | # | + | #include |
| - | + | | |
| - | //============================================================================================== | + | #include "TH1.h" |
| - | // Get MC pile-up | + | # |
| - | PUWeight::Scenario PUWeight:: | + | |
| - | | + | // Compute |
| - | if( str == " | + | |
| - | else { | + | |
| - | | + | enum Scenario |
| - | throw std:: | + | |
| - | } | + | static Scenario toScenario(const std::string& |
| - | + | | |
| - | return sc; | + | |
| - | } | + | // Constructor. Initializes default behaviour to return PU weight of 1 |
| - | + | PUWeight(); | |
| - | // | + | |
| - | // MC pile-up scenario to string representation | + | // Initialise weights for a given MC pile-up scenario. Can only be |
| - | std:: | + | // called once. |
| - | std::string str; | + | void initPUWeights(const |
| - | if( sc == Summer12S10 ) str = " | + | |
| - | else { | + | } |
| - | std::cerr << " | + | void initPUWeights(const std::string& nameOfDataDistribution, |
| - | throw std:: | + | |
| - | } | + | // Get weight factor dependent on number of added PU interactions |
| - | + | // nPU is the ' | |
| - | return str; | + | // https:// |
| - | } | + | double |
| - | + | | |
| - | // | + | |
| - | // Constructor. Initializes default behaviour to return PU weight of 1 | + | |
| - | PUWeight::PUWeight() | + | |
| - | : isInit_(false), | + | |
| - | + | std::vector<double> puWeigths_; | |
| - | // | + | |
| - | // Initialise weights for a given MC pile-up scenario. Can only be | + | // Generate weights for given data PU distribution |
| - | // called once. | + | std:: |
| - | void PUWeight::initPUWeights(const | + | |
| - | + | ||
| - | if( isInit_ ) { | + | |
| - | | + | |
| - | throw std:: | + | |
| - | } | + | |
| - | + | ||
| - | // Get data distribution from file | + | |
| - | TFile file(nameOfDataDistribution.c_str(), " | + | |
| - | TH1* h = NULL; | + | |
| - | | + | |
| - | if( h == NULL ) { | + | |
| - | | + | |
| - | throw std:: | + | |
| - | } | + | |
| - | h-> | + | |
| - | file.Close(); | + | |
| - | + | ||
| - | // Computing weights | + | |
| - | puWeigths_ = generateWeights(sc,h); | + | |
| - | | + | |
| - | + | ||
| - | // Clean up | + | |
| - | delete h; | + | |
| - | + | ||
| - | isInit_ = true; | + | |
| - | } | + | |
| - | + | ||
| - | // | + | |
| - | // Get weight factor dependent on number of added PU interactions | + | |
| - | double PUWeight:: | + | |
| - | double w = 1.; | + | |
| - | if( isInit_ ) { | + | |
| - | if( nPU >= nPUMax_ ) { | + | |
| - | //std::cerr << " | + | |
| - | // In case nPU is out-of data-profile binning, | + | |
| - | // use weight from last bin | + | |
| - | w = puWeigths_.back(); | + | |
| - | } else { | + | |
| - | w = puWeigths_.at(nPU); | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | return w; | + | |
| - | } | + | |
| - | + | ||
| - | // | + | |
| - | // Generate weights for given data PU distribution | + | |
| - | // Scenarios from: https:// | + | |
| - | // Code adapted from: https:// | + | |
| - | std:: | + | |
| - | + | ||
| - | // Store probabilites for each pu bin | + | |
| - | unsigned int nPUMax = 0; | + | |
| - | | + | |
| - | + | ||
| - | if( sc == Summer12S10 ) { | + | |
| - | | + | |
| - | double npuSummer12_S10[60] = { | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | 5.005E-05, | + | |
| - | 1.001E-04, | + | |
| - | 2.705E-04, | + | |
| - | 1.999E-03, | + | |
| - | 6.097E-03, | + | |
| - | 1.046E-02, | + | |
| - | 1.383E-02, | + | |
| - | 1.685E-02, | + | |
| - | 2.055E-02, | + | |
| - | 2.572E-02, | + | |
| - | 3.262E-02, | + | |
| - | 4.121E-02, | + | |
| - | 4.977E-02, | + | |
| - | 5.539E-02, | + | |
| - | 5.725E-02, | + | |
| - | 5.607E-02, | + | |
| - | 5.312E-02, | + | |
| - | 5.008E-02, | + | |
| - | 4.763E-02, | + | |
| - | 4.558E-02, | + | |
| - | 4.363E-02, | + | |
| - | 4.159E-02, | + | |
| - | 3.933E-02, | + | |
| - | 3.681E-02, | + | |
| - | 3.406E-02, | + | |
| - | 3.116E-02, | + | |
| - | 2.818E-02, | + | |
| - | 2.519E-02, | + | |
| - | 2.226E-02, | + | |
| - | 1.946E-02, | + | |
| - | 1.682E-02, | + | |
| - | 1.437E-02, | + | |
| - | 1.215E-02, | + | |
| - | 1.016E-02, | + | |
| - | 8.400E-03, | + | |
| - | 6.873E-03, | + | |
| - | 5.564E-03, | + | |
| - | 4.457E-03, | + | |
| - | 3.533E-03, | + | |
| - | 2.772E-03, | + | |
| - | 2.154E-03, | + | |
| - | 1.656E-03, | + | |
| - | 1.261E-03, | + | |
| - | 9.513E-04, | + | |
| - | 7.107E-04, | + | |
| - | 5.259E-04, | + | |
| - | 3.856E-04, | + | |
| - | 2.801E-04, | + | |
| - | 2.017E-04, | + | |
| - | 1.439E-04, | + | |
| - | 1.017E-04, | + | |
| - | 7.126E-05, | + | |
| - | 4.948E-05, | + | |
| - | 3.405E-05, | + | |
| - | 2.322E-05, | + | |
| - | 1.570E-05, | + | |
| - | 5.005E-06}; | + | |
| - | npuProbs = npuSummer12_S10; | + | |
| - | } | + | |
| - | + | ||
| - | // Check that binning of data-profile matches MC scenario | + | |
| - | if( nPUMax != static_cast< | + | |
| - | | + | |
| - | throw std:: | + | |
| - | } | + | |
| - | + | ||
| - | | + | |
| - | double s = 0.; | + | |
| - | for(unsigned int npu = 0; npu < nPUMax; ++npu) { | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | } | + | |
| - | | + | |
| - | for(unsigned int npu = 0; npu < nPUMax; ++npu) { | + | |
| - | result[npu] /= s; | + | |
| - | } | + | |
| - | + | ||
| - | return result; | + | |
| - | } | + | |
| - | + | ||