Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-13 02:58:34

0001 #ifndef Validation_HLTrigger_HLTGenValHist_h
0002 #define Validation_HLTrigger_HLTGenValHist_h
0003 
0004 //********************************************************************************
0005 //
0006 // Description:
0007 //   Histogram holder class for the GEN-level HLT validation
0008 //   Handling and filling of 1D and 2D histograms is done by this class.
0009 //
0010 //
0011 // Author : Finn Labe, UHH, Jul. 2022
0012 //          (Strongly inspired by Sam Harpers HLTDQMHist class)
0013 //
0014 //***********************************************************************************
0015 
0016 #include "DQMOffline/Trigger/interface/FunctionDefs.h"
0017 
0018 #include "DQMOffline/Trigger/interface/VarRangeCutColl.h"
0019 
0020 #include "FWCore/Framework/interface/Event.h"
0021 
0022 #include "Validation/HLTrigger/interface/HLTGenValObject.h"
0023 
0024 #include <TH1.h>
0025 #include <TH2.h>
0026 #include <TProfile.h>
0027 // base histogram class, with specific implementations following below
0028 class HLTGenValHist {
0029 public:
0030   HLTGenValHist() = default;
0031   virtual ~HLTGenValHist() = default;
0032   virtual void fill(const HLTGenValObject& objType) = 0;
0033 };
0034 
0035 // specific implimentation of a HLTGenValHist for 1D histograms
0036 // it takes the histogram which it will fill
0037 // it takes the variable to plot (func) and its name (varName)
0038 // also, it takes additional cuts (rangeCuts) applied before filling
0039 // to fill the histogram, an object is passed in the Fill function
0040 class HLTGenValHist1D : public HLTGenValHist {
0041 public:
0042   HLTGenValHist1D(TH1* hist,
0043                   std::string varName,
0044                   std::function<float(const HLTGenValObject&)> func,
0045                   VarRangeCutColl<HLTGenValObject> rangeCuts)
0046       : var_(std::move(func)), varName_(std::move(varName)), rangeCuts_(std::move(rangeCuts)), hist_(hist) {}
0047 
0048   void fill(const HLTGenValObject& obj) override {
0049     if (rangeCuts_(obj, varName_))
0050       hist_->Fill(var_(obj));
0051   }
0052 
0053 private:
0054   std::function<float(const HLTGenValObject&)> var_;
0055   std::string varName_;
0056   VarRangeCutColl<HLTGenValObject> rangeCuts_;
0057   TH1* hist_;  //we do not own this
0058 };
0059 
0060 // specific implimentation of a HLTGenValHist for 2D histograms
0061 // it takes the histogram which it will fill
0062 // it takes the two variable to plot (func) and their name (varName)
0063 // to fill the histogram, two objects are passed in the Fill function
0064 class HLTGenValHist2D : public HLTGenValHist {
0065 public:
0066   HLTGenValHist2D(TH2* hist,
0067                   std::string varNameX,
0068                   std::string varNameY,
0069                   std::function<float(const HLTGenValObject&)> funcX,
0070                   std::function<float(const HLTGenValObject&)> funcY,
0071                   VarRangeCutColl<HLTGenValObject> rangeCuts = VarRangeCutColl<HLTGenValObject>())
0072       : varX_(std::move(funcX)),
0073         varY_(std::move(funcY)),
0074         varNameX_(std::move(varNameX)),
0075         varNameY_(std::move(varNameY)),
0076         rangeCuts_(rangeCuts),
0077         hist_(hist),
0078         histProf_(nullptr) {}
0079 
0080   HLTGenValHist2D(TH2* hist,
0081                   TProfile* histProf,
0082                   std::string varNameX,
0083                   std::string varNameY,
0084                   std::function<float(const HLTGenValObject&)> funcX,
0085                   std::function<float(const HLTGenValObject&)> funcY,
0086                   VarRangeCutColl<HLTGenValObject> rangeCuts = VarRangeCutColl<HLTGenValObject>())
0087       : varX_(std::move(funcX)),
0088         varY_(std::move(funcY)),
0089         varNameX_(std::move(varNameX)),
0090         varNameY_(std::move(varNameY)),
0091         rangeCuts_(rangeCuts),
0092         hist_(hist),
0093         histProf_(histProf) {}
0094 
0095   void fill(const HLTGenValObject& obj) override {
0096     if (rangeCuts_(obj, {varNameX_, varNameY_})) {
0097       hist_->Fill(varX_(obj), varY_(obj));
0098       if (histProf_)
0099         histProf_->Fill(varX_(obj), varY_(obj));
0100     }
0101   }
0102 
0103 private:
0104   std::function<float(const HLTGenValObject&)> varX_;
0105   std::function<float(const HLTGenValObject&)> varY_;
0106   std::string varNameX_;
0107   std::string varNameY_;
0108   VarRangeCutColl<HLTGenValObject> rangeCuts_;
0109   TH2* hist_;           //we do not own this
0110   TProfile* histProf_;  //we do not own this
0111 };
0112 
0113 #endif