CMS 3D CMS Logo

SiPixelFEDChannelContainer_PayloadInspector.cc
Go to the documentation of this file.
1 
11 
19 
28 
29 // the data format of the condition to be inspected
31 #include "CondFormats/SiPixelObjects/interface/SiPixelQualityProbabilities.h" // to display aggregate probability
36 
37 #include <memory>
38 #include <sstream>
39 #include <iostream>
40 #include <fmt/printf.h>
41 
42 // include ROOT
43 #include "TH2F.h"
44 #include "TLegend.h"
45 #include "TCanvas.h"
46 #include "TLine.h"
47 #include "TGraph.h"
48 #include "TGaxis.h"
49 #include "TStyle.h"
50 #include "TLatex.h"
51 #include "TPave.h"
52 #include "TPaveStats.h"
53 
54 namespace {
55 
56  using namespace cond::payloadInspector;
57 
58  /************************************************
59  1d histogram of SiPixelFEDChannelContainer of 1 IOV
60  *************************************************/
61 
62  template <SiPixelPI::DetType myType>
63  class SiPixelFEDChannelContainerMap : public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
64  public:
65  SiPixelFEDChannelContainerMap()
67  "SiPixelFEDChannelContainer Pixel Track Map of one (or more scenarios"),
69  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {
70  // for inputs
71  PlotBase::addInputParam("Scenarios");
72 
73  // hardcoded connection to the MC cabling tag, though luck
74  m_condDbCabling = "frontier://FrontierProd/CMS_CONDITIONS";
75  m_CablingTagName = "SiPixelFedCablingMap_phase1_v7";
76 
77  m_connectionPool.setParameters(m_connectionPset);
78  m_connectionPool.configure();
79  }
80 
81  bool fill() override {
82  std::vector<std::string> the_scenarios = {};
83 
84  auto paramValues = PlotBase::inputParamValues();
85  auto ip = paramValues.find("Scenarios");
86  if (ip != paramValues.end()) {
87  auto input = ip->second;
88  typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
89  boost::char_separator<char> sep{","};
90  tokenizer tok{input, sep};
91  for (const auto& t : tok) {
92  the_scenarios.push_back(t);
93  }
94  } else {
95  edm::LogWarning(k_ClassName)
96  << "\n WARNING!!!! \n The needed parameter Scenarios has not been passed. Will use all the scenarios in "
97  "the file!"
98  << "\n Buckle your seatbelts... this might take a while... \n\n";
99  the_scenarios.push_back("all");
100  }
101 
102  Phase1PixelROCMaps theROCMap("");
103 
104  auto tag = PlotBase::getTag<0>();
105  auto tagname = tag.name;
106  auto iov = tag.iovs.front();
107 
108  // open db session for the cabling map
109  edm::LogPrint(k_ClassName) << "[SiPixelFEDChannelContainerTest::" << __func__ << "] "
110  << "Query the condition database " << m_condDbCabling;
111 
112  cond::persistency::Session condDbSession = m_connectionPool.createSession(m_condDbCabling);
113  condDbSession.transaction().start(true);
114 
115  // query the database
116  edm::LogPrint(k_ClassName) << "[SiPixelFEDChannelContainerTest::" << __func__ << "] "
117  << "Reading IOVs from tag " << m_CablingTagName;
118 
121 
122  // get the list of payloads for the Cabling Map
123  std::vector<std::tuple<cond::Time_t, cond::Hash>> m_cabling_iovs;
124  condDbSession.readIov(m_CablingTagName).selectRange(MIN_VAL, MAX_VAL, m_cabling_iovs);
125 
126  std::vector<unsigned int> listOfCablingIOVs;
127  std::transform(m_cabling_iovs.begin(),
128  m_cabling_iovs.end(),
129  std::back_inserter(listOfCablingIOVs),
130  [](std::tuple<cond::Time_t, cond::Hash> myIOV2) -> unsigned int { return std::get<0>(myIOV2); });
131 
132  edm::LogPrint(k_ClassName) << " Number of SiPixelFedCablngMap payloads: " << listOfCablingIOVs.size()
133  << std::endl;
134 
135  auto it = std::find(
136  listOfCablingIOVs.begin(), listOfCablingIOVs.end(), closest_from_below(listOfCablingIOVs, std::get<0>(iov)));
137  int index = std::distance(listOfCablingIOVs.begin(), it);
138 
139  edm::LogPrint(k_ClassName) << " using the SiPixelFedCablingMap with hash: "
140  << std::get<1>(m_cabling_iovs.at(index)) << std::endl;
141 
142  auto theCablingMap = condDbSession.fetchPayload<SiPixelFedCablingMap>(std::get<1>(m_cabling_iovs.at(index)));
143  theCablingMap->initializeRocs();
144  // auto theCablingTree = (*theCablingMap).cablingTree();
145 
146  //auto map = theCablingMap->det2fedMap();
147  //for (const auto &element : map){
148  // std::cout << element.first << " " << element.second << std::endl;
149  //}
150 
151  std::shared_ptr<SiPixelFEDChannelContainer> payload = fetchPayload(std::get<1>(iov));
152  const auto& scenarioMap = payload->getScenarioMap();
153 
154  auto pIndexConverter = PixelIndices(numColumns, numRows);
155 
156  for (const auto& scenario : scenarioMap) {
157  std::string scenName = scenario.first;
158 
159  if (std::find_if(the_scenarios.begin(), the_scenarios.end(), compareKeys(scenName)) != the_scenarios.end() ||
160  the_scenarios[0] == "all") {
161  edm::LogPrint(k_ClassName) << "\t Found Scenario: " << scenName << " ==> dumping it";
162  } else {
163  continue;
164  }
165 
166  //if (strcmp(scenName.c_str(),"320824_103") != 0) continue;
167 
168  const auto& theDetSetBadPixelFedChannels = payload->getDetSetBadPixelFedChannels(scenName);
169  for (const auto& disabledChannels : *theDetSetBadPixelFedChannels) {
170  const auto t_detid = disabledChannels.detId();
171  int subid = DetId(t_detid).subdetId();
172  LogDebug(k_ClassName) << fmt::sprintf("DetId : %i \n", t_detid) << std::endl;
173 
174  std::bitset<16> badRocsFromFEDChannels;
175 
176  for (const auto& ch : disabledChannels) {
177  std::string toOut_ = fmt::sprintf("fed : %i | link : %2i | roc_first : %2i | roc_last: %2i \n",
178  ch.fed,
179  ch.link,
180  ch.roc_first,
181  ch.roc_last);
182 
183  LogDebug(k_ClassName) << toOut_ << std::endl;
184  const std::vector<sipixelobjects::CablingPathToDetUnit>& path =
185  theCablingMap->pathToDetUnit(disabledChannels.detId());
186  for (unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
187  for (const auto p : path) {
188  const sipixelobjects::PixelROC* myroc = theCablingMap->findItem(p);
189  if (myroc->idInDetUnit() == static_cast<unsigned int>(i_roc)) {
190  sipixelobjects::LocalPixel::RocRowCol local = {39, 25}; //corresponding to center of ROC row,col
192  int chipIndex(0), colROC(0), rowROC(0);
193 
194  pIndexConverter.transformToROC(global.col, global.row, chipIndex, colROC, rowROC);
195 
196  LogDebug(k_ClassName) << " => i_roc:" << i_roc << " " << global.col << "-" << global.row << " | => "
197  << chipIndex << " : (" << colROC << "," << rowROC << ")" << std::endl;
198 
199  badRocsFromFEDChannels[chipIndex] = true;
200  }
201  }
202  }
203  }
204 
205  LogDebug(k_ClassName) << badRocsFromFEDChannels << std::endl;
206 
207  auto myDetId = DetId(t_detid);
208 
209  if (subid == PixelSubdetector::PixelBarrel) {
210  theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
211  } // if it's barrel
212  else if (subid == PixelSubdetector::PixelEndcap) {
213  theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
214  } // if it's endcap
215  else {
216  throw cms::Exception("LogicError") << "Unknown Pixel SubDet ID " << std::endl;
217  } // else nonsense
218  } // loop on the channels
219  } // loop on the scenarios
220 
221  gStyle->SetOptStat(0);
222  //=========================
223  TCanvas canvas("Summary", "Summary", 1200, k_height[myType]);
224  canvas.cd();
225 
226  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
227 
228  std::string IOVstring = (unpacked.first == 0)
229  ? std::to_string(unpacked.second)
230  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second));
231 
232  const auto headerText = fmt::sprintf("#color[4]{%s}, IOV: #color[4]{%s}", tagname, IOVstring);
233 
234  switch (myType) {
235  case SiPixelPI::t_barrel:
236  theROCMap.drawBarrelMaps(canvas, headerText);
237  break;
239  theROCMap.drawForwardMaps(canvas, headerText);
240  break;
241  case SiPixelPI::t_all:
242  theROCMap.drawMaps(canvas, headerText);
243  break;
244  default:
245  throw cms::Exception("LogicError") << "\nERROR: unrecognized Pixel Detector part " << std::endl;
246  }
247 
248  std::string fileName(m_imageFileName);
249  canvas.SaveAs(fileName.c_str());
250 
251  // close the DB session
252  condDbSession.transaction().commit();
253 
254  return true;
255  }
256 
257  public:
258  inline unsigned int closest_from_above(std::vector<unsigned int> const& vec, unsigned int value) {
259  auto const it = std::lower_bound(vec.begin(), vec.end(), value);
260  return vec.at(it - vec.begin() - 1);
261  }
262 
263  inline unsigned int closest_from_below(std::vector<unsigned int> const& vec, unsigned int value) {
264  auto const it = std::upper_bound(vec.begin(), vec.end(), value);
265  return vec.at(it - vec.begin() - 1);
266  }
267 
268  // auxilliary check
269  struct compareKeys {
271  compareKeys(std::string const& i) : key(i) {}
272 
273  bool operator()(std::string const& i) { return (key == i); }
274  };
275 
276  private:
277  // tough luck, we can only do phase-1...
278  static constexpr int numColumns = 416;
279  static constexpr int numRows = 160;
280  static constexpr int n_rings = 2;
281  static constexpr int n_layers = 4;
282 
283  // graphics
284  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
285  static constexpr const char* k_ClassName = "SiPixelFEDChannelContainerMap";
286 
287  TrackerTopology m_trackerTopo;
288  edm::ParameterSet m_connectionPset;
289  cond::persistency::ConnectionPool m_connectionPool;
290  std::string m_CablingTagName;
291  std::string m_condDbCabling;
292  };
293 
294  /************************************************
295  1d histogram of SiPixelFEDChannelContainer of 1 IOV
296  *************************************************/
297 
298  template <SiPixelPI::DetType myType>
299  class SiPixelFEDChannelContainerMapSimple : public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
300  public:
301  SiPixelFEDChannelContainerMapSimple()
303  "SiPixelFEDChannelContainer Pixel Track Map of one (or more scenarios)") {
304  // for inputs
305  PlotBase::addInputParam("Scenarios");
306  }
307 
308  bool fill() override {
309  std::vector<std::string> the_scenarios = {};
310 
311  auto paramValues = PlotBase::inputParamValues();
312  auto ip = paramValues.find("Scenarios");
313  if (ip != paramValues.end()) {
314  auto input = ip->second;
315  typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
316  boost::char_separator<char> sep{","};
317  tokenizer tok{input, sep};
318  for (const auto& t : tok) {
319  the_scenarios.push_back(t);
320  }
321  } else {
322  edm::LogWarning(k_ClassName)
323  << "\n WARNING!!!! \n The needed parameter Scenarios has not been passed. Will use all the scenarios in "
324  "the file!"
325  << "\n Buckle your seatbelts... this might take a while... \n\n";
326  the_scenarios.push_back("all");
327  }
328 
329  Phase1PixelROCMaps theROCMap("");
330 
331  auto tag = PlotBase::getTag<0>();
332  auto tagname = tag.name;
333  auto iov = tag.iovs.front();
334 
335  std::shared_ptr<SiPixelFEDChannelContainer> payload = fetchPayload(std::get<1>(iov));
336  const auto& scenarioMap = payload->getScenarioMap();
337 
338  for (const auto& scenario : scenarioMap) {
339  std::string scenName = scenario.first;
340 
341  if (std::find_if(the_scenarios.begin(), the_scenarios.end(), compareKeys(scenName)) != the_scenarios.end() ||
342  the_scenarios[0] == "all") {
343  edm::LogPrint(k_ClassName) << "\t Found Scenario: " << scenName << " ==> dumping it";
344  } else {
345  continue;
346  }
347 
348  const auto& theDetSetBadPixelFedChannels = payload->getDetSetBadPixelFedChannels(scenName);
349  for (const auto& disabledChannels : *theDetSetBadPixelFedChannels) {
350  const auto t_detid = disabledChannels.detId();
351  int subid = DetId(t_detid).subdetId();
352  LogDebug(k_ClassName) << fmt::sprintf("DetId : %i \n", t_detid) << std::endl;
353 
354  std::bitset<16> badRocsFromFEDChannels;
355 
356  for (const auto& ch : disabledChannels) {
357  std::string toOut_ = fmt::sprintf("fed : %i | link : %2i | roc_first : %2i | roc_last: %2i \n",
358  ch.fed,
359  ch.link,
360  ch.roc_first,
361  ch.roc_last);
362 
363  LogDebug(k_ClassName) << toOut_ << std::endl;
364  for (unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
365  badRocsFromFEDChannels.set(i_roc);
366  }
367  }
368 
369  LogDebug(k_ClassName) << badRocsFromFEDChannels << std::endl;
370 
371  const auto& myDetId = DetId(t_detid);
372 
373  if (subid == PixelSubdetector::PixelBarrel) {
374  theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
375  } // if it's barrel
376  else if (subid == PixelSubdetector::PixelEndcap) {
377  theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
378  } // if it's endcap
379  else {
380  throw cms::Exception("LogicError") << "Unknown Pixel SubDet ID " << std::endl;
381  } // else nonsense
382  } // loop on the channels
383  } // loop on the scenarios
384 
385  gStyle->SetOptStat(0);
386  //=========================
387  TCanvas canvas("Summary", "Summary", 1200, k_height[myType]);
388  canvas.cd();
389 
390  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
391 
392  std::string IOVstring = (unpacked.first == 0)
393  ? std::to_string(unpacked.second)
394  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second));
395 
396  const auto headerText = fmt::sprintf("#color[4]{%s}, IOV: #color[4]{%s}", tagname, IOVstring);
397 
398  switch (myType) {
399  case SiPixelPI::t_barrel:
400  theROCMap.drawBarrelMaps(canvas, headerText);
401  break;
403  theROCMap.drawForwardMaps(canvas, headerText);
404  break;
405  case SiPixelPI::t_all:
406  theROCMap.drawMaps(canvas, headerText);
407  break;
408  default:
409  throw cms::Exception("LogicError") << "\nERROR: unrecognized Pixel Detector part " << std::endl;
410  }
411 
412  // add list of scenarios watermark
413  canvas.cd();
414  auto ltx = TLatex();
415  ltx.SetTextFont(62);
416  //ltx.SetTextColor(kMagenta);
417  ltx.SetTextSize(0.023);
418  ltx.DrawLatexNDC(
419  gPad->GetLeftMargin() - 0.09,
420  gPad->GetBottomMargin() - 0.09,
421  ("scenarios: #color[4]{" +
422  std::accumulate(the_scenarios.begin(),
423  the_scenarios.end(),
424  std::string(),
425  [](const std::string& acc, const std::string& str) { return acc + " " + str; }) +
426  "}")
427  .c_str());
428 
429  std::string fileName(m_imageFileName);
430  canvas.SaveAs(fileName.c_str());
431  return true;
432  }
433 
434  public:
435  // auxilliary check
436  struct compareKeys {
438  compareKeys(std::string const& i) : key(i) {}
439 
440  bool operator()(std::string const& i) { return (key == i); }
441  };
442 
443  private:
444  // graphics
445  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
446  static constexpr const char* k_ClassName = "SiPixelFEDChannelContainerMapSimple";
447  };
448 
449  using SiPixelBPixFEDChannelContainerMap = SiPixelFEDChannelContainerMapSimple<SiPixelPI::t_barrel>;
450  using SiPixelFPixFEDChannelContainerMap = SiPixelFEDChannelContainerMapSimple<SiPixelPI::t_forward>;
451  using SiPixelFullFEDChannelContainerMap = SiPixelFEDChannelContainerMapSimple<SiPixelPI::t_all>;
452 
453  /*
454  Produces an aggregate map of the masked components for all scenarios,
455  weighted on the probability per PU unit from SiPixelQualityProbabilities
456  assuming a flat PU profile in the range encoded in SiPixelQualityProbabilities
457  The SiPixelQualityProbabilities tag comes from user input
458  */
459  template <SiPixelPI::DetType myType>
460  class SiPixelFEDChannelContainerMapWeigthed : public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
461  public:
462  SiPixelFEDChannelContainerMapWeigthed()
464  "SiPixelFEDChannelContainer Pixel Track Map of one (or more scenarios)") {
465  // for inputs
466  PlotBase::addInputParam("SiPixelQualityProbabilitiesTag");
467 
468  // hardcoded connection to the SiPixelQualityProbability tag, though luck
469  m_condSiPixelProb = "frontier://FrontierProd/CMS_CONDITIONS";
470  m_connectionPool.setParameters(m_connectionPset);
471  m_connectionPool.configure();
472  }
473 
474  bool fill() override {
475  auto paramValues = PlotBase::inputParamValues();
476  auto ip = paramValues.find("SiPixelQualityProbabilitiesTag");
477  if (ip != paramValues.end()) {
478  m_SiPixelProbTagName = ip->second;
479  } else {
480  edm::LogWarning(k_ClassName) << "\n WARNING!!!! \n The needed parameter SiPixelQualityProbabilitiesTag was not "
481  "inputed from the user \n Display will be aborted \n\n";
482  return false;
483  }
484 
485  Phase1PixelROCMaps theROCMap("", "Masking Probability [%]");
486 
487  auto tag = PlotBase::getTag<0>();
488  auto tagname = tag.name;
489  auto iov = tag.iovs.front();
490 
491  // open db session for the cabling map
492  edm::LogPrint(k_ClassName) << "[SiPixelFEDChannelContainerTest::" << __func__ << "] "
493  << "Query the condition database " << m_condSiPixelProb;
494 
495  cond::persistency::Session condDbSession = m_connectionPool.createSession(m_condSiPixelProb);
496  condDbSession.transaction().start(true);
497 
498  // query the database
499  edm::LogPrint(k_ClassName) << "[SiPixelFEDChannelContainerTest::" << __func__ << "] "
500  << "Reading IOVs from tag " << m_SiPixelProbTagName;
501 
504 
505  // get the list of payloads for the Cabling Map
506  std::vector<std::tuple<cond::Time_t, cond::Hash>> m_pixelProb_iovs;
507  condDbSession.readIov(m_SiPixelProbTagName).selectRange(MIN_VAL, MAX_VAL, m_pixelProb_iovs);
508 
509  // in MC there should be only 1 IOV, oh well...
510  edm::LogPrint(k_ClassName) << " using the SiPixelQualityProbabilities with hash: "
511  << std::get<1>(m_pixelProb_iovs.front()) << std::endl;
512 
513  auto probabilitiesPayload =
514  condDbSession.fetchPayload<SiPixelQualityProbabilities>(std::get<1>(m_pixelProb_iovs.front()));
515 
516  const auto& PUbins = probabilitiesPayload->getPileUpBins();
517 
518  SiPixelQualityProbabilities::probabilityMap m_probabilities = probabilitiesPayload->getProbability_Map();
519 
520  // find the PU-averaged (assuming flat PU in the range) probabilities for each scenario
521  std::map<std::string, float> puAvgedProbabilities;
522  for (const auto& [PUbin, ProbMap] : m_probabilities) {
523  float totProbInPUbin = 0.f;
524  for (const auto& [scenName, prob] : ProbMap) {
525  totProbInPUbin += prob;
526  if (puAvgedProbabilities.find(scenName) == puAvgedProbabilities.end()) {
527  puAvgedProbabilities[scenName] += prob;
528  } else {
529  puAvgedProbabilities.insert({scenName, prob});
530  }
531  }
532  LogDebug(k_ClassName) << "PU bin: " << PUbin << " tot probability " << totProbInPUbin << std::endl;
533  }
534 
535  std::shared_ptr<SiPixelFEDChannelContainer> payload = fetchPayload(std::get<1>(iov));
536  const auto& scenarioMap = payload->getScenarioMap();
537 
538  float totProb{0.f};
539  for (const auto& [scenName, prob] : puAvgedProbabilities) {
540  // only sum up the scenarios that are in the SiPixelFEDChannelContainer payload!
541  if (scenarioMap.find(scenName) != scenarioMap.end()) {
542  LogDebug(k_ClassName) << scenName << " : " << prob << std::endl;
543  totProb += prob;
544  }
545  }
546 
547  LogDebug(k_ClassName) << "Total probability to normalize to: " << totProb << std::endl;
548 
549  //normalize the probabilities per scenario to the toal probability
550  for (auto& pair : puAvgedProbabilities) {
551  pair.second /= totProb;
552  }
553 
554  for (const auto& scenario : scenarioMap) {
555  std::string scenName = scenario.first;
556  LogDebug(k_ClassName) << "\t Found Scenario: " << scenName << " ==> dumping it";
557 
558  // calculate the weight
559  float w_frac = 0.f;
560  if (puAvgedProbabilities.find(scenName) != puAvgedProbabilities.end()) {
561  w_frac = puAvgedProbabilities[scenName];
562  }
563 
564  // if scenario is not in the probability payload, continue
565  if (w_frac == 0.f)
566  continue;
567 
568  LogDebug(k_ClassName) << "scen: " << scenName << " weight: " << w_frac << " log(weight):" << log10(w_frac)
569  << std::endl;
570 
571  const auto& theDetSetBadPixelFedChannels = payload->getDetSetBadPixelFedChannels(scenName);
572  for (const auto& disabledChannels : *theDetSetBadPixelFedChannels) {
573  const auto t_detid = disabledChannels.detId();
574  int subid = DetId(t_detid).subdetId();
575  LogDebug(k_ClassName) << fmt::sprintf("DetId : %i \n", t_detid) << std::endl;
576 
577  std::bitset<16> badRocsFromFEDChannels;
578 
579  for (const auto& ch : disabledChannels) {
580  std::string toOut_ = fmt::sprintf("fed : %i | link : %2i | roc_first : %2i | roc_last: %2i \n",
581  ch.fed,
582  ch.link,
583  ch.roc_first,
584  ch.roc_last);
585 
586  LogDebug(k_ClassName) << toOut_ << std::endl;
587  for (unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
588  badRocsFromFEDChannels.set(i_roc);
589  }
590  }
591 
592  LogDebug(k_ClassName) << badRocsFromFEDChannels << std::endl;
593 
594  const auto& myDetId = DetId(t_detid);
595 
596  if (subid == PixelSubdetector::PixelBarrel) {
597  theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, w_frac * 100);
598  } // if it's barrel
599  else if (subid == PixelSubdetector::PixelEndcap) {
600  theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, w_frac * 100);
601  } // if it's endcap
602  else {
603  throw cms::Exception("LogicError") << "Unknown Pixel SubDet ID " << std::endl;
604  } // else nonsense
605  } // loop on the channels
606  } // loop on the scenarios
607 
608  gStyle->SetOptStat(0);
609  //=========================
610  TCanvas canvas("Summary", "Summary", 1200, k_height[myType]);
611  canvas.cd();
612 
613  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
614 
615  std::string IOVstring = (unpacked.first == 0)
616  ? std::to_string(unpacked.second)
617  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second));
618 
619  const auto headerText =
620  fmt::sprintf("#bf{#scale[0.6]{#color[2]{%s}, #color[4]{%s}}}", tagname, m_SiPixelProbTagName);
621 
622  switch (myType) {
623  case SiPixelPI::t_barrel:
624  theROCMap.drawBarrelMaps(canvas, headerText);
625  break;
627  theROCMap.drawForwardMaps(canvas, headerText);
628  break;
629  case SiPixelPI::t_all:
630  theROCMap.drawMaps(canvas, headerText);
631  break;
632  default:
633  throw cms::Exception("LogicError") << "\nERROR: unrecognized Pixel Detector part " << std::endl;
634  }
635 
636  // add list of scenarios watermark
637  canvas.cd();
638  auto ltx = TLatex();
639  ltx.SetTextFont(62);
640  //ltx.SetTextColor(kMagenta);
641  ltx.SetTextSize(0.023);
642  ltx.DrawLatexNDC(gPad->GetLeftMargin() - 0.09, gPad->GetBottomMargin() - 0.09, "");
643 
644  std::string fileName(m_imageFileName);
645  canvas.SaveAs(fileName.c_str());
646  return true;
647  }
648 
649  private:
650  // graphics
651  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
652  static constexpr const char* k_ClassName = "SiPixelFEDChannelContainerMapWeigthed";
653 
654  // parameters for auxilliary DB connection
655  edm::ParameterSet m_connectionPset;
656  cond::persistency::ConnectionPool m_connectionPool;
657  std::string m_SiPixelProbTagName;
658  std::string m_condSiPixelProb;
659  };
660 
661  using SiPixelBPixFEDChannelContainerWeightedMap = SiPixelFEDChannelContainerMapWeigthed<SiPixelPI::t_barrel>;
662  using SiPixelFPixFEDChannelContainerWeightedMap = SiPixelFEDChannelContainerMapWeigthed<SiPixelPI::t_forward>;
663  using SiPixelFullFEDChannelContainerWeightedMap = SiPixelFEDChannelContainerMapWeigthed<SiPixelPI::t_all>;
664 
665  /************************************************
666  1d histogram of number of SiPixelFEDChannelContainer scenarios
667  *************************************************/
668 
669  class SiPixelFEDChannelContainerScenarios : public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
670  public:
671  SiPixelFEDChannelContainerScenarios()
672  : PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV>("SiPixelFEDChannelContainer scenarios count") {}
673  bool fill() override {
674  auto tag = PlotBase::getTag<0>();
675  auto tagname = tag.name;
676  auto iov = tag.iovs.front();
677 
678  TGaxis::SetMaxDigits(3);
679 
680  std::shared_ptr<SiPixelFEDChannelContainer> payload = fetchPayload(std::get<1>(iov));
681  std::vector<std::string> scenarios = payload->getScenarioList();
682  sort(scenarios.begin(), scenarios.end());
683 
684  TCanvas canvas("Canv", "Canv", 1200, 1000);
685  canvas.cd();
686  canvas.SetGrid();
687  auto h1 = std::make_unique<TH1F>("Count",
688  "SiPixelFEDChannelContainer Bad Roc count;Scenario index;n. of bad ROCs",
689  scenarios.size(),
690  1,
691  scenarios.size());
692  h1->SetStats(false);
693 
694  canvas.SetTopMargin(0.06);
695  canvas.SetBottomMargin(0.12);
696  canvas.SetLeftMargin(0.12);
697  canvas.SetRightMargin(0.05);
698  canvas.Modified();
699 
700  int scenarioIndex = 0;
701  for (const auto& scenario : scenarios) {
702  scenarioIndex++;
703  int badRocCount = 0;
704  LogDebug("SiPixelFEDChannelContainerScenarios") << scenario << std::endl;
705  auto badChannelCollection = payload->getDetSetBadPixelFedChannels(scenario);
706  for (const auto& disabledChannels : *badChannelCollection) {
707  for (const auto& ch : disabledChannels) {
708  int local_bad_rocs = ch.roc_last - ch.roc_first;
709  badRocCount += local_bad_rocs;
710  } // loop on the channels
711  } // loop on the DetSetVector
712 
713  h1->SetBinContent(scenarioIndex, badRocCount);
714  } // loop on scenarios
715 
716  TGaxis::SetExponentOffset(-0.1, 0.01, "y"); // Y offset
717  TGaxis::SetExponentOffset(-0.03, -0.10, "x"); // Y and Y offset for X axis
718 
719  h1->SetTitle("");
720  h1->GetYaxis()->SetRangeUser(0., h1->GetMaximum() * 1.30);
721  h1->SetFillColor(kRed);
722  h1->SetMarkerStyle(20);
723  h1->SetMarkerSize(1);
724  h1->Draw("bar2");
725 
727 
728  canvas.Update();
729 
730  TLegend legend = TLegend(0.30, 0.88, 0.95, 0.94);
731  //legend.SetHeader(("#splitline{Payload hash: #bf{" + (std::get<1>(iov)) + "}}{Total Scenarios:"+std::to_string(scenarioIndex)+"}").c_str(),"C"); // option "C" allows to center the header
732 
733  legend.SetHeader(fmt::sprintf("Payload hash: #bf{%s}", std::get<1>(iov)).c_str(), "C");
734  legend.AddEntry(h1.get(), fmt::sprintf("total scenarios: #bf{%s}", std::to_string(scenarioIndex)).c_str(), "F");
735  legend.SetTextSize(0.025);
736  legend.Draw("same");
737 
738  auto ltx = TLatex();
739  ltx.SetTextFont(62);
740  //ltx.SetTextColor(kBlue);
741  //ltx.SetTextAlign(11);
742  ltx.SetTextSize(0.040);
743  ltx.DrawLatexNDC(
744  gPad->GetLeftMargin(),
745  1 - gPad->GetTopMargin() + 0.01,
746  fmt::sprintf("#color[4]{%s} IOV: #color[4]{%s}", tagname, std::to_string(std::get<0>(iov))).c_str());
747 
748  std::string fileName(m_imageFileName);
749  canvas.SaveAs(fileName.c_str());
750 
751  return true;
752 
753  } // fill
754  };
755 
756 } // namespace
757 
758 // Register the classes as boost python plugin
760  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixFEDChannelContainerMap);
761  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixFEDChannelContainerMap);
762  PAYLOAD_INSPECTOR_CLASS(SiPixelFullFEDChannelContainerMap);
763  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixFEDChannelContainerWeightedMap);
764  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixFEDChannelContainerWeightedMap);
765  PAYLOAD_INSPECTOR_CLASS(SiPixelFullFEDChannelContainerWeightedMap);
766  PAYLOAD_INSPECTOR_CLASS(SiPixelFEDChannelContainerScenarios);
767 }
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
std::map< unsigned int, probabilityVec > probabilityMap
Time_t beginValue
Definition: Time.h:41
void start(bool readOnly=true)
Definition: Session.cc:18
const Time_t MIN_VAL(0)
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
Transaction & transaction()
Definition: Session.cc:52
scenario
Definition: constants.h:219
identify pixel inside single ROC
Definition: LocalPixel.h:7
static std::string to_string(const XMLCh *ch)
static std::string const input
Definition: EdmProvDump.cc:50
global coordinates (row and column in DetUnit, as in PixelDigi)
Definition: GlobalPixel.h:6
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
GlobalPixel toGlobal(const LocalPixel &loc) const
Definition: PixelROC.h:55
key
prepare the HTCondor submission files and eventually submit them
double f[11][100]
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Definition: value.py:1
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Log< level::Warning, true > LogPrint
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
const std::map< std::string, std::string > & inputParamValues() const
void addInputParam(const std::string &paramName)
Definition: DetId.h:17
void makeNicePlotStyle(TH1 *hist)
row and collumn in ROC representation
Definition: LocalPixel.h:13
IOVArray selectRange(const cond::Time_t &begin, const cond::Time_t &end)
Definition: IOVProxy.cc:197
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
def canvas(sub, attr)
Definition: svgfig.py:482
Log< level::Warning, false > LogWarning
Time_t endValue
Definition: Time.h:42
#define str(s)
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:37
#define LogDebug(id)
unsigned transform(const HcalDetId &id, unsigned transformCode)