CMS 3D CMS Logo

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