CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EgHLTOfflineSummaryClient.cc
Go to the documentation of this file.
2 
7 
9 
11 
14 #include <boost/algorithm/string.hpp>
15 #include <fnmatch.h>
16 
18  : egHLTSumHistName_("egHLTTrigSum"), isSetup_(false) {
20  "DQMDirName"); //only one chance to get this, if we every have another shot, remember to check isSetup is okay
22  if (!dbe_) {
23  edm::LogError("EgHLTOfflineSummaryClient")
24  << "unable to get DQMStore service, no summary histograms will be produced";
25  } else {
26  dbe_->setCurrentFolder(dirName_);
27  }
28 
29  eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
30  phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
31  eleHLTFilterNamesForSumBit_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNamesForSumBit");
32  phoHLTFilterNamesForSumBit_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNamesForSumBit");
33 
34  filterInactiveTriggers_ = iConfig.getParameter<bool>("filterInactiveTriggers");
35  hltTag_ = iConfig.getParameter<std::string>("hltTag");
36 
37  usePathNames_ = iConfig.getParameter<bool>("usePathNames");
38 
39  //std::vector<std::string> egHLTSumQTests = iConfig.getParameter<std::vector<std::string> >("egHLTSumQTests");
40  // splitStringsToPairs_(egHLTSumQTests,egHLTSumHistXBins_);
41 
42  fillQTestData_(iConfig, egHLTSumHistXBins_, "egHLTSumQTests");
43  fillQTestData_(iConfig, eleQTestsForSumBit_, "egHLTEleQTestsForSumBit");
44  fillQTestData_(iConfig, phoQTestsForSumBit_, "egHLTPhoQTestsForSumBit");
45 
46  runClientEndLumiBlock_ = iConfig.getParameter<bool>("runClientEndLumiBlock");
47  runClientEndRun_ = iConfig.getParameter<bool>("runClientEndRun");
48  runClientEndJob_ = iConfig.getParameter<bool>("runClientEndJob");
49 
50  //egHLTSumHistXBins_.push_back(std::make_pair("Ele Rel Trig Eff",&EgHLTOfflineSummaryClient::eleTrigRelEffQTestResult_));
51  //egHLTSumHistXBins_.push_back(std::make_pair("Pho Rel Trig Eff",&EgHLTOfflineSummaryClient::phoTrigRelEffQTestResult_));
52  //egHLTSumHistXBins_.push_back(std::make_pair("Ele T&P Trig Eff",&EgHLTOfflineSummaryClient::eleTrigTPEffQTestResult_));
53  //egHLTSumHistXBins_.push_back(std::make_pair("Triggered Ele",&EgHLTOfflineSummaryClient::trigEleQTestResult_));
54  //egHLTSumHistXBins_.push_back(std::make_pair("Triggered Pho",&EgHLTOfflineSummaryClient::trigPhoQTestResult_));
55 }
56 
58 
60 
62  if (runClientEndJob_)
63  runClient_();
64 }
65 
67  if (!isSetup_) {
68  bool changed;
70  hltConfig.init(run, c, hltTag_, changed);
72  std::vector<std::string> activeFilters;
73  std::vector<std::string> activeEleFilters;
74  std::vector<std::string> activeEle2LegFilters;
75  std::vector<std::string> activePhoFilters;
76  std::vector<std::string> activePho2LegFilters;
77 
79  hltConfig, activeFilters, activeEleFilters, activeEle2LegFilters, activePhoFilters, activePho2LegFilters);
80 
85  }
87 
88  if (usePathNames_)
90  isSetup_ = true;
91  }
92 }
93 
95  if (runClientEndRun_)
96  runClient_();
97 }
98 
99 //dummy analysis function
101 
104  runClient_();
105 }
106 
108  MonitorElement* egHLTSumME = getEgHLTSumHist_();
109 
110  for (size_t filterNr = 0; filterNr < egHLTFiltersToMon_.size(); filterNr++) {
111  for (size_t xBinNr = 0; xBinNr < egHLTSumHistXBins_.size(); xBinNr++) {
112  //egHLTSumHist->setBinContent(xBinNr+1,filterNr+1,(*egHLTSumHistXBins_[xBinNr].second)(egHLTFiltersToMon_[filterNr].c_str()));
113  egHLTSumME->setBinContent(
114  xBinNr + 1,
115  filterNr + 1,
116  getQTestResults_(egHLTFiltersToMon_[filterNr], egHLTSumHistXBins_[xBinNr].qTestPatterns));
117  }
118  }
119 
120  MonitorElement* hltEleSumBit = dbe_->get("HLT/EventInfo/reportSummaryContents/HLT_Electron");
121  MonitorElement* hltPhoSumBit = dbe_->get("HLT/EventInfo/reportSummaryContents/HLT_Photon");
122  dbe_->setCurrentFolder("HLT/EventInfo/reportSummaryContents/");
123  if (hltEleSumBit == nullptr)
124  hltEleSumBit = dbe_->bookFloat("HLT_Electron");
125  if (hltPhoSumBit == nullptr)
126  hltPhoSumBit = dbe_->bookFloat("HLT_Photon");
127 
128  float eleSumBit = 1.;
129  for (size_t filterNr = 0; filterNr < eleHLTFilterNamesForSumBit_.size() && eleSumBit == 1;
130  filterNr++) { //breaks as soon as a test fails
131  for (size_t testNr = 0; testNr < eleQTestsForSumBit_.size() && eleSumBit == 1; testNr++) {
132  if (getQTestResults_(eleHLTFilterNamesForSumBit_[filterNr], eleQTestsForSumBit_[testNr].qTestPatterns) == 0)
133  eleSumBit = 0;
134  }
135  }
136  hltEleSumBit->Fill(eleSumBit);
137 
138  float phoSumBit = 1.;
139  for (size_t filterNr = 0; filterNr < phoHLTFilterNamesForSumBit_.size() && phoSumBit == 1;
140  filterNr++) { //breaks as soon as a test fails
141  for (size_t testNr = 0; testNr < phoQTestsForSumBit_.size() && phoSumBit == 1; testNr++) {
142  if (getQTestResults_(phoHLTFilterNamesForSumBit_[filterNr], phoQTestsForSumBit_[testNr].qTestPatterns) == 0)
143  phoSumBit = 0;
144  }
145  }
146  hltPhoSumBit->Fill(phoSumBit);
147 }
148 void EgHLTOfflineSummaryClient::splitStringsToPairs_(const std::vector<std::string>& stringsToSplit,
149  std::vector<std::pair<std::string, std::string> >& splitStrings) {
150  splitStrings.clear();
151  splitStrings.reserve(stringsToSplit.size());
152  for (auto const& stringNr : stringsToSplit) {
153  std::vector<std::string> tempSplitStrings;
154  boost::split(tempSplitStrings, stringNr, boost::is_any_of(std::string(":")));
155  if (tempSplitStrings.size() == 2) {
156  splitStrings.push_back(std::make_pair(tempSplitStrings[0], tempSplitStrings[1]));
157  } else {
158  edm::LogWarning("EgHLTOfflineSummaryClient")
159  << " Error : entry " << stringNr
160  << " is not of form A:B, ignoring (ie this quailty test isnt being included in the sumamry hist) ";
161  }
162  }
163 }
164 
166  MonitorElement* egHLTSumHist = dbe_->get(dirName_ + "/" + egHLTSumHistName_);
167  if (egHLTSumHist == nullptr) {
168  auto* hist = new TH2F(egHLTSumHistName_.c_str(),
169  "E/g HLT Offline Summary",
170  egHLTSumHistXBins_.size(),
171  0.,
172  1.,
173  egHLTFiltersToMon_.size(),
174  0.,
175  1.);
176  for (size_t xBinNr = 0; xBinNr < egHLTSumHistXBins_.size(); xBinNr++) {
177  hist->GetXaxis()->SetBinLabel(xBinNr + 1, egHLTSumHistXBins_[xBinNr].name.c_str());
178  }
179 
180  for (size_t yBinNr = 0; yBinNr < egHLTFiltersToMon_.size(); yBinNr++) {
181  if (usePathNames_ && egHLTFiltersToMonPaths_.size() == egHLTFiltersToMon_.size()) {
182  hist->GetYaxis()->SetBinLabel(yBinNr + 1, egHLTFiltersToMonPaths_[yBinNr].c_str());
183  } else {
184  hist->GetYaxis()->SetBinLabel(yBinNr + 1, egHLTFiltersToMon_[yBinNr].c_str());
185  }
186  }
187  for (size_t xBinNr = 0; xBinNr < egHLTSumHistXBins_.size(); xBinNr++) {
188  for (size_t yBinNr = 0; yBinNr < egHLTFiltersToMon_.size(); yBinNr++) {
189  hist->SetBinContent(xBinNr + 1, yBinNr + 1, -2);
190  }
191  }
192 
194  egHLTSumHist = dbe_->book2D(egHLTSumHistName_, hist);
195  }
196  return egHLTSumHist;
197 }
198 
199 //this function puts every e/g trigger monitored in a std::vector
200 //this is *very* similar to EgHLTOfflineSource::getHLTFilterNamesUsed but
201 //it differs in the fact it only gets the E/g primary triggers not the backups
202 //due to the design, to ensure we get every filter, filters will be inserted multiple times
203 //eg electron filters will contain photon triggers which are also in the photon filters
204 //but only want one copy in the vector
205 //this function is intended to be called once per job so some inefficiency can can be tolerated
206 //therefore we will use a std::set to ensure ensure that each filtername is only inserted once
207 //and then convert to a std::vector
208 void EgHLTOfflineSummaryClient::getEgHLTFiltersToMon_(std::vector<std::string>& filterNames) const {
209  std::set<std::string> filterNameSet;
210  for (auto const& eleHLTFilterName : eleHLTFilterNames_)
211  filterNameSet.insert(eleHLTFilterName);
212  for (auto const& phoHLTFilterName : phoHLTFilterNames_)
213  filterNameSet.insert(phoHLTFilterName);
214 
215  //right all the triggers are inserted once and only once in the set, convert to vector
216  //very lazy, create a new vector so can use the constructor and then use swap to transfer
217  std::vector<std::string>(filterNameSet.begin(), filterNameSet.end()).swap(filterNames);
218 }
219 
220 //only returns 0 or 1, 0 is bad, one is good and if the test is not found defaults to good
221 //(this is because its a dumb algorithm, photon tests are run for electron triggers which unsurprisingly are not found)
223  const std::vector<std::string>& patterns) const {
224  int nrFail = 0;
225  int nrQTests = 0;
226  for (auto const& pattern : patterns) {
227  auto filterpattern = filterName + pattern;
228  std::vector<MonitorElement*> monElems = dbe_->getAllContents(dirName_);
229  // std::cout <<"mon elem "<<dirName_+"/"+filterName+patterns[patternNr]<<"nr monElems "<<monElems.size()<<std::endl;
230  for (auto& monElem : monElems) {
231  const auto& name = monElem->getName();
232  int match = fnmatch(filterpattern.c_str(), name.c_str(), 0);
233  if (match == FNM_NOMATCH)
234  continue;
235 
236  std::vector<QReport*> qTests = monElem->getQReports();
237  nrQTests += qTests.size();
238  // std::cout <<monElems[monElemNr]->getName()<<" "<<monElems[monElemNr]->hasError()<<" nr test "<<qTests.size()<<std::endl;
239  if (monElem->hasError())
240  nrFail++;
241  }
242  }
243  if (nrQTests == 0)
244  return -1;
245  else if (nrFail == 0)
246  return 1;
247  else
248  return 0;
249 }
250 
252  std::vector<SumHistBinData>& qTests,
253  const std::string& label) {
254  std::vector<edm::ParameterSet> qTestPara = iConfig.getParameter<std::vector<edm::ParameterSet> >(label);
255  qTests.resize(qTestPara.size());
256  for (size_t testNr = 0; testNr < qTestPara.size(); testNr++) {
257  qTests[testNr].name = qTestPara[testNr].getParameter<std::string>("name");
258  qTests[testNr].qTestPatterns = qTestPara[testNr].getParameter<std::vector<std::string> >("qTestsToCheck");
259  }
260 }
261 
262 // int EgHLTOfflineSummaryClient::eleTrigRelEffQTestResult_(const std::string& filterName)const
263 // {
264 
265 // }
266 
267 // int EgHLTOfflineSummaryClient::phoTrigRelEffQTestResult_(const std::string& filterName)const
268 // {
269 
270 // }
271 
272 // int EgHLTOfflineSummaryClient::eleTrigTPEffQTestResult_(const std::string& filterName)const
273 // {
274 
275 // }
276 
277 // int EgHLTOfflineSummaryClient::trigEleQTestResult_(const std::string& filterName)const
278 // {
279 
280 // }
281 
282 // int EgHLTOfflineSummaryClient::trigPhoQTestResult_(const std::string& filterName)const
283 // {
284 
285 // }
std::vector< std::string > phoHLTFilterNamesForSumBit_
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
const edm::EventSetup & c
void splitStringsToPairs_(const std::vector< std::string > &stringsToSplit, std::vector< std::pair< std::string, std::string > > &splitStrings)
std::vector< std::string > egHLTFiltersToMonPaths_
void getEgHLTFiltersToMon_(std::vector< std::string > &filterNames) const
std::vector< std::string > eleHLTFilterNamesForSumBit_
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:569
std::vector< SumHistBinData > egHLTSumHistXBins_
std::vector< std::string > eleHLTFilterNames_
std::vector< SumHistBinData > eleQTestsForSumBit_
std::vector< std::string > egHLTFiltersToMon_
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
Log< level::Error, false > LogError
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
Definition: DQMStore.cc:609
void endRun(const edm::Run &run, const edm::EventSetup &c) override
void Fill(long long x)
char const * label
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
void analyze(const edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
~EgHLTOfflineSummaryClient() override
std::vector< SumHistBinData > phoQTestsForSumBit_
__shared__ Hist hist
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
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
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< std::string > phoHLTFilterNames_
int getQTestResults_(const std::string &filterName, const std::vector< std::string > &pattern) const
void filterInactiveTriggers(std::vector< std::string > &namesToFilter, std::vector< std::string > &activeFilters)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
EgHLTOfflineSummaryClient(const EgHLTOfflineSummaryClient &rhs)
Log< level::Warning, false > LogWarning
void translateFiltersToPathNames(const HLTConfigProvider &hltConfig, const std::vector< std::string > &filters, std::vector< std::string > &paths)
Definition: Run.h:45
static void fillQTestData_(const edm::ParameterSet &iConfig, std::vector< SumHistBinData > &qTests, const std::string &label)