CMS 3D CMS Logo

SiStripBadStrip_PayloadInspector.cc
Go to the documentation of this file.
1 
10 
14 
15 // the data format of the condition to be inspected
20 
22 
23 // needed for the tracker map
26 
27 // auxilliary functions
30 
33 
34 #include <memory>
35 #include <sstream>
36 #include <iostream>
37 
38 // include ROOT
39 #include "TH2F.h"
40 #include "TLegend.h"
41 #include "TCanvas.h"
42 #include "TLine.h"
43 #include "TStyle.h"
44 #include "TLatex.h"
45 #include "TPave.h"
46 #include "TPaveStats.h"
47 
48 namespace {
49 
50  using namespace cond::payloadInspector;
51 
52  /************************************************
53  test class
54  *************************************************/
55 
56  class SiStripBadStripTest : public Histogram1D<SiStripBadStrip, SINGLE_IOV> {
57  public:
58  SiStripBadStripTest()
59  : Histogram1D<SiStripBadStrip, SINGLE_IOV>("SiStrip Bad Strip test", "SiStrip Bad Strip test", 10, 0.0, 10.0) {}
60 
61  bool fill() override {
62  auto tag = PlotBase::getTag<0>();
63  for (auto const& iov : tag.iovs) {
64  std::shared_ptr<SiStripBadStrip> payload = Base::fetchPayload(std::get<1>(iov));
65  if (payload.get()) {
66  fillWithValue(1.);
67 
68  std::stringstream ss;
69  ss << "Summary of bad strips:" << std::endl;
70 
71  //payload->printDebug(ss);
72  //payload->printSummary(ss);
73  //std::cout<<ss.str()<<std::endl;
74 
75  std::vector<uint32_t> detid;
76  payload->getDetIds(detid);
77 
78  for (const auto& d : detid) {
80  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second;
81  ++badStrip) {
82  ss << "DetId=" << d << " Strip=" << payload->decode(*badStrip).firstStrip << ":"
83  << payload->decode(*badStrip).range << " flag=" << payload->decode(*badStrip).flag << std::endl;
84  }
85  }
86 
87  std::cout << ss.str() << std::endl;
88 
89  } // payload
90  } // iovs
91  return true;
92  } // fill
93  };
94 
95  /************************************************
96  TrackerMap of SiStripBadStrip (bad strip per detid)
97  *************************************************/
98  class SiStripBadModuleTrackerMap : public PlotImage<SiStripBadStrip, SINGLE_IOV> {
99  public:
100  SiStripBadModuleTrackerMap() : PlotImage<SiStripBadStrip, SINGLE_IOV>("Tracker Map of SiStrip Bad Strips") {}
101 
102  bool fill() override {
103  auto tag = PlotBase::getTag<0>();
104  auto iov = tag.iovs.front();
105  auto tagname = PlotBase::getTag<0>().name;
106  std::shared_ptr<SiStripBadStrip> payload = fetchPayload(std::get<1>(iov));
107 
108  auto theIOVsince = std::to_string(std::get<0>(iov));
109 
110  std::string titleMap = "Modules w/ at least 1 bad Strip, Run: " + theIOVsince + " (tag: " + tagname + ")";
111 
112  std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("SiStripBadStrips");
113  tmap->setTitle(titleMap);
114  tmap->setPalette(1);
115 
116  std::vector<uint32_t> detid;
117  payload->getDetIds(detid);
118 
119  for (const auto& d : detid) {
120  tmap->fill(d, 1.);
121  } // loop over detIds
122 
123  //=========================
124 
125  std::string fileName(m_imageFileName);
126  tmap->save(true, 0, 1., fileName);
127 
128  return true;
129  }
130  };
131 
132  /************************************************
133  TrackerMap of SiStripBadStrip (bad strips fraction)
134  *************************************************/
135  class SiStripBadStripFractionTrackerMap : public PlotImage<SiStripBadStrip, SINGLE_IOV> {
136  public:
137  SiStripBadStripFractionTrackerMap()
138  : PlotImage<SiStripBadStrip, SINGLE_IOV>("Tracker Map of SiStrip Bad Components fraction") {}
139 
140  bool fill() override {
141  auto tag = PlotBase::getTag<0>();
142  auto iov = tag.iovs.front();
143  auto tagname = PlotBase::getTag<0>().name;
144  std::shared_ptr<SiStripBadStrip> payload = fetchPayload(std::get<1>(iov));
145 
146  const auto detInfo =
148 
149  auto theIOVsince = std::to_string(std::get<0>(iov));
150 
151  std::string titleMap = "Fraction of bad Strips per module, Run: " + theIOVsince + " (tag: " + tagname + ")";
152 
153  std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("SiStripBadStrips");
154  tmap->setTitle(titleMap);
155  tmap->setPalette(1);
156 
157  std::vector<uint32_t> detid;
158  payload->getDetIds(detid);
159 
160  std::map<uint32_t, int> badStripsPerDetId;
161 
162  for (const auto& d : detid) {
163  SiStripBadStrip::Range range = payload->getRange(d);
164  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
165  badStripsPerDetId[d] += payload->decode(*badStrip).range;
166  //ss << "DetId="<< d << " Strip=" << payload->decode(*badStrip).firstStrip <<":"<< payload->decode(*badStrip).range << " flag="<< payload->decode(*badStrip).flag << std::endl;
167  }
168  float fraction =
169  badStripsPerDetId[d] / (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(d).first);
170  tmap->fill(d, fraction);
171  } // loop over detIds
172 
173  //=========================
174 
175  std::pair<float, float> extrema = tmap->getAutomaticRange();
176 
177  std::string fileName(m_imageFileName);
178 
179  // protect against uniform values across the map (bad components fractions are defined positive)
180  if (extrema.first != extrema.second) {
181  tmap->save(true, 0, 0, fileName);
182  } else {
183  tmap->save(true, extrema.first * 0.95, extrema.first * 1.05, fileName);
184  }
185 
186  return true;
187  }
188  };
189 
190  /************************************************
191  TrackerMap of SiStripBadStrip (bad strips fraction)
192  *************************************************/
193  class SiStripBadStripFractionTkMap : public PlotImage<SiStripBadStrip, SINGLE_IOV> {
194  public:
195  SiStripBadStripFractionTkMap()
196  : PlotImage<SiStripBadStrip, SINGLE_IOV>("Tracker Map of SiStrip Bad Components fraction") {}
197 
198  bool fill() override {
199  //SiStripPI::setPaletteStyle(SiStripPI::DEFAULT);
200  gStyle->SetPalette(1);
201 
202  auto tag = PlotBase::getTag<0>();
203  auto iov = tag.iovs.front();
204  auto tagname = PlotBase::getTag<0>().name;
205  std::shared_ptr<SiStripBadStrip> payload = fetchPayload(std::get<1>(iov));
206 
207  const auto detInfo =
209 
210  auto theIOVsince = std::to_string(std::get<0>(iov));
211 
212  std::string titleMap =
213  "Fraction of bad Strips per module, Run: " + theIOVsince + " (tag:#color[2]{" + tagname + "})";
214 
215  SiStripTkMaps myMap("COLZA0 L");
216  myMap.bookMap(titleMap, "Fraction of bad Strips per module");
217 
218  SiStripTkMaps ghost("AL");
219  ghost.bookMap(titleMap, "");
220 
221  std::vector<uint32_t> detid;
222  payload->getDetIds(detid);
223 
224  std::map<uint32_t, int> badStripsPerDetId;
225 
226  for (const auto& d : detid) {
227  SiStripBadStrip::Range range = payload->getRange(d);
228  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
229  badStripsPerDetId[d] += payload->decode(*badStrip).range;
230  }
231  float fraction =
232  badStripsPerDetId[d] / (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(d).first);
233  if (fraction > 0.) {
234  myMap.fill(d, fraction);
235  }
236  } // loop over detIds
237 
238  //=========================
239 
240  std::string fileName(m_imageFileName);
241  TCanvas canvas("Bad Components fraction", "bad components fraction");
242  myMap.drawMap(canvas, "");
243  ghost.drawMap(canvas, "same");
244  canvas.SaveAs(fileName.c_str());
245 
246  return true;
247  }
248  };
249 
250  /************************************************
251  time history histogram of bad components fraction
252  *************************************************/
253 
254  class SiStripBadStripFractionByRun : public HistoryPlot<SiStripBadStrip, float> {
255  public:
256  SiStripBadStripFractionByRun()
257  : HistoryPlot<SiStripBadStrip, float>("SiStrip Bad Strip fraction per run", "Bad Strip fraction [%]") {}
258  ~SiStripBadStripFractionByRun() override = default;
259 
260  float getFromPayload(SiStripBadStrip& payload) override {
261  const auto detInfo =
263 
264  std::vector<uint32_t> detid;
265  payload.getDetIds(detid);
266 
267  std::map<uint32_t, int> badStripsPerDetId;
268 
269  for (const auto& d : detid) {
271  int badStrips(0);
272  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
273  badStrips += payload.decode(*badStrip).range;
274  }
275  badStripsPerDetId[d] = badStrips;
276  } // loop over detIds
277 
278  float numerator(0.), denominator(0.);
279  std::vector<uint32_t> all_detids = detInfo.getAllDetIds();
280  for (const auto& det : all_detids) {
281  denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
282  if (badStripsPerDetId.count(det) != 0)
283  numerator += badStripsPerDetId[det];
284  }
285 
286  return (numerator / denominator) * 100.;
287 
288  } // payload
289  };
290 
291  /************************************************
292  time history histogram of bad components fraction (TIB)
293  *************************************************/
294 
295  class SiStripBadStripTIBFractionByRun : public HistoryPlot<SiStripBadStrip, float> {
296  public:
297  SiStripBadStripTIBFractionByRun()
298  : HistoryPlot<SiStripBadStrip, float>("SiStrip Inner Barrel Bad Strip fraction per run",
299  "TIB Bad Strip fraction [%]") {}
300  ~SiStripBadStripTIBFractionByRun() override = default;
301 
302  float getFromPayload(SiStripBadStrip& payload) override {
303  const auto detInfo =
305 
306  std::vector<uint32_t> detid;
307  payload.getDetIds(detid);
308 
309  std::map<uint32_t, int> badStripsPerDetId;
310 
311  for (const auto& d : detid) {
313  int badStrips(0);
314  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
315  badStrips += payload.decode(*badStrip).range;
316  }
317  badStripsPerDetId[d] = badStrips;
318  } // loop over detIds
319 
320  float numerator(0.), denominator(0.);
321  std::vector<uint32_t> all_detids = detInfo.getAllDetIds();
322  for (const auto& det : all_detids) {
323  int subid = DetId(det).subdetId();
324  if (subid != StripSubdetector::TIB)
325  continue;
326  denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
327  if (badStripsPerDetId.count(det) != 0)
328  numerator += badStripsPerDetId[det];
329  }
330 
331  return (numerator / denominator) * 100.;
332 
333  } // payload
334  };
335 
336  /************************************************
337  time history histogram of bad components fraction (TOB)
338  *************************************************/
339 
340  class SiStripBadStripTOBFractionByRun : public HistoryPlot<SiStripBadStrip, float> {
341  public:
342  SiStripBadStripTOBFractionByRun()
343  : HistoryPlot<SiStripBadStrip, float>("SiStrip Outer Barrel Bad Strip fraction per run",
344  "TOB Bad Strip fraction [%]") {}
345  ~SiStripBadStripTOBFractionByRun() override = default;
346 
347  float getFromPayload(SiStripBadStrip& payload) override {
348  const auto detInfo =
350 
351  std::vector<uint32_t> detid;
352  payload.getDetIds(detid);
353 
354  std::map<uint32_t, int> badStripsPerDetId;
355 
356  for (const auto& d : detid) {
358  int badStrips(0);
359  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
360  badStrips += payload.decode(*badStrip).range;
361  }
362  badStripsPerDetId[d] = badStrips;
363  } // loop over detIds
364 
365  float numerator(0.), denominator(0.);
366  std::vector<uint32_t> all_detids = detInfo.getAllDetIds();
367  for (const auto& det : all_detids) {
368  int subid = DetId(det).subdetId();
369  if (subid != StripSubdetector::TOB)
370  continue;
371  denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
372  if (badStripsPerDetId.count(det) != 0)
373  numerator += badStripsPerDetId[det];
374  }
375 
376  return (numerator / denominator) * 100.;
377 
378  } // payload
379  };
380 
381  /************************************************
382  time history histogram of bad components fraction (TID)
383  *************************************************/
384 
385  class SiStripBadStripTIDFractionByRun : public HistoryPlot<SiStripBadStrip, float> {
386  public:
387  SiStripBadStripTIDFractionByRun()
388  : HistoryPlot<SiStripBadStrip, float>("SiStrip Inner Disks Bad Strip fraction per run",
389  "TID Bad Strip fraction [%]") {}
390  ~SiStripBadStripTIDFractionByRun() override = default;
391 
392  float getFromPayload(SiStripBadStrip& payload) override {
393  const auto detInfo =
395 
396  std::vector<uint32_t> detid;
397  payload.getDetIds(detid);
398 
399  std::map<uint32_t, int> badStripsPerDetId;
400 
401  for (const auto& d : detid) {
403  int badStrips(0);
404  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
405  badStrips += payload.decode(*badStrip).range;
406  }
407  badStripsPerDetId[d] = badStrips;
408  } // loop over detIds
409 
410  float numerator(0.), denominator(0.);
411  std::vector<uint32_t> all_detids = detInfo.getAllDetIds();
412  for (const auto& det : all_detids) {
413  int subid = DetId(det).subdetId();
414  if (subid != StripSubdetector::TID)
415  continue;
416  denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
417  if (badStripsPerDetId.count(det) != 0)
418  numerator += badStripsPerDetId[det];
419  }
420 
421  return (numerator / denominator) * 100.;
422 
423  } // payload
424  };
425 
426  /************************************************
427  time history histogram of bad components fraction (TEC)
428  *************************************************/
429 
430  class SiStripBadStripTECFractionByRun : public HistoryPlot<SiStripBadStrip, float> {
431  public:
432  SiStripBadStripTECFractionByRun()
433  : HistoryPlot<SiStripBadStrip, float>("SiStrip Endcaps Bad Strip fraction per run",
434  "TEC Bad Strip fraction [%]") {}
435  ~SiStripBadStripTECFractionByRun() override = default;
436 
437  float getFromPayload(SiStripBadStrip& payload) override {
438  const auto detInfo =
440 
441  std::vector<uint32_t> detid;
442  payload.getDetIds(detid);
443 
444  std::map<uint32_t, int> badStripsPerDetId;
445 
446  for (const auto& d : detid) {
448  int badStrips(0);
449  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
450  badStrips += payload.decode(*badStrip).range;
451  }
452  badStripsPerDetId[d] = badStrips;
453  } // loop over detIds
454 
455  float numerator(0.), denominator(0.);
456  std::vector<uint32_t> all_detids = detInfo.getAllDetIds();
457  for (const auto& det : all_detids) {
458  int subid = DetId(det).subdetId();
459  if (subid != StripSubdetector::TEC)
460  continue;
461  denominator += sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first;
462  if (badStripsPerDetId.count(det) != 0)
463  numerator += badStripsPerDetId[det];
464  }
465 
466  return (numerator / denominator) * 100.;
467 
468  } // payload
469  };
470 
471  /************************************************
472  Plot BadStrip by region
473  *************************************************/
474 
475  class SiStripBadStripByRegion : public PlotImage<SiStripBadStrip, SINGLE_IOV> {
476  public:
477  SiStripBadStripByRegion()
478  : PlotImage<SiStripBadStrip, SINGLE_IOV>("SiStrip BadStrip By Region"),
480  edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
481 
482  bool fill() override {
483  auto tag = PlotBase::getTag<0>();
484  auto iov = tag.iovs.front();
485  std::shared_ptr<SiStripBadStrip> payload = fetchPayload(std::get<1>(iov));
486 
487  std::vector<uint32_t> detid;
488  payload->getDetIds(detid);
489 
490  SiStripDetSummary summaryBadStrips{&m_trackerTopo};
491  int totalBadStrips = 0;
492 
493  for (const auto& d : detid) {
494  SiStripBadStrip::Range range = payload->getRange(d);
495  int badStrips(0);
496  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
497  badStrips += payload->decode(*badStrip).range;
498  }
499  totalBadStrips += badStrips;
500  summaryBadStrips.add(d, badStrips);
501  }
502  std::map<unsigned int, SiStripDetSummary::Values> mapBadStrips = summaryBadStrips.getCounts();
503 
504  //=========================
505 
506  TCanvas canvas("BadStrip Region summary", "SiStripBadStrip region summary", 1200, 1000);
507  canvas.cd();
508  auto h_BadStrips = std::make_unique<TH1F>("BadStripsbyRegion",
509  "SiStrip Bad Strip summary by region;; n. bad strips",
510  mapBadStrips.size(),
511  0.,
512  mapBadStrips.size());
513  h_BadStrips->SetStats(false);
514 
515  canvas.SetBottomMargin(0.18);
516  canvas.SetLeftMargin(0.12);
517  canvas.SetRightMargin(0.05);
518  canvas.Modified();
519 
520  std::vector<int> boundaries;
521  unsigned int iBin = 0;
522 
524  std::string currentDetector;
525 
526  for (const auto& element : mapBadStrips) {
527  iBin++;
528  int countBadStrips = (element.second.mean);
529 
530  if (currentDetector.empty())
531  currentDetector = "TIB";
532 
533  switch ((element.first) / 1000) {
534  case 1:
535  detector = "TIB";
536  break;
537  case 2:
538  detector = "TOB";
539  break;
540  case 3:
541  detector = "TEC";
542  break;
543  case 4:
544  detector = "TID";
545  break;
546  }
547 
548  h_BadStrips->SetBinContent(iBin, countBadStrips);
549  h_BadStrips->GetXaxis()->SetBinLabel(iBin, SiStripPI::regionType(element.first).second);
550  h_BadStrips->GetXaxis()->LabelsOption("v");
551 
552  if (detector != currentDetector) {
553  boundaries.push_back(iBin);
554  currentDetector = detector;
555  }
556  }
557 
558  h_BadStrips->SetMarkerStyle(21);
559  h_BadStrips->SetMarkerSize(1);
560  h_BadStrips->SetLineColor(kBlue);
561  h_BadStrips->SetLineStyle(9);
562  h_BadStrips->SetMarkerColor(kBlue);
563  h_BadStrips->GetYaxis()->SetRangeUser(0., h_BadStrips->GetMaximum() * 1.30);
564  h_BadStrips->GetYaxis()->SetTitleOffset(1.7);
565  h_BadStrips->Draw("HISTsame");
566  h_BadStrips->Draw("TEXTsame");
567 
568  canvas.Update();
569  canvas.cd();
570 
571  TLine l[boundaries.size()];
572  unsigned int i = 0;
573  for (const auto& line : boundaries) {
574  l[i] = TLine(h_BadStrips->GetBinLowEdge(line),
575  canvas.cd()->GetUymin(),
576  h_BadStrips->GetBinLowEdge(line),
577  canvas.cd()->GetUymax());
578  l[i].SetLineWidth(1);
579  l[i].SetLineStyle(9);
580  l[i].SetLineColor(2);
581  l[i].Draw("same");
582  i++;
583  }
584 
585  TLegend legend = TLegend(0.52, 0.82, 0.95, 0.9);
586  legend.SetHeader((std::get<1>(iov)).c_str(), "C"); // option "C" allows to center the header
587  legend.AddEntry(
588  h_BadStrips.get(),
589  ("IOV: " + std::to_string(std::get<0>(iov)) + "| n. of bad strips:" + std::to_string(totalBadStrips)).c_str(),
590  "PL");
591  legend.SetTextSize(0.025);
592  legend.Draw("same");
593 
594  std::string fileName(m_imageFileName);
595  canvas.SaveAs(fileName.c_str());
596 
597  return true;
598  }
599 
600  private:
601  TrackerTopology m_trackerTopo;
602  };
603 
604  /************************************************
605  Plot BadStrip by region comparison
606  *************************************************/
607 
608  template <int ntags, IOVMultiplicity nIOVs>
609  class SiStripBadStripByRegionComparisonBase : public PlotImage<SiStripBadStrip, nIOVs, ntags> {
610  public:
611  SiStripBadStripByRegionComparisonBase()
612  : PlotImage<SiStripBadStrip, nIOVs, ntags>("SiStrip BadStrip By Region Comparison"),
614  edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
615 
616  bool fill() override {
617  // trick to deal with the multi-ioved tag and two tag case at the same time
618  auto theIOVs = PlotBase::getTag<0>().iovs;
619  auto tagname1 = PlotBase::getTag<0>().name;
620  std::string tagname2 = "";
621  auto firstiov = theIOVs.front();
622  std::tuple<cond::Time_t, cond::Hash> lastiov;
623 
624  // we don't support (yet) comparison with more than 2 tags
625  assert(this->m_plotAnnotations.ntags < 3);
626 
627  if (this->m_plotAnnotations.ntags == 2) {
628  auto tag2iovs = PlotBase::getTag<1>().iovs;
629  tagname2 = PlotBase::getTag<1>().name;
630  lastiov = tag2iovs.front();
631  } else {
632  lastiov = theIOVs.back();
633  }
634 
635  std::shared_ptr<SiStripBadStrip> last_payload = this->fetchPayload(std::get<1>(lastiov));
636  std::shared_ptr<SiStripBadStrip> first_payload = this->fetchPayload(std::get<1>(firstiov));
637 
638  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
639  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
640 
641  // last payload
642  std::vector<uint32_t> detid;
643  last_payload->getDetIds(detid);
644 
645  SiStripDetSummary summaryLastBadStrips{&m_trackerTopo};
646  int totalLastBadStrips = 0;
647 
648  for (const auto& d : detid) {
649  SiStripBadStrip::Range range = last_payload->getRange(d);
650  int badStrips(0);
651  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
652  badStrips += last_payload->decode(*badStrip).range;
653  }
654  totalLastBadStrips += badStrips;
655  summaryLastBadStrips.add(d, badStrips);
656  }
657  std::map<unsigned int, SiStripDetSummary::Values> mapLastBadStrips = summaryLastBadStrips.getCounts();
658 
659  // first payload
660  // needs to be cleared to avoid bias using only detIds of last payload
661  detid.clear();
662  first_payload->getDetIds(detid);
663 
664  SiStripDetSummary summaryFirstBadStrips{&m_trackerTopo};
665  int totalFirstBadStrips = 0;
666 
667  for (const auto& d : detid) {
668  SiStripBadStrip::Range range = first_payload->getRange(d);
669  int badStrips(0);
670  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
671  badStrips += first_payload->decode(*badStrip).range;
672  }
673  totalFirstBadStrips += badStrips;
674  summaryFirstBadStrips.add(d, badStrips);
675  }
676  std::map<unsigned int, SiStripDetSummary::Values> mapFirstBadStrips = summaryFirstBadStrips.getCounts();
677 
678  //=========================
679 
680  TCanvas canvas("BadStrip Partion summary", "SiStripBadStrip region summary", 1200, 1000);
681  canvas.cd();
682 
683  auto h_LastBadStrips = std::make_unique<TH1F>("BadStripsbyRegion1",
684  "SiStrip Bad Strip summary by region;; n. bad strips",
685  mapLastBadStrips.size(),
686  0.,
687  mapLastBadStrips.size());
688  h_LastBadStrips->SetStats(false);
689 
690  auto h_FirstBadStrips = std::make_unique<TH1F>("BadStripsbyRegion2",
691  "SiStrip Bad Strip summary by region;; n. bad strips",
692  mapFirstBadStrips.size(),
693  0.,
694  mapFirstBadStrips.size());
695  h_FirstBadStrips->SetStats(false);
696 
697  canvas.SetBottomMargin(0.18);
698  canvas.SetLeftMargin(0.12);
699  canvas.SetRightMargin(0.05);
700  canvas.Modified();
701 
702  std::vector<int> boundaries;
703  unsigned int iBin = 0;
704 
706  std::string currentDetector;
707 
708  for (const auto& element : mapLastBadStrips) {
709  iBin++;
710  int countBadStrips = (element.second.mean);
711 
712  if (currentDetector.empty())
713  currentDetector = "TIB";
714 
715  switch ((element.first) / 1000) {
716  case 1:
717  detector = "TIB";
718  break;
719  case 2:
720  detector = "TOB";
721  break;
722  case 3:
723  detector = "TEC";
724  break;
725  case 4:
726  detector = "TID";
727  break;
728  }
729 
730  h_LastBadStrips->SetBinContent(iBin, countBadStrips);
731  h_LastBadStrips->GetXaxis()->SetBinLabel(iBin, SiStripPI::regionType(element.first).second);
732  h_LastBadStrips->GetXaxis()->LabelsOption("v");
733 
734  if (detector != currentDetector) {
735  boundaries.push_back(iBin);
736  currentDetector = detector;
737  }
738  }
739 
740  // reset the count
741  iBin = 0;
742 
743  for (const auto& element : mapFirstBadStrips) {
744  iBin++;
745  int countBadStrips = (element.second.mean);
746 
747  h_FirstBadStrips->SetBinContent(iBin, countBadStrips);
748  h_FirstBadStrips->GetXaxis()->SetBinLabel(iBin, SiStripPI::regionType(element.first).second);
749  h_FirstBadStrips->GetXaxis()->LabelsOption("v");
750  }
751 
752  auto extrema = SiStripPI::getExtrema(h_FirstBadStrips.get(), h_LastBadStrips.get());
753  h_LastBadStrips->GetYaxis()->SetRangeUser(extrema.first, extrema.second);
754 
755  h_LastBadStrips->SetMarkerStyle(21);
756  h_LastBadStrips->SetMarkerSize(1);
757  h_LastBadStrips->SetLineColor(kBlue);
758  h_LastBadStrips->SetFillColor(kBlue);
759  h_LastBadStrips->SetLineStyle(9);
760  h_LastBadStrips->SetMarkerColor(kBlue);
761  h_LastBadStrips->GetYaxis()->SetRangeUser(0., h_LastBadStrips->GetMaximum() * 1.30);
762  h_LastBadStrips->GetYaxis()->SetTitleOffset(1.7);
763 
764  h_LastBadStrips->SetBarWidth(0.45);
765  h_LastBadStrips->SetBarOffset(0.1);
766  h_LastBadStrips->Draw("bar2");
767  h_LastBadStrips->Draw("TEXTsame");
768 
769  h_FirstBadStrips->SetMarkerStyle(20);
770  h_FirstBadStrips->SetMarkerSize(1);
771  h_FirstBadStrips->SetFillColor(kRed);
772  h_FirstBadStrips->SetLineColor(kRed);
773  h_FirstBadStrips->SetLineStyle(1);
774  h_FirstBadStrips->SetMarkerColor(kRed);
775  h_FirstBadStrips->GetYaxis()->SetTitleOffset(1.7);
776 
777  h_FirstBadStrips->SetBarWidth(0.4);
778  h_FirstBadStrips->SetBarOffset(0.55);
779 
780  h_FirstBadStrips->Draw("bar2same");
781  h_FirstBadStrips->Draw("TEXT45same");
782 
783  canvas.Update();
784  canvas.cd();
785 
786  TLine l[boundaries.size()];
787  unsigned int i = 0;
788  for (const auto& line : boundaries) {
789  l[i] = TLine(h_LastBadStrips->GetBinLowEdge(line),
790  canvas.cd()->GetUymin(),
791  h_LastBadStrips->GetBinLowEdge(line),
792  canvas.cd()->GetUymax());
793  l[i].SetLineWidth(1);
794  l[i].SetLineStyle(9);
795  l[i].SetLineColor(kMagenta);
796  l[i].Draw("same");
797  i++;
798  }
799 
800  TLegend legend = TLegend(0.52, 0.82, 0.95, 0.9);
801  legend.SetHeader("Bad Components comparison", "C"); // option "C" allows to center the header
802  legend.AddEntry(
803  h_LastBadStrips.get(),
804  ("IOV: " + std::to_string(std::get<0>(lastiov)) + "| n. of bad strips:" + std::to_string(totalLastBadStrips))
805  .c_str(),
806  "PL");
807  legend.AddEntry(h_FirstBadStrips.get(),
808  ("IOV: " + std::to_string(std::get<0>(firstiov)) +
809  "| n. of bad strips:" + std::to_string(totalFirstBadStrips))
810  .c_str(),
811  "PL");
812  legend.SetTextSize(0.025);
813  legend.Draw("same");
814 
815  std::string fileName(this->m_imageFileName);
816  canvas.SaveAs(fileName.c_str());
817 
818  return true;
819  }
820 
821  private:
822  TrackerTopology m_trackerTopo;
823  };
824 
825  using SiStripBadStripByRegionComparisonSingleTag = SiStripBadStripByRegionComparisonBase<1, MULTI_IOV>;
826  using SiStripBadStripByRegionComparisonTwoTags = SiStripBadStripByRegionComparisonBase<2, SINGLE_IOV>;
827 
828  /************************************************
829  TrackerMap of SiStripBadStrip (bad strips fraction difference)
830  *************************************************/
831 
832  template <int ntags, IOVMultiplicity nIOVs>
833  class SiStripBadStripFractionComparisonTrackerMapBase : public PlotImage<SiStripBadStrip, nIOVs, ntags> {
834  public:
835  SiStripBadStripFractionComparisonTrackerMapBase()
836  : PlotImage<SiStripBadStrip, nIOVs, ntags>("Tracker Map of SiStrip bad strip fraction difference") {}
837 
838  bool fill() override {
839  // trick to deal with the multi-ioved tag and two tag case at the same time
840  auto theIOVs = PlotBase::getTag<0>().iovs;
841  auto tagname1 = PlotBase::getTag<0>().name;
842  std::string tagname2 = "";
843  auto firstiov = theIOVs.front();
844  std::tuple<cond::Time_t, cond::Hash> lastiov;
845 
846  // we don't support (yet) comparison with more than 2 tags
847  assert(this->m_plotAnnotations.ntags < 3);
848 
849  if (this->m_plotAnnotations.ntags == 2) {
850  auto tag2iovs = PlotBase::getTag<1>().iovs;
851  tagname2 = PlotBase::getTag<1>().name;
852  lastiov = tag2iovs.front();
853  } else {
854  lastiov = theIOVs.back();
855  }
856 
857  std::shared_ptr<SiStripBadStrip> last_payload = this->fetchPayload(std::get<1>(lastiov));
858  std::shared_ptr<SiStripBadStrip> first_payload = this->fetchPayload(std::get<1>(firstiov));
859 
860  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
861  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
862 
863  const auto detInfo =
865 
866  std::string titleMap =
867  "#Delta fraction of bad Strips per module (IOV:" + lastIOVsince + " - IOV:" + firstIOVsince + ")";
868 
869  std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("SiStripBadStrips");
870  tmap->setTitle(titleMap);
871  tmap->setPalette(1);
872 
873  std::vector<uint32_t> detid1;
874  last_payload->getDetIds(detid1);
875 
876  std::map<uint32_t, float> FirstFractionPerDetId;
877  std::map<uint32_t, float> LastFractionPerDetId;
878 
879  for (const auto& d : detid1) {
880  SiStripBadStrip::Range range = last_payload->getRange(d);
881  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
882  LastFractionPerDetId[d] += last_payload->decode(*badStrip).range;
883  }
884  // normalize to the number of strips per module
885  LastFractionPerDetId[d] /= (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(d).first);
886  } // loop over detIds
887 
888  std::vector<uint32_t> detid2;
889  first_payload->getDetIds(detid2);
890 
891  //std::cout << "Size 2: " << detid1.size() << "| Size 1: "<< detid2.size() << std::endl;
892 
893  for (const auto& d : detid2) {
894  SiStripBadStrip::Range range = first_payload->getRange(d);
895  for (std::vector<unsigned int>::const_iterator badStrip = range.first; badStrip != range.second; ++badStrip) {
896  FirstFractionPerDetId[d] += first_payload->decode(*badStrip).range;
897  }
898  // normalize to the number of strips per module
899  FirstFractionPerDetId[d] /= (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(d).first);
900  } // loop over detIds
901 
902  std::vector<uint32_t> allDetIds = detInfo.getAllDetIds();
903 
904 #ifdef MMDEBUG
905  int countLastButNotFirst(0);
906  int countFirstButNotLast(0);
907  int countBoth(0);
908 #endif
909 
910  for (const auto& d : allDetIds) {
911  if (LastFractionPerDetId.find(d) != LastFractionPerDetId.end() &&
912  FirstFractionPerDetId.find(d) == FirstFractionPerDetId.end()) {
913  tmap->fill(d, LastFractionPerDetId[d]);
914 #ifdef MMDEBUG
915  countLastButNotFirst++;
916 #endif
917  } else if (LastFractionPerDetId.find(d) == LastFractionPerDetId.end() &&
918  FirstFractionPerDetId.find(d) != FirstFractionPerDetId.end()) {
919  tmap->fill(d, -FirstFractionPerDetId[d]);
920 #ifdef MMDEBUG
921  countFirstButNotLast++;
922 #endif
923  } else if (LastFractionPerDetId.find(d) != LastFractionPerDetId.end() &&
924  FirstFractionPerDetId.find(d) != FirstFractionPerDetId.end()) {
925  float delta = (LastFractionPerDetId[d] - FirstFractionPerDetId[d]);
926  if (delta != 0.) {
927  tmap->fill(d, delta);
928  }
929 #ifdef MMDEBUG
930  countBoth++;
931 #endif
932  }
933  }
934 
935 #ifdef MMDEBUG
936  std::cout << "In 2 but not in 1:" << countLastButNotFirst << std::endl;
937  std::cout << "In 1 but not in 2:" << countFirstButNotLast << std::endl;
938  std::cout << "In both:" << countBoth << std::endl;
939 #endif
940 
941  //=========================
942 
943  std::string fileName(this->m_imageFileName);
944  tmap->save(true, 0, 0, fileName);
945 
946  return true;
947  }
948  };
949 
950  using SiStripBadStripFractionComparisonTrackerMapSingleTag =
951  SiStripBadStripFractionComparisonTrackerMapBase<1, MULTI_IOV>;
952  using SiStripBadStripFractionComparisonTrackerMapTwoTags =
953  SiStripBadStripFractionComparisonTrackerMapBase<2, SINGLE_IOV>;
954 
955  /************************************************
956  Plot BadStrip Quality analysis
957  *************************************************/
958 
959  class SiStripBadStripQualityAnalysis : public PlotImage<SiStripBadStrip, SINGLE_IOV> {
960  public:
961  SiStripBadStripQualityAnalysis()
962  : PlotImage<SiStripBadStrip, SINGLE_IOV>("SiStrip BadStrip Quality Analysis"),
964  edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
965 
966  bool fill() override {
967  auto tag = PlotBase::getTag<0>();
968  auto iov = tag.iovs.front();
969  std::shared_ptr<SiStripBadStrip> payload = fetchPayload(std::get<1>(iov));
970 
971  const auto detInfo =
973  SiStripQuality* siStripQuality_ = new SiStripQuality(detInfo);
974  siStripQuality_->add(payload.get());
975  siStripQuality_->cleanUp();
976  siStripQuality_->fillBadComponents();
977 
978  // store global info
979 
980  //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
981  int NTkBadComponent[4] = {0};
982 
983  //legend: NBadComponent[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
984  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
985  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
986  int NBadComponent[4][19][4] = {{{0}}};
987 
988  // call the filler
989  SiStripPI::fillBCArrays(siStripQuality_, NTkBadComponent, NBadComponent, m_trackerTopo);
990 
991  //&&&&&&&&&&&&&&&&&&
992  // printout
993  //&&&&&&&&&&&&&&&&&&
994 
995  std::stringstream ss;
996  ss.str("");
997  ss << "\n-----------------\nGlobal Info\n-----------------";
998  ss << "\nBadComponent \t Modules \tFibers "
999  "\tApvs\tStrips\n----------------------------------------------------------------";
1000  ss << "\nTracker:\t\t" << NTkBadComponent[0] << "\t" << NTkBadComponent[1] << "\t" << NTkBadComponent[2] << "\t"
1001  << NTkBadComponent[3];
1002  ss << "\n";
1003  ss << "\nTIB:\t\t\t" << NBadComponent[0][0][0] << "\t" << NBadComponent[0][0][1] << "\t" << NBadComponent[0][0][2]
1004  << "\t" << NBadComponent[0][0][3];
1005  ss << "\nTID:\t\t\t" << NBadComponent[1][0][0] << "\t" << NBadComponent[1][0][1] << "\t" << NBadComponent[1][0][2]
1006  << "\t" << NBadComponent[1][0][3];
1007  ss << "\nTOB:\t\t\t" << NBadComponent[2][0][0] << "\t" << NBadComponent[2][0][1] << "\t" << NBadComponent[2][0][2]
1008  << "\t" << NBadComponent[2][0][3];
1009  ss << "\nTEC:\t\t\t" << NBadComponent[3][0][0] << "\t" << NBadComponent[3][0][1] << "\t" << NBadComponent[3][0][2]
1010  << "\t" << NBadComponent[3][0][3];
1011  ss << "\n";
1012 
1013  for (int i = 1; i < 5; ++i)
1014  ss << "\nTIB Layer " << i << " :\t\t" << NBadComponent[0][i][0] << "\t" << NBadComponent[0][i][1] << "\t"
1015  << NBadComponent[0][i][2] << "\t" << NBadComponent[0][i][3];
1016  ss << "\n";
1017  for (int i = 1; i < 4; ++i)
1018  ss << "\nTID+ Disk " << i << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
1019  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
1020  for (int i = 4; i < 7; ++i)
1021  ss << "\nTID- Disk " << i - 3 << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
1022  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
1023  ss << "\n";
1024  for (int i = 1; i < 7; ++i)
1025  ss << "\nTOB Layer " << i << " :\t\t" << NBadComponent[2][i][0] << "\t" << NBadComponent[2][i][1] << "\t"
1026  << NBadComponent[2][i][2] << "\t" << NBadComponent[2][i][3];
1027  ss << "\n";
1028  for (int i = 1; i < 10; ++i)
1029  ss << "\nTEC+ Disk " << i << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
1030  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
1031  for (int i = 10; i < 19; ++i)
1032  ss << "\nTEC- Disk " << i - 9 << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
1033  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
1034  ss << "\n";
1035 
1036  edm::LogInfo("SiStripBadStrip_PayloadInspector") << ss.str() << std::endl;
1037  //std::cout<< ss.str() << std::endl;
1038 
1039  auto masterTable = std::make_unique<TH2I>("table", "", 4, 0., 4., 39, 0., 39.);
1040 
1041  std::string labelsX[4] = {"Bad Modules", "Bad Fibers", "Bad APVs", "Bad Strips"};
1042  std::string labelsY[40] = {
1043  "Tracker", "TIB", "TID", "TOB", "TEC", "TIB Layer 1", "TIB Layer 2",
1044  "TIB Layer 3", "TIB Layer 4", "TID+ Disk 1", "TID+ Disk 2", "TID+ Disk 3", "TID- Disk 1", "TID- Disk 2",
1045  "TID- Disk 3", "TOB Layer 1", "TOB Layer 2", "TOB Layer 3", "TOB Layer 4", "TOB Layer 5", "TOB Layer 6",
1046  "TEC+ Disk 1", "TEC+ Disk 2", "TEC+ Disk 3", "TEC+ Disk 4", "TEC+ Disk 5", "TEC+ Disk 6", "TEC+ Disk 7",
1047  "TEC+ Disk 8", "TEC+ Disk 9", "TEC- Disk 1", "TEC- Disk 2", "TEC- Disk 3", "TEC- Disk 4", "TEC- Disk 5",
1048  "TEC- Disk 6", "TEC- Disk 7", "TEC- Disk 8", "TEC- Disk 9"};
1049 
1050  for (int iX = 0; iX <= 3; iX++) {
1051  masterTable->GetXaxis()->SetBinLabel(iX + 1, labelsX[iX].c_str());
1052  }
1053 
1054  for (int iY = 39; iY >= 1; iY--) {
1055  masterTable->GetYaxis()->SetBinLabel(iY, labelsY[39 - iY].c_str());
1056  }
1057 
1058  // 0 1 2 3
1059  int layerBoundaries[4] = {4, 6, 6, 18};
1060  std::vector<int> boundaries;
1061  boundaries.push_back(39);
1062  boundaries.push_back(35);
1063 
1064  int cursor = 0;
1065  int layerIndex = 0;
1066  for (int iY = 39; iY >= 1; iY--) {
1067  for (int iX = 0; iX <= 3; iX++) {
1068  if (iY == 39) {
1069  masterTable->SetBinContent(iX + 1, iY, NTkBadComponent[iX]);
1070  } else if (iY >= 35) {
1071  masterTable->SetBinContent(iX + 1, iY, NBadComponent[(39 - iY) - 1][0][iX]);
1072  } else {
1073  if (iX == 0)
1074  layerIndex++;
1075  //std::cout<<"iY:"<<iY << " cursor: " <<cursor << " layerIndex: " << layerIndex << " layer check: "<< layerBoundaries[cursor] <<std::endl;
1076  masterTable->SetBinContent(iX + 1, iY, NBadComponent[cursor][layerIndex][iX]);
1077  }
1078  }
1079  if (layerIndex == layerBoundaries[cursor]) {
1080  // bring on the subdet counter and reset the layer count
1081  cursor++;
1082  layerIndex = 0;
1083  boundaries.push_back(iY);
1084  }
1085  }
1086 
1087  TCanvas canv("canv", "canv", 800, 800);
1088  canv.cd();
1089 
1090  canv.SetTopMargin(0.05);
1091  canv.SetBottomMargin(0.07);
1092  canv.SetLeftMargin(0.18);
1093  canv.SetRightMargin(0.05);
1094 
1095  masterTable->GetYaxis()->SetLabelSize(0.04);
1096  masterTable->GetXaxis()->SetLabelSize(0.05);
1097 
1098  masterTable->SetStats(false);
1099  canv.SetGrid();
1100 
1101  masterTable->Draw("text");
1102 
1103  canv.Update();
1104  canv.cd();
1105 
1106  TLine l[boundaries.size()];
1107  unsigned int i = 0;
1108  for (const auto& line : boundaries) {
1109  l[i] = TLine(canv.cd()->GetUxmin(),
1110  masterTable->GetYaxis()->GetBinLowEdge(line),
1111  canv.cd()->GetUxmax(),
1112  masterTable->GetYaxis()->GetBinLowEdge(line));
1113  l[i].SetLineWidth(2);
1114  l[i].SetLineStyle(9);
1115  l[i].SetLineColor(kMagenta);
1116  l[i].Draw("same");
1117  i++;
1118  }
1119 
1120  canv.cd();
1121  TLatex title;
1122  title.SetTextSize(0.027);
1123  title.SetTextColor(kBlue);
1124  title.DrawLatexNDC(0.12, 0.97, ("IOV: " + std::to_string(std::get<0>(iov)) + "| " + std::get<1>(iov)).c_str());
1125  std::string fileName(m_imageFileName);
1126  canv.SaveAs(fileName.c_str());
1127 
1128  delete siStripQuality_;
1129  return true;
1130  }
1131 
1132  private:
1133  TrackerTopology m_trackerTopo;
1134  };
1135 
1136  /************************************************
1137  Plot BadStrip Quality Comparison
1138  *************************************************/
1139 
1140  template <int ntags, IOVMultiplicity nIOVs>
1141  class SiStripBadStripQualityComparisonBase : public PlotImage<SiStripBadStrip, nIOVs, ntags> {
1142  public:
1143  SiStripBadStripQualityComparisonBase()
1144  : PlotImage<SiStripBadStrip, nIOVs, ntags>("SiStrip BadStrip Quality Comparison Analysis"),
1146  edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
1147 
1148  bool fill() override {
1149  //SiStripPI::setPaletteStyle(SiStripPI::BLUERED);
1150  gStyle->SetPalette(kTemperatureMap);
1151 
1152  // trick to deal with the multi-ioved tag and two tag case at the same time
1153  auto theIOVs = PlotBase::getTag<0>().iovs;
1154  auto tagname1 = PlotBase::getTag<0>().name;
1155  std::string tagname2 = "";
1156  auto firstiov = theIOVs.front();
1157  std::tuple<cond::Time_t, cond::Hash> lastiov;
1158 
1159  // we don't support (yet) comparison with more than 2 tags
1160  assert(this->m_plotAnnotations.ntags < 3);
1161 
1162  if (this->m_plotAnnotations.ntags == 2) {
1163  auto tag2iovs = PlotBase::getTag<1>().iovs;
1164  tagname2 = PlotBase::getTag<1>().name;
1165  lastiov = tag2iovs.front();
1166  } else {
1167  lastiov = theIOVs.back();
1168  }
1169 
1170  std::shared_ptr<SiStripBadStrip> last_payload = this->fetchPayload(std::get<1>(lastiov));
1171  std::shared_ptr<SiStripBadStrip> first_payload = this->fetchPayload(std::get<1>(firstiov));
1172 
1173  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1174  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1175 
1176  // store global info
1177 
1178  //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
1179  int f_NTkBadComponent[4] = {0};
1180  int l_NTkBadComponent[4] = {0};
1181 
1182  // for the total
1183  int tot_NTkComponents[4] = {0};
1184 
1185  //legend: NBadComponent[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
1186  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
1187  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
1188  int f_NBadComponent[4][19][4] = {{{0}}};
1189  int l_NBadComponent[4][19][4] = {{{0}}};
1190 
1191  // for the total
1192  int totNComponents[4][19][4] = {{{0}}};
1193 
1194  const auto detInfo =
1196  SiStripQuality* f_siStripQuality_ = new SiStripQuality(detInfo);
1197  f_siStripQuality_->add(first_payload.get());
1198  f_siStripQuality_->cleanUp();
1199  f_siStripQuality_->fillBadComponents();
1200 
1201  // call the filler
1202  SiStripPI::fillBCArrays(f_siStripQuality_, f_NTkBadComponent, f_NBadComponent, m_trackerTopo);
1203 
1204  SiStripQuality* l_siStripQuality_ = new SiStripQuality(detInfo);
1205  l_siStripQuality_->add(last_payload.get());
1206  l_siStripQuality_->cleanUp();
1207  l_siStripQuality_->fillBadComponents();
1208 
1209  // call the filler
1210  SiStripPI::fillBCArrays(l_siStripQuality_, l_NTkBadComponent, l_NBadComponent, m_trackerTopo);
1211 
1212  // fill the total number of components
1213  SiStripPI::fillTotalComponents(tot_NTkComponents, totNComponents, m_trackerTopo);
1214 
1215  // debug
1216  //SiStripPI::printBCDebug(f_NTkBadComponent,f_NBadComponent);
1217  //SiStripPI::printBCDebug(l_NTkBadComponent,l_NBadComponent);
1218 
1219  //SiStripPI::printBCDebug(tot_NTkComponents,totNComponents);
1220 
1221  // declare histograms
1222  auto masterTable = std::make_unique<TH2F>("table", "", 4, 0., 4., 39, 0., 39.);
1223  auto masterTableColor = std::make_unique<TH2F>("colortable", "", 4, 0., 4., 39, 0., 39.);
1224 
1225  std::string labelsX[4] = {"Bad Modules", "Bad Fibers", "Bad APVs", "Bad Strips"};
1226  std::string labelsY[40] = {
1227  "Tracker", "TIB", "TID", "TOB", "TEC", "TIB Layer 1", "TIB Layer 2",
1228  "TIB Layer 3", "TIB Layer 4", "TID+ Disk 1", "TID+ Disk 2", "TID+ Disk 3", "TID- Disk 1", "TID- Disk 2",
1229  "TID- Disk 3", "TOB Layer 1", "TOB Layer 2", "TOB Layer 3", "TOB Layer 4", "TOB Layer 5", "TOB Layer 6",
1230  "TEC+ Disk 1", "TEC+ Disk 2", "TEC+ Disk 3", "TEC+ Disk 4", "TEC+ Disk 5", "TEC+ Disk 6", "TEC+ Disk 7",
1231  "TEC+ Disk 8", "TEC+ Disk 9", "TEC- Disk 1", "TEC- Disk 2", "TEC- Disk 3", "TEC- Disk 4", "TEC- Disk 5",
1232  "TEC- Disk 6", "TEC- Disk 7", "TEC- Disk 8", "TEC- Disk 9"};
1233 
1234  for (int iX = 0; iX <= 3; iX++) {
1235  masterTable->GetXaxis()->SetBinLabel(iX + 1, labelsX[iX].c_str());
1236  masterTableColor->GetXaxis()->SetBinLabel(iX + 1, labelsX[iX].c_str());
1237  }
1238 
1239  for (int iY = 39; iY >= 1; iY--) {
1240  masterTable->GetYaxis()->SetBinLabel(iY, labelsY[39 - iY].c_str());
1241  masterTableColor->GetYaxis()->SetBinLabel(iY, labelsY[39 - iY].c_str());
1242  }
1243 
1244  // 0 1 2 3
1245  int layerBoundaries[4] = {4, 6, 6, 18};
1246  std::vector<int> boundaries;
1247  boundaries.push_back(39);
1248  boundaries.push_back(35);
1249 
1250  int cursor = 0;
1251  int layerIndex = 0;
1252  for (int iY = 39; iY >= 1; iY--) {
1253  for (int iX = 0; iX <= 3; iX++) {
1254  if (iY == 39) {
1255  masterTable->SetBinContent(iX + 1, iY, l_NTkBadComponent[iX] - f_NTkBadComponent[iX]);
1256  masterTableColor->SetBinContent(
1257  iX + 1, iY, 100 * float(l_NTkBadComponent[iX] - f_NTkBadComponent[iX]) / tot_NTkComponents[iX]);
1258  //std::cout<< (l_NTkBadComponent[iX]-f_NTkBadComponent[iX]) << " " << tot_NTkComponents[iX] << " " << float(l_NTkBadComponent[iX]-f_NTkBadComponent[iX])/tot_NTkComponents[iX] << std::endl;
1259  } else if (iY >= 35) {
1260  masterTable->SetBinContent(
1261  iX + 1, iY, (l_NBadComponent[(39 - iY) - 1][0][iX] - f_NBadComponent[(39 - iY) - 1][0][iX]));
1262  masterTableColor->SetBinContent(
1263  iX + 1,
1264  iY,
1265  100 * float(l_NBadComponent[(39 - iY) - 1][0][iX] - f_NBadComponent[(39 - iY) - 1][0][iX]) /
1266  totNComponents[(39 - iY) - 1][0][iX]);
1267  } else {
1268  if (iX == 0)
1269  layerIndex++;
1270  //std::cout<<"iY:"<<iY << " cursor: " <<cursor << " layerIndex: " << layerIndex << " layer check: "<< layerBoundaries[cursor] <<std::endl;
1271  masterTable->SetBinContent(
1272  iX + 1, iY, (l_NBadComponent[cursor][layerIndex][iX] - f_NBadComponent[cursor][layerIndex][iX]));
1273  masterTableColor->SetBinContent(
1274  iX + 1,
1275  iY,
1276  100 * float(l_NBadComponent[cursor][layerIndex][iX] - f_NBadComponent[cursor][layerIndex][iX]) /
1277  totNComponents[cursor][layerIndex][iX]);
1278  }
1279  }
1280  if (layerIndex == layerBoundaries[cursor]) {
1281  // bring on the subdet counter and reset the layer count
1282  cursor++;
1283  layerIndex = 0;
1284  boundaries.push_back(iY);
1285  }
1286  }
1287 
1288  TCanvas canv("canv", "canv", 1000, 800);
1289  canv.cd();
1290 
1291  canv.SetTopMargin(0.05);
1292  canv.SetBottomMargin(0.07);
1293  canv.SetLeftMargin(0.13);
1294  canv.SetRightMargin(0.16);
1295 
1296  masterTable->SetStats(false);
1297  masterTableColor->SetStats(false);
1298  canv.SetGrid();
1299 
1300  masterTable->SetMarkerColor(kBlack);
1301  masterTable->SetMarkerSize(1.5);
1302 
1303  float extremum = std::abs(masterTableColor->GetMaximum()) > std::abs(masterTableColor->GetMinimum())
1304  ? std::abs(masterTableColor->GetMaximum())
1305  : std::abs(masterTableColor->GetMinimum());
1306  //masterTableColor->Draw("text");
1307  masterTableColor->GetZaxis()->SetRangeUser(-extremum, extremum);
1308  masterTableColor->GetZaxis()->SetTitle("percent change [%]");
1309  masterTableColor->GetZaxis()->CenterTitle(true);
1310  masterTableColor->GetZaxis()->SetTitleSize(0.05);
1311 
1312  masterTableColor->GetYaxis()->SetLabelSize(0.04);
1313  masterTableColor->GetXaxis()->SetLabelSize(0.06);
1314 
1315  masterTable->GetYaxis()->SetLabelSize(0.04);
1316  masterTable->GetXaxis()->SetLabelSize(0.06);
1317 
1318  masterTableColor->Draw("COLZ");
1319  masterTable->Draw("textsame");
1320 
1321  canv.Update();
1322  canv.cd();
1323 
1324  TLine l[boundaries.size()];
1325  unsigned int i = 0;
1326  for (const auto& line : boundaries) {
1327  l[i] = TLine(canv.cd()->GetUxmin(),
1328  masterTable->GetYaxis()->GetBinLowEdge(line),
1329  canv.cd()->GetUxmax(),
1330  masterTable->GetYaxis()->GetBinLowEdge(line));
1331  l[i].SetLineWidth(2);
1332  l[i].SetLineStyle(9);
1333  l[i].SetLineColor(kMagenta);
1334  l[i].Draw("same");
1335  i++;
1336  }
1337 
1338  canv.cd();
1339  TLatex title;
1340  title.SetTextSize(0.045);
1341  title.SetTextColor(kBlue);
1342  title.DrawLatexNDC(
1343  0.33,
1344  0.96,
1345  ("#DeltaIOV: " + std::to_string(std::get<0>(lastiov)) + " - " + std::to_string(std::get<0>(firstiov)))
1346  .c_str());
1347  std::string fileName(this->m_imageFileName);
1348  canv.SaveAs(fileName.c_str());
1349 
1350  delete f_siStripQuality_;
1351  delete l_siStripQuality_;
1352 
1353  return true;
1354  }
1355 
1356  private:
1357  TrackerTopology m_trackerTopo;
1358  };
1359 
1360  using SiStripBadStripQualityComparisonSingleTag = SiStripBadStripQualityComparisonBase<1, MULTI_IOV>;
1361  using SiStripBadStripQualityComparisonTwoTags = SiStripBadStripQualityComparisonBase<2, SINGLE_IOV>;
1362 
1363 } // namespace
1364 
1365 // Register the classes as boost python plugin
1367  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTest);
1368  PAYLOAD_INSPECTOR_CLASS(SiStripBadModuleTrackerMap);
1369  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionTrackerMap);
1370  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionTkMap);
1371  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionByRun);
1372  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTIBFractionByRun);
1373  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTOBFractionByRun);
1374  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTIDFractionByRun);
1375  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTECFractionByRun);
1376  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripByRegion);
1377  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripByRegionComparisonSingleTag);
1378  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripByRegionComparisonTwoTags);
1379  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionComparisonTrackerMapSingleTag);
1380  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionComparisonTrackerMapTwoTags);
1381  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripQualityAnalysis);
1382  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripQualityComparisonSingleTag);
1383  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripQualityComparisonTwoTags);
1384 }
static constexpr auto TEC
bool cleanUp(bool force=false)
std::pair< int, const char * > regionType(int index)
void fillBCArrays(const SiStripQuality *siStripQuality_, int NTkBadComponent[4], int NBadComponent[4][19][4], const TrackerTopology m_trackerTopo)
assert(be >=bs)
void add(uint32_t, const SiStripBadStrip::Range &)
static std::string to_string(const XMLCh *ch)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
std::pair< float, float > getExtrema(TH1 *h1, TH1 *h2)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
SiStripDetInfo read(std::string filePath)
static constexpr auto TOB
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
void fillBadComponents()
d
Definition: ztail.py:151
Log< level::Info, false > LogInfo
Definition: DetId.h:17
static constexpr auto TIB
void fillTotalComponents(int NTkComponents[4], int NComponents[4][19][4], const TrackerTopology m_trackerTopo)
static const uint16_t STRIPS_PER_APV
std::pair< ContainerIterator, ContainerIterator > Range
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
def canvas(sub, attr)
Definition: svgfig.py:482
static constexpr char const *const kDefaultFile
static constexpr auto TID