CMS 3D CMS Logo

SiPixelTemplateHelper.h
Go to the documentation of this file.
1 #ifndef CONDCORE_SIPIXELPLUGINS_SIPIXELTEMPLATEHELPER_H
2 #define CONDCORE_SIPIXELPLUGINS_SIPIXELTEMPLATEHELPER_H
3 
14 
15 #include <type_traits>
16 #include <memory>
17 #include <sstream>
18 #include <fmt/printf.h>
19 #include <boost/range/adaptor/indexed.hpp>
20 
21 // include ROOT
22 #include "TH2F.h"
23 #include "TH1F.h"
24 #include "TLegend.h"
25 #include "TCanvas.h"
26 #include "TLine.h"
27 #include "TStyle.h"
28 #include "TLatex.h"
29 #include "TPave.h"
30 #include "TPaveStats.h"
31 #include "TGaxis.h"
32 
33 namespace templateHelper {
34 
35  //************************************************
36  // Display of Template/GenError Titles
37  // *************************************************/
38  template <class PayloadType, class StoreType, class TransientType>
40  : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
41  public:
43  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
44  "Table of SiPixelTemplate/GenError titles") {
45  if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
46  isTemplate_ = false;
47  label_ = "SiPixelGenErrorDBObject_PayloadInspector";
48  } else {
49  isTemplate_ = true;
50  label_ = "SiPixelTemplateDBObject_PayloadInspector";
51  }
52  }
53 
54  bool fill() override {
55  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
56  auto iov = tag.iovs.front();
57  auto tagname = tag.name;
58  std::vector<StoreType> thePixelTemp_;
59  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
60 
61  std::string IOVsince = std::to_string(std::get<0>(iov));
62 
63  if (payload.get()) {
64  if (!TransientType::pushfile(*payload, thePixelTemp_)) {
65  throw cms::Exception(label_) << "\nERROR:" << (isTemplate_ ? "Templates" : "GenErrors")
66  << " not filled correctly."
67  << " Check the conditions. Using "
68  << (isTemplate_ ? "SiPixelTemplateDBObject" : "SiPixelGenErrorDBObject")
69  << " version " << payload->version() << "\n\n";
70  }
71 
72  unsigned int mapsize = thePixelTemp_.size();
73  float pitch = 1. / (mapsize * 1.1);
74 
75  float y, x1, x2;
76  std::vector<float> y_x1, y_x2, y_line;
77  std::vector<std::string> s_x1, s_x2, s_x3;
78 
79  // starting table at y=1.0 (top of the canvas)
80  // first column is at 0.02, second column at 0.32 NDC
81  y = 1.0;
82  x1 = 0.02;
83  x2 = x1 + 0.30;
84 
85  y -= pitch;
86  y_x1.push_back(y);
87  s_x1.push_back(Form("#scale[1.2]{%s}", (isTemplate_ ? "Template ID" : "GenError ID")));
88  y_x2.push_back(y);
89  s_x2.push_back(Form("#scale[1.2]{#color[4]{%s} in IOV: #color[4]{%s}}", tagname.c_str(), IOVsince.c_str()));
90 
91  y -= pitch / 2.;
92  y_line.push_back(y);
93 
94  for (const auto& element : thePixelTemp_) {
95  y -= pitch;
96  y_x1.push_back(y);
97  s_x1.push_back(std::to_string(element.head.ID));
98 
99  y_x2.push_back(y);
100  s_x2.push_back(Form("#color[2]{%s}", element.head.title));
101 
102  y_line.push_back(y - (pitch / 2.));
103  }
104 
105  const auto& c_title = fmt::sprintf("%s titles", (isTemplate_ ? "Template" : "GenError"));
106  TCanvas canvas(c_title.c_str(), c_title.c_str(), 2000, std::max(y_x1.size(), y_x2.size()) * 40);
107  TLatex l;
108  // Draw the columns titles
109  l.SetTextAlign(12);
110 
111  float newpitch = 1 / (std::max(y_x1.size(), y_x2.size()) * 1.1);
112  float factor = newpitch / pitch;
113  l.SetTextSize(newpitch - 0.002);
114  canvas.cd();
115  for (unsigned int i = 0; i < y_x1.size(); i++) {
116  l.DrawLatexNDC(x1, 1 - (1 - y_x1[i]) * factor, s_x1[i].c_str());
117  }
118 
119  for (unsigned int i = 0; i < y_x2.size(); i++) {
120  l.DrawLatexNDC(x2, 1 - (1 - y_x2[i]) * factor, s_x2[i].c_str());
121  }
122 
123  canvas.cd();
124  canvas.Update();
125 
126  TLine lines[y_line.size()];
127  unsigned int iL = 0;
128  for (const auto& line : y_line) {
129  lines[iL] = TLine(gPad->GetUxmin(), 1 - (1 - line) * factor, gPad->GetUxmax(), 1 - (1 - line) * factor);
130  lines[iL].SetLineWidth(1);
131  lines[iL].SetLineStyle(9);
132  lines[iL].SetLineColor(2);
133  lines[iL].Draw("same");
134  iL++;
135  }
136 
138  canvas.SaveAs(fileName.c_str());
139 
140  } // if payload.get()
141  return true;
142  }
143 
144  protected:
147  };
148 
149  /************************************************
150  // header plotting
151  *************************************************/
152  template <class PayloadType, class StoreType, class TransientType>
153  class SiPixelHeaderTable : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
154  public:
156  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
157  "SiPixel CPE Conditions Header summary") {
158  if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
159  isTemplate_ = false;
160  label_ = "SiPixelGenErrorDBObject_PayloadInspector";
161  } else {
162  isTemplate_ = true;
163  label_ = "SiPixelTemplateDBObject_PayloadInspector";
164  }
165  }
166 
167  bool fill() override {
168  gStyle->SetHistMinimumZero(); // will display zero as zero in the text map
169  gStyle->SetPalette(kMint); // for the ghost plot (colored BPix and FPix bins)
170 
171  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
172  auto iov = tag.iovs.front();
173  auto tagname = tag.name;
174  std::vector<StoreType> thePixelTemp_;
175  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
176 
177  if (payload.get()) {
178  if (!TransientType::pushfile(*payload, thePixelTemp_)) {
179  throw cms::Exception(label_) << "\nERROR:" << (isTemplate_ ? "Templates" : "GenErrors")
180  << " not filled correctly."
181  << " Check the conditions. Using "
182  << (isTemplate_ ? "SiPixelTemplateDBObject" : "SiPixelGenErrorDBObject")
183  << payload->version() << "\n\n";
184  }
185 
186  // store the map of ID / interesting quantities
187  TransientType templ(thePixelTemp_);
188  TCanvas canvas("Header Summary", "Header summary", 1400, 1000);
189  canvas.cd();
190 
191  unsigned int tempSize = thePixelTemp_.size();
192 
193  canvas.SetTopMargin(0.07);
194  canvas.SetBottomMargin(0.06);
195  canvas.SetLeftMargin(0.17);
196  canvas.SetRightMargin(0.03);
197  canvas.Modified();
198  canvas.SetGrid();
199 
200  auto h2_Header = std::make_unique<TH2F>("Header", ";;", tempSize, 0, tempSize, 12, 0., 12.);
201  auto h2_ghost = std::make_unique<TH2F>("ghost", ";;", tempSize, 0, tempSize, 12, 0., 12.);
202  h2_Header->SetStats(false);
203  h2_ghost->SetStats(false);
204 
205  int tempVersion = -999;
206 
207  for (const auto& theTemp : thePixelTemp_ | boost::adaptors::indexed(1)) {
208  auto tempValue = theTemp.value();
209  auto idx = theTemp.index();
210  float uH = -99.;
211  if (tempValue.head.Bfield != 0.) {
212  uH = roundoff(tempValue.head.lorxwidth / tempValue.head.zsize / tempValue.head.Bfield, 4);
213  }
214 
215  // clang-format off
216  h2_Header->SetBinContent(idx, 12, tempValue.head.ID);
217  h2_Header->SetBinContent(idx, 11, tempValue.head.Bfield);
218  h2_Header->SetBinContent(idx, 10, uH);
219  h2_Header->SetBinContent(idx, 9, tempValue.head.xsize);
220  h2_Header->SetBinContent(idx, 8, tempValue.head.ysize);
221  h2_Header->SetBinContent(idx, 7, tempValue.head.zsize);
222  h2_Header->SetBinContent(idx, 6, tempValue.head.NTy);
223  h2_Header->SetBinContent(idx, 5, tempValue.head.NTyx);
224  h2_Header->SetBinContent(idx, 4, tempValue.head.NTxx);
225  h2_Header->SetBinContent(idx, 3, tempValue.head.Dtype);
226  h2_Header->SetBinContent(idx, 2, tempValue.head.qscale);
227  h2_Header->SetBinContent(idx, 1, tempValue.head.Vbias);
228  // clang-format on
229 
230  h2_Header->GetYaxis()->SetBinLabel(12, (isTemplate_ ? "TemplateID" : "GenErrorID"));
231  h2_Header->GetYaxis()->SetBinLabel(11, "B-field [T]");
232  h2_Header->GetYaxis()->SetBinLabel(10, "#mu_{H} [1/T]");
233  h2_Header->GetYaxis()->SetBinLabel(9, "x-size [#mum]");
234  h2_Header->GetYaxis()->SetBinLabel(8, "y-size [#mum]");
235  h2_Header->GetYaxis()->SetBinLabel(7, "z-size [#mum]");
236  h2_Header->GetYaxis()->SetBinLabel(6, "NTy");
237  h2_Header->GetYaxis()->SetBinLabel(5, "NTyx");
238  h2_Header->GetYaxis()->SetBinLabel(4, "NTxx");
239  h2_Header->GetYaxis()->SetBinLabel(3, "DetectorType");
240  h2_Header->GetYaxis()->SetBinLabel(2, "qScale");
241  h2_Header->GetYaxis()->SetBinLabel(1, "VBias [V]");
242  h2_Header->GetXaxis()->SetBinLabel(idx, "");
243 
244  for (unsigned int iy = 1; iy <= 12; iy++) {
245  // Some of the Phase-2 templates have DType = 0 for all partitions (TBPX, TEPX, TFPX)
246  // so they are distinguished by the uH strength value (<0).
247  // To avoid changing the behaviour of 0T payload (uH=-99) that case is treated separately
248  if (tempValue.head.Dtype != 0 || (uH < 0 && uH > -99)) {
249  h2_ghost->SetBinContent(idx, iy, 1);
250  } else {
251  h2_ghost->SetBinContent(idx, iy, -1);
252  }
253  h2_ghost->GetYaxis()->SetBinLabel(iy, h2_Header->GetYaxis()->GetBinLabel(iy));
254  h2_ghost->GetXaxis()->SetBinLabel(idx, "");
255  }
256 
257  if (tempValue.head.templ_version != tempVersion) {
258  tempVersion = tempValue.head.templ_version;
259  }
260  }
261 
262  h2_Header->GetXaxis()->LabelsOption("h");
263  h2_Header->GetXaxis()->SetNdivisions(500 + tempSize, false);
264  h2_Header->GetYaxis()->SetLabelSize(0.05);
265  h2_Header->SetMarkerSize(1.5);
266 
267  h2_ghost->GetXaxis()->LabelsOption("h");
268  h2_ghost->GetXaxis()->SetNdivisions(500 + tempSize, false);
269  h2_ghost->GetYaxis()->SetLabelSize(0.05);
270 
271  canvas.cd();
272  h2_ghost->Draw("col");
273  h2_Header->Draw("TEXTsame");
274 
275  TPaveText ksPt(0, 0, 0.88, 0.04, "NDC");
276  ksPt.SetBorderSize(0);
277  ksPt.SetFillColor(0);
278  const char* textToAdd = Form("%s Version: #color[2]{%i}. Payload hash: #color[2]{%s}",
279  (isTemplate_ ? "Template" : "GenError"),
280  tempVersion,
281  (std::get<1>(iov)).c_str());
282  ksPt.AddText(textToAdd);
283  ksPt.Draw();
284 
285  auto ltx = TLatex();
286  ltx.SetTextFont(62);
287  ltx.SetTextSize(0.040);
288  ltx.SetTextAlign(11);
289  ltx.DrawLatexNDC(
290  gPad->GetLeftMargin(),
291  1 - gPad->GetTopMargin() + 0.01,
292  ("#color[4]{" + tagname + "}, IOV: #color[4]{" + std::to_string(std::get<0>(iov)) + "}").c_str());
293 
295  canvas.SaveAs(fileName.c_str());
296  }
297  return true;
298  }
299 
300  float roundoff(float value, unsigned char prec) {
301  float pow_10 = pow(10.0f, (float)prec);
302  return round(value * pow_10) / pow_10;
303  }
304 
305  protected:
308  };
309 
310  //***********************************************
311  // TH2Poly Map of IDs
312  //***********************************************/
313  template <class PayloadType, SiPixelPI::DetType myType>
314  class SiPixelIDs : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
315  public:
317  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
318  "SiPixelMap of Template / GenError ID Values") {
319  if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
320  isTemplate_ = false;
321  label_ = "SiPixelGenErrorDBObject_PayloadInspector";
322  } else {
323  isTemplate_ = true;
324  label_ = "SiPixelTemplateDBObject_PayloadInspector";
325  }
326  }
327 
328  bool fill() override {
329  gStyle->SetPalette(kRainBow);
330 
331  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
332  auto iov = tag.iovs.front();
333  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
334 
335  std::string barrelName_ = fmt::sprintf("%sIDsBarrel", (isTemplate_ ? "template" : "genError"));
336  std::string endcapName_ = fmt::sprintf("%sIDsForward", (isTemplate_ ? "template" : "genError"));
337  std::string title_ = fmt::sprintf("%s IDs", (isTemplate_ ? "template" : "genError"));
338 
339  if (payload.get()) {
340  // Book the TH2Poly
341  Phase1PixelMaps theMaps("text");
342  if (myType == SiPixelPI::t_barrel) {
343  // book the barrel bins of the TH2Poly
344  theMaps.bookBarrelHistograms(barrelName_, title_.c_str(), title_.c_str());
345  } else if (myType == SiPixelPI::t_forward) {
346  // book the forward bins of the TH2Poly
347  theMaps.bookForwardHistograms(endcapName_, title_.c_str(), title_.c_str());
348  }
349 
350  std::map<unsigned int, short> templMap;
351  if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
352  templMap = payload->getGenErrorIDs();
353  } else {
354  templMap = payload->getTemplateIDs();
355  }
356 
357  if (templMap.size() == SiPixelPI::phase0size || templMap.size() > SiPixelPI::phase1size) {
359  << "There are " << templMap.size()
360  << " DetIds in this payload. SiPixelIDs maps are not supported for non-Phase1 Pixel geometries !";
361  TCanvas canvas("Canv", "Canv", 1200, 1000);
362  SiPixelPI::displayNotSupported(canvas, templMap.size());
364  canvas.SaveAs(fileName.c_str());
365  return false;
366  } else {
367  if (templMap.size() < SiPixelPI::phase1size) {
368  edm::LogWarning(label_) << "\n ********* WARNING! ********* \n There are " << templMap.size()
369  << " DetIds in this payload !"
370  << "\n **************************** \n";
371  }
372  }
373 
374  /*
375  std::vector<unsigned int> detids;
376  std::transform(templMap.begin(),
377  templMap.end(),
378  std::back_inserter(detids),
379  [](const std::map<unsigned int, short>::value_type& pair) { return pair.first; });
380  */
381 
382  for (auto const& entry : templMap) {
383  COUT << "DetID: " << entry.first << fmt::sprintf("%s ID ", (isTemplate_ ? "Template" : "GenError"))
384  << entry.second << std::endl;
385  auto detid = DetId(entry.first);
386  if ((detid.subdetId() == PixelSubdetector::PixelBarrel) && (myType == SiPixelPI::t_barrel)) {
387  theMaps.fillBarrelBin(barrelName_, entry.first, entry.second);
388  } else if ((detid.subdetId() == PixelSubdetector::PixelEndcap) && (myType == SiPixelPI::t_forward)) {
389  theMaps.fillForwardBin(endcapName_, entry.first, entry.second);
390  }
391  }
392 
393  theMaps.beautifyAllHistograms();
394 
395  TCanvas canvas("Canv", "Canv", (myType == SiPixelPI::t_barrel) ? 1200 : 1500, 1000);
396  if (myType == SiPixelPI::t_barrel) {
397  theMaps.drawBarrelMaps(barrelName_, canvas);
398  } else if (myType == SiPixelPI::t_forward) {
399  theMaps.drawForwardMaps(endcapName_, canvas);
400  }
401 
402  canvas.cd();
403 
405  canvas.SaveAs(fileName.c_str());
406  }
407  return true;
408  }
409 
410  protected:
413  };
414 
415  /************************************************
416  Full Pixel Tracker Map class
417  *************************************************/
418  template <class PayloadType, class StoreType, class TransientType>
420  : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
421  public:
423  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
424  "SiPixel CPE conditions Map of IDs") {
425  if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
426  isTemplate_ = false;
427  label_ = "SiPixelGenErrorDBObject_PayloadInspector";
428  } else {
429  isTemplate_ = true;
430  label_ = "SiPixelTemplateDBObject_PayloadInspector";
431  }
432  }
433 
434  bool fill() override {
435  gStyle->SetPalette(1);
436  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
437  auto iov = tag.iovs.front();
438  std::vector<StoreType> thePixelTemp_;
439  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
440 
441  std::string payloadString = (isTemplate_ ? "Templates" : "GenErrors");
442 
443  if (payload.get()) {
444  if (!TransientType::pushfile(*payload, thePixelTemp_)) {
445  throw cms::Exception(label_) << "\nERROR: " << payloadString
446  << " not filled correctly. Check the conditions. Using "
447  << (isTemplate_ ? "SiPixelTemplateDBObject" : "SiPixelGenErrorDBObject")
448  << payload->version() << "\n\n";
449  }
450 
451  Phase1PixelSummaryMap fullMap("", fmt::sprintf("%s IDs", payloadString), fmt::sprintf("%s ID", payloadString));
452  fullMap.createTrackerBaseMap();
453 
454  std::map<unsigned int, short> templMap;
455  if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
456  templMap = payload->getGenErrorIDs();
457  } else {
458  templMap = payload->getTemplateIDs();
459  }
460 
461  for (const auto& entry : templMap) {
462  fullMap.fillTrackerMap(entry.first, entry.second);
463  }
464 
465  if (templMap.size() == SiPixelPI::phase0size || templMap.size() > SiPixelPI::phase1size) {
467  << "There are " << templMap.size()
468  << " DetIds in this payload. SiPixelIDs maps are not supported for non-Phase1 Pixel geometries !";
469  TCanvas canvas("Canv", "Canv", 1200, 1000);
470  SiPixelPI::displayNotSupported(canvas, templMap.size());
472  canvas.SaveAs(fileName.c_str());
473  return false;
474  } else {
475  if (templMap.size() < SiPixelPI::phase1size) {
476  edm::LogWarning(label_) << "\n ********* WARNING! ********* \n There are " << templMap.size()
477  << " DetIds in this payload !"
478  << "\n **************************** \n";
479  }
480  }
481 
482  TCanvas canvas("Canv", "Canv", 3000, 2000);
483  fullMap.printTrackerMap(canvas);
484 
485  //fmt::sprintf("#color[2]{%s, IOV %i}",tag.name,std::get<0>(iov));
486 
487  auto ltx = TLatex();
488  ltx.SetTextFont(62);
489  ltx.SetTextSize(0.025);
490  ltx.SetTextAlign(11);
491  ltx.DrawLatexNDC(
492  gPad->GetLeftMargin() + 0.01,
493  gPad->GetBottomMargin() + 0.01,
494  ("#color[4]{" + tag.name + "}, IOV: #color[4]{" + std::to_string(std::get<0>(iov)) + "}").c_str());
495 
497  canvas.SaveAs(fileName.c_str());
498  }
499  return true;
500  }
501 
502  protected:
505  };
506 
507  enum headerParam {
508  k_ID = 0,
509  k_NTy = 1,
510  k_NTyx = 2,
511  k_NTxx = 3,
512  k_Dtype = 4,
513  k_qscale = 5,
518  k_Vbias = 10,
520  k_fluence = 12,
521  k_s50 = 13,
522  k_ss50 = 14,
523  k_title = 15,
525  k_Bfield = 17,
526  k_fbin = 18,
528  };
529 
530  static constexpr const char* header_types[] = {"ID;templated ID",
531  "NTy;number of template y entries",
532  "NTyx;number of template y-slices of x entries",
533  "NTxx;number of template x-entries in each slice",
534  "Dtype;detector type (0=BPix, 1=FPix)",
535  "qScale;charge scaling correction",
536  "lorxwidth;estimate of the y-Lorentz width",
537  "lorywidth;estimate of the x-Lorentz width",
538  "lorybias;estimate of the y-Lorentz bias",
539  "lorxbias;estimate of the x-Lorentz bias",
540  "Vbias;detector bias [V]",
541  "temperature;detector temperature [K]",
542  "fluence;radiation fluence [n_{eq}/cm^{2}] ",
543  "s50;1/2 of the multihit dcol threshold [e]",
544  "ss50;1/2 of the single hit dcol threshold [e]",
545  "title;title",
546  "template version;template version number",
547  "B-field;B-field [T]",
548  "fbin;Qbin in Q_{clus}/Q_{avg}",
549  "NOT HERE;NOT HERE"};
550 
551  // class to display values of the template header information in a Phase1 Pixel Map
552  template <class PayloadType, class StoreType, class TransientType, SiPixelPI::DetType myType, headerParam myParam>
554  : public cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV> {
555  struct header_info {
556  int ID;
557  int NTy;
558  int NTyx;
559  int NTxx;
560  int Dtype;
561  float qscale;
562  float lorywidth;
563  float lorxwidth;
564  float lorybias;
565  float lorxbias;
566  float Vbias;
567  float temperature;
568  float fluence;
569  float s50;
570  float ss50;
571  char title[80];
573  float Bfield;
574  float fbin[3];
575  };
576 
577  public:
579  : cond::payloadInspector::PlotImage<PayloadType, cond::payloadInspector::SINGLE_IOV>(
580  "SiPixel CPE conditions Map of header quantities") {
581  if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
582  isTemplate_ = false;
583  label_ = "SiPixelGenErrorDBObject_PayloadInspector";
584  } else {
585  isTemplate_ = true;
586  label_ = "SiPixelTemplateDBObject_PayloadInspector";
587  }
588  }
589 
590  bool fill() override {
591  gStyle->SetPalette(kRainBow);
592  if (!(myParam == headerParam::k_Vbias || myParam == headerParam::k_Dtype)) {
593  TGaxis::SetMaxDigits(2);
594  }
595 
596  auto tag = cond::payloadInspector::PlotBase::getTag<0>();
597  auto iov = tag.iovs.front();
598  const auto& tagname = tag.name;
599  std::vector<StoreType> thePixelTemp_;
600  std::shared_ptr<PayloadType> payload = this->fetchPayload(std::get<1>(iov));
601 
602  if (payload.get()) {
603  if (!TransientType::pushfile(*payload, thePixelTemp_)) {
604  throw cms::Exception(label_) << "\nERROR: Templates not filled correctly. Check the conditions. Using "
605  "payload version "
606  << payload->version() << "\n\n";
607  }
608 
609  // store the map of ID / interesting quantities
610  SiPixelTemplate templ(thePixelTemp_);
611  for (const auto& theTemp : thePixelTemp_) {
613  info.ID = theTemp.head.ID;
614  info.NTy = theTemp.head.NTy;
615  info.NTyx = theTemp.head.NTyx;
616  info.NTxx = theTemp.head.NTxx;
617  info.Dtype = theTemp.head.Dtype;
618  info.qscale = theTemp.head.qscale;
619  info.lorywidth = theTemp.head.lorywidth;
620  info.lorxwidth = theTemp.head.lorxwidth;
621  info.lorybias = theTemp.head.lorybias;
622  info.lorxbias = theTemp.head.lorxbias;
623  info.Vbias = theTemp.head.Vbias;
624  info.temperature = theTemp.head.temperature;
625  info.fluence = theTemp.head.fluence;
626  info.s50 = theTemp.head.s50;
627  info.ss50 = theTemp.head.ss50;
628  info.templ_version = theTemp.head.templ_version;
629  info.Bfield = theTemp.head.Bfield;
630  theInfos_[theTemp.head.ID] = info;
631  }
632 
633  // Book the TH2Poly
634  Phase1PixelMaps theMaps("");
635  if (myType == SiPixelPI::t_all) {
636  theMaps.resetOption("COLZA L");
637  } else {
638  theMaps.resetOption("COLZL");
639  }
640 
641  std::string input{header_types[myParam]};
642  std::string delimiter = ";";
643  std::string first = input.substr(0, input.find(delimiter));
644  std::string second = input.substr(input.find(delimiter) + 1);
645 
646  if (myType == SiPixelPI::t_barrel) {
647  theMaps.bookBarrelHistograms("templateLABarrel", first.c_str(), second.c_str());
648  } else if (myType == SiPixelPI::t_forward) {
649  theMaps.bookForwardHistograms("templateLAForward", first.c_str(), second.c_str());
650  } else if (myType == SiPixelPI::t_all) {
651  theMaps.bookBarrelHistograms("templateLA", first.c_str(), second.c_str());
652  theMaps.bookForwardHistograms("templateLA", first.c_str(), second.c_str());
653  } else {
654  edm::LogError(label_) << " un-recognized detector type " << myType << std::endl;
655  return false;
656  }
657 
658  std::map<unsigned int, short> templMap = payload->getTemplateIDs();
659  if (templMap.size() == SiPixelPI::phase0size || templMap.size() > SiPixelPI::phase1size) {
661  << "There are " << templMap.size()
662  << " DetIds in this payload. SiPixelTempate Lorentz Angle maps are not supported for non-Phase1 Pixel "
663  "geometries !";
664  TCanvas canvas("Canv", "Canv", 1200, 1000);
665  SiPixelPI::displayNotSupported(canvas, templMap.size());
667  canvas.SaveAs(fileName.c_str());
668  return false;
669  } else {
670  if (templMap.size() < SiPixelPI::phase1size) {
671  edm::LogWarning(label_) << "\n ********* WARNING! ********* \n There are " << templMap.size()
672  << " DetIds in this payload !"
673  << "\n **************************** \n";
674  }
675  }
676 
677  for (auto const& entry : templMap) {
678  //templ.interpolate(entry.second, 0.f, 0.f, 1.f, 1.f);
679 
680  const auto& theInfo = theInfos_[entry.second];
681 
682  std::function<float(headerParam, header_info)> cutFunctor = [](headerParam my_param, header_info myInfo) {
683  float ret(-999.);
684  switch (my_param) {
685  case k_ID:
686  return (float)myInfo.ID;
687  case k_NTy:
688  return (float)myInfo.NTy;
689  case k_NTyx:
690  return (float)myInfo.NTyx;
691  case k_NTxx:
692  return (float)myInfo.NTxx;
693  case k_Dtype:
694  return (float)myInfo.Dtype;
695  case k_qscale:
696  return (float)myInfo.qscale;
697  case k_lorywidth:
698  return (float)myInfo.lorywidth;
699  case k_lorxwidth:
700  return (float)myInfo.lorxwidth;
701  case k_lorybias:
702  return (float)myInfo.lorybias;
703  case k_lorxbias:
704  return (float)myInfo.lorxbias;
705  case k_Vbias:
706  return (float)myInfo.Vbias;
707  case k_temperature:
708  return (float)myInfo.temperature;
709  case k_fluence:
710  return (float)myInfo.fluence;
711  case k_s50:
712  return (float)myInfo.s50;
713  case k_ss50:
714  return (float)myInfo.ss50;
715  case k_title:
716  return (float)myInfo.templ_version;
717  case k_Bfield:
718  return (float)myInfo.Bfield;
719  case k_END_OF_TYPES:
720  return ret;
721  default:
722  return ret;
723  }
724  };
725 
726  auto detid = DetId(entry.first);
727  if (myType == SiPixelPI::t_all) {
728  if ((detid.subdetId() == PixelSubdetector::PixelBarrel)) {
729  theMaps.fillBarrelBin("templateLA", entry.first, cutFunctor(myParam, theInfo));
730  }
731  if ((detid.subdetId() == PixelSubdetector::PixelEndcap)) {
732  theMaps.fillForwardBin("templateLA", entry.first, cutFunctor(myParam, theInfo));
733  }
734  } else if ((detid.subdetId() == PixelSubdetector::PixelBarrel) && (myType == SiPixelPI::t_barrel)) {
735  theMaps.fillBarrelBin("templateLABarrel", entry.first, cutFunctor(myParam, theInfo));
736  } else if ((detid.subdetId() == PixelSubdetector::PixelEndcap) && (myType == SiPixelPI::t_forward)) {
737  theMaps.fillForwardBin("templateLAForward", entry.first, cutFunctor(myParam, theInfo));
738  }
739  }
740 
741  theMaps.beautifyAllHistograms();
742 
743  TCanvas canvas("Canv", "Canv", (myType == SiPixelPI::t_barrel) ? 1200 : 1600, 1000);
744  if (myType == SiPixelPI::t_barrel) {
745  theMaps.drawBarrelMaps("templateLABarrel", canvas);
746  } else if (myType == SiPixelPI::t_forward) {
747  theMaps.drawForwardMaps("templateLAForward", canvas);
748  } else if (myType == SiPixelPI::t_all) {
749  theMaps.drawSummaryMaps("templateLA", canvas);
750  }
751 
752  canvas.cd();
753  TPaveText ksPt(0, 0, 0.88, 0.04, "NDC");
754  ksPt.SetBorderSize(0);
755  ksPt.SetFillColor(0);
756  const char* textToAdd = Form("%s Tag: #color[2]{%s}, IOV: #color[2]{%s}. Payload hash: #color[2]{%s}",
757  (isTemplate_ ? "Template" : "GenError"),
758  tagname.c_str(),
759  std::to_string(std::get<0>(iov)).c_str(),
760  (std::get<1>(iov)).c_str());
761  ksPt.AddText(textToAdd);
762  ksPt.Draw();
763 
765  canvas.SaveAs(fileName.c_str());
766  }
767  return true;
768  } // fill
769 
770  protected:
773 
774  private:
775  std::map<int, header_info> theInfos_;
776  };
777 
778 } // namespace templateHelper
779 
780 #endif
void drawForwardMaps(const std::string &currentHistoName, TCanvas &canvas, const char *drawOption=nullptr)
static const TGPicture * info(bool iBackgroundIsBlack)
ret
prodAgent to be discontinued
static const unsigned int phase0size
static constexpr const char * header_types[]
float fbin[3]
The QBin definitions in Q_clus/Q_avg.
int templ_version
Version number of the template to ensure code compatibility.
Log< level::Error, false > LogError
float s50
1/2 of the multihit dcol threshold in electrons
void drawSummaryMaps(const std::string &currentHistoName, TCanvas &canvas, const char *drawOption=nullptr)
static std::string to_string(const XMLCh *ch)
static std::string const input
Definition: EdmProvDump.cc:50
void fillForwardBin(const std::string &currentHistoName, unsigned int id, double value)
U second(std::pair< T, U > const &p)
void drawBarrelMaps(const std::string &currentHistoName, TCanvas &canvas, const char *drawOption=nullptr)
void resetOption(const char *option)
static const unsigned int phase1size
float lorywidth
estimate of y-lorentz width for optimal resolution
double f[11][100]
Definition: value.py:1
#define COUT
void beautifyAllHistograms()
int NTxx
number of Template x-entries in each slice
Definition: DetId.h:17
float ss50
1/2 of the single hit dcol threshold in electrons
void bookBarrelHistograms(const std::string &currentHistoName, const char *what, const char *zaxis)
void displayNotSupported(TCanvas &canv, const unsigned int size)
void printTrackerMap(TCanvas &canvas, const float topMargin=0.02, int index=0)
void bookForwardHistograms(const std::string &currentHistoName, const char *what, const char *zaxis)
void fillBarrelBin(const std::string &currentHistoName, unsigned int id, double value)
bool fillTrackerMap(unsigned int id, double value)
int NTyx
number of Template y-slices of x entries
float lorxwidth
estimate of x-lorentz width for optimal resolution
def canvas(sub, attr)
Definition: svgfig.py:482
float qscale
Charge scaling to match cmssw and pixelav.
Log< level::Warning, false > LogWarning
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
float roundoff(float value, unsigned char prec)
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)