TIMBER  beta
Tree Interface for Making Binned Events with RDataFrame
WeightCalculatorFromHistogram.h
1 //https://raw.githubusercontent.com/cms-nanoAOD/nanoAOD-tools/master/interface/WeightCalculatorFromHistogram.h
2 #ifndef PhysicsTools_NanoAODTools_WeightCalculatorFromHistogram_h
3 #define PhysicsTools_NanoAODTools_WeightCalculatorFromHistogram_h
4 
5 #include <iostream>
6 #include <iomanip>
7 #include <vector>
8 #include <algorithm>
9 #include <TH1.h>
10 
12  public:
14  // get the weight from the bin content of the passed histogram
15  WeightCalculatorFromHistogram(TH1 *histogram, bool verbose=false) : histogram_(histogram), verbose_(verbose) {}
16  // get the weight from the bin content of the ratio hist/targethist
17  WeightCalculatorFromHistogram(TH1 *hist, TH1* targethist, bool norm=true, bool fixLargeWeights=true, bool verbose=false);
19 
20  float getWeight(float x, float y=0) const;
21  float getWeightErr(float x, float y=0) const;
22 
23  private:
24  std::vector<float> loadVals(TH1 *hist, bool norm=true);
25  TH1* ratio(TH1 *hist, TH1* targethist, bool fixLargeWgts);
26  void fixLargeWeights(std::vector<float> &weights, float maxshift=0.0025,float hardmax=3);
27  float checkIntegral(std::vector<float> wgt1, std::vector<float> wgt2);
28 
29  TH1* histogram_;
30  std::vector<float> refvals_,targetvals_;
31  bool verbose_;
32  bool norm_;
33 };
34 
35 #endif
Definition: WeightCalculatorFromHistogram.h:11