CMS 3D CMS Logo

HLTDQMHist.h
Go to the documentation of this file.
1 #ifndef DQMOnline_Trigger_HLTDQMHist_h
2 #define DQMOnline_Trigger_HLTDQMHist_h
3 
4 //********************************************************************************
5 //
6 // Description:
7 // A histogram together with the necessary information to fill it when pass an
8 // object and minimal selection cuts. These selection cuts are intended to be
9 // simple selections on kinematic variables. There are two levels of these
10 // selection cuts, global (which apply to all histograms in the group and passed
11 // by the calling function) and local (which are stored with the histogram
12 // and are specific to that histogram. Global selection cuts on the variable being
13 // plotted are ignored, for example Et cuts are removed for turn on plots
14 //
15 // Implimentation:
16 // std::function holds the function which generates the vs variable
17 // the name of the vs variable is also stored so we can determine if we should not apply
18 // a given selection cut
19 // selection is done by VarRangeCutColl
20 //
21 // Author : Sam Harper , RAL, May 2017
22 //
23 //***********************************************************************************
24 
27 
29 
30 #include <TH1.h>
31 #include <TH2.h>
32 
33 //our base class for our histograms
34 //takes an object, edm::Event,edm::EventSetup and fills the histogram
35 //with the predetermined variable (or varaibles)
36 template <typename ObjType>
37 class HLTDQMHist {
38 public:
39  HLTDQMHist() = default;
40  virtual ~HLTDQMHist() = default;
41  virtual void fill(const ObjType& objType,
42  const edm::Event& event,
43  const edm::EventSetup& setup,
45 };
46 
47 //this class is a specific implimentation of a HLTDQMHist
48 //it has the value with which to fill the histogram
49 //and the histogram itself
50 //we do not own the histogram
51 template <typename ObjType, typename ValType>
52 class HLTDQMHist1D : public HLTDQMHist<ObjType> {
53 public:
55  std::string varName,
56  std::function<ValType(const ObjType&)> func,
59 
60  void fill(const ObjType& obj,
61  const edm::Event& event,
62  const edm::EventSetup& setup,
63  const VarRangeCutColl<ObjType>& globalRangeCuts) override {
64  //local range cuts are specific to a histogram so dont ignore variables
65  //like global ones (all local cuts should be approprate to the histogram in question
66  if (globalRangeCuts(obj, varName_) && localRangeCuts_(obj)) {
67  hist_->Fill(var_(obj));
68  }
69  }
70 
71 private:
72  std::function<ValType(const ObjType&)> var_;
75  TH1* hist_; //we do not own this
76 };
77 
78 template <typename ObjType, typename XValType, typename YValType = XValType>
79 class HLTDQMHist2D : public HLTDQMHist<ObjType> {
80 public:
82  std::string xVarName,
83  std::string yVarName,
84  std::function<XValType(const ObjType&)> xFunc,
85  std::function<YValType(const ObjType&)> yFunc,
87  : xVar_(std::move(xFunc)),
88  yVar_(std::move(yFunc)),
89  xVarName_(std::move(xVarName)),
90  yVarName_(std::move(yVarName)),
92  hist_(hist) {}
93 
94  void fill(const ObjType& obj,
95  const edm::Event& event,
96  const edm::EventSetup& setup,
97  const VarRangeCutColl<ObjType>& globalRangeCuts) override {
98  //local range cuts are specific to a histogram so dont ignore variables
99  //like global ones (all local cuts should be approprate to the histogram in question
100  if (globalRangeCuts(obj, std::vector<std::string>{xVarName_, yVarName_}) && localRangeCuts_(obj)) {
101  hist_->Fill(xVar_(obj), yVar_(obj));
102  }
103  }
104 
105 private:
106  std::function<XValType(const ObjType&)> xVar_;
107  std::function<YValType(const ObjType&)> yVar_;
111  TH2* hist_; //we do not own this
112 };
113 
114 #endif
virtual void fill(const ObjType &objType, const edm::Event &event, const edm::EventSetup &setup, const VarRangeCutColl< ObjType > &rangeCuts)=0
std::string yVarName_
Definition: HLTDQMHist.h:109
HLTDQMHist1D(TH1 *hist, std::string varName, std::function< ValType(const ObjType &)> func, VarRangeCutColl< ObjType > rangeCuts)
Definition: HLTDQMHist.h:54
TH1 * hist_
Definition: HLTDQMHist.h:75
virtual ~HLTDQMHist()=default
std::function< XValType(const ObjType &)> xVar_
Definition: HLTDQMHist.h:106
std::function< ValType(const ObjType &)> var_
Definition: HLTDQMHist.h:72
VarRangeCutColl< ObjType > localRangeCuts_
Definition: HLTDQMHist.h:74
void fill(const ObjType &obj, const edm::Event &event, const edm::EventSetup &setup, const VarRangeCutColl< ObjType > &globalRangeCuts) override
Definition: HLTDQMHist.h:60
std::string varName_
Definition: HLTDQMHist.h:73
HLTDQMHist()=default
__shared__ Hist hist
void fill(const ObjType &obj, const edm::Event &event, const edm::EventSetup &setup, const VarRangeCutColl< ObjType > &globalRangeCuts) override
Definition: HLTDQMHist.h:94
std::string xVarName_
Definition: HLTDQMHist.h:108
std::function< YValType(const ObjType &)> yVar_
Definition: HLTDQMHist.h:107
VarRangeCutColl< ObjType > localRangeCuts_
Definition: HLTDQMHist.h:110
def move(src, dest)
Definition: eostools.py:511
HLTDQMHist2D(TH2 *hist, std::string xVarName, std::string yVarName, std::function< XValType(const ObjType &)> xFunc, std::function< YValType(const ObjType &)> yFunc, VarRangeCutColl< ObjType > rangeCuts)
Definition: HLTDQMHist.h:81
Definition: event.py:1