TIMBER  beta
Tree Interface for Making Binned Events with RDataFrame
JES_weight.h
1 #ifndef _TIMBER_JES_WEIGHT
2 #define _TIMBER_JES_WEIGHT
3 // Requires CMSSW
4 #include <string>
5 #include <vector>
6 #include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
7 #include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h"
8 #include "CondFormats/JetMETObjects/interface/JetCorrectionUncertainty.h"
9 #include <ROOT/RVec.hxx>
10 #include "JetRecalibrator.h"
11 #include "common.h"
12 
13 using namespace ROOT::VecOps;
17 class JES_weight {
18  private:
19  const std::string _jecTag, _jetType, _uncertType;
20  const bool _redoJECs;
21  JetRecalibrator _jetRecalib;
22  bool check_type_exists();
23  std::vector<std::string> get_sources();
24 
25  public:
37  JES_weight(str jecTag, str jetType, str uncertType = "", bool redoJECs=false);
38  ~JES_weight(){};
56  template <class T>
57  RVec< RVec<float> > eval(std::vector<T> jets, float fixedGridRhoFastjetAll){
58  RVec< RVec<float> > out (jets.size());
59 
60  for (size_t ijet = 0; ijet < jets.size(); ijet++) {
61  RVec<float> ijet_out {1.0, 1.0, 1.0};
62 
63  if (_redoJECs) {
64  _jetRecalib.CalculateCorrection(jets[ijet], fixedGridRhoFastjetAll);
65  _jetRecalib.CalculateUncertainty(jets[ijet]);
66 
67  ijet_out[0] = _jetRecalib.GetCorrection();
68  ijet_out[1] = _jetRecalib.GetCorrection()*(1+_jetRecalib.GetUncertainty());
69  ijet_out[2] = _jetRecalib.GetCorrection()*(1-_jetRecalib.GetUncertainty());
70  } else {
71  _jetRecalib.CalculateUncertainty(jets[ijet], fixedGridRhoFastjetAll);
72  ijet_out[1] = 1+_jetRecalib.GetUncertainty();
73  ijet_out[2] = 1-_jetRecalib.GetUncertainty();
74  }
75  out[ijet] = ijet_out;
76  }
77  return out;
78  };
79 };
80 #endif
void CalculateUncertainty(T jet, float delta=1)
Calculate the correction uncertainty for a given jet and store the value internally. WARNING: CalculateCorrection must be run first.
Definition: JetRecalibrator.h:88
C++ class to handle the JES/JEC weight calculations.
Definition: JES_weight.h:17
float GetCorrection()
Return the internally stored correction value that was calculated during CalculateCorrection.
Definition: JetRecalibrator.h:105
RVec< RVec< float > > eval(std::vector< T > jets, float fixedGridRhoFastjetAll)
If redoJECs is true, evaluation calculates the weight necessary to uncorrect and recorrect the jet en...
Definition: JES_weight.h:57
C++ class to recalibrate the of jets. Initialized with basic parameters and calculations done on vec...
Definition: JetRecalibrator.h:23
void CalculateCorrection(T jet, float fixedGridRhoFastjetAll)
Calculate the correction for a given jet and rho and store the value internally.
Definition: JetRecalibrator.h:71
float GetUncertainty()
Return the internally stored uncertainty value that was calculated during CalculateUncertainty.
Definition: JetRecalibrator.h:112