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 
26 
27 //our base class for our histograms
28 //takes an object, edm::Event,edm::EventSetup and fills the histogram
29 //with the predetermined variable (or varaibles)
30 template <typename ObjType>
31 class HLTDQMHist {
32 public:
33  HLTDQMHist()=default;
34  virtual ~HLTDQMHist()=default;
35  virtual void fill(const ObjType& objType,const edm::Event& event,
36  const edm::EventSetup& setup,const VarRangeCutColl<ObjType>& rangeCuts)=0;
37 };
38 
39 
40 //this class is a specific implimentation of a HLTDQMHist
41 //it has the value with which to fill the histogram
42 //and the histogram itself
43 //we do not own the histogram
44 template <typename ObjType,typename ValType>
45 class HLTDQMHist1D : public HLTDQMHist<ObjType> {
46 public:
47  HLTDQMHist1D(TH1* hist,const std::string& varName,
48  std::function<ValType(const ObjType&)> func,
49  const VarRangeCutColl<ObjType>& rangeCuts):
50  var_(func),varName_(varName),localRangeCuts_(rangeCuts),hist_(hist){}
51 
52  void fill(const ObjType& obj,const edm::Event& event,
53  const edm::EventSetup& setup,const VarRangeCutColl<ObjType>& globalRangeCuts)override{
54  //local range cuts are specific to a histogram so dont ignore variables
55  //like global ones (all local cuts should be approprate to the histogram in question
56  if(globalRangeCuts(obj,varName_) && localRangeCuts_(obj)){
57  hist_->Fill(var_(obj));
58  }
59  }
60 private:
61  std::function<ValType(const ObjType&)> var_;
64  TH1* hist_; //we do not own this
65 };
66 
67 template <typename ObjType,typename XValType,typename YValType=XValType>
68 class HLTDQMHist2D : public HLTDQMHist<ObjType> {
69 public:
70  HLTDQMHist2D(TH2* hist,const std::string& xVarName,const std::string& yVarName,
71  std::function<XValType(const ObjType&)> xFunc,
72  std::function<YValType(const ObjType&)> yFunc,
73  const VarRangeCutColl<ObjType>& rangeCuts):
74  xVar_(xFunc),yVar_(yFunc),
75  xVarName_(xVarName),yVarName_(yVarName),
76  localRangeCuts_(rangeCuts),hist_(hist){}
77 
78  void fill(const ObjType& obj,const edm::Event& event,
79  const edm::EventSetup& setup,const VarRangeCutColl<ObjType>& globalRangeCuts)override{
80  //local range cuts are specific to a histogram so dont ignore variables
81  //like global ones (all local cuts should be approprate to the histogram in question
82  if(globalRangeCuts(obj,std::vector<std::string>{xVarName_,yVarName_}) &&
83  localRangeCuts_(obj)){
84  hist_->Fill(xVar_(obj),yVar_(obj));
85  }
86  }
87 private:
88  std::function<XValType(const ObjType&)> xVar_;
89  std::function<YValType(const ObjType&)> yVar_;
93  TH2* hist_; //we do not own this
94 };
95 
96 #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:91
TH1 * hist_
Definition: HLTDQMHist.h:64
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
virtual ~HLTDQMHist()=default
std::function< XValType(const ObjType &)> xVar_
Definition: HLTDQMHist.h:88
std::function< ValType(const ObjType &)> var_
Definition: HLTDQMHist.h:61
VarRangeCutColl< ObjType > localRangeCuts_
Definition: HLTDQMHist.h:63
void fill(const ObjType &obj, const edm::Event &event, const edm::EventSetup &setup, const VarRangeCutColl< ObjType > &globalRangeCuts) override
Definition: HLTDQMHist.h:52
HLTDQMHist2D(TH2 *hist, const std::string &xVarName, const std::string &yVarName, std::function< XValType(const ObjType &)> xFunc, std::function< YValType(const ObjType &)> yFunc, const VarRangeCutColl< ObjType > &rangeCuts)
Definition: HLTDQMHist.h:70
std::string varName_
Definition: HLTDQMHist.h:62
TH2 * hist_
Definition: HLTDQMHist.h:93
HLTDQMHist1D(TH1 *hist, const std::string &varName, std::function< ValType(const ObjType &)> func, const VarRangeCutColl< ObjType > &rangeCuts)
Definition: HLTDQMHist.h:47
HLTDQMHist()=default
void fill(const ObjType &obj, const edm::Event &event, const edm::EventSetup &setup, const VarRangeCutColl< ObjType > &globalRangeCuts) override
Definition: HLTDQMHist.h:78
std::string xVarName_
Definition: HLTDQMHist.h:90
std::function< YValType(const ObjType &)> yVar_
Definition: HLTDQMHist.h:89
VarRangeCutColl< ObjType > localRangeCuts_
Definition: HLTDQMHist.h:92
Definition: event.py:1