CMS 3D CMS Logo

SiPixelQuality_PayloadInspector.cc
Go to the documentation of this file.
1 
10 
18 
19 // the data format of the condition to be inspected
26 
27 #include <memory>
28 #include <sstream>
29 #include <iostream>
30 
31 // include ROOT
32 #include "TH2F.h"
33 #include "TLegend.h"
34 #include "TCanvas.h"
35 #include "TLine.h"
36 #include "TGraph.h"
37 #include "TStyle.h"
38 #include "TLatex.h"
39 #include "TPave.h"
40 #include "TPaveStats.h"
41 
42 namespace {
43 
44  using namespace cond::payloadInspector;
45 
46  /************************************************
47  test class
48  *************************************************/
49 
50  class SiPixelQualityTest : public Histogram1D<SiPixelQuality, SINGLE_IOV> {
51  public:
52  SiPixelQualityTest()
53  : Histogram1D<SiPixelQuality, SINGLE_IOV>("SiPixelQuality test", "SiPixelQuality test", 10, 0.0, 10.0) {}
54 
55  bool fill() override {
56  auto tag = PlotBase::getTag<0>();
57  for (auto const& iov : tag.iovs) {
58  std::shared_ptr<SiPixelQuality> payload = Base::fetchPayload(std::get<1>(iov));
59  if (payload.get()) {
60  fillWithValue(1.);
61 
62  auto theDisabledModules = payload->getBadComponentList();
63  for (const auto& mod : theDisabledModules) {
64  int BadRocCount(0);
65  for (unsigned short n = 0; n < 16; n++) {
66  unsigned short mask = 1 << n; // 1 << n = 2^{n} using bitwise shift
67  if (mod.BadRocs & mask)
68  BadRocCount++;
69  }
70  COUT << "detId:" << mod.DetID << " error type:" << mod.errorType << " BadRocs:" << BadRocCount << std::endl;
71  }
72  } // payload
73  } // iovs
74  return true;
75  } // fill
76  };
77 
78  /************************************************
79  Debugging class, to not be displayed
80  *************************************************/
81 
82  class SiPixelQualityDebugger : public Histogram1D<SiPixelQuality, SINGLE_IOV> {
83  public:
84  SiPixelQualityDebugger()
85  : Histogram1D<SiPixelQuality, SINGLE_IOV>("SiPixelQuality test", "SiPixelQuality test", 10, 0.0, 10.0) {}
86 
87  bool fill() override {
88  auto tag = PlotBase::getTag<0>();
89  for (auto const& iov : tag.iovs) {
90  std::shared_ptr<SiPixelQuality> payload = Base::fetchPayload(std::get<1>(iov));
91  if (payload.get()) {
92  fillWithValue(1.);
93 
94  SiPixelPI::topolInfo t_info_fromXML;
95  t_info_fromXML.init();
96 
97  auto theDisabledModules = payload->getBadComponentList();
98  for (const auto& mod : theDisabledModules) {
99  DetId detid(mod.DetID);
101  const char* path_toTopologyXML = PhInfo.pathToTopoXML();
102  auto tTopo =
104  t_info_fromXML.fillGeometryInfo(detid, tTopo, PhInfo.phase());
105  std::stringstream ss;
106  t_info_fromXML.printAll(ss);
107  std::bitset<16> bad_rocs(mod.BadRocs);
108 
109  if (t_info_fromXML.subDetId() == 1 && t_info_fromXML.layer() == 1) {
110  std::cout << ss.str() << " s_module: " << SiPixelPI::signed_module(mod.DetID, tTopo, true)
111  << " s_ladder: " << SiPixelPI::signed_ladder(mod.DetID, tTopo, true)
112  << " error type:" << mod.errorType << " BadRocs: " << bad_rocs.to_string('O', 'X') << std::endl;
113  }
114  }
115  } // payload
116  } // iovs
117  return true;
118  } // fill
119  };
120 
121  /************************************************
122  summary class
123  *************************************************/
124 
125  class SiPixelQualityBadRocsSummary : public PlotImage<SiPixelQuality, MULTI_IOV, 1> {
126  public:
127  SiPixelQualityBadRocsSummary() : PlotImage<SiPixelQuality, MULTI_IOV, 1>("SiPixel Quality Summary") {}
128 
129  bool fill() override {
130  auto tag = PlotBase::getTag<0>();
131  for (const auto& iov : tag.iovs) {
132  std::shared_ptr<SiPixelQuality> payload = fetchPayload(std::get<1>(iov));
133  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
134 
135  COUT << "======================= " << unpacked.first << " : " << unpacked.second << std::endl;
136  auto theDisabledModules = payload->getBadComponentList();
137  for (const auto& mod : theDisabledModules) {
138  COUT << "detId: " << mod.DetID << " |error type: " << mod.errorType << " |BadRocs: " << mod.BadRocs
139  << std::endl;
140  }
141  }
142 
143  //=========================
144  TCanvas canv("Partition summary", "partition summary", 1200, 1000);
145  canv.SetBottomMargin(0.11);
146  canv.SetLeftMargin(0.13);
147  canv.SetRightMargin(0.05);
148  canv.cd();
150 
151  std::string fileName(m_imageFileName);
152  canv.SaveAs(fileName.c_str());
153 
154  return true;
155  }
156  };
157 
158  /************************************************
159  time history class
160  *************************************************/
161 
162  class SiPixelQualityBadRocsTimeHistory : public TimeHistoryPlot<SiPixelQuality, std::pair<double, double> > {
163  public:
164  SiPixelQualityBadRocsTimeHistory()
165  : TimeHistoryPlot<SiPixelQuality, std::pair<double, double> >("bad ROCs count vs time", "bad ROCs count") {}
166 
167  std::pair<double, double> getFromPayload(SiPixelQuality& payload) override {
168  return std::make_pair(extractBadRocCount(payload), 0.);
169  }
170 
171  unsigned int extractBadRocCount(SiPixelQuality& payload) {
172  unsigned int BadRocCount(0);
173  auto theDisabledModules = payload.getBadComponentList();
174  for (const auto& mod : theDisabledModules) {
175  for (unsigned short n = 0; n < 16; n++) {
176  unsigned short mask = 1 << n; // 1 << n = 2^{n} using bitwise shift
177  if (mod.BadRocs & mask)
178  BadRocCount++;
179  }
180  }
181  return BadRocCount;
182  }
183  };
184 
185  /************************************************
186  occupancy style map whole Pixel
187  *************************************************/
188  template <SiPixelPI::DetType myType>
189  class SiPixelQualityMap : public PlotImage<SiPixelQuality, SINGLE_IOV> {
190  public:
191  SiPixelQualityMap()
192  : PlotImage<SiPixelQuality, SINGLE_IOV>("SiPixelQuality Pixel Map"),
194  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {}
195 
196  bool fill() override {
197  auto tag = PlotBase::getTag<0>();
198  auto iov = tag.iovs.front();
199  auto tagname = tag.name;
200  std::shared_ptr<SiPixelQuality> payload = fetchPayload(std::get<1>(iov));
201 
202  Phase1PixelROCMaps theMap("");
203 
204  auto theDisabledModules = payload->getBadComponentList();
205  if (this->isPhase0(theDisabledModules)) {
206  edm::LogError("SiPixelQuality_PayloadInspector")
207  << "SiPixelQuality maps are not supported for non-Phase1 Pixel geometries !";
208  TCanvas canvas("Canv", "Canv", 1200, 1000);
210  std::string fileName(m_imageFileName);
211  canvas.SaveAs(fileName.c_str());
212  return false;
213  }
214 
215  for (const auto& mod : theDisabledModules) {
216  int subid = DetId(mod.DetID).subdetId();
217 
218  if ((subid == PixelSubdetector::PixelBarrel && myType == SiPixelPI::t_barrel) ||
219  (subid == PixelSubdetector::PixelEndcap && myType == SiPixelPI::t_forward) ||
220  (myType == SiPixelPI::t_all)) {
221  std::bitset<16> bad_rocs(mod.BadRocs);
222  if (payload->IsModuleBad(mod.DetID)) {
223  theMap.fillWholeModule(mod.DetID, 1.);
224  } else {
225  theMap.fillSelectedRocs(mod.DetID, bad_rocs, 1.);
226  }
227  }
228  }
229 
230  gStyle->SetOptStat(0);
231  //=========================
232  TCanvas canvas("Summary", "Summary", 1200, k_height[myType]);
233  canvas.cd();
234 
235  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
236 
237  std::string IOVstring = (unpacked.first == 0)
238  ? std::to_string(unpacked.second)
239  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second));
240 
241  const auto headerText = fmt::sprintf("#color[4]{%s}, IOV: #color[4]{%s}", tagname, IOVstring);
242 
243  switch (myType) {
244  case SiPixelPI::t_barrel:
245  theMap.drawBarrelMaps(canvas, headerText);
246  break;
248  theMap.drawForwardMaps(canvas, headerText);
249  break;
250  case SiPixelPI::t_all:
251  theMap.drawMaps(canvas, headerText);
252  break;
253  default:
254  throw cms::Exception("SiPixelQualityMap") << "\nERROR: unrecognized Pixel Detector part " << std::endl;
255  }
256 
257  std::string fileName(m_imageFileName);
258  canvas.SaveAs(fileName.c_str());
259 #ifdef MMDEBUG
260  canvas.SaveAs("outAll.root");
261 #endif
262 
263  return true;
264  }
265 
266  private:
267  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
268  TrackerTopology m_trackerTopo;
269 
270  //_________________________________________________
271  bool isPhase0(std::vector<SiPixelQuality::disabledModuleType> mods) {
274  const auto& p0detIds = reader.getAllDetIds();
275 
276  std::vector<uint32_t> ownDetIds;
277  std::transform(mods.begin(),
278  mods.end(),
279  std::back_inserter(ownDetIds),
280  [](SiPixelQuality::disabledModuleType d) -> uint32_t { return d.DetID; });
281 
282  for (const auto& det : ownDetIds) {
283  // if found at least one phase-0 detId early return
284  if (std::find(p0detIds.begin(), p0detIds.end(), det) != p0detIds.end()) {
285  return true;
286  }
287  }
288  return false;
289  }
290  };
291 
292  using SiPixelBPixQualityMap = SiPixelQualityMap<SiPixelPI::t_barrel>;
293  using SiPixelFPixQualityMap = SiPixelQualityMap<SiPixelPI::t_forward>;
294  using SiPixelFullQualityMap = SiPixelQualityMap<SiPixelPI::t_all>;
295 
296  /************************************************
297  occupancy style map whole Pixel, difference of payloads
298  *************************************************/
299  template <SiPixelPI::DetType myType, IOVMultiplicity nIOVs, int ntags>
300  class SiPixelQualityMapComparisonBase : public PlotImage<SiPixelQuality, nIOVs, ntags> {
301  public:
302  SiPixelQualityMapComparisonBase()
303  : PlotImage<SiPixelQuality, nIOVs, ntags>(
304  Form("SiPixelQuality %s Pixel Map", SiPixelPI::DetNames[myType].c_str())),
306  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {}
307 
308  bool fill() override {
309  // trick to deal with the multi-ioved tag and two tag case at the same time
310  auto theIOVs = PlotBase::getTag<0>().iovs;
311  auto f_tagname = PlotBase::getTag<0>().name;
312  std::string l_tagname = "";
313  auto firstiov = theIOVs.front();
314  std::tuple<cond::Time_t, cond::Hash> lastiov;
315 
316  // we don't support (yet) comparison with more than 2 tags
317  assert(this->m_plotAnnotations.ntags < 3);
318 
319  if (this->m_plotAnnotations.ntags == 2) {
320  auto tag2iovs = PlotBase::getTag<1>().iovs;
321  l_tagname = PlotBase::getTag<1>().name;
322  lastiov = tag2iovs.front();
323  } else {
324  lastiov = theIOVs.back();
325  }
326 
327  std::shared_ptr<SiPixelQuality> last_payload = this->fetchPayload(std::get<1>(lastiov));
328  std::shared_ptr<SiPixelQuality> first_payload = this->fetchPayload(std::get<1>(firstiov));
329 
330  if (this->isPhase0(first_payload) || this->isPhase0(last_payload)) {
331  edm::LogError("SiPixelQuality_PayloadInspector")
332  << "SiPixelQuality comparison maps are not supported for non-Phase1 Pixel geometries !";
333  TCanvas canvas("Canv", "Canv", 1200, 1000);
335  std::string fileName(this->m_imageFileName);
336  canvas.SaveAs(fileName.c_str());
337  return false;
338  }
339 
340  Phase1PixelROCMaps theMap("", "#Delta payload A - payload B");
341 
342  gStyle->SetOptStat(0);
343  //=========================
344  TCanvas canvas("Summary", "Summary", 1200, k_height[myType]);
345  canvas.cd();
346 
347  auto f_unpacked = SiPixelPI::unpack(std::get<0>(firstiov));
348  auto l_unpacked = SiPixelPI::unpack(std::get<0>(lastiov));
349 
350  std::string f_IOVstring = (f_unpacked.first == 0)
351  ? std::to_string(f_unpacked.second)
352  : (std::to_string(f_unpacked.first) + "," + std::to_string(f_unpacked.second));
353 
354  std::string l_IOVstring = (l_unpacked.first == 0)
355  ? std::to_string(l_unpacked.second)
356  : (std::to_string(l_unpacked.first) + "," + std::to_string(l_unpacked.second));
357 
358  std::string headerText;
359 
360  if (this->m_plotAnnotations.ntags == 2) {
361  headerText = fmt::sprintf(
362  "#Delta #color[2]{A: %s, %s} - #color[4]{B: %s, %s}", f_tagname, f_IOVstring, l_tagname, l_IOVstring);
363  } else {
364  headerText =
365  fmt::sprintf("%s, #Delta IOV #color[2]{A: %s} - #color[4]{B: %s} ", f_tagname, f_IOVstring, l_IOVstring);
366  }
367 
368  switch (myType) {
369  case SiPixelPI::t_barrel:
370  theMap.drawBarrelMaps(canvas, headerText);
371  break;
373  theMap.drawForwardMaps(canvas, headerText);
374  break;
375  case SiPixelPI::t_all:
376  theMap.drawMaps(canvas, headerText);
377  break;
378  default:
379  throw cms::Exception("SiPixelQualityMapComparison")
380  << "\nERROR: unrecognized Pixel Detector part " << std::endl;
381  }
382 
383  // first loop on the first payload (newest)
384  fillTheMapFromPayload(theMap, first_payload, false);
385 
386  // then loop on the second payload (oldest)
387  fillTheMapFromPayload(theMap, last_payload, true); // true will subtract
388 
389  std::string fileName(this->m_imageFileName);
390  canvas.SaveAs(fileName.c_str());
391 #ifdef MMDEBUG
392  canvas.SaveAs("outAll.root");
393 #endif
394 
395  return true;
396  }
397 
398  private:
399  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
400  TrackerTopology m_trackerTopo;
401 
402  //_________________________________________________
403  bool isPhase0(const std::shared_ptr<SiPixelQuality>& payload) {
404  const auto mods = payload->getBadComponentList();
407  const auto& p0detIds = reader.getAllDetIds();
408 
409  std::vector<uint32_t> ownDetIds;
410  std::transform(mods.begin(),
411  mods.end(),
412  std::back_inserter(ownDetIds),
413  [](SiPixelQuality::disabledModuleType d) -> uint32_t { return d.DetID; });
414 
415  for (const auto& det : ownDetIds) {
416  // if found at least one phase-0 detId early return
417  if (std::find(p0detIds.begin(), p0detIds.end(), det) != p0detIds.end()) {
418  return true;
419  }
420  }
421  return false;
422  }
423 
424  //____________________________________________________________________________________________
425  void fillTheMapFromPayload(Phase1PixelROCMaps& theMap,
426  const std::shared_ptr<SiPixelQuality>& payload,
427  bool subtract) {
428  const auto theDisabledModules = payload->getBadComponentList();
429  for (const auto& mod : theDisabledModules) {
430  int subid = DetId(mod.DetID).subdetId();
431  if ((subid == PixelSubdetector::PixelBarrel && myType == SiPixelPI::t_barrel) ||
432  (subid == PixelSubdetector::PixelEndcap && myType == SiPixelPI::t_forward) ||
433  (myType == SiPixelPI::t_all)) {
434  std::bitset<16> bad_rocs(mod.BadRocs);
435  if (payload->IsModuleBad(mod.DetID)) {
436  theMap.fillWholeModule(mod.DetID, (subtract ? -1. : 1.));
437  } else {
438  theMap.fillSelectedRocs(mod.DetID, bad_rocs, (subtract ? -1. : 1.));
439  }
440  }
441  }
442  }
443  };
444 
445  using SiPixelBPixQualityMapCompareSingleTag = SiPixelQualityMapComparisonBase<SiPixelPI::t_barrel, MULTI_IOV, 1>;
446  using SiPixelFPixQualityMapCompareSingleTag = SiPixelQualityMapComparisonBase<SiPixelPI::t_forward, MULTI_IOV, 1>;
447  using SiPixelFullQualityMapCompareSingleTag = SiPixelQualityMapComparisonBase<SiPixelPI::t_all, MULTI_IOV, 1>;
448  using SiPixelBPixQualityMapCompareTwoTags = SiPixelQualityMapComparisonBase<SiPixelPI::t_barrel, SINGLE_IOV, 2>;
449  using SiPixelFPixQualityMapCompareTwoTags = SiPixelQualityMapComparisonBase<SiPixelPI::t_forward, SINGLE_IOV, 2>;
450  using SiPixelFullQualityMapCompareTwoTags = SiPixelQualityMapComparisonBase<SiPixelPI::t_all, SINGLE_IOV, 2>;
451 
452  /************************************************
453  Full Pixel Tracker Map class
454  *************************************************/
455  class SiPixelQualityBadFractionMap : public PlotImage<SiPixelQuality, SINGLE_IOV> {
456  public:
457  SiPixelQualityBadFractionMap() : PlotImage<SiPixelQuality, SINGLE_IOV>("SiPixelQuality Map") {
458  label_ = "SiPixelQualityFullPixelMap";
459  payloadString = "Quality";
460  }
461 
462  bool fill() override {
463  gStyle->SetPalette(1);
464  auto tag = PlotBase::getTag<0>();
465  auto iov = tag.iovs.front();
466  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
467  std::shared_ptr<SiPixelQuality> payload = this->fetchPayload(std::get<1>(iov));
468 
469  if (payload.get()) {
470  Phase1PixelSummaryMap fullMap(
471  "", fmt::sprintf("%s", payloadString), fmt::sprintf("bad %s fraction [%%]", payloadString));
472  fullMap.createTrackerBaseMap();
473 
474  auto theDisabledModules = payload->getBadComponentList();
475  if (this->isPhase0(theDisabledModules)) {
476  edm::LogError("SiPixelQuality_PayloadInspector")
477  << "SiPixelQuality maps are not supported for non-Phase1 Pixel geometries !";
478  TCanvas canvas("Canv", "Canv", 1200, 1000);
480  std::string fileName(m_imageFileName);
481  canvas.SaveAs(fileName.c_str());
482  return false;
483  }
484 
485  for (const auto& mod : theDisabledModules) {
486  std::bitset<16> bad_rocs(mod.BadRocs);
487  fullMap.fillTrackerMap(mod.DetID, (bad_rocs.count() / 16.) * 100); // 16 ROCs in a Pixel Phase-1 module!
488  }
489 
490  TCanvas canvas("Canv", "Canv", 3000, 2000);
491  fullMap.printTrackerMap(canvas);
492 
493  auto ltx = TLatex();
494  ltx.SetTextFont(62);
495  ltx.SetTextSize(0.025);
496  ltx.SetTextAlign(11);
497  ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
498  gPad->GetBottomMargin() + 0.01,
499  ("#color[4]{" + tag.name + "}, IOV: #color[4]{" + std::to_string(unpacked.first) + "," +
500  std::to_string(unpacked.second) + " }")
501  .c_str());
502 
503  std::string fileName(this->m_imageFileName);
504  canvas.SaveAs(fileName.c_str());
505  }
506  return true;
507  }
508 
509  protected:
510  std::string payloadString;
511  std::string label_;
512 
513  private:
514  //_________________________________________________
515  bool isPhase0(std::vector<SiPixelQuality::disabledModuleType> mods) {
518  const auto& p0detIds = reader.getAllDetIds();
519 
520  std::vector<uint32_t> ownDetIds;
521  std::transform(mods.begin(),
522  mods.end(),
523  std::back_inserter(ownDetIds),
524  [](SiPixelQuality::disabledModuleType d) -> uint32_t { return d.DetID; });
525 
526  for (const auto& det : ownDetIds) {
527  // if found at least one phase-0 detId early return
528  if (std::find(p0detIds.begin(), p0detIds.end(), det) != p0detIds.end()) {
529  return true;
530  }
531  }
532  return false;
533  }
534  };
535 } // namespace
536 
537 // Register the classes as boost python plugin
539  PAYLOAD_INSPECTOR_CLASS(SiPixelQualityTest);
540  PAYLOAD_INSPECTOR_CLASS(SiPixelQualityBadRocsSummary);
541  PAYLOAD_INSPECTOR_CLASS(SiPixelQualityBadRocsTimeHistory);
542  //PAYLOAD_INSPECTOR_CLASS(SiPixelQualityDebugger);
543  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixQualityMap);
544  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixQualityMap);
545  PAYLOAD_INSPECTOR_CLASS(SiPixelFullQualityMap);
546  PAYLOAD_INSPECTOR_CLASS(SiPixelQualityBadFractionMap);
547  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixQualityMapCompareSingleTag);
548  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixQualityMapCompareSingleTag);
549  PAYLOAD_INSPECTOR_CLASS(SiPixelFullQualityMapCompareSingleTag);
550  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixQualityMapCompareTwoTags);
551  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixQualityMapCompareTwoTags);
552  PAYLOAD_INSPECTOR_CLASS(SiPixelFullQualityMapCompareTwoTags);
553 }
void fillGeometryInfo(const DetId &detId, const TrackerTopology &tTopo, const SiPixelPI::phase &ph)
reader
Definition: DQM.py:105
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
static std::string to_string(const XMLCh *ch)
void fillWholeModule(const uint32_t &detid, double value)
int signed_ladder(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
void printAll(std::stringstream &ss) const
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
static const unsigned int phase1size
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
#define COUT
d
Definition: ztail.py:151
Definition: DetId.h:17
const std::array< std::string, 3 > DetNames
int signed_module(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
void displayNotSupported(TCanvas &canv, const unsigned int size)
void fillSelectedRocs(const uint32_t &detid, const std::bitset< 16 > &theROCs, double value)
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
def canvas(sub, attr)
Definition: svgfig.py:482
static constexpr char const *const kPh0DefaultFile
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
unsigned transform(const HcalDetId &id, unsigned transformCode)