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