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