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