00001 #ifndef HZZ2L2NU_INCLUDE_PILEUPIDWEIGHT_H_ 00002 #define HZZ2L2NU_INCLUDE_PILEUPIDWEIGHT_H_ 00003 00004 #include <WeightBase.h> 00005 00006 #include <array> 00007 #include <memory> 00008 #include <optional> 00009 #include <string_view> 00010 00011 #include <TH2.h> 00012 #include <TTreeReaderValue.h> 00013 00014 #include <Dataset.h> 00015 #include <EventCache.h> 00016 #include <JetBuilder.h> 00017 #include <Options.h> 00018 #include <PhysicsObjects.h> 00019 #include <PileUpIdFilter.h> 00020 #include <XGBoostPredictor.h> 00021 00022 00039 class PileUpIdWeight : public WeightBase { 00040 public: 00050 PileUpIdWeight( 00051 Dataset &dataset, Options const &options, 00052 PileUpIdFilter const *pileUpIdFilter, 00053 JetBuilder const *jetBuilder); 00054 00055 double NominalWeight() const override { 00056 if (cache_.IsUpdated()) 00057 Update(); 00058 return weights_[0]; 00059 } 00060 00061 int NumVariations() const override { 00062 return 4; 00063 } 00064 00065 double operator()() const override { 00066 if (cache_.IsUpdated()) 00067 Update(); 00068 return weights_[int(defaultVariation_)]; 00069 } 00070 00071 double RelWeight(int variation) const override { 00072 if (cache_.IsUpdated()) 00073 Update(); 00074 return weights_[variation + 1] / weights_[0]; 00075 } 00076 00077 std::string_view VariationName(int variation) const override; 00078 00079 private: 00085 enum class Variation : int { 00086 kNominal = 0, 00087 kTagUp = 1, 00088 kTagDown = 2, 00089 kMistagUp = 3, 00090 kMistagDown = 4 00091 }; 00092 00094 struct Context { 00095 Context(Jet::PileUpId wp) 00096 : workingPoint{wp} {} 00097 00099 Jet::PileUpId workingPoint; 00100 00105 std::shared_ptr<TH2> sfMatched, sfUncMatched, sfPileUp, sfUncPileUp; 00106 }; 00107 00112 Context const &FindContext(Jet const &jet) const; 00113 00115 double GetEfficiency(Context const &context, Jet const &jet) const; 00116 00118 double GetScaleFactor( 00119 Context const &context, Jet const &jet, Variation variation) const; 00120 00128 void LoadScaleFactors(YAML::Node const config, int year); 00129 00131 void Update() const; 00132 00133 PileUpIdFilter const *pileUpIdFilter_; 00134 JetBuilder const *jetBuilder_; 00135 00141 std::vector<double> absEtaEdges_; 00142 00144 std::vector<Context> contexts_; 00145 00153 mutable std::array<float, 13> effFeatures_; 00154 00156 std::optional<XGBoostPredictor> effCalc_; 00157 00159 mutable TTreeReaderValue<float> expPileUp_; 00160 00162 Variation defaultVariation_; 00163 00164 EventCache cache_; 00165 00171 mutable std::array<double, 5> weights_; 00172 }; 00173 00174 #endif // HZZ2L2NU_INCLUDE_PILEUPIDWEIGHT_H_ 00175