00001 #ifndef HZZ2L2NU_INCLUDE_PILEUPWEIGHT_H_ 00002 #define HZZ2L2NU_INCLUDE_PILEUPWEIGHT_H_ 00003 00004 #include <array> 00005 #include <filesystem> 00006 #include <memory> 00007 #include <string> 00008 00009 #include <TH1.h> 00010 #include <TTreeReaderValue.h> 00011 00012 #include <Dataset.h> 00013 #include <EventCache.h> 00014 #include <Options.h> 00015 #include <RunSampler.h> 00016 #include <WeightBase.h> 00017 00018 00037 class PileUpWeight : public WeightBase { 00038 public: 00040 PileUpWeight(Dataset &dataset, Options const &options, 00041 RunSampler const *runSampler); 00042 00043 double NominalWeight() const override { 00044 if (cache_.IsUpdated()) 00045 Update(); 00046 return weights_[0]; 00047 } 00048 00049 int NumVariations() const override { 00050 return 2; 00051 } 00052 00054 double operator()() const override { 00055 if (cache_.IsUpdated()) 00056 Update(); 00057 return weights_[defaultWeightIndex_]; 00058 } 00059 00060 double RelWeight(int variation) const override { 00061 if (cache_.IsUpdated()) 00062 Update(); 00063 return weights_[variation + 1] / weights_[0]; 00064 } 00065 00066 std::string_view VariationName(int variation) const override; 00067 00068 private: 00070 struct Era { 00072 int minRun, maxRun; 00073 00082 std::array<std::unique_ptr<TH1>, 3> dataProfiles; 00083 }; 00084 00086 void LoadDataProfiles(std::filesystem::path const &path); 00087 00089 void LoadSimProfile(YAML::Node const &config, std::string const &datasetName); 00090 00092 void Update() const; 00093 00100 std::unique_ptr<TH1> simProfile_; 00101 00108 std::vector<Era> eras_; 00109 00110 EventCache cache_; 00111 00113 RunSampler const *runSampler_; 00114 00120 mutable std::array<double, 3> weights_; 00121 00127 int defaultWeightIndex_; 00128 00130 mutable TTreeReaderValue<float> mu_; 00131 }; 00132 00133 #endif // HZZ2L2NU_INCLUDE_PILEUPWEIGHT_H_