CMS 3D CMS Logo

TPUtils.cc
Go to the documentation of this file.
1 #include <cmath>
2 
4 
5 namespace emtf::phase2::tp {
6 
7  // _______________________________________________________________________
8  // radians <-> degrees
9  float degToRad(float deg) {
10  constexpr float factor = M_PI / 180.;
11  return deg * factor;
12  }
13 
14  float radToDeg(float rad) {
15  constexpr float factor = 180. / M_PI;
16 
17  return rad * factor;
18  }
19 
20  // _______________________________________________________________________
21  // phi range: [-180..180] or [-pi..pi]
22  float wrapPhiDeg(float deg) {
23  float twopi = 360.;
24  float recip = 1.0 / twopi;
25 
26  return deg - (std::round(deg * recip) * twopi);
27  }
28 
29  float wrapPhiRad(float rad) {
30  const float twopi = M_PI * 2.;
31  const float recip = 1.0 / twopi;
32 
33  return rad - (std::round(rad * recip) * twopi);
34  }
35 
36  // _______________________________________________________________________
37  // theta
38  float calcThetaRadFromEta(float eta) {
39  float theta = std::atan2(1.0, std::sinh(eta)); // cot(theta) = sinh(eta)
40 
41  return theta;
42  }
43 
44  float calcThetaDegFromEta(float eta) {
46 
47  return theta;
48  }
49 
50  float calcThetaRadFromInt(int theta_int) {
51  float theta = degToRad(calcThetaDegFromInt(theta_int));
52 
53  return theta;
54  }
55 
56  float calcThetaDegFromInt(int theta_int) {
57  float theta = static_cast<float>(theta_int);
58 
59  theta = theta * (45.0 - 8.5) / 128. + 8.5;
60 
61  return theta;
62  }
63 
64  int calcThetaInt(int endcap, float theta) { // theta in deg [0..180], endcap [-1, +1]
65  theta = (endcap == -1) ? (180. - theta) : theta;
66  theta = (theta - 8.5) * 128. / (45.0 - 8.5);
67 
68  int theta_int = static_cast<int>(std::round(theta));
69 
70  theta_int = (theta_int <= 0) ? 1 : theta_int; // protect against invalid value
71 
72  return theta_int;
73  }
74 
75  // _______________________________________________________________________
76  // phi
77  float calcPhiGlobDegFromLoc(int sector, float loc) { // loc in deg, sector [1..6]
78  float glob = loc + 15. + (60. * (sector - 1));
79 
80  glob = (glob >= 180.) ? (glob - 360.) : glob;
81 
82  return glob;
83  }
84 
85  float calcPhiGlobRadFromLoc(int sector, float loc) { // loc in rad, sector [1..6]
86  float glob = degToRad(calcPhiGlobDegFromLoc(sector, radToDeg(loc)));
87 
88  return glob;
89  }
90 
91  float calcPhiLocDegFromInt(int phi_int) {
92  float loc = static_cast<float>(phi_int);
93 
94  loc = (loc / 60.) - 22.;
95 
96  return loc;
97  }
98 
99  float calcPhiLocRadFromInt(int phi_int) {
100  float loc = degToRad(calcPhiLocDegFromInt(phi_int));
101 
102  return loc;
103  }
104 
105  float calcPhiLocDegFromGlob(int sector, float glob) { // glob in deg [-180..180], sector [1..6]
106  glob = wrapPhiDeg(glob);
107 
108  float loc = glob - 15. - (60. * (sector - 1));
109 
110  return loc;
111  }
112 
113  int calcPhiInt(int sector, float glob) { // glob in deg [-180..180], sector [1..6]
114  float loc = calcPhiLocDegFromGlob(sector, glob);
115 
116  loc = ((loc + 22.) < 0.) ? (loc + 360.) : loc;
117  loc = (loc + 22.) * 60.;
118 
119  int phi_int = static_cast<int>(std::round(loc));
120 
121  return phi_int;
122  }
123 
124 } // namespace emtf::phase2::tp
float calcPhiLocDegFromInt(int)
Definition: TPUtils.cc:91
float calcThetaDegFromEta(float)
Definition: TPUtils.cc:44
float calcPhiLocRadFromInt(int)
Definition: TPUtils.cc:99
int calcThetaInt(int, float)
Definition: TPUtils.cc:64
float calcPhiLocDegFromGlob(int, float)
Definition: TPUtils.cc:105
float wrapPhiRad(float)
Definition: TPUtils.cc:29
float calcThetaDegFromInt(int)
Definition: TPUtils.cc:56
int calcPhiInt(int, float)
Definition: TPUtils.cc:113
float calcPhiGlobDegFromLoc(int, float)
Definition: TPUtils.cc:77
#define M_PI
float calcThetaRadFromInt(int)
Definition: TPUtils.cc:50
float radToDeg(float rad)
Definition: TPUtils.cc:14
float calcThetaRadFromEta(float)
Definition: TPUtils.cc:38
float calcPhiGlobRadFromLoc(int, float)
Definition: TPUtils.cc:85
Geom::Theta< T > theta() const
float degToRad(float deg)
Definition: TPUtils.cc:9
float wrapPhiDeg(float)
Definition: TPUtils.cc:22