CMS 3D CMS Logo

HLTGenValHist.h
Go to the documentation of this file.
1 #ifndef Validation_HLTrigger_HLTGenValHist_h
2 #define Validation_HLTrigger_HLTGenValHist_h
3 
4 //********************************************************************************
5 //
6 // Description:
7 // Histogram holder class for the GEN-level HLT validation
8 // Handling and filling of 1D and 2D histograms is done by this class.
9 //
10 //
11 // Author : Finn Labe, UHH, Jul. 2022
12 // (Strongly inspired by Sam Harpers HLTDQMHist class)
13 //
14 //***********************************************************************************
15 
17 
19 
21 
23 
24 #include <TH1.h>
25 #include <TH2.h>
26 
27 // base histogram class, with specific implementations following below
29 public:
30  HLTGenValHist() = default;
31  virtual ~HLTGenValHist() = default;
32  virtual void fill(const HLTGenValObject& objType) = 0;
33 };
34 
35 // specific implimentation of a HLTGenValHist for 1D histograms
36 // it takes the histogram which it will fill
37 // it takes the variable to plot (func) and its name (varName)
38 // also, it takes additional cuts (rangeCuts) applied before filling
39 // to fill the histogram, an object is passed in the Fill function
41 public:
43  std::string varName,
44  std::function<float(const HLTGenValObject&)> func,
46  : var_(std::move(func)), varName_(std::move(varName)), rangeCuts_(std::move(rangeCuts)), hist_(hist) {}
47 
48  void fill(const HLTGenValObject& obj) override {
49  if (rangeCuts_(obj))
50  hist_->Fill(var_(obj));
51  }
52 
53 private:
54  std::function<float(const HLTGenValObject&)> var_;
57  TH1* hist_; //we do not own this
58 };
59 
60 // specific implimentation of a HLTGenValHist for 2D histograms
61 // it takes the histogram which it will fill
62 // it takes the two variable to plot (func) and their name (varName)
63 // to fill the histogram, two objects are passed in the Fill function
65 public:
67  std::string varNameX,
68  std::string varNameY,
69  std::function<float(const HLTGenValObject&)> funcX,
70  std::function<float(const HLTGenValObject&)> funcY)
71  : varX_(std::move(funcX)),
72  varY_(std::move(funcY)),
73  varNameX_(std::move(varNameX)),
74  varNameY_(std::move(varNameY)),
75  hist_(hist) {}
76 
77  void fill(const HLTGenValObject& obj) override { hist_->Fill(varX_(obj), varY_(obj)); }
78 
79 private:
80  std::function<float(const HLTGenValObject&)> varX_;
81  std::function<float(const HLTGenValObject&)> varY_;
84  TH2* hist_; //we do not own this
85 };
86 
87 #endif
virtual ~HLTGenValHist()=default
void fill(const HLTGenValObject &obj) override
Definition: HLTGenValHist.h:48
std::string varNameX_
Definition: HLTGenValHist.h:82
HLTGenValHist()=default
HLTGenValHist1D(TH1 *hist, std::string varName, std::function< float(const HLTGenValObject &)> func, VarRangeCutColl< HLTGenValObject > rangeCuts)
Definition: HLTGenValHist.h:42
std::function< float(const HLTGenValObject &)> var_
Definition: HLTGenValHist.h:54
__shared__ Hist hist
HLTGenValHist2D(TH2 *hist, std::string varNameX, std::string varNameY, std::function< float(const HLTGenValObject &)> funcX, std::function< float(const HLTGenValObject &)> funcY)
Definition: HLTGenValHist.h:66
std::function< float(const HLTGenValObject &)> varY_
Definition: HLTGenValHist.h:81
std::string varName_
Definition: HLTGenValHist.h:55
void fill(const HLTGenValObject &obj) override
Definition: HLTGenValHist.h:77
std::function< float(const HLTGenValObject &)> varX_
Definition: HLTGenValHist.h:80
virtual void fill(const HLTGenValObject &objType)=0
VarRangeCutColl< HLTGenValObject > rangeCuts_
Definition: HLTGenValHist.h:56
def move(src, dest)
Definition: eostools.py:511
std::string varNameY_
Definition: HLTGenValHist.h:83