CMS 3D CMS Logo

SiPixelGainCalibHelper.h
Go to the documentation of this file.
1 #ifndef CONDCORE_SIPIXELPLUGINS_SIPIXELGAINCALIBHELPER_H
2 #define CONDCORE_SIPIXELPLUGINS_SIPIXELGAINCALIBHELPER_H
3 
16 
17 #include <type_traits>
18 #include <memory>
19 #include <sstream>
20 #include <fmt/printf.h>
21 
22 // include ROOT
23 #include "TH2F.h"
24 #include "TH1F.h"
25 #include "TLegend.h"
26 #include "TCanvas.h"
27 #include "TLine.h"
28 #include "TStyle.h"
29 #include "TLatex.h"
30 #include "TPave.h"
31 #include "TPaveStats.h"
32 #include "TGaxis.h"
33 
34 namespace gainCalibHelper {
35 
36  using AvgMap = std::map<uint32_t, float>;
37 
38  namespace gainCalibPI {
39 
40  enum type { t_gain = 0, t_pedestal = 1, t_correlation = 2 };
41  static const std::array<std::string, 3> t_titles = {{"gain", "pedestal", "correlation"}};
42 
43  //===========================================================================
44  // helper method to fill the ratio and diff distributions
45  template <typename PayloadType>
46  static std::array<std::shared_ptr<TH1F>, 2> fillDiffAndRatio(const std::shared_ptr<PayloadType>& payload_A,
47  const std::shared_ptr<PayloadType>& payload_B,
48  const gainCalibPI::type& theType) {
49  std::array<std::shared_ptr<TH1F>, 2> arr;
50 
51  std::vector<uint32_t> detids_A;
52  payload_A->getDetIds(detids_A);
53  std::vector<uint32_t> detids_B;
54  payload_B->getDetIds(detids_B);
55 
56  std::vector<float> v_ratios;
57  std::vector<float> v_diffs;
58 
59  if (detids_A != detids_B) {
60  edm::LogError("fillDiffAndRatio") << "the list of DetIds for the two payloads are not equal"
61  << " cannot make any comparison!" << std::endl;
62  }
63 
64  assert(detids_A == detids_B);
65  for (const auto& d : detids_A) {
66  auto range = payload_A->getRange(d);
67  int numberOfRowsToAverageOver = payload_A->getNumberOfRowsToAverageOver();
68  int ncols = payload_A->getNCols(d);
69  int nRocsInRow = (range.second - range.first) / ncols / numberOfRowsToAverageOver;
70  unsigned int nRowsForHLT = 1;
71  int nrows = std::max((payload_A->getNumberOfRowsToAverageOver() * nRocsInRow),
72  nRowsForHLT); // dirty trick to make it work for the HLT payload
73 
74  auto rAndCol_A = payload_A->getRangeAndNCols(d);
75  auto rAndCol_B = payload_B->getRangeAndNCols(d);
76  bool isDeadCol, isNoisyCol;
77 
78  float ratio(-.1), diff(-1.);
79  for (int col = 0; col < ncols; col++) {
80  for (int row = 0; row < nrows; row++) {
81  switch (theType) {
82  case gainCalibPI::t_gain: {
83  auto gainA = payload_A->getGain(col, row, rAndCol_A.first, rAndCol_A.second, isDeadCol, isNoisyCol);
84  auto gainB = payload_B->getGain(col, row, rAndCol_B.first, rAndCol_B.second, isDeadCol, isNoisyCol);
85  ratio = gainB != 0 ? (gainA / gainB) : -1.; // if the ratio does not make sense the default is -1
86  diff = gainA - gainB;
87  break;
88  }
90  auto pedA = payload_A->getPed(col, row, rAndCol_A.first, rAndCol_A.second, isDeadCol, isNoisyCol);
91  auto pedB = payload_B->getPed(col, row, rAndCol_B.first, rAndCol_B.second, isDeadCol, isNoisyCol);
92  ratio = pedB != 0 ? (pedA / pedB) : -1.; // if the ratio does not make sense the default is -1
93  diff = pedA - pedB;
94  break;
95  }
96  default:
97  edm::LogError("gainCalibPI::fillTheHisto") << "Unrecognized type " << theType << std::endl;
98  break;
99  }
100  // fill the containers
101  v_diffs.push_back(diff);
102  v_ratios.push_back(ratio);
103  } // loop on rows
104  } // loop on cols
105  } // loop on detids
106 
107  std::sort(v_diffs.begin(), v_diffs.end());
108  std::sort(v_ratios.begin(), v_ratios.end());
109 
110  double minDiff = v_diffs.front();
111  double maxDiff = v_diffs.back();
112  double minRatio = v_ratios.front();
113  double maxRatio = v_ratios.back();
114 
115  arr[0] = std::make_shared<TH1F>("h_Ratio", "", 50, minRatio - 1., maxRatio + 1.);
116  arr[1] = std::make_shared<TH1F>("h_Diff", "", 50, minDiff - 1., maxDiff + 1.);
117 
118  for (const auto& r : v_ratios) {
119  arr[0]->Fill(r);
120  }
121  for (const auto& d : v_diffs) {
122  arr[1]->Fill(d);
123  }
124  return arr;
125  }
126 
127  //============================================================================
128  // helper method to fill the gain / pedestals distributions
129  template <typename PayloadType>
130  static void fillTheHisto(const std::shared_ptr<PayloadType>& payload,
131  std::shared_ptr<TH1F> h1,
132  gainCalibPI::type theType,
133  const std::vector<uint32_t>& wantedIds = {}) {
134  std::vector<uint32_t> detids;
135  if (wantedIds.empty()) {
136  payload->getDetIds(detids);
137  } else {
138  detids.assign(wantedIds.begin(), wantedIds.end());
139  }
140 
141  for (const auto& d : detids) {
142  // skip the special case used to signal there are no attached dets
143  if (d == 0xFFFFFFFF)
144  continue;
145 
146  auto range = payload->getRange(d);
147  int numberOfRowsToAverageOver = payload->getNumberOfRowsToAverageOver();
148  int ncols = payload->getNCols(d);
149  int nRocsInRow = (range.second - range.first) / ncols / numberOfRowsToAverageOver;
150  unsigned int nRowsForHLT = 1;
151  int nrows = std::max((payload->getNumberOfRowsToAverageOver() * nRocsInRow),
152  nRowsForHLT); // dirty trick to make it work for the HLT payload
153 
154  auto rangeAndCol = payload->getRangeAndNCols(d);
155  bool isDeadColumn;
156  bool isNoisyColumn;
157 
158  COUT << "NCOLS: " << payload->getNCols(d) << " " << rangeAndCol.second << " NROWS:" << nrows
159  << ", RANGES: " << rangeAndCol.first.second - rangeAndCol.first.first
160  << ", Ratio: " << float(rangeAndCol.first.second - rangeAndCol.first.first) / rangeAndCol.second
161  << std::endl;
162 
163  float quid(-99999.);
164 
165  for (int col = 0; col < ncols; col++) {
166  for (int row = 0; row < nrows; row++) {
167  switch (theType) {
168  case gainCalibPI::t_gain:
169  quid = payload->getGain(col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
170  break;
172  quid = payload->getPed(col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
173  break;
174  default:
175  edm::LogError("gainCalibPI::fillTheHisto") << "Unrecognized type " << theType << std::endl;
176  break;
177  }
178  h1->Fill(quid);
179  } // loop on rows
180  } // loop on cols
181  } // loop on detids
182  } // fillTheHisto
183 
184  //============================================================================
185  // helper method to fill the gain / pedestal averages per module maps
186  template <typename PayloadType>
187  static void fillThePerModuleMap(const std::shared_ptr<PayloadType>& payload,
188  AvgMap& map,
189  gainCalibPI::type theType) {
190  std::vector<uint32_t> detids;
191  payload->getDetIds(detids);
192 
193  for (const auto& d : detids) {
194  auto range = payload->getRange(d);
195  int numberOfRowsToAverageOver = payload->getNumberOfRowsToAverageOver();
196  int ncols = payload->getNCols(d);
197  int nRocsInRow = (range.second - range.first) / ncols / numberOfRowsToAverageOver;
198  unsigned int nRowsForHLT = 1;
199  int nrows = std::max((payload->getNumberOfRowsToAverageOver() * nRocsInRow),
200  nRowsForHLT); // dirty trick to make it work for the HLT payload
201 
202  auto rangeAndCol = payload->getRangeAndNCols(d);
203  bool isDeadColumn;
204  bool isNoisyColumn;
205 
206  float sumOfX(0.);
207  int nPixels(0);
208  for (int col = 0; col < ncols; col++) {
209  for (int row = 0; row < nrows; row++) {
210  nPixels++;
211  switch (theType) {
212  case gainCalibPI::t_gain:
213  sumOfX +=
214  payload->getGain(col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
215  break;
217  sumOfX += payload->getPed(col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
218  break;
219  default:
220  edm::LogError("gainCalibPI::fillThePerModuleMap") << "Unrecognized type " << theType << std::endl;
221  break;
222  } // switch on the type
223  } // rows
224  } // columns
225  // fill the return value map
226  map[d] = sumOfX / nPixels;
227  } // loop on the detId
228  } // fillThePerModuleMap
229 
230  //============================================================================
231  // helper method to fill the gain / pedestals distributions
232  template <typename PayloadType>
233  static void fillTheHistos(const std::shared_ptr<PayloadType>& payload,
234  std::shared_ptr<TH1> hBPix,
235  std::shared_ptr<TH1> hFPix,
236  gainCalibPI::type theType) {
237  std::vector<uint32_t> detids;
238  payload->getDetIds(detids);
239 
240  bool isCorrelation_ = hBPix.get()->InheritsFrom(TH2::Class()) && (theType == gainCalibPI::t_correlation);
241 
242  for (const auto& d : detids) {
243  int subid = DetId(d).subdetId();
244  auto range = payload->getRange(d);
245  int numberOfRowsToAverageOver = payload->getNumberOfRowsToAverageOver();
246  int ncols = payload->getNCols(d);
247  int nRocsInRow = (range.second - range.first) / ncols / numberOfRowsToAverageOver;
248  unsigned int nRowsForHLT = 1;
249  int nrows = std::max((payload->getNumberOfRowsToAverageOver() * nRocsInRow),
250  nRowsForHLT); // dirty trick to make it work for the HLT payload
251 
252  auto rangeAndCol = payload->getRangeAndNCols(d);
253  bool isDeadColumn;
254  bool isNoisyColumn;
255 
256  for (int col = 0; col < ncols; col++) {
257  for (int row = 0; row < nrows; row++) {
258  float gain = payload->getGain(col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
259  float ped = payload->getPed(col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
260 
261  switch (subid) {
263  if (isCorrelation_) {
264  hBPix->Fill(gain, ped);
265  } else {
266  hBPix->Fill((theType == gainCalibPI::t_gain ? gain : ped));
267  }
268  break;
269  }
271  if (isCorrelation_) {
272  hFPix->Fill(gain, ped);
273  } else {
274  hFPix->Fill((theType == gainCalibPI::t_gain ? gain : ped));
275  }
276  break;
277  }
278  default:
279  edm::LogError("gainCalibPI::fillTheHistos") << d << " is not a Pixel DetId" << std::endl;
280  break;
281  } // switch on subid
282  } // row loop
283  } // column loop
284  } // detid loop
285  } // filltheHistos
286  } // namespace gainCalibPI
287 
288  constexpr char const* TypeName[2] = {"Gains", "Pedestals"};
289 
290  /*******************************************************************
291  1d histogram of SiPixelGainCalibration for Gains of 1 IOV
292  ********************************************************************/
293  template <gainCalibPI::type myType, class PayloadType>
295  : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
296  public:
298  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
299  Form("SiPixelGainCalibration %s Values", TypeName[myType])) {
300  if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
301  isForHLT_ = false;
302  label_ = "SiPixelGainCalibrationOffline_PayloadInspector";
303  } else {
304  isForHLT_ = true;
305  label_ = "SiPixelGainCalibrationForHLT_PayloadInspector";
306  }
307  }
308 
309  bool fill() override {
310  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
311  auto iov = tag.iovs.front();
312 
313  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
314 
315  gStyle->SetOptStat("emr");
316 
317  float minimum(9999.);
318  float maximum(-9999.);
319 
320  switch (myType) {
321  case gainCalibPI::t_gain:
322  maximum = payload->getGainHigh();
323  minimum = payload->getGainLow();
324  break;
326  maximum = payload->getPedHigh();
327  minimum = payload->getPedLow();
328  break;
329  default:
330  edm::LogError(label_) << "Unrecognized type " << myType << std::endl;
331  break;
332  }
333 
334  TCanvas canvas("Canv", "Canv", 1200, 1000);
335  auto h1 = std::make_shared<TH1F>(Form("%s values", TypeName[myType]),
336  Form("SiPixel Gain Calibration %s - %s;per %s %s;# %ss",
337  (isForHLT_ ? "ForHLT" : "Offline"),
338  TypeName[myType],
339  (isForHLT_ ? "Column" : "Pixel"),
340  TypeName[myType],
341  (isForHLT_ ? "column" : "pixel")),
342  200,
343  minimum,
344  maximum);
345  canvas.cd();
346  SiPixelPI::adjustCanvasMargins(canvas.cd(), 0.06, 0.12, 0.12, 0.05);
347  canvas.Modified();
348 
349  // fill the histogram
350  gainCalibPI::fillTheHisto(payload, h1, myType);
351 
352  canvas.cd()->SetLogy();
353  h1->SetTitle("");
354  h1->GetYaxis()->SetRangeUser(0.1, h1->GetMaximum() * 10.);
355  h1->SetFillColor(kBlue);
356  h1->SetMarkerStyle(20);
357  h1->SetMarkerSize(1);
358  h1->Draw("bar2");
359 
361  h1->SetStats(true);
362 
363  canvas.Update();
364 
365  TLegend legend = TLegend(0.40, 0.88, 0.94, 0.93);
366  legend.SetHeader(("Payload hash: #bf{" + (std::get<1>(iov)) + "}").c_str(),
367  "C"); // option "C" allows to center the header
368  //legend.AddEntry(h1.get(), ("IOV: " + std::to_string(std::get<0>(iov))).c_str(), "PL");
369  legend.SetLineColor(10);
370  legend.SetTextSize(0.025);
371  legend.Draw("same");
372 
373  TPaveStats* st = (TPaveStats*)h1->FindObject("stats");
374  st->SetTextSize(0.03);
375  SiPixelPI::adjustStats(st, 0.15, 0.83, 0.39, 0.93);
376 
377  auto ltx = TLatex();
378  ltx.SetTextFont(62);
379  //ltx.SetTextColor(kBlue);
380  ltx.SetTextSize(0.05);
381  ltx.SetTextAlign(11);
382  ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.1,
383  1 - gPad->GetTopMargin() + 0.01,
384  ("SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
385 
387  canvas.SaveAs(fileName.c_str());
388 
389  return true;
390  }
391 
392  protected:
393  bool isForHLT_;
395  };
396 
397  /*******************************************************************
398  1d histograms per region of SiPixelGainCalibration for Gains of 1 IOV
399  ********************************************************************/
400  template <bool isBarrel, gainCalibPI::type myType, class PayloadType>
402  : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
403  public:
405  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
406  Form("SiPixelGainCalibration %s Values Per Region", TypeName[myType])) {
408 
409  if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
410  isForHLT_ = false;
411  label_ = "SiPixelGainCalibrationOffline_PayloadInspector";
412  } else {
413  isForHLT_ = true;
414  label_ = "SiPixelGainCalibrationForHLT_PayloadInspector";
415  }
416  }
417 
418  bool fill() override {
419  gStyle->SetOptStat("mr");
420 
421  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
422  auto iov = tag.iovs.front();
423 
424  // parse first if log
425  bool setLog(true);
427  auto ip = paramValues.find("SetLog");
428  if (ip != paramValues.end()) {
429  auto answer = ip->second;
430  if (!SiPixelPI::checkAnswerOK(answer, setLog)) {
431  throw cms::Exception(label_)
432  << "\nERROR: " << answer
433  << " is not a valid setting for this parameter, please use True,False,1,0,Yes,No \n\n";
434  }
435  }
436 
437  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
438 
439  std::vector<uint32_t> detids;
440  payload->getDetIds(detids);
441 
442  float minimum(9999.);
443  float maximum(-9999.);
444 
445  switch (myType) {
446  case gainCalibPI::t_gain:
447  maximum = payload->getGainHigh();
448  minimum = payload->getGainLow();
449  break;
451  maximum = payload->getPedHigh();
452  minimum = payload->getPedLow();
453  break;
454  default:
455  edm::LogError(label_) << "Unrecognized type " << myType << std::endl;
456  break;
457  }
458 
459  TCanvas canvas("Canv", "Canv", isBarrel ? 1400 : 1800, 1200);
460  if (detids.size() > SiPixelPI::phase1size) {
461  SiPixelPI::displayNotSupported(canvas, detids.size());
463  canvas.SaveAs(fileName.c_str());
464  return false;
465  }
466 
467  canvas.cd();
468 
469  SiPixelPI::PhaseInfo phaseInfo(detids.size());
470  const char* path_toTopologyXML = phaseInfo.pathToTopoXML();
471 
472  TrackerTopology tTopo =
474 
475  auto myPlots = PixelRegions::PixelRegionContainers(&tTopo, phaseInfo.phase());
476  myPlots.bookAll(Form("SiPixel Gain Calibration %s - %s", (isForHLT_ ? "ForHLT" : "Offline"), TypeName[myType]),
477  Form("per %s %s", (isForHLT_ ? "Column" : "Pixel"), TypeName[myType]),
478  Form("# %ss", (isForHLT_ ? "column" : "pixel")),
479  200,
480  minimum,
481  maximum);
482 
483  canvas.Modified();
484 
485  // fill the histograms
486  for (const auto& pixelId : PixelRegions::PixelIDs) {
487  auto wantedDets = PixelRegions::attachedDets(pixelId, &tTopo, phaseInfo.phase());
488  gainCalibPI::fillTheHisto(payload, myPlots.getHistoFromMap(pixelId), myType, wantedDets);
489  }
490 
491  if (setLog) {
492  myPlots.setLogScale();
493  }
494  myPlots.beautify(kBlue, -1);
495  myPlots.draw(canvas, isBarrel, "HIST");
496 
497  TLegend legend = TLegend(0.45, 0.88, 0.91, 0.92);
498  legend.SetHeader(("hash: #bf{" + (std::get<1>(iov)) + "}").c_str(),
499  "C"); // option "C" allows to center the header
500  //legend.AddEntry(h1.get(), ("IOV: " + std::to_string(std::get<0>(iov))).c_str(), "PL");
501  legend.SetLineColor(10);
502  legend.SetTextSize(0.025);
503  legend.Draw("same");
504 
505  unsigned int maxPads = isBarrel ? 4 : 12;
506  for (unsigned int c = 1; c <= maxPads; c++) {
507  canvas.cd(c);
508  SiPixelPI::adjustCanvasMargins(canvas.cd(c), 0.06, 0.12, 0.12, 0.05);
509  legend.Draw("same");
510  canvas.cd(c)->Update();
511  }
512 
513  myPlots.stats();
514 
515  auto ltx = TLatex();
516  ltx.SetTextFont(62);
517  ltx.SetTextSize(0.05);
518  ltx.SetTextAlign(11);
519 
520  for (unsigned int c = 1; c <= maxPads; c++) {
521  auto index = isBarrel ? c - 1 : c + 3;
522  canvas.cd(c);
523  auto leftX = setLog ? 0. : 0.1;
524  ltx.DrawLatexNDC(gPad->GetLeftMargin() + leftX,
525  1 - gPad->GetTopMargin() + 0.01,
526  (PixelRegions::IDlabels.at(index) + ", IOV:" + std::to_string(std::get<0>(iov))).c_str());
527  }
528 
530  canvas.SaveAs(fileName.c_str());
531 
532  return true;
533  }
534 
535  protected:
536  bool isForHLT_;
538  };
539 
540  /*******************************************************************
541  1d histograms comparison per region of SiPixelGainCalibration for Gains of 2 IOV
542  ********************************************************************/
543  template <bool isBarrel,
544  gainCalibPI::type myType,
546  int ntags,
547  class PayloadType>
549  : public cond::payloadInspector::PlotImage<PayloadType, nIOVs, ntags> {
550  public:
552  : cond::payloadInspector::PlotImage<PayloadType, nIOVs, ntags>(
553  Form("SiPixelGainCalibration %s Values Per Region %i tag(s)", TypeName[myType], ntags)) {
555 
556  if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
557  isForHLT_ = false;
558  label_ = "SiPixelGainCalibrationOffline_PayloadInspector";
559  } else {
560  isForHLT_ = true;
561  label_ = "SiPixelGainCalibrationForHLT_PayloadInspector";
562  }
563  }
564 
565  bool fill() override {
566  gStyle->SetOptStat("mr");
567 
568  COUT << "ntags: " << ntags << " this->m_plotAnnotations.ntags: " << this->m_plotAnnotations.ntags << std::endl;
569 
570  // trick to deal with the multi-ioved tag and two tag case at the same time
571  auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
572  auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name;
573  std::string l_tagname = "";
574  auto firstiov = theIOVs.front();
575  std::tuple<cond::Time_t, cond::Hash> lastiov;
576 
577  // we don't support (yet) comparison with more than 2 tags
578  assert(this->m_plotAnnotations.ntags < 3);
579 
580  if (this->m_plotAnnotations.ntags == 2) {
581  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
582  l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name;
583  lastiov = tag2iovs.front();
584  } else {
585  lastiov = theIOVs.back();
586  }
587 
588  // parse first if log
589  bool setLog(true);
591  auto ip = paramValues.find("SetLog");
592  if (ip != paramValues.end()) {
593  auto answer = ip->second;
594  if (!SiPixelPI::checkAnswerOK(answer, setLog)) {
595  throw cms::Exception(label_)
596  << "\nERROR: " << answer
597  << " is not a valid setting for this parameter, please use True,False,1,0,Yes,No \n\n";
598  }
599  }
600 
601  std::shared_ptr<PayloadType> last_payload = this->fetchPayload(std::get<1>(lastiov));
602  std::shared_ptr<PayloadType> first_payload = this->fetchPayload(std::get<1>(firstiov));
603 
604  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
605  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
606 
607  std::vector<uint32_t> f_detids, l_detids;
608  last_payload->getDetIds(l_detids);
609  first_payload->getDetIds(f_detids);
610 
611  float minimum(9999.);
612  float maximum(-9999.);
613 
614  switch (myType) {
615  case gainCalibPI::t_gain:
616  maximum = std::max(last_payload->getGainHigh(), first_payload->getGainHigh());
617  minimum = std::min(last_payload->getGainLow(), first_payload->getGainLow());
618  break;
620  maximum = std::max(last_payload->getPedHigh(), first_payload->getPedHigh());
621  minimum = std::min(last_payload->getPedLow(), first_payload->getPedLow());
622  break;
623  default:
624  edm::LogError(label_) << "Unrecognized type " << myType << std::endl;
625  break;
626  }
627 
628  TCanvas canvas("Canv", "Canv", isBarrel ? 1400 : 1800, 1200);
629  if (std::max(l_detids.size(), f_detids.size()) > SiPixelPI::phase1size) {
630  SiPixelPI::displayNotSupported(canvas, std::max(f_detids.size(), l_detids.size()));
632  canvas.SaveAs(fileName.c_str());
633  return false;
634  }
635 
636  canvas.cd();
637 
638  SiPixelPI::PhaseInfo l_phaseInfo(l_detids.size());
639  SiPixelPI::PhaseInfo f_phaseInfo(f_detids.size());
640  const char* path_toTopologyXML = l_phaseInfo.pathToTopoXML();
641 
642  auto l_tTopo =
644 
645  auto l_myPlots = PixelRegions::PixelRegionContainers(&l_tTopo, l_phaseInfo.phase());
646  l_myPlots.bookAll(
647  Form("Last SiPixel Gain Calibration %s - %s", (isForHLT_ ? "ForHLT" : "Offline"), TypeName[myType]),
648  Form("per %s %s", (isForHLT_ ? "Column" : "Pixel"), TypeName[myType]),
649  Form("# %ss", (isForHLT_ ? "column" : "pixel")),
650  200,
651  minimum,
652  maximum);
653 
654  path_toTopologyXML = f_phaseInfo.pathToTopoXML();
655 
656  auto f_tTopo =
658 
659  auto f_myPlots = PixelRegions::PixelRegionContainers(&f_tTopo, f_phaseInfo.phase());
660  f_myPlots.bookAll(
661  Form("First SiPixel Gain Calibration %s - %s", (isForHLT_ ? "ForHLT" : "Offline"), TypeName[myType]),
662  Form("per %s %s", (isForHLT_ ? "Column" : "Pixel"), TypeName[myType]),
663  Form("# %ss", (isForHLT_ ? "column" : "pixel")),
664  200,
665  minimum,
666  maximum);
667 
668  // fill the histograms
669  for (const auto& pixelId : PixelRegions::PixelIDs) {
670  auto f_wantedDets = PixelRegions::attachedDets(pixelId, &f_tTopo, f_phaseInfo.phase());
671  auto l_wantedDets = PixelRegions::attachedDets(pixelId, &l_tTopo, l_phaseInfo.phase());
672  gainCalibPI::fillTheHisto(first_payload, f_myPlots.getHistoFromMap(pixelId), myType, f_wantedDets);
673  gainCalibPI::fillTheHisto(last_payload, l_myPlots.getHistoFromMap(pixelId), myType, l_wantedDets);
674  }
675 
676  if (setLog) {
677  f_myPlots.setLogScale();
678  l_myPlots.setLogScale();
679  }
680 
681  l_myPlots.beautify(kRed, -1);
682  f_myPlots.beautify(kAzure, -1);
683 
684  l_myPlots.draw(canvas, isBarrel, "HIST", f_phaseInfo.isPhase1Comparison(l_phaseInfo));
685  f_myPlots.draw(canvas, isBarrel, "HISTsames", f_phaseInfo.isPhase1Comparison(l_phaseInfo));
686 
687  // rescale the y-axis ranges in order to fit the canvas
688  l_myPlots.rescaleMax(f_myPlots);
689 
690  // done dealing with IOVs
691  auto colorTag = isBarrel ? PixelRegions::L1 : PixelRegions::Rm1l;
692  std::unique_ptr<TLegend> legend;
693  if (this->m_plotAnnotations.ntags == 2) {
694  legend = std::make_unique<TLegend>(0.36, 0.86, 0.94, 0.92);
695  legend->AddEntry(l_myPlots.getHistoFromMap(colorTag).get(), ("#color[2]{" + l_tagname + "}").c_str(), "F");
696  legend->AddEntry(f_myPlots.getHistoFromMap(colorTag).get(), ("#color[4]{" + f_tagname + "}").c_str(), "F");
697  legend->SetTextSize(0.024);
698  } else {
699  legend = std::make_unique<TLegend>(0.58, 0.80, 0.90, 0.92);
700  legend->AddEntry(l_myPlots.getHistoFromMap(colorTag).get(), ("#color[2]{" + lastIOVsince + "}").c_str(), "F");
701  legend->AddEntry(f_myPlots.getHistoFromMap(colorTag).get(), ("#color[4]{" + firstIOVsince + "}").c_str(), "F");
702  legend->SetTextSize(0.040);
703  }
704  legend->SetLineColor(10);
705 
706  unsigned int maxPads = isBarrel ? 4 : 12;
707  for (unsigned int c = 1; c <= maxPads; c++) {
708  canvas.cd(c);
709  SiPixelPI::adjustCanvasMargins(canvas.cd(c), 0.06, 0.12, 0.12, 0.05);
710  legend->Draw("same");
711  canvas.cd(c)->Update();
712  }
713 
714  f_myPlots.stats(0);
715  l_myPlots.stats(1);
716 
717  auto ltx = TLatex();
718  ltx.SetTextFont(62);
719  ltx.SetTextSize(0.05);
720  ltx.SetTextAlign(11);
721 
722  for (unsigned int c = 1; c <= maxPads; c++) {
723  auto index = isBarrel ? c - 1 : c + 3;
724  canvas.cd(c);
725  auto leftX = setLog ? 0. : 0.1;
726  ltx.DrawLatexNDC(gPad->GetLeftMargin() + leftX,
727  1 - gPad->GetTopMargin() + 0.01,
728  (PixelRegions::IDlabels.at(index) + " : #color[4]{" + std::to_string(std::get<0>(firstiov)) +
729  "} vs #color[2]{" + std::to_string(std::get<0>(lastiov)) + "}")
730  .c_str());
731  }
732 
734  canvas.SaveAs(fileName.c_str());
735 
736  return true;
737  }
738 
739  protected:
740  bool isForHLT_;
742  };
743 
744  /*******************************************************************
745  1d histogram of SiPixelGainCalibration for Gain/Pedestals
746  correlation of 1 IOV
747  ********************************************************************/
748  template <class PayloadType>
750  : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
751  public:
753  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
754  "SiPixelGainCalibration gain/pedestal correlations") {
755  if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
756  isForHLT_ = false;
757  label_ = "SiPixelGainCalibrationOffline_PayloadInspector";
758  } else {
759  isForHLT_ = true;
760  label_ = "SiPixelGainCalibrationForHLT_PayloadInspector";
761  }
762  }
763 
764  bool fill() override {
765  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
766  auto iov = tag.iovs.front();
767 
768  gStyle->SetOptStat("emr");
769  gStyle->SetPalette(1);
770 
771  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
772 
773  TCanvas canvas("Canv", "Canv", 1400, 800);
774  canvas.Divide(2, 1);
775  canvas.cd();
776 
777  auto hBPix = std::make_shared<TH2F>("Correlation BPIX",
778  Form("SiPixel Gain Calibration %s BPIx;per %s gains;per %s pedestals",
779  (isForHLT_ ? "ForHLT" : "Offline"),
780  (isForHLT_ ? "column" : "pixel"),
781  (isForHLT_ ? "column" : "pixel")),
782  200,
783  payload->getGainLow(),
784  payload->getGainHigh(),
785  200,
786  payload->getPedLow(),
787  payload->getPedHigh());
788 
789  auto hFPix = std::make_shared<TH2F>("Correlation FPIX",
790  Form("SiPixel Gain Calibration %s FPix;per %s gains;per %s pedestals",
791  (isForHLT_ ? "ForHLT" : "Offline"),
792  (isForHLT_ ? "column" : "pixel"),
793  (isForHLT_ ? "column" : "pixel")),
794  200,
795  payload->getGainLow(),
796  payload->getGainHigh(),
797  200,
798  payload->getPedLow(),
799  payload->getPedHigh());
800 
801  for (unsigned int i : {1, 2}) {
802  SiPixelPI::adjustCanvasMargins(canvas.cd(i), 0.04, 0.12, 0.15, 0.13);
803  canvas.cd(i)->Modified();
804  }
805 
806  // actually fill the histograms
808 
809  canvas.cd(1)->SetLogz();
810  hBPix->SetTitle("");
811  hBPix->Draw("colz");
812 
813  SiPixelPI::makeNicePlotStyle(hBPix.get());
814  hBPix->GetYaxis()->SetTitleOffset(1.65);
815 
816  canvas.cd(2)->SetLogz();
817  hFPix->SetTitle("");
818  hFPix->Draw("colz");
819 
820  SiPixelPI::makeNicePlotStyle(hFPix.get());
821  hFPix->GetYaxis()->SetTitleOffset(1.65);
822  canvas.Update();
823 
824  TLegend legend = TLegend(0.3, 0.92, 0.70, 0.95);
825  legend.SetHeader(("Payload hash: #bf{" + (std::get<1>(iov)) + "}").c_str(),
826  "C"); // option "C" allows to center the header
827  legend.SetLineColor(10);
828  legend.SetTextSize(0.025);
829  canvas.cd(1);
830  legend.Draw("same");
831  canvas.cd(2);
832  legend.Draw("same");
833 
834  auto ltx = TLatex();
835  ltx.SetTextFont(62);
836  //ltx.SetTextColor(kBlue);
837  ltx.SetTextSize(0.045);
838  ltx.SetTextAlign(11);
839  canvas.cd(1);
840  ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
841  1 - gPad->GetTopMargin() + 0.01,
842  ("SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
843 
844  ltx.DrawLatexNDC(0.75, 0.15, "BPIX");
845 
846  canvas.cd(2);
847  ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
848  1 - gPad->GetTopMargin() + 0.01,
849  ("SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
850 
851  ltx.DrawLatexNDC(0.75, 0.15, "FPIX");
852 
854  canvas.SaveAs(fileName.c_str());
855 #ifdef MMDEBUG
856  canvas.SaveAs("out.root");
857 #endif
858  return true;
859  }
860 
861  protected:
862  bool isForHLT_;
864  };
865 
866  /*******************************************************************
867  1d histogram of SiPixelGainCalibration for Pedestals of 1 IOV
868  ********************************************************************/
869  template <gainCalibPI::type myType, class PayloadType>
871  : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
872  public:
874  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
875  Form("SiPixelGainCalibrationOffline %s Values By Partition", TypeName[myType])) {
876  if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
877  isForHLT_ = false;
878  label_ = "SiPixelGainCalibrationOffline_PayloadInspector";
879  } else {
880  isForHLT_ = true;
881  label_ = "SiPixelGainCalibrationForHLT_PayloadInspector";
882  }
883  }
884 
885  bool fill() override {
886  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
887  auto iov = tag.iovs.front();
888 
889  gStyle->SetOptStat("emr");
890 
891  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
892 
893  TCanvas canvas("Canv", "Canv", 1400, 800);
894  canvas.Divide(2, 1);
895  canvas.cd();
896 
897  float minimum(9999.);
898  float maximum(-9999.);
899 
900  switch (myType) {
901  case gainCalibPI::t_gain:
902  maximum = payload->getGainHigh();
903  minimum = payload->getGainLow();
904  break;
906  maximum = payload->getPedHigh();
907  minimum = payload->getPedLow();
908  break;
909  default:
910  edm::LogError(label_) << "Unrecognized type " << myType << std::endl;
911  break;
912  }
913 
914  auto hBPix = std::make_shared<TH1F>(Form("%s BPIX", TypeName[myType]),
915  Form("SiPixel Gain Calibration %s BPIx -%s;per %s %s (BPix);# %ss",
916  (isForHLT_ ? "ForHLT" : "Offline"),
917  TypeName[myType],
918  (isForHLT_ ? "Column" : "Pixel"),
919  TypeName[myType],
920  (isForHLT_ ? "column" : "pixel")),
921  200,
922  minimum,
923  maximum);
924 
925  auto hFPix = std::make_shared<TH1F>(Form("%s FPIX", TypeName[myType]),
926  Form("SiPixel Gain Calibration %s FPix -%s;per %s %s (FPix);# %ss",
927  (isForHLT_ ? "ForHLT" : "Offline"),
928  TypeName[myType],
929  (isForHLT_ ? "Column" : "Pixel"),
930  TypeName[myType],
931  (isForHLT_ ? "column" : "pixel")),
932  200,
933  minimum,
934  maximum);
935 
936  for (unsigned int i : {1, 2}) {
937  SiPixelPI::adjustCanvasMargins(canvas.cd(i), 0.04, 0.12, 0.12, 0.02);
938  canvas.cd(i)->Modified();
939  }
940 
941  // actually fill the histograms
942  fillTheHistos(payload, hBPix, hFPix, myType);
943 
944  canvas.cd(1)->SetLogy();
945  hBPix->SetTitle("");
946  hBPix->GetYaxis()->SetRangeUser(0.1, hBPix->GetMaximum() * 10);
947  hBPix->SetFillColor(kBlue);
948  hBPix->SetMarkerStyle(20);
949  hBPix->SetMarkerSize(1);
950  hBPix->Draw("hist");
951 
952  SiPixelPI::makeNicePlotStyle(hBPix.get());
953  hBPix->SetStats(true);
954 
955  canvas.cd(2)->SetLogy();
956  hFPix->SetTitle("");
957  hFPix->GetYaxis()->SetRangeUser(0.1, hFPix->GetMaximum() * 10);
958  hFPix->SetFillColor(kBlue);
959  hFPix->SetMarkerStyle(20);
960  hFPix->SetMarkerSize(1);
961  hFPix->Draw("hist");
962 
963  SiPixelPI::makeNicePlotStyle(hFPix.get());
964  hFPix->SetStats(true);
965 
966  canvas.Update();
967 
968  TLegend legend = TLegend(0.32, 0.92, 0.97, 0.95);
969  legend.SetHeader(("Payload hash: #bf{" + (std::get<1>(iov)) + "}").c_str(),
970  "C"); // option "C" allows to center the header
971  //legend.AddEntry(h1.get(), ("IOV: " + std::to_string(std::get<0>(iov))).c_str(), "PL");
972  legend.SetLineColor(10);
973  legend.SetTextSize(0.025);
974  canvas.cd(1);
975  legend.Draw("same");
976  canvas.cd(2);
977  legend.Draw("same");
978 
979  canvas.cd(1);
980  TPaveStats* st1 = (TPaveStats*)hBPix->FindObject("stats");
981  st1->SetTextSize(0.03);
982  SiPixelPI::adjustStats(st1, 0.13, 0.815, 0.44, 0.915);
983 
984  canvas.cd(2);
985  TPaveStats* st2 = (TPaveStats*)hFPix->FindObject("stats");
986  st2->SetTextSize(0.03);
987  SiPixelPI::adjustStats(st2, 0.14, 0.815, 0.44, 0.915);
988 
989  auto ltx = TLatex();
990  ltx.SetTextFont(62);
991  //ltx.SetTextColor(kBlue);
992  ltx.SetTextSize(0.045);
993  ltx.SetTextAlign(11);
994  canvas.cd(1);
995  ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
996  1 - gPad->GetTopMargin() + 0.01,
997  ("SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
998 
999  canvas.cd(2);
1000  ltx.DrawLatexNDC(gPad->GetLeftMargin() + 0.01,
1001  1 - gPad->GetTopMargin() + 0.01,
1002  ("SiPixel Gain Calibration IOV:" + std::to_string(std::get<0>(iov))).c_str());
1003 
1005  canvas.SaveAs(fileName.c_str());
1006 
1007  return true;
1008  }
1009 
1010  protected:
1013  };
1014 
1015  /************************************************
1016  1d histogram comparison of SiPixelGainCalibration
1017  *************************************************/
1018  template <gainCalibPI::type myType, class PayloadType>
1020  public:
1022  : cond::payloadInspector::PlotImage<PayloadType>(
1023  Form("SiPixelGainCalibration %s Values Comparison", TypeName[myType])) {
1024  if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1025  isForHLT_ = false;
1026  } else {
1027  isForHLT_ = true;
1028  }
1029  }
1030  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
1031  gStyle->SetOptStat("emr");
1032  TGaxis::SetExponentOffset(-0.1, 0.01, "y"); // Y offset
1033  TH1F::SetDefaultSumw2(true);
1034 
1035  std::vector<std::tuple<cond::Time_t, cond::Hash>> sorted_iovs = iovs;
1036  // make absolute sure the IOVs are sortd by since
1037  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const& t1, auto const& t2) {
1038  return std::get<0>(t1) < std::get<0>(t2);
1039  });
1040  auto firstiov = sorted_iovs.front();
1041  auto lastiov = sorted_iovs.back();
1042 
1043  std::shared_ptr<PayloadType> last_payload = this->fetchPayload(std::get<1>(lastiov));
1044  std::shared_ptr<PayloadType> first_payload = this->fetchPayload(std::get<1>(firstiov));
1045 
1046  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1047  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1048 
1049  float minimum(9999.);
1050  float maximum(-9999.);
1051 
1052  switch (myType) {
1053  case gainCalibPI::t_gain:
1054  maximum = std::max(last_payload->getGainHigh(), first_payload->getGainHigh());
1055  minimum = std::min(last_payload->getGainLow(), first_payload->getGainLow());
1056  break;
1058  maximum = std::max(last_payload->getPedHigh(), first_payload->getPedHigh());
1059  minimum = std::min(last_payload->getPedLow(), first_payload->getPedLow());
1060  break;
1061  default:
1062  edm::LogError(label_) << "Unrecognized type " << myType << std::endl;
1063  break;
1064  }
1065 
1066  TCanvas canvas("Canv", "Canv", 1200, 1000);
1067  canvas.cd();
1068  auto hfirst = std::make_shared<TH1F>(Form("First, IOV %s", firstIOVsince.c_str()),
1069  Form("SiPixel Gain Calibration %s - %s;per %s %s;# %ss",
1070  (isForHLT_ ? "ForHLT" : "Offline"),
1071  TypeName[myType],
1072  (isForHLT_ ? "Column" : "Pixel"),
1073  TypeName[myType],
1074  (isForHLT_ ? "column" : "pixel")),
1075  200,
1076  minimum,
1077  maximum);
1078 
1079  auto hlast = std::make_shared<TH1F>(Form("Last, IOV %s", lastIOVsince.c_str()),
1080  Form("SiPixel Gain Calibration %s - %s;per %s %s;# %ss",
1081  (isForHLT_ ? "ForHLT" : "Offline"),
1082  TypeName[myType],
1083  (isForHLT_ ? "Column" : "Pixel"),
1084  TypeName[myType],
1085  (isForHLT_ ? "column" : "pixel")),
1086  200,
1087  minimum,
1088  maximum);
1089 
1090  SiPixelPI::adjustCanvasMargins(canvas.cd(), 0.05, 0.12, 0.12, 0.03);
1091  canvas.Modified();
1092 
1093  gainCalibPI::fillTheHisto(first_payload, hfirst, myType);
1094  gainCalibPI::fillTheHisto(last_payload, hlast, myType);
1095 
1096  canvas.cd()->SetLogy();
1097  auto extrema = SiPixelPI::getExtrema(hfirst.get(), hlast.get());
1098  //hfirst->GetYaxis()->SetRangeUser(extrema.first, extrema.second * 1.10);
1099  hfirst->GetYaxis()->SetRangeUser(1., extrema.second * 10);
1100 
1101  hfirst->SetTitle("");
1102  hfirst->SetLineColor(kRed);
1103  hfirst->SetBarWidth(0.95);
1104  hfirst->Draw("hist");
1105 
1106  hlast->SetTitle("");
1107  hlast->SetFillColorAlpha(kBlue, 0.20);
1108  hlast->SetBarWidth(0.95);
1109  hlast->Draw("histsames");
1110 
1111  SiPixelPI::makeNicePlotStyle(hfirst.get());
1112  hfirst->SetStats(true);
1113  SiPixelPI::makeNicePlotStyle(hlast.get());
1114  hlast->SetStats(true);
1115 
1116  canvas.Update();
1117 
1118  TLegend legend = TLegend(0.45, 0.86, 0.74, 0.94);
1119  //legend.SetHeader("#font[22]{SiPixel Offline Gain Calibration Comparison}", "C"); // option "C" allows to center the header
1120  //legend.AddEntry(hfirst.get(), ("IOV: " + std::to_string(std::get<0>(firstiov))).c_str(), "FL");
1121  //legend.AddEntry(hlast.get(), ("IOV: " + std::to_string(std::get<0>(lastiov))).c_str(), "FL");
1122  legend.AddEntry(hfirst.get(), ("payload: #color[2]{" + std::get<1>(firstiov) + "}").c_str(), "F");
1123  legend.AddEntry(hlast.get(), ("payload: #color[4]{" + std::get<1>(lastiov) + "}").c_str(), "F");
1124  legend.SetTextSize(0.022);
1125  legend.SetLineColor(10);
1126  legend.Draw("same");
1127 
1128  TPaveStats* st1 = (TPaveStats*)hfirst->FindObject("stats");
1129  st1->SetTextSize(0.021);
1130  st1->SetLineColor(kRed);
1131  st1->SetTextColor(kRed);
1132  SiPixelPI::adjustStats(st1, 0.13, 0.86, 0.31, 0.94);
1133 
1134  TPaveStats* st2 = (TPaveStats*)hlast->FindObject("stats");
1135  st2->SetTextSize(0.021);
1136  st2->SetLineColor(kBlue);
1137  st2->SetTextColor(kBlue);
1138  SiPixelPI::adjustStats(st2, 0.13, 0.77, 0.31, 0.85);
1139 
1140  auto ltx = TLatex();
1141  ltx.SetTextFont(62);
1142  //ltx.SetTextColor(kBlue);
1143  ltx.SetTextSize(0.047);
1144  ltx.SetTextAlign(11);
1145  ltx.DrawLatexNDC(gPad->GetLeftMargin(),
1146  1 - gPad->GetTopMargin() + 0.01,
1147  ("SiPixel Gain Calibration IOV:#color[2]{" + std::to_string(std::get<0>(firstiov)) +
1148  "} vs IOV:#color[4]{" + std::to_string(std::get<0>(lastiov)) + "}")
1149  .c_str());
1150 
1152  canvas.SaveAs(fileName.c_str());
1153 #ifdef MMDEBUG
1154  canvas.SaveAs("out.root");
1155 #endif
1156 
1157  return true;
1158  }
1159 
1160  protected:
1163  };
1164 
1165  template <gainCalibPI::type myType, class PayloadType>
1167  : public SiPixelGainCalibrationValueComparisonBase<myType, PayloadType> {
1168  public:
1170  : SiPixelGainCalibrationValueComparisonBase<myType, PayloadType>() {
1171  this->setSingleIov(false);
1172  }
1173  };
1174 
1175  template <gainCalibPI::type myType, class PayloadType>
1177  : public SiPixelGainCalibrationValueComparisonBase<myType, PayloadType> {
1178  public:
1180  this->setTwoTags(true);
1181  }
1182  };
1183 
1184  /************************************************
1185  Diff and Ratio histograms of 2 IOVs
1186  *************************************************/
1187  template <gainCalibPI::type myType, cond::payloadInspector::IOVMultiplicity nIOVs, int ntags, class PayloadType>
1188  class SiPixelGainCalibDiffAndRatioBase : public cond::payloadInspector::PlotImage<PayloadType, nIOVs, ntags> {
1189  public:
1191  : cond::payloadInspector::PlotImage<PayloadType, nIOVs, ntags>(
1192  Form("SiPixelGainCalibration %s Diff and Ratio %i tag(s)", TypeName[myType], ntags)) {
1193  if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1194  isForHLT_ = false;
1195  } else {
1196  isForHLT_ = true;
1197  }
1198  }
1199 
1200  bool fill() override {
1201  gStyle->SetOptStat("emr");
1202  TGaxis::SetExponentOffset(-0.1, 0.01, "y"); // Y offset
1203  TH1F::SetDefaultSumw2(true);
1204 
1205  COUT << "ntags: " << ntags << " this->m_plotAnnotations.ntags: " << this->m_plotAnnotations.ntags << std::endl;
1206 
1207  // trick to deal with the multi-ioved tag and two tag case at the same time
1208  auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
1209  auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name;
1210  std::string l_tagname = "";
1211  auto firstiov = theIOVs.front();
1212  std::tuple<cond::Time_t, cond::Hash> lastiov;
1213 
1214  // we don't support (yet) comparison with more than 2 tags
1215  assert(this->m_plotAnnotations.ntags < 3);
1216 
1217  if (this->m_plotAnnotations.ntags == 2) {
1218  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
1219  l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name;
1220  lastiov = tag2iovs.front();
1221  } else {
1222  lastiov = theIOVs.back();
1223  }
1224 
1225  std::shared_ptr<PayloadType> last_payload = this->fetchPayload(std::get<1>(lastiov));
1226  std::shared_ptr<PayloadType> first_payload = this->fetchPayload(std::get<1>(firstiov));
1227 
1228  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1229  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1230 
1231  TCanvas canvas("Canv", "Canv", 1300, 800);
1232  canvas.Divide(2, 1);
1233  canvas.cd();
1234 
1235  SiPixelPI::adjustCanvasMargins(canvas.cd(1), 0.05, 0.12, 0.12, 0.04);
1236  SiPixelPI::adjustCanvasMargins(canvas.cd(2), 0.05, 0.12, 0.12, 0.04);
1237  canvas.Modified();
1238 
1239  auto array = gainCalibPI::fillDiffAndRatio(first_payload, last_payload, myType);
1240 
1241  array[0]->SetTitle(Form("SiPixel Gain Calibration %s - %s;per %s %s ratio;# %ss",
1242  (isForHLT_ ? "ForHLT" : "Offline"),
1243  TypeName[myType],
1244  (isForHLT_ ? "Column" : "Pixel"),
1245  TypeName[myType],
1246  (isForHLT_ ? "column" : "pixel")));
1247 
1248  array[1]->SetTitle(Form("SiPixel Gain Calibration %s - %s;per %s %s difference;# %ss",
1249  (isForHLT_ ? "ForHLT" : "Offline"),
1250  TypeName[myType],
1251  (isForHLT_ ? "Column" : "Pixel"),
1252  TypeName[myType],
1253  (isForHLT_ ? "column" : "pixel")));
1254 
1255  canvas.cd(1)->SetLogy();
1256  array[0]->SetTitle("");
1257  array[0]->SetLineColor(kBlack);
1258  array[0]->SetFillColor(kRed);
1259  array[0]->SetBarWidth(0.90);
1260  array[0]->SetMaximum(array[0]->GetMaximum() * 10);
1261  array[0]->Draw("bar");
1263  array[0]->SetStats(true);
1264 
1265  canvas.cd(2)->SetLogy();
1266  array[1]->SetTitle("");
1267  array[1]->SetLineColor(kBlack);
1268  array[1]->SetFillColor(kBlue);
1269  array[1]->SetBarWidth(0.90);
1270  array[1]->SetMaximum(array[1]->GetMaximum() * 10);
1271  array[1]->Draw("bar");
1273  array[1]->SetStats(true);
1274 
1275  canvas.Update();
1276 
1277  canvas.cd(1);
1278  TLatex latex;
1279  latex.SetTextSize(0.024);
1280  latex.SetTextAlign(13); //align at top
1281  latex.DrawLatexNDC(
1282  .41,
1283  .94,
1284  fmt::sprintf("#scale[1.2]{SiPixelGainCalibration%s Ratio}", (isForHLT_ ? "ForHLT" : "Offline")).c_str());
1285  if (this->m_plotAnnotations.ntags == 2) {
1286  latex.DrawLatexNDC(
1287  .41, .91, ("#splitline{#font[12]{" + f_tagname + "}}{ / #font[12]{" + l_tagname + "}}").c_str());
1288  } else {
1289  latex.DrawLatexNDC(.41, .91, (firstIOVsince + " / " + lastIOVsince).c_str());
1290  }
1291 
1292  canvas.cd(2);
1293  TLatex latex2;
1294  latex2.SetTextSize(0.024);
1295  latex2.SetTextAlign(13); //align at top
1296  latex2.DrawLatexNDC(
1297  .41,
1298  .94,
1299  fmt::sprintf("#scale[1.2]{SiPixelGainCalibration%s Diff}", (isForHLT_ ? "ForHLT" : "Offline")).c_str());
1300  if (this->m_plotAnnotations.ntags == 2) {
1301  latex2.DrawLatexNDC(
1302  .41, .91, ("#splitline{#font[12]{" + f_tagname + "}}{ - #font[12]{" + l_tagname + "}}").c_str());
1303  } else {
1304  latex2.DrawLatexNDC(.41, .91, (firstIOVsince + " - " + lastIOVsince).c_str());
1305  }
1306 
1307  TPaveStats* st1 = (TPaveStats*)array[0]->FindObject("stats");
1308  st1->SetTextSize(0.027);
1309  st1->SetLineColor(kRed);
1310  st1->SetTextColor(kRed);
1311  SiPixelPI::adjustStats(st1, 0.13, 0.84, 0.40, 0.94);
1312 
1313  TPaveStats* st2 = (TPaveStats*)array[1]->FindObject("stats");
1314  st2->SetTextSize(0.027);
1315  st2->SetLineColor(kBlue);
1316  st2->SetTextColor(kBlue);
1317  SiPixelPI::adjustStats(st2, 0.13, 0.84, 0.40, 0.94);
1318 
1319  auto ltx = TLatex();
1320  ltx.SetTextFont(62);
1321  //ltx.SetTextColor(kBlue);
1322  ltx.SetTextSize(0.040);
1323  ltx.SetTextAlign(11);
1324  canvas.cd(1);
1325  ltx.DrawLatexNDC(
1326  gPad->GetLeftMargin(),
1327  1 - gPad->GetTopMargin() + 0.01,
1328  fmt::sprintf("SiPixel %s Ratio, IOV %s / %s", TypeName[myType], firstIOVsince, lastIOVsince).c_str());
1329 
1330  canvas.cd(2);
1331  ltx.DrawLatexNDC(
1332  gPad->GetLeftMargin(),
1333  1 - gPad->GetTopMargin() + 0.01,
1334  fmt::sprintf("SiPixel %s Diff, IOV %s - %s", TypeName[myType], firstIOVsince, lastIOVsince).c_str());
1335 
1337  canvas.SaveAs(fileName.c_str());
1338 #ifdef MMDEBUG
1339  canvas.SaveAs("out.root");
1340 #endif
1341 
1342  return true;
1343  }
1344 
1345  protected:
1348  };
1349 
1350  // 2D MAPS
1351 
1352  /************************************************
1353  occupancy style map BPix
1354  *************************************************/
1355  template <gainCalibPI::type myType, class PayloadType, SiPixelPI::DetType myDetType>
1357  : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
1358  public:
1360  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
1361  Form("SiPixelGainCalibration %s Barrel Pixel Map", TypeName[myType])),
1363  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {
1364  if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1365  isForHLT_ = false;
1366  label_ = "SiPixelGainCalibrationOffline_PayloadInspector";
1367  } else {
1368  isForHLT_ = true;
1369  label_ = "SiPixelGainCalibrationForHLT_PayloadInspector";
1370  }
1371  };
1372 
1373  bool fill() override {
1374  TGaxis::SetMaxDigits(2);
1375 
1376  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
1377  auto tagname = tag.name;
1378  auto iov = tag.iovs.front();
1379 
1380  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
1381 
1383  fmt::sprintf("average per %s %s", isForHLT_ ? "column" : "pixel", gainCalibPI::t_titles[myType]);
1384  Phase1PixelROCMaps theGainsMap("", ztitle);
1385 
1386  std::map<uint32_t, float> GainCalibMap_;
1387  gainCalibPI::fillThePerModuleMap(payload, GainCalibMap_, myType);
1388  if (GainCalibMap_.size() != SiPixelPI::phase1size) {
1389  edm::LogError(label_) << "SiPixelGainCalibration maps are not supported for non-Phase1 Pixel geometries !";
1390  TCanvas canvas("Canv", "Canv", 1200, 1000);
1391  SiPixelPI::displayNotSupported(canvas, GainCalibMap_.size());
1393  canvas.SaveAs(fileName.c_str());
1394  return false;
1395  }
1396 
1397  // hard-coded phase-I
1398  std::array<double, n_layers> b_minima = {{999., 999., 999., 999.}};
1399  std::array<double, n_rings> f_minima = {{999., 999.}};
1400 
1401  for (const auto& element : GainCalibMap_) {
1402  int subid = DetId(element.first).subdetId();
1403  if (subid == PixelSubdetector::PixelBarrel) {
1404  auto layer = m_trackerTopo.pxbLayer(DetId(element.first));
1405  if (element.second < b_minima.at(layer - 1)) {
1406  b_minima.at(layer - 1) = element.second;
1407  }
1408  theGainsMap.fillWholeModule(element.first, element.second);
1409  } else if (subid == PixelSubdetector::PixelEndcap) {
1410  auto ring = SiPixelPI::ring(DetId(element.first), m_trackerTopo, true);
1411  if (element.second < f_minima.at(ring - 1)) {
1412  f_minima.at(ring - 1) = element.second;
1413  }
1414  theGainsMap.fillWholeModule(element.first, element.second);
1415  }
1416  }
1417 
1418  gStyle->SetOptStat(0);
1419  //=========================
1420  TCanvas canvas("Summary", "Summary", 1200, k_height[myDetType]);
1421  canvas.cd();
1422 
1423  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
1424 
1425  std::string IOVstring = (unpacked.first == 0)
1426  ? std::to_string(unpacked.second)
1427  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second));
1428 
1429  const auto headerText = fmt::sprintf("#color[4]{%s}, IOV: #color[4]{%s}", tagname, IOVstring);
1430 
1431  switch (myDetType) {
1432  case SiPixelPI::t_barrel:
1433  theGainsMap.drawBarrelMaps(canvas, headerText);
1434  break;
1435  case SiPixelPI::t_forward:
1436  theGainsMap.drawForwardMaps(canvas, headerText);
1437  break;
1438  case SiPixelPI::t_all:
1439  theGainsMap.drawMaps(canvas, headerText);
1440  break;
1441  default:
1442  throw cms::Exception("SiPixelGainCalibrationMap")
1443  << "\nERROR: unrecognized Pixel Detector part " << std::endl;
1444  }
1445 
1446  if (myDetType == SiPixelPI::t_barrel || myDetType == SiPixelPI::t_all) {
1447  for (unsigned int lay = 1; lay <= n_layers; lay++) {
1448  //SiPixelPI::adjustCanvasMargins(canvas.cd(lay), -1, 0.08, 0.1, 0.13);
1449 
1450  auto h_bpix_Gains = theGainsMap.getLayerMaps();
1451 
1452  COUT << " layer:" << lay << " max:" << h_bpix_Gains[lay - 1]->GetMaximum() << " min: " << b_minima.at(lay - 1)
1453  << std::endl;
1454 
1455  h_bpix_Gains[lay - 1]->GetZaxis()->SetRangeUser(b_minima.at(lay - 1) - 0.001,
1456  h_bpix_Gains[lay - 1]->GetMaximum() + 0.001);
1457  }
1458  }
1459 
1460  if (myDetType == SiPixelPI::t_forward || myDetType == SiPixelPI::t_all) {
1461  for (unsigned int ring = 1; ring <= n_rings; ring++) {
1462  //SiPixelPI::adjustCanvasMargins(canvas.cd(ring), -1, 0.08, 0.1, 0.13);
1463 
1464  auto h_fpix_Gains = theGainsMap.getRingMaps();
1465 
1466  COUT << " ring:" << ring << " max:" << h_fpix_Gains[ring - 1]->GetMaximum()
1467  << " min: " << f_minima.at(ring - 1) << std::endl;
1468 
1469  h_fpix_Gains[ring - 1]->GetZaxis()->SetRangeUser(f_minima.at(ring - 1) - 0.001,
1470  h_fpix_Gains[ring - 1]->GetMaximum() + 0.001);
1471  }
1472  }
1473 
1475  canvas.SaveAs(fileName.c_str());
1476 
1477  return true;
1478  }
1479 
1480  private:
1482  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
1483  static constexpr int n_layers = 4;
1484  static constexpr int n_rings = 2;
1485 
1486  protected:
1489  };
1490 
1491  /************************************************
1492  Summary Comparison per region of SiPixelGainCalibration between 2 IOVs
1493  *************************************************/
1494  template <gainCalibPI::type myType, class PayloadType, cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
1496  : public cond::payloadInspector::PlotImage<PayloadType, nIOVs, ntags> {
1497  public:
1499  : cond::payloadInspector::PlotImage<PayloadType, nIOVs, ntags>(
1500  Form("SiPixelGainCalibration %s Comparison by Region", TypeName[myType])) {
1501  if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationOffline>) {
1502  isForHLT_ = false;
1503  label_ = "SiPixelGainCalibrationOffline_PayloadInspector";
1504  } else {
1505  isForHLT_ = true;
1506  label_ = "SiPixelGainCalibrationForHLT_PayloadInspector";
1507  }
1508  }
1509 
1510  bool fill() override {
1511  gStyle->SetPaintTextFormat(".3f");
1512 
1513  // trick to deal with the multi-ioved tag and two tag case at the same time
1514  auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
1515  auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name;
1516  std::string l_tagname = "";
1517  auto firstiov = theIOVs.front();
1518  std::tuple<cond::Time_t, cond::Hash> lastiov;
1519 
1520  // we don't support (yet) comparison with more than 2 tags
1521  assert(this->m_plotAnnotations.ntags < 3);
1522 
1523  if (this->m_plotAnnotations.ntags == 2) {
1524  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
1525  l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name;
1526  lastiov = tag2iovs.front();
1527  } else {
1528  lastiov = theIOVs.back();
1529  }
1530 
1531  std::shared_ptr<PayloadType> last_payload = this->fetchPayload(std::get<1>(lastiov));
1532  std::shared_ptr<PayloadType> first_payload = this->fetchPayload(std::get<1>(firstiov));
1533 
1534  std::map<uint32_t, float> f_GainsMap_;
1535  gainCalibPI::fillThePerModuleMap(first_payload, f_GainsMap_, myType);
1536 
1537  std::map<uint32_t, float> l_GainsMap_;
1538  gainCalibPI::fillThePerModuleMap(last_payload, l_GainsMap_, myType);
1539 
1540  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1541  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1542 
1543  TCanvas canvas("Comparison", "Comparison", 1600, 800);
1544 
1545  SiPixelPI::PhaseInfo f_phaseInfo(f_GainsMap_.size());
1546  SiPixelPI::PhaseInfo l_phaseInfo(l_GainsMap_.size());
1547 
1548  std::map<SiPixelPI::regions, std::shared_ptr<TH1F>> FirstGains_spectraByRegion;
1549  std::map<SiPixelPI::regions, std::shared_ptr<TH1F>> LastGains_spectraByRegion;
1550  std::shared_ptr<TH1F> summaryFirst;
1551  std::shared_ptr<TH1F> summaryLast;
1552 
1553  float minimum(9999.);
1554  float maximum(-9999.);
1555 
1556  switch (myType) {
1557  case gainCalibPI::t_gain:
1558  maximum = std::max(last_payload->getGainHigh(), first_payload->getGainHigh());
1559  minimum = std::min(last_payload->getGainLow(), first_payload->getGainLow());
1560  break;
1562  maximum = std::max(last_payload->getPedHigh(), first_payload->getPedHigh());
1563  minimum = std::min(last_payload->getPedLow(), first_payload->getPedLow());
1564  break;
1565  default:
1566  edm::LogError(label_) << "Unrecognized type " << myType << std::endl;
1567  break;
1568  }
1569 
1570  // book the intermediate histograms
1571  for (int r = SiPixelPI::BPixL1o; r != SiPixelPI::NUM_OF_REGIONS; r++) {
1572  SiPixelPI::regions part = static_cast<SiPixelPI::regions>(r);
1574 
1575  FirstGains_spectraByRegion[part] =
1576  std::make_shared<TH1F>(Form("hfirstGains_%s", s_part.c_str()),
1577  Form(";%s #LT %s #GT;n. of modules", s_part.c_str(), TypeName[myType]),
1578  200,
1579  minimum,
1580  maximum);
1581 
1582  LastGains_spectraByRegion[part] =
1583  std::make_shared<TH1F>(Form("hlastGains_%s", s_part.c_str()),
1584  Form(";%s #LT %s #GT;n. of modules", s_part.c_str(), TypeName[myType]),
1585  200,
1586  minimum,
1587  maximum);
1588  }
1589 
1590  summaryFirst = std::make_shared<TH1F>("first Summary",
1591  Form("Summary of #LT per %s %s #GT;;average %s",
1592  (isForHLT_ ? "Column" : "Pixel"),
1593  TypeName[myType],
1594  TypeName[myType]),
1595  FirstGains_spectraByRegion.size(),
1596  0,
1597  FirstGains_spectraByRegion.size());
1598 
1599  summaryLast = std::make_shared<TH1F>("last Summary",
1600  Form("Summary of #LT per %s %s #GT;;average %s",
1601  (isForHLT_ ? "Column" : "Pixel"),
1602  TypeName[myType],
1603  TypeName[myType]),
1604  LastGains_spectraByRegion.size(),
1605  0,
1606  LastGains_spectraByRegion.size());
1607 
1608  // deal with first IOV
1609  const char* path_toTopologyXML = f_phaseInfo.pathToTopoXML();
1610 
1611  auto f_tTopo =
1613 
1614  // -------------------------------------------------------------------
1615  // loop on the first Gains Map
1616  // -------------------------------------------------------------------
1617  for (const auto& it : f_GainsMap_) {
1618  if (DetId(it.first).det() != DetId::Tracker) {
1619  edm::LogWarning(label_) << "Encountered invalid Tracker DetId:" << it.first << " - terminating ";
1620  return false;
1621  }
1622 
1623  SiPixelPI::topolInfo t_info_fromXML;
1624  t_info_fromXML.init();
1625  DetId detid(it.first);
1626  t_info_fromXML.fillGeometryInfo(detid, f_tTopo, f_phaseInfo.phase());
1627 
1628  SiPixelPI::regions thePart = t_info_fromXML.filterThePartition();
1629  FirstGains_spectraByRegion[thePart]->Fill(it.second);
1630  } // ends loop on the vector of error transforms
1631 
1632  // deal with last IOV
1633  path_toTopologyXML = l_phaseInfo.pathToTopoXML();
1634 
1635  auto l_tTopo =
1637 
1638  // -------------------------------------------------------------------
1639  // loop on the second Gains Map
1640  // -------------------------------------------------------------------
1641  for (const auto& it : l_GainsMap_) {
1642  if (DetId(it.first).det() != DetId::Tracker) {
1643  edm::LogWarning(label_) << "Encountered invalid Tracker DetId:" << it.first << " - terminating ";
1644  return false;
1645  }
1646 
1647  SiPixelPI::topolInfo t_info_fromXML;
1648  t_info_fromXML.init();
1649  DetId detid(it.first);
1650  t_info_fromXML.fillGeometryInfo(detid, l_tTopo, l_phaseInfo.phase());
1651 
1652  SiPixelPI::regions thePart = t_info_fromXML.filterThePartition();
1653  LastGains_spectraByRegion[thePart]->Fill(it.second);
1654  } // ends loop on the vector of error transforms
1655 
1656  // fill the summary plots
1657  int bin = 1;
1658  for (int r = SiPixelPI::BPixL1o; r != SiPixelPI::NUM_OF_REGIONS; r++) {
1659  SiPixelPI::regions part = static_cast<SiPixelPI::regions>(r);
1660 
1661  summaryFirst->GetXaxis()->SetBinLabel(bin, SiPixelPI::getStringFromRegionEnum(part).c_str());
1662  // avoid filling the histogram with numerical noise
1663  float f_mean =
1664  FirstGains_spectraByRegion[part]->GetMean() > 10.e-6 ? FirstGains_spectraByRegion[part]->GetMean() : 0.;
1665  summaryFirst->SetBinContent(bin, f_mean);
1666  //summaryFirst->SetBinError(bin,Gains_spectraByRegion[hash]->GetRMS());
1667 
1668  summaryLast->GetXaxis()->SetBinLabel(bin, SiPixelPI::getStringFromRegionEnum(part).c_str());
1669  // avoid filling the histogram with numerical noise
1670  float l_mean =
1671  LastGains_spectraByRegion[part]->GetMean() > 10.e-6 ? LastGains_spectraByRegion[part]->GetMean() : 0.;
1672  summaryLast->SetBinContent(bin, l_mean);
1673  //summaryLast->SetBinError(bin,Gains_spectraByRegion[hash]->GetRMS());
1674  bin++;
1675  }
1676 
1677  SiPixelPI::makeNicePlotStyle(summaryFirst.get()); //, kBlue);
1678  summaryFirst->SetMarkerColor(kRed);
1679  summaryFirst->GetXaxis()->LabelsOption("v");
1680  summaryFirst->GetXaxis()->SetLabelSize(0.05);
1681  summaryFirst->GetYaxis()->SetTitleOffset(0.9);
1682 
1683  SiPixelPI::makeNicePlotStyle(summaryLast.get()); //, kRed);
1684  summaryLast->SetMarkerColor(kBlue);
1685  summaryLast->GetYaxis()->SetTitleOffset(0.9);
1686  summaryLast->GetXaxis()->LabelsOption("v");
1687  summaryLast->GetXaxis()->SetLabelSize(0.05);
1688 
1689  canvas.cd()->SetGridy();
1690 
1691  SiPixelPI::adjustCanvasMargins(canvas.cd(), -1, 0.18, 0.11, 0.02);
1692  canvas.Modified();
1693 
1694  summaryFirst->SetFillColor(kRed);
1695  summaryLast->SetFillColor(kBlue);
1696 
1697  summaryFirst->SetBarWidth(0.45);
1698  summaryFirst->SetBarOffset(0.1);
1699 
1700  summaryLast->SetBarWidth(0.4);
1701  summaryLast->SetBarOffset(0.55);
1702 
1703  summaryLast->SetMarkerSize(1.2);
1704  summaryFirst->SetMarkerSize(1.2);
1705 
1706  float max = (summaryFirst->GetMaximum() > summaryLast->GetMaximum()) ? summaryFirst->GetMaximum()
1707  : summaryLast->GetMaximum();
1708 
1709  summaryFirst->GetYaxis()->SetRangeUser(0., std::max(0., max * 1.40));
1710 
1711  summaryFirst->Draw("b text0");
1712  summaryLast->Draw("b text0 same");
1713 
1714  TLegend legend = TLegend(0.52, 0.80, 0.98, 0.9);
1715  legend.SetHeader(Form("#LT %s #GT value comparison", TypeName[myType]),
1716  "C"); // option "C" allows to center the header
1717 
1718  legend.SetHeader("#mu_{H} value comparison", "C"); // option "C" allows to center the header
1719  std::string l_tagOrHash, f_tagOrHash;
1720  if (this->m_plotAnnotations.ntags == 2) {
1721  l_tagOrHash = l_tagname;
1722  f_tagOrHash = f_tagname;
1723  } else {
1724  l_tagOrHash = std::get<1>(lastiov);
1725  f_tagOrHash = std::get<1>(firstiov);
1726  }
1727 
1728  legend.AddEntry(
1729  summaryLast.get(),
1730  ("IOV: #scale[1.2]{" + std::to_string(std::get<0>(lastiov)) + "} | #color[4]{" + l_tagOrHash + "}").c_str(),
1731  "F");
1732  legend.AddEntry(
1733  summaryFirst.get(),
1734  ("IOV: #scale[1.2]{" + std::to_string(std::get<0>(firstiov)) + "} | #color[2]{" + f_tagOrHash + "}").c_str(),
1735  "F");
1736 
1737  legend.SetTextSize(0.025);
1738  legend.Draw("same");
1739 
1741  canvas.SaveAs(fileName.c_str());
1742  return true;
1743  }
1744 
1745  protected:
1748  };
1749 } // namespace gainCalibHelper
1750 
1751 #endif
static const std::array< std::string, 3 > t_titles
void drawMaps(TCanvas &canvas, const std::string &text="")
unsigned int pxbLayer(const DetId &id) const
static constexpr std::array< int, 3 > k_height
const std::vector< std::string > IDlabels
void fillGeometryInfo(const DetId &detId, const TrackerTopology &tTopo, const SiPixelPI::phase &ph)
void drawBarrelMaps(TCanvas &canvas, const std::string &text="")
Log< level::Error, false > LogError
std::pair< float, float > getExtrema(TH1 *h1, TH1 *h2)
assert(be >=bs)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
static std::array< std::shared_ptr< TH1F >, 2 > fillDiffAndRatio(const std::shared_ptr< PayloadType > &payload_A, const std::shared_ptr< PayloadType > &payload_B, const gainCalibPI::type &theType)
bool checkAnswerOK(std::string &answer, bool &result)
static std::string to_string(const XMLCh *ch)
void fillWholeModule(const uint32_t &detid, double value)
static void fillThePerModuleMap(const std::shared_ptr< PayloadType > &payload, AvgMap &map, gainCalibPI::type theType)
void drawForwardMaps(TCanvas &canvas, const std::string &text="")
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
std::array< std::shared_ptr< TH2D >, 4 > getLayerMaps()
static const unsigned int phase1size
SiPixelPI::regions filterThePartition()
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
constexpr char const * TypeName[2]
const std::vector< PixelId > PixelIDs
#define COUT
static void fillTheHisto(const std::shared_ptr< PayloadType > &payload, std::shared_ptr< TH1F > h1, gainCalibPI::type theType, const std::vector< uint32_t > &wantedIds={})
void adjustCanvasMargins(TVirtualPad *pad, float top, float bottom, float left, float right)
d
Definition: ztail.py:151
void adjustStats(TPaveStats *stats, float X1, float Y1, float X2, float Y2)
const std::map< std::string, std::string > & inputParamValues() const
void addInputParam(const std::string &paramName)
void bookAll(std::string title_label, std::string x_label, std::string y_label, const int nbins, const float xmin, const float xmax)
int ring(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Definition: DetId.h:17
void makeNicePlotStyle(TH1 *hist)
part
Definition: HCALResponse.h:20
float maxDiff(float one, float two, float three, float four)
void displayNotSupported(TCanvas &canv, const unsigned int size)
static void fillTheHistos(const std::shared_ptr< PayloadType > &payload, std::shared_ptr< TH1 > hBPix, std::shared_ptr< TH1 > hFPix, gainCalibPI::type theType)
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash >> &iovs) override
std::map< uint32_t, float > AvgMap
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
col
Definition: cuy.py:1009
def canvas(sub, attr)
Definition: svgfig.py:482
std::string getStringFromRegionEnum(SiPixelPI::regions e)
Log< level::Warning, false > LogWarning
std::array< std::shared_ptr< TH2D >, 2 > getRingMaps()
static const std::vector< uint32_t > attachedDets(const PixelRegions::PixelId theId, const TrackerTopology *trackTopo, const SiPixelPI::phase &ph)
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)