CMS 3D CMS Logo

EgHLTOfflineSource.cc
Go to the documentation of this file.
2 
5 
8 
10 
13 
14 #include <boost/algorithm/string.hpp>
15 
16 //#include "DQMOffline/Trigger/interface/EgHLTCutCodes.h"
20 using namespace egHLT;
21 
22 EgHLTOfflineSource::EgHLTOfflineSource(const edm::ParameterSet& iConfig) : nrEventsProcessed_(0) {
23  binData_.setup(iConfig.getParameter<edm::ParameterSet>("binData"));
24  cutMasks_.setup(iConfig.getParameter<edm::ParameterSet>("cutMasks"));
25  eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
26  eleHLTFilterNames2Leg_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames2Leg");
27  phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
28  eleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("eleTightLooseTrigNames");
29  diEleTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diEleTightLooseTrigNames");
30  phoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("phoTightLooseTrigNames");
31  diPhoTightLooseTrigNames_ = iConfig.getParameter<std::vector<std::string> >("diPhoTightLooseTrigNames");
32 
33  filterInactiveTriggers_ = iConfig.getParameter<bool>("filterInactiveTriggers");
34  hltTag_ = iConfig.getParameter<std::string>("hltTag");
35  dohep_ = iConfig.getParameter<bool>("doHEP");
36 
38  "DQMDirName"); //"HLT/EgHLTOfflineSource_" + iConfig.getParameter<std::string>("@module_label");
39 
40  subdirName_ = iConfig.getParameter<std::string>("subDQMDirName");
41 
42  offEvtHelper_.setup(iConfig, consumesCollector());
43 }
44 
46  // LogDebug("EgHLTOfflineSource") << "destructor called";
47  for (auto& eleFilterMonHist : eleFilterMonHists_) {
48  delete eleFilterMonHist;
49  }
50  for (auto& phoFilterMonHist : phoFilterMonHists_) {
51  delete phoFilterMonHist;
52  }
53  for (auto& eleMonElem : eleMonElems_) {
54  delete eleMonElem;
55  }
56  for (auto& phoMonElem : phoMonElems_) {
57  delete phoMonElem;
58  }
59 }
60 
62  iBooker.setCurrentFolder(dirName_);
63 
64  //the one monitor element the source fills directly
65  dqmErrsMonElem_ = iBooker.book1D("dqmErrors", "EgHLTOfflineSource Errors", 101, -0.5, 100.5);
66  nrEventsProcessedMonElem_ = iBooker.bookInt("nrEventsProcessed");
67 
68  //if the HLTConfig changes during the job, the results are "un predictable" but in practice should be fine
69  //the HLTConfig is used for working out which triggers are active, working out which filternames correspond to paths and L1 seeds
70  //assuming those dont change for E/g it *should* be fine
72  bool changed = false;
73  hltConfig.init(run, c, hltTag_, changed);
76 
77  std::vector<std::string> hltFiltersUsed;
78  getHLTFilterNamesUsed(hltFiltersUsed);
79  trigCodes.reset(TrigCodes::makeCodes(hltFiltersUsed));
80 
82 
83  MonElemFuncs monElemFuncs(iBooker, *trigCodes);
84 
85  //now book ME's
86  iBooker.setCurrentFolder(dirName_ + "/" + subdirName_);
87  //each trigger path with generate object distributions and efficiencies (BUT not trigger efficiencies...)
88  for (auto const& eleHLTFilterName : eleHLTFilterNames_) {
89  iBooker.setCurrentFolder(dirName_ + "/" + subdirName_ + "/" + eleHLTFilterName);
90  addEleTrigPath(monElemFuncs, eleHLTFilterName);
91  }
92  for (auto const& phoHLTFilterName : phoHLTFilterNames_) {
93  iBooker.setCurrentFolder(dirName_ + "/" + subdirName_ + "/" + phoHLTFilterName);
94  addPhoTrigPath(monElemFuncs, phoHLTFilterName);
95  }
96  //efficiencies of one trigger path relative to another
98  //new EgHLTDQMVarCut<OffEle>(cutMasks_.stdEle,&OffEle::cutCode));
99  //monElemFuncs.initTightLooseTrigHistsTrigCuts(eleMonElems_,eleTightLooseTrigNames_,binData_);
100 
102  // new EgHLTDQMVarCut<OffPho>(cutMasks_.stdPho,&OffPho::cutCode));
103  //monElemFuncs.initTightLooseTrigHistsTrigCuts(phoMonElems_,phoTightLooseTrigNames_,binData_);
104 
105  //di-object triggers
107  // new EgDiEleCut(cutMasks_.stdEle,&OffEle::cutCode));
109  // new EgDiPhoCut(cutMasks_.stdPho,&OffPho::cutCode));
110 
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  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  for (auto& eleFilterMonHist : eleFilterMonHists_) {
151  eleFilterMonHist->fill(offEvt_, weight);
152  }
153  for (auto& phoFilterMonHist : phoFilterMonHists_) {
154  phoFilterMonHist->fill(offEvt_, weight);
155  }
156 
157  for (auto& eleMonElem : eleMonElems_) {
158  const std::vector<OffEle>& eles = offEvt_.eles();
159  for (auto const& ele : eles) {
160  eleMonElem->fill(ele, offEvt_, weight);
161  }
162  }
163 
164  for (auto& phoMonElem : phoMonElems_) {
165  const std::vector<OffPho>& phos = offEvt_.phos();
166  for (auto const& pho : phos) {
167  phoMonElem->fill(pho, offEvt_, weight);
168  }
169  }
170 }
171 
173  auto* filterMon =
174  new EleHLTFilterMon(monElemFuncs, name, trigCodes->getCode(name.c_str()), binData_, cutMasks_, dohep_);
175  eleFilterMonHists_.push_back(filterMon);
176  std::sort(eleFilterMonHists_.begin(), eleFilterMonHists_.end(), [](auto const& x, auto const& y) { return *x < *y; });
177  //takes a minor efficiency hit at initalisation to ensure that the vector is always sorted
178 }
179 
181  PhoHLTFilterMon* filterMon =
182  new PhoHLTFilterMon(monElemFuncs, name, trigCodes->getCode(name.c_str()), binData_, cutMasks_, dohep_);
183  phoFilterMonHists_.push_back(filterMon);
184  std::sort(phoFilterMonHists_.begin(), phoFilterMonHists_.end(), [](auto const& x, auto const& y) { return *x < *y; });
185  //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  std::set<std::string> filterNameSet;
197  for (auto const& eleHLTFilterName : eleHLTFilterNames_)
198  filterNameSet.insert(eleHLTFilterName);
199  for (auto const& phoHLTFilterName : phoHLTFilterNames_)
200  filterNameSet.insert(phoHLTFilterName);
201  //here we are little more complicated as entries are of the form "tightTrig:looseTrig"
202  //so we need to split them first
203  for (auto const& eleTightLooseTrigName : eleTightLooseTrigNames_) {
204  std::vector<std::string> trigNames;
205  boost::split(trigNames, eleTightLooseTrigName, boost::is_any_of(std::string(":")));
206  if (trigNames.size() != 2)
207  continue; //format incorrect
208  filterNameSet.insert(trigNames[0]);
209  filterNameSet.insert(trigNames[1]);
210  }
211  for (auto const& diEleTightLooseTrigName : diEleTightLooseTrigNames_) {
212  std::vector<std::string> trigNames;
213  boost::split(trigNames, diEleTightLooseTrigName, boost::is_any_of(std::string(":")));
214  if (trigNames.size() != 2)
215  continue; //format incorrect
216  filterNameSet.insert(trigNames[0]);
217  filterNameSet.insert(trigNames[1]);
218  }
219  for (auto const& phoTightLooseTrigName : phoTightLooseTrigNames_) {
220  std::vector<std::string> trigNames;
221  boost::split(trigNames, phoTightLooseTrigName, boost::is_any_of(std::string(":")));
222  if (trigNames.size() != 2)
223  continue; //format incorrect
224  filterNameSet.insert(trigNames[0]);
225  filterNameSet.insert(trigNames[1]);
226  }
227  for (auto const& diPhoTightLooseTrigName : diPhoTightLooseTrigNames_) {
228  std::vector<std::string> trigNames;
229  boost::split(trigNames, diPhoTightLooseTrigName, boost::is_any_of(std::string(":")));
230  if (trigNames.size() != 2)
231  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  std::vector<std::string> activeFilters;
242  std::vector<std::string> activeEleFilters;
243  std::vector<std::string> activeEle2LegFilters;
244  std::vector<std::string> activePhoFilters;
245  std::vector<std::string> activePho2LegFilters;
246 
248  hltConfig, activeFilters, activeEleFilters, activeEle2LegFilters, activePhoFilters, activePho2LegFilters);
249 
257 }
258 
std::vector< std::string > diPhoTightLooseTrigNames_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void initTightLooseDiObjTrigHistsTrigCuts(std::vector< MonElemContainer< OffEle > *> &eleMonElems, const std::vector< std::string > &tightLooseTrigs, const BinData &bins)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
egHLT::OffHelper offEvtHelper_
MonitorElement * dqmErrsMonElem_
std::vector< egHLT::EleHLTFilterMon * > eleFilterMonHists_
std::vector< std::string > phoTightLooseTrigNames_
const std::vector< OffEle > & eles() const
Definition: EgHLTOffEvt.h:48
Definition: weight.py:1
const std::vector< OffPho > & phos() const
Definition: EgHLTOffEvt.h:50
std::vector< std::string > eleHLTFilterNames2Leg_
void setup(const edm::ParameterSet &conf)
Definition: EgHLTBinData.cc:5
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
std::vector< egHLT::MonElemContainer< egHLT::OffEle > * > eleMonElems_
void addEleTrigPath(egHLT::MonElemFuncs &monElemFuncs, const std::string &name)
std::vector< egHLT::PhoHLTFilterMon * > phoFilterMonHists_
void initTightLooseTrigHists(std::vector< MonElemContainer< OffEle > *> &eleMonElems, const std::vector< std::string > &tightLooseTrigs, const BinData &bins, EgHLTDQMCut< OffEle > *eleCut)
void Fill(long long x)
EgHLTOfflineSource(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
void addPhoTrigPath(egHLT::MonElemFuncs &monElemFuncs, const std::string &name)
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~EgHLTOfflineSource() override
std::vector< std::string > eleTightLooseTrigNames_
std::vector< egHLT::MonElemContainer< egHLT::OffPho > * > phoMonElems_
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:57
void initTrigTagProbeHist(std::vector< MonElemContainer< OffEle > *> &eleMonElems, const std::string &filterName, int cutMask, const BinData &bins)
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)
MonitorElement * bookInt(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:73
std::vector< std::string > diEleTightLooseTrigNames_
std::vector< std::string > eleHLTFilterNames_
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 setupTriggers(const HLTConfigProvider &config, const std::vector< std::string > &hltFiltersUsed, const TrigCodes &trigCodes)
egHLT::CutMasks cutMasks_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void filterInactiveTightLooseTriggers(std::vector< std::string > &namesToFilter, const std::vector< std::string > &activeFilters)
void getHLTFilterNamesUsed(std::vector< std::string > &filterNames) const
void initTrigTagProbeHist_2Leg(std::vector< MonElemContainer< OffEle > *> &eleMonElems, const std::string &filterName, int cutMask, const BinData &bins)
Definition: Run.h:45
void setup(const edm::ParameterSet &conf)
Definition: EgHLTCutMasks.h:21