CMS 3D CMS Logo

EgHLTOfflineSource.cc
Go to the documentation of this file.
2 
5 
9 
11 
14 
15 #include <boost/algorithm/string.hpp>
16 
17 //#include "DQMOffline/Trigger/interface/EgHLTCutCodes.h"
21 using namespace egHLT;
22 
24  nrEventsProcessed_(0)
25 {
26  binData_.setup(iConfig.getParameter<edm::ParameterSet>("binData"));
27  cutMasks_.setup(iConfig.getParameter<edm::ParameterSet>("cutMasks"));
28  eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
29  eleHLTFilterNames2Leg_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames2Leg");
30  phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
31  eleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("eleTightLooseTrigNames");
32  diEleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diEleTightLooseTrigNames");
33  phoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("phoTightLooseTrigNames");
34  diPhoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diPhoTightLooseTrigNames");
35 
36  filterInactiveTriggers_ =iConfig.getParameter<bool>("filterInactiveTriggers");
37  hltTag_ = iConfig.getParameter<std::string>("hltTag");
38  dohep_ = iConfig.getParameter<bool>("doHEP");
39 
40  dirName_=iConfig.getParameter<std::string>("DQMDirName");//"HLT/EgHLTOfflineSource_" + iConfig.getParameter<std::string>("@module_label");
41 
42  subdirName_=iConfig.getParameter<std::string>("subDQMDirName");
43 
44  offEvtHelper_.setup(iConfig, consumesCollector());
45 }
46 
47 
49 {
50  // LogDebug("EgHLTOfflineSource") << "destructor called";
51  for(auto & eleFilterMonHist : eleFilterMonHists_){
52  delete eleFilterMonHist;
53  }
54  for(auto & phoFilterMonHist : phoFilterMonHists_){
55  delete phoFilterMonHist;
56  }
57  for(auto & eleMonElem : eleMonElems_){
58  delete eleMonElem;
59  }
60  for(auto & phoMonElem : phoMonElems_){
61  delete phoMonElem;
62  }
63 }
64 
66 {
67  iBooker.setCurrentFolder(dirName_);
68 
69  //the one monitor element the source fills directly
70  dqmErrsMonElem_ = iBooker.book1D("dqmErrors","EgHLTOfflineSource Errors",101,-0.5,100.5);
71  nrEventsProcessedMonElem_ = iBooker.bookInt("nrEventsProcessed");
72 
73  //if the HLTConfig changes during the job, the results are "un predictable" but in practice should be fine
74  //the HLTConfig is used for working out which triggers are active, working out which filternames correspond to paths and L1 seeds
75  //assuming those dont change for E/g it *should* be fine
76  HLTConfigProvider hltConfig;
77  bool changed=false;
78  hltConfig.init(run,c,hltTag_,changed);
80 
81  std::vector<std::string> hltFiltersUsed;
82  getHLTFilterNamesUsed(hltFiltersUsed);
83  trigCodes.reset(TrigCodes::makeCodes(hltFiltersUsed));
84 
85  offEvtHelper_.setupTriggers(hltConfig,hltFiltersUsed, *trigCodes);
86 
87  MonElemFuncs monElemFuncs(iBooker, *trigCodes);
88 
89  //now book ME's
91  //each trigger path with generate object distributions and efficiencies (BUT not trigger efficiencies...)
92  for(auto const & eleHLTFilterName : eleHLTFilterNames_){iBooker.setCurrentFolder(dirName_+"/"+subdirName_+"/"+eleHLTFilterName); addEleTrigPath(monElemFuncs,eleHLTFilterName);}
93  for(auto const & phoHLTFilterName : phoHLTFilterNames_){iBooker.setCurrentFolder(dirName_+"/"+subdirName_+"/"+phoHLTFilterName); addPhoTrigPath(monElemFuncs,phoHLTFilterName);}
94  //efficiencies of one trigger path relative to another
96  //new EgHLTDQMVarCut<OffEle>(cutMasks_.stdEle,&OffEle::cutCode));
97  //monElemFuncs.initTightLooseTrigHistsTrigCuts(eleMonElems_,eleTightLooseTrigNames_,binData_);
98 
99 
101  // new EgHLTDQMVarCut<OffPho>(cutMasks_.stdPho,&OffPho::cutCode));
102  //monElemFuncs.initTightLooseTrigHistsTrigCuts(phoMonElems_,phoTightLooseTrigNames_,binData_);
103 
104  //di-object triggers
106  // new EgDiEleCut(cutMasks_.stdEle,&OffEle::cutCode));
108  // new EgDiPhoCut(cutMasks_.stdPho,&OffPho::cutCode));
109 
112 
113 
114  //tag and probe trigger efficiencies
115  //this is to do measure the trigger efficiency with respect to a fully selected offline electron
116  //using a tag and probe technique (note: this will be different to the trigger efficiency normally calculated)
117  bool doTrigTagProbeEff=false;
118  if(doTrigTagProbeEff && (!dohep_)){
119  for(auto const & eleHLTFilterName : eleHLTFilterNames_){
120  iBooker.setCurrentFolder(dirName_+"/"+subdirName_+"/"+eleHLTFilterName);
121  monElemFuncs.initTrigTagProbeHist(eleMonElems_,eleHLTFilterName,cutMasks_.trigTPEle,binData_);
122  }
123  for(auto const & phoHLTFilterName : phoHLTFilterNames_){
124  iBooker.setCurrentFolder(dirName_+"/"+subdirName_+"/"+phoHLTFilterName);
125  monElemFuncs.initTrigTagProbeHist(phoMonElems_,phoHLTFilterName,cutMasks_.trigTPPho,binData_);
126  }
127  for(auto & i : eleHLTFilterNames2Leg_){
128  iBooker.setCurrentFolder(dirName_+"/"+subdirName_+"/"+i.substr(i.find("::")+2));
129  //std::cout<<"FilterName: "<<eleHLTFilterNames2Leg_[i]<<std::endl;
130  //std::cout<<"Folder: "<<eleHLTFilterNames2Leg_[i].substr(eleHLTFilterNames2Leg_[i].find("::")+2)<<std::endl;
132  }
133  //tag and probe not yet implimented for photons (attemping to see if it makes sense first)
134  // monElemFuncs.initTrigTagProbeHists(phoMonElems,phoHLTFilterNames_);
135  }
136 
137  iBooker.setCurrentFolder(dirName_);
138 }
139 
141 {
142  const double weight=1.; //we have the ability to weight but its disabled for now - maybe use this for prescales?
145  int errCode = offEvtHelper_.makeOffEvt(iEvent,iSetup,offEvt_,*trigCodes);
146  if(errCode!=0){
147  dqmErrsMonElem_->Fill(errCode);
148  return;
149  }
150 
151 
152  for(auto & eleFilterMonHist : eleFilterMonHists_){
153  eleFilterMonHist->fill(offEvt_,weight);
154  }
155  for(auto & phoFilterMonHist : phoFilterMonHists_){
156  phoFilterMonHist->fill(offEvt_,weight);
157  }
158 
159  for(auto & eleMonElem : eleMonElems_){
160  const std::vector<OffEle>& eles = offEvt_.eles();
161  for(auto const & ele : eles){
162  eleMonElem->fill(ele,offEvt_,weight);
163  }
164  }
165 
166  for(auto & phoMonElem : phoMonElems_){
167  const std::vector<OffPho>& phos = offEvt_.phos();
168  for(auto const & pho : phos){
169  phoMonElem->fill(pho,offEvt_,weight);
170  }
171  }
172 }
173 
174 
176 {
177  auto* filterMon = new EleHLTFilterMon(monElemFuncs,name,trigCodes->getCode(name.c_str()),binData_,cutMasks_,dohep_);
178  eleFilterMonHists_.push_back(filterMon);
180  [](auto const& x, auto const& y){ return *x < *y; });
181  //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
182 }
183 
185 {
186  PhoHLTFilterMon* filterMon = new PhoHLTFilterMon(monElemFuncs,name,trigCodes->getCode(name.c_str()),binData_,cutMasks_,dohep_);
187  phoFilterMonHists_.push_back(filterMon);
189  [](auto const& x, auto const& y){ return *x < *y; });
190  //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
191 }
192 
193 //this function puts every filter name used in a std::vector
194 //due to the design, to ensure we get every filter, filters will be inserted multiple times
195 //eg electron filters will contain photon triggers which are also in the photon filters
196 //but only want one copy in the vector
197 //this function is intended to be called once per job so some inefficiency can can be tolerated
198 //therefore we will use a std::set to ensure that each filtername is only inserted once
199 //and then convert to a std::vector
200 void EgHLTOfflineSource::getHLTFilterNamesUsed(std::vector<std::string>& filterNames)const
201 {
202  std::set<std::string> filterNameSet;
203  for(auto const & eleHLTFilterName : eleHLTFilterNames_) filterNameSet.insert(eleHLTFilterName);
204  for(auto const & phoHLTFilterName : phoHLTFilterNames_) filterNameSet.insert(phoHLTFilterName);
205  //here we are little more complicated as entries are of the form "tightTrig:looseTrig"
206  //so we need to split them first
207  for(auto const & eleTightLooseTrigName : eleTightLooseTrigNames_){
208  std::vector<std::string> trigNames;
209  boost::split(trigNames,eleTightLooseTrigName,boost::is_any_of(std::string(":")));
210  if(trigNames.size()!=2) continue; //format incorrect
211  filterNameSet.insert(trigNames[0]);
212  filterNameSet.insert(trigNames[1]);
213  }
214  for(auto const & diEleTightLooseTrigName : diEleTightLooseTrigNames_){
215  std::vector<std::string> trigNames;
216  boost::split(trigNames,diEleTightLooseTrigName,boost::is_any_of(std::string(":")));
217  if(trigNames.size()!=2) continue; //format incorrect
218  filterNameSet.insert(trigNames[0]);
219  filterNameSet.insert(trigNames[1]);
220  }
221  for(auto const & phoTightLooseTrigName : phoTightLooseTrigNames_){
222  std::vector<std::string> trigNames;
223  boost::split(trigNames,phoTightLooseTrigName,boost::is_any_of(std::string(":")));
224  if(trigNames.size()!=2) continue; //format incorrect
225  filterNameSet.insert(trigNames[0]);
226  filterNameSet.insert(trigNames[1]);
227  }
228  for(auto const & diPhoTightLooseTrigName : diPhoTightLooseTrigNames_){
229  std::vector<std::string> trigNames;
230  boost::split(trigNames,diPhoTightLooseTrigName,boost::is_any_of(std::string(":")));
231  if(trigNames.size()!=2) continue; //format incorrect
232  filterNameSet.insert(trigNames[0]);
233  filterNameSet.insert(trigNames[1]);
234  }
235  //right all the triggers are inserted once and only once in the set, convert to vector
236  //very lazy, create a new vector so can use the constructor and then use swap to transfer
237  std::vector<std::string>(filterNameSet.begin(),filterNameSet.end()).swap(filterNames);
238 }
239 
241 {
242 
243  std::vector<std::string> activeFilters;
244  std::vector<std::string> activeEleFilters;
245  std::vector<std::string> activeEle2LegFilters;
246  std::vector<std::string> activePhoFilters;
247  std::vector<std::string> activePho2LegFilters;
248 
249  trigTools::getActiveFilters(hltConfig,activeFilters,activeEleFilters,activeEle2LegFilters,activePhoFilters,activePho2LegFilters);
250 
258 }
std::vector< std::string > diPhoTightLooseTrigNames_
T getParameter(std::string const &) const
egHLT::OffHelper offEvtHelper_
MonitorElement * dqmErrsMonElem_
std::vector< egHLT::EleHLTFilterMon * > eleFilterMonHists_
std::vector< std::string > phoTightLooseTrigNames_
void initTrigTagProbeHist(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::string &filterName, int cutMask, const BinData &bins)
MonitorElement * bookInt(Args &&...args)
Definition: DQMStore.h:104
Definition: weight.py:1
void initTightLooseDiObjTrigHistsTrigCuts(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::vector< std::string > &tightLooseTrigs, const BinData &bins)
std::vector< std::string > eleHLTFilterNames2Leg_
void setup(const edm::ParameterSet &conf)
Definition: EgHLTBinData.cc:6
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
std::vector< egHLT::MonElemContainer< egHLT::OffEle > * > eleMonElems_
void addEleTrigPath(egHLT::MonElemFuncs &monElemFuncs, const std::string &name)
void Fill(long long x)
std::vector< egHLT::PhoHLTFilterMon * > phoFilterMonHists_
int iEvent
Definition: GenABIO.cc:224
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
EgHLTOfflineSource(const EgHLTOfflineSource &rhs)=delete
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
void addPhoTrigPath(egHLT::MonElemFuncs &monElemFuncs, const std::string &name)
void analyze(const edm::Event &, const edm::EventSetup &) override
void initTightLooseTrigHists(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::vector< std::string > &tightLooseTrigs, const BinData &bins, EgHLTDQMCut< OffEle > *eleCut)
void getHLTFilterNamesUsed(std::vector< std::string > &filterNames) const
~EgHLTOfflineSource() override
std::vector< std::string > eleTightLooseTrigNames_
std::vector< egHLT::MonElemContainer< egHLT::OffPho > * > phoMonElems_
const std::vector< OffPho > & phos() const
Definition: EgHLTOffEvt.h:50
void initTrigTagProbeHist_2Leg(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::string &filterName, int cutMask, const BinData &bins)
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
std::vector< std::string > phoHLTFilterNames_
MonitorElement * nrEventsProcessedMonElem_
void getActiveFilters(const HLTConfigProvider &hltConfig, std::vector< std::string > &activeFilters, std::vector< std::string > &activeEleFilters, std::vector< std::string > &activeEle2LegFilters, std::vector< std::string > &activePhoFilters, std::vector< std::string > &activePho2LegFilters)
int makeOffEvt(const edm::Event &edmEvent, const edm::EventSetup &setup, egHLT::OffEvt &offEvent, const TrigCodes &trigCodes)
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::vector< std::string > diEleTightLooseTrigNames_
std::vector< std::string > eleHLTFilterNames_
const std::vector< OffEle > & eles() const
Definition: EgHLTOffEvt.h:48
void setup(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
void filterTriggers(const HLTConfigProvider &hltConfig)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::unique_ptr< egHLT::TrigCodes > trigCodes
egHLT::BinData binData_
void filterInactiveTriggers(std::vector< std::string > &namesToFilter, std::vector< std::string > &activeFilters)
void setupTriggers(const HLTConfigProvider &config, const std::vector< std::string > &hltFiltersUsed, const TrigCodes &trigCodes)
egHLT::CutMasks cutMasks_
void filterInactiveTightLooseTriggers(std::vector< std::string > &namesToFilter, const std::vector< std::string > &activeFilters)
double split
Definition: MVATrainer.cc:139
Definition: Run.h:45
void setup(const edm::ParameterSet &conf)
Definition: EgHLTCutMasks.h:23