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