CMS 3D CMS Logo

HLTDQMFilterEffHists.h
Go to the documentation of this file.
1 #ifndef DQMOnline_Trigger_HLTDQMHistColl_h
2 #define DQMOnline_Trigger_HLTDQMHistColl_h
3 
4 //********************************************************************************
5 //
6 // Description:
7 // This contains a collection of HLTDQMHists used to measure the efficiency of a
8 // specified filter. It is resonsible for booking and filling the histograms
9 // For every hist specified, it books two, one to record the
10 // total objects passing sample selection passed to the class and then one for those objects
11 // which then pass the HLT filter
12 // The class contains a simple selection cuts (mostly intended for kinematic range cuts)
13 // which are passed to the histograms as they are filled.
14 // The cuts are passed to the histograms as some histograms will ignore certain cuts
15 // for example, eff vs Et will ignore any global Et cuts applied
16 //
17 // Author : Sam Harper , RAL, May 2017
18 //
19 //***********************************************************************************
20 
21 
24 
27 
29 
34 
35 template <typename ObjType>
37 public:
38 
40  std::string baseHistName,
41  std::string hltProcess);
42 
45 
46  void bookHists(DQMStore::IBooker& iBooker,const std::vector<edm::ParameterSet>& histConfigs);
47  void fillHists(const ObjType& obj,const edm::Event& event,
48  const edm::EventSetup& setup,const trigger::TriggerEvent& trigEvt);
49 private:
50  void book1D(DQMStore::IBooker& iBooker,const edm::ParameterSet& histConfig);
51  void book2D(DQMStore::IBooker& iBooker,const edm::ParameterSet& histConfig);
52 private:
53  std::vector<std::unique_ptr<HLTDQMHist<ObjType> > > histsPass_;
54  std::vector<std::unique_ptr<HLTDQMHist<ObjType> > > histsTot_;
61 
62 };
63 
64 template <typename ObjType>
66  std::string baseHistName,
67  std::string hltProcess):
68  rangeCuts_(config.getParameter<std::vector<edm::ParameterSet> >("rangeCuts")),
69  filterName_(config.getParameter<std::string>("filterName")),
70  histTitle_(config.getParameter<std::string>("histTitle")),
71  folderName_(config.getParameter<std::string>("folderName")),
72  baseHistName_(std::move(baseHistName)),
73  hltProcess_(std::move(hltProcess))
74 {
75 
76 }
77 
78 template<typename ObjType>
80 {
82  desc.addVPSet("rangeCuts",VarRangeCut<ObjType>::makePSetDescription(),std::vector<edm::ParameterSet>());
83  desc.add<std::string>("filterName","");
84  desc.add<std::string>("histTitle","");
85  desc.add<std::string>("folderName","");
86  return desc;
87 }
88 
89 template<typename ObjType>
91 {
93 
94  //what this is doing is trival and is left as an exercise to the reader
95  auto histDescCases =
96  "1D" >>
97  (edm::ParameterDescription<std::vector<double> >("binLowEdges",std::vector<double>(),true) and
98  edm::ParameterDescription<std::string>("nameSuffex","",true) and
99  edm::ParameterDescription<std::string>("vsVar","",true)) or
100  "2D" >>
101  (edm::ParameterDescription<std::vector<double> >("xBinLowEdges",std::vector<double>(),true) and
102  edm::ParameterDescription<std::vector<double> >("yBinLowEdges",std::vector<double>(),true) and
103  edm::ParameterDescription<std::string>("nameSuffex","",true) and
104  edm::ParameterDescription<std::string>("xVar","",true) and
105  edm::ParameterDescription<std::string>("yVar","",true));
106 
107  desc.ifValue(edm::ParameterDescription<std::string>("histType","1D",true), std::move(histDescCases));
108  desc.addVPSet("rangeCuts",VarRangeCut<ObjType>::makePSetDescription(),std::vector<edm::ParameterSet>());
109  return desc;
110 }
111 
112 
113 template <typename ObjType>
114 void HLTDQMFilterEffHists<ObjType>::bookHists(DQMStore::IBooker& iBooker,const std::vector<edm::ParameterSet>& histConfigs)
115 {
116  iBooker.setCurrentFolder(folderName_);
117  for(auto& histConfig : histConfigs){
118  std::string histType = histConfig.getParameter<std::string>("histType");
119  if(histType=="1D"){
120  book1D(iBooker,histConfig);
121  }else if(histType=="2D"){
122  book2D(iBooker,histConfig);
123  }else{
124  throw cms::Exception("ConfigError")<<" histType "<<histType<<" not recognised"<<std::endl;
125  }
126  }
127 }
128 
129 template <typename ObjType>
131 {
132  auto binLowEdgesDouble = histConfig.getParameter<std::vector<double> >("binLowEdges");
133  std::vector<float> binLowEdges;
134  for(double lowEdge : binLowEdgesDouble) binLowEdges.push_back(lowEdge);
135  auto nameSuffex = histConfig.getParameter<std::string>("nameSuffex");
136  auto mePass = iBooker.book1D((baseHistName_+filterName_+nameSuffex+"_pass").c_str(),
137  (histTitle_+nameSuffex+" Pass").c_str(),
138  binLowEdges.size()-1,&binLowEdges[0]);
139  std::unique_ptr<HLTDQMHist<ObjType> > hist;
140  auto vsVar = histConfig.getParameter<std::string>("vsVar");
141  auto vsVarFunc = hltdqm::getUnaryFuncFloat<ObjType>(vsVar);
142  if(!vsVarFunc) {
143  throw cms::Exception("ConfigError")<<" vsVar "<<vsVar<<" is giving null ptr (likely empty) in "<<__FILE__<<","<<__LINE__<<std::endl;
144  }
145  VarRangeCutColl<ObjType> rangeCuts(histConfig.getParameter<std::vector<edm::ParameterSet> >("rangeCuts"));
146  hist = std::make_unique<HLTDQMHist1D<ObjType,float> >(mePass->getTH1(),vsVar,vsVarFunc,rangeCuts);
147  histsPass_.emplace_back(std::move(hist));
148  auto meTot = iBooker.book1D((baseHistName_+filterName_+nameSuffex+"_tot").c_str(),
149  (histTitle_+nameSuffex+" Total").c_str(),
150  binLowEdges.size()-1,&binLowEdges[0]);
151  hist = std::make_unique<HLTDQMHist1D<ObjType,float> >(meTot->getTH1(),vsVar,vsVarFunc,rangeCuts);
152  histsTot_.emplace_back(std::move(hist));
153 
154 }
155 
156 template <typename ObjType>
158 {
159  auto xBinLowEdgesDouble = histConfig.getParameter<std::vector<double> >("xBinLowEdges");
160  auto yBinLowEdgesDouble = histConfig.getParameter<std::vector<double> >("yBinLowEdges");
161  std::vector<float> xBinLowEdges;
162  std::vector<float> yBinLowEdges;
163  for(double lowEdge : xBinLowEdgesDouble) xBinLowEdges.push_back(lowEdge);
164  for(double lowEdge : yBinLowEdgesDouble) yBinLowEdges.push_back(lowEdge);
165  auto nameSuffex = histConfig.getParameter<std::string>("nameSuffex");
166  auto mePass = iBooker.book2D((baseHistName_+filterName_+nameSuffex+"_pass").c_str(),
167  (histTitle_+nameSuffex+" Pass").c_str(),
168  xBinLowEdges.size()-1,&xBinLowEdges[0],
169  yBinLowEdges.size()-1,&yBinLowEdges[0]);
170  std::unique_ptr<HLTDQMHist<ObjType> > hist;
171  auto xVar = histConfig.getParameter<std::string>("xVar");
172  auto yVar = histConfig.getParameter<std::string>("yVar");
173  auto xVarFunc = hltdqm::getUnaryFuncFloat<ObjType>(xVar);
174  auto yVarFunc = hltdqm::getUnaryFuncFloat<ObjType>(yVar);
175  if(!xVarFunc || !yVarFunc) {
176  throw cms::Exception("ConfigError")<<" xVar "<<xVar<<" or yVar "<<yVar<<" is giving null ptr (likely empty str passed)"<<std::endl;
177  }
178  VarRangeCutColl<ObjType> rangeCuts(histConfig.getParameter<std::vector<edm::ParameterSet> >("rangeCuts"));
179 
180 
181  //really? really no MonitorElement::getTH2...sigh
182  hist = std::make_unique<HLTDQMHist2D<ObjType,float> >(static_cast<TH2*>(mePass->getTH1()),xVar,yVar,xVarFunc,yVarFunc,rangeCuts);
183  histsPass_.emplace_back(std::move(hist));
184 
185  auto meTot = iBooker.book2D((baseHistName_+filterName_+nameSuffex+"_tot").c_str(),
186  (histTitle_+nameSuffex+" Total").c_str(),
187  xBinLowEdges.size()-1,&xBinLowEdges[0],
188  yBinLowEdges.size()-1,&yBinLowEdges[0]);
189 
190  hist = std::make_unique<HLTDQMHist2D<ObjType,float> >(static_cast<TH2*>(meTot->getTH1()),xVar,yVar,xVarFunc,yVarFunc,rangeCuts);
191  histsTot_.emplace_back(std::move(hist));
192 }
193 
194 template <typename ObjType>
196  const edm::Event& event,
197  const edm::EventSetup& setup,
198  const trigger::TriggerEvent& trigEvt)
199 {
200 
201  for(auto& hist : histsTot_){
202  hist->fill(obj,event,setup,rangeCuts_);
203  }
204 
205  if(hltdqm::passTrig(obj.eta(),obj.phi(),trigEvt,filterName_,hltProcess_)){
206  for(auto& hist : histsPass_){
207  hist->fill(obj,event,setup,rangeCuts_);
208  }
209 
210  }
211 }
212 #endif
HLTDQMFilterEffHists(const edm::ParameterSet &config, std::string baseHistName, std::string hltProcess)
T getParameter(std::string const &) const
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T >> cases)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
VarRangeCutColl< ObjType > rangeCuts_
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
Definition: config.py:1
static edm::ParameterSetDescription makePSetDescriptionHistConfigs()
void book2D(DQMStore::IBooker &iBooker, const edm::ParameterSet &histConfig)
void book1D(DQMStore::IBooker &iBooker, const edm::ParameterSet &histConfig)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
std::vector< std::unique_ptr< HLTDQMHist< ObjType > > > histsPass_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< std::unique_ptr< HLTDQMHist< ObjType > > > histsTot_
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
HLT enums.
void bookHists(DQMStore::IBooker &iBooker, const std::vector< edm::ParameterSet > &histConfigs)
static edm::ParameterSetDescription makePSetDescription()
void fillHists(const ObjType &obj, const edm::Event &event, const edm::EventSetup &setup, const trigger::TriggerEvent &trigEvt)
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
bool passTrig(const float objEta, float objPhi, const trigger::TriggerEvent &trigEvt, const std::string &filterName, const std::string &processName)
Definition: UtilFuncs.h:14