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 <string>
7 #include "TGraph.h"
8 #include "TH1.h"
9 #include "TH2.h"
10 #include "TLatex.h"
11 #include "TLine.h"
12 #include "TPave.h"
13 #include "TPaveStats.h"
14 #include "TPaveText.h"
15 #include "TStyle.h"
16 #include "TCanvas.h"
23 
24 //#define MMDEBUG
25 #ifdef MMDEBUG
26 #include <iostream>
27 #define COUT std::cout << "MM "
28 #else
29 #define COUT edm::LogVerbatim("")
30 #endif
31 
32 namespace SiPixelPI {
33 
34  // size of the phase-0 pixel detID list
35  static const unsigned int phase0size = 1440;
36 
37  std::pair<unsigned int, unsigned int> unpack(cond::Time_t since) {
38  auto kLowMask = 0XFFFFFFFF;
39  auto run = (since >> 32);
40  auto lumi = (since & kLowMask);
41  return std::make_pair(run, lumi);
42  }
43 
44  //============================================================================
45  // Taken from pixel naming classes
46  // BmO (-z-x) = 1, BmI (-z+x) = 2 , BpO (+z-x) = 3 , BpI (+z+x) = 4
47  int quadrant(const DetId& detid, const TrackerTopology* tTopo_, bool phase_) {
48  if (detid.subdetId() == PixelSubdetector::PixelBarrel) {
49  return PixelBarrelName(detid, tTopo_, phase_).shell();
50  } else {
51  return PixelEndcapName(detid, tTopo_, phase_).halfCylinder();
52  }
53  }
54 
55  //============================================================================
56  // Online ladder convention taken from pixel naming class for barrel
57  // Apply sign convention (- sign for BmO and BpO)
58  int signed_ladder(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
60  return -9999;
61  int signed_ladder = PixelBarrelName(detid, &tTopo_, phase_).ladderName();
62  if (quadrant(detid, &tTopo_, phase_) % 2)
63  signed_ladder *= -1;
64  return signed_ladder;
65  }
66 
67  //============================================================================
68  // Online mdoule convention taken from pixel naming class for barrel
69  // Apply sign convention (- sign for BmO and BmI)
70  int signed_module(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
72  return -9999;
73  int signed_module = PixelBarrelName(detid, &tTopo_, phase_).moduleName();
74  if (quadrant(detid, &tTopo_, phase_) < 3)
75  signed_module *= -1;
76  return signed_module;
77  }
78 
79  //============================================================================
80  // Phase 0: Ring was not an existing convention
81  // but the 7 plaquettes were split by HV group
82  // --> Derive Ring 1/2 for them
83  // Panel 1 plq 1-2, Panel 2, plq 1 = Ring 1
84  // Panel 1 plq 3-4, Panel 2, plq 2-3 = Ring 2
85  // Phase 1: Using pixel naming class for endcap
86  int ring(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
88  return -9999;
89  int ring = -9999;
90  if (phase_ == 0) {
91  ring = 1 + (tTopo_.pxfPanel(detid) + tTopo_.pxfModule(detid) > 3);
92  } else if (phase_ == 1) {
93  ring = PixelEndcapName(detid, &tTopo_, phase_).ringName();
94  }
95  return ring;
96  }
97 
98  //============================================================================
99  // Online blade convention taken from pixel naming class for endcap
100  // Apply sign convention (- sign for BmO and BpO)
101  int signed_blade(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
103  return -9999;
104  int signed_blade = PixelEndcapName(detid, &tTopo_, phase_).bladeName();
105  if (quadrant(detid, &tTopo_, phase_) % 2)
106  signed_blade *= -1;
107  return signed_blade;
108  }
109 
110  //============================================================================
111  int signed_blade_panel(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
113  return -9999;
114  int signed_blade_panel = signed_blade(detid, tTopo_, phase_) + (tTopo_.pxfPanel(detid) - 1);
115  return signed_blade_panel;
116  }
117 
118  //============================================================================
119  // Online disk convention
120  // Apply sign convention (- sign for BmO and BmI)
121  int signed_disk(const DetId& detid, const TrackerTopology& tTopo_, bool phase_) {
123  return -9999;
124  int signed_disk = tTopo_.pxfDisk(DetId(detid));
125  if (quadrant(detid, &tTopo_, phase_) < 3)
126  signed_disk *= -1;
127  return signed_disk;
128  }
129 
130  //============================================================================
131  void draw_line(double x1, double x2, double y1, double y2, int width = 2, int style = 1, int color = 1) {
132  TLine* l = new TLine(x1, y1, x2, y2);
133  l->SetBit(kCanDelete);
134  l->SetLineWidth(width);
135  l->SetLineStyle(style);
136  l->SetLineColor(color);
137  l->Draw();
138  }
139 
140  //============================================================================
141  void dress_occup_plot(TCanvas& canv,
142  TH2* h,
143  int lay,
144  int ring = 0,
145  int phase = 0,
146  bool half_shift = true,
147  bool mark_zero = true,
148  bool standard_palette = true) {
149  std::string s_title;
150 
151  if (lay > 0) {
152  canv.cd(lay);
153  s_title = "Barrel Pixel Layer" + std::to_string(lay);
154  } else {
155  canv.cd(ring);
156  s_title = "Forward Pixel Ring" + std::to_string(ring);
157  }
158 
159  gStyle->SetPadRightMargin(0.125);
160 
161  if (standard_palette) {
162  gStyle->SetPalette(1);
163  } else {
164  // this is the fine gradient palette
165  const Int_t NRGBs = 5;
166  const Int_t NCont = 255;
167 
168  Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
169  Double_t red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
170  Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
171  Double_t blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
172  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
173  gStyle->SetNumberContours(NCont);
174  }
175 
176  h->SetMarkerSize(0.7);
177  h->Draw("colz");
178 
179  auto ltx = TLatex();
180  ltx.SetTextFont(62);
181  ltx.SetTextColor(1);
182  ltx.SetTextSize(0.06);
183  ltx.SetTextAlign(31);
184  ltx.DrawLatexNDC(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, (s_title).c_str());
185 
186  // Draw Lines around modules
187  if (lay > 0) {
188  std::vector<std::vector<int> > nladder = {{10, 16, 22}, {6, 14, 22, 32}};
189  int nlad = nladder[phase][lay - 1];
190  for (int xsign = -1; xsign <= 1; xsign += 2)
191  for (int ysign = -1; ysign <= 1; ysign += 2) {
192  float xlow = xsign * (half_shift * 0.5);
193  float xhigh = xsign * (half_shift * 0.5 + 4);
194  float ylow = ysign * (half_shift * 0.5 + (phase == 0) * 0.5);
195  float yhigh = ysign * (half_shift * 0.5 - (phase == 0) * 0.5 + nlad);
196  // Outside box
197  draw_line(xlow, xhigh, ylow, ylow, 1); // bottom
198  draw_line(xlow, xhigh, yhigh, yhigh, 1); // top
199  draw_line(xlow, xlow, ylow, yhigh, 1); // left
200  draw_line(xhigh, xhigh, ylow, yhigh, 1); // right
201  // Inner Horizontal lines
202  for (int lad = 1; lad < nlad; ++lad) {
203  float y = ysign * (lad + half_shift * 0.5);
204  draw_line(xlow, xhigh, y, y, 1);
205  }
206  for (int lad = 1; lad <= nlad; ++lad)
207  if (!(phase == 0 && (lad == 1 || lad == nlad))) {
208  float y = ysign * (lad + half_shift * 0.5 - 0.5);
209  draw_line(xlow, xhigh, y, y, 1, 3);
210  }
211  // Inner Vertical lines
212  for (int mod = 1; mod < 4; ++mod) {
213  float x = xsign * (mod + half_shift * 0.5);
214  draw_line(x, x, ylow, yhigh, 1);
215  }
216  // Make a BOX around ROC 0
217  // Phase 0 - ladder +1 is always non-flipped
218  // Phase 1 - ladder +1 is always flipped
219  if (mark_zero) {
220  for (int mod = 1; mod <= 4; ++mod)
221  for (int lad = 1; lad <= nlad; ++lad) {
222  bool flipped = ysign == 1 ? lad % 2 == 0 : lad % 2 == 1;
223  if (phase == 1)
224  flipped = !flipped;
225  int roc0_orientation = flipped ? -1 : 1;
226  if (xsign == -1)
227  roc0_orientation *= -1;
228  if (ysign == -1)
229  roc0_orientation *= -1;
230  float x1 = xsign * (mod + half_shift * 0.5);
231  float x2 = xsign * (mod + half_shift * 0.5 - 1. / 8);
232  float y1 = ysign * (lad + half_shift * 0.5 - 0.5);
233  float y2 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation * 1. / 2);
234  if (!(phase == 0 && (lad == 1 || lad == nlad) && xsign == -1)) {
235  if (lay == 1 && xsign <= -1) {
236  float x1 = xsign * ((mod - 1) + half_shift * 0.5);
237  float x2 = xsign * ((mod - 1) + half_shift * 0.5 + 1. / 8);
238  float y1 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation);
239  float y2 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation * 3. / 2);
240  draw_line(x1, x2, y1, y1, 1);
241  draw_line(x2, x2, y1, y2, 1);
242  } else {
243  draw_line(x1, x2, y1, y1, 1);
244  //draw_line(x1, x2, y2, y2, 1);
245  //draw_line(x1, x1, y1, y2, 1);
246  draw_line(x2, x2, y1, y2, 1);
247  }
248  }
249  }
250  }
251  }
252  } else {
253  // FPIX
254  for (int dsk = 1, ndsk = 2 + (phase == 1); dsk <= ndsk; ++dsk) {
255  for (int xsign = -1; xsign <= 1; xsign += 2)
256  for (int ysign = -1; ysign <= 1; ysign += 2) {
257  if (phase == 0) {
258  int first_roc = 3, nbin = 16;
259  for (int bld = 1, nbld = 12; bld <= nbld; ++bld) {
260  // Horizontal lines
261  for (int plq = 1, nplq = 7; plq <= nplq; ++plq) {
262  float xlow =
263  xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1)) / (float)nbin);
264  float xhigh =
265  xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * (plq + 1) - (plq == 7)) / (float)nbin);
266  float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + plq / 2) * 0.1);
267  float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + plq / 2) * 0.1);
268  draw_line(xlow, xhigh, ylow, ylow, 1); // bottom
269  draw_line(xlow, xhigh, yhigh, yhigh, 1); // top
270  }
271  // Vertical lines
272  for (int plq = 1, nplq = 7 + 1; plq <= nplq; ++plq) {
273  float x = xsign * (half_shift * 0.5 + dsk - 1 +
274  (first_roc - 3 + 2 * plq + (plq == 1) - (plq == 8)) / (float)nbin);
275  float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + (plq - (plq == 8)) / 2) * 0.1);
276  float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + (plq - (plq == 8)) / 2) * 0.1);
277  draw_line(x, x, ylow, yhigh, 1);
278  }
279  // Panel 2 has dashed mid-plane
280  for (int plq = 2, nplq = 6; plq <= nplq; ++plq)
281  if (plq % 2 == 0) {
282  float x = xsign * (half_shift * 0.5 + dsk - 1 +
283  (first_roc - 3 + 2 * plq + (plq == 1) - (plq == 8) + 1) / (float)nbin);
284  float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + (plq - (plq == 8)) / 2) * 0.1);
285  float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + (plq - (plq == 8)) / 2) * 0.1);
286  draw_line(x, x, ylow, yhigh, 1, 2);
287  }
288  // Make a BOX around ROC 0
289  for (int plq = 1, nplq = 7; plq <= nplq; ++plq) {
290  float x1 =
291  xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1)) / (float)nbin);
292  float x2 =
293  xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1) + 1) / (float)nbin);
294  int sign = xsign * ysign * ((plq % 2) ? 1 : -1);
295  float y1 = ysign * (half_shift * 0.5 + (bld - 0.5) + sign * (2 + plq / 2) * 0.1);
296  float y2 = ysign * (half_shift * 0.5 + (bld - 0.5) + sign * (plq / 2) * 0.1);
297  //draw_line(x1, x2, y1, y1, 1);
298  draw_line(x1, x2, y2, y2, 1);
299  //draw_line(x1, x1, y1, y2, 1);
300  draw_line(x2, x2, y1, y2, 1);
301  }
302  }
303  } else if (phase == 1) {
304  if (ring == 0) { // both
305  for (int ring = 1; ring <= 2; ++ring)
306  for (int bld = 1, nbld = 5 + ring * 6; bld <= nbld; ++bld) {
307  float scale = (ring == 1) ? 1.5 : 1;
308  Color_t p1_color = 1, p2_color = 1;
309  // Horizontal lines
310  // Panel 2 has dashed mid-plane
311  float x1 = xsign * (half_shift * 0.5 + dsk - 1 + (ring - 1) * 0.5);
312  float x2 = xsign * (half_shift * 0.5 + dsk - 1 + ring * 0.5);
313  int sign = ysign;
314  float y1 = ysign * (half_shift * 0.5 - 0.5 + scale * bld + sign * 0.5);
315  //float yp1_mid = ysign * (half_shift*0.5 - 0.5 + scale*bld + sign*0.25);
316  float y2 = ysign * (half_shift * 0.5 - 0.5 + scale * bld);
317  float yp2_mid = ysign * (half_shift * 0.5 - 0.5 + scale * bld - sign * 0.25);
318  float y3 = ysign * (half_shift * 0.5 - 0.5 + scale * bld - sign * 0.5);
319  draw_line(x1, x2, y1, y1, 1, 1, p1_color);
320  //draw_line(x1, x2, yp1_mid, yp1_mid, 1, 3);
321  draw_line(x1, x2, y2, y2, 1, 1, p1_color);
322  draw_line(x1, x2, yp2_mid, yp2_mid, 1, 2);
323  draw_line(x1, x2, y3, y3, 1, 1, p2_color);
324  // Vertical lines
325  float x = xsign * (half_shift * 0.5 + dsk - 1 + (ring - 1) * 0.5);
326  draw_line(x, x, y1, y2, 1, 1, p1_color);
327  draw_line(x, x, y2, y3, 1, 1, p2_color);
328  if (ring == 2) {
329  //draw_line(x, x, y2, y3, 1, 1, p1_color);
330  x = xsign * (half_shift * 0.5 + dsk);
331  draw_line(x, x, y1, y2, 1, 1, p1_color);
332  draw_line(x, x, y2, y3, 1, 1, p2_color);
333  }
334  // Make a BOX around ROC 0
335  x1 = xsign * (half_shift * 0.5 + dsk - 1 + ring * 0.5 - 1 / 16.);
336  x2 = xsign * (half_shift * 0.5 + dsk - 1 + ring * 0.5);
337  float y1_p1 = ysign * (half_shift * 0.5 - 0.5 + scale * bld + sign * 0.25);
338  float y2_p1 = ysign * (half_shift * 0.5 - 0.5 + scale * bld + sign * 0.25 + xsign * ysign * 0.25);
339  draw_line(x1, x2, y1_p1, y1_p1, 1);
340  //draw_line(x1, x2, y2_p1, y2_p1, 1);
341  draw_line(x1, x1, y1_p1, y2_p1, 1);
342  //draw_line(x2, x2, y1_p1, y2_p1, 1);
343  float y1_p2 = ysign * (half_shift * 0.5 - 0.5 + scale * bld - sign * 0.25);
344  float y2_p2 = ysign * (half_shift * 0.5 - 0.5 + scale * bld - sign * 0.25 - xsign * ysign * 0.25);
345  draw_line(x1, x2, y1_p2, y1_p2, 1);
346  //draw_line(x1, x2, y2_p2, y2_p2, 1);
347  draw_line(x1, x1, y1_p2, y2_p2, 1);
348  //draw_line(x2, x2, y1_p2, y2_p2, 1);
349  }
350  } else { // only one ring, 1 or 2
351  for (int bld = 1, nbld = 5 + ring * 6; bld <= nbld; ++bld) {
352  Color_t p1_color = 1, p2_color = 1;
353  // Horizontal lines
354  // Panel 2 has dashed mid-plane
355  float x1 = xsign * (half_shift * 0.5 + dsk - 1);
356  float x2 = xsign * (half_shift * 0.5 + dsk);
357  int sign = ysign;
358  float y1 = ysign * (half_shift * 0.5 - 0.5 + bld + sign * 0.5);
359  //float yp1_mid = ysign * (half_shift*0.5 - 0.5 + bld + sign*0.25);
360  float y2 = ysign * (half_shift * 0.5 - 0.5 + bld);
361  float yp2_mid = ysign * (half_shift * 0.5 - 0.5 + bld - sign * 0.25);
362  float y3 = ysign * (half_shift * 0.5 - 0.5 + bld - sign * 0.5);
363  draw_line(x1, x2, y1, y1, 1, 1, p1_color);
364  //draw_line(x1, x2, yp1_mid, yp1_mid, 1, 3);
365  draw_line(x1, x2, y2, y2, 1, 1, p1_color);
366  draw_line(x1, x2, yp2_mid, yp2_mid, 1, 2);
367  draw_line(x1, x2, y3, y3, 1, 1, p2_color);
368  // Vertical lines
369  float x = xsign * (half_shift * 0.5 + dsk - 1);
370  draw_line(x, x, y1, y2, 1, 1, p1_color);
371  draw_line(x, x, y2, y3, 1, 1, p2_color);
372  if (ring == 2) {
373  //draw_line(x, x, y2, y3, 1, 1, p1_color);
374  x = xsign * (half_shift * 0.5 + dsk);
375  draw_line(x, x, y1, y2, 1, 1, p1_color);
376  draw_line(x, x, y2, y3, 1, 1, p2_color);
377  }
378  // Make a BOX around ROC 0
379  x1 = xsign * (half_shift * 0.5 + dsk - 1 / 8.);
380  x2 = xsign * (half_shift * 0.5 + dsk);
381  float y1_p1 = ysign * (half_shift * 0.5 - 0.5 + bld + sign * 0.25);
382  float y2_p1 = ysign * (half_shift * 0.5 - 0.5 + bld + sign * 0.25 + xsign * ysign * 0.25);
383  draw_line(x1, x2, y1_p1, y1_p1, 1);
384  //draw_line(x1, x2, y2_p1, y2_p1, 1);
385  draw_line(x1, x1, y1_p1, y2_p1, 1);
386  //draw_line(x2, x2, y1_p1, y2_p1, 1);
387  float y1_p2 = ysign * (half_shift * 0.5 - 0.5 + bld - sign * 0.25);
388  float y2_p2 = ysign * (half_shift * 0.5 - 0.5 + bld - sign * 0.25 - xsign * ysign * 0.25);
389  draw_line(x1, x2, y1_p2, y1_p2, 1);
390  //draw_line(x1, x2, y2_p2, y2_p2, 1);
391  draw_line(x1, x1, y1_p2, y2_p2, 1);
392  //draw_line(x2, x2, y1_p2, y2_p2, 1);
393  }
394  }
395  }
396  }
397  }
398  // Special shifted "rebin" for Phase 0
399  // Y axis should always have at least half-roc granularity because
400  // there are half-ROC size shifts implemented in the coordinates
401  // To remove this and show full ROC granularity
402  // We merge bin contents in each pair of bins corresponding to one ROC
403  // TODO: make sure this works for Profiles
404  if (phase == 0 && h->GetNbinsY() == 250 && h->GetNbinsX() == 80) {
405  int nentries = h->GetEntries();
406  for (int binx = 1; binx <= 80; ++binx) {
407  double sum = 0;
408  for (int biny = 1; biny <= 250; ++biny) {
409  bool odd_nrocy = (binx - 1 < 40) != (((binx - 1) / 4) % 2);
410  if (biny % 2 == odd_nrocy)
411  sum += h->GetBinContent(binx, biny);
412  else {
413  sum += h->GetBinContent(binx, biny);
414  if (sum) {
415  h->SetBinContent(binx, biny, sum);
416  h->SetBinContent(binx, biny - 1, sum);
417  }
418  sum = 0;
419  }
420  }
421  }
422  h->SetEntries(nentries);
423  }
424  }
425  }
426 
427  /*--------------------------------------------------------------------*/
428  std::pair<float, float> getExtrema(TH1* h1, TH1* h2)
429  /*--------------------------------------------------------------------*/
430  {
431  float theMax(-9999.);
432  float theMin(9999.);
433  theMax = h1->GetMaximum() > h2->GetMaximum() ? h1->GetMaximum() : h2->GetMaximum();
434  theMin = h1->GetMinimum() < h2->GetMaximum() ? h1->GetMinimum() : h2->GetMinimum();
435 
436  float add_min = theMin > 0. ? -0.05 : 0.05;
437  float add_max = theMax > 0. ? 0.05 : -0.05;
438 
439  auto result = std::make_pair(theMin * (1 + add_min), theMax * (1 + add_max));
440  return result;
441  }
442 
443  /*--------------------------------------------------------------------*/
445  /*--------------------------------------------------------------------*/
446  {
447  hist->SetStats(kFALSE);
448  hist->SetLineWidth(2);
449  hist->GetXaxis()->CenterTitle(true);
450  hist->GetYaxis()->CenterTitle(true);
451  hist->GetXaxis()->SetTitleFont(42);
452  hist->GetYaxis()->SetTitleFont(42);
453  hist->GetXaxis()->SetTitleSize(0.05);
454  hist->GetYaxis()->SetTitleSize(0.05);
455  hist->GetXaxis()->SetTitleOffset(1.1);
456  hist->GetYaxis()->SetTitleOffset(1.3);
457  hist->GetXaxis()->SetLabelFont(42);
458  hist->GetYaxis()->SetLabelFont(42);
459  hist->GetYaxis()->SetLabelSize(.05);
460  hist->GetXaxis()->SetLabelSize(.05);
461  }
462 
463  enum regions {
464  BPixL1o, //0 Barrel Pixel Layer 1 outer
465  BPixL1i, //1 Barrel Pixel Layer 1 inner
466  BPixL2o, //2 Barrel Pixel Layer 2 outer
467  BPixL2i, //3 Barrel Pixel Layer 2 inner
468  BPixL3o, //4 Barrel Pixel Layer 3 outer
469  BPixL3i, //5 Barrel Pixel Layer 3 inner
470  BPixL4o, //6 Barrel Pixel Layer 4 outer
471  BPixL4i, //7 Barrel Pixel Layer 4 inner
472  FPixmL1, //8 Forward Pixel Minus side Disk 1
473  FPixmL2, //9 Forward Pixel Minus side Disk 2
474  FPixmL3, //10 Forward Pixel Minus side Disk 3
475  FPixpL1, //11 Forward Pixel Plus side Disk 1
476  FPixpL2, //12 Forward Pixel Plus side Disk 2
477  FPixpL3, //13 Forward Pixel Plus side Disk 3
478  NUM_OF_REGIONS //14 -- default
479  };
480 
481  /*--------------------------------------------------------------------*/
483  /*--------------------------------------------------------------------*/
484  {
485  switch (e) {
486  case SiPixelPI::BPixL1o:
487  return "BPix L1/o";
488  case SiPixelPI::BPixL1i:
489  return "BPix L1/i";
490  case SiPixelPI::BPixL2o:
491  return "BPix L2/o";
492  case SiPixelPI::BPixL2i:
493  return "BPix L2/i";
494  case SiPixelPI::BPixL3o:
495  return "BPix L3/o";
496  case SiPixelPI::BPixL3i:
497  return "BPix L3/i";
498  case SiPixelPI::BPixL4o:
499  return "BPix L4/o";
500  case SiPixelPI::BPixL4i:
501  return "BPix L4/i";
502  case SiPixelPI::FPixmL1:
503  return "FPix- D1";
504  case SiPixelPI::FPixmL2:
505  return "FPix- D2";
506  case SiPixelPI::FPixmL3:
507  return "FPix- D3";
508  case SiPixelPI::FPixpL1:
509  return "FPix+ D1";
510  case SiPixelPI::FPixpL2:
511  return "FPix+ D2";
512  case SiPixelPI::FPixpL3:
513  return "FPix+ D3";
514  default:
515  edm::LogWarning("LogicError") << "Unknown partition: " << e;
516  return "";
517  }
518  }
519 
520  /*--------------------------------------------------------------------*/
521  bool isBPixOuterLadder(const DetId& detid, const TrackerTopology& tTopo, bool isPhase0)
522  /*--------------------------------------------------------------------*/
523  {
524  bool isOuter = false;
525  int layer = tTopo.pxbLayer(detid.rawId());
526  bool odd_ladder = tTopo.pxbLadder(detid.rawId()) % 2;
527  if (isPhase0) {
528  if (layer == 2)
529  isOuter = !odd_ladder;
530  else
531  isOuter = odd_ladder;
532  } else {
533  if (layer == 4)
534  isOuter = odd_ladder;
535  else
536  isOuter = !odd_ladder;
537  }
538  return isOuter;
539  }
540 
541  // ancillary struct to manage the topology
542  // info in a more compact way
543 
544  struct topolInfo {
545  private:
546  uint32_t m_rawid;
548  int m_layer;
549  int m_side;
550  int m_ring;
552 
553  public:
554  void init();
555  void fillGeometryInfo(const DetId& detId, const TrackerTopology& tTopo, bool isPhase0);
557  bool sanityCheck();
558  void printAll();
559  virtual ~topolInfo() {}
560  };
561 
562  /*--------------------------------------------------------------------*/
564  /*--------------------------------------------------------------------*/
565  {
566  std::cout << " detId:" << m_rawid << " subdetid: " << m_subdetid << " layer: " << m_layer << " side: " << m_side
567  << " ring: " << m_ring << " isInternal:" << m_isInternal << std::endl;
568  }
569 
570  /*--------------------------------------------------------------------*/
572  /*--------------------------------------------------------------------*/
573  {
574  m_rawid = 0;
575  m_subdetid = -1;
576  m_layer = -1;
577  m_side = -1;
578  m_ring = -1;
579  m_isInternal = false;
580  };
581 
582  /*--------------------------------------------------------------------*/
584  /*--------------------------------------------------------------------*/
585  {
586  if (m_layer == 0 || (m_subdetid == 1 && m_layer > 4) || (m_subdetid == 2 && m_layer > 3)) {
587  return false;
588  } else {
589  return true;
590  }
591  }
592  /*--------------------------------------------------------------------*/
593  void topolInfo::fillGeometryInfo(const DetId& detId, const TrackerTopology& tTopo, bool isPhase0)
594  /*--------------------------------------------------------------------*/
595  {
596  unsigned int subdetId = static_cast<unsigned int>(detId.subdetId());
597 
598  m_rawid = detId.rawId();
599  m_subdetid = subdetId;
600  if (subdetId == PixelSubdetector::PixelBarrel) {
601  m_layer = tTopo.pxbLayer(detId.rawId());
602  m_isInternal = !SiPixelPI::isBPixOuterLadder(detId, tTopo, isPhase0);
603  } else if (subdetId == PixelSubdetector::PixelEndcap) {
604  m_layer = tTopo.pxfDisk(detId.rawId());
605  m_side = tTopo.pxfSide(detId.rawId());
606  } else
607  edm::LogWarning("LogicError") << "Unknown subdetid: " << subdetId;
608  }
609 
610  // ------------ method to assign a partition based on the topology struct info ---------------
611 
612  /*--------------------------------------------------------------------*/
614  /*--------------------------------------------------------------------*/
615  {
617 
618  // BPix
619  if (m_subdetid == 1) {
620  switch (m_layer) {
621  case 1:
623  break;
624  case 2:
626  break;
627  case 3:
629  break;
630  case 4:
632  break;
633  default:
634  edm::LogWarning("LogicError") << "Unknow BPix layer: " << m_layer;
635  break;
636  }
637  // FPix
638  } else if (m_subdetid == 2) {
639  switch (m_layer) {
640  case 1:
641  m_side > 1 ? ret = SiPixelPI::FPixpL1 : ret = SiPixelPI::FPixmL1;
642  break;
643  case 2:
644  m_side > 1 ? ret = SiPixelPI::FPixpL2 : ret = SiPixelPI::FPixmL2;
645  break;
646  case 3:
647  m_side > 1 ? ret = SiPixelPI::FPixpL3 : ret = SiPixelPI::FPixmL3;
648  break;
649  default:
650  edm::LogWarning("LogicError") << "Unknow FPix disk: " << m_layer;
651  break;
652  }
653  }
654  return ret;
655  }
656 
657  // overloaded method: mask entire module
658  /*--------------------------------------------------------------------*/
659  std::vector<std::pair<int, int> > maskedBarrelRocsToBins(int layer, int ladder, int module)
660  /*--------------------------------------------------------------------*/
661  {
662  std::vector<std::pair<int, int> > rocsToMask;
663 
664  int nlad_list[4] = {6, 14, 22, 32};
665  int nlad = nlad_list[layer - 1];
666 
667  int start_x = module > 0 ? ((module + 4) * 8) + 1 : ((4 - (std::abs(module))) * 8) + 1;
668  int start_y = ladder > 0 ? ((ladder + nlad) * 2) + 1 : ((nlad - (std::abs(ladder))) * 2) + 1;
669 
670  int end_x = start_x + 7;
671  int end_y = start_y + 1;
672 
673  COUT << "module: " << module << " start_x:" << start_x << " end_x:" << end_x << std::endl;
674  COUT << "ladder: " << ladder << " start_y:" << start_y << " end_y:" << end_y << std::endl;
675  COUT << "==================================================================" << std::endl;
676 
677  for (int bin_x = 1; bin_x <= 72; bin_x++) {
678  for (int bin_y = 1; bin_y <= (nlad * 4 + 2); bin_y++) {
679  if (bin_x >= start_x && bin_x <= end_x && bin_y >= start_y && bin_y <= end_y) {
680  rocsToMask.push_back(std::make_pair(bin_x, bin_y));
681  }
682  }
683  }
684  return rocsToMask;
685  }
686 
687  // overloaded method: mask single ROCs
688  /*--------------------------------------------------------------------*/
689  std::vector<std::tuple<int, int, int> > maskedBarrelRocsToBins(
690  int layer, int ladder, int module, std::bitset<16> bad_rocs, bool isFlipped)
691  /*--------------------------------------------------------------------*/
692  {
693  std::vector<std::tuple<int, int, int> > rocsToMask;
694 
695  int nlad_list[4] = {6, 14, 22, 32};
696  int nlad = nlad_list[layer - 1];
697 
698  int start_x = module > 0 ? ((module + 4) * 8) + 1 : ((4 - (std::abs(module))) * 8) + 1;
699  int start_y = ladder > 0 ? ((ladder + nlad) * 2) + 1 : ((nlad - (std::abs(ladder))) * 2) + 1;
700 
701  int roc0_x = ((layer == 1) || (layer > 1 && module > 0)) ? start_x + 7 : start_x;
702  int roc0_y = start_y - 1;
703 
704  size_t idx = 0;
705  while (idx < bad_rocs.size()) {
706  if (bad_rocs.test(idx)) {
708  // | //
709  // In BPix Layer1 and module>0 in L2,3,4 | In BPix Layer 2,3,4 module > 0 //
710  // | //
711  // ROCs are ordered in the following | ROCs are ordered in the following //
712  // fashion for unplipped modules | fashion for unplipped modules //
713  // | //
714  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
715  // | 8 |9 |10 |11 |12 |13 |14 |15 | | |15 |14 |13 |12 |11 |10 | 9 | 8 | //
716  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
717  // | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | //
718  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
719  // | //
720  // if the module is flipped the ordering | if the module is flipped the ordering //
721  // is reveresed | is reversed //
722  // | //
723  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
724  // | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | //
725  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
726  // | 8 | 9 |10 |11 |12 |13 |14 |15 | | |15 |14 |13 |12 |11 |10 | 9 | 8 | //
727  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
729 
730  int roc_x(0), roc_y(0);
731 
732  if ((layer == 1) || (layer > 1 && module > 0)) {
733  if (!isFlipped) {
734  roc_x = idx < 8 ? roc0_x - idx : (start_x - 8) + idx;
735  roc_y = idx < 8 ? roc0_y + 1 : roc0_y + 2;
736  } else {
737  roc_x = idx < 8 ? roc0_x - idx : (start_x - 8) + idx;
738  roc_y = idx < 8 ? roc0_y + 2 : roc0_y + 1;
739  }
740  } else {
741  if (!isFlipped) {
742  roc_x = idx < 8 ? roc0_x + idx : (roc0_x + 7) - (idx - 8);
743  roc_y = idx < 8 ? roc0_y + 1 : roc0_y + 2;
744  } else {
745  roc_x = idx < 8 ? roc0_x + idx : (roc0_x + 7) - (idx - 8);
746  roc_y = idx < 8 ? roc0_y + 2 : roc0_y + 1;
747  }
748  }
749 
750  COUT << bad_rocs << " : (idx)= " << idx << std::endl;
751  COUT << " layer: " << layer << std::endl;
752  COUT << "module: " << module << " roc_x:" << roc_x << std::endl;
753  COUT << "ladder: " << ladder << " roc_y:" << roc_y << std::endl;
754  COUT << "==================================================================" << std::endl;
755 
756  rocsToMask.push_back(std::make_tuple(roc_x, roc_y, idx));
757  }
758  ++idx;
759  }
760  return rocsToMask;
761  }
762 
763  // overloaded method: mask entire module
764  /*--------------------------------------------------------------------*/
765  std::vector<std::pair<int, int> > maskedForwardRocsToBins(int ring, int blade, int panel, int disk)
766  /*--------------------------------------------------------------------*/
767  {
768  std::vector<std::pair<int, int> > rocsToMask;
769 
770  //int nblade_list[2] = {11, 17};
771  int nybins_list[2] = {92, 140};
772  //int nblade = nblade_list[ring - 1];
773  int nybins = nybins_list[ring - 1];
774 
775  int start_x = disk > 0 ? ((disk + 3) * 8) + 1 : ((3 - (std::abs(disk))) * 8) + 1;
776  //int start_y = blade > 0 ? ((blade+nblade)*4)-panel*2 : ((nblade-(std::abs(blade)))*4)-panel*2;
777  int start_y = blade > 0 ? (nybins / 2) + (blade * 4) - (panel * 2) + 3
778  : ((nybins / 2) - (std::abs(blade) * 4) - panel * 2) + 3;
779 
780  int end_x = start_x + 7;
781  int end_y = start_y + 1;
782 
783  COUT << "==================================================================" << std::endl;
784  COUT << "disk: " << disk << " start_x:" << start_x << " end_x:" << end_x << std::endl;
785  COUT << "blade: " << blade << " start_y:" << start_y << " end_y:" << end_y << std::endl;
786 
787  for (int bin_x = 1; bin_x <= 56; bin_x++) {
788  for (int bin_y = 1; bin_y <= nybins; bin_y++) {
789  if (bin_x >= start_x && bin_x <= end_x && bin_y >= start_y && bin_y <= end_y) {
790  rocsToMask.push_back(std::make_pair(bin_x, bin_y));
791  }
792  }
793  }
794  return rocsToMask;
795  }
796 
797  // overloaded method: mask single ROCs
798  /*--------------------------------------------------------------------*/
799  std::vector<std::tuple<int, int, int> > maskedForwardRocsToBins(
800  int ring, int blade, int panel, int disk, std::bitset<16> bad_rocs, bool isFlipped)
801  /*--------------------------------------------------------------------*/
802  {
803  std::vector<std::tuple<int, int, int> > rocsToMask;
804 
805  //int nblade_list[2] = {11, 17};
806  int nybins_list[2] = {92, 140};
807  //int nblade = nblade_list[ring - 1];
808  int nybins = nybins_list[ring - 1];
809 
810  int start_x = disk > 0 ? ((disk + 3) * 8) + 1 : ((3 - (std::abs(disk))) * 8) + 1;
811  //int start_y = blade > 0 ? ((blade+nblade)*4)-panel*2 : ((nblade-(std::abs(blade)))*4)-panel*2;
812  int start_y = blade > 0 ? (nybins / 2) + (blade * 4) - (panel * 2) + 3
813  : ((nybins / 2) - (std::abs(blade) * 4) - panel * 2) + 3;
814 
815  int roc0_x = disk > 0 ? start_x + 7 : start_x;
816  int roc0_y = start_y - 1;
817 
818  size_t idx = 0;
819  while (idx < bad_rocs.size()) {
820  if (bad_rocs.test(idx)) {
821  int roc_x(0), roc_y(0);
822 
824  // | //
825  // In FPix + (Disk 1,2,3) | In FPix - (Disk -1,-2,-3) //
826  // | //
827  // ROCs are ordered in the following | ROCs are ordered in the following //
828  // fashion for unplipped modules | fashion for unplipped modules //
829  // | //
830  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
831  // | 8 |9 |10 |11 |12 |13 |14 |15 | | |15 |14 |13 |12 |11 |10 | 9 | 8 | //
832  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
833  // | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | //
834  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
835  // | //
836  // if the module is flipped the ordering | if the module is flipped the ordering //
837  // is reveresed | is reversed //
838  // | //
839  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
840  // | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | //
841  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
842  // | 8 | 9 |10 |11 |12 |13 |14 |15 | | |15 |14 |13 |12 |11 |10 | 9 | 8 | //
843  // +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ //
845 
846  if (disk > 0) {
847  if (!isFlipped) {
848  roc_x = idx < 8 ? roc0_x - idx : (start_x - 8) + idx;
849  roc_y = idx < 8 ? roc0_y + 1 : roc0_y + 2;
850  } else {
851  roc_x = idx < 8 ? roc0_x - idx : (start_x - 8) + idx;
852  roc_y = idx < 8 ? roc0_y + 2 : roc0_y + 1;
853  }
854  } else {
855  if (!isFlipped) {
856  roc_x = idx < 8 ? roc0_x + idx : (roc0_x + 7) - (idx - 8);
857  roc_y = idx < 8 ? roc0_y + 1 : roc0_y + 2;
858  } else {
859  roc_x = idx < 8 ? roc0_x + idx : (roc0_x + 7) - (idx - 8);
860  roc_y = idx < 8 ? roc0_y + 2 : roc0_y + 1;
861  }
862  }
863 
864  COUT << bad_rocs << " : (idx)= " << idx << std::endl;
865  COUT << " panel: " << panel << " isFlipped: " << isFlipped << std::endl;
866  COUT << " disk: " << disk << " roc_x:" << roc_x << std::endl;
867  COUT << " blade: " << blade << " roc_y:" << roc_y << std::endl;
868  COUT << "===============================" << std::endl;
869 
870  rocsToMask.push_back(std::make_tuple(roc_x, roc_y, idx));
871  }
872  ++idx;
873  }
874  return rocsToMask;
875  }
876 
877 }; // namespace SiPixelPI
878 #endif
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
int signed_blade_panel(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
int moduleName() const
module id (index in z)
ret
prodAgent to be discontinued
static const unsigned int phase0size
unsigned int pxfDisk(const DetId &id) const
int quadrant(const DetId &detid, const TrackerTopology *tTopo_, bool phase_)
unsigned int pxbLadder(const DetId &id) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const Time_t kLowMask(0xFFFFFFFF)
std::pair< float, float > getExtrema(TH1 *h1, TH1 *h2)
int bladeName() const
blade id
std::vector< std::pair< int, int > > maskedForwardRocsToBins(int ring, int blade, int panel, int disk)
int signed_ladder(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
unsigned long long Time_t
Definition: Time.h:14
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_)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
SiPixelPI::regions filterThePartition()
void draw_line(double x1, double x2, double y1, double y2, int width=2, int style=1, int color=1)
unsigned int pxfModule(const DetId &id) const
unsigned int pxbLayer(const DetId &id) const
std::vector< std::pair< int, int > > maskedBarrelRocsToBins(int layer, int ladder, int module)
int ring(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Definition: DetId.h:17
void makeNicePlotStyle(TH1 *hist)
int ladderName() const
ladder id (index in phi)
int signed_module(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Shell shell() const
bool isBPixOuterLadder(const DetId &detid, const TrackerTopology &tTopo, bool isPhase0)
unsigned int pxfSide(const DetId &id) const
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)
int ringName() const
ring Id
HalfCylinder halfCylinder() const
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
Definition: vlib.h:198
unsigned int pxfPanel(const DetId &id) const
void fillGeometryInfo(const DetId &detId, const TrackerTopology &tTopo, bool isPhase0)