CMS 3D CMS Logo

AlignmentPayloadInspectorHelper.h
Go to the documentation of this file.
1 #ifndef CONDCORE_ALIGNMENTPLUGINS_ALIGNMENTPAYLOADINSPECTORHELPER_H
2 #define CONDCORE_ALIGNMENTPLUGINS_ALIGNMENTPAYLOADINSPECTORHELPER_H
3 
4 #include <iostream>
5 #include <algorithm>
6 #include <vector>
7 #include <numeric>
8 #include <string>
9 #include "TH1.h"
10 #include "TCanvas.h"
11 #include "TPaveStats.h"
12 #include "TStyle.h"
13 #include "TList.h"
18 #include "DataFormats/Math/interface/Rounding.h" // for rounding
19 
20 //#define MMDEBUG // uncomment for debugging at compile time
21 #ifdef MMDEBUG
22 #include <iostream>
23 #define COUT std::cout << "MM "
24 #else
25 #define COUT edm::LogVerbatim("")
26 #endif
27 
28 namespace AlignmentPI {
29 
30  // size of the phase-I Tracker APE payload (including both SS + DS modules)
31  static const unsigned int phase0size = 19876;
32  static const float cmToUm = 10000.f;
33  static const float tomRad = 1000.f;
34 
35  // method to zero all elements whose difference from 2Pi
36  // is less than the tolerance (2*10e-7)
37  inline float returnZeroIfNear2PI(const float phi) {
38  const double tol = 2.e-7; // default tolerance 1.e-7 doesn't account for possible variations
39  if (cms_rounding::roundIfNear0(std::abs(phi) - 2 * M_PI, tol) == 0.f) {
40  return 0.f;
41  } else {
42  return phi;
43  }
44  }
45 
46  enum coordinate {
47  t_x = 1,
48  t_y = 2,
49  t_z = 3,
50  rot_alpha = 4,
51  rot_beta = 5,
52  rot_gamma = 6,
53  };
54 
55  // M.M. 2017/09/12
56  // As the matrix is symmetric, we map only 6/9 terms
57  // More terms for the extended APE can be added to the following methods
58 
59  enum index { XX = 1, XY = 2, XZ = 3, YZ = 4, YY = 5, ZZ = 6 };
60 
61  enum partitions { BPix = 1, FPix = 2, TIB = 3, TID = 4, TOB = 5, TEC = 6 };
62 
63  enum class PARTITION {
64  BPIX, // 0 Barrel Pixel
65  FPIXp, // 1 Forward Pixel Plus
66  FPIXm, // 2 Forward Pixel Minus
67  TIB, // 3 Tracker Inner Barrel
68  TIDp, // 4 Tracker Inner Disks Plus
69  TIDm, // 5 Tracker Inner Disks Minus
70  TOB, // 6 Tracker Outer Barrel
71  TECp, // 7 Tracker Endcaps Plus
72  TECm, // 8 Tracker Endcaps Minus
73  LAST = TECm
74  };
75 
76  extern const PARTITION PARTITIONS[(int)PARTITION::LAST + 1];
86 
87  inline std::ostream& operator<<(std::ostream& o, PARTITION x) {
89  }
90 
91  enum regions {
92  BPixL1o, //0 Barrel Pixel Layer 1 outer
93  BPixL1i, //1 Barrel Pixel Layer 1 inner
94  BPixL2o, //2 Barrel Pixel Layer 2 outer
95  BPixL2i, //3 Barrel Pixel Layer 2 inner
96  BPixL3o, //4 Barrel Pixel Layer 3 outer
97  BPixL3i, //5 Barrel Pixel Layer 3 inner
98  BPixL4o, //6 Barrel Pixel Layer 4 outer
99  BPixL4i, //7 Barrel Pixel Layer 4 inner
100  FPixmL1, //8 Forward Pixel Minus side Disk 1
101  FPixmL2, //9 Forward Pixel Minus side Disk 2
102  FPixmL3, //10 Forward Pixel Minus side Disk 3
103  FPixpL1, //11 Forward Pixel Plus side Disk 1
104  FPixpL2, //12 Forward Pixel Plus side Disk 2
105  FPixpL3, //13 Forward Pixel Plus side Disk 3
106  TIBL1Ro, //14 Inner Barrel Layer 1 Rphi outer
107  TIBL1Ri, //15 Inner Barrel Layer 1 Rphi inner
108  TIBL1So, //16 Inner Barrel Layer 1 Stereo outer
109  TIBL1Si, //17 Inner Barrel Layer 1 Stereo inner
110  TIBL2Ro, //18 Inner Barrel Layer 2 Rphi outer
111  TIBL2Ri, //19 Inner Barrel Layer 2 Rphi inner
112  TIBL2So, //20 Inner Barrel Layer 2 Stereo outer
113  TIBL2Si, //21 Inner Barrel Layer 2 Stereo inner
114  TIBL3o, //22 Inner Barrel Layer 3 outer
115  TIBL3i, //23 Inner Barrel Layer 3 inner
116  TIBL4o, //24 Inner Barrel Layer 4 outer
117  TIBL4i, //25 Inner Barrel Layer 4 inner
118  TOBL1Ro, //26 Outer Barrel Layer 1 Rphi outer
119  TOBL1Ri, //27 Outer Barrel Layer 1 Rphi inner
120  TOBL1So, //28 Outer Barrel Layer 1 Stereo outer
121  TOBL1Si, //29 Outer Barrel Layer 1 Stereo inner
122  TOBL2Ro, //30 Outer Barrel Layer 2 Rphi outer
123  TOBL2Ri, //31 Outer Barrel Layer 2 Rphi inner
124  TOBL2So, //32 Outer Barrel Layer 2 Stereo outer
125  TOBL2Si, //33 Outer Barrel Layer 2 Stereo inner
126  TOBL3o, //34 Outer Barrel Layer 3 outer
127  TOBL3i, //35 Outer Barrel Layer 3 inner
128  TOBL4o, //36 Outer Barrel Layer 4 outer
129  TOBL4i, //37 Outer Barrel Layer 4 inner
130  TOBL5o, //38 Outer Barrel Layer 5 outer
131  TOBL5i, //39 Outer Barrel Layer 5 inner
132  TOBL6o, //40 Outer Barrel Layer 6 outer
133  TOBL6i, //41 Outer Barrel Layer 6 inner
134  TIDmR1R, //42 Inner Disk Minus side Ring 1 Rphi
135  TIDmR1S, //43 Inner Disk Minus side Ring 1 Stereo
136  TIDmR2R, //44 Inner Disk Minus side Ring 2 Rphi
137  TIDmR2S, //45 Inner Disk Minus side Ring 2 Stereo
138  TIDmR3, //46 Inner Disk Minus side Ring 3
139  TIDpR1R, //47 Inner Disk Plus side Ring 1 Rphi
140  TIDpR1S, //48 Inner Disk Plus side Ring 1 Stereo
141  TIDpR2R, //49 Inner Disk Plus side Ring 2 Rphi
142  TIDpR2S, //50 Inner Disk Plus side Ring 2 Stereo
143  TIDpR3, //51 Inner Disk Plus side Ring 3
144  TECmR1R, //52 Endcaps Minus side Ring 1 Rphi
145  TECmR1S, //53 Endcaps Minus side Ring 1 Stereo
146  TECmR2R, //54 Encdaps Minus side Ring 2 Rphi
147  TECmR2S, //55 Endcaps Minus side Ring 2 Stereo
148  TECmR3, //56 Endcaps Minus side Ring 3
149  TECmR4, //57 Endcaps Minus side Ring 4
150  TECmR5, //58 Endcaps Minus side Ring 5
151  TECmR6, //59 Endcaps Minus side Ring 6
152  TECmR7, //60 Endcaps Minus side Ring 7
153  TECpR1R, //61 Endcaps Plus side Ring 1 Rphi
154  TECpR1S, //62 Endcaps Plus side Ring 1 Stereo
155  TECpR2R, //63 Encdaps Plus side Ring 2 Rphi
156  TECpR2S, //64 Endcaps Plus side Ring 2 Stereo
157  TECpR3, //65 Endcaps Plus side Ring 3
158  TECpR4, //66 Endcaps Plus side Ring 4
159  TECpR5, //67 Endcaps Plus side Ring 5
160  TECpR6, //68 Endcaps Plus side Ring 6
161  TECpR7, //67 Endcaps Plus side Ring 7
162  StripDoubleSide, // 70 -- not to be considered
163  NUM_OF_REGIONS // 71 -- default
164  };
165 
166  /*--------------------------------------------------------------------*/
168  /*--------------------------------------------------------------------*/
169  {
170  switch (e) {
172  return "BPixL1o";
174  return "BPixL1i";
176  return "BPixL2o";
178  return "BPixL2i";
180  return "BPixL3o";
182  return "BPixL3i";
184  return "BPixL4o";
186  return "BPixL4i";
188  return "FPixmL1";
190  return "FPixmL2";
192  return "FPixmL3";
194  return "FPixpL1";
196  return "FPixpL2";
198  return "FPixpL3";
200  return "TIBL1Ro";
202  return "TIBL1Ri";
204  return "TIBL1So";
206  return "TIBL1Si";
208  return "TIBL2Ro";
210  return "TIBL2Ri";
212  return "TIBL2So";
214  return "TIBL2Si";
215  case AlignmentPI::TIBL3o:
216  return "TIBL3o";
217  case AlignmentPI::TIBL3i:
218  return "TIBL3i";
219  case AlignmentPI::TIBL4o:
220  return "TIBL4o";
221  case AlignmentPI::TIBL4i:
222  return "TIBL4i";
224  return "TOBL1Ro";
226  return "TOBL1Ri";
228  return "TOBL1So";
230  return "TOBL1Si";
232  return "TOBL2Ro";
234  return "TOBL2Ri";
236  return "TOBL2So";
238  return "TOBL2Si";
239  case AlignmentPI::TOBL3o:
240  return "TOBL3o";
241  case AlignmentPI::TOBL3i:
242  return "TOBL3i";
243  case AlignmentPI::TOBL4o:
244  return "TOBL4o";
245  case AlignmentPI::TOBL4i:
246  return "TOBL4i";
247  case AlignmentPI::TOBL5o:
248  return "TOBL5o";
249  case AlignmentPI::TOBL5i:
250  return "TOBL5i";
251  case AlignmentPI::TOBL6o:
252  return "TOBL6o";
253  case AlignmentPI::TOBL6i:
254  return "TOBL6i";
256  return "TIDmR1R";
258  return "TIDmR1S";
260  return "TIDmR2R";
262  return "TIDmR2S";
263  case AlignmentPI::TIDmR3:
264  return "TIDmR3";
266  return "TIDpR1R";
268  return "TIDpR1S";
270  return "TIDpR2R";
272  return "TIDpR2S";
273  case AlignmentPI::TIDpR3:
274  return "TIDpR3";
276  return "TECmR1R";
278  return "TECmR1S";
280  return "TECmR2R";
282  return "TECmR2S";
283  case AlignmentPI::TECmR3:
284  return "TECmR3";
285  case AlignmentPI::TECmR4:
286  return "TECmR4";
287  case AlignmentPI::TECmR5:
288  return "TECmR5";
289  case AlignmentPI::TECmR6:
290  return "TECmR6";
291  case AlignmentPI::TECmR7:
292  return "TECmR7";
294  return "TECpR1R";
296  return "TECpR1S";
298  return "TECpR2R";
300  return "TECpR2S";
301  case AlignmentPI::TECpR3:
302  return "TECpR3";
303  case AlignmentPI::TECpR4:
304  return "TECpR4";
305  case AlignmentPI::TECpR5:
306  return "TECpR5";
307  case AlignmentPI::TECpR6:
308  return "TECpR6";
309  case AlignmentPI::TECpR7:
310  return "TECpR7";
311  default:
312  edm::LogWarning("LogicError") << "Unknown partition: " << e;
313  return "";
314  }
315  }
316 
317  /*--------------------------------------------------------------------*/
318  inline bool isBPixOuterLadder(const DetId& detid, const TrackerTopology& tTopo, bool isPhase0)
319  /*--------------------------------------------------------------------*/
320  {
321  bool isOuter = false;
322  int layer = tTopo.pxbLayer(detid.rawId());
323  bool odd_ladder = tTopo.pxbLadder(detid.rawId()) % 2;
324  if (isPhase0) {
325  if (layer == 2)
326  isOuter = !odd_ladder;
327  else
328  isOuter = odd_ladder;
329  } else {
330  if (layer == 4)
331  isOuter = odd_ladder;
332  else
333  isOuter = !odd_ladder;
334  }
335  return isOuter;
336  }
337 
338  // ancillary struct to manage the topology
339  // info in a more compact way
340 
341  struct topolInfo {
342  private:
343  uint32_t m_rawid;
345  int m_layer;
346  int m_side;
347  int m_ring;
348  bool m_isRphi;
351 
352  public:
353  void init();
354  void fillGeometryInfo(const DetId& detId, const TrackerTopology& tTopo, bool isPhase0);
356  bool sanityCheck();
357  void printAll();
358  virtual ~topolInfo() {}
359  };
360 
361  /*--------------------------------------------------------------------*/
362  inline void topolInfo::printAll()
363  /*--------------------------------------------------------------------*/
364  {
365  std::cout << " detId:" << m_rawid << " subdetid: " << m_subdetid << " layer: " << m_layer << " side: " << m_side
366  << " ring: " << m_ring << " isRphi:" << m_isRphi << " isDoubleSide:" << m_isDoubleSide
367  << " isInternal:" << m_isInternal << std::endl;
368  }
369 
370  /*--------------------------------------------------------------------*/
371  inline void topolInfo::init()
372  /*--------------------------------------------------------------------*/
373  {
374  m_rawid = 0;
375  m_subdetid = -1;
376  m_layer = -1;
377  m_side = -1;
378  m_ring = -1;
379  m_isRphi = false;
380  m_isDoubleSide = false;
381  m_isInternal = false;
382  };
383 
384  /*--------------------------------------------------------------------*/
386  /*--------------------------------------------------------------------*/
387  {
388  if (m_layer == 0 || (m_subdetid == 1 && m_layer > 4) || (m_subdetid == 2 && m_layer > 3)) {
389  return false;
390  } else {
391  return true;
392  }
393  }
394  /*--------------------------------------------------------------------*/
395  inline void topolInfo::fillGeometryInfo(const DetId& detId, const TrackerTopology& tTopo, bool isPhase0)
396  /*--------------------------------------------------------------------*/
397  {
398  unsigned int subdetId = static_cast<unsigned int>(detId.subdetId());
399 
400  m_rawid = detId.rawId();
401  m_subdetid = subdetId;
402 
403  if (subdetId == StripSubdetector::TIB) {
404  m_layer = tTopo.tibLayer(detId.rawId());
405  m_side = tTopo.tibSide(detId.rawId());
406  m_isRphi = tTopo.isRPhi(detId.rawId());
407  m_isDoubleSide = tTopo.tibIsDoubleSide(detId.rawId());
408  m_isInternal = tTopo.tibIsInternalString(detId.rawId());
409  } else if (subdetId == StripSubdetector::TOB) {
410  m_layer = tTopo.tobLayer(detId.rawId());
411  m_side = tTopo.tobSide(detId.rawId());
412  m_isRphi = tTopo.isRPhi(detId.rawId());
413  m_isDoubleSide = tTopo.tobIsDoubleSide(detId.rawId());
414  m_isInternal = tTopo.tobModule(detId.rawId()) % 2;
415  } else if (subdetId == StripSubdetector::TID) {
416  m_layer = tTopo.tidWheel(detId.rawId());
417  m_side = tTopo.tidSide(detId.rawId());
418  m_isRphi = tTopo.isRPhi(detId.rawId());
419  m_ring = tTopo.tidRing(detId.rawId());
420  m_isDoubleSide = tTopo.tidIsDoubleSide(detId.rawId());
421  m_isInternal = tTopo.tidModuleInfo(detId.rawId())[0];
422  } else if (subdetId == StripSubdetector::TEC) {
423  m_layer = tTopo.tecWheel(detId.rawId());
424  m_side = tTopo.tecSide(detId.rawId());
425  m_isRphi = tTopo.isRPhi(detId.rawId());
426  m_ring = tTopo.tecRing(detId.rawId());
427  m_isDoubleSide = tTopo.tecIsDoubleSide(detId.rawId());
428  m_isInternal = tTopo.tecPetalInfo(detId.rawId())[0];
429  } else if (subdetId == PixelSubdetector::PixelBarrel) {
430  m_layer = tTopo.pxbLayer(detId.rawId());
431  m_isInternal = !AlignmentPI::isBPixOuterLadder(detId, tTopo, isPhase0);
432  } else if (subdetId == PixelSubdetector::PixelEndcap) {
433  m_layer = tTopo.pxfDisk(detId.rawId());
434  m_side = tTopo.pxfSide(detId.rawId());
435  } else
436  edm::LogWarning("LogicError") << "Unknown subdetid: " << subdetId;
437  }
438 
439  // ------------ method to assign a partition based on the topology struct info ---------------
440 
441  /*--------------------------------------------------------------------*/
443  /*--------------------------------------------------------------------*/
444  {
446 
447  if (m_isDoubleSide) {
449  }
450 
451  // BPix
452  if (m_subdetid == 1) {
453  switch (m_layer) {
454  case 1:
456  break;
457  case 2:
459  break;
460  case 3:
462  break;
463  case 4:
465  break;
466  default:
467  edm::LogWarning("LogicError") << "Unknow BPix layer: " << m_layer;
468  break;
469  }
470  // FPix
471  } else if (m_subdetid == 2) {
472  switch (m_layer) {
473  case 1:
475  break;
476  case 2:
478  break;
479  case 3:
481  break;
482  default:
483  edm::LogWarning("LogicError") << "Unknow FPix disk: " << m_layer;
484  break;
485  }
486  // TIB
487  } else if (m_subdetid == 3) {
488  switch (m_layer) {
489  case 1:
490  if (m_isRphi) {
492  } else {
494  }
495  break;
496  case 2:
497  if (m_isRphi) {
499  } else {
501  }
502  break;
503  case 3:
505  break;
506  case 4:
508  break;
509  default:
510  edm::LogWarning("LogicError") << "Unknow TIB layer: " << m_layer;
511  break;
512  }
513  // TID
514  } else if (m_subdetid == 4) {
515  switch (m_ring) {
516  case 1:
517  if (m_isRphi) {
519  } else {
521  }
522  break;
523  case 2:
524  if (m_isRphi) {
526  } else {
528  }
529  break;
530  case 3:
532  break;
533  default:
534  edm::LogWarning("LogicError") << "Unknow TID wheel: " << m_layer;
535  break;
536  }
537  // TOB
538  } else if (m_subdetid == 5) {
539  switch (m_layer) {
540  case 1:
541  if (m_isRphi) {
543  } else {
545  }
546  break;
547  case 2:
548  if (m_isRphi) {
550  } else {
552  }
553  break;
554  case 3:
556  break;
557  case 4:
559  break;
560  case 5:
562  break;
563  case 6:
565  break;
566  default:
567  edm::LogWarning("LogicError") << "Unknow TOB layer: " << m_layer;
568  break;
569  }
570  // TEC
571  } else if (m_subdetid == 6) {
572  switch (m_ring) {
573  case 1:
574  if (m_isRphi) {
576  } else {
578  }
579  break;
580  case 2:
581  if (m_isRphi) {
583  } else {
585  }
586  break;
587  case 3:
589  break;
590  case 4:
592  break;
593  case 5:
595  break;
596  case 6:
598  break;
599  case 7:
601  break;
602  default:
603  edm::LogWarning("LogicError") << "Unknow TEC ring: " << m_ring;
604  break;
605  }
606  }
607 
608  return ret;
609  }
610 
611  /*--------------------------------------------------------------------*/
613  /*--------------------------------------------------------------------*/
614  {
615  switch (coord) {
616  case t_x:
617  return "x-translation";
618  case t_y:
619  return "y-translation";
620  case t_z:
621  return "z-translation";
622  case rot_alpha:
623  return "#alpha angle rotation";
624  case rot_beta:
625  return "#beta angle rotation";
626  case rot_gamma:
627  return "#gamma angle rotation";
628  default:
629  return "should never be here!";
630  }
631  }
632 
633  /*--------------------------------------------------------------------*/
635  /*--------------------------------------------------------------------*/
636  {
637  switch (i) {
638  case XX:
639  return "XX";
640  case XY:
641  return "XY";
642  case XZ:
643  return "XZ";
644  case YZ:
645  return "YX";
646  case YY:
647  return "YY";
648  case ZZ:
649  return "ZZ";
650  default:
651  return "should never be here!";
652  }
653  }
654 
655  /*--------------------------------------------------------------------*/
657  /*--------------------------------------------------------------------*/
658  {
659  switch (i) {
660  case BPix:
661  return "BPix";
662  case FPix:
663  return "FPix";
664  case TIB:
665  return "TIB";
666  case TID:
667  return "TID";
668  case TOB:
669  return "TOB";
670  case TEC:
671  return "TEC";
672  default:
673  return "should never be here!";
674  }
675  }
676 
677  /*--------------------------------------------------------------------*/
678  inline std::pair<int, int> getIndices(AlignmentPI::index i)
679  /*--------------------------------------------------------------------*/
680  {
681  switch (i) {
682  case XX:
683  return std::make_pair(0, 0);
684  case XY:
685  return std::make_pair(0, 1);
686  case XZ:
687  return std::make_pair(0, 2);
688  case YZ:
689  return std::make_pair(1, 0);
690  case YY:
691  return std::make_pair(1, 1);
692  case ZZ:
693  return std::make_pair(2, 2);
694  default:
695  return std::make_pair(-1, -1);
696  }
697  }
698 
699  /*--------------------------------------------------------------------*/
700  inline void makeNicePlotStyle(TH1* hist, int color)
701  /*--------------------------------------------------------------------*/
702  {
703  hist->SetStats(kFALSE);
704 
705  hist->GetXaxis()->SetTitleColor(color);
706  hist->SetLineColor(color);
707  hist->SetTitleSize(0.08);
708  hist->SetLineWidth(2);
709  hist->GetXaxis()->CenterTitle(true);
710  hist->GetYaxis()->CenterTitle(true);
711  hist->GetXaxis()->SetTitleFont(42);
712  hist->GetYaxis()->SetTitleFont(42);
713  hist->GetXaxis()->SetNdivisions(505);
714  hist->GetXaxis()->SetTitleSize(0.06);
715  hist->GetYaxis()->SetTitleSize(0.06);
716  hist->GetXaxis()->SetTitleOffset(1.0);
717  hist->GetYaxis()->SetTitleOffset(1.3);
718  hist->GetXaxis()->SetLabelFont(42);
719  hist->GetYaxis()->SetLabelFont(42);
720  hist->GetYaxis()->SetLabelSize(.05);
721  hist->GetXaxis()->SetLabelSize(.05);
722  }
723 
724  /*--------------------------------------------------------------------*/
725  inline void makeNiceStats(TH1F* hist, AlignmentPI::partitions part, int color)
726  /*--------------------------------------------------------------------*/
727  {
728  char buffer[255];
729  TPaveText* stat = new TPaveText(0.60, 0.75, 0.95, 0.95, "NDC");
730  sprintf(buffer, "%s \n", AlignmentPI::getStringFromPart(part).c_str());
731  stat->AddText(buffer);
732 
733  sprintf(buffer, "Entries : %i\n", (int)hist->GetEntries());
734  stat->AddText(buffer);
735 
736  if (std::abs(hist->GetMean()) > 0.01) {
737  sprintf(buffer, "Mean : %6.2f\n", hist->GetMean());
738  } else {
739  sprintf(buffer, "Mean : %6.2f e-2\n", 100 * hist->GetMean());
740  }
741  stat->AddText(buffer);
742 
743  if (std::abs(hist->GetRMS()) > 0.01) {
744  sprintf(buffer, "RMS : %6.2f\n", hist->GetRMS());
745  } else {
746  sprintf(buffer, "RMS : %6.2f e-2\n", 100 * hist->GetRMS());
747  }
748  stat->AddText(buffer);
749 
750  stat->SetLineColor(color);
751  stat->SetTextColor(color);
752  stat->SetFillColor(10);
753  stat->SetShadowColor(10);
754  stat->Draw();
755  }
756 
757  /*--------------------------------------------------------------------*/
758  inline std::pair<float, float> getTheRange(std::map<uint32_t, float> values, const float nsigma)
759  /*--------------------------------------------------------------------*/
760  {
761  float sum = std::accumulate(
762  std::begin(values), std::end(values), 0.0, [](float value, const std::map<uint32_t, float>::value_type& p) {
763  return value + p.second;
764  });
765 
766  float m = sum / values.size();
767 
768  float accum = 0.0;
769  std::for_each(std::begin(values), std::end(values), [&](const std::map<uint32_t, float>::value_type& p) {
770  accum += (p.second - m) * (p.second - m);
771  });
772 
773  float stdev = sqrt(accum / (values.size() - 1));
774 
775  if (stdev != 0.) {
776  return std::make_pair(m - nsigma * stdev, m + nsigma * stdev);
777  } else {
778  return std::make_pair(m > 0. ? 0.95 * m : 1.05 * m, m > 0 ? 1.05 * m : 0.95 * m);
779  }
780  }
781 
782  /*--------------------------------------------------------------------*/
783  inline std::pair<double, double> calculatePosition(TVirtualPad* myPad, int boundary)
784  /*--------------------------------------------------------------------*/
785  {
786  int ix1;
787  int ix2;
788  int iw = myPad->GetWw();
789  int ih = myPad->GetWh();
790  double x1p, y1p, x2p, y2p;
791  myPad->GetPadPar(x1p, y1p, x2p, y2p);
792  ix1 = (int)(iw * x1p);
793  ix2 = (int)(iw * x2p);
794  double wndc = std::min(1., (double)iw / (double)ih);
795  double rw = wndc / (double)iw;
796  double x1ndc = (double)ix1 * rw;
797  double x2ndc = (double)ix2 * rw;
798  double rx1, ry1, rx2, ry2;
799  myPad->GetRange(rx1, ry1, rx2, ry2);
800  double rx = (x2ndc - x1ndc) / (rx2 - rx1);
801  double _sx;
802  _sx = rx * (boundary - rx1) + x1ndc;
803  double _dx = _sx + 0.05;
804 
805  return std::make_pair(_sx, _dx);
806  }
807 
808  // ancillary struct to manage the barycenters
809  // info in a more compact way
810 
812  std::map<AlignmentPI::PARTITION, double> Xbarycenters;
813  std::map<AlignmentPI::PARTITION, double> Ybarycenters;
814  std::map<AlignmentPI::PARTITION, double> Zbarycenters;
815  std::map<AlignmentPI::PARTITION, double> nmodules;
816 
817  public:
818  void init();
820  void computeBarycenters(const std::vector<AlignTransform>& input,
821  const TrackerTopology& tTopo,
822  const std::map<AlignmentPI::coordinate, float>& GPR);
823  const double getNModules(AlignmentPI::PARTITION p) { return nmodules[p]; };
824 
825  // M.M. 2020/01/09
826  // introduce methods for entire partitions, summing up the two sides of the
827  // endcap detectors
828 
829  /*--------------------------------------------------------------------*/
830  const std::array<double, 6> getX()
831  /*--------------------------------------------------------------------*/
832  {
833  return {{Xbarycenters[PARTITION::BPIX],
839  };
840 
841  /*--------------------------------------------------------------------*/
842  const std::array<double, 6> getY()
843  /*--------------------------------------------------------------------*/
844  {
845  return {{Ybarycenters[PARTITION::BPIX],
851  };
852 
853  /*--------------------------------------------------------------------*/
854  const std::array<double, 6> getZ()
855  /*--------------------------------------------------------------------*/
856  {
857  return {{Zbarycenters[PARTITION::BPIX],
863  };
864  virtual ~TkAlBarycenters() {}
865  };
866 
867  /*--------------------------------------------------------------------*/
869  /*--------------------------------------------------------------------*/
870  {
872  }
873 
874  /*--------------------------------------------------------------------*/
875  inline void TkAlBarycenters::computeBarycenters(const std::vector<AlignTransform>& input,
876  const TrackerTopology& tTopo,
877  const std::map<AlignmentPI::coordinate, float>& GPR)
878  /*--------------------------------------------------------------------*/
879  {
880  // zero in the n. modules per partition...
881  for (const auto& p : PARTITIONS) {
882  nmodules[p] = 0.;
883  }
884 
885  for (const auto& ali : input) {
886  if (DetId(ali.rawId()).det() != DetId::Tracker) {
887  edm::LogWarning("TkAlBarycenters::computeBarycenters")
888  << "Encountered invalid Tracker DetId:" << ali.rawId() << " " << DetId(ali.rawId()).det()
889  << " is different from " << DetId::Tracker << " - terminating ";
890  assert(DetId(ali.rawId()).det() != DetId::Tracker);
891  }
892 
893  int subid = DetId(ali.rawId()).subdetId();
894  switch (subid) {
896  Xbarycenters[PARTITION::BPIX] += (ali.translation().x());
897  Ybarycenters[PARTITION::BPIX] += (ali.translation().y());
898  Zbarycenters[PARTITION::BPIX] += (ali.translation().z());
900  break;
902 
903  // minus side
904  if (tTopo.pxfSide(DetId(ali.rawId())) == 1) {
905  Xbarycenters[PARTITION::FPIXm] += (ali.translation().x());
906  Ybarycenters[PARTITION::FPIXm] += (ali.translation().y());
907  Zbarycenters[PARTITION::FPIXm] += (ali.translation().z());
909  } // plus side
910  else {
911  Xbarycenters[PARTITION::FPIXp] += (ali.translation().x());
912  Ybarycenters[PARTITION::FPIXp] += (ali.translation().y());
913  Zbarycenters[PARTITION::FPIXp] += (ali.translation().z());
915  }
916  break;
918  Xbarycenters[PARTITION::TIB] += (ali.translation().x());
919  Ybarycenters[PARTITION::TIB] += (ali.translation().y());
920  Zbarycenters[PARTITION::TIB] += (ali.translation().z());
922  break;
924  // minus side
925  if (tTopo.tidSide(DetId(ali.rawId())) == 1) {
926  Xbarycenters[PARTITION::TIDm] += (ali.translation().x());
927  Ybarycenters[PARTITION::TIDm] += (ali.translation().y());
928  Zbarycenters[PARTITION::TIDm] += (ali.translation().z());
930  } // plus side
931  else {
932  Xbarycenters[PARTITION::TIDp] += (ali.translation().x());
933  Ybarycenters[PARTITION::TIDp] += (ali.translation().y());
934  Zbarycenters[PARTITION::TIDp] += (ali.translation().z());
936  }
937  break;
939  Xbarycenters[PARTITION::TOB] += (ali.translation().x());
940  Ybarycenters[PARTITION::TOB] += (ali.translation().y());
941  Zbarycenters[PARTITION::TOB] += (ali.translation().z());
943  break;
945  // minus side
946  if (tTopo.tecSide(DetId(ali.rawId())) == 1) {
947  Xbarycenters[PARTITION::TECm] += (ali.translation().x());
948  Ybarycenters[PARTITION::TECm] += (ali.translation().y());
949  Zbarycenters[PARTITION::TECm] += (ali.translation().z());
951  } // plus side
952  else {
953  Xbarycenters[PARTITION::TECp] += (ali.translation().x());
954  Ybarycenters[PARTITION::TECp] += (ali.translation().y());
955  Zbarycenters[PARTITION::TECp] += (ali.translation().z());
957  }
958  break;
959  default:
960  edm::LogError("TrackerAlignment_PayloadInspector") << "Unrecognized partition " << subid << std::endl;
961  break;
962  }
963  }
964 
965  for (const auto& p : PARTITIONS) {
966  // take the arithmetic mean
967  Xbarycenters[p] /= nmodules[p];
968  Ybarycenters[p] /= nmodules[p];
969  Zbarycenters[p] /= nmodules[p];
970 
971  // add the Tracker Global Position Record
972  Xbarycenters[p] += GPR.at(AlignmentPI::t_x);
973  Ybarycenters[p] += GPR.at(AlignmentPI::t_y);
974  Zbarycenters[p] += GPR.at(AlignmentPI::t_z);
975 
976  COUT << "Partition: " << p << " n. modules: " << nmodules[p] << "|"
977  << " X: " << std::right << std::setw(12) << Xbarycenters[p] << " Y: " << std::right << std::setw(12)
978  << Ybarycenters[p] << " Z: " << std::right << std::setw(12) << Zbarycenters[p] << std::endl;
979  }
980  }
981 } // namespace AlignmentPI
982 
983 #endif
const std::array< double, 6 > getY()
const double getNModules(AlignmentPI::PARTITION p)
static constexpr auto TEC
bool tibIsDoubleSide(const DetId &id) const
bool tecIsDoubleSide(const DetId &id) const
bool tidIsDoubleSide(const DetId &id) const
unsigned int tobLayer(const DetId &id) const
unsigned int pxbLayer(const DetId &id) const
unsigned int tibSide(const DetId &id) const
unsigned int tobSide(const DetId &id) const
std::ostream & operator<<(std::ostream &o, PARTITION x)
std::vector< unsigned int > tidModuleInfo(const DetId &id) const
void makeNicePlotStyle(TH1 *hist, int color)
void computeBarycenters(const std::vector< AlignTransform > &input, const TrackerTopology &tTopo, const std::map< AlignmentPI::coordinate, float > &GPR)
ret
prodAgent to be discontinued
unsigned int tidSide(const DetId &id) const
std::vector< unsigned int > tecPetalInfo(const DetId &id) const
unsigned int tidWheel(const DetId &id) const
unsigned int tecWheel(const DetId &id) const
const PARTITION PARTITIONS[(int) PARTITION::LAST+1]
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::string getStringFromPart(AlignmentPI::partitions i)
bool isBPixOuterLadder(const DetId &detid, const TrackerTopology &tTopo, bool isPhase0)
bool isRPhi(const DetId &id) const
unsigned int pxbLadder(const DetId &id) const
Log< level::Error, false > LogError
assert(be >=bs)
unsigned int tecRing(const DetId &id) const
ring id
bool tobIsDoubleSide(const DetId &id) const
static const float cmToUm
constexpr std::array< uint8_t, layerIndexSize > layer
static std::string const input
Definition: EdmProvDump.cc:50
void makeNiceStats(TH1F *hist, AlignmentPI::partitions part, int color)
const std::array< double, 6 > getX()
static const unsigned int phase0size
unsigned int tecSide(const DetId &id) const
static const float tomRad
T sqrt(T t)
Definition: SSEVec.h:19
void fillGeometryInfo(const DetId &detId, const TrackerTopology &tTopo, bool isPhase0)
unsigned int pxfDisk(const DetId &id) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Definition: value.py:1
std::map< AlignmentPI::PARTITION, double > Zbarycenters
static constexpr auto TOB
std::pair< int, int > getIndices(AlignmentPI::index i)
constexpr valType roundIfNear0(valType value, double tolerance=1.e-7)
Definition: Rounding.h:11
#define M_PI
std::pair< float, float > getTheRange(std::map< uint32_t, float > values, const float nsigma)
__shared__ Hist hist
GlobalPoint getPartitionAvg(AlignmentPI::PARTITION p)
Definition: DetId.h:17
unsigned int pxfSide(const DetId &id) const
static constexpr auto TIB
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::string getStringFromCoordinate(AlignmentPI::coordinate coord)
part
Definition: HCALResponse.h:20
AlignmentPI::regions filterThePartition()
bool tibIsInternalString(const DetId &id) const
std::string getStringFromIndex(AlignmentPI::index i)
std::map< AlignmentPI::PARTITION, double > Ybarycenters
std::pair< double, double > calculatePosition(TVirtualPad *myPad, int boundary)
std::map< AlignmentPI::PARTITION, double > nmodules
float x
unsigned int tidRing(const DetId &id) const
def stdev(xlist)
Definition: plotscripts.py:69
std::map< AlignmentPI::PARTITION, double > Xbarycenters
unsigned int tibLayer(const DetId &id) const
std::string getStringFromRegionEnum(AlignmentPI::regions e)
unsigned int tobModule(const DetId &id) const
Log< level::Warning, false > LogWarning
const std::array< double, 6 > getZ()
static constexpr auto TID
float returnZeroIfNear2PI(const float phi)