CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripQualityChecker.cc
Go to the documentation of this file.
6 
8 
10 
14 
17 
20 
21 
22 #include <iomanip>
23 //
24 // -- Constructor
25 //
27  edm::LogInfo("SiStripQualityChecker") <<
28  " Creating SiStripQualityChecker " << "\n" ;
29 
30  bookedStripStatus_ = false;
31 
32  SubDetFolderMap.insert(std::pair<std::string, std::string>("TIB", "TIB"));
33  SubDetFolderMap.insert(std::pair<std::string, std::string>("TOB", "TOB"));
34  SubDetFolderMap.insert(std::pair<std::string, std::string>("TECF", "TEC/PLUS"));
35  SubDetFolderMap.insert(std::pair<std::string, std::string>("TECB", "TEC/MINUS"));
36  SubDetFolderMap.insert(std::pair<std::string, std::string>("TIDF", "TID/PLUS"));
37  SubDetFolderMap.insert(std::pair<std::string, std::string>("TIDB", "TID/MINUS"));
38  badModuleList.clear();
39 
40  if(!edm::Service<TkDetMap>().isAvailable()){
41  edm::LogError("TkHistoMap") <<
42  "\n------------------------------------------"
43  "\nUnAvailable Service TkHistoMap: please insert in the configuration file an instance like"
44  "\n\tprocess.TkDetMap = cms.Service(\"TkDetMap\")"
45  "\n------------------------------------------";
46  }
48 
49 }
50 //
51 // -- Destructor
52 //
54  edm::LogInfo("SiStripQualityChecker") <<
55  " Deleting SiStripQualityChecker " << "\n" ;
56 }
57 //
58 // -- create reportSummary MEs
59 //
61 
62  if (!bookedStripStatus_) {
63  dqm_store->cd();
64  std::string strip_dir = "";
65  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
66  if (strip_dir.size() == 0) strip_dir = "SiStrip";
67 
68  // Non Standard Plots and should be put outside EventInfo folder
69 
70  dqm_store->setCurrentFolder(strip_dir+"/MechanicalView");
71 
72  std::string hname, htitle;
73  hname = "detFractionReportMap";
74  htitle = "SiStrip Report for Good Detector Fraction";
75  DetFractionReportMap = dqm_store->book2D(hname, htitle, 6,0.5,6.5,9,0.5,9.5);
76  DetFractionReportMap->setAxisTitle("Sub Detector Type", 1);
77  DetFractionReportMap->setAxisTitle("Layer/Disc Number", 2);
78  hname = "sToNReportMap";
79  htitle = "SiStrip Report for Signal-to-Noise";
80  SToNReportMap = dqm_store->book2D(hname, htitle, 6,0.5,6.5,9,0.5,9.5);
81  SToNReportMap->setAxisTitle("Sub Detector Type", 1);
82  SToNReportMap->setAxisTitle("Layer/Disc Number", 2);
83 
84  // this is the main reportSummary 2D plot and should be in EventInfo
85  dqm_store->setCurrentFolder(strip_dir+"/EventInfo");
86 
87  hname = "reportSummaryMap";
88  htitle = "SiStrip Report Summary Map";
89  SummaryReportMap = dqm_store->book2D(hname, htitle, 6,0.5,6.5,9,0.5,9.5);
90  SummaryReportMap->setAxisTitle("Sub Detector Type", 1);
91  SummaryReportMap->setAxisTitle("Layer/Disc Number", 2);
92 
93  SummaryReportGlobal = dqm_store->bookFloat("reportSummary");
94  int ibin = 0;
95 
96  dqm_store->setCurrentFolder(strip_dir+"/EventInfo/reportSummaryContents");
97  for (std::map<std::string, std::string>::const_iterator it = SubDetFolderMap.begin();
98  it != SubDetFolderMap.end(); it++) {
99  ibin++;
100  std::string det = it->first;
102  SToNReportMap->setBinLabel(ibin,det);
103  SummaryReportMap->setBinLabel(ibin,det);
104 
105  SubDetMEs local_mes;
106 
107  if (det == "TECF") local_mes.detectorTag = "TEC+";
108  else if (det == "TECB") local_mes.detectorTag = "TEC-";
109  else if (det == "TIDF") local_mes.detectorTag = "TID+";
110  else if (det == "TIDB") local_mes.detectorTag = "TID-";
111  else local_mes.detectorTag = det;
112 
113  std::string me_name;
114  me_name = "SiStrip_" + det;
115  local_mes.SummaryFlag = dqm_store->bookFloat(me_name);
116 
117  me_name = "SiStrip_DetFraction_" + det;
118  local_mes.DetFraction = dqm_store->bookFloat(me_name);
119 
120  me_name = "SiStrip_SToNFlag_" + det;
121  local_mes.SToNFlag = dqm_store->bookFloat(me_name);
122  SubDetMEsMap.insert(std::pair<std::string, SubDetMEs>(det, local_mes));
123  }
124  bookedStripStatus_ = true;
125  }
126 }
127 //
128 // -- Fill Dummy Status
129 //
131 
132  resetStatus();
133  if (bookedStripStatus_) {
134  for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin();
135  it != SubDetMEsMap.end(); it++) {
136  SubDetMEs local_mes = it->second;
137  local_mes.SummaryFlag -> Fill(-1.0);
138  local_mes.DetFraction -> Fill(-1.0);
139  local_mes.SToNFlag -> Fill(-1.0);
140  }
141 
142  for (int xbin = 1; xbin < SummaryReportMap->getNbinsX()+1; xbin++) {
143  for (int ybin = 1; ybin < SummaryReportMap->getNbinsY()+1; ybin++) {
144  SummaryReportMap -> Fill(xbin, ybin, -1.0);
145  DetFractionReportMap -> Fill(xbin, ybin, -1.0);
146  SToNReportMap -> Fill(xbin, ybin, -1.0);
147  }
148  }
149  SummaryReportGlobal->Fill(-1.0);
150  }
151 }
152 //
153 // -- Reset Status
154 //
156  if (bookedStripStatus_) {
157  for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin();
158  it != SubDetMEsMap.end(); it++) {
159  SubDetMEs local_mes = it->second;
160  local_mes.DetFraction -> Reset();
161  local_mes.SummaryFlag -> Reset();
162  local_mes.SToNFlag -> Reset();
163  }
166  SToNReportMap->Reset();
167 
169  }
170 }
171 //
172 // -- Fill Status
173 //
175  if (!bookedStripStatus_) bookStatus(dqm_store);
176 
177  fillDummyStatus();
178  fillDetectorStatus(dqm_store, cabling);
179 
180  int faulty_moduleflag = pSet_.getUntrackedParameter<bool>("PrintFaultyModuleList", false);
181  if (faulty_moduleflag) fillFaultyModuleStatus(dqm_store, eSetup);
182 }
183 //
184 // Fill Detector Status
185 //
187  unsigned int xbin = 0;
188  float global_flag = 0;
189  dqm_store->cd();
190  std::string mdir = "MechanicalView";
191  if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
192  std::string mechanicalview_dir = dqm_store->pwd();
193 
195  for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin();
196  it != SubDetMEsMap.end(); it++) {
197  std::string det = it->first;
198  std::map<std::string, std::string>::const_iterator cPos = SubDetFolderMap.find(det);
199  if (cPos == SubDetFolderMap.end()) continue;
200  std::string dname = mechanicalview_dir + "/" + cPos->second;
201  if (!dqm_store->dirExists(dname)) continue;
202  dqm_store->cd(dname);
203  SubDetMEs local_mes = it->second;
204  xbin++;
205  float flag;
206  fillSubDetStatus(dqm_store, cabling, local_mes, xbin,flag);
207  global_flag += flag;
208  }
209  global_flag = global_flag/xbin*1.0;
210  if (SummaryReportGlobal) SummaryReportGlobal->Fill(global_flag);
211  dqm_store->cd();
212 }
213 //
214 // -- Fill Sub detector Reports
215 //
217  const edm::ESHandle< SiStripDetCabling >& cabling,
218  SubDetMEs& mes, unsigned int xbin, float& gflag) {
219 
220  int status_flag = pSet_.getUntrackedParameter<int>("GlobalStatusFilling", 1);
221  if (status_flag < 1) return;
222 
223  std::vector<std::string> subDirVec = dqm_store->getSubdirs();
224 
225  unsigned int ybin = 0;
226  int tot_ndet = 0;
227  int tot_errdet = 0;
228  float tot_ston_stat = 0;
229 
230  for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
231  ic != subDirVec.end(); ic++) {
232  std::string dname = (*ic);
233  if (dname.find("BadModuleList") != std::string::npos) continue;
234  if (dname.find("ring") !=std::string::npos) continue;
235  std::vector<MonitorElement*> meVec;
236  if (dname.find("ring") !=std::string::npos) continue;
237 
238  ybin++;
239  dqm_store->cd((*ic));
240  meVec = dqm_store->getContents((*ic));
241  uint16_t ndet = 100;
242  int errdet = 0;
243 
244  int ston_stat = 1;
245  int lnum = atoi(dname.substr(dname.find_last_of("_")+1).c_str());
246  ndet = cabling->connectedNumber(mes.detectorTag, lnum);
247 
248  getModuleStatus(dqm_store, meVec, errdet);
249 
250  for (std::vector<MonitorElement*>::const_iterator it = meVec.begin();
251  it != meVec.end(); it++) {
252  MonitorElement * me = (*it);
253  if (!me) continue;
254  std::vector<QReport *> reports = me->getQReports();
255 
256  if (reports.size() == 0) continue;
257  std::string name = me->getName();
258 
259  if( name.find("Summary_ClusterStoNCorr__OnTrack") != std::string::npos){
260  int istat = SiStripUtility::getMEStatus((*it));
261  if (reports[0]->getQTresult() == -1) {
262  ston_stat =-1;
263  } else {
264  if (istat == dqm::qstatus::ERROR) ston_stat = 0;
265  else if (istat == dqm::qstatus::STATUS_OK) ston_stat = 1;
266  }
267  }
268  }
269  if (ndet > 0) {
270  float eff_fac = 1 - (errdet*1.0/ndet);
271  fillStatusHistogram(SToNReportMap, xbin, ybin, ston_stat);
272  fillStatusHistogram(DetFractionReportMap, xbin, ybin, eff_fac);
273  if (ston_stat < 0) fillStatusHistogram(SummaryReportMap, xbin, ybin, eff_fac);
274  else fillStatusHistogram(SummaryReportMap, xbin, ybin, ston_stat*eff_fac);
275 
276  tot_ndet += ndet;
277  tot_errdet += errdet;
278  tot_ston_stat += ston_stat;
279  }
280  dqm_store->cd((*ic));
281  }
282  if (tot_ndet > 0) {
283  float tot_eff_fac = 1 - (tot_errdet*1.0/tot_ndet);
284  if (mes.DetFraction) mes.DetFraction->Fill(tot_eff_fac);
285  float tot_ston_fac = tot_ston_stat/ybin;
286  if (mes.SToNFlag) mes.SToNFlag->Fill(tot_ston_fac);
287  if (tot_ston_fac < 0){
288  gflag = tot_eff_fac;
289  }else{
290  gflag = std::min(tot_eff_fac,tot_ston_fac);
291  }
292  if (mes.SummaryFlag) mes.SummaryFlag->Fill(gflag);
293  }
294 }
295 //
296 // -- Print Status Report
297 //
299  std::ostringstream det_summary_str;
300  for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin();
301  it != SubDetMEsMap.end(); it++) {
302  std::string det = it->first;
303  det_summary_str << std::setprecision(4);
304  det_summary_str << std::setiosflags(std::ios::fixed);
305 
306  det_summary_str << " Printing Status for " << det << " : " << std::endl;
307  SubDetMEs local_mes = it->second;
308 
309  std::string sval;
310  float fval1, fval2, fval3;
311  fval1 = fval2 = fval3 = -1.0;
312 
313 
314  SiStripUtility::getMEValue(local_mes.DetFraction, sval);
315  if (sval.size() > 0) fval1 = atof(sval.c_str());
316  SiStripUtility::getMEValue(local_mes.SToNFlag, sval);
317  if (sval.size() > 0) fval2 = atof(sval.c_str());
318  SiStripUtility::getMEValue(local_mes.SummaryFlag, sval);
319  if (sval.size() > 0) fval3 = atof(sval.c_str());
320 
321  det_summary_str << std::setw(7) << " % of good detectors " << fval1
322  << " SToN Flag " << fval2
323  << " Summary Flag " << fval3 << std::endl;
324  }
325 }
326 //
327 // -- Get Module Status from Layer Level Histograms
328 //
329 void SiStripQualityChecker::getModuleStatus(DQMStore* dqm_store, std::vector<MonitorElement*>& layer_mes,int& errdet) {
330 
331  std::string lname;
332  std::map<uint32_t,uint16_t> bad_modules;
333  for (std::vector<MonitorElement*>::const_iterator it = layer_mes.begin();
334  it != layer_mes.end(); it++) {
335  MonitorElement * me = (*it);
336  if (!me) continue;
337  std::vector<QReport *> qreports = me->getQReports();
338  if (qreports.size() == 0) continue;
339  std::string name = me->getName();
340  std::vector<DQMChannel> bad_channels_me;
342  bad_channels_me = qreports[0]->getBadChannels();
343  lname = "";
344  } else if (me->kind() == MonitorElement::DQM_KIND_TPROFILE2D && name.find("TkHMap") != std::string::npos) {
345  bad_channels_me = qreports[0]->getBadChannels();
346  lname = name.substr(name.find("TkHMap_")+7);
347  lname = lname.substr(lname.find("_T")+1);
348 
349  }
350  for (std::vector<DQMChannel>::iterator it = bad_channels_me.begin(); it != bad_channels_me.end(); it++){
351  int xval = (*it).getBinX();
352  int yval = (*it).getBinY();
353  uint32_t detId = tkDetMap_->getDetFromBin(lname, xval, yval);
354  std::map<uint32_t,uint16_t>::iterator iPos = bad_modules.find(detId);
355  uint16_t flag;
356  if (iPos != bad_modules.end()){
357  flag = iPos->second;
359  iPos->second = flag;
360  } else {
361  //
362  //if not in the local bad module list, check the BadModuleList dir
363  //
364  std::ostringstream detid_str;
365  detid_str << detId;
366  //now in the layer/wheel dir
367  std::string currentdir = dqm_store->pwd();
368  std::string thisMEpath = currentdir.substr( 0 , currentdir.rfind( "/" ) ) + "/BadModuleList/" + detid_str.str() ;
369 
370  MonitorElement *meBadModule = dqm_store->get ( thisMEpath );
371  if ( meBadModule )
372  {
373  std::string val_str;
374  SiStripUtility::getMEValue ( meBadModule , val_str );
375  flag = atoi ( val_str.c_str() );
376  }
377  else
378  flag = 0;
379 
381  bad_modules.insert(std::pair<uint32_t,uint16_t>(detId,flag));
382  }
383  }
384  }
385  for(std::map<uint32_t,uint16_t>::const_iterator it = bad_modules.begin();
386  it != bad_modules.end(); it++) {
387  uint32_t detId = it->first;
388  uint16_t flag = it->second;
389  std::map<uint32_t,uint16_t>::iterator iPos = badModuleList.find(detId);
390  if (iPos != badModuleList.end()){
391  iPos->second = flag;
392  } else {
393  badModuleList.insert(std::pair<uint32_t,uint16_t>(detId,flag));
394  }
395  }
396  errdet = bad_modules.size();
397 }
398 //
399 // -- Fill Report Summary Map
400 //
401  void SiStripQualityChecker::fillStatusHistogram(MonitorElement* me, int xbin, int ybin, float val){
402  if (me && me->kind() == MonitorElement::DQM_KIND_TH2F) {
403  TH2F* th2d = me->getTH2F();
404  th2d->SetBinContent(xbin, ybin, val);
405  }
406  }
407 //
408 // -- Create Monitor Elements for Modules
409 //
411  if (badModuleList.size() == 0) return;
412 
413  //Retrieve tracker topology from geometry
414  edm::ESHandle<TrackerTopology> tTopoHandle;
415  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
416  const TrackerTopology* const tTopo = tTopoHandle.product();
417 
418  dqm_store->cd();
419  std::string mdir = "MechanicalView";
420  if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
421  std::string mechanical_dir = dqm_store->pwd();
422 
423  SiStripFolderOrganizer folder_organizer;
424  for (std::map<uint32_t,uint16_t>::const_iterator it = badModuleList.begin() ; it != badModuleList.end(); it++) {
425  uint32_t detId = it->first;
426  std::string subdet_folder ;
427  folder_organizer.getSubDetFolder(detId,tTopo,subdet_folder);
428  if (!dqm_store->dirExists(subdet_folder)) {
429  subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find("MechanicalView")+14);
430  if (!dqm_store->dirExists(subdet_folder)) continue;
431  }
432  std::string bad_module_folder = subdet_folder + "/" + "BadModuleList";
433  dqm_store->setCurrentFolder(bad_module_folder);
434 
435  std::ostringstream detid_str;
436  detid_str << detId;
437  std::string full_path = bad_module_folder + "/" + detid_str.str();
438  MonitorElement* me = dqm_store->get(full_path);
439  if (me) me->Reset();
440  else me = dqm_store->bookInt(detid_str.str());
441  me->Fill(it->second);
442  }
443  dqm_store->cd();
444 }
445 //
446 // -- Initialise Bad Module List
447 //
449  for (std::map<uint32_t,uint16_t>::iterator it=badModuleList.begin(); it!=badModuleList.end(); it++) {
450  it->second = 0;
451  }
452 }
453 //
454 // -- Fill Status information and the lumi block
455 //
457  if (!bookedStripStatus_) bookStatus(dqm_store);
458  fillDummyStatus();
459  fillDetectorStatusAtLumi(dqm_store);
460 }
461 //
462 // Fill Detector Status MEs at the Lumi block
463 //
465 
466 
467 
468  dqm_store->cd();
469  std::string rdir = "ReadoutView";
470  if (!SiStripUtility::goToDir(dqm_store, rdir)) return;
471  std::string fullpath = dqm_store->pwd()
472  // + "/FedSummary/PerLumiSection/"
473  + "/PerLumiSection/"
474  + "lumiErrorFraction";
475  MonitorElement* me = dqm_store->get(fullpath);
476  if (me && me->kind() == MonitorElement::DQM_KIND_TH1F) {
477  TH1F* th1 = me->getTH1F();
478  float global_fraction = 0.0;
479  float dets = 0.0;
480  for (int ibin = 1; ibin <= th1->GetNbinsX(); ibin++) {
481  std::string label = th1->GetXaxis()->GetBinLabel(ibin);
482  std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(label);
483  if (iPos != SubDetMEsMap.end()) {
484  float fraction = 1.0 - th1->GetBinContent(ibin);
485  global_fraction += fraction;
486  dets++;
487  iPos->second.DetFraction -> Fill(fraction);
488  iPos->second.SToNFlag -> Fill(-1.0);
489  iPos->second.SummaryFlag -> Fill(fraction);
490  }
491  }
492  global_fraction = global_fraction/dets;
493  if (SummaryReportGlobal) SummaryReportGlobal->Fill(global_fraction);
494  }
495  dqm_store->cd();
496 }
void fillStatus(DQMStore *dqm_store, const edm::ESHandle< SiStripDetCabling > &cabling, const edm::EventSetup &eSetup)
static void setBadModuleFlag(std::string &hname, uint16_t &flg)
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
void getSubDetFolder(const uint32_t &detid, const TrackerTopology *tTopo, std::string &folder_name)
void bookStatus(DQMStore *dqm_store)
void fillDetectorStatusAtLumi(DQMStore *dqm_store)
std::vector< std::string > getSubdirs(void) const
Definition: DQMStore.cc:1711
void fillDetectorStatus(DQMStore *dqm_store, const edm::ESHandle< SiStripDetCabling > &cabling)
static void getMEValue(MonitorElement *me, std::string &val)
std::map< std::string, std::string > SubDetFolderMap
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:696
void getModuleStatus(DQMStore *dqm_store, std::vector< MonitorElement * > &layer_mes, int &errdet)
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)
tuple currentdir
parse figure configuration if found
Definition: lumiPlot.py:48
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:943
SiStripQualityChecker(edm::ParameterSet const &ps)
int getNbinsY(void) const
get # of bins in Y-axis
void Fill(long long x)
std::map< std::string, SubDetMEs > SubDetMEsMap
uint32_t getDetFromBin(int layer, int ix, int iy) const
Definition: TkDetMap.h:128
void fillFaultyModuleStatus(DQMStore *dqm_store, const edm::EventSetup &eSetup)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T min(T a, T b)
Definition: MathUtil.h:58
Kind kind(void) const
Get the type of the monitor element.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1760
std::vector< MonitorElement * > getContents(const std::string &path) const
Definition: DQMStore.cc:1789
MonitorElement * DetFractionReportMap
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:784
std::vector< QReport * > getQReports(void) const
get map of QReports
static int getMEStatus(MonitorElement *me)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
TH1F * getTH1F(void) const
void fillStatusAtLumi(DQMStore *dqm_store)
MonitorElement * SummaryReportMap
MonitorElement * SummaryReportGlobal
MonitorElement * SToNReportMap
int getNbinsX(void) const
get # of bins in X-axis
static const int STATUS_OK
std::map< uint32_t, uint16_t > badModuleList
void Reset(std::vector< TH2F > &depth)
TH2F * getTH2F(void) const
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:913
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:1134
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)
void fillSubDetStatus(DQMStore *dqm_store, const edm::ESHandle< SiStripDetCabling > &cabling, SubDetMEs &mes, unsigned int xbin, float &gflag)
static bool goToDir(DQMStore *dqm_store, std::string name)
static void getTopFolderPath(DQMStore *dqm_store, std::string top_dir, std::string &path)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:719
static const int ERROR
void fillStatusHistogram(MonitorElement *, int xbin, int ybin, float val)
const std::string & pwd(void) const
Definition: DQMStore.cc:691