Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:41

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 
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))
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       : varX_(std::move(funcX)),
0072         varY_(std::move(funcY)),
0073         varNameX_(std::move(varNameX)),
0074         varNameY_(std::move(varNameY)),
0075         hist_(hist) {}
0076 
0077   void fill(const HLTGenValObject& obj) override { hist_->Fill(varX_(obj), varY_(obj)); }
0078 
0079 private:
0080   std::function<float(const HLTGenValObject&)> varX_;
0081   std::function<float(const HLTGenValObject&)> varY_;
0082   std::string varNameX_;
0083   std::string varNameY_;
0084   TH2* hist_;  //we do not own this
0085 };
0086 
0087 #endif