CMS 3D CMS Logo

SiPixelDynamicInefficiency_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 <cmath>
28 #include <memory>
29 #include <sstream>
30 #include <iostream>
31 
32 // include ROOT
33 #include "TCanvas.h"
34 #include "TGraph.h"
35 #include "TH2F.h"
36 #include "TLatex.h"
37 #include "TLegend.h"
38 #include "TLine.h"
39 #include "TPave.h"
40 #include "TPaveStats.h"
41 #include "TStyle.h"
42 #include "TF1.h"
43 #include "TMath.h"
44 #include <Math/Polynomial.h>
45 
46 namespace {
47 
48  using namespace cond::payloadInspector;
49  namespace SiPixDynIneff {
50 
51  // different types of geometrical inefficiency factors
52  enum factor { geom = 0, colgeom = 1, chipgeom = 2, pu = 3, INVALID = 4 };
53  const std::array<std::string, 5> factorString = {
54  {"pixel geometry", "column geometry", "chip geometry", "PU", "invalid"}};
55 
56  using FactorMap = std::map<unsigned int, double>;
57  using PUFactorMap = std::map<unsigned int, std::vector<double> >;
58 
59  // constants for ROC level simulation for Phase1
60  enum shiftEnumerator { FPixRocIdShift = 3, BPixRocIdShift = 6 };
61  const int rocIdMaskBits = 0x1F;
62 
63  struct packedBadRocFraction {
64  std::vector<int> badRocNumber;
65  std::vector<float> badRocFrac;
66  };
67 
68  using BRFractions = std::unordered_map<uint32_t, packedBadRocFraction>;
69 
70  //_________________________________________________
71  BRFractions pbrf(std::shared_ptr<SiPixelDynamicInefficiency> payload) {
72  BRFractions f;
73  const std::map<uint32_t, double>& PixelGeomFactorsDBIn = payload->getPixelGeomFactors();
74 
75  // first fill
76  for (const auto db_factor : PixelGeomFactorsDBIn) {
77  int subid = DetId(db_factor.first).subdetId();
78  int shift = (subid == static_cast<int>(PixelSubdetector::PixelBarrel)) ? BPixRocIdShift : FPixRocIdShift;
79  unsigned int rocMask = rocIdMaskBits << shift;
80  unsigned int rocId = (((db_factor.first) & rocMask) >> shift);
81  uint32_t rawid = db_factor.first & (~rocMask);
82 
83  if (f.find(rawid) == f.end()) {
84  packedBadRocFraction p;
85  f.insert(std::make_pair(rawid, p));
86  }
87 
88  if (rocId != 0) {
89  rocId--;
90  double factor = db_factor.second;
91  double badFraction = 1 - factor;
92 
93  f.at(rawid).badRocNumber.emplace_back(rocId);
94  f.at(rawid).badRocFrac.emplace_back(badFraction);
95  }
96  }
97  return f;
98  }
99 
100  //_________________________________________________
101  bool isPhase0(const BRFractions& fractions) {
104  const auto& p0detIds = reader.getAllDetIds();
105  std::vector<uint32_t> ownDetIds;
106 
107  std::transform(fractions.begin(),
108  fractions.end(),
109  std::back_inserter(ownDetIds),
110  [](std::pair<uint32_t, packedBadRocFraction> d) -> uint32_t { return d.first; });
111 
112  for (const auto& det : ownDetIds) {
113  // if found at least one phase-0 detId early return
114  if (std::find(p0detIds.begin(), p0detIds.end(), det) != p0detIds.end()) {
115  return true;
116  }
117  }
118  return false;
119  }
120 
121  //_________________________________________________
122  double getMatchingGeomFactor(const DetId& detid,
123  const std::map<unsigned int, double>& map_geomfactor,
124  const std::vector<uint32_t>& detIdmasks) {
125  double geomfactor_db = 1;
126  for (auto map_element : map_geomfactor) {
127  const DetId mapid = DetId(map_element.first);
128  if (mapid.subdetId() != detid.subdetId())
129  continue;
130  size_t __i = 0;
131  for (; __i < detIdmasks.size(); __i++) {
132  DetId maskid = DetId(detIdmasks.at(__i));
133  if (maskid.subdetId() != mapid.subdetId())
134  continue;
135  if ((detid.rawId() & maskid.rawId()) != (mapid.rawId() & maskid.rawId()) &&
136  (mapid.rawId() & maskid.rawId()) != DetId(mapid.det(), mapid.subdetId()).rawId())
137  break;
138  }
139  if (__i != detIdmasks.size())
140  continue;
141  geomfactor_db *= map_element.second;
142  }
143  return geomfactor_db;
144  }
145 
146  //_________________________________________________
147  std::vector<double> getMatchingPUFactors(const DetId& detid,
148  const std::map<unsigned int, std::vector<double> >& map_pufactory,
149  const std::vector<uint32_t>& detIdmasks) {
150  std::vector<double> pufactors_db;
151  for (const auto& map_element : map_pufactory) {
152  const DetId mapid = DetId(map_element.first);
153  if (mapid.subdetId() != detid.subdetId())
154  continue;
155  size_t __i = 0;
156  for (; __i < detIdmasks.size(); __i++) {
157  DetId maskid = DetId(detIdmasks.at(__i));
158  if (maskid.subdetId() != mapid.subdetId())
159  continue;
160  if ((detid.rawId() & maskid.rawId()) != (mapid.rawId() & maskid.rawId()) &&
161  (mapid.rawId() & maskid.rawId()) != DetId(mapid.det(), mapid.subdetId()).rawId())
162  break;
163  }
164  if (__i != detIdmasks.size())
165  continue;
166  pufactors_db = map_element.second;
167  }
168  return pufactors_db;
169  }
170 
171  //(Not used for the moment)
172  //_________________________________________________
173  [[maybe_unused]] bool matches(const DetId& detid, const DetId& db_id, const std::vector<uint32_t>& DetIdmasks) {
174  if (detid.subdetId() != db_id.subdetId())
175  return false;
176  for (size_t i = 0; i < DetIdmasks.size(); ++i) {
177  DetId maskid = DetId(DetIdmasks.at(i));
178  if (maskid.subdetId() != db_id.subdetId())
179  continue;
180  if ((detid.rawId() & maskid.rawId()) != (db_id.rawId() & maskid.rawId()) &&
181  (db_id.rawId() & maskid.rawId()) != DetId(db_id.det(), db_id.subdetId()).rawId())
182  return false;
183  }
184  return true;
185  }
186 
187  //_________________________________________________
188  bool checkPhase(const SiPixelPI::phase phase, const std::vector<uint32_t>& masks_db) {
189  const char* inputFile;
190  switch (phase) {
192  inputFile = "Geometry/TrackerCommonData/data/trackerParameters.xml";
193  break;
195  inputFile = "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
196  break;
198  inputFile = "Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml";
199  break;
200  default:
201  throw cms::Exception("SiPixelDynamicInefficiency_PayloadInspector") << "checkPhase: unrecongnized phase!";
202  }
203 
204  // create the standalone tracker topology
205  const auto& tkTopo =
207 
208  // Check what masks we would get using the current geometry
209  // It has to match what is in the db content!!
210 
211  std::vector<uint32_t> masks_geom;
213 
214  masks_geom.push_back(tkTopo.pxbDetId(max, 0, 0).rawId());
215  masks_geom.push_back(tkTopo.pxbDetId(0, max, 0).rawId());
216  masks_geom.push_back(tkTopo.pxbDetId(0, 0, max).rawId());
217  masks_geom.push_back(tkTopo.pxfDetId(max, 0, 0, 0, 0).rawId());
218  masks_geom.push_back(tkTopo.pxfDetId(0, max, 0, 0, 0).rawId());
219  masks_geom.push_back(tkTopo.pxfDetId(0, 0, max, 0, 0).rawId());
220  masks_geom.push_back(tkTopo.pxfDetId(0, 0, 0, max, 0).rawId());
221  masks_geom.push_back(tkTopo.pxfDetId(0, 0, 0, 0, max).rawId());
222 
223  return (masks_geom.size() == masks_db.size() &&
224  std::equal(masks_geom.begin(), masks_geom.end(), masks_db.begin()));
225  }
226 
227  //_________________________________________________
228  unsigned int maxDepthOfPUArray(const std::map<unsigned int, std::vector<double> >& map_pufactor) {
229  unsigned int size{0};
230  for (const auto& [id, vec] : map_pufactor) {
231  if (vec.size() > size)
232  size = vec.size();
233  }
234  return size;
235  }
236 
237  //_________________________________________________
238  std::pair<int, int> getClosestFactors(int input) {
239  if ((input % 2 != 0) && input > 1) {
240  input += 1;
241  }
242 
243  int testNum = (int)sqrt(input);
244  while (input % testNum != 0) {
245  testNum--;
246  }
247  return std::make_pair(testNum, input / testNum);
248  }
249 
253  std::string findStem(const std::vector<std::string>& arr) {
254  // Determine size of the array
255  int n = arr.size();
256 
257  // Take first word from array as reference
258  const std::string& s = arr[0];
259  int len = s.length();
260 
261  std::string res = "";
262 
263  for (int i = 0; i < len; i++) {
264  for (int j = i + 1; j <= len; j++) {
265  // generating all possible substrings
266  // of our reference string arr[0] i.e s
267  std::string stem = s.substr(i, j);
268  int k = 1;
269  for (k = 1; k < n; k++) {
270  // Check if the generated stem is
271  // common to all words
272  if (arr[k].find(stem) == std::string::npos)
273  break;
274  }
275 
276  // If current substring is present in
277  // all strings and its length is greater
278  // than current result
279  if (k == n && res.length() < stem.length())
280  res = stem;
281  }
282  }
283  return res;
284  }
285 
289  std::string attachLocationLabel(const std::vector<uint32_t>& listOfDetIds, SiPixelPI::PhaseInfo& phInfo) {
290  // collect all the regions in which it can be split
291  std::vector<std::string> regions;
292  for (const auto& rawId : listOfDetIds) {
293  SiPixelPI::topolInfo t_info_fromXML;
294  t_info_fromXML.init();
295  DetId detid(rawId);
296 
297  const char* path_toTopologyXML = phInfo.pathToTopoXML();
298  auto tTopo =
300  t_info_fromXML.fillGeometryInfo(detid, tTopo, phInfo.phase());
301  const auto& reg = SiPixelPI::getStringFromRegionEnum(t_info_fromXML.filterThePartition());
302  if (!std::count(regions.begin(), regions.end(), reg)) {
303  regions.push_back(reg);
304  }
305  }
306 
307  std::string retVal = "";
308  // if perfect match (only one category)
309  if (regions.size() == 1) {
310  retVal = regions.front();
311  } else {
312  retVal = findStem(regions);
313  }
314 
315  // if the last char is "/" strip it from the string
316  if (retVal.back() == '/')
317  retVal.pop_back();
318 
319  return retVal;
320  }
321 
322  void fillParametrizations(std::vector<std::vector<double> >& listOfParametrizations,
323  std::vector<TF1*>& parametrizations,
324  std::vector<std::string>& formulas,
325  const std::vector<std::string>& namesOfParts) {
326  static constexpr double xmin_ = 0.; // x10e34 (min inst. lumi)
327  static constexpr double xmax_ = 25.; // x10e34 (max inst. lumi)
328 
329  // functional for polynomial of n-th degree
330  auto func = [](double* x, double* p) {
331  int n = p[0];
332  double* params = p + 1;
333  ROOT::Math::Polynomial pol(n);
334  return pol(x, params);
335  };
336 
337  int index{0};
338  for (auto& params : listOfParametrizations) {
339  index++;
340  int n = params.size();
341  int npar = n + 2;
342  std::string str{namesOfParts[index - 1]};
343  if (str.length() >= 2 && str.substr(str.length() - 2) == "/i") {
344  str += "nner";
345  } else if (str.length() >= 2 && str.substr(str.length() - 2) == "/o") {
346  str += "uter";
347  }
348 
349  TF1* f1 = new TF1((fmt::sprintf("region: #bf{%s}", str)).c_str(), func, xmin_, xmax_, npar);
350 
351  // push polynomial degree as first entry in the vector
352  params.insert(params.begin(), n);
353  // TF1::SetParameters needs a C-style array
354  double* arr = params.data();
355  f1->SetLineWidth(2);
356 
357  // fill in the parameter
358  for (unsigned int j = 0; j < params.size(); j++) {
359  f1->SetParameter(j, arr[j]);
360  }
361 
362  parametrizations.push_back(f1);
363 
364  // build the formula to be displayed
366  edm::LogVerbatim("fillParametrizations") << "index: " << index;
367  for (unsigned int i = 1; i < params.size(); i++) {
368  edm::LogVerbatim("fillParametrizations") << " " << params[i];
369  formula += fmt::sprintf("%s%fx^{%i}", (i == 1 ? "" : (std::signbit(params[i]) ? "" : "+")), params[i], i - 1);
370  }
371  edm::LogVerbatim("fillParametrizations") << std::endl;
372  formulas.push_back(formula);
373  }
374  }
375  } // namespace SiPixDynIneff
376 
377  /************************************************
378  test class
379  *************************************************/
380 
381  class SiPixelDynamicInefficiencyTest : public Histogram1D<SiPixelDynamicInefficiency, SINGLE_IOV> {
382  public:
383  SiPixelDynamicInefficiencyTest()
385  "SiPixelDynamicInefficiency test", "SiPixelDynamicInefficiency test", 1, 0.0, 1.0) {}
386 
387  bool fill() override {
388  auto tag = PlotBase::getTag<0>();
389  for (auto const& iov : tag.iovs) {
390  std::shared_ptr<SiPixelDynamicInefficiency> payload = Base::fetchPayload(std::get<1>(iov));
391  if (payload.get()) {
392  fillWithValue(1.);
393 
394  std::map<unsigned int, double> map_pixelgeomfactor = payload->getPixelGeomFactors();
395  std::map<unsigned int, double> map_colgeomfactor = payload->getColGeomFactors();
396  std::map<unsigned int, double> map_chipgeomfactor = payload->getChipGeomFactors();
397  std::map<unsigned int, std::vector<double> > map_pufactor = payload->getPUFactors();
398  std::vector<uint32_t> detIdmasks_db = payload->getDetIdmasks();
399  double theInstLumiScaleFactor_db = payload->gettheInstLumiScaleFactor_();
400 
401  edm::LogPrint("SiPixelDynamicInefficiencyTest") << "-------------------------------------------------------";
402  edm::LogPrint("SiPixelDynamicInefficiencyTest") << "Printing out DB content:\n";
403 
404  edm::LogPrint("SiPixelDynamicInefficiencyTest") << " PixelGeomFactors:";
405  for (auto pixel : map_pixelgeomfactor)
406  edm::LogPrint("SiPixelDynamicInefficiencyTest")
407  << " MapID = " << pixel.first << "\tFactor = " << pixel.second;
408  edm::LogPrint("SiPixelDynamicInefficiencyTest");
409 
410  edm::LogPrint("SiPixelDynamicInefficiencyTest") << " ColGeomFactors:";
411  for (auto col : map_colgeomfactor)
412  edm::LogPrint("SiPixelDynamicInefficiencyTest")
413  << " MapID = " << col.first << "\tFactor = " << col.second;
414  edm::LogPrint("SiPixelDynamicInefficiencyTest");
415 
416  edm::LogPrint("SiPixelDynamicInefficiencyTest") << " ChipGeomFactors:";
417  for (auto chip : map_chipgeomfactor)
418  edm::LogPrint("SiPixelDynamicInefficiencyTest")
419  << " MapID = " << chip.first << "\tFactor = " << chip.second;
420  edm::LogPrint("SiPixelDynamicInefficiencyTest");
421 
422  edm::LogPrint("SiPixelDynamicInefficiencyTest") << " PUFactors:";
423  for (auto pu : map_pufactor) {
424  edm::LogPrint("SiPixelDynamicInefficiencyTest")
425  << " MapID = " << pu.first << "\t Factor" << (pu.second.size() > 1 ? "s" : "") << " = ";
426  for (size_t i = 0, n = pu.second.size(); i < n; ++i)
427  edm::LogPrint("SiPixelDynamicInefficiencyTest") << pu.second[i] << ((i == n - 1) ? "\n" : ", ");
428  }
429  edm::LogPrint("SiPixelDynamicInefficiencyTest");
430 
431  edm::LogPrint("SiPixelDynamicInefficiencyTest") << " DetIdmasks:";
432  for (auto mask : detIdmasks_db)
433  edm::LogPrint("SiPixelDynamicInefficiencyTest") << " MaskID = " << mask;
434  edm::LogPrint("SiPixelDynamicInefficiencyTest");
435 
436  edm::LogPrint("SiPixelDynamicInefficiencyTest") << " theInstLumiScaleFactor = " << theInstLumiScaleFactor_db;
437 
438  } // payload
439  } // iovs
440  return true;
441  } // fill
442  };
443 
444  /************************************************
445  occupancy style map whole Pixel of inefficient ROCs
446  *************************************************/
447  template <SiPixelPI::DetType myType>
448  class SiPixelIneffROCfromDynIneffMap : public PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV> {
449  public:
450  SiPixelIneffROCfromDynIneffMap()
451  : PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV>("SiPixel Inefficient ROC from Dyn Ineff Pixel Map"),
453  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {}
454 
455  bool fill() override {
456  auto tag = PlotBase::getTag<0>();
457  auto iov = tag.iovs.front();
458  auto tagname = tag.name;
459  std::shared_ptr<SiPixelDynamicInefficiency> payload = fetchPayload(std::get<1>(iov));
460 
461  const auto fr = SiPixDynIneff::pbrf(payload);
462 
463  if (SiPixDynIneff::isPhase0(fr)) {
464  edm::LogError("SiPixelDynamicInefficiency_PayloadInspector")
465  << "SiPixelIneffROCfromDynIneff maps are not supported for non-Phase1 Pixel geometries !";
466  TCanvas canvas("Canv", "Canv", 1200, 1000);
468  std::string fileName(m_imageFileName);
469  canvas.SaveAs(fileName.c_str());
470  return false;
471  }
472 
473  Phase1PixelROCMaps theMap("", "bad pixel fraction in ROC [%]");
474 
475  for (const auto& element : fr) {
476  auto rawid = element.first;
477  int subid = DetId(rawid).subdetId();
478  auto packedinfo = element.second;
479  auto badRocs = packedinfo.badRocNumber;
480  auto badRocsF = packedinfo.badRocFrac;
481 
482  for (size_t i = 0; i < badRocs.size(); i++) {
483  std::bitset<16> rocToMark;
484  rocToMark.set(badRocs[i]);
485  if ((subid == PixelSubdetector::PixelBarrel && myType == SiPixelPI::t_barrel) ||
486  (subid == PixelSubdetector::PixelEndcap && myType == SiPixelPI::t_forward) ||
487  (myType == SiPixelPI::t_all)) {
488  theMap.fillSelectedRocs(rawid, rocToMark, badRocsF[i] * 100.f);
489  }
490  }
491  }
492 
493  gStyle->SetOptStat(0);
494  //=========================
495  TCanvas canvas("Summary", "Summary", 1200, k_height[myType]);
496  canvas.cd();
497 
498  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
499 
500  std::string IOVstring = (unpacked.first == 0)
501  ? std::to_string(unpacked.second)
502  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second));
503 
504  const auto headerText = fmt::sprintf("#color[4]{%s}, IOV: #color[4]{%s}", tagname, IOVstring);
505 
506  switch (myType) {
507  case SiPixelPI::t_barrel:
508  theMap.drawBarrelMaps(canvas, headerText);
509  break;
511  theMap.drawForwardMaps(canvas, headerText);
512  break;
513  case SiPixelPI::t_all:
514  theMap.drawMaps(canvas, headerText);
515  break;
516  default:
517  throw cms::Exception("SiPixelIneffROCfromDynIneffMap") << "\nERROR: unrecognized Pixel Detector part ";
518  }
519 
520  std::string fileName(m_imageFileName);
521  canvas.SaveAs(fileName.c_str());
522 #ifdef MMDEBUG
523  canvas.SaveAs("outAll.root");
524 #endif
525 
526  return true;
527  }
528 
529  private:
530  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
531  TrackerTopology m_trackerTopo;
532  };
533 
534  using SiPixelBPixIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_barrel>;
535  using SiPixelFPixIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_forward>;
536  using SiPixelFullIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_all>;
537 
538  /************************************************
539  occupancy style map whole Pixel, difference of payloads
540  *************************************************/
541  template <SiPixelPI::DetType myType, IOVMultiplicity nIOVs, int ntags>
542  class SiPixelIneffROCComparisonBase : public PlotImage<SiPixelDynamicInefficiency, nIOVs, ntags> {
543  public:
544  SiPixelIneffROCComparisonBase()
545  : PlotImage<SiPixelDynamicInefficiency, nIOVs, ntags>(
546  Form("SiPixelDynamicInefficiency %s Pixel Map", SiPixelPI::DetNames[myType].c_str())),
548  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {}
549 
550  bool fill() override {
551  // trick to deal with the multi-ioved tag and two tag case at the same time
552  auto theIOVs = PlotBase::getTag<0>().iovs;
553  auto f_tagname = PlotBase::getTag<0>().name;
554  std::string l_tagname = "";
555  auto firstiov = theIOVs.front();
556  std::tuple<cond::Time_t, cond::Hash> lastiov;
557 
558  // we don't support (yet) comparison with more than 2 tags
559  assert(this->m_plotAnnotations.ntags < 3);
560 
561  if (this->m_plotAnnotations.ntags == 2) {
562  auto tag2iovs = PlotBase::getTag<1>().iovs;
563  l_tagname = PlotBase::getTag<1>().name;
564  lastiov = tag2iovs.front();
565  } else {
566  lastiov = theIOVs.back();
567  }
568 
569  std::shared_ptr<SiPixelDynamicInefficiency> last_payload = this->fetchPayload(std::get<1>(lastiov));
570  std::shared_ptr<SiPixelDynamicInefficiency> first_payload = this->fetchPayload(std::get<1>(firstiov));
571 
572  const auto fp = SiPixDynIneff::pbrf(last_payload);
573  const auto lp = SiPixDynIneff::pbrf(first_payload);
574 
575  if (SiPixDynIneff::isPhase0(fp) || SiPixDynIneff::isPhase0(lp)) {
576  edm::LogError("SiPixelDynamicInefficiency_PayloadInspector")
577  << "SiPixelDynamicInefficiency comparison maps are not supported for non-Phase1 Pixel geometries !";
578  TCanvas canvas("Canv", "Canv", 1200, 1000);
580  std::string fileName(this->m_imageFileName);
581  canvas.SaveAs(fileName.c_str());
582  return false;
583  }
584 
585  Phase1PixelROCMaps theMap("", "#Delta payload A - payload B");
586 
587  gStyle->SetOptStat(0);
588  //=========================
589  TCanvas canvas("Summary", "Summary", 1200, k_height[myType]);
590  canvas.cd();
591 
592  auto f_unpacked = SiPixelPI::unpack(std::get<0>(firstiov));
593  auto l_unpacked = SiPixelPI::unpack(std::get<0>(lastiov));
594 
595  std::string f_IOVstring = (f_unpacked.first == 0)
596  ? std::to_string(f_unpacked.second)
597  : (std::to_string(f_unpacked.first) + "," + std::to_string(f_unpacked.second));
598 
599  std::string l_IOVstring = (l_unpacked.first == 0)
600  ? std::to_string(l_unpacked.second)
601  : (std::to_string(l_unpacked.first) + "," + std::to_string(l_unpacked.second));
602 
603  std::string headerText;
604 
605  if (this->m_plotAnnotations.ntags == 2) {
606  headerText =
607  fmt::sprintf("#color[2]{A: %s, %s} - #color[4]{B: %s, %s}", f_tagname, f_IOVstring, l_tagname, l_IOVstring);
608  } else {
609  headerText = fmt::sprintf("%s,IOV #color[2]{A: %s} - #color[4]{B: %s} ", f_tagname, f_IOVstring, l_IOVstring);
610  }
611 
612  switch (myType) {
613  case SiPixelPI::t_barrel:
614  theMap.drawBarrelMaps(canvas, headerText);
615  break;
617  theMap.drawForwardMaps(canvas, headerText);
618  break;
619  case SiPixelPI::t_all:
620  theMap.drawMaps(canvas, headerText);
621  break;
622  default:
623  throw cms::Exception("SiPixelDynamicInefficiencyMapComparison")
624  << "\nERROR: unrecognized Pixel Detector part ";
625  }
626 
627  // first loop on the first payload (newest)
628  fillTheMapFromPayload(theMap, fp, false);
629 
630  // then loop on the second payload (oldest)
631  fillTheMapFromPayload(theMap, lp, true); // true will subtract
632 
633  std::string fileName(this->m_imageFileName);
634  canvas.SaveAs(fileName.c_str());
635 #ifdef MMDEBUG
636  canvas.SaveAs("outAll.root");
637 #endif
638 
639  return true;
640  }
641 
642  private:
643  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
644  TrackerTopology m_trackerTopo;
645 
646  //____________________________________________________________________________________________
647  void fillTheMapFromPayload(Phase1PixelROCMaps& theMap, const SiPixDynIneff::BRFractions& fr, bool subtract) {
648  for (const auto& element : fr) {
649  auto rawid = element.first;
650  int subid = DetId(rawid).subdetId();
651  auto packedinfo = element.second;
652  auto badRocs = packedinfo.badRocNumber;
653  auto badRocsF = packedinfo.badRocFrac;
654 
655  for (size_t i = 0; i < badRocs.size(); i++) {
656  std::bitset<16> rocToMark;
657  rocToMark.set(badRocs[i]);
658  if ((subid == PixelSubdetector::PixelBarrel && myType == SiPixelPI::t_barrel) ||
659  (subid == PixelSubdetector::PixelEndcap && myType == SiPixelPI::t_forward) ||
660  (myType == SiPixelPI::t_all)) {
661  theMap.fillSelectedRocs(rawid, rocToMark, badRocsF[i] * (subtract ? -1. : 1.));
662  }
663  }
664  }
665  }
666  };
667 
668  /*
669  These are not implemented for the time being, since the SiPixelDynamicInefficiency is a condition
670  used only in simulation, hence there is no such thing as a multi-IoV Dynamic Inefficiency tag
671  */
672 
673  using SiPixelBPixIneffROCsMapCompareSingleTag = SiPixelIneffROCComparisonBase<SiPixelPI::t_barrel, MULTI_IOV, 1>;
674  using SiPixelFPixIneffROCsMapCompareSingleTag = SiPixelIneffROCComparisonBase<SiPixelPI::t_forward, MULTI_IOV, 1>;
675  using SiPixelFullIneffROCsMapCompareSingleTag = SiPixelIneffROCComparisonBase<SiPixelPI::t_all, MULTI_IOV, 1>;
676 
677  using SiPixelBPixIneffROCsMapCompareTwoTags = SiPixelIneffROCComparisonBase<SiPixelPI::t_barrel, SINGLE_IOV, 2>;
678  using SiPixelFPixIneffROCsMapCompareTwoTags = SiPixelIneffROCComparisonBase<SiPixelPI::t_forward, SINGLE_IOV, 2>;
679  using SiPixelFullIneffROCsMapCompareTwoTags = SiPixelIneffROCComparisonBase<SiPixelPI::t_all, SINGLE_IOV, 2>;
680 
681  /************************************************
682  Full Pixel Tracker Map class (for geometrical factors)
683  *************************************************/
684  template <SiPixDynIneff::factor theFactor>
685  class SiPixelDynamicInefficiencyFullPixelMap : public PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV> {
686  public:
687  SiPixelDynamicInefficiencyFullPixelMap()
688  : PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV>("SiPixelDynamicInefficiency Map") {
689  label_ = "SiPixelDynamicInefficiencyFullPixelMap";
690  payloadString = fmt::sprintf("%s Dynamic Inefficiency", SiPixDynIneff::factorString[theFactor]);
691  }
692 
693  bool fill() override {
694  gStyle->SetPalette(1);
695  auto tag = PlotBase::getTag<0>();
696  auto iov = tag.iovs.front();
697  std::shared_ptr<SiPixelDynamicInefficiency> payload = this->fetchPayload(std::get<1>(iov));
698 
699  if (payload.get()) {
700  Phase1PixelSummaryMap fullMap("", fmt::sprintf("%s", payloadString), fmt::sprintf("%s", payloadString));
701  fullMap.createTrackerBaseMap();
702 
703  SiPixDynIneff::FactorMap theMap{};
704  switch (theFactor) {
705  case SiPixDynIneff::geom:
706  theMap = payload->getPixelGeomFactors();
707  break;
708  case SiPixDynIneff::colgeom:
709  theMap = payload->getColGeomFactors();
710  break;
711  case SiPixDynIneff::chipgeom:
712  theMap = payload->getChipGeomFactors();
713  break;
714  default:
715  throw cms::Exception(label_) << "\nERROR: unrecognized type of geometry factor ";
716  }
717 
718  std::vector<uint32_t> detIdmasks_db = payload->getDetIdmasks();
719 
720  if (!SiPixDynIneff::checkPhase(SiPixelPI::phase::one, detIdmasks_db)) {
721  edm::LogError(label_) << label_ << " maps are not supported for non-Phase1 Pixel geometries !";
722  TCanvas canvas("Canv", "Canv", 1200, 1000);
724  std::string fileName(m_imageFileName);
725  canvas.SaveAs(fileName.c_str());
726  return false;
727  }
728 
731  const auto& p1detIds = reader.getAllDetIds();
732 
733  for (const auto& det : p1detIds) {
734  const auto& value = SiPixDynIneff::getMatchingGeomFactor(det, theMap, detIdmasks_db);
735  fullMap.fillTrackerMap(det, value);
736  }
737 
738  const auto& range = fullMap.getZAxisRange();
739  if (range.first == range.second) {
740  // in case the map is completely filled with one value;
741  // set the z-axis to be meaningful
742  fullMap.setZAxisRange(range.first - 0.01, range.second + 0.01);
743  }
744 
745  TCanvas canvas("Canv", "Canv", 3000, 2000);
746  fullMap.printTrackerMap(canvas);
747 
748  auto ltx = TLatex();
749  ltx.SetTextFont(62);
750  ltx.SetTextSize(0.025);
751  ltx.SetTextAlign(11);
752  ltx.DrawLatexNDC(
753  gPad->GetLeftMargin() + 0.01,
754  gPad->GetBottomMargin() + 0.01,
755  ("#color[4]{" + tag.name + "}, IOV: #color[4]{" + std::to_string(std::get<0>(iov)) + "}").c_str());
756 
757  std::string fileName(this->m_imageFileName);
758  canvas.SaveAs(fileName.c_str());
759  }
760  return true;
761  }
762 
763  protected:
764  std::string payloadString;
765  std::string label_;
766  };
767 
768  using SiPixelDynamicInefficiencyGeomFactorMap = SiPixelDynamicInefficiencyFullPixelMap<SiPixDynIneff::geom>;
769  using SiPixelDynamicInefficiencyColGeomFactorMap = SiPixelDynamicInefficiencyFullPixelMap<SiPixDynIneff::colgeom>;
770  using SiPixelDynamicInefficiencyChipGeomFactorMap = SiPixelDynamicInefficiencyFullPixelMap<SiPixDynIneff::chipgeom>;
771 
772  /************************************************
773  Full Pixel Tracker Map class (for PU factors)
774  *************************************************/
775  class SiPixelDynamicInefficiencyPUPixelMaps : public PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV> {
776  public:
777  SiPixelDynamicInefficiencyPUPixelMaps()
778  : PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV>("SiPixelDynamicInefficiency Map") {
779  label_ = "SiPixelDynamicInefficiencyFullPixelMap";
780  payloadString = fmt::sprintf("%s Dynamic Inefficiency", SiPixDynIneff::factorString[SiPixDynIneff::pu]);
781  }
782 
783  bool fill() override {
784  gStyle->SetPalette(1);
785  auto tag = PlotBase::getTag<0>();
786  auto iov = tag.iovs.front();
787  std::shared_ptr<SiPixelDynamicInefficiency> payload = this->fetchPayload(std::get<1>(iov));
788 
789  if (payload.get()) {
790  std::vector<Phase1PixelSummaryMap> maps;
791 
792  SiPixDynIneff::PUFactorMap theMap = payload->getPUFactors();
793  std::vector<uint32_t> detIdmasks_db = payload->getDetIdmasks();
794 
795  if (!SiPixDynIneff::checkPhase(SiPixelPI::phase::one, detIdmasks_db)) {
796  edm::LogError(label_) << label_ << " maps are not supported for non-Phase1 Pixel geometries !";
797  TCanvas canvas("Canv", "Canv", 1200, 1000);
799  std::string fileName(m_imageFileName);
800  canvas.SaveAs(fileName.c_str());
801  return false;
802  }
803 
804  unsigned int depth = SiPixDynIneff::maxDepthOfPUArray(theMap);
805 
806  // create the maps
807  for (unsigned int i = 0; i < depth; i++) {
808  maps.emplace_back(
809  "", fmt::sprintf("%s, factor %i", payloadString, i), fmt::sprintf("%s, factor %i", payloadString, i));
810  maps[i].createTrackerBaseMap();
811  }
812 
813  // retrieve the list of phase1 detids
814  const auto& reader =
816  const auto& p1detIds = reader.getAllDetIds();
817 
818  // fill the maps
819  for (const auto& det : p1detIds) {
820  const auto& values = SiPixDynIneff::getMatchingPUFactors(det, theMap, detIdmasks_db);
821  int index = 0;
822  for (const auto& value : values) {
823  maps[index].fillTrackerMap(det, value);
824  index++;
825  }
826  }
827 
828  // in case the map is completely filled with one value;
829  // set the z-axis to be meaningful
830  for (unsigned int i = 0; i < depth; i++) {
831  const auto& range = maps[i].getZAxisRange();
832  if (range.first == range.second) {
833  maps[i].setZAxisRange(range.first - 0.01, range.second + 0.01);
834  }
835  }
836 
837  // determine how the plot will be paginated
838  auto sides = SiPixDynIneff::getClosestFactors(depth);
839  TCanvas canvas("Canv", "Canv", sides.second * 900, sides.first * 600);
840  canvas.Divide(sides.second, sides.first);
841 
842  // print the sub-canvases
843  for (unsigned int i = 0; i < depth; i++) {
844  maps[i].printTrackerMap(canvas, 0.035, i + 1);
845  auto ltx = TLatex();
846  ltx.SetTextFont(62);
847  ltx.SetTextSize(0.025);
848  ltx.SetTextAlign(11);
849  ltx.DrawLatexNDC(
850  gPad->GetLeftMargin() + 0.01,
851  gPad->GetBottomMargin() + 0.01,
852  ("#color[4]{" + tag.name + "}, IOV: #color[4]{" + std::to_string(std::get<0>(iov)) + "}").c_str());
853  }
854 
855  std::string fileName(this->m_imageFileName);
856  canvas.SaveAs(fileName.c_str());
857  }
858  return true;
859  }
860 
861  protected:
862  std::string payloadString;
863  std::string label_;
864  };
865 
866  /************************************************
867  Per sector plot of the inefficiency parameterization vs inst lumi (for PU factors)
868  *************************************************/
869  class SiPixelDynamicInefficiencyPUParametrization : public PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV> {
870  public:
871  SiPixelDynamicInefficiencyPUParametrization()
872  : PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV>("SiPixelDynamicInefficiency PU parametrization") {
873  label_ = "SiPixelDynamicInefficiencyPUParameterization";
874  payloadString =
875  fmt::sprintf("%s Dynamic Inefficiency parametrization", SiPixDynIneff::factorString[SiPixDynIneff::pu]);
876  }
877 
878  bool fill() override {
879  gStyle->SetPalette(1);
880  auto tag = PlotBase::getTag<0>();
881  auto iov = tag.iovs.front();
882  std::shared_ptr<SiPixelDynamicInefficiency> payload = this->fetchPayload(std::get<1>(iov));
883 
884  if (payload.get()) {
885  SiPixDynIneff::PUFactorMap theMap = payload->getPUFactors();
886  std::vector<uint32_t> detIdmasks_db = payload->getDetIdmasks();
887 
888  if (!SiPixDynIneff::checkPhase(SiPixelPI::phase::one, detIdmasks_db)) {
889  edm::LogError(label_) << label_ << " maps are not supported for non-Phase1 Pixel geometries !";
890  TCanvas canvas("Canv", "Canv", 1200, 1000);
892  std::string fileName(m_imageFileName);
893  canvas.SaveAs(fileName.c_str());
894  return false;
895  }
896 
897  std::vector<std::vector<double> > listOfParametrizations;
898 
899  // retrieve the list of phase1 detids
900  const auto& reader =
902  auto p1detIds = reader.getAllDetIds();
903 
904  // follows hack to get an inner ladder module first
905  // skip the first 8 dets since they lay on the same ladder
906  std::swap(p1detIds[0], p1detIds[8]);
907 
908  std::map<unsigned int, std::vector<uint32_t> > modules_per_region;
909 
910  // fill the maps
911  for (const auto& det : p1detIds) {
912  const auto& values = SiPixDynIneff::getMatchingPUFactors(det, theMap, detIdmasks_db);
913  // find the index in the vector
914  auto pIndex = std::find(listOfParametrizations.begin(), listOfParametrizations.end(), values);
915  // if it's not there push it back in the list of parametrizations and then insert in the map
916  if (pIndex == listOfParametrizations.end()) {
917  listOfParametrizations.push_back(values);
918  std::vector<unsigned int> toInsert = {det};
919  modules_per_region.insert(std::make_pair(listOfParametrizations.size() - 1, toInsert));
920  } else {
921  modules_per_region.at(pIndex - listOfParametrizations.begin()).push_back(det);
922  }
923  }
924 
925  unsigned int depth = listOfParametrizations.size();
926 
927  std::vector<std::string> namesOfParts;
928  namesOfParts.reserve(depth);
929  // fill in the (ordered) information about regions
930  for (const auto& [index, modules] : modules_per_region) {
932  const auto& regName = SiPixDynIneff::attachLocationLabel(modules, PhInfo);
933  namesOfParts.push_back(regName);
934 
935  /*
936  * The following is needed for internal
937  * debug / cross-check
938  */
939 
940  std::stringstream ss;
941  ss << "region name: " << regName << " has the following modules attached: [";
942  for (const auto& module : modules) {
943  ss << module << ", ";
944  }
945  ss.seekp(-2, std::ios_base::end); // remove last two chars
946  ss << "] "
947  << " has representation (";
948  for (const auto& param : listOfParametrizations[index]) {
949  ss << param << ", ";
950  }
951  ss.seekp(-2, std::ios_base::end); // remove last two chars
952  ss << ") ";
953  edm::LogPrint(label_) << ss.str() << "\n\n";
954  ss.str(std::string()); /* clear the stringstream */
955  }
956 
957  std::vector<TF1*> parametrizations;
958  std::vector<std::string> formulas;
959  parametrizations.reserve(depth);
960  formulas.reserve(depth);
961 
962  // fill the parametrization plots
963  SiPixDynIneff::fillParametrizations(listOfParametrizations, parametrizations, formulas, namesOfParts);
964 
965  // determine how the plot will be paginated
966  auto sides = SiPixDynIneff::getClosestFactors(depth);
967  TCanvas canvas("Canv", "Canv", sides.second * 900, sides.first * 600);
968  canvas.Divide(sides.second, sides.first);
969 
970  // print the sub-canvases
971  for (unsigned int i = 0; i < depth; i++) {
972  canvas.cd(i + 1);
973  gPad->SetGrid();
974  SiPixelPI::adjustCanvasMargins(gPad, 0.07, 0.14, 0.14, 0.03);
975  parametrizations[i]->Draw();
976 
977  // set axis
978  TH1* h = parametrizations[i]->GetHistogram();
979  TAxis* ax = h->GetXaxis();
980  ax->SetTitle("Inst. luminosity [10^{33} cm^{-2}s^{-1}]");
981 
982  TAxis* ay = h->GetYaxis();
983  ay->SetRangeUser(0.80, 1.00); // force the scale
984  ay->SetTitle("Double Column Efficiency parametrization");
985 
986  // beautify
988 
989  auto ltx = TLatex();
990  ltx.SetTextFont(62);
991  ltx.SetTextSize(0.045);
992  ltx.SetTextAlign(11);
993  ltx.DrawLatexNDC(
994  gPad->GetLeftMargin() + 0.03,
995  gPad->GetBottomMargin() + 0.08,
996  ("#color[2]{" + tag.name + "},IOV: #color[2]{" + std::to_string(std::get<0>(iov)) + "}").c_str());
997 
998  auto ltxForm = TLatex();
999  ltxForm.SetTextFont(62);
1000  ltxForm.SetTextColor(kRed);
1001  ltxForm.SetTextSize(0.035);
1002  ltxForm.SetTextAlign(11);
1003  ltxForm.DrawLatexNDC(gPad->GetLeftMargin() + 0.03, gPad->GetBottomMargin() + 0.04, formulas[i].c_str());
1004 
1005  edm::LogPrint(label_) << namesOfParts[i] << " => " << formulas[i] << std::endl;
1006  }
1007 
1008  std::string fileName(this->m_imageFileName);
1009  canvas.SaveAs(fileName.c_str());
1010 
1011  } // if payload.get()
1012  return true;
1013  } // fill()
1014 
1015  protected:
1016  std::string payloadString;
1017  std::string label_;
1018  };
1019 
1020  template <IOVMultiplicity nIOVs, int ntags>
1021  class SiPixelDynamicInefficiencyPUParamComparisonBase : public PlotImage<SiPixelDynamicInefficiency, nIOVs, ntags> {
1022  public:
1023  SiPixelDynamicInefficiencyPUParamComparisonBase()
1024  : PlotImage<SiPixelDynamicInefficiency, nIOVs, ntags>(
1025  Form("SiPixelDynamic Inefficiency parameterization comparison by Region %i tag(s)", ntags)) {
1026  label_ = "SiPixelDynamicInefficiencyPUParameterization";
1027  }
1028 
1029  bool fill() override {
1030  gStyle->SetPalette(1);
1031 
1032  // trick to deal with the multi-ioved tag and two tag case at the same time
1033  auto theIOVs = PlotBase::getTag<0>().iovs;
1034  auto f_tagname = PlotBase::getTag<0>().name;
1035  std::string l_tagname = "";
1036  auto firstiov = theIOVs.front();
1037  std::tuple<cond::Time_t, cond::Hash> lastiov;
1038 
1039  // we don't support (yet) comparison with more than 2 tags
1040  assert(this->m_plotAnnotations.ntags < 3);
1041 
1042  if (this->m_plotAnnotations.ntags == 2) {
1043  auto tag2iovs = PlotBase::getTag<1>().iovs;
1044  l_tagname = PlotBase::getTag<1>().name;
1045  lastiov = tag2iovs.front();
1046  } else {
1047  lastiov = theIOVs.back();
1048  }
1049 
1050  std::shared_ptr<SiPixelDynamicInefficiency> last_payload = this->fetchPayload(std::get<1>(lastiov));
1051  std::shared_ptr<SiPixelDynamicInefficiency> first_payload = this->fetchPayload(std::get<1>(firstiov));
1052 
1053  if (first_payload.get() && last_payload.get()) {
1054  SiPixDynIneff::PUFactorMap f_theMap = first_payload->getPUFactors();
1055  std::vector<uint32_t> f_detIdmasks_db = first_payload->getDetIdmasks();
1056 
1057  SiPixDynIneff::PUFactorMap l_theMap = last_payload->getPUFactors();
1058  std::vector<uint32_t> l_detIdmasks_db = last_payload->getDetIdmasks();
1059 
1060  if (!SiPixDynIneff::checkPhase(SiPixelPI::phase::one, f_detIdmasks_db) ||
1061  !SiPixDynIneff::checkPhase(SiPixelPI::phase::one, l_detIdmasks_db)) {
1062  edm::LogError(label_) << label_ << " maps are not supported for non-Phase1 Pixel geometries !";
1063  TCanvas canvas("Canv", "Canv", 1200, 1000);
1065  std::string fileName(this->m_imageFileName);
1066  canvas.SaveAs(fileName.c_str());
1067  return false;
1068  }
1069 
1070  std::vector<std::vector<double> > f_listOfParametrizations;
1071  std::vector<std::vector<double> > l_listOfParametrizations;
1072 
1073  // retrieve the list of phase1 detids
1074  const auto& reader =
1076  auto p1detIds = reader.getAllDetIds();
1077 
1078  // follows hack to get an inner ladder module first
1079  // skip the first 8 dets since they lay on the same ladder
1080  std::swap(p1detIds[0], p1detIds[8]);
1081 
1082  std::map<unsigned int, std::vector<uint32_t> > modules_per_region;
1083 
1084  // fill the maps
1085  for (const auto& det : p1detIds) {
1086  const auto& f_values = SiPixDynIneff::getMatchingPUFactors(det, f_theMap, f_detIdmasks_db);
1087  const auto& l_values = SiPixDynIneff::getMatchingPUFactors(det, l_theMap, l_detIdmasks_db);
1088 
1089  // find the index in the vector
1090  auto fIndex = std::find(f_listOfParametrizations.begin(), f_listOfParametrizations.end(), f_values);
1091  auto lIndex = std::find(l_listOfParametrizations.begin(), l_listOfParametrizations.end(), l_values);
1092 
1093  // if it's not there push it back in the list of parametrizations and then insert in the map
1094  if (fIndex == f_listOfParametrizations.end()) {
1095  f_listOfParametrizations.push_back(f_values);
1096  std::vector<unsigned int> toInsert = {det};
1097  modules_per_region.insert(std::make_pair(f_listOfParametrizations.size() - 1, toInsert));
1098  } else {
1099  modules_per_region.at(fIndex - f_listOfParametrizations.begin()).push_back(det);
1100  }
1101 
1102  if (lIndex == l_listOfParametrizations.end()) {
1103  l_listOfParametrizations.push_back(l_values);
1104  }
1105  }
1106 
1107  unsigned int f_depth = f_listOfParametrizations.size();
1108  unsigned int l_depth = l_listOfParametrizations.size();
1109 
1110  if (l_depth != f_depth) {
1111  edm::LogError(label_) << label_
1112  << " trying to compare dynamic inefficiencys payload with different detid masks!";
1113  TCanvas canvas("Canv", "Canv", 1200, 1000);
1115  std::string fileName(this->m_imageFileName);
1116  canvas.SaveAs(fileName.c_str());
1117  return false;
1118  }
1119 
1120  assert(f_depth == l_depth);
1121 
1122  std::vector<std::string> namesOfParts;
1123  namesOfParts.reserve(f_depth);
1124  // fill in the (ordered) information about regions
1125  for (const auto& [index, modules] : modules_per_region) {
1127  const auto& regName = SiPixDynIneff::attachLocationLabel(modules, PhInfo);
1128  namesOfParts.push_back(regName);
1129 
1130  /*
1131  * The following is needed for internal
1132  * debug / cross-check
1133  */
1134 
1135  std::stringstream ss;
1136  ss << "region name: " << regName << " has the following modules attached: [";
1137  for (const auto& module : modules) {
1138  ss << module << ", ";
1139  }
1140  ss.seekp(-2, std::ios_base::end); // remove last two chars
1141  ss << "] "
1142  << " has representation (";
1143  for (const auto& param : f_listOfParametrizations[index]) {
1144  ss << param << ", ";
1145  }
1146  ss.seekp(-2, std::ios_base::end); // remove last two chars
1147  ss << ") ";
1148  edm::LogPrint(label_) << ss.str() << "\n\n";
1149  ss.str(std::string()); /* clear the stringstream */
1150  }
1151 
1152  // now fill the paramtrizations
1153  std::vector<TF1*> f_parametrizations;
1154  std::vector<std::string> f_formulas;
1155  f_parametrizations.reserve(f_depth);
1156  f_formulas.reserve(f_depth);
1157 
1158  std::vector<TF1*> l_parametrizations;
1159  std::vector<std::string> l_formulas;
1160  l_parametrizations.reserve(l_depth);
1161  l_formulas.reserve(l_depth);
1162 
1163  // fill the parametrization plots
1164  SiPixDynIneff::fillParametrizations(f_listOfParametrizations, f_parametrizations, f_formulas, namesOfParts);
1165  SiPixDynIneff::fillParametrizations(l_listOfParametrizations, l_parametrizations, l_formulas, namesOfParts);
1166 
1167  // determine how the plot will be paginated
1168  auto sides = SiPixDynIneff::getClosestFactors(f_depth);
1169  TCanvas canvas("Canv", "Canv", sides.second * 900, sides.first * 600);
1170  canvas.Divide(sides.second, sides.first);
1171 
1172  // print the sub-canvases
1173  for (unsigned int i = 0; i < f_depth; i++) {
1174  canvas.cd(i + 1);
1175  gPad->SetGrid();
1176  SiPixelPI::adjustCanvasMargins(gPad, 0.07, 0.14, 0.14, 0.03);
1177  f_parametrizations[i]->Draw();
1178  l_parametrizations[i]->SetLineColor(kBlue);
1179  l_parametrizations[i]->SetLineStyle(kDashed);
1180  l_parametrizations[i]->Draw("same");
1181 
1182  // set axis
1183  TH1* h = f_parametrizations[i]->GetHistogram();
1184  TAxis* ax = h->GetXaxis();
1185  ax->SetTitle("Inst. luminosity [10^{33} cm^{-2}s^{-1}]");
1186 
1187  TAxis* ay = h->GetYaxis();
1188  ay->SetRangeUser(0.80, 1.00); // force the scale
1189  ay->SetTitle("Double Column Efficiency parametrization");
1190 
1191  // beautify
1193 
1194  auto ltx = TLatex();
1195  ltx.SetTextFont(62);
1196  ltx.SetTextSize(0.045);
1197  ltx.SetTextAlign(11);
1198  ltx.DrawLatexNDC(
1199  gPad->GetLeftMargin() + 0.03,
1200  gPad->GetBottomMargin() + 0.16,
1201  ("#color[2]{" + f_tagname + "},IOV: #color[2]{" + std::to_string(std::get<0>(firstiov)) + "}").c_str());
1202  ltx.DrawLatexNDC(
1203  gPad->GetLeftMargin() + 0.03,
1204  gPad->GetBottomMargin() + 0.08,
1205  ("#color[4]{" + l_tagname + "},IOV: #color[4]{" + std::to_string(std::get<0>(lastiov)) + "}").c_str());
1206 
1207  auto ltxForm = TLatex();
1208  ltxForm.SetTextFont(62);
1209  ltxForm.SetTextColor(kRed);
1210  ltxForm.SetTextSize(0.035);
1211  ltxForm.SetTextAlign(11);
1212  ltxForm.DrawLatexNDC(gPad->GetLeftMargin() + 0.03, gPad->GetBottomMargin() + 0.12, f_formulas[i].c_str());
1213 
1214  ltxForm.SetTextColor(kBlue);
1215  ltxForm.DrawLatexNDC(gPad->GetLeftMargin() + 0.03, gPad->GetBottomMargin() + 0.04, l_formulas[i].c_str());
1216 
1217  edm::LogPrint(label_) << namesOfParts[i] << " => " << f_formulas[i] << std::endl;
1218  edm::LogPrint(label_) << namesOfParts[i] << " => " << l_formulas[i] << std::endl;
1219  }
1220 
1221  std::string fileName(this->m_imageFileName);
1222  canvas.SaveAs(fileName.c_str());
1223  //canvas.SaveAs((fileName+".root").c_str());
1224 
1225  } // if payload.get()
1226  return true;
1227  } // fill()
1228 
1229  protected:
1230  std::string label_;
1231  };
1232 
1233  using SiPixelDynamicInefficiencyPUParamComparisonTwoTags =
1234  SiPixelDynamicInefficiencyPUParamComparisonBase<SINGLE_IOV, 2>;
1235 
1236 } // namespace
1237 
1238 // Register the classes as boost python plugin
1240  PAYLOAD_INSPECTOR_CLASS(SiPixelDynamicInefficiencyTest);
1241  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixIneffROCfromDynIneffMap);
1242  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixIneffROCfromDynIneffMap);
1243  PAYLOAD_INSPECTOR_CLASS(SiPixelFullIneffROCfromDynIneffMap);
1244  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixIneffROCsMapCompareTwoTags);
1245  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixIneffROCsMapCompareTwoTags);
1246  PAYLOAD_INSPECTOR_CLASS(SiPixelFullIneffROCsMapCompareTwoTags);
1247  PAYLOAD_INSPECTOR_CLASS(SiPixelDynamicInefficiencyGeomFactorMap);
1248  PAYLOAD_INSPECTOR_CLASS(SiPixelDynamicInefficiencyColGeomFactorMap);
1249  PAYLOAD_INSPECTOR_CLASS(SiPixelDynamicInefficiencyChipGeomFactorMap);
1250  PAYLOAD_INSPECTOR_CLASS(SiPixelDynamicInefficiencyPUPixelMaps);
1251  PAYLOAD_INSPECTOR_CLASS(SiPixelDynamicInefficiencyPUParametrization);
1252  PAYLOAD_INSPECTOR_CLASS(SiPixelDynamicInefficiencyPUParamComparisonTwoTags);
1253 }
size
Write out results.
Log< level::Info, true > LogVerbatim
void fillGeometryInfo(const DetId &detId, const TrackerTopology &tTopo, const SiPixelPI::phase &ph)
static constexpr char const *const kPh1DefaultFile
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)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
Definition: Electron.h:6
constexpr uint32_t mask
Definition: gpuClustering.h:26
static std::string to_string(const XMLCh *ch)
bool equal(const T &first, const T &second)
Definition: Equal.h:32
static std::string const input
Definition: EdmProvDump.cc:50
const SiPixelPI::phase phase() const
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:19
static const unsigned int phase1size
SiPixelPI::regions filterThePartition()
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)
void adjustCanvasMargins(TVirtualPad *pad, float top, float bottom, float left, float right)
Log< level::Warning, true > LogPrint
d
Definition: ztail.py:151
Definition: DetId.h:17
const std::array< std::string, 3 > DetNames
void makeNicePlotStyle(TH1 *hist)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void displayNotSupported(TCanvas &canv, const unsigned int size)
void fillSelectedRocs(const uint32_t &detid, const std::bitset< 16 > &theROCs, double value)
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
col
Definition: cuy.py:1009
def canvas(sub, attr)
Definition: svgfig.py:482
uint32_t first(const DetId &id) const
static unsigned int const shift
float x
static constexpr char const *const kPh0DefaultFile
std::string getStringFromRegionEnum(SiPixelPI::regions e)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define str(s)
unsigned transform(const HcalDetId &id, unsigned transformCode)