CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackingQualityChecker.cc
Go to the documentation of this file.
6 
8 
10 
14 
16 
19 
20 
21 #include <iomanip>
22 //
23 // -- Constructor
24 //
26  pSet_(ps)
27 {
28  edm::LogInfo("TrackingQualityChecker") << " Creating TrackingQualityChecker " << "\n" ;
29 
32 
33  if(!edm::Service<TkDetMap>().isAvailable()){
34  edm::LogError("TkHistoMap") <<
35  "\n------------------------------------------"
36  "\nUnAvailable Service TkHistoMap: please insert in the configuration file an instance like"
37  "\n\tprocess.TkDetMap = cms.Service(\"TkDetMap\")"
38  "\n------------------------------------------";
39  }
40 
41  TopFolderName_ = pSet_.getUntrackedParameter<std::string>("TopFolderName","Tracking");
42 
43  TrackingMEs tracking_mes;
44  std::vector<edm::ParameterSet> TrackingGlobalQualityMEs = pSet_.getParameter< std::vector<edm::ParameterSet> >("TrackingGlobalQualityPSets" );
45  for ( auto meQTset : TrackingGlobalQualityMEs ) {
46 
47  std::string QTname = meQTset.getParameter<std::string>("QT");
48  tracking_mes.HistoDir = meQTset.getParameter<std::string>("dir");
49  tracking_mes.HistoName = meQTset.getParameter<std::string>("name");
50  // std::cout << "[TrackingQualityChecker::TrackingQualityChecker] inserting " << QTname << " in TrackingMEsMap" << std::endl;
51  TrackingMEsMap.insert(std::pair<std::string, TrackingMEs>(QTname, tracking_mes));
52  }
53  // std::cout << "[TrackingQualityChecker::TrackingQualityChecker] created TrackingMEsMap" << std::endl;
54 
55  TrackingLSMEs tracking_ls_mes;
56  std::vector<edm::ParameterSet> TrackingLSQualityMEs = pSet_.getParameter< std::vector<edm::ParameterSet> >("TrackingLSQualityPSets" );
57  for ( auto meQTset : TrackingLSQualityMEs ) {
58 
59  std::string QTname = meQTset.getParameter<std::string>("QT");
60  tracking_ls_mes.HistoLSDir = meQTset.exists("LSdir") ? meQTset.getParameter<std::string>("LSdir") : "";
61  tracking_ls_mes.HistoLSName = meQTset.exists("LSname") ? meQTset.getParameter<std::string>("LSname") : "";
62  tracking_ls_mes.HistoLSLowerCut = meQTset.exists("LSlowerCut") ? meQTset.getParameter<double>("LSlowerCut") : -1.;
63  tracking_ls_mes.HistoLSUpperCut = meQTset.exists("LSupperCut") ? meQTset.getParameter<double>("LSupperCut") : -1.;
64  tracking_ls_mes.TrackingFlag = 0;
65 
66  // std::cout << "[TrackingQualityChecker::TrackingQualityChecker] inserting " << QTname << " in TrackingMEsMap" << std::endl;
67  TrackingLSMEsMap.insert(std::pair<std::string, TrackingLSMEs>(QTname, tracking_ls_mes));
68  }
69  // std::cout << "[TrackingQualityChecker::TrackingQualityChecker] created TrackingLSMEsMap" << std::endl;
70 
71 }
72 //
73 // -- Destructor
74 //
76  edm::LogInfo("TrackingQualityChecker") << " Deleting TrackingQualityChecker " << "\n" ;
77 }
78 //
79 // -- create reportSummary MEs
80 //
82 
83  // std::cout << "[TrackingQualityChecker::bookGlobalStatus] already booked ? " << (bookedTrackingGlobalStatus_ ? "yes" : "nope") << std::endl;
84 
86  dqm_store->cd();
87  edm::LogInfo("TrackingQualityChecker") << " booking TrackingQualityStatus" << "\n";
88 
89  std::string tracking_dir = "";
90  TrackingUtility::getTopFolderPath(dqm_store, TopFolderName_, tracking_dir);
91  dqm_store->setCurrentFolder(TopFolderName_+"/EventInfo");
92 
93  TrackGlobalSummaryReportGlobal = dqm_store->bookFloat("reportSummary");
94 
95  std::string hname, htitle;
96  hname = "reportSummaryMap";
97  htitle = "Tracking Report Summary Map";
98 
99  size_t nQT = TrackingMEsMap.size();
100  // std::cout << "[TrackingQualityChecker::bookGlobalStatus] nQT: " << nQT << std::endl;
101  TrackGlobalSummaryReportMap = dqm_store->book2D(hname, htitle, nQT,0.5,float(nQT)+0.5,1,0.5,1.5);
102  TrackGlobalSummaryReportMap->setAxisTitle("Track Quality Type", 1);
103  TrackGlobalSummaryReportMap->setAxisTitle("QTest Flag", 2);
104  size_t ibin =0;
105  for ( auto meQTset : TrackingMEsMap ) {
106  TrackGlobalSummaryReportMap->setBinLabel(ibin+1,meQTset.first);
107  ibin++;
108  }
109 
110  dqm_store->setCurrentFolder(TopFolderName_+"/EventInfo/reportSummaryContents");
111 
112  for (std::map<std::string, TrackingMEs>::iterator it = TrackingMEsMap.begin();
113  it != TrackingMEsMap.end(); it++) {
114  std::string meQTname = it->first;
115  it->second.TrackingFlag = dqm_store->bookFloat("Track"+meQTname);
116  // std::cout << "[TrackingQualityChecker::bookGlobalStatus] " << it->first << " exists ? " << it->second.TrackingFlag << std::endl;
117  // std::cout << "[TrackingQualityChecker::bookGlobalStatus] DONE w/ TrackingMEsMap" << std::endl;
118  }
119 
121  dqm_store->cd();
122  }
123 }
124 
126 
127  // std::cout << "[TrackingQualityChecker::bookLSStatus] already booked ? " << (bookedTrackingLSStatus_ ? "yes" : "nope") << std::endl;
128 
130  dqm_store->cd();
131  edm::LogInfo("TrackingQualityChecker") << " booking TrackingQualityStatus" << "\n";
132 
133  std::string tracking_dir = "";
134  TrackingUtility::getTopFolderPath(dqm_store, TopFolderName_, tracking_dir);
135  dqm_store->setCurrentFolder(TopFolderName_+"/EventInfo");
136 
137  TrackLSSummaryReportGlobal = dqm_store->bookFloat("reportSummary");
138 
139  std::string hname, htitle;
140  hname = "reportSummaryMap";
141  htitle = "Tracking Report Summary Map";
142 
143  // size_t nQT = TrackingLSMEsMap.size();
144  // std::cout << "[TrackingQualityChecker::bookLSStatus] nQT: " << nQT << std::endl;
145 
146  dqm_store->setCurrentFolder(TopFolderName_+"/EventInfo/reportSummaryContents");
147  for (std::map<std::string, TrackingLSMEs>::iterator it = TrackingLSMEsMap.begin();
148  it != TrackingLSMEsMap.end(); it++) {
149  std::string meQTname = it->first;
150  it->second.TrackingFlag = dqm_store->bookFloat("Track"+meQTname);
151  // std::cout << "[TrackingQualityChecker::bookLSStatus] " << it->first << " exists ? " << it->second.TrackingFlag << std::endl;
152  // std::cout << "[TrackingQualityChecker::bookLSStatus] DONE w/ TrackingLSMEsMap" << std::endl;
153  }
154 
156  dqm_store->cd();
157  }
158 }
159 
160 //
161 // -- Fill Dummy Status
162 //
164  // std::cout << "[TrackingQualityChecker::fillDummyGlobalStatus] starting ..." << std::endl;
165 
167  // std::cout << "[TrackingQualityChecker::fillDummyGlobalStatus] already booked ? " << (bookedTrackingGlobalStatus_ ? "yes" : "nope") << std::endl;
169 
171 
172  for (int ibin = 1; ibin < TrackGlobalSummaryReportMap->getNbinsX()+1; ibin++) {
174  }
175 
176  for (std::map<std::string, TrackingMEs>::iterator it = TrackingMEsMap.begin();
177  it != TrackingMEsMap.end(); it++)
178  it->second.TrackingFlag->Fill(-1.0);
179  // std::cout << "[TrackingQualityChecker::fillDummyGlobalStatus] DONE w/ TrackingMEsMap" << std::endl;
180 
181  }
182 }
184  // std::cout << "[TrackingQualityChecker::fillDummyLSStatus] starting ..." << std::endl;
185 
186  resetLSStatus();
187  // std::cout << "[TrackingQualityChecker::fillDummyLSStatus] already booked ? " << (bookedTrackingLSStatus_ ? "yes" : "nope") << std::endl;
189 
191  for (std::map<std::string, TrackingLSMEs>::iterator it = TrackingLSMEsMap.begin();
192  it != TrackingLSMEsMap.end(); it++)
193  it->second.TrackingFlag->Fill(-1.0);
194  // std::cout << "[TrackingQualityChecker::fillDummyLSStatus] DONE w/ TrackingLSMEsMap" << std::endl;
195 
196  }
197 }
198 
199 //
200 // -- Reset Status
201 //
203 
204  // std::cout << "[TrackingQualityChecker::resetGlobalStatus] already booked ? " << (bookedTrackingGlobalStatus_ ? "yes" : "nope") << std::endl;
206 
209 
210  for (std::map<std::string, TrackingMEs>::iterator it = TrackingMEsMap.begin();
211  it != TrackingMEsMap.end(); it++) {
212  MonitorElement* me = it->second.TrackingFlag;
213  // std::cout << "[TrackingQualityChecker::resetGlobalStatus] " << it->second.HistoName << " exist ? " << ( it->second.TrackingFlag == NULL ? "nope" : "yes" ) << " ---> " << me << std::endl;
214  me->Reset();
215  }
216  // std::cout << "[TrackingQualityChecker::resetGlobalStatus] DONE w/ TrackingMEsMap" << std::endl;
217 
218  }
219 }
221 
222  // std::cout << "[TrackingQualityChecker::resetLSStatus] already booked ? " << (bookedTrackingLSStatus_ ? "yes" : "nope") << std::endl;
224 
226  for (std::map<std::string, TrackingLSMEs>::iterator it = TrackingLSMEsMap.begin();
227  it != TrackingLSMEsMap.end(); it++) {
228  MonitorElement* me = it->second.TrackingFlag;
229  // std::cout << "[TrackingQualityChecker::resetLSStatus] " << it->second.HistoLSName << " exist ? " << ( it->second.TrackingFlag == NULL ? "nope" : "yes" ) << " ---> " << me << std::endl;
230  me->Reset();
231  }
232  // std::cout << "[TrackingQualityChecker::resetLSStatus] DONE w/ TrackingLSMEsMap" << std::endl;
233 
234  }
235 }
236 
237 //
238 // -- Fill Status
239 //
241 
242  // std::cout << "[TrackingQualityChecker::fillGlobalStatus] already booked ? " << (bookedTrackingGlobalStatus_ ? "yes" : "nope") << std::endl;
244 
246  fillTrackingStatus(dqm_store);
247  // std::cout << "[TrackingQualityChecker::fillGlobalStatus] DONE" << std::endl;
248  dqm_store->cd();
249 }
250 
252 
253  // std::cout << "[TrackingQualityChecker::fillLSStatus] already booked ? " << (bookedTrackingLSStatus_ ? "yes" : "nope") << std::endl;
254  if (!bookedTrackingLSStatus_) bookLSStatus(dqm_store);
255 
257  fillTrackingStatusAtLumi(dqm_store);
258  // std::cout << "[TrackingQualityChecker::fillLSStatus] DONE" << std::endl;
259  dqm_store->cd();
260 }
261 
262 //
263 // -- Fill Tracking Status
264 //
266 
267  float gstatus = 0.0;
268 
269  dqm_store->cd();
270  if (!TrackingUtility::goToDir(dqm_store, TopFolderName_)) return;
271 
272 
273  int ibin = 0;
274  for (std::map<std::string, TrackingMEs>::iterator it = TrackingMEsMap.begin();
275  it != TrackingMEsMap.end(); it++) {
276 
277  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
278 
279  ibin++;
280 
281  std::string localMEdirpath = it->second.HistoDir;
282  std::string MEname = it->second.HistoName;
283 
284  std::vector<MonitorElement*> tmpMEvec = dqm_store->getContents(dqm_store->pwd()+"/"+localMEdirpath);
285  MonitorElement* me = NULL;
286 
287  size_t nMEs = 0;
288  for ( auto ime : tmpMEvec ) {
289  std::string name = ime->getName();
290  if ( name.find(MEname) != std::string::npos) {
291  me = ime;
292  nMEs++;
293  }
294  }
295  // only one ME found
296  if (nMEs == 1) {
297  float status = 0.;
298  for ( auto ime : tmpMEvec ) {
299  std::string name = ime->getName();
300  if ( name.find(MEname) != std::string::npos) {
301  me = ime;
302  }
303  }
304  if (!me) continue;
305  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] status: " << status << std::endl;
306  std::vector<QReport *> qt_reports = me->getQReports();
307  size_t nQTme = qt_reports.size();
308  if (nQTme != 0) {
309  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] qt_reports: " << qt_reports.size() << std::endl;
310  // loop on possible QTs
311  for ( auto iQT : qt_reports ) {
312  status += iQT->getQTresult();
313  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] iQT: " << iQT->getQRName() << std::endl;
314  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] MEname: " << MEname << " status: " << iQT->getQTresult() << " exists ? " << (it->second.TrackingFlag ? "yes " : "no ") << it->second.TrackingFlag << std::endl;
315  }
316  status = status/float(nQTme);
317  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] MEname: " << MEname << " status: " << status << std::endl;
318  it->second.TrackingFlag->Fill(status);
319  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] TrackGlobalSummaryReportMap: " << TrackGlobalSummaryReportMap << std::endl;
321  }
322 
323  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] gstatus: " << gstatus << " x status: " << status << std::endl;
324  if ( status < 0. ) gstatus = -1.;
325  else gstatus += status;
326  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] ===> gstatus: " << gstatus << std::endl;
327  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
328 
329  } else { // more than 1 ME w/ the same root => they need to be considered together
330  float status = 1.;
331  for ( auto ime : tmpMEvec ) {
332  float tmp_status = 1.;
333  std::string name = ime->getName();
334  if ( name.find(MEname) != std::string::npos) {
335  me = ime;
336 
337  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] status: " << status << std::endl;
338  std::vector<QReport *> qt_reports = me->getQReports();
339  size_t nQTme = qt_reports.size();
340  if (nQTme != 0) {
341  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] qt_reports: " << qt_reports.size() << std::endl;
342  // loop on possible QTs
343  for ( auto iQT : qt_reports ) {
344  tmp_status += iQT->getQTresult();
345  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] iQT: " << iQT->getQRName() << std::endl;
346  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] MEname: " << MEname << " status: " << iQT->getQTresult() << " exists ? " << (it->second.TrackingFlag ? "yes " : "no ") << it->second.TrackingFlag << std::endl;
347  }
348  tmp_status = tmp_status/float(nQTme);
349  }
350  }
351  status = fminf(tmp_status,status);
352  }
353  if ( status < 0. ) gstatus = -1.;
354  else gstatus += status;
355  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] MEname: " << MEname << " status: " << status << std::endl;
356  it->second.TrackingFlag->Fill(status);
357  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] TrackGlobalSummaryReportMap: " << TrackGlobalSummaryReportMap << std::endl;
358 
360  }
361  }
362 
363  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] gstatus: " << gstatus << std::endl;
364  size_t nQT = TrackingMEsMap.size();
365  if (gstatus < 1.) gstatus = -1.;
366  else gstatus = gstatus/float(nQT);
367 
368  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] ===> gstatus: " << gstatus << std::endl;
370  dqm_store->cd();
371 
372  // std::cout << "[TrackingQualityChecker::fillTrackingStatus] DONE" << std::endl;
373 
374 }
375 
376 //
377 // -- Fill Report Summary Map
378 //
379  void TrackingQualityChecker::fillStatusHistogram(MonitorElement* me, int xbin, int ybin, float val){
380  if (me && me->kind() == MonitorElement::DQM_KIND_TH2F) {
381  TH2F* th2d = me->getTH2F();
382  th2d->SetBinContent(xbin, ybin, val);
383  }
384  }
385 
386 // Fill Tracking Status MEs at the Lumi block
387 //
389 
390  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] starting .. " << std::endl;
391  float gstatus = 1.0;
392 
393  dqm_store->cd();
394  if (!TrackingUtility::goToDir(dqm_store, TopFolderName_)) return;
395 
396 
397  int ibin = 0;
398  for (std::map<std::string, TrackingLSMEs>::iterator it = TrackingLSMEsMap.begin();
399  it != TrackingLSMEsMap.end(); it++) {
400 
401  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
402 
403  ibin++;
404 
405  std::string localMEdirpath = it->second.HistoLSDir;
406  std::string MEname = it->second.HistoLSName;
407  float lower_cut = it->second.HistoLSLowerCut;
408  float upper_cut = it->second.HistoLSUpperCut;
409 
410  float status = 1.0;
411 
412  std::vector<MonitorElement*> tmpMEvec = dqm_store->getContents(dqm_store->pwd()+"/"+localMEdirpath);
413  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] tmpMEvec: " << tmpMEvec.size() << std::endl;
414 
415  MonitorElement* me = NULL;
416 
417  size_t nMEs = 0;
418  for ( auto ime : tmpMEvec ) {
419  std::string name = ime->getName();
420  if ( name.find(MEname) != std::string::npos) {
421  me = ime;
422  nMEs++;
423  }
424  }
425  // only one ME found
426  if (nMEs == 1) {
427  for ( auto ime : tmpMEvec ) {
428  std::string name = ime->getName();
429  if ( name.find(MEname) != std::string::npos) {
430  me = ime;
431  }
432  }
433  if (!me) continue;
434 
435  if (me->kind() == MonitorElement::DQM_KIND_TH1F) {
436  float x_mean = me->getMean();
437  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] MEname: " << MEname << " x_mean: " << x_mean << std::endl;
438  if (x_mean <= lower_cut || x_mean > upper_cut) status = 0.0;
439  else status = 1.0;
440  }
441  } else { // more than 1 ME w/ the same root => they need to be considered together
442  for ( auto ime : tmpMEvec ) {
443  float tmp_status = 1.;
444  std::string name = ime->getName();
445  if ( name.find(MEname) != std::string::npos) {
446  me = ime;
447  if (!me) continue;
448 
449  if (me->kind() == MonitorElement::DQM_KIND_TH1F) {
450  float x_mean = me->getMean();
451  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] MEname: " << MEname << "[" << me->getName() << "] x_mean: " << x_mean << std::endl;
452  if (x_mean <= lower_cut || x_mean > upper_cut) tmp_status = 0.0;
453  else tmp_status = 1.0;
454  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] tmp_status: " << tmp_status << std::endl;
455  }
456  }
457  status = fminf(tmp_status,status);
458  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] ==> status: " << status << std::endl;
459  } // loop on tmpMEvec
460  }
461  it->second.TrackingFlag->Fill(status);
462  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] ===> status: " << status << " [" << gstatus << "]" << std::endl;
463  if (status == 0.0) gstatus = -1.0;
464  else gstatus = gstatus * status;
465  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] ===> gstatus: " << gstatus << std::endl;
466  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
467  }
469  dqm_store->cd();
470 
471  // std::cout << "[TrackingQualityChecker::fillTrackingStatusAtLumi] DONE" << std::endl;
472 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void fillTrackingStatus(DQMStore *dqm_store)
MonitorElement * TrackGlobalSummaryReportMap
static bool goToDir(DQMStore *dqm_store, std::string name)
void fillGlobalStatus(DQMStore *dqm_store)
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:561
std::map< std::string, TrackingMEs > TrackingMEsMap
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
void bookLSStatus(DQMStore *dqm_store)
#define NULL
Definition: scimark2.h:8
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
static void getTopFolderPath(DQMStore *dqm_store, std::string top_dir, std::string &path)
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:809
void Fill(long long x)
TrackingQualityChecker(edm::ParameterSet const &ps)
MonitorElement * TrackLSSummaryReportGlobal
void fillStatusHistogram(MonitorElement *, int xbin, int ybin, float val)
Kind kind(void) const
Get the type of the monitor element.
std::vector< MonitorElement * > getContents(const std::string &path) const
Definition: DQMStore.cc:1652
void bookGlobalStatus(DQMStore *dqm_store)
std::vector< QReport * > getQReports(void) const
get map of QReports
void fillTrackingStatusAtLumi(DQMStore *dqm_store)
void fillLSStatus(DQMStore *dqm_store)
int getNbinsX(void) const
get # of bins in X-axis
MonitorElement * TrackGlobalSummaryReportGlobal
void Reset(std::vector< TH2F > &depth)
tuple status
Definition: ntuplemaker.py:245
TH2F * getTH2F(void) const
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:1000
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
std::map< std::string, TrackingLSMEs > TrackingLSMEsMap
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
const std::string & pwd(void) const
Definition: DQMStore.cc:556