00001 #ifndef HZZ2L2NU_INCLUDE_JETCORRECTOR_H_
00002 #define HZZ2L2NU_INCLUDE_JETCORRECTOR_H_
00003
00004 #include <array>
00005 #include <filesystem>
00006 #include <memory>
00007 #include <vector>
00008
00009 #include <TLorentzVector.h>
00010 #include <TTreeReaderValue.h>
00011
00012 #include <Dataset.h>
00013 #include <Options.h>
00014 #include <PhysicsObjects.h>
00015 #include <TabulatedRandomGenerator.h>
00016
00017
00018
00019
00020 class FactorizedJetCorrector;
00021 class JetCorrectionUncertainty;
00022
00023 namespace JME {
00024 class JetResolution;
00025 class JetResolutionScaleFactor;
00026 }
00027
00028
00039 class JetCorrector {
00040 public:
00041 JetCorrector(Dataset &dataset, Options const &options,
00042 TabulatedRngEngine &rngEngine);
00043 ~JetCorrector() noexcept;
00044
00051 double GetJecFull(TLorentzVector const &rawP4, double area) const;
00052
00059 double GetJecL1(TLorentzVector const &rawP4, double area) const;
00060
00069 double GetJecUncFactor(TLorentzVector const &corrP4) const;
00070
00091 double GetJerFactor(TLorentzVector const &corrP4, GenJet const *genJet,
00092 double ptResultion, int rngChannel) const;
00093
00100 double GetPtResolution(TLorentzVector const &corrP4) const;
00101
00108 void UpdateIov() const;
00109
00110 private:
00112 enum class Syst {
00113 None,
00114 JEC,
00115 JER
00116 };
00117
00119 enum class SystDirection {
00120 Up,
00121 Down
00122 };
00123
00125 using run_t = uint64_t;
00126
00128 struct IovParams {
00130 bool Contains(run_t run) const {
00131 return run >= runRange[0] and run <= runRange[1];
00132 }
00133
00139 std::array<run_t, 2> runRange;
00140
00142 std::vector<std::filesystem::path> jecLevels;
00143 };
00144
00156 double ClipFactor(double factor, double pt) const;
00157
00159 void LoadJec() const;
00160
00171 void ReadIovParams(YAML::Node const config);
00172
00174 Syst syst_;
00175
00177 SystDirection systDirection_;
00178
00180 std::vector<IovParams> iovs_;
00181
00183 double minPtClip_;
00184
00186 mutable IovParams const *currentIov_;
00187
00189 mutable run_t cachedRun_;
00190
00197 mutable std::unique_ptr<FactorizedJetCorrector> jetEnergyCorrector_;
00198
00205 std::unique_ptr<JetCorrectionUncertainty> jecUncProvider_;
00206
00212 std::unique_ptr<JME::JetResolution> jerProvider_;
00213
00220 std::unique_ptr<JME::JetResolutionScaleFactor> jerSFProvider_;
00221
00223 TabulatedRandomGenerator tabulatedRng_;
00224
00226 mutable TTreeReaderValue<UInt_t> run_;
00227
00229 mutable TTreeReaderValue<float> rho_;
00230 };
00231
00232 #endif // HZZ2L2NU_INCLUDE_JETCORRECTOR_H_