This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| users:ngadiuba:tools:puweightrecipe:puweighth [2014/04/15 14:31] – ngadiuba | users:ngadiuba:tools:puweightrecipe:puweighth [2014/04/15 14:34] (current) – ngadiuba | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | #include " | + | |
| - | #include " | + | #define PUWeight_H |
| - | #include < | + | |
| - | // | + | #include <string> |
| - | // Get MC pile-up scenario from string | + | # |
| - | PUWeight:: | + | |
| - | | + | |
| - | if( str == " | + | |
| - | else { | + | |
| - | | + | |
| - | throw std:: | + | |
| - | } | + | |
| - | | + | #include " |
| - | } | + | # |
| - | //============================================================================================== | + | |
| - | // MC pile-up | + | |
| - | std:: | + | |
| - | std::string str; | + | enum Scenario { Summer12S10 |
| - | if( sc == Summer12S10 | + | |
| - | else { | + | |
| - | | + | |
| - | throw std:: | + | |
| - | } | + | |
| - | | + | static Scenario toScenario(const std:: |
| - | } | + | |
| - | // | + | |
| - | // Constructor. Initializes default behaviour to return PU weight of 1 | + | PUWeight(); |
| - | | + | |
| - | : isInit_(false), | + | |
| - | // | + | |
| - | // Initialise weights for a given MC pile-up scenario. Can only be | + | // called once. |
| - | | + | void initPUWeights(const TString& |
| - | | + | initPUWeights( std:: |
| + | } | ||
| + | void initPUWeights(const std:: | ||
| - | if( isInit_ ) { | + | // Get weight factor dependent on number of added PU interactions |
| - | std::cerr << " | + | // nPU is the ' |
| - | throw std:: | + | // https:// |
| - | } | + | |
| - | // Get data distribution from file | ||
| - | TFile file(nameOfDataDistribution.c_str(), | ||
| - | TH1* h = NULL; | ||
| - | | ||
| - | if( h == NULL ) { | ||
| - | | ||
| - | throw std:: | ||
| - | } | ||
| - | | ||
| - | | ||
| - | // Computing weights | + | |
| - | | + | bool isInit_; |
| - | | + | |
| + | std:: | ||
| - | // Clean up | + | |
| - | delete h; | + | std:: |
| + | }; | ||
| - | | + | |
| - | } | + | |
| - | + | ||
| - | // | + | |
| - | // Get weight factor dependent on number of added PU interactions | + | |
| - | | + | |
| - | | + | |
| - | 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); | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | | + | |
| - | } | + | |
| - | + | ||
| - | // | + | |
| - | // Generate weights for given data PU distribution | + | |
| - | // Scenarios from: https:// | + | |
| - | // Code adapted from: https:// | + | |
| - | | + | |
| - | + | ||
| - | // Store probabilites for each pu bin | + | |
| - | | + | |
| - | | + | |
| - | + | ||
| - | if( sc == Summer12S10 ) { | + | |
| - | | + | |
| - | | + | |
| - | 2.560E-06, | + | |
| - | 5.239E-06, | + | |
| - | 1.420E-05, | + | |
| - | 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}; | + | |
| - | | + | |
| - | } | + | |
| - | + | ||
| - | // Check that binning of data-profile matches MC scenario | + | |
| - | if( nPUMax != static_cast< | + | |
| - | | + | |
| - | throw std:: | + | |
| - | } | + | |
| - | + | ||
| - | | + | |
| - | | + | |
| - | | + | |
| - | const double npu_estimated = data_npu_estimated-> | + | |
| - | | + | |
| - | s += npu_estimated; | + | |
| - | } | + | |
| - | // normalize weights such that the total sum of weights over thw whole sample is 1.0, i.e., sum_i result[i] * npu_probs[i] should be 1.0 (!) | + | |
| - | | + | |
| - | | + | |
| - | } | + | |
| - | + | ||
| - | | + | |
| - | } | + | |