CMS 3D CMS Logo

SiPixelPayloadInspectorHelper.h
Go to the documentation of this file.
1 #ifndef CONDCORE_SIPIXELPLUGINS_SIPIXELPAYLOADINSPECTORHELPER_H
2 #define CONDCORE_SIPIXELPLUGINS_SIPIXELPAYLOADINSPECTORHELPER_H
3 
4 #include <vector>
5 #include <numeric>
6 #include <fstream> // std::ifstream
7 #include <string>
8 #include <bitset>
9 
10 #include "TGraph.h"
11 #include "TH1.h"
12 #include "TH2.h"
13 #include "TLatex.h"
14 #include "TLine.h"
15 #include "TPave.h"
16 #include "TPaveStats.h"
17 #include "TPaveText.h"
18 #include "TStyle.h"
19 #include "TCanvas.h"
20 
28 
29 //#define MMDEBUG
30 #ifdef MMDEBUG
31 #include <iostream>
32 #define COUT std::cout << "MM "
33 #else
34 #define COUT edm::LogVerbatim("")
35 #endif
36 
37 namespace SiPixelPI {
38 
39  enum phase { zero = 0, one = 1, two = 2, undefined = 999 };
40 
41  // size of the phase-0 pixel detID list
42  static const unsigned int phase0size = 1440;
43  static const unsigned int phase1size = 1856;
44  static const unsigned int phase2size = 3892;
45  static const unsigned int mismatched = 9999;
46 
47  //============================================================================
48  // struct to store info useful to construct topology based on the detid list
49  struct PhaseInfo {
50  // construct with det size
51  PhaseInfo(unsigned int size) : m_detsize(size) {}
52  // construct passing the phase
53  PhaseInfo(const phase& thePhase) {
54  switch (thePhase) {
55  case phase::zero:
57  break;
58  case phase::one:
60  break;
61  case phase::two:
63  break;
64  default:
65  m_detsize = 99999;
66  edm::LogError("PhaseInfo") << "undefined phase: " << thePhase;
67  }
68  }
69  virtual ~PhaseInfo() { edm::LogInfo("PhaseInfo") << "PhaseInfo::~PhaseInfo()\n"; }
70  const SiPixelPI::phase phase() const {
71  if (m_detsize == phase0size)
72  return phase::zero;
73  else if (m_detsize == phase1size)
74  return phase::one;
75  else if (m_detsize > phase1size)
76  return phase::two;
77  else {
78  throw cms::Exception("LogicError") << "this detId list size: " << m_detsize << "should not exist!";
79  }
80  }
81 
82  const char* pathToTopoXML() {
83  if (m_detsize == phase0size)
84  return "Geometry/TrackerCommonData/data/trackerParameters.xml";
85  else if (m_detsize == phase1size)
86  return "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
87  else if (m_detsize > phase1size)
88  return "Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml";
89  else {
90  throw cms::Exception("LogicError") << "this detId list size: " << m_detsize << "should not exist!";
91  }
92  }
93 
94  const bool isPhase1Comparison(const PhaseInfo& theOtherPhase) const {
95  if (phase() == phase::one || theOtherPhase.phase() == phase::one)
96  return true;
97  else
98  return false;
99  }
100 
101  const bool isComparedWithPhase2(const PhaseInfo& theOtherPhase) const {
102  if ((phase() == phase::two && theOtherPhase.phase() != phase::two) ||
103  (phase() != phase::two && theOtherPhase.phase() == phase::two)) {
104  return true;
105  } else {
106  return false;
107  }
108  }
109 
110  private:
111  size_t m_detsize;
112  };
113 
114  //============================================================================
115  inline std::pair<unsigned int, unsigned int> unpack(cond::Time_t since) {
116  auto kLowMask = 0XFFFFFFFF;
117  auto run = (since >> 32);
118  auto lumi = (since & kLowMask);
119  return std::make_pair(run, lumi);
120  }
121 
122  //============================================================================
123  // Taken from pixel naming classes
124  // BmO (-z-x) = 1, BmI (-z+x) = 2 , BpO (+z-x) = 3 , BpI (+z+x) = 4
125  inline int quadrant(const DetId& detid, const TrackerTopology* tTopo_, bool phase_) {
126  if (detid.subdetId() == PixelSubdetector::PixelBarrel) {
127  return PixelBarrelName(detid, tTopo_, phase_).shell();
128  } else {
129  return PixelEndcapName(detid, tTopo_, phase_).halfCylinder();
130  }
131  }
132 
133  //============================================================================
134  // Online ladder convention taken from pixel naming class for barrel
135  // Apply sign convention (- sign for BmO and BpO)
136  inline int signed_ladder(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
138  return -9999;
139  int signed_ladder = PixelBarrelName(detid, &tTopo_, phase_).ladderName();
140  if (quadrant(detid, &tTopo_, phase_) % 2)
141  signed_ladder *= -1;
142  return signed_ladder;
143  }
144 
145  //============================================================================
146  // Online mdoule convention taken from pixel naming class for barrel
147  // Apply sign convention (- sign for BmO and BmI)
148  inline int signed_module(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
150  return -9999;
151  int signed_module = PixelBarrelName(detid, &tTopo_, phase_).moduleName();
152  if (quadrant(detid, &tTopo_, phase_) < 3)
153  signed_module *= -1;
154  return signed_module;
155  }
156 
157  //============================================================================
158  // Phase 0: Ring was not an existing convention
159  // but the 7 plaquettes were split by HV group
160  // --> Derive Ring 1/2 for them
161  // Panel 1 plq 1-2, Panel 2, plq 1 = Ring 1
162  // Panel 1 plq 3-4, Panel 2, plq 2-3 = Ring 2
163  // Phase 1: Using pixel naming class for endcap
164  inline int ring(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
166  return -9999;
167  int ring = -9999;
168  if (phase_ == 0) {
169  ring = 1 + (tTopo_.pxfPanel(detid) + tTopo_.pxfModule(detid) > 3);
170  } else if (phase_ == 1) {
171  ring = PixelEndcapName(detid, &tTopo_, phase_).ringName();
172  }
173  return ring;
174  }
175 
176  //============================================================================
177  // Online blade convention taken from pixel naming class for endcap
178  // Apply sign convention (- sign for BmO and BpO)
179  inline int signed_blade(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
181  return -9999;
182  int signed_blade = PixelEndcapName(detid, &tTopo_, phase_).bladeName();
183  if (quadrant(detid, &tTopo_, phase_) % 2)
184  signed_blade *= -1;
185  return signed_blade;
186  }
187 
188  //============================================================================
189  inline int signed_blade_panel(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
191  return -9999;
192  int signed_blade_panel = signed_blade(detid, tTopo_, phase_) + (tTopo_.pxfPanel(detid) - 1);
193  return signed_blade_panel;
194  }
195 
196  //============================================================================
197  // Online disk convention
198  // Apply sign convention (- sign for BmO and BmI)
199  inline int signed_disk(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
201  return -9999;
202  int signed_disk = tTopo_.pxfDisk(DetId(detid));
203  if (quadrant(detid, &tTopo_, phase_) < 3)
204  signed_disk *= -1;
205  return signed_disk;
206  }
207 
208  //============================================================================
209  inline void draw_line(double x1, double x2, double y1, double y2, int width = 2, int style = 1, int color = 1) {
210  TLine* l = new TLine(x1, y1, x2, y2);
211  l->SetBit(kCanDelete);
212  l->SetLineWidth(width);
213  l->SetLineStyle(style);
214  l->SetLineColor(color);
215  l->Draw();
216  }
217 
218  //============================================================================
219  inline void dress_occup_plot(TCanvas& canv,
220  TH2* h,
221  int lay,
222  int ring = 0,
223  int phase = 0,
224  bool half_shift = true,
225  bool mark_zero = true,
226  bool standard_palette = true) {
227  std::string s_title;
228 
229  if (lay > 0) {
230  canv.cd(lay);
231  s_title = "Barrel Pixel Layer " + std::to_string(lay);
232  } else {
233  canv.cd(ring);
234  if (ring > 4) {
235  ring = ring - 4;
236  }
237  s_title = "Forward Pixel Ring " + std::to_string(ring);
238  }
239 
240  gStyle->SetPadRightMargin(0.125);
241 
242  if (standard_palette) {
243  gStyle->SetPalette(1);
244  } else {
245  // this is the fine gradient palette
246  const Int_t NRGBs = 5;
247  const Int_t NCont = 255;
248 
249  Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
250  Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
251  Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
252  Double_t blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
253  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
254  gStyle->SetNumberContours(NCont);
255  }
256 
257  h->SetMarkerSize(0.7);
258  h->Draw("colz1");
259 
260  auto ltx = TLatex();
261  ltx.SetTextFont(62);
262  ltx.SetTextColor(1);
263  ltx.SetTextSize(0.06);
264  ltx.SetTextAlign(31);
265  ltx.DrawLatexNDC(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, (s_title).c_str());
266 
267  // Draw Lines around modules
268  if (lay > 0) {
269  std::vector<std::vector<int>> nladder = {{10, 16, 22}, {6, 14, 22, 32}};
270  int nlad = nladder[phase][lay - 1];
271  for (int xsign = -1; xsign <= 1; xsign += 2)
272  for (int ysign = -1; ysign <= 1; ysign += 2) {
273  float xlow = xsign * (half_shift * 0.5);
274  float xhigh = xsign * (half_shift * 0.5 + 4);
275  float ylow = ysign * (half_shift * 0.5 + (phase == 0) * 0.5);
276  float yhigh = ysign * (half_shift * 0.5 - (phase == 0) * 0.5 + nlad);
277  // Outside box
278  draw_line(xlow, xhigh, ylow, ylow, 1); // bottom
279  draw_line(xlow, xhigh, yhigh, yhigh, 1); // top
280  draw_line(xlow, xlow, ylow, yhigh, 1); // left
281  draw_line(xhigh, xhigh, ylow, yhigh, 1); // right
282  // Inner Horizontal lines
283  for (int lad = 1; lad < nlad; ++lad) {
284  float y = ysign * (lad + half_shift * 0.5);
285  draw_line(xlow, xhigh, y, y, 1);
286  }
287  for (int lad = 1; lad <= nlad; ++lad)
288  if (!(phase == 0 && (lad == 1 || lad == nlad))) {
289  float y = ysign * (lad + half_shift * 0.5 - 0.5);
290  draw_line(xlow, xhigh, y, y, 1, 3);
291  }
292  // Inner Vertical lines
293  for (int mod = 1; mod < 4; ++mod) {
294  float x = xsign * (mod + half_shift * 0.5);
295  draw_line(x, x, ylow, yhigh, 1);
296  }
297  // Make a BOX around ROC 0
298  // Phase 0 - ladder +1 is always non-flipped
299  // Phase 1 - ladder +1 is always flipped
300  if (mark_zero) {
301  for (int mod = 1; mod <= 4; ++mod)
302  for (int lad = 1; lad <= nlad; ++lad) {
303  bool flipped = ysign == 1 ? lad % 2 == 0 : lad % 2 == 1;
304  if (phase == 1)
305  flipped = !flipped;
306  int roc0_orientation = flipped ? -1 : 1;
307  if (xsign == -1)
308  roc0_orientation *= -1;
309  if (ysign == -1)
310  roc0_orientation *= -1;
311  float x1 = xsign * (mod + half_shift * 0.5);
312  float x2 = xsign * (mod + half_shift * 0.5 - 1. / 8);
313  float y1 = ysign * (lad + half_shift * 0.5 - 0.5);
314  float y2 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation * 1. / 2);
315  if (!(phase == 0 && (lad == 1 || lad == nlad) && xsign == -1)) {
316  if (lay == 1 && xsign <= -1) {
317  float x1 = xsign * ((mod - 1) + half_shift * 0.5);
318  float x2 = xsign * ((mod - 1) + half_shift * 0.5 + 1. / 8);
319  float y1 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation);
320  float y2 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation * 3. / 2);
321  draw_line(x1, x2, y1, y1, 1);
322  draw_line(x2, x2, y1, y2, 1);
323  } else {
324  draw_line(x1, x2, y1, y1, 1);
325  //draw_line(x1, x2, y2, y2, 1);
326  //draw_line(x1, x1, y1, y2, 1);
327  draw_line(x2, x2, y1, y2, 1);
328  }
329  }
330  }
331  }
332  }
333  } else {
334  // FPIX
335  for (int dsk = 1, ndsk = 2 + (phase == 1); dsk <= ndsk; ++dsk) {
336  for (int xsign = -1; xsign <= 1; xsign += 2)
337  for (int ysign = -1; ysign <= 1; ysign += 2) {
338  if (phase == 0) {
339  int first_roc = 3, nbin = 16;
340  for (int bld = 1, nbld = 12; bld <= nbld; ++bld) {
341  // Horizontal lines
342  for (int plq = 1, nplq = 7; plq <= nplq; ++plq) {
343  float xlow =
344  xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1)) / (float)nbin);
345  float xhigh =
346  xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * (plq + 1) - (plq == 7)) / (float)nbin);
347  float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + plq / 2) * 0.1);
348  float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + plq / 2) * 0.1);
349  draw_line(xlow, xhigh, ylow, ylow, 1); // bottom
350  draw_line(xlow, xhigh, yhigh, yhigh, 1); // top
351  }
352  // Vertical lines
353  for (int plq = 1, nplq = 7 + 1; plq <= nplq; ++plq) {
354  float x = xsign * (half_shift * 0.5 + dsk - 1 +
355  (first_roc - 3 + 2 * plq + (plq == 1) - (plq == 8)) / (float)nbin);
356  float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + (plq - (plq == 8)) / 2) * 0.1);
357  float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + (plq - (plq == 8)) / 2) * 0.1);
358  draw_line(x, x, ylow, yhigh, 1);
359  }
360  // Panel 2 has dashed mid-plane
361  for (int plq = 2, nplq = 6; plq <= nplq; ++plq)
362  if (plq % 2 == 0) {
363  float x = xsign * (half_shift * 0.5 + dsk - 1 +
364  (first_roc - 3 + 2 * plq + (plq == 1) - (plq == 8) + 1) / (float)nbin);
365  float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + (plq - (plq == 8)) / 2) * 0.1);
366  float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + (plq - (plq == 8)) / 2) * 0.1);
367  draw_line(x, x, ylow, yhigh, 1, 2);
368  }
369  // Make a BOX around ROC 0
370  for (int plq = 1, nplq = 7; plq <= nplq; ++plq) {
371  float x1 =
372  xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1)) / (float)nbin);
373  float x2 =
374  xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1) + 1) / (float)nbin);
375  int sign = xsign * ysign * ((plq % 2) ? 1 : -1);
376  float y1 = ysign * (half_shift * 0.5 + (bld - 0.5) + sign * (2 + plq / 2) * 0.1);
377  float y2 = ysign * (half_shift * 0.5 + (bld - 0.5) + sign * (plq / 2) * 0.1);
378  //draw_line(x1, x2, y1, y1, 1);
379  draw_line(x1, x2, y2, y2, 1);
380  //draw_line(x1, x1, y1, y2, 1);
381  draw_line(x2, x2, y1, y2, 1);
382  }
383  }
384  } else if (phase == 1) {
385  if (ring == 0) { // both
386  for (int ring = 1; ring <= 2; ++ring)
387  for (int bld = 1, nbld = 5 + ring * 6; bld <= nbld; ++bld) {
388  float scale = (ring == 1) ? 1.5 : 1;
389  Color_t p1_color = 1, p2_color = 1;
390  // Horizontal lines
391  // Panel 2 has dashed mid-plane
392  float x1 = xsign * (half_shift * 0.5 + dsk - 1 + (ring - 1) * 0.5);
393  float x2 = xsign * (half_shift * 0.5 + dsk - 1 + ring * 0.5);
394  int sign = ysign;
395  float y1 = ysign * (half_shift * 0.5 - 0.5 + scale * bld + sign * 0.5);
396  //float yp1_mid = ysign * (half_shift*0.5 - 0.5 + scale*bld + sign*0.25);
397  float y2 = ysign * (half_shift * 0.5 - 0.5 + scale * bld);
398  float yp2_mid = ysign * (half_shift * 0.5 - 0.5 + scale * bld - sign * 0.25);
399  float y3 = ysign * (half_shift * 0.5 - 0.5 + scale * bld - sign * 0.5);
400  draw_line(x1, x2, y1, y1, 1, 1, p1_color);
401  //draw_line(x1, x2, yp1_mid, yp1_mid, 1, 3);
402  draw_line(x1, x2, y2, y2, 1, 1, p1_color);
403  draw_line(x1, x2, yp2_mid, yp2_mid, 1, 2);
404  draw_line(x1, x2, y3, y3, 1, 1, p2_color);
405  // Vertical lines
406  float x = xsign * (half_shift * 0.5 + dsk - 1 + (ring - 1) * 0.5);
407  draw_line(x, x, y1, y2, 1, 1, p1_color);
408  draw_line(x, x, y2, y3, 1, 1, p2_color);
409  if (ring == 2) {
410  //draw_line(x, x, y2, y3, 1, 1, p1_color);
411  x = xsign * (half_shift * 0.5 + dsk);
412  draw_line(x, x, y1, y2, 1, 1, p1_color);
413  draw_line(x, x, y2, y3, 1, 1, p2_color);
414  }
415  // Make a BOX around ROC 0
416  x1 = xsign * (half_shift * 0.5 + dsk - 1 + ring * 0.5 - 1 / 16.);
417  x2 = xsign * (half_shift * 0.5 + dsk - 1 + ring * 0.5);
418  float y1_p1 = ysign * (half_shift * 0.5 - 0.5 + scale * bld + sign * 0.25);
419  float y2_p1 = ysign * (half_shift * 0.5 - 0.5 + scale * bld + sign * 0.25 + xsign * ysign * 0.25);
420  draw_line(x1, x2, y1_p1, y1_p1, 1);
421  //draw_line(x1, x2, y2_p1, y2_p1, 1);
422  draw_line(x1, x1, y1_p1, y2_p1, 1);
423  //draw_line(x2, x2, y1_p1, y2_p1, 1);
424  float y1_p2 = ysign * (half_shift * 0.5 - 0.5 + scale * bld - sign * 0.25);
425  float y2_p2 = ysign * (half_shift * 0.5 - 0.5 + scale * bld - sign * 0.25 - xsign * ysign * 0.25);
426  draw_line(x1, x2, y1_p2, y1_p2, 1);
427  //draw_line(x1, x2, y2_p2, y2_p2, 1);
428  draw_line(x1, x1, y1_p2, y2_p2, 1);
429  //draw_line(x2, x2, y1_p2, y2_p2, 1);
430  }
431  } else { // only one ring, 1 or 2
432  for (int bld = 1, nbld = 5 + ring * 6; bld <= nbld; ++bld) {
433  Color_t p1_color = 1, p2_color = 1;
434  // Horizontal lines
435  // Panel 2 has dashed mid-plane
436  float x1 = xsign * (half_shift * 0.5 + dsk - 1);
437  float x2 = xsign * (half_shift * 0.5 + dsk);
438  int sign = ysign;
439  float y1 = ysign * (half_shift * 0.5 - 0.5 + bld + sign * 0.5);
440  //float yp1_mid = ysign * (half_shift*0.5 - 0.5 + bld + sign*0.25);
441  float y2 = ysign * (half_shift * 0.5 - 0.5 + bld);
442  float yp2_mid = ysign * (half_shift * 0.5 - 0.5 + bld - sign * 0.25);
443  float y3 = ysign * (half_shift * 0.5 - 0.5 + bld - sign * 0.5);
444  draw_line(x1, x2, y1, y1, 1, 1, p1_color);
445  //draw_line(x1, x2, yp1_mid, yp1_mid, 1, 3);
446  draw_line(x1, x2, y2, y2, 1, 1, p1_color);
447  draw_line(x1, x2, yp2_mid, yp2_mid, 1, 2);
448  draw_line(x1, x2, y3, y3, 1, 1, p2_color);
449  // Vertical lines
450  float x = xsign * (half_shift * 0.5 + dsk - 1);
451  draw_line(x, x, y1, y2, 1, 1, p1_color);
452  draw_line(x, x, y2, y3, 1, 1, p2_color);
453  if (ring == 2) {
454  //draw_line(x, x, y2, y3, 1, 1, p1_color);
455  x = xsign * (half_shift * 0.5 + dsk);
456  draw_line(x, x, y1, y2, 1, 1, p1_color);
457  draw_line(x, x, y2, y3, 1, 1, p2_color);
458  }
459  // Make a BOX around ROC 0
460  x1 = xsign * (half_shift * 0.5 + dsk - 1 / 8.);
461  x2 = xsign * (half_shift * 0.5 + dsk);
462  float y1_p1 = ysign * (half_shift * 0.5 - 0.5 + bld + sign * 0.25);
463  float y2_p1 = ysign * (half_shift * 0.5 - 0.5 + bld + sign * 0.25 + xsign * ysign * 0.25);
464  draw_line(x1, x2, y1_p1, y1_p1, 1);
465  //draw_line(x1, x2, y2_p1, y2_p1, 1);
466  draw_line(x1, x1, y1_p1, y2_p1, 1);
467  //draw_line(x2, x2, y1_p1, y2_p1, 1);
468  float y1_p2 = ysign * (half_shift * 0.5 - 0.5 + bld - sign * 0.25);
469  float y2_p2 = ysign * (half_shift * 0.5 - 0.5 + bld - sign * 0.25 - xsign * ysign * 0.25);
470  draw_line(x1, x2, y1_p2, y1_p2, 1);
471  //draw_line(x1, x2, y2_p2, y2_p2, 1);
472  draw_line(x1, x1, y1_p2, y2_p2, 1);
473  //draw_line(x2, x2, y1_p2, y2_p2, 1);
474  }
475  }
476  }
477  }
478  }
479  // Special shifted "rebin" for Phase 0
480  // Y axis should always have at least half-roc granularity because
481  // there are half-ROC size shifts implemented in the coordinates
482  // To remove this and show full ROC granularity
483  // We merge bin contents in each pair of bins corresponding to one ROC
484  // TODO: make sure this works for Profiles
485  if (phase == 0 && h->GetNbinsY() == 250 && h->GetNbinsX() == 80) {
486  int nentries = h->GetEntries();
487  for (int binx = 1; binx <= 80; ++binx) {
488  double sum = 0;
489  for (int biny = 1; biny <= 250; ++biny) {
490  bool odd_nrocy = (binx - 1 < 40) != (((binx - 1) / 4) % 2);
491  if (biny % 2 == odd_nrocy)
492  sum += h->GetBinContent(binx, biny);
493  else {
494  sum += h->GetBinContent(binx, biny);
495  if (sum) {
496  h->SetBinContent(binx, biny, sum);
497  h->SetBinContent(binx, biny - 1, sum);
498  }
499  sum = 0;
500  }
501  }
502  }
503  h->SetEntries(nentries);
504  }
505  }
506  }
507 
508  /*--------------------------------------------------------------------*/
509  inline void adjustCanvasMargins(TVirtualPad* pad, float top, float bottom, float left, float right)
510  /*--------------------------------------------------------------------*/
511  {
512  if (top > 0)
513  pad->SetTopMargin(top);
514  if (bottom > 0)
515  pad->SetBottomMargin(bottom);
516  if (left > 0)
517  pad->SetLeftMargin(left);
518  if (right > 0)
519  pad->SetRightMargin(right);
520  }
521 
522  /*--------------------------------------------------------------------*/
523  inline void adjustStats(TPaveStats* stats, float X1, float Y1, float X2, float Y2)
524  /*--------------------------------------------------------------------*/
525  {
526  stats->SetX1NDC(X1); //new x start position
527  stats->SetY1NDC(Y1); //new y start position
528  stats->SetX2NDC(X2); //new x end position
529  stats->SetY2NDC(Y2); //new y end position
530  }
531 
532  /*--------------------------------------------------------------------*/
533  inline std::pair<float, float> getExtrema(TH1* h1, TH1* h2)
534  /*--------------------------------------------------------------------*/
535  {
536  float theMax(-9999.);
537  float theMin(9999.);
538  theMax = h1->GetMaximum() > h2->GetMaximum() ? h1->GetMaximum() : h2->GetMaximum();
539  theMin = h1->GetMinimum() < h2->GetMaximum() ? h1->GetMinimum() : h2->GetMinimum();
540 
541  float add_min = theMin > 0. ? -0.05 : 0.05;
542  float add_max = theMax > 0. ? 0.05 : -0.05;
543 
544  auto result = std::make_pair(theMin * (1 + add_min), theMax * (1 + add_max));
545  return result;
546  }
547 
548  /*--------------------------------------------------------------------*/
549  inline void makeNicePlotStyle(TH1* hist)
550  /*--------------------------------------------------------------------*/
551  {
552  hist->SetStats(kFALSE);
553  hist->SetLineWidth(2);
554  hist->GetXaxis()->CenterTitle(true);
555  hist->GetYaxis()->CenterTitle(true);
556  hist->GetXaxis()->SetTitleFont(42);
557  hist->GetYaxis()->SetTitleFont(42);
558  hist->GetXaxis()->SetTitleSize(0.05);
559  hist->GetYaxis()->SetTitleSize(0.05);
560  hist->GetXaxis()->SetTitleOffset(1.1);
561  hist->GetYaxis()->SetTitleOffset(1.3);
562  hist->GetXaxis()->SetLabelFont(42);
563  hist->GetYaxis()->SetLabelFont(42);
564  hist->GetYaxis()->SetLabelSize(.05);
565  hist->GetXaxis()->SetLabelSize(.05);
566 
567  if (hist->InheritsFrom(TH2::Class())) {
568  hist->GetZaxis()->SetLabelFont(42);
569  hist->GetZaxis()->SetLabelFont(42);
570  hist->GetZaxis()->SetLabelSize(.05);
571  hist->GetZaxis()->SetLabelSize(.05);
572  }
573  }
574 
575  enum DetType { t_barrel = 0, t_forward = 1, t_all = 2 };
576  const std::array<std::string, 3> DetNames = {{"Barrel", "End Caps", "Whole"}};
577 
578  enum regions {
579  BPixL1o, //0 Barrel Pixel Layer 1 outer
580  BPixL1i, //1 Barrel Pixel Layer 1 inner
581  BPixL2o, //2 Barrel Pixel Layer 2 outer
582  BPixL2i, //3 Barrel Pixel Layer 2 inner
583  BPixL3o, //4 Barrel Pixel Layer 3 outer
584  BPixL3i, //5 Barrel Pixel Layer 3 inner
585  BPixL4o, //6 Barrel Pixel Layer 4 outer
586  BPixL4i, //7 Barrel Pixel Layer 4 inner
587  FPixmL1, //8 Forward Pixel Minus side Disk 1
588  FPixmL2, //9 Forward Pixel Minus side Disk 2
589  FPixmL3, //10 Forward Pixel Minus side Disk 3
590  FPixpL1, //11 Forward Pixel Plus side Disk 1
591  FPixpL2, //12 Forward Pixel Plus side Disk 2
592  FPixpL3, //13 Forward Pixel Plus side Disk 3
593  NUM_OF_REGIONS //14 -- default
594  };
595 
596  /*--------------------------------------------------------------------*/
598  /*--------------------------------------------------------------------*/
599  {
600  switch (e) {
601  case SiPixelPI::BPixL1o:
602  return "BPix L1/o";
603  case SiPixelPI::BPixL1i:
604  return "BPix L1/i";
605  case SiPixelPI::BPixL2o:
606  return "BPix L2/o";
607  case SiPixelPI::BPixL2i:
608  return "BPix L2/i";
609  case SiPixelPI::BPixL3o:
610  return "BPix L3/o";
611  case SiPixelPI::BPixL3i:
612  return "BPix L3/i";
613  case SiPixelPI::BPixL4o:
614  return "BPix L4/o";
615  case SiPixelPI::BPixL4i:
616  return "BPix L4/i";
617  case SiPixelPI::FPixmL1:
618  return "FPix- D1";
619  case SiPixelPI::FPixmL2:
620  return "FPix- D2";
621  case SiPixelPI::FPixmL3:
622  return "FPix- D3";
623  case SiPixelPI::FPixpL1:
624  return "FPix+ D1";
625  case SiPixelPI::FPixpL2:
626  return "FPix+ D2";
627  case SiPixelPI::FPixpL3:
628  return "FPix+ D3";
629  default:
630  edm::LogWarning("LogicError") << "Unknown partition: " << e;
631  return "";
632  }
633  }
634 
635  /*--------------------------------------------------------------------*/
636  inline bool isBPixOuterLadder(const DetId& detid, const TrackerTopology& tTopo, bool isPhase0)
637  /*--------------------------------------------------------------------*/
638  {
639  // Using TrackerTopology
640  // Ladders have a staggered structure
641  // Non-flipped ladders are on the outer radius
642  // Phase 0: Outer ladders are odd for layer 1,3 and even for layer 2
643  // Phase 1: Outer ladders are odd for layer 1,2,3 and even for layer 4
644  bool isOuter = false;
645  int layer = tTopo.pxbLayer(detid.rawId());
646  bool odd_ladder = tTopo.pxbLadder(detid.rawId()) % 2;
647  if (isPhase0) {
648  if (layer == 2)
649  isOuter = !odd_ladder;
650  else
651  isOuter = odd_ladder;
652  } else {
653  if (layer == 4)
654  isOuter = !odd_ladder;
655  else
656  isOuter = odd_ladder;
657  }
658  return isOuter;
659  }
660 
661  // ancillary struct to manage the topology
662  // info in a more compact way
663 
664  struct topolInfo {
665  private:
666  uint32_t m_rawid;
668  int m_layer;
669  int m_side;
670  int m_ring;
673 
674  public:
675  void init();
676  void fillGeometryInfo(const DetId& detId, const TrackerTopology& tTopo, const SiPixelPI::phase& ph);
678  bool sanityCheck();
679  int subDetId() { return m_subdetid; }
680  int layer() { return m_layer; }
681  int side() { return m_side; }
682  int ring() { return m_ring; }
683  bool isInternal() { return m_isInternal; }
684 
685  void printAll(std::stringstream& ss) const;
686  virtual ~topolInfo() {}
687  };
688 
689  /*--------------------------------------------------------------------*/
690  inline void topolInfo::printAll(std::stringstream& ss) const
691  /*--------------------------------------------------------------------*/
692  {
693  ss << " detId: " << m_rawid << " subdetid: " << m_subdetid << " layer: " << m_layer << " side: " << m_side
694  << " ring: " << m_ring << " isInternal: " << m_isInternal;
695  }
696 
697  /*--------------------------------------------------------------------*/
698  inline void topolInfo::init()
699  /*--------------------------------------------------------------------*/
700  {
702  m_rawid = 0;
703  m_subdetid = -1;
704  m_layer = -1;
705  m_side = -1;
706  m_ring = -1;
707  m_isInternal = false;
708  };
709 
710  /*--------------------------------------------------------------------*/
712  /*--------------------------------------------------------------------*/
713  {
714  if (m_layer == 0 || (m_subdetid == 1 && m_layer > 4) || (m_subdetid == 2 && m_layer > 3)) {
715  return false;
716  } else {
717  return true;
718  }
719  }
720  /*--------------------------------------------------------------------*/
721  inline void topolInfo::fillGeometryInfo(const DetId& detId, const TrackerTopology& tTopo, const SiPixelPI::phase& ph)
722  /*--------------------------------------------------------------------*/
723  {
724  // set the phase
725  m_Phase = ph;
726  unsigned int subdetId = static_cast<unsigned int>(detId.subdetId());
727 
728  m_rawid = detId.rawId();
729  m_subdetid = subdetId;
730  if (subdetId == PixelSubdetector::PixelBarrel) {
731  m_layer = tTopo.pxbLayer(detId.rawId());
733  } else if (subdetId == PixelSubdetector::PixelEndcap) {
734  m_layer = tTopo.pxfDisk(detId.rawId());
735  m_side = tTopo.pxfSide(detId.rawId());
736  } else
737  edm::LogWarning("LogicError") << "Unknown subdetid: " << subdetId;
738  }
739 
740  // ------------ method to assign a partition based on the topology struct info ---------------
741 
742  /*--------------------------------------------------------------------*/
744  /*--------------------------------------------------------------------*/
745  {
747 
748  if (m_Phase == SiPixelPI::undefined) {
749  throw cms::Exception("LogicError") << "Cannot call filterThePartition BEFORE filling the geometry info!";
750  }
751 
752  // BPix
753  if (m_subdetid == 1) {
754  switch (m_layer) {
755  case 1:
757  break;
758  case 2:
760  break;
761  case 3:
763  break;
764  case 4:
766  break;
767  default:
768  edm::LogWarning("LogicError") << "Unknow BPix layer: " << m_layer;
769  break;
770  }
771  // FPix
772  } else if (m_subdetid == 2) {
773  switch (m_layer) {
774  case 1:
776  break;
777  case 2:
779  break;
780  case 3:
782  break;
783  default:
785  // warning message only if the phase2 is < 2
786  edm::LogWarning("LogicError") << "Unknow FPix disk: " << m_layer;
787  }
788  break;
789  }
790  }
791  return ret;
792  }
793 
794  /*--------------------------------------------------------------------*/
795  inline void displayNotSupported(TCanvas& canv, const unsigned int size)
796  /*--------------------------------------------------------------------*/
797  {
798  std::string phase = (size < SiPixelPI::phase1size) ? "Phase-0" : "Phase-2";
799  canv.cd();
800  TLatex t2;
801  t2.SetTextAlign(21);
802  t2.SetTextSize(0.1);
803  t2.SetTextAngle(45);
804  t2.SetTextColor(kRed);
805  if (size != SiPixelPI::mismatched) {
806  t2.DrawLatexNDC(0.6, 0.50, Form("%s NOT SUPPORTED!", phase.c_str()));
807  } else {
808  t2.DrawLatexNDC(0.6, 0.50, "MISMATCHED PAYLOAD SIZE!");
809  }
810  }
811 
812  /*--------------------------------------------------------------------*/
813  template <typename T>
814  std::pair<T, T> findMinMaxInMap(const std::map<unsigned int, T>& theMap)
815  /*--------------------------------------------------------------------*/
816  {
817  using pairtype = std::pair<unsigned int, T>;
818  auto max = *std::max_element(
819  theMap.begin(), theMap.end(), [](const pairtype& p1, const pairtype& p2) { return p1.second < p2.second; });
820  auto min = *std::min_element(
821  theMap.begin(), theMap.end(), [](const pairtype& p1, const pairtype& p2) { return p1.second < p2.second; });
822  return std::make_pair(min.second, max.second);
823  }
824 
825  /*--------------------------------------------------------------------*/
826  inline bool checkAnswerOK(std::string& answer, bool& result)
827  /*--------------------------------------------------------------------*/
828  {
829  std::transform(answer.begin(), answer.end(), answer.begin(), [](unsigned char x) { return ::tolower(x); });
830 
831  bool answer_valid = (answer == "y") || (answer == "n") || (answer == "yes") || (answer == "no") ||
832  (answer == "true") || (answer == "false") || (answer == "1") || (answer == "0");
833 
834  result = answer_valid && (answer[0] == 'y' || answer[0] == 't' || answer[0] == '1');
835  return answer_valid;
836  }
837 }; // namespace SiPixelPI
838 #endif
size
Write out results.
unsigned int pxbLayer(const DetId &id) const
int ringName() const
ring Id
PhaseInfo(const phase &thePhase)
int signed_blade_panel(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
ret
prodAgent to be discontinued
static const unsigned int phase0size
int bladeName() const
blade id
int moduleName() const
module id (index in z)
unsigned int pxfModule(const DetId &id) const
int quadrant(const DetId &detid, const TrackerTopology *tTopo_, bool phase_)
const Time_t kLowMask(0xFFFFFFFF)
void fillGeometryInfo(const DetId &detId, const TrackerTopology &tTopo, const SiPixelPI::phase &ph)
unsigned int pxbLadder(const DetId &id) const
Log< level::Error, false > LogError
std::pair< float, float > getExtrema(TH1 *h1, TH1 *h2)
bool checkAnswerOK(std::string &answer, bool &result)
static std::string to_string(const XMLCh *ch)
const SiPixelPI::phase phase() const
int signed_ladder(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
unsigned long long Time_t
Definition: Time.h:14
void printAll(std::stringstream &ss) const
std::pair< T, T > findMinMaxInMap(const std::map< unsigned int, T > &theMap)
int signed_disk(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
Definition: style.py:1
int signed_blade(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
HalfCylinder halfCylinder() const
static const unsigned int phase1size
unsigned int pxfDisk(const DetId &id) const
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
void draw_line(double x1, double x2, double y1, double y2, int width=2, int style=1, int color=1)
void adjustCanvasMargins(TVirtualPad *pad, float top, float bottom, float left, float right)
void adjustStats(TPaveStats *stats, float X1, float Y1, float X2, float Y2)
Shell shell() const
unsigned int pxfPanel(const DetId &id) const
Log< level::Info, false > LogInfo
int ring(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Definition: DetId.h:17
const std::array< std::string, 3 > DetNames
unsigned int pxfSide(const DetId &id) const
void makeNicePlotStyle(TH1 *hist)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int signed_module(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
void displayNotSupported(TCanvas &canv, const unsigned int size)
const bool isComparedWithPhase2(const PhaseInfo &theOtherPhase) const
bool isBPixOuterLadder(const DetId &detid, const TrackerTopology &tTopo, bool isPhase0)
float x
int ladderName() const
ladder id (index in phi)
std::string getStringFromRegionEnum(SiPixelPI::regions e)
void dress_occup_plot(TCanvas &canv, TH2 *h, int lay, int ring=0, int phase=0, bool half_shift=true, bool mark_zero=true, bool standard_palette=true)
Log< level::Warning, false > LogWarning
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
static const unsigned int mismatched
static const unsigned int phase2size
const bool isPhase1Comparison(const PhaseInfo &theOtherPhase) const
unsigned transform(const HcalDetId &id, unsigned transformCode)