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"
14 #include "TLatex.h"
18 #include "DataFormats/Math/interface/Rounding.h" // for rounding
19 #include "DataFormats/Math/interface/deltaPhi.h" // for deltaPhi
23 
24 //#define MMDEBUG // uncomment for debugging at compile time
25 #ifdef MMDEBUG
26 #include <iostream>
27 #define COUT std::cout << "MM "
28 #else
29 #define COUT edm::LogVerbatim("")
30 #endif
31 
32 namespace AlignmentPI {
33 
34  // size of the phase-I Tracker APE payload (including both SS + DS modules)
35  static const unsigned int phase0size = 19876;
36  static const unsigned int phase1size = 20292;
37  static const unsigned int mismatched = 99999;
38  static const float cmToUm = 10000.f;
39  static const float tomRad = 1000.f;
40 
41  /*--------------------------------------------------------------------*/
42  inline void displayNotSupported(TCanvas& canv, const unsigned int size)
43  /*--------------------------------------------------------------------*/
44  {
45  std::string phase = (size < AlignmentPI::phase1size) ? "Phase-0" : "Phase-2";
46  canv.cd();
47  TLatex t2;
48  t2.SetTextAlign(21);
49  t2.SetTextSize(0.1);
50  t2.SetTextAngle(45);
51  t2.SetTextColor(kRed);
52  if (size != AlignmentPI::mismatched) {
53  t2.DrawLatexNDC(0.6, 0.50, Form("%s NOT SUPPORTED!", phase.c_str()));
54  } else {
55  t2.DrawLatexNDC(0.6, 0.50, "MISMATCHED PAYLOAD SIZE!");
56  }
57  }
58 
59  // method to zero all elements whose difference from 2Pi
60  // is less than the tolerance (2*10e-7)
61  inline double returnZeroIfNear2PI(const double phi) {
62  const double tol = 2.e-7; // default tolerance 1.e-7 doesn't account for possible variations
63  if (cms_rounding::roundIfNear0(std::abs(phi) - 2 * M_PI, tol) == 0.f) {
64  return 0.f;
65  } else {
66  return phi;
67  }
68  }
69 
70  // method to bring back around 0 all elements whose difference
71  // frm 2Pi is is less than the tolerance (in micro-rad)
72  inline double trim2PIs(const double phi, const double tolerance = 1.f) {
73  if (std::abs((std::abs(phi) - 2 * M_PI) * tomRad) < tolerance) {
74  return (std::abs(phi) - 2 * M_PI);
75  } else {
76  return phi;
77  }
78  }
79 
80  enum coordinate {
81  t_x = 1,
82  t_y = 2,
83  t_z = 3,
84  rot_alpha = 4,
85  rot_beta = 5,
86  rot_gamma = 6,
87  };
88 
89  // M.M. 2017/09/12
90  // As the matrix is symmetric, we map only 6/9 terms
91  // More terms for the extended APE can be added to the following methods
92 
93  enum index { XX = 1, XY = 2, XZ = 3, YZ = 4, YY = 5, ZZ = 6 };
94 
95  enum partitions { INVALID = 0, BPix = 1, FPix = 2, TIB = 3, TID = 4, TOB = 5, TEC = 6 };
96 
97  enum class PARTITION {
98  BPIX, // 0 Barrel Pixel
99  FPIXp, // 1 Forward Pixel Plus
100  FPIXm, // 2 Forward Pixel Minus
101  TIB, // 3 Tracker Inner Barrel
102  TIDp, // 4 Tracker Inner Disks Plus
103  TIDm, // 5 Tracker Inner Disks Minus
104  TOB, // 6 Tracker Outer Barrel
105  TECp, // 7 Tracker Endcaps Plus
106  TECm, // 8 Tracker Endcaps Minus
107  LAST = TECm
108  };
109 
110  extern const PARTITION PARTITIONS[(int)PARTITION::LAST + 1];
120 
121  inline std::ostream& operator<<(std::ostream& o, PARTITION x) {
123  }
124 
125  enum regions {
126  BPixL1o, //0 Barrel Pixel Layer 1 outer
127  BPixL1i, //1 Barrel Pixel Layer 1 inner
128  BPixL2o, //2 Barrel Pixel Layer 2 outer
129  BPixL2i, //3 Barrel Pixel Layer 2 inner
130  BPixL3o, //4 Barrel Pixel Layer 3 outer
131  BPixL3i, //5 Barrel Pixel Layer 3 inner
132  BPixL4o, //6 Barrel Pixel Layer 4 outer
133  BPixL4i, //7 Barrel Pixel Layer 4 inner
134  FPixmL1, //8 Forward Pixel Minus side Disk 1
135  FPixmL2, //9 Forward Pixel Minus side Disk 2
136  FPixmL3, //10 Forward Pixel Minus side Disk 3
137  FPixpL1, //11 Forward Pixel Plus side Disk 1
138  FPixpL2, //12 Forward Pixel Plus side Disk 2
139  FPixpL3, //13 Forward Pixel Plus side Disk 3
140  TIBL1Ro, //14 Inner Barrel Layer 1 Rphi outer
141  TIBL1Ri, //15 Inner Barrel Layer 1 Rphi inner
142  TIBL1So, //16 Inner Barrel Layer 1 Stereo outer
143  TIBL1Si, //17 Inner Barrel Layer 1 Stereo inner
144  TIBL2Ro, //18 Inner Barrel Layer 2 Rphi outer
145  TIBL2Ri, //19 Inner Barrel Layer 2 Rphi inner
146  TIBL2So, //20 Inner Barrel Layer 2 Stereo outer
147  TIBL2Si, //21 Inner Barrel Layer 2 Stereo inner
148  TIBL3o, //22 Inner Barrel Layer 3 outer
149  TIBL3i, //23 Inner Barrel Layer 3 inner
150  TIBL4o, //24 Inner Barrel Layer 4 outer
151  TIBL4i, //25 Inner Barrel Layer 4 inner
152  TOBL1Ro, //26 Outer Barrel Layer 1 Rphi outer
153  TOBL1Ri, //27 Outer Barrel Layer 1 Rphi inner
154  TOBL1So, //28 Outer Barrel Layer 1 Stereo outer
155  TOBL1Si, //29 Outer Barrel Layer 1 Stereo inner
156  TOBL2Ro, //30 Outer Barrel Layer 2 Rphi outer
157  TOBL2Ri, //31 Outer Barrel Layer 2 Rphi inner
158  TOBL2So, //32 Outer Barrel Layer 2 Stereo outer
159  TOBL2Si, //33 Outer Barrel Layer 2 Stereo inner
160  TOBL3o, //34 Outer Barrel Layer 3 outer
161  TOBL3i, //35 Outer Barrel Layer 3 inner
162  TOBL4o, //36 Outer Barrel Layer 4 outer
163  TOBL4i, //37 Outer Barrel Layer 4 inner
164  TOBL5o, //38 Outer Barrel Layer 5 outer
165  TOBL5i, //39 Outer Barrel Layer 5 inner
166  TOBL6o, //40 Outer Barrel Layer 6 outer
167  TOBL6i, //41 Outer Barrel Layer 6 inner
168  TIDmR1R, //42 Inner Disk Minus side Ring 1 Rphi
169  TIDmR1S, //43 Inner Disk Minus side Ring 1 Stereo
170  TIDmR2R, //44 Inner Disk Minus side Ring 2 Rphi
171  TIDmR2S, //45 Inner Disk Minus side Ring 2 Stereo
172  TIDmR3, //46 Inner Disk Minus side Ring 3
173  TIDpR1R, //47 Inner Disk Plus side Ring 1 Rphi
174  TIDpR1S, //48 Inner Disk Plus side Ring 1 Stereo
175  TIDpR2R, //49 Inner Disk Plus side Ring 2 Rphi
176  TIDpR2S, //50 Inner Disk Plus side Ring 2 Stereo
177  TIDpR3, //51 Inner Disk Plus side Ring 3
178  TECmR1R, //52 Endcaps Minus side Ring 1 Rphi
179  TECmR1S, //53 Endcaps Minus side Ring 1 Stereo
180  TECmR2R, //54 Encdaps Minus side Ring 2 Rphi
181  TECmR2S, //55 Endcaps Minus side Ring 2 Stereo
182  TECmR3, //56 Endcaps Minus side Ring 3
183  TECmR4, //57 Endcaps Minus side Ring 4
184  TECmR5, //58 Endcaps Minus side Ring 5
185  TECmR6, //59 Endcaps Minus side Ring 6
186  TECmR7, //60 Endcaps Minus side Ring 7
187  TECpR1R, //61 Endcaps Plus side Ring 1 Rphi
188  TECpR1S, //62 Endcaps Plus side Ring 1 Stereo
189  TECpR2R, //63 Encdaps Plus side Ring 2 Rphi
190  TECpR2S, //64 Endcaps Plus side Ring 2 Stereo
191  TECpR3, //65 Endcaps Plus side Ring 3
192  TECpR4, //66 Endcaps Plus side Ring 4
193  TECpR5, //67 Endcaps Plus side Ring 5
194  TECpR6, //68 Endcaps Plus side Ring 6
195  TECpR7, //67 Endcaps Plus side Ring 7
196  StripDoubleSide, // 70 -- not to be considered
197  NUM_OF_REGIONS // 71 -- default
198  };
199 
200  /*--------------------------------------------------------------------*/
202  /*--------------------------------------------------------------------*/
203  {
204  switch (e) {
206  return "BPixL1o";
208  return "BPixL1i";
210  return "BPixL2o";
212  return "BPixL2i";
214  return "BPixL3o";
216  return "BPixL3i";
218  return "BPixL4o";
220  return "BPixL4i";
222  return "FPixmL1";
224  return "FPixmL2";
226  return "FPixmL3";
228  return "FPixpL1";
230  return "FPixpL2";
232  return "FPixpL3";
234  return "TIBL1Ro";
236  return "TIBL1Ri";
238  return "TIBL1So";
240  return "TIBL1Si";
242  return "TIBL2Ro";
244  return "TIBL2Ri";
246  return "TIBL2So";
248  return "TIBL2Si";
249  case AlignmentPI::TIBL3o:
250  return "TIBL3o";
251  case AlignmentPI::TIBL3i:
252  return "TIBL3i";
253  case AlignmentPI::TIBL4o:
254  return "TIBL4o";
255  case AlignmentPI::TIBL4i:
256  return "TIBL4i";
258  return "TOBL1Ro";
260  return "TOBL1Ri";
262  return "TOBL1So";
264  return "TOBL1Si";
266  return "TOBL2Ro";
268  return "TOBL2Ri";
270  return "TOBL2So";
272  return "TOBL2Si";
273  case AlignmentPI::TOBL3o:
274  return "TOBL3o";
275  case AlignmentPI::TOBL3i:
276  return "TOBL3i";
277  case AlignmentPI::TOBL4o:
278  return "TOBL4o";
279  case AlignmentPI::TOBL4i:
280  return "TOBL4i";
281  case AlignmentPI::TOBL5o:
282  return "TOBL5o";
283  case AlignmentPI::TOBL5i:
284  return "TOBL5i";
285  case AlignmentPI::TOBL6o:
286  return "TOBL6o";
287  case AlignmentPI::TOBL6i:
288  return "TOBL6i";
290  return "TIDmR1R";
292  return "TIDmR1S";
294  return "TIDmR2R";
296  return "TIDmR2S";
297  case AlignmentPI::TIDmR3:
298  return "TIDmR3";
300  return "TIDpR1R";
302  return "TIDpR1S";
304  return "TIDpR2R";
306  return "TIDpR2S";
307  case AlignmentPI::TIDpR3:
308  return "TIDpR3";
310  return "TECmR1R";
312  return "TECmR1S";
314  return "TECmR2R";
316  return "TECmR2S";
317  case AlignmentPI::TECmR3:
318  return "TECmR3";
319  case AlignmentPI::TECmR4:
320  return "TECmR4";
321  case AlignmentPI::TECmR5:
322  return "TECmR5";
323  case AlignmentPI::TECmR6:
324  return "TECmR6";
325  case AlignmentPI::TECmR7:
326  return "TECmR7";
328  return "TECpR1R";
330  return "TECpR1S";
332  return "TECpR2R";
334  return "TECpR2S";
335  case AlignmentPI::TECpR3:
336  return "TECpR3";
337  case AlignmentPI::TECpR4:
338  return "TECpR4";
339  case AlignmentPI::TECpR5:
340  return "TECpR5";
341  case AlignmentPI::TECpR6:
342  return "TECpR6";
343  case AlignmentPI::TECpR7:
344  return "TECpR7";
345  default:
346  edm::LogWarning("LogicError") << "Unknown partition: " << e;
347  return "";
348  }
349  }
350 
351  /*--------------------------------------------------------------------*/
352  inline bool isBPixOuterLadder(const DetId& detid, const TrackerTopology& tTopo, bool isPhase0)
353  /*--------------------------------------------------------------------*/
354  {
355  // Using TrackerTopology
356  // Ladders have a staggered structure
357  // Non-flipped ladders are on the outer radius
358  // Phase 0: Outer ladders are odd for layer 1,3 and even for layer 2
359  // Phase 1: Outer ladders are odd for layer 1,2,3 and even for layer 4
360  bool isOuter = false;
361  int layer = tTopo.pxbLayer(detid.rawId());
362  bool odd_ladder = tTopo.pxbLadder(detid.rawId()) % 2;
363  if (isPhase0) {
364  if (layer == 2)
365  isOuter = !odd_ladder;
366  else
367  isOuter = odd_ladder;
368  } else {
369  if (layer == 4)
370  isOuter = !odd_ladder;
371  else
372  isOuter = odd_ladder;
373  }
374  return isOuter;
375  }
376 
377  // ancillary struct to manage the topology
378  // info in a more compact way
379 
380  struct topolInfo {
381  private:
382  uint32_t m_rawid;
384  int m_layer;
385  int m_side;
386  int m_ring;
387  bool m_isRphi;
390 
391  public:
392  void init();
393  void fillGeometryInfo(const DetId& detId, const TrackerTopology& tTopo, bool isPhase0);
395  bool sanityCheck();
396  void printAll();
397  virtual ~topolInfo() {}
398  };
399 
400  /*--------------------------------------------------------------------*/
401  inline void topolInfo::printAll()
402  /*--------------------------------------------------------------------*/
403  {
404  std::cout << " detId:" << m_rawid << " subdetid: " << m_subdetid << " layer: " << m_layer << " side: " << m_side
405  << " ring: " << m_ring << " isRphi:" << m_isRphi << " isDoubleSide:" << m_isDoubleSide
406  << " isInternal:" << m_isInternal << std::endl;
407  }
408 
409  /*--------------------------------------------------------------------*/
410  inline void topolInfo::init()
411  /*--------------------------------------------------------------------*/
412  {
413  m_rawid = 0;
414  m_subdetid = -1;
415  m_layer = -1;
416  m_side = -1;
417  m_ring = -1;
418  m_isRphi = false;
419  m_isDoubleSide = false;
420  m_isInternal = false;
421  };
422 
423  /*--------------------------------------------------------------------*/
425  /*--------------------------------------------------------------------*/
426  {
427  if (m_layer == 0 || (m_subdetid == 1 && m_layer > 4) || (m_subdetid == 2 && m_layer > 3)) {
428  return false;
429  } else {
430  return true;
431  }
432  }
433  /*--------------------------------------------------------------------*/
434  inline void topolInfo::fillGeometryInfo(const DetId& detId, const TrackerTopology& tTopo, bool isPhase0)
435  /*--------------------------------------------------------------------*/
436  {
437  unsigned int subdetId = static_cast<unsigned int>(detId.subdetId());
438 
439  m_rawid = detId.rawId();
440  m_subdetid = subdetId;
441 
442  if (subdetId == StripSubdetector::TIB) {
443  m_layer = tTopo.tibLayer(detId.rawId());
444  m_side = tTopo.tibSide(detId.rawId());
445  m_isRphi = tTopo.isRPhi(detId.rawId());
446  m_isDoubleSide = tTopo.tibIsDoubleSide(detId.rawId());
447  m_isInternal = tTopo.tibIsInternalString(detId.rawId());
448  } else if (subdetId == StripSubdetector::TOB) {
449  m_layer = tTopo.tobLayer(detId.rawId());
450  m_side = tTopo.tobSide(detId.rawId());
451  m_isRphi = tTopo.isRPhi(detId.rawId());
452  m_isDoubleSide = tTopo.tobIsDoubleSide(detId.rawId());
453  m_isInternal = tTopo.tobModule(detId.rawId()) % 2;
454  } else if (subdetId == StripSubdetector::TID) {
455  m_layer = tTopo.tidWheel(detId.rawId());
456  m_side = tTopo.tidSide(detId.rawId());
457  m_isRphi = tTopo.isRPhi(detId.rawId());
458  m_ring = tTopo.tidRing(detId.rawId());
459  m_isDoubleSide = tTopo.tidIsDoubleSide(detId.rawId());
460  m_isInternal = tTopo.tidModuleInfo(detId.rawId())[0];
461  } else if (subdetId == StripSubdetector::TEC) {
462  m_layer = tTopo.tecWheel(detId.rawId());
463  m_side = tTopo.tecSide(detId.rawId());
464  m_isRphi = tTopo.isRPhi(detId.rawId());
465  m_ring = tTopo.tecRing(detId.rawId());
466  m_isDoubleSide = tTopo.tecIsDoubleSide(detId.rawId());
467  m_isInternal = tTopo.tecPetalInfo(detId.rawId())[0];
468  } else if (subdetId == PixelSubdetector::PixelBarrel) {
469  m_layer = tTopo.pxbLayer(detId.rawId());
471  } else if (subdetId == PixelSubdetector::PixelEndcap) {
472  m_layer = tTopo.pxfDisk(detId.rawId());
473  m_side = tTopo.pxfSide(detId.rawId());
474  } else
475  edm::LogWarning("LogicError") << "Unknown subdetid: " << subdetId;
476  }
477 
478  // ------------ method to assign a partition based on the topology struct info ---------------
479 
480  /*--------------------------------------------------------------------*/
482  /*--------------------------------------------------------------------*/
483  {
485 
486  if (m_isDoubleSide) {
488  }
489 
490  // BPix
491  if (m_subdetid == 1) {
492  switch (m_layer) {
493  case 1:
495  break;
496  case 2:
498  break;
499  case 3:
501  break;
502  case 4:
504  break;
505  default:
506  edm::LogWarning("LogicError") << "Unknow BPix layer: " << m_layer;
507  break;
508  }
509  // FPix
510  } else if (m_subdetid == 2) {
511  switch (m_layer) {
512  case 1:
514  break;
515  case 2:
517  break;
518  case 3:
520  break;
521  default:
522  edm::LogWarning("LogicError") << "Unknow FPix disk: " << m_layer;
523  break;
524  }
525  // TIB
526  } else if (m_subdetid == 3) {
527  switch (m_layer) {
528  case 1:
529  if (m_isRphi) {
531  } else {
533  }
534  break;
535  case 2:
536  if (m_isRphi) {
538  } else {
540  }
541  break;
542  case 3:
544  break;
545  case 4:
547  break;
548  default:
549  edm::LogWarning("LogicError") << "Unknow TIB layer: " << m_layer;
550  break;
551  }
552  // TID
553  } else if (m_subdetid == 4) {
554  switch (m_ring) {
555  case 1:
556  if (m_isRphi) {
558  } else {
560  }
561  break;
562  case 2:
563  if (m_isRphi) {
565  } else {
567  }
568  break;
569  case 3:
571  break;
572  default:
573  edm::LogWarning("LogicError") << "Unknow TID wheel: " << m_layer;
574  break;
575  }
576  // TOB
577  } else if (m_subdetid == 5) {
578  switch (m_layer) {
579  case 1:
580  if (m_isRphi) {
582  } else {
584  }
585  break;
586  case 2:
587  if (m_isRphi) {
589  } else {
591  }
592  break;
593  case 3:
595  break;
596  case 4:
598  break;
599  case 5:
601  break;
602  case 6:
604  break;
605  default:
606  edm::LogWarning("LogicError") << "Unknow TOB layer: " << m_layer;
607  break;
608  }
609  // TEC
610  } else if (m_subdetid == 6) {
611  switch (m_ring) {
612  case 1:
613  if (m_isRphi) {
615  } else {
617  }
618  break;
619  case 2:
620  if (m_isRphi) {
622  } else {
624  }
625  break;
626  case 3:
628  break;
629  case 4:
631  break;
632  case 5:
634  break;
635  case 6:
637  break;
638  case 7:
640  break;
641  default:
642  edm::LogWarning("LogicError") << "Unknow TEC ring: " << m_ring;
643  break;
644  }
645  }
646 
647  return ret;
648  }
649 
650  /*--------------------------------------------------------------------*/
652  /*--------------------------------------------------------------------*/
653  {
654  switch (coord) {
655  case t_x:
656  return "x-translation";
657  case t_y:
658  return "y-translation";
659  case t_z:
660  return "z-translation";
661  case rot_alpha:
662  return "#alpha angle rotation";
663  case rot_beta:
664  return "#beta angle rotation";
665  case rot_gamma:
666  return "#gamma angle rotation";
667  default:
668  return "should never be here!";
669  }
670  }
671 
672  /*--------------------------------------------------------------------*/
674  /*--------------------------------------------------------------------*/
675  {
676  switch (i) {
677  case XX:
678  return "XX";
679  case XY:
680  return "XY";
681  case XZ:
682  return "XZ";
683  case YZ:
684  return "YX";
685  case YY:
686  return "YY";
687  case ZZ:
688  return "ZZ";
689  default:
690  return "should never be here!";
691  }
692  }
693 
694  /*--------------------------------------------------------------------*/
696  /*--------------------------------------------------------------------*/
697  {
698  switch (i) {
699  case BPix:
700  return "BPix";
701  case FPix:
702  return "FPix";
703  case TIB:
704  return (isPhase2 ? "TIB-invalid" : "TIB");
705  case TID:
706  return (isPhase2 ? "P2OTEC" : "TID");
707  case TOB:
708  return (isPhase2 ? "P2OTB" : "TOB");
709  case TEC:
710  return (isPhase2 ? "TEC-invalid" : "TEC");
711  default:
712  return "should never be here!";
713  }
714  }
715 
716  /*--------------------------------------------------------------------*/
717  inline std::pair<int, int> getIndices(AlignmentPI::index i)
718  /*--------------------------------------------------------------------*/
719  {
720  switch (i) {
721  case XX:
722  return std::make_pair(0, 0);
723  case XY:
724  return std::make_pair(0, 1);
725  case XZ:
726  return std::make_pair(0, 2);
727  case YZ:
728  return std::make_pair(1, 0);
729  case YY:
730  return std::make_pair(1, 1);
731  case ZZ:
732  return std::make_pair(2, 2);
733  default:
734  return std::make_pair(-1, -1);
735  }
736  }
737 
738  /*--------------------------------------------------------------------*/
739  inline void makeNicePlotStyle(TH1* hist, int color)
740  /*--------------------------------------------------------------------*/
741  {
742  hist->SetStats(kFALSE);
743 
744  hist->GetXaxis()->SetTitleColor(color);
745  hist->SetLineColor(color);
746  hist->SetTitleSize(0.08);
747  hist->SetLineWidth(2);
748  hist->GetXaxis()->CenterTitle(true);
749  hist->GetYaxis()->CenterTitle(true);
750  hist->GetXaxis()->SetTitleFont(42);
751  hist->GetYaxis()->SetTitleFont(42);
752  hist->GetXaxis()->SetNdivisions(505);
753  hist->GetXaxis()->SetTitleSize(0.06);
754  hist->GetYaxis()->SetTitleSize(0.06);
755  hist->GetXaxis()->SetTitleOffset(1.0);
756  hist->GetYaxis()->SetTitleOffset(1.3);
757  hist->GetXaxis()->SetLabelFont(42);
758  hist->GetYaxis()->SetLabelFont(42);
759  hist->GetYaxis()->SetLabelSize(.05);
760  hist->GetXaxis()->SetLabelSize(.05);
761  }
762 
763  /*--------------------------------------------------------------------*/
764  inline void makeNiceStats(TH1F* hist, AlignmentPI::partitions part, int color)
765  /*--------------------------------------------------------------------*/
766  {
767  char buffer[255];
768  TPaveText* stat = new TPaveText(0.71, 0.75, 0.95, 0.88, "NDC");
769  sprintf(buffer, "%s \n", AlignmentPI::getStringFromPart(part).c_str());
770  stat->AddText(buffer);
771 
772  sprintf(buffer, "Entries : %i\n", (int)hist->GetEntries());
773  stat->AddText(buffer);
774 
775  if (std::abs(hist->GetMean()) > 0.01) {
776  sprintf(buffer, "Mean : %6.2f\n", hist->GetMean());
777  } else {
778  sprintf(buffer, "Mean : %6.2f e-2\n", 100 * hist->GetMean());
779  }
780  stat->AddText(buffer);
781 
782  if (std::abs(hist->GetRMS()) > 0.01) {
783  sprintf(buffer, "RMS : %6.2f\n", hist->GetRMS());
784  } else {
785  sprintf(buffer, "RMS : %6.2f e-2\n", 100 * hist->GetRMS());
786  }
787  stat->AddText(buffer);
788 
789  stat->SetLineColor(0);
790  stat->SetTextColor(color);
791  stat->SetFillColor(10);
792  stat->SetShadowColor(10);
793  stat->Draw();
794  }
795 
796  /*--------------------------------------------------------------------*/
797  inline std::pair<float, float> getTheRange(std::map<uint32_t, float> values, const float nsigma)
798  /*--------------------------------------------------------------------*/
799  {
800  float sum = std::accumulate(
801  std::begin(values), std::end(values), 0.0, [](float value, const std::map<uint32_t, float>::value_type& p) {
802  return value + p.second;
803  });
804 
805  float m = sum / values.size();
806 
807  float accum = 0.0;
808  std::for_each(std::begin(values), std::end(values), [&](const std::map<uint32_t, float>::value_type& p) {
809  accum += (p.second - m) * (p.second - m);
810  });
811 
812  float stdev = sqrt(accum / (values.size() - 1));
813 
814  if (stdev != 0.) {
815  return std::make_pair(m - nsigma * stdev, m + nsigma * stdev);
816  } else {
817  return std::make_pair(m > 0. ? 0.95 * m : 1.05 * m, m > 0 ? 1.05 * m : 0.95 * m);
818  }
819  }
820 
821  /*--------------------------------------------------------------------*/
822  inline std::pair<double, double> calculatePosition(TVirtualPad* myPad, int boundary)
823  /*--------------------------------------------------------------------*/
824  {
825  int ix1;
826  int ix2;
827  int iw = myPad->GetWw();
828  int ih = myPad->GetWh();
829  double x1p, y1p, x2p, y2p;
830  myPad->GetPadPar(x1p, y1p, x2p, y2p);
831  ix1 = (int)(iw * x1p);
832  ix2 = (int)(iw * x2p);
833  double wndc = std::min(1., (double)iw / (double)ih);
834  double rw = wndc / (double)iw;
835  double x1ndc = (double)ix1 * rw;
836  double x2ndc = (double)ix2 * rw;
837  double rx1, ry1, rx2, ry2;
838  myPad->GetRange(rx1, ry1, rx2, ry2);
839  double rx = (x2ndc - x1ndc) / (rx2 - rx1);
840  double _sx;
841  _sx = rx * (boundary - rx1) + x1ndc;
842  double _dx = _sx + 0.05;
843 
844  return std::make_pair(_sx, _dx);
845  }
846 
847  // ancillary struct to manage the barycenters
848  // info in a more compact way
849 
851  std::map<AlignmentPI::PARTITION, double> Xbarycenters;
852  std::map<AlignmentPI::PARTITION, double> Ybarycenters;
853  std::map<AlignmentPI::PARTITION, double> Zbarycenters;
854  std::map<AlignmentPI::PARTITION, double> nmodules;
855 
856  public:
857  void init();
859  void computeBarycenters(const std::vector<AlignTransform>& input,
860  const TrackerTopology& tTopo,
861  const std::map<AlignmentPI::coordinate, float>& GPR);
862  const double getNModules(AlignmentPI::PARTITION p) { return nmodules[p]; };
863 
864  // M.M. 2020/01/09
865  // introduce methods for entire partitions, summing up the two sides of the
866  // endcap detectors
867 
868  /*--------------------------------------------------------------------*/
869  const std::array<double, 6> getX()
870  /*--------------------------------------------------------------------*/
871  {
872  return {{Xbarycenters[PARTITION::BPIX],
878  };
879 
880  /*--------------------------------------------------------------------*/
881  const std::array<double, 6> getY()
882  /*--------------------------------------------------------------------*/
883  {
884  return {{Ybarycenters[PARTITION::BPIX],
890  };
891 
892  /*--------------------------------------------------------------------*/
893  const std::array<double, 6> getZ()
894  /*--------------------------------------------------------------------*/
895  {
896  return {{Zbarycenters[PARTITION::BPIX],
902  };
903  virtual ~TkAlBarycenters() {}
904  };
905 
906  /*--------------------------------------------------------------------*/
907  inline void TkAlBarycenters::init()
908  /*--------------------------------------------------------------------*/
909  {
910  // empty all maps
911  Xbarycenters.clear();
912  Ybarycenters.clear();
913  Zbarycenters.clear();
914  nmodules.clear();
915  }
916 
917  /*--------------------------------------------------------------------*/
919  /*--------------------------------------------------------------------*/
920  {
922  }
923 
924  /*--------------------------------------------------------------------*/
925  inline void TkAlBarycenters::computeBarycenters(const std::vector<AlignTransform>& input,
926  const TrackerTopology& tTopo,
927  const std::map<AlignmentPI::coordinate, float>& GPR)
928  /*--------------------------------------------------------------------*/
929  {
930  // clear all data members;
931  init();
932 
933  for (const auto& ali : input) {
934  if (DetId(ali.rawId()).det() != DetId::Tracker) {
935  edm::LogWarning("TkAlBarycenters::computeBarycenters")
936  << "Encountered invalid Tracker DetId:" << ali.rawId() << " " << DetId(ali.rawId()).det()
937  << " is different from " << DetId::Tracker << " - terminating ";
938  assert(DetId(ali.rawId()).det() != DetId::Tracker);
939  }
940 
941  int subid = DetId(ali.rawId()).subdetId();
942  switch (subid) {
944  Xbarycenters[PARTITION::BPIX] += (ali.translation().x());
945  Ybarycenters[PARTITION::BPIX] += (ali.translation().y());
946  Zbarycenters[PARTITION::BPIX] += (ali.translation().z());
948  break;
950 
951  // minus side
952  if (tTopo.pxfSide(DetId(ali.rawId())) == 1) {
953  Xbarycenters[PARTITION::FPIXm] += (ali.translation().x());
954  Ybarycenters[PARTITION::FPIXm] += (ali.translation().y());
955  Zbarycenters[PARTITION::FPIXm] += (ali.translation().z());
957  } // plus side
958  else {
959  Xbarycenters[PARTITION::FPIXp] += (ali.translation().x());
960  Ybarycenters[PARTITION::FPIXp] += (ali.translation().y());
961  Zbarycenters[PARTITION::FPIXp] += (ali.translation().z());
963  }
964  break;
966  Xbarycenters[PARTITION::TIB] += (ali.translation().x());
967  Ybarycenters[PARTITION::TIB] += (ali.translation().y());
968  Zbarycenters[PARTITION::TIB] += (ali.translation().z());
970  break;
972  // minus side
973  if (tTopo.tidSide(DetId(ali.rawId())) == 1) {
974  Xbarycenters[PARTITION::TIDm] += (ali.translation().x());
975  Ybarycenters[PARTITION::TIDm] += (ali.translation().y());
976  Zbarycenters[PARTITION::TIDm] += (ali.translation().z());
978  } // plus side
979  else {
980  Xbarycenters[PARTITION::TIDp] += (ali.translation().x());
981  Ybarycenters[PARTITION::TIDp] += (ali.translation().y());
982  Zbarycenters[PARTITION::TIDp] += (ali.translation().z());
984  }
985  break;
987  Xbarycenters[PARTITION::TOB] += (ali.translation().x());
988  Ybarycenters[PARTITION::TOB] += (ali.translation().y());
989  Zbarycenters[PARTITION::TOB] += (ali.translation().z());
991  break;
993  // minus side
994  if (tTopo.tecSide(DetId(ali.rawId())) == 1) {
995  Xbarycenters[PARTITION::TECm] += (ali.translation().x());
996  Ybarycenters[PARTITION::TECm] += (ali.translation().y());
997  Zbarycenters[PARTITION::TECm] += (ali.translation().z());
999  } // plus side
1000  else {
1001  Xbarycenters[PARTITION::TECp] += (ali.translation().x());
1002  Ybarycenters[PARTITION::TECp] += (ali.translation().y());
1003  Zbarycenters[PARTITION::TECp] += (ali.translation().z());
1005  }
1006  break;
1007  default:
1008  edm::LogError("TrackerAlignment_PayloadInspector") << "Unrecognized partition " << subid << std::endl;
1009  break;
1010  }
1011  }
1012 
1013  for (const auto& p : PARTITIONS) {
1014  // take the arithmetic mean
1015  Xbarycenters[p] /= nmodules[p];
1016  Ybarycenters[p] /= nmodules[p];
1017  Zbarycenters[p] /= nmodules[p];
1018 
1019  // add the Tracker Global Position Record
1020  Xbarycenters[p] += GPR.at(AlignmentPI::t_x);
1021  Ybarycenters[p] += GPR.at(AlignmentPI::t_y);
1022  Zbarycenters[p] += GPR.at(AlignmentPI::t_z);
1023 
1024  COUT << "Partition: " << p << " n. modules: " << nmodules[p] << "|"
1025  << " X: " << std::right << std::setw(12) << Xbarycenters[p] << " Y: " << std::right << std::setw(12)
1026  << Ybarycenters[p] << " Z: " << std::right << std::setw(12) << Zbarycenters[p] << std::endl;
1027  }
1028  }
1029 
1030  /*--------------------------------------------------------------------*/
1032  std::map<int, AlignmentPI::partitions>& boundaries,
1033  const std::vector<AlignTransform>& ref_ali,
1034  const std::vector<AlignTransform>& target_ali,
1035  std::unique_ptr<TH1F>& compare)
1036  /*--------------------------------------------------------------------*/
1037  {
1038  int counter = 0; /* start the counter */
1040  for (unsigned int i = 0; i < ref_ali.size(); i++) {
1041  if (ref_ali[i].rawId() == target_ali[i].rawId()) {
1042  counter++;
1043  int subid = DetId(ref_ali[i].rawId()).subdetId();
1044 
1045  auto thePart = static_cast<AlignmentPI::partitions>(subid);
1046  if (thePart != currentPart) {
1047  currentPart = thePart;
1048  boundaries.insert({counter, thePart});
1049  }
1050 
1051  CLHEP::HepRotation target_rot(target_ali[i].rotation());
1052  CLHEP::HepRotation ref_rot(ref_ali[i].rotation());
1053 
1054  align::RotationType target_ROT(target_rot.xx(),
1055  target_rot.xy(),
1056  target_rot.xz(),
1057  target_rot.yx(),
1058  target_rot.yy(),
1059  target_rot.yz(),
1060  target_rot.zx(),
1061  target_rot.zy(),
1062  target_rot.zz());
1063 
1064  align::RotationType ref_ROT(ref_rot.xx(),
1065  ref_rot.xy(),
1066  ref_rot.xz(),
1067  ref_rot.yx(),
1068  ref_rot.yy(),
1069  ref_rot.yz(),
1070  ref_rot.zx(),
1071  ref_rot.zy(),
1072  ref_rot.zz());
1073 
1074  const std::vector<double> deltaRot = {::deltaPhi(align::toAngles(target_ROT)[0], align::toAngles(ref_ROT)[0]),
1075  ::deltaPhi(align::toAngles(target_ROT)[1], align::toAngles(ref_ROT)[1]),
1076  ::deltaPhi(align::toAngles(target_ROT)[2], align::toAngles(ref_ROT)[2])};
1077 
1078  const auto& deltaTrans = target_ali[i].translation() - ref_ali[i].translation();
1079 
1080  switch (coord) {
1081  case AlignmentPI::t_x:
1082  compare->SetBinContent(i + 1, deltaTrans.x() * AlignmentPI::cmToUm);
1083  break;
1084  case AlignmentPI::t_y:
1085  compare->SetBinContent(i + 1, deltaTrans.y() * AlignmentPI::cmToUm);
1086  break;
1087  case AlignmentPI::t_z:
1088  compare->SetBinContent(i + 1, deltaTrans.z() * AlignmentPI::cmToUm);
1089  break;
1091  compare->SetBinContent(i + 1, deltaRot[0] * AlignmentPI::tomRad);
1092  break;
1093  case AlignmentPI::rot_beta:
1094  compare->SetBinContent(i + 1, deltaRot[1] * AlignmentPI::tomRad);
1095  break;
1097  compare->SetBinContent(i + 1, deltaRot[2] * AlignmentPI::tomRad);
1098  break;
1099  default:
1100  edm::LogError("TrackerAlignment_PayloadInspector") << "Unrecognized coordinate " << coord << std::endl;
1101  break;
1102  } // switch on the coordinate
1103  } // check on the same detID
1104  } // loop on the components
1105  }
1106 
1107  /*--------------------------------------------------------------------*/
1108  inline void fillComparisonHistograms(std::map<int, AlignmentPI::partitions>& boundaries,
1109  const std::vector<AlignTransform>& ref_ali,
1110  const std::vector<AlignTransform>& target_ali,
1111  std::unordered_map<AlignmentPI::coordinate, std::unique_ptr<TH1F> >& compare,
1112  bool diff = false,
1114  /*--------------------------------------------------------------------*/
1115  {
1116  int counter = 0; /* start the counter */
1118  for (unsigned int i = 0; i < ref_ali.size(); i++) {
1119  if (ref_ali[i].rawId() == target_ali[i].rawId()) {
1120  counter++;
1121  int subid = DetId(ref_ali[i].rawId()).subdetId();
1122 
1123  auto thePart = static_cast<AlignmentPI::partitions>(subid);
1124 
1125  // in case it has to be filtered
1126  if (checkPart > 0 && thePart != checkPart) {
1127  continue;
1128  }
1129 
1130  if (thePart != currentPart) {
1131  currentPart = thePart;
1132  boundaries.insert({counter, thePart});
1133  }
1134 
1135  CLHEP::HepRotation target_rot(target_ali[i].rotation());
1136  CLHEP::HepRotation ref_rot(ref_ali[i].rotation());
1137 
1138  align::RotationType target_ROT(target_rot.xx(),
1139  target_rot.xy(),
1140  target_rot.xz(),
1141  target_rot.yx(),
1142  target_rot.yy(),
1143  target_rot.yz(),
1144  target_rot.zx(),
1145  target_rot.zy(),
1146  target_rot.zz());
1147 
1148  align::RotationType ref_ROT(ref_rot.xx(),
1149  ref_rot.xy(),
1150  ref_rot.xz(),
1151  ref_rot.yx(),
1152  ref_rot.yy(),
1153  ref_rot.yz(),
1154  ref_rot.zx(),
1155  ref_rot.zy(),
1156  ref_rot.zz());
1157 
1158  const std::vector<double> deltaRot = {::deltaPhi(align::toAngles(target_ROT)[0], align::toAngles(ref_ROT)[0]),
1159  ::deltaPhi(align::toAngles(target_ROT)[1], align::toAngles(ref_ROT)[1]),
1160  ::deltaPhi(align::toAngles(target_ROT)[2], align::toAngles(ref_ROT)[2])};
1161 
1162  const auto& deltaTrans = target_ali[i].translation() - ref_ali[i].translation();
1163 
1164  // fill the histograms
1165  if (diff) {
1166  compare[AlignmentPI::t_x]->Fill(deltaTrans.x() * AlignmentPI::cmToUm);
1167  compare[AlignmentPI::t_y]->Fill(deltaTrans.y() * AlignmentPI::cmToUm);
1168  compare[AlignmentPI::t_z]->Fill(deltaTrans.z() * AlignmentPI::cmToUm);
1169 
1170  compare[AlignmentPI::rot_alpha]->Fill(deltaRot[0] * AlignmentPI::tomRad);
1171  compare[AlignmentPI::rot_beta]->Fill(deltaRot[1] * AlignmentPI::tomRad);
1172  compare[AlignmentPI::rot_gamma]->Fill(deltaRot[2] * AlignmentPI::tomRad);
1173  } else {
1174  compare[AlignmentPI::t_x]->SetBinContent(i + 1, deltaTrans.x() * AlignmentPI::cmToUm);
1175  compare[AlignmentPI::t_y]->SetBinContent(i + 1, deltaTrans.y() * AlignmentPI::cmToUm);
1176  compare[AlignmentPI::t_z]->SetBinContent(i + 1, deltaTrans.z() * AlignmentPI::cmToUm);
1177 
1178  compare[AlignmentPI::rot_alpha]->SetBinContent(i + 1, deltaRot[0] * AlignmentPI::tomRad);
1179  compare[AlignmentPI::rot_beta]->SetBinContent(i + 1, deltaRot[1] * AlignmentPI::tomRad);
1180  compare[AlignmentPI::rot_gamma]->SetBinContent(i + 1, deltaRot[2] * AlignmentPI::tomRad);
1181  }
1182 
1183  } // if it's the same detid
1184  } // loop on detids
1185  }
1186 
1187 } // namespace AlignmentPI
1188 
1189 #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
double trim2PIs(const double phi, const double tolerance=1.f)
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
const double tolerance
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
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
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 returnZeroIfNear2PI(const double phi)
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
static const unsigned int phase1size
Definition: value.py:1
std::map< AlignmentPI::PARTITION, double > Zbarycenters
EulerAngles toAngles(const RotationType &)
Convert rotation matrix to angles about x-, y-, z-axes (frame rotation).
Definition: Utilities.cc:8
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)
void fillComparisonHistograms(std::map< int, AlignmentPI::partitions > &boundaries, const std::vector< AlignTransform > &ref_ali, const std::vector< AlignTransform > &target_ali, std::unordered_map< AlignmentPI::coordinate, std::unique_ptr< TH1F > > &compare, bool diff=false, AlignmentPI::partitions checkPart=AlignmentPI::INVALID)
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
static std::atomic< unsigned int > counter
float x
unsigned int tidRing(const DetId &id) const
void displayNotSupported(TCanvas &canv, const unsigned int size)
def stdev(xlist)
Definition: plotscripts.py:69
void fillComparisonHistogram(const AlignmentPI::coordinate &coord, std::map< int, AlignmentPI::partitions > &boundaries, const std::vector< AlignTransform > &ref_ali, const std::vector< AlignTransform > &target_ali, std::unique_ptr< TH1F > &compare)
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()
std::string getStringFromPart(AlignmentPI::partitions i, bool isPhase2=false)
static constexpr auto TID
static const unsigned int mismatched