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  int countLastButNotFirst(0);
905  int countFirstButNotLast(0);
906  int countBoth(0);
907 
908  for (const auto& d : allDetIds) {
909  if (LastFractionPerDetId.find(d) != LastFractionPerDetId.end() &&
910  FirstFractionPerDetId.find(d) == FirstFractionPerDetId.end()) {
911  tmap->fill(d, LastFractionPerDetId[d]);
912  countLastButNotFirst++;
913  } else if (LastFractionPerDetId.find(d) == LastFractionPerDetId.end() &&
914  FirstFractionPerDetId.find(d) != FirstFractionPerDetId.end()) {
915  tmap->fill(d, -FirstFractionPerDetId[d]);
916  countFirstButNotLast++;
917  } else if (LastFractionPerDetId.find(d) != LastFractionPerDetId.end() &&
918  FirstFractionPerDetId.find(d) != FirstFractionPerDetId.end()) {
919  float delta = (LastFractionPerDetId[d] - FirstFractionPerDetId[d]);
920  if (delta != 0.) {
921  tmap->fill(d, delta);
922  }
923  countBoth++;
924  }
925  }
926 
927 #ifdef MMDEBUG
928  std::cout << "In 2 but not in 1:" << countLastButNotFirst << std::endl;
929  std::cout << "In 1 but not in 2:" << countFirstButNotLast << std::endl;
930  std::cout << "In both:" << countBoth << std::endl;
931 #endif
932 
933  //=========================
934 
935  std::string fileName(this->m_imageFileName);
936  tmap->save(true, 0, 0, fileName);
937 
938  return true;
939  }
940  };
941 
942  using SiStripBadStripFractionComparisonTrackerMapSingleTag =
943  SiStripBadStripFractionComparisonTrackerMapBase<1, MULTI_IOV>;
944  using SiStripBadStripFractionComparisonTrackerMapTwoTags =
945  SiStripBadStripFractionComparisonTrackerMapBase<2, SINGLE_IOV>;
946 
947  /************************************************
948  Plot BadStrip Quality analysis
949  *************************************************/
950 
951  class SiStripBadStripQualityAnalysis : public PlotImage<SiStripBadStrip, SINGLE_IOV> {
952  public:
953  SiStripBadStripQualityAnalysis()
954  : PlotImage<SiStripBadStrip, SINGLE_IOV>("SiStrip BadStrip Quality Analysis"),
956  edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
957 
958  bool fill() override {
959  auto tag = PlotBase::getTag<0>();
960  auto iov = tag.iovs.front();
961  std::shared_ptr<SiStripBadStrip> payload = fetchPayload(std::get<1>(iov));
962 
963  const auto detInfo =
965  SiStripQuality* siStripQuality_ = new SiStripQuality(detInfo);
966  siStripQuality_->add(payload.get());
967  siStripQuality_->cleanUp();
968  siStripQuality_->fillBadComponents();
969 
970  // store global info
971 
972  //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
973  int NTkBadComponent[4] = {0};
974 
975  //legend: NBadComponent[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
976  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
977  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
978  int NBadComponent[4][19][4] = {{{0}}};
979 
980  // call the filler
981  SiStripPI::fillBCArrays(siStripQuality_, NTkBadComponent, NBadComponent, m_trackerTopo);
982 
983  //&&&&&&&&&&&&&&&&&&
984  // printout
985  //&&&&&&&&&&&&&&&&&&
986 
987  std::stringstream ss;
988  ss.str("");
989  ss << "\n-----------------\nGlobal Info\n-----------------";
990  ss << "\nBadComponent \t Modules \tFibers "
991  "\tApvs\tStrips\n----------------------------------------------------------------";
992  ss << "\nTracker:\t\t" << NTkBadComponent[0] << "\t" << NTkBadComponent[1] << "\t" << NTkBadComponent[2] << "\t"
993  << NTkBadComponent[3];
994  ss << "\n";
995  ss << "\nTIB:\t\t\t" << NBadComponent[0][0][0] << "\t" << NBadComponent[0][0][1] << "\t" << NBadComponent[0][0][2]
996  << "\t" << NBadComponent[0][0][3];
997  ss << "\nTID:\t\t\t" << NBadComponent[1][0][0] << "\t" << NBadComponent[1][0][1] << "\t" << NBadComponent[1][0][2]
998  << "\t" << NBadComponent[1][0][3];
999  ss << "\nTOB:\t\t\t" << NBadComponent[2][0][0] << "\t" << NBadComponent[2][0][1] << "\t" << NBadComponent[2][0][2]
1000  << "\t" << NBadComponent[2][0][3];
1001  ss << "\nTEC:\t\t\t" << NBadComponent[3][0][0] << "\t" << NBadComponent[3][0][1] << "\t" << NBadComponent[3][0][2]
1002  << "\t" << NBadComponent[3][0][3];
1003  ss << "\n";
1004 
1005  for (int i = 1; i < 5; ++i)
1006  ss << "\nTIB Layer " << i << " :\t\t" << NBadComponent[0][i][0] << "\t" << NBadComponent[0][i][1] << "\t"
1007  << NBadComponent[0][i][2] << "\t" << NBadComponent[0][i][3];
1008  ss << "\n";
1009  for (int i = 1; i < 4; ++i)
1010  ss << "\nTID+ Disk " << i << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
1011  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
1012  for (int i = 4; i < 7; ++i)
1013  ss << "\nTID- Disk " << i - 3 << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
1014  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
1015  ss << "\n";
1016  for (int i = 1; i < 7; ++i)
1017  ss << "\nTOB Layer " << i << " :\t\t" << NBadComponent[2][i][0] << "\t" << NBadComponent[2][i][1] << "\t"
1018  << NBadComponent[2][i][2] << "\t" << NBadComponent[2][i][3];
1019  ss << "\n";
1020  for (int i = 1; i < 10; ++i)
1021  ss << "\nTEC+ Disk " << i << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
1022  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
1023  for (int i = 10; i < 19; ++i)
1024  ss << "\nTEC- Disk " << i - 9 << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
1025  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
1026  ss << "\n";
1027 
1028  edm::LogInfo("SiStripBadStrip_PayloadInspector") << ss.str() << std::endl;
1029  //std::cout<< ss.str() << std::endl;
1030 
1031  auto masterTable = std::make_unique<TH2I>("table", "", 4, 0., 4., 39, 0., 39.);
1032 
1033  std::string labelsX[4] = {"Bad Modules", "Bad Fibers", "Bad APVs", "Bad Strips"};
1034  std::string labelsY[40] = {
1035  "Tracker", "TIB", "TID", "TOB", "TEC", "TIB Layer 1", "TIB Layer 2",
1036  "TIB Layer 3", "TIB Layer 4", "TID+ Disk 1", "TID+ Disk 2", "TID+ Disk 3", "TID- Disk 1", "TID- Disk 2",
1037  "TID- Disk 3", "TOB Layer 1", "TOB Layer 2", "TOB Layer 3", "TOB Layer 4", "TOB Layer 5", "TOB Layer 6",
1038  "TEC+ Disk 1", "TEC+ Disk 2", "TEC+ Disk 3", "TEC+ Disk 4", "TEC+ Disk 5", "TEC+ Disk 6", "TEC+ Disk 7",
1039  "TEC+ Disk 8", "TEC+ Disk 9", "TEC- Disk 1", "TEC- Disk 2", "TEC- Disk 3", "TEC- Disk 4", "TEC- Disk 5",
1040  "TEC- Disk 6", "TEC- Disk 7", "TEC- Disk 8", "TEC- Disk 9"};
1041 
1042  for (int iX = 0; iX <= 3; iX++) {
1043  masterTable->GetXaxis()->SetBinLabel(iX + 1, labelsX[iX].c_str());
1044  }
1045 
1046  for (int iY = 39; iY >= 1; iY--) {
1047  masterTable->GetYaxis()->SetBinLabel(iY, labelsY[39 - iY].c_str());
1048  }
1049 
1050  // 0 1 2 3
1051  int layerBoundaries[4] = {4, 6, 6, 18};
1052  std::vector<int> boundaries;
1053  boundaries.push_back(39);
1054  boundaries.push_back(35);
1055 
1056  int cursor = 0;
1057  int layerIndex = 0;
1058  for (int iY = 39; iY >= 1; iY--) {
1059  for (int iX = 0; iX <= 3; iX++) {
1060  if (iY == 39) {
1061  masterTable->SetBinContent(iX + 1, iY, NTkBadComponent[iX]);
1062  } else if (iY >= 35) {
1063  masterTable->SetBinContent(iX + 1, iY, NBadComponent[(39 - iY) - 1][0][iX]);
1064  } else {
1065  if (iX == 0)
1066  layerIndex++;
1067  //std::cout<<"iY:"<<iY << " cursor: " <<cursor << " layerIndex: " << layerIndex << " layer check: "<< layerBoundaries[cursor] <<std::endl;
1068  masterTable->SetBinContent(iX + 1, iY, NBadComponent[cursor][layerIndex][iX]);
1069  }
1070  }
1071  if (layerIndex == layerBoundaries[cursor]) {
1072  // bring on the subdet counter and reset the layer count
1073  cursor++;
1074  layerIndex = 0;
1075  boundaries.push_back(iY);
1076  }
1077  }
1078 
1079  TCanvas canv("canv", "canv", 800, 800);
1080  canv.cd();
1081 
1082  canv.SetTopMargin(0.05);
1083  canv.SetBottomMargin(0.07);
1084  canv.SetLeftMargin(0.18);
1085  canv.SetRightMargin(0.05);
1086 
1087  masterTable->GetYaxis()->SetLabelSize(0.04);
1088  masterTable->GetXaxis()->SetLabelSize(0.05);
1089 
1090  masterTable->SetStats(false);
1091  canv.SetGrid();
1092 
1093  masterTable->Draw("text");
1094 
1095  canv.Update();
1096  canv.cd();
1097 
1098  TLine l[boundaries.size()];
1099  unsigned int i = 0;
1100  for (const auto& line : boundaries) {
1101  l[i] = TLine(canv.cd()->GetUxmin(),
1102  masterTable->GetYaxis()->GetBinLowEdge(line),
1103  canv.cd()->GetUxmax(),
1104  masterTable->GetYaxis()->GetBinLowEdge(line));
1105  l[i].SetLineWidth(2);
1106  l[i].SetLineStyle(9);
1107  l[i].SetLineColor(kMagenta);
1108  l[i].Draw("same");
1109  i++;
1110  }
1111 
1112  canv.cd();
1113  TLatex title;
1114  title.SetTextSize(0.027);
1115  title.SetTextColor(kBlue);
1116  title.DrawLatexNDC(0.12, 0.97, ("IOV: " + std::to_string(std::get<0>(iov)) + "| " + std::get<1>(iov)).c_str());
1117  std::string fileName(m_imageFileName);
1118  canv.SaveAs(fileName.c_str());
1119 
1120  delete siStripQuality_;
1121  return true;
1122  }
1123 
1124  private:
1125  TrackerTopology m_trackerTopo;
1126  };
1127 
1128  /************************************************
1129  Plot BadStrip Quality Comparison
1130  *************************************************/
1131 
1132  template <int ntags, IOVMultiplicity nIOVs>
1133  class SiStripBadStripQualityComparisonBase : public PlotImage<SiStripBadStrip, nIOVs, ntags> {
1134  public:
1135  SiStripBadStripQualityComparisonBase()
1136  : PlotImage<SiStripBadStrip, nIOVs, ntags>("SiStrip BadStrip Quality Comparison Analysis"),
1138  edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())} {}
1139 
1140  bool fill() override {
1141  //SiStripPI::setPaletteStyle(SiStripPI::BLUERED);
1142  gStyle->SetPalette(kTemperatureMap);
1143 
1144  // trick to deal with the multi-ioved tag and two tag case at the same time
1145  auto theIOVs = PlotBase::getTag<0>().iovs;
1146  auto tagname1 = PlotBase::getTag<0>().name;
1147  std::string tagname2 = "";
1148  auto firstiov = theIOVs.front();
1149  std::tuple<cond::Time_t, cond::Hash> lastiov;
1150 
1151  // we don't support (yet) comparison with more than 2 tags
1152  assert(this->m_plotAnnotations.ntags < 3);
1153 
1154  if (this->m_plotAnnotations.ntags == 2) {
1155  auto tag2iovs = PlotBase::getTag<1>().iovs;
1156  tagname2 = PlotBase::getTag<1>().name;
1157  lastiov = tag2iovs.front();
1158  } else {
1159  lastiov = theIOVs.back();
1160  }
1161 
1162  std::shared_ptr<SiStripBadStrip> last_payload = this->fetchPayload(std::get<1>(lastiov));
1163  std::shared_ptr<SiStripBadStrip> first_payload = this->fetchPayload(std::get<1>(firstiov));
1164 
1165  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1166  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1167 
1168  // store global info
1169 
1170  //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
1171  int f_NTkBadComponent[4] = {0};
1172  int l_NTkBadComponent[4] = {0};
1173 
1174  // for the total
1175  int tot_NTkComponents[4] = {0};
1176 
1177  //legend: NBadComponent[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
1178  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
1179  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
1180  int f_NBadComponent[4][19][4] = {{{0}}};
1181  int l_NBadComponent[4][19][4] = {{{0}}};
1182 
1183  // for the total
1184  int totNComponents[4][19][4] = {{{0}}};
1185 
1186  const auto detInfo =
1188  SiStripQuality* f_siStripQuality_ = new SiStripQuality(detInfo);
1189  f_siStripQuality_->add(first_payload.get());
1190  f_siStripQuality_->cleanUp();
1191  f_siStripQuality_->fillBadComponents();
1192 
1193  // call the filler
1194  SiStripPI::fillBCArrays(f_siStripQuality_, f_NTkBadComponent, f_NBadComponent, m_trackerTopo);
1195 
1196  SiStripQuality* l_siStripQuality_ = new SiStripQuality(detInfo);
1197  l_siStripQuality_->add(last_payload.get());
1198  l_siStripQuality_->cleanUp();
1199  l_siStripQuality_->fillBadComponents();
1200 
1201  // call the filler
1202  SiStripPI::fillBCArrays(l_siStripQuality_, l_NTkBadComponent, l_NBadComponent, m_trackerTopo);
1203 
1204  // fill the total number of components
1205  SiStripPI::fillTotalComponents(tot_NTkComponents, totNComponents, m_trackerTopo);
1206 
1207  // debug
1208  //SiStripPI::printBCDebug(f_NTkBadComponent,f_NBadComponent);
1209  //SiStripPI::printBCDebug(l_NTkBadComponent,l_NBadComponent);
1210 
1211  //SiStripPI::printBCDebug(tot_NTkComponents,totNComponents);
1212 
1213  // declare histograms
1214  auto masterTable = std::make_unique<TH2F>("table", "", 4, 0., 4., 39, 0., 39.);
1215  auto masterTableColor = std::make_unique<TH2F>("colortable", "", 4, 0., 4., 39, 0., 39.);
1216 
1217  std::string labelsX[4] = {"Bad Modules", "Bad Fibers", "Bad APVs", "Bad Strips"};
1218  std::string labelsY[40] = {
1219  "Tracker", "TIB", "TID", "TOB", "TEC", "TIB Layer 1", "TIB Layer 2",
1220  "TIB Layer 3", "TIB Layer 4", "TID+ Disk 1", "TID+ Disk 2", "TID+ Disk 3", "TID- Disk 1", "TID- Disk 2",
1221  "TID- Disk 3", "TOB Layer 1", "TOB Layer 2", "TOB Layer 3", "TOB Layer 4", "TOB Layer 5", "TOB Layer 6",
1222  "TEC+ Disk 1", "TEC+ Disk 2", "TEC+ Disk 3", "TEC+ Disk 4", "TEC+ Disk 5", "TEC+ Disk 6", "TEC+ Disk 7",
1223  "TEC+ Disk 8", "TEC+ Disk 9", "TEC- Disk 1", "TEC- Disk 2", "TEC- Disk 3", "TEC- Disk 4", "TEC- Disk 5",
1224  "TEC- Disk 6", "TEC- Disk 7", "TEC- Disk 8", "TEC- Disk 9"};
1225 
1226  for (int iX = 0; iX <= 3; iX++) {
1227  masterTable->GetXaxis()->SetBinLabel(iX + 1, labelsX[iX].c_str());
1228  masterTableColor->GetXaxis()->SetBinLabel(iX + 1, labelsX[iX].c_str());
1229  }
1230 
1231  for (int iY = 39; iY >= 1; iY--) {
1232  masterTable->GetYaxis()->SetBinLabel(iY, labelsY[39 - iY].c_str());
1233  masterTableColor->GetYaxis()->SetBinLabel(iY, labelsY[39 - iY].c_str());
1234  }
1235 
1236  // 0 1 2 3
1237  int layerBoundaries[4] = {4, 6, 6, 18};
1238  std::vector<int> boundaries;
1239  boundaries.push_back(39);
1240  boundaries.push_back(35);
1241 
1242  int cursor = 0;
1243  int layerIndex = 0;
1244  for (int iY = 39; iY >= 1; iY--) {
1245  for (int iX = 0; iX <= 3; iX++) {
1246  if (iY == 39) {
1247  masterTable->SetBinContent(iX + 1, iY, l_NTkBadComponent[iX] - f_NTkBadComponent[iX]);
1248  masterTableColor->SetBinContent(
1249  iX + 1, iY, 100 * float(l_NTkBadComponent[iX] - f_NTkBadComponent[iX]) / tot_NTkComponents[iX]);
1250  //std::cout<< (l_NTkBadComponent[iX]-f_NTkBadComponent[iX]) << " " << tot_NTkComponents[iX] << " " << float(l_NTkBadComponent[iX]-f_NTkBadComponent[iX])/tot_NTkComponents[iX] << std::endl;
1251  } else if (iY >= 35) {
1252  masterTable->SetBinContent(
1253  iX + 1, iY, (l_NBadComponent[(39 - iY) - 1][0][iX] - f_NBadComponent[(39 - iY) - 1][0][iX]));
1254  masterTableColor->SetBinContent(
1255  iX + 1,
1256  iY,
1257  100 * float(l_NBadComponent[(39 - iY) - 1][0][iX] - f_NBadComponent[(39 - iY) - 1][0][iX]) /
1258  totNComponents[(39 - iY) - 1][0][iX]);
1259  } else {
1260  if (iX == 0)
1261  layerIndex++;
1262  //std::cout<<"iY:"<<iY << " cursor: " <<cursor << " layerIndex: " << layerIndex << " layer check: "<< layerBoundaries[cursor] <<std::endl;
1263  masterTable->SetBinContent(
1264  iX + 1, iY, (l_NBadComponent[cursor][layerIndex][iX] - f_NBadComponent[cursor][layerIndex][iX]));
1265  masterTableColor->SetBinContent(
1266  iX + 1,
1267  iY,
1268  100 * float(l_NBadComponent[cursor][layerIndex][iX] - f_NBadComponent[cursor][layerIndex][iX]) /
1269  totNComponents[cursor][layerIndex][iX]);
1270  }
1271  }
1272  if (layerIndex == layerBoundaries[cursor]) {
1273  // bring on the subdet counter and reset the layer count
1274  cursor++;
1275  layerIndex = 0;
1276  boundaries.push_back(iY);
1277  }
1278  }
1279 
1280  TCanvas canv("canv", "canv", 1000, 800);
1281  canv.cd();
1282 
1283  canv.SetTopMargin(0.05);
1284  canv.SetBottomMargin(0.07);
1285  canv.SetLeftMargin(0.13);
1286  canv.SetRightMargin(0.16);
1287 
1288  masterTable->SetStats(false);
1289  masterTableColor->SetStats(false);
1290  canv.SetGrid();
1291 
1292  masterTable->SetMarkerColor(kBlack);
1293  masterTable->SetMarkerSize(1.5);
1294 
1295  float extremum = std::abs(masterTableColor->GetMaximum()) > std::abs(masterTableColor->GetMinimum())
1296  ? std::abs(masterTableColor->GetMaximum())
1297  : std::abs(masterTableColor->GetMinimum());
1298  //masterTableColor->Draw("text");
1299  masterTableColor->GetZaxis()->SetRangeUser(-extremum, extremum);
1300  masterTableColor->GetZaxis()->SetTitle("percent change [%]");
1301  masterTableColor->GetZaxis()->CenterTitle(true);
1302  masterTableColor->GetZaxis()->SetTitleSize(0.05);
1303 
1304  masterTableColor->GetYaxis()->SetLabelSize(0.04);
1305  masterTableColor->GetXaxis()->SetLabelSize(0.06);
1306 
1307  masterTable->GetYaxis()->SetLabelSize(0.04);
1308  masterTable->GetXaxis()->SetLabelSize(0.06);
1309 
1310  masterTableColor->Draw("COLZ");
1311  masterTable->Draw("textsame");
1312 
1313  canv.Update();
1314  canv.cd();
1315 
1316  TLine l[boundaries.size()];
1317  unsigned int i = 0;
1318  for (const auto& line : boundaries) {
1319  l[i] = TLine(canv.cd()->GetUxmin(),
1320  masterTable->GetYaxis()->GetBinLowEdge(line),
1321  canv.cd()->GetUxmax(),
1322  masterTable->GetYaxis()->GetBinLowEdge(line));
1323  l[i].SetLineWidth(2);
1324  l[i].SetLineStyle(9);
1325  l[i].SetLineColor(kMagenta);
1326  l[i].Draw("same");
1327  i++;
1328  }
1329 
1330  canv.cd();
1331  TLatex title;
1332  title.SetTextSize(0.045);
1333  title.SetTextColor(kBlue);
1334  title.DrawLatexNDC(
1335  0.33,
1336  0.96,
1337  ("#DeltaIOV: " + std::to_string(std::get<0>(lastiov)) + " - " + std::to_string(std::get<0>(firstiov)))
1338  .c_str());
1339  std::string fileName(this->m_imageFileName);
1340  canv.SaveAs(fileName.c_str());
1341 
1342  delete f_siStripQuality_;
1343  delete l_siStripQuality_;
1344 
1345  return true;
1346  }
1347 
1348  private:
1349  TrackerTopology m_trackerTopo;
1350  };
1351 
1352  using SiStripBadStripQualityComparisonSingleTag = SiStripBadStripQualityComparisonBase<1, MULTI_IOV>;
1353  using SiStripBadStripQualityComparisonTwoTags = SiStripBadStripQualityComparisonBase<2, SINGLE_IOV>;
1354 
1355 } // namespace
1356 
1357 // Register the classes as boost python plugin
1359  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTest);
1360  PAYLOAD_INSPECTOR_CLASS(SiStripBadModuleTrackerMap);
1361  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionTrackerMap);
1362  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionTkMap);
1363  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionByRun);
1364  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTIBFractionByRun);
1365  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTOBFractionByRun);
1366  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTIDFractionByRun);
1367  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripTECFractionByRun);
1368  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripByRegion);
1369  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripByRegionComparisonSingleTag);
1370  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripByRegionComparisonTwoTags);
1371  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionComparisonTrackerMapSingleTag);
1372  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripFractionComparisonTrackerMapTwoTags);
1373  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripQualityAnalysis);
1374  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripQualityComparisonSingleTag);
1375  PAYLOAD_INSPECTOR_CLASS(SiStripBadStripQualityComparisonTwoTags);
1376 }
static constexpr auto TEC
bool cleanUp(bool force=false)
std::pair< int, const char * > regionType(int index)
std::string to_string(const V &value)
Definition: OMSAccess.h:71
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 &)
#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