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 
10 
12 
15 
16 #include <boost/algorithm/string.hpp>
17 
18 //#include "DQMOffline/Trigger/interface/EgHLTCutCodes.h"
22 using namespace egHLT;
23 
25  nrEventsProcessed_(0),isSetup_(false)
26 {
27  dbe_ = edm::Service<DQMStore>().operator->(); //only one chance to get this, if we ever have another shot, remember to check isSetup is okay
28  if (!dbe_) {
29  //our one and only error message ever logged
30  edm::LogInfo("EgHLTOfflineSource") << "unable to get DQMStore service?";
31  }
32  if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
33  dbe_->setVerbose(0);
34  }
35 
36 
37  binData_.setup(iConfig.getParameter<edm::ParameterSet>("binData"));
38  cutMasks_.setup(iConfig.getParameter<edm::ParameterSet>("cutMasks"));
39  eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
40  eleHLTFilterNames2Leg_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames2Leg");
41  phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
42  eleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("eleTightLooseTrigNames");
43  diEleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diEleTightLooseTrigNames");
44  phoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("phoTightLooseTrigNames");
45  diPhoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diPhoTightLooseTrigNames");
46 
47  filterInactiveTriggers_ =iConfig.getParameter<bool>("filterInactiveTriggers");
48  hltTag_ = iConfig.getParameter<std::string>("hltTag");
49 
50 
51  dirName_=iConfig.getParameter<std::string>("DQMDirName");//"HLT/EgHLTOfflineSource_" + iConfig.getParameter<std::string>("@module_label");
52 
53 
54  offEvtHelper_.setup(iConfig);
55 
56 }
57 
58 
60 {
61  // LogDebug("EgHLTOfflineSource") << "destructor called";
62  for(size_t i=0;i<eleFilterMonHists_.size();i++){
63  delete eleFilterMonHists_[i];
64  }
65  for(size_t i=0;i<phoFilterMonHists_.size();i++){
66  delete phoFilterMonHists_[i];
67  }
68  for(size_t i=0;i<eleMonElems_.size();i++){
69  delete eleMonElems_[i];
70  }
71  for(size_t i=0;i<phoMonElems_.size();i++){
72  delete phoMonElems_[i];
73  }
74 }
75 
77 {
78  if(dbe_) {
80  //the one monitor element the source fills directly
81  dqmErrsMonElem_ =dbe_->book1D("dqmErrors","EgHLTOfflineSource Errors",101,-0.5,100.5);
82  nrEventsProcessedMonElem_ = dbe_->bookInt("nrEventsProcessed");
83  }
84 }
85 
87 {
88  // LogDebug("EgHLTOfflineSource") << "ending job";
89 }
90 
91 //due to changes in HLTConfigProvider to be called at beginRun rather then beginJob, I moved everything from beginJob here and ensure that it is only called once
92 //if the HLTConfig changes during the job, the results are "un predictable" but in practice should be fine
93 //the HLTConfig is used for working out which triggers are active, working out which filternames correspond to paths and L1 seeds
94 //assuming those dont change for E/g it *should* be fine
96 {
97  if(dbe_ && !isSetup_){
99  bool changed=false;
100  hltConfig.init(run,c,hltTag_,changed);
102 
103  std::vector<std::string> hltFiltersUsed;
104  getHLTFilterNamesUsed(hltFiltersUsed);
105  TrigCodes::setCodes(hltFiltersUsed);
106 
107  offEvtHelper_.setupTriggers(hltConfig,hltFiltersUsed);
108 
109  //now book ME's
110  dbe_->setCurrentFolder(dirName_+"/Source_Histos");
111  //each trigger path with generate object distributions and efficiencies (BUT not trigger efficiencies...)
112  for(size_t i=0;i<eleHLTFilterNames_.size();i++){dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames_[i]); addEleTrigPath(eleHLTFilterNames_[i]);}
113  for(size_t i=0;i<phoHLTFilterNames_.size();i++){dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+phoHLTFilterNames_[i]); addPhoTrigPath(phoHLTFilterNames_[i]);}
114  //efficiencies of one trigger path relative to another
116  //new EgHLTDQMVarCut<OffEle>(cutMasks_.stdEle,&OffEle::cutCode));
117  //MonElemFuncs::initTightLooseTrigHistsTrigCuts(eleMonElems_,eleTightLooseTrigNames_,binData_);
118 
119 
121  // new EgHLTDQMVarCut<OffPho>(cutMasks_.stdPho,&OffPho::cutCode));
122  //MonElemFuncs::initTightLooseTrigHistsTrigCuts(phoMonElems_,phoTightLooseTrigNames_,binData_);
123 
124  //di-object triggers
126  // new EgDiEleCut(cutMasks_.stdEle,&OffEle::cutCode));
128  // new EgDiPhoCut(cutMasks_.stdPho,&OffPho::cutCode));
129 
132 
133 
134  //tag and probe trigger efficiencies
135  //this is to do measure the trigger efficiency with respect to a fully selected offline electron
136  //using a tag and probe technique (note: this will be different to the trigger efficiency normally calculated)
137  bool doTrigTagProbeEff=false;
138  if(doTrigTagProbeEff){
139  for(size_t i=0;i<eleHLTFilterNames_.size();i++){
140  dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames_[i]);
142  }
143  for(size_t i=0;i<phoHLTFilterNames_.size();i++){
144  dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+phoHLTFilterNames_[i]);
146  }
147  for(size_t i=0;i<eleHLTFilterNames2Leg_.size();i++){
148  dbe_->setCurrentFolder(dirName_+"/Source_Histos/"+eleHLTFilterNames2Leg_[i].substr(eleHLTFilterNames2Leg_[i].find("::")+2));
149  //std::cout<<"FilterName: "<<eleHLTFilterNames2Leg_[i]<<std::endl;
150  //std::cout<<"Folder: "<<eleHLTFilterNames2Leg_[i].substr(eleHLTFilterNames2Leg_[i].find("::")+2)<<std::endl;
152  }
153  //tag and probe not yet implimented for photons (attemping to see if it makes sense first)
154  // MonElemFuncs::initTrigTagProbeHists(phoMonElems,phoHLTFilterNames_);
155  }
156  isSetup_=true;
157 
159  }
160 }
161 
162 
164 {
165  //LogDebug("EgHLTOfflineSource") << "endRun, run " << run.id();
166 }
167 
168 
170 {
171  //debugging info, commented out for prod
172  // int nrProducts = debug::listAllProducts<edm::ValueMap<double> >(iEvent,"EgHLTOfflineSource");
173  //edm::LogInfo("EgHLTOfflineSource")<<" HERE ";
174  // std::cout <<"here"<<std::endl;
175  if(!dbe_) return;
176 
177 
178 
179 
180 
181  const double weight=1.; //we have the ability to weight but its disabled for now - maybe use this for prescales?
184  int errCode = offEvtHelper_.makeOffEvt(iEvent,iSetup,offEvt_);
185  if(errCode!=0){
186  dqmErrsMonElem_->Fill(errCode);
187  return;
188  }
189 
190 
191  for(size_t pathNr=0;pathNr<eleFilterMonHists_.size();pathNr++){
192  eleFilterMonHists_[pathNr]->fill(offEvt_,weight);
193  }
194  for(size_t pathNr=0;pathNr<phoFilterMonHists_.size();pathNr++){
195  phoFilterMonHists_[pathNr]->fill(offEvt_,weight);
196  }
197 
198  for(size_t monElemNr=0;monElemNr<eleMonElems_.size();monElemNr++){
199  const std::vector<OffEle>& eles = offEvt_.eles();
200  for(size_t eleNr=0;eleNr<eles.size();eleNr++){
201  eleMonElems_[monElemNr]->fill(eles[eleNr],offEvt_,weight);
202  }
203  }
204 
205  for(size_t monElemNr=0;monElemNr<phoMonElems_.size();monElemNr++){
206  const std::vector<OffPho>& phos = offEvt_.phos();
207  for(size_t phoNr=0;phoNr<phos.size();phoNr++){
208  phoMonElems_[monElemNr]->fill(phos[phoNr],offEvt_,weight);
209  }
210  }
211 }
212 
213 
215 {
216  EleHLTFilterMon* filterMon = new EleHLTFilterMon(name,TrigCodes::getCode(name.c_str()),binData_,cutMasks_);
217  eleFilterMonHists_.push_back(filterMon);
218  std::sort(eleFilterMonHists_.begin(),eleFilterMonHists_.end(),EleHLTFilterMon::ptrLess<EleHLTFilterMon>()); //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
219 }
220 
222 {
223  PhoHLTFilterMon* filterMon = new PhoHLTFilterMon(name,TrigCodes::getCode(name.c_str()),binData_,cutMasks_);
224  phoFilterMonHists_.push_back(filterMon);
225  std::sort(phoFilterMonHists_.begin(),phoFilterMonHists_.end(),PhoHLTFilterMon::ptrLess<PhoHLTFilterMon>()); //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
226 }
227 
228 //this function puts every filter name used in a std::vector
229 //due to the design, to ensure we get every filter, filters will be inserted multiple times
230 //eg electron filters will contain photon triggers which are also in the photon filters
231 //but only want one copy in the vector
232 //this function is intended to be called once per job so some inefficiency can can be tolerated
233 //therefore we will use a std::set to ensure that each filtername is only inserted once
234 //and then convert to a std::vector
235 void EgHLTOfflineSource::getHLTFilterNamesUsed(std::vector<std::string>& filterNames)const
236 {
237  std::set<std::string> filterNameSet;
238  for(size_t i=0;i<eleHLTFilterNames_.size();i++) filterNameSet.insert(eleHLTFilterNames_[i]);
239  for(size_t i=0;i<phoHLTFilterNames_.size();i++) filterNameSet.insert(phoHLTFilterNames_[i]);
240  //here we are little more complicated as entries are of the form "tightTrig:looseTrig"
241  //so we need to split them first
242  for(size_t tightLooseNr=0;tightLooseNr<eleTightLooseTrigNames_.size();tightLooseNr++){
243  std::vector<std::string> trigNames;
244  boost::split(trigNames,eleTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
245  if(trigNames.size()!=2) continue; //format incorrect
246  filterNameSet.insert(trigNames[0]);
247  filterNameSet.insert(trigNames[1]);
248  }
249  for(size_t tightLooseNr=0;tightLooseNr<diEleTightLooseTrigNames_.size();tightLooseNr++){
250  std::vector<std::string> trigNames;
251  boost::split(trigNames,diEleTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
252  if(trigNames.size()!=2) continue; //format incorrect
253  filterNameSet.insert(trigNames[0]);
254  filterNameSet.insert(trigNames[1]);
255  }
256  for(size_t tightLooseNr=0;tightLooseNr<phoTightLooseTrigNames_.size();tightLooseNr++){
257  std::vector<std::string> trigNames;
258  boost::split(trigNames,phoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
259  if(trigNames.size()!=2) continue; //format incorrect
260  filterNameSet.insert(trigNames[0]);
261  filterNameSet.insert(trigNames[1]);
262  }
263  for(size_t tightLooseNr=0;tightLooseNr<diPhoTightLooseTrigNames_.size();tightLooseNr++){
264  std::vector<std::string> trigNames;
265  boost::split(trigNames,diPhoTightLooseTrigNames_[tightLooseNr],boost::is_any_of(std::string(":")));
266  if(trigNames.size()!=2) continue; //format incorrect
267  filterNameSet.insert(trigNames[0]);
268  filterNameSet.insert(trigNames[1]);
269  }
270  //right all the triggers are inserted once and only once in the set, convert to vector
271  //very lazy, create a new vector so can use the constructor and then use swap to transfer
272  std::vector<std::string>(filterNameSet.begin(),filterNameSet.end()).swap(filterNames);
273 }
274 
276 {
277 
278  std::vector<std::string> activeFilters;
279  std::vector<std::string> activeEleFilters;
280  std::vector<std::string> activeEle2LegFilters;
281  std::vector<std::string> activePhoFilters;
282  std::vector<std::string> activePho2LegFilters;
283 
284  trigTools::getActiveFilters(hltConfig,activeFilters,activeEleFilters,activeEle2LegFilters,activePhoFilters,activePho2LegFilters);
285 
293 }
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
std::vector< std::string > diPhoTightLooseTrigNames_
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual void beginJob()
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
egHLT::OffHelper offEvtHelper_
MonitorElement * dqmErrsMonElem_
std::vector< egHLT::EleHLTFilterMon * > eleFilterMonHists_
std::vector< std::string > phoTightLooseTrigNames_
void initTightLooseTrigHists(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::vector< std::string > &tightLooseTrigs, const BinData &bins, EgHLTDQMCut< OffEle > *eleCut)
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 Fill(long long x)
std::vector< egHLT::PhoHLTFilterMon * > phoFilterMonHists_
int iEvent
Definition: GenABIO.cc:243
void addPhoTrigPath(const std::string &name)
void getHLTFilterNamesUsed(std::vector< std::string > &filterNames) const
void setVerbose(unsigned level)
Definition: DQMStore.cc:548
std::vector< std::string > eleTightLooseTrigNames_
void addEleTrigPath(const std::string &name)
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
void initTrigTagProbeHist_2Leg(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::string filterName, int cutMask, const BinData &bins)
std::vector< std::string > phoHLTFilterNames_
MonitorElement * nrEventsProcessedMonElem_
void setup(const edm::ParameterSet &conf)
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)
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
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void filterTriggers(const HLTConfigProvider &hltConfig)
egHLT::BinData binData_
void filterInactiveTriggers(std::vector< std::string > &namesToFilter, std::vector< std::string > &activeFilters)
egHLT::CutMasks cutMasks_
volatile std::atomic< bool > shutdown_flag false
int weight
Definition: histoStyle.py:50
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:779
void filterInactiveTightLooseTriggers(std::vector< std::string > &namesToFilter, const std::vector< std::string > &activeFilters)
virtual void endRun(const edm::Run &run, const edm::EventSetup &c)
void initTrigTagProbeHist(std::vector< MonElemContainer< OffEle > * > &eleMonElems, const std::string filterName, int cutMask, const BinData &bins)
void setupTriggers(const HLTConfigProvider &config, const std::vector< std::string > &hltFiltersUsed)
EgHLTOfflineSource(const EgHLTOfflineSource &rhs)
double split
Definition: MVATrainer.cc:139
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
Definition: Run.h:41
int makeOffEvt(const edm::Event &edmEvent, const edm::EventSetup &setup, egHLT::OffEvt &offEvent)
virtual void beginRun(const edm::Run &run, const edm::EventSetup &c)
void setup(const edm::ParameterSet &conf)
Definition: EgHLTCutMasks.h:23