CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
39 
40  dirName_=iConfig.getParameter<std::string>("DQMDirName");//"HLT/EgHLTOfflineSource_" + iConfig.getParameter<std::string>("@module_label");
41 
42 
44 }
45 
46 
48 {
49  // LogDebug("EgHLTOfflineSource") << "destructor called";
50  for(size_t i=0;i<eleFilterMonHists_.size();i++){
51  delete eleFilterMonHists_[i];
52  }
53  for(size_t i=0;i<phoFilterMonHists_.size();i++){
54  delete phoFilterMonHists_[i];
55  }
56  for(size_t i=0;i<eleMonElems_.size();i++){
57  delete eleMonElems_[i];
58  }
59  for(size_t i=0;i<phoMonElems_.size();i++){
60  delete phoMonElems_[i];
61  }
62 }
63 
65 {
66  iBooker.setCurrentFolder(dirName_);
67 
68  //the one monitor element the source fills directly
69  dqmErrsMonElem_ = iBooker.book1D("dqmErrors","EgHLTOfflineSource Errors",101,-0.5,100.5);
70  nrEventsProcessedMonElem_ = iBooker.bookInt("nrEventsProcessed");
71 
72  //if the HLTConfig changes during the job, the results are "un predictable" but in practice should be fine
73  //the HLTConfig is used for working out which triggers are active, working out which filternames correspond to paths and L1 seeds
74  //assuming those dont change for E/g it *should* be fine
76  bool changed=false;
77  hltConfig.init(run,c,hltTag_,changed);
79 
80  std::vector<std::string> hltFiltersUsed;
81  getHLTFilterNamesUsed(hltFiltersUsed);
82  trigCodes.reset(TrigCodes::makeCodes(hltFiltersUsed));
83 
84  offEvtHelper_.setupTriggers(hltConfig,hltFiltersUsed, *trigCodes);
85 
86  MonElemFuncs monElemFuncs(iBooker, *trigCodes);
87 
88  //now book ME's
89  iBooker.setCurrentFolder(dirName_+"/Source_Histos");
90  //each trigger path with generate object distributions and efficiencies (BUT not trigger efficiencies...)
91  for(size_t i=0;i<eleHLTFilterNames_.size();i++){iBooker.setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames_[i]); addEleTrigPath(monElemFuncs,eleHLTFilterNames_[i]);}
92  for(size_t i=0;i<phoHLTFilterNames_.size();i++){iBooker.setCurrentFolder(dirName_+"/Source_Histos/"+phoHLTFilterNames_[i]); addPhoTrigPath(monElemFuncs,phoHLTFilterNames_[i]);}
93  //efficiencies of one trigger path relative to another
95  //new EgHLTDQMVarCut<OffEle>(cutMasks_.stdEle,&OffEle::cutCode));
96  //monElemFuncs.initTightLooseTrigHistsTrigCuts(eleMonElems_,eleTightLooseTrigNames_,binData_);
97 
98 
100  // new EgHLTDQMVarCut<OffPho>(cutMasks_.stdPho,&OffPho::cutCode));
101  //monElemFuncs.initTightLooseTrigHistsTrigCuts(phoMonElems_,phoTightLooseTrigNames_,binData_);
102 
103  //di-object triggers
105  // new EgDiEleCut(cutMasks_.stdEle,&OffEle::cutCode));
107  // new EgDiPhoCut(cutMasks_.stdPho,&OffPho::cutCode));
108 
111 
112 
113  //tag and probe trigger efficiencies
114  //this is to do measure the trigger efficiency with respect to a fully selected offline electron
115  //using a tag and probe technique (note: this will be different to the trigger efficiency normally calculated)
116  bool doTrigTagProbeEff=false;
117  if(doTrigTagProbeEff){
118  for(size_t i=0;i<eleHLTFilterNames_.size();i++){
119  iBooker.setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames_[i]);
121  }
122  for(size_t i=0;i<phoHLTFilterNames_.size();i++){
123  iBooker.setCurrentFolder(dirName_+"/Source_Histos/"+phoHLTFilterNames_[i]);
125  }
126  for(size_t i=0;i<eleHLTFilterNames2Leg_.size();i++){
127  iBooker.setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames2Leg_[i].substr(eleHLTFilterNames2Leg_[i].find("::")+2));
128  //std::cout<<"FilterName: "<<eleHLTFilterNames2Leg_[i]<<std::endl;
129  //std::cout<<"Folder: "<<eleHLTFilterNames2Leg_[i].substr(eleHLTFilterNames2Leg_[i].find("::")+2)<<std::endl;
131  }
132  //tag and probe not yet implimented for photons (attemping to see if it makes sense first)
133  // monElemFuncs.initTrigTagProbeHists(phoMonElems,phoHLTFilterNames_);
134  }
135 
136  iBooker.setCurrentFolder(dirName_);
137 }
138 
140 {
141  const double weight=1.; //we have the ability to weight but its disabled for now - maybe use this for prescales?
144  int errCode = offEvtHelper_.makeOffEvt(iEvent,iSetup,offEvt_,*trigCodes);
145  if(errCode!=0){
146  dqmErrsMonElem_->Fill(errCode);
147  return;
148  }
149 
150 
151  for(size_t pathNr=0;pathNr<eleFilterMonHists_.size();pathNr++){
152  eleFilterMonHists_[pathNr]->fill(offEvt_,weight);
153  }
154  for(size_t pathNr=0;pathNr<phoFilterMonHists_.size();pathNr++){
155  phoFilterMonHists_[pathNr]->fill(offEvt_,weight);
156  }
157 
158  for(size_t monElemNr=0;monElemNr<eleMonElems_.size();monElemNr++){
159  const std::vector<OffEle>& eles = offEvt_.eles();
160  for(size_t eleNr=0;eleNr<eles.size();eleNr++){
161  eleMonElems_[monElemNr]->fill(eles[eleNr],offEvt_,weight);
162  }
163  }
164 
165  for(size_t monElemNr=0;monElemNr<phoMonElems_.size();monElemNr++){
166  const std::vector<OffPho>& phos = offEvt_.phos();
167  for(size_t phoNr=0;phoNr<phos.size();phoNr++){
168  phoMonElems_[monElemNr]->fill(phos[phoNr],offEvt_,weight);
169  }
170  }
171 }
172 
173 
175 {
176  EleHLTFilterMon* filterMon = new EleHLTFilterMon(monElemFuncs,name,trigCodes->getCode(name.c_str()),binData_,cutMasks_);
177  eleFilterMonHists_.push_back(filterMon);
178  std::sort(eleFilterMonHists_.begin(),eleFilterMonHists_.end(),EleHLTFilterMon::ptrLess<EleHLTFilterMon>()); //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
179 }
180 
182 {
183  PhoHLTFilterMon* filterMon = new PhoHLTFilterMon(monElemFuncs,name,trigCodes->getCode(name.c_str()),binData_,cutMasks_);
184  phoFilterMonHists_.push_back(filterMon);
185  std::sort(phoFilterMonHists_.begin(),phoFilterMonHists_.end(),PhoHLTFilterMon::ptrLess<PhoHLTFilterMon>()); //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
186 }
187 
188 //this function puts every filter name used in a std::vector
189 //due to the design, to ensure we get every filter, filters will be inserted multiple times
190 //eg electron filters will contain photon triggers which are also in the photon filters
191 //but only want one copy in the vector
192 //this function is intended to be called once per job so some inefficiency can can be tolerated
193 //therefore we will use a std::set to ensure that each filtername is only inserted once
194 //and then convert to a std::vector
195 void EgHLTOfflineSource::getHLTFilterNamesUsed(std::vector<std::string>& filterNames)const
196 {
197  std::set<std::string> filterNameSet;
198  for(size_t i=0;i<eleHLTFilterNames_.size();i++) filterNameSet.insert(eleHLTFilterNames_[i]);
199  for(size_t i=0;i<phoHLTFilterNames_.size();i++) filterNameSet.insert(phoHLTFilterNames_[i]);
200  //here we are little more complicated as entries are of the form "tightTrig:looseTrig"
201  //so we need to split them first
202  for(size_t tightLooseNr=0;tightLooseNr<eleTightLooseTrigNames_.size();tightLooseNr++){
203  std::vector<std::string> trigNames;
204  boost::split(trigNames,eleTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
205  if(trigNames.size()!=2) continue; //format incorrect
206  filterNameSet.insert(trigNames[0]);
207  filterNameSet.insert(trigNames[1]);
208  }
209  for(size_t tightLooseNr=0;tightLooseNr<diEleTightLooseTrigNames_.size();tightLooseNr++){
210  std::vector<std::string> trigNames;
211  boost::split(trigNames,diEleTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
212  if(trigNames.size()!=2) continue; //format incorrect
213  filterNameSet.insert(trigNames[0]);
214  filterNameSet.insert(trigNames[1]);
215  }
216  for(size_t tightLooseNr=0;tightLooseNr<phoTightLooseTrigNames_.size();tightLooseNr++){
217  std::vector<std::string> trigNames;
218  boost::split(trigNames,phoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
219  if(trigNames.size()!=2) continue; //format incorrect
220  filterNameSet.insert(trigNames[0]);
221  filterNameSet.insert(trigNames[1]);
222  }
223  for(size_t tightLooseNr=0;tightLooseNr<diPhoTightLooseTrigNames_.size();tightLooseNr++){
224  std::vector<std::string> trigNames;
225  boost::split(trigNames,diPhoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
226  if(trigNames.size()!=2) continue; //format incorrect
227  filterNameSet.insert(trigNames[0]);
228  filterNameSet.insert(trigNames[1]);
229  }
230  //right all the triggers are inserted once and only once in the set, convert to vector
231  //very lazy, create a new vector so can use the constructor and then use swap to transfer
232  std::vector<std::string>(filterNameSet.begin(),filterNameSet.end()).swap(filterNames);
233 }
234 
236 {
237 
238  std::vector<std::string> activeFilters;
239  std::vector<std::string> activeEleFilters;
240  std::vector<std::string> activeEle2LegFilters;
241  std::vector<std::string> activePhoFilters;
242  std::vector<std::string> activePho2LegFilters;
243 
244  trigTools::getActiveFilters(hltConfig,activeFilters,activeEleFilters,activeEle2LegFilters,activePhoFilters,activePho2LegFilters);
245 
253 }
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
std::vector< std::string > diPhoTightLooseTrigNames_
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
egHLT::OffHelper offEvtHelper_
MonitorElement * dqmErrsMonElem_
std::vector< egHLT::EleHLTFilterMon * > eleFilterMonHists_
std::vector< std::string > phoTightLooseTrigNames_
MonitorElement * bookInt(Args &&...args)
Definition: DQMStore.h:103
void initTrigTagProbeHist_2Leg(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::string filterName, int cutMask, const BinData &bins)
void initTightLooseDiObjTrigHistsTrigCuts(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::vector< std::string > &tightLooseTrigs, const BinData &bins)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< std::string > eleHLTFilterNames2Leg_
void setup(const edm::ParameterSet &conf)
Definition: EgHLTBinData.cc:6
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:230
EgHLTOfflineSource(const EgHLTOfflineSource &rhs)=delete
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
void addPhoTrigPath(egHLT::MonElemFuncs &monElemFuncs, const std::string &name)
virtual 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
void initTrigTagProbeHist(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::string filterName, int cutMask, const BinData &bins)
std::vector< std::string > eleTightLooseTrigNames_
std::vector< egHLT::MonElemContainer< egHLT::OffPho > * > phoMonElems_
const std::vector< OffPho > & phos() const
Definition: EgHLTOffEvt.h:48
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
std::vector< std::string > phoHLTFilterNames_
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:273
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:46
void setup(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
void filterTriggers(const HLTConfigProvider &hltConfig)
virtual 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:43
void setup(const edm::ParameterSet &conf)
Definition: EgHLTCutMasks.h:23