CMS 3D CMS Logo

TrackTools.h
Go to the documentation of this file.
1 #ifndef L1TMuonEndCap_TrackTools_h
2 #define L1TMuonEndCap_TrackTools_h
3 
4 #include <cmath>
5 
6 namespace emtf {
7 
8  // Please refers to DN-2015/017 for uGMT conventions
9 
10  int calc_ring(int station, int csc_ID, int strip);
11 
12  int calc_chamber(int station, int sector, int subsector, int ring, int csc_ID);
13 
14  int calc_uGMT_chamber(int csc_ID, int subsector, int neighbor, int station);
15 
16  // CSC trigger sector & CSC ID
17 
18  int get_trigger_sector(int ring, int station, int chamber);
19 
20  int get_trigger_csc_ID(int ring, int station, int chamber);
21 
22  // CSC max strip & max wire
23 
24  std::pair<int, int> get_csc_max_strip_and_wire(int station, int ring);
25 
26  // CSC max pattern & max quality
27 
28  std::pair<int, int> get_csc_max_pattern_and_quality(int station, int ring);
29 
30  // CSC max slope
31 
32  int get_csc_max_slope(int station, int ring, bool useRun3CCLUT_OTMB, bool useRun3CCLUT_TMB);
33 
34  // ___________________________________________________________________________
35  // coordinate ranges: phi[-180, 180] or [-pi, pi], theta[0, 90] or [0, pi/2]
36  inline double wrap_phi_deg(double deg) {
37  while (deg < -180.)
38  deg += 360.;
39  while (deg >= +180.)
40  deg -= 360.;
41  return deg;
42  }
43 
44  inline double wrap_phi_rad(double rad) {
45  while (rad < -M_PI)
46  rad += 2. * M_PI;
47  while (rad >= +M_PI)
48  rad -= 2. * M_PI;
49  return rad;
50  }
51 
52  inline double wrap_theta_deg(double deg) {
53  deg = std::abs(deg);
54  while (deg >= 180.)
55  deg -= 180.;
56  if (deg >= 180. / 2.)
57  deg = 180. - deg;
58  return deg;
59  }
60 
61  inline double wrap_theta_rad(double rad) {
62  rad = std::abs(rad);
63  while (rad >= M_PI)
64  rad -= M_PI;
65  if (rad >= M_PI / 2.)
66  rad = M_PI - rad;
67  return rad;
68  }
69 
70  // ___________________________________________________________________________
71  // radians, degrees
72  inline double deg_to_rad(double deg) {
73  constexpr double factor = M_PI / 180.;
74  return deg * factor;
75  }
76 
77  inline double rad_to_deg(double rad) {
78  constexpr double factor = 180. / M_PI;
79  return rad * factor;
80  }
81 
82  // ___________________________________________________________________________
83  // pt
84  inline double calc_pt(int bits) {
85  double pt = static_cast<double>(bits);
86  pt = 0.5 * (pt - 1);
87  return pt;
88  }
89 
90  inline int calc_pt_GMT(double val) {
91  val = (val * 2) + 1;
92  int gmt_pt = static_cast<int>(std::round(val));
93  gmt_pt = (gmt_pt > 511) ? 511 : gmt_pt;
94  return gmt_pt;
95  }
96 
97  // ___________________________________________________________________________
98  // eta
99  inline double calc_eta(int bits) {
100  double eta = static_cast<double>(bits);
101  eta *= 0.010875;
102  return eta;
103  }
104 
105  //inline double calc_eta_corr(int bits, int endcap) { // endcap [-1,+1]
106  // bits = (endcap == -1) ? bits+1 : bits;
107  // double eta = static_cast<double>(bits);
108  // eta *= 0.010875;
109  // return eta;
110  //}
111 
112  inline double calc_eta_from_theta_rad(double theta_rad) {
113  double eta = -1. * std::log(std::tan(theta_rad / 2.));
114  return eta;
115  }
116 
117  inline double calc_eta_from_theta_deg(double theta_deg, int endcap) { // endcap [-1,+1]
118  double theta_rad = deg_to_rad(wrap_theta_deg(theta_deg)); // put theta in [0, 90] range
119  double eta = calc_eta_from_theta_rad(theta_rad);
120  eta = (endcap == -1) ? -eta : eta;
121  return eta;
122  }
123 
124  inline int calc_eta_GMT(double val) {
125  val /= 0.010875;
126  int gmt_eta = static_cast<int>(std::round(val));
127  return gmt_eta;
128  }
129 
130  // ___________________________________________________________________________
131  // theta
132  inline double calc_theta_deg_from_int(int theta_int) {
133  double theta = static_cast<double>(theta_int);
134  theta = theta * (45.0 - 8.5) / 128. + 8.5;
135  return theta;
136  }
137 
138  inline double calc_theta_rad_from_int(int theta_int) { return deg_to_rad(calc_theta_deg_from_int(theta_int)); }
139 
140  inline double calc_theta_rad(double eta) {
141  double theta_rad = 2. * std::atan(std::exp(-1. * eta));
142  return theta_rad;
143  }
144 
145  inline double calc_theta_deg(double eta) { return rad_to_deg(calc_theta_rad(eta)); }
146 
147  inline int calc_theta_int(double theta, int endcap) { // theta in deg, endcap [-1,+1]
148  theta = (endcap == -1) ? (180. - theta) : theta;
149  theta = (theta - 8.5) * 128. / (45.0 - 8.5);
150  int theta_int = static_cast<int>(std::round(theta));
151  return theta_int;
152  }
153 
154  inline int calc_theta_int_rpc(double theta, int endcap) { // theta in deg, endcap [-1,+1]
155  theta = (endcap == -1) ? (180. - theta) : theta;
156  theta = (theta - 8.5) * (128. / 4.) / (45.0 - 8.5); // 4x coarser resolution
157  int theta_int = static_cast<int>(std::round(theta));
158  return theta_int;
159  }
160 
161  inline double calc_theta_rad_from_eta(double eta) {
162  double theta = std::atan2(1.0, std::sinh(eta)); // cot(theta) = sinh(eta)
163  return theta;
164  }
165 
167 
168  // ___________________________________________________________________________
169  // phi
170  inline double calc_phi_glob_deg(double loc, int sector) { // loc in deg, sector [1-6]
171  double glob = loc + 15. + (60. * (sector - 1));
172  glob = (glob < 180.) ? glob : glob - 360.;
173  return glob;
174  }
175 
176  inline double calc_phi_glob_rad(double loc, int sector) { // loc in rad, sector [1-6]
178  }
179 
180  inline double calc_phi_loc_deg(int bits) {
181  double loc = static_cast<double>(bits);
182  loc = (loc / 60.) - 22.;
183  return loc;
184  }
185 
186  inline double calc_phi_loc_rad(int bits) { return deg_to_rad(calc_phi_loc_deg(bits)); }
187 
188  //inline double calc_phi_loc_deg_corr(int bits, int endcap) { // endcap [-1,+1]
189  // double loc = static_cast<double>(bits);
190  // loc = (loc/60.) - 22.;
191  // loc = (endcap == -1) ? loc - (36./60.) : loc - (28./60.);
192  // return loc;
193  //}
194 
195  //inline double calc_phi_loc_rad_corr(int bits, int endcap) { // endcap [-1,+1]
196  // return deg_to_rad(calc_phi_loc_deg_corr(bits, endcap));
197  //}
198 
199  inline double calc_phi_loc_deg_from_glob(double glob, int sector) { // glob in deg, sector [1-6]
200  glob = wrap_phi_deg(glob); // put phi in [-180,180] range
201  double loc = glob - 15. - (60. * (sector - 1));
202  return loc;
203  }
204 
205  inline int calc_phi_loc_int(double glob, int sector) { // glob in deg, sector [1-6]
207  loc = ((loc + 22.) < 0.) ? loc + 360. : loc;
208  loc = (loc + 22.) * 60.;
209  int phi_int = static_cast<int>(std::round(loc));
210  return phi_int;
211  }
212 
213  inline int calc_phi_loc_int_rpc(double glob, int sector) { // glob in deg, sector [1-6]
215  loc = ((loc + 22.) < 0.) ? loc + 360. : loc;
216  loc = (loc + 22.) * 60. / 4.; // 4x coarser resolution
217  int phi_int = static_cast<int>(std::round(loc));
218  return phi_int;
219  }
220 
221  inline double calc_phi_GMT_deg(int bits) {
222  double phi = static_cast<double>(bits);
223  phi = (phi * 360. / 576.) + (180. / 576.);
224  return phi;
225  }
226 
227  //inline double calc_phi_GMT_deg_corr(int bits) { // AWB mod 09.02.16
228  // return (bits * 0.625 * 1.0208) + 0.3125 * 1.0208 + 0.552;
229  //}
230 
231  inline double calc_phi_GMT_rad(int bits) { return deg_to_rad(calc_phi_GMT_deg(bits)); }
232 
233  inline int calc_phi_GMT_int(double val) { // phi in deg
234  val = wrap_phi_deg(val); // put phi in [-180,180] range
235  val = (val - 180. / 576.) / (360. / 576.);
236  int gmt_phi = static_cast<int>(std::round(val));
237  return gmt_phi;
238  }
239 
240 } // namespace emtf
241 
242 #endif
int calc_eta_GMT(double val)
Definition: TrackTools.h:124
double wrap_theta_rad(double rad)
Definition: TrackTools.h:61
double calc_pt(int bits)
Definition: TrackTools.h:84
int calc_chamber(int station, int sector, int subsector, int ring, int csc_ID)
Definition: TrackTools.cc:28
double calc_phi_glob_rad(double loc, int sector)
Definition: TrackTools.h:176
int get_trigger_sector(int ring, int station, int chamber)
Definition: TrackTools.cc:85
double calc_phi_loc_deg(int bits)
Definition: TrackTools.h:180
int calc_uGMT_chamber(int csc_ID, int subsector, int neighbor, int station)
Definition: TrackTools.cc:53
double calc_theta_rad(double eta)
Definition: TrackTools.h:140
int calc_phi_loc_int(double glob, int sector)
Definition: TrackTools.h:205
double calc_phi_loc_deg_from_glob(double glob, int sector)
Definition: TrackTools.h:199
Definition: Event.h:15
std::pair< int, int > get_csc_max_pattern_and_quality(int station, int ring)
Definition: TrackTools.cc:169
std::vector< TString > glob(const std::string &pattern)
Definition: fileutil.cc:100
double calc_phi_loc_rad(int bits)
Definition: TrackTools.h:186
double calc_theta_deg_from_eta(double eta)
Definition: TrackTools.h:166
double wrap_theta_deg(double deg)
Definition: TrackTools.h:52
int calc_theta_int_rpc(double theta, int endcap)
Definition: TrackTools.h:154
int get_trigger_csc_ID(int ring, int station, int chamber)
Definition: TrackTools.cc:100
double calc_theta_rad_from_int(int theta_int)
Definition: TrackTools.h:138
double calc_eta_from_theta_rad(double theta_rad)
Definition: TrackTools.h:112
double calc_theta_deg_from_int(int theta_int)
Definition: TrackTools.h:132
double wrap_phi_deg(double deg)
Definition: TrackTools.h:36
int get_csc_max_slope(int station, int ring, bool useRun3CCLUT_OTMB, bool useRun3CCLUT_TMB)
Definition: TrackTools.cc:175
double wrap_phi_rad(double rad)
Definition: TrackTools.h:44
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
int calc_phi_loc_int_rpc(double glob, int sector)
Definition: TrackTools.h:213
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int calc_pt_GMT(double val)
Definition: TrackTools.h:90
double calc_phi_glob_deg(double loc, int sector)
Definition: TrackTools.h:170
double calc_theta_rad_from_eta(double eta)
Definition: TrackTools.h:161
double calc_theta_deg(double eta)
Definition: TrackTools.h:145
int calc_theta_int(double theta, int endcap)
Definition: TrackTools.h:147
#define M_PI
int calc_phi_GMT_int(double val)
Definition: TrackTools.h:233
double deg_to_rad(double deg)
Definition: TrackTools.h:72
int calc_ring(int station, int csc_ID, int strip)
Definition: TrackTools.cc:5
double calc_eta_from_theta_deg(double theta_deg, int endcap)
Definition: TrackTools.h:117
std::pair< int, int > get_csc_max_strip_and_wire(int station, int ring)
Definition: TrackTools.cc:141
double calc_phi_GMT_deg(int bits)
Definition: TrackTools.h:221
double rad_to_deg(double rad)
Definition: TrackTools.h:77
double calc_phi_GMT_rad(int bits)
Definition: TrackTools.h:231
double calc_eta(int bits)
Definition: TrackTools.h:99
MPlex< T, D1, D2, N > atan2(const MPlex< T, D1, D2, N > &y, const MPlex< T, D1, D2, N > &x)
Definition: Matriplex.h:648