File indexing completed on 2024-04-06 12:20:55
0001 #ifndef L1TMuonEndCap_TrackTools_h
0002 #define L1TMuonEndCap_TrackTools_h
0003
0004 #include <cmath>
0005
0006 namespace emtf {
0007
0008
0009
0010 int calc_ring(int station, int csc_ID, int strip);
0011
0012 int calc_chamber(int station, int sector, int subsector, int ring, int csc_ID);
0013
0014 int calc_uGMT_chamber(int csc_ID, int subsector, int neighbor, int station);
0015
0016
0017
0018 int get_trigger_sector(int ring, int station, int chamber);
0019
0020 int get_trigger_csc_ID(int ring, int station, int chamber);
0021
0022
0023
0024 std::pair<int, int> get_csc_max_strip_and_wire(int station, int ring);
0025
0026
0027
0028 std::pair<int, int> get_csc_max_pattern_and_quality(int station, int ring);
0029
0030
0031
0032 int get_csc_max_slope(int station, int ring, bool useRun3CCLUT_OTMB, bool useRun3CCLUT_TMB);
0033
0034
0035
0036 inline double wrap_phi_deg(double deg) {
0037 while (deg < -180.)
0038 deg += 360.;
0039 while (deg >= +180.)
0040 deg -= 360.;
0041 return deg;
0042 }
0043
0044 inline double wrap_phi_rad(double rad) {
0045 while (rad < -M_PI)
0046 rad += 2. * M_PI;
0047 while (rad >= +M_PI)
0048 rad -= 2. * M_PI;
0049 return rad;
0050 }
0051
0052 inline double wrap_theta_deg(double deg) {
0053 deg = std::abs(deg);
0054 while (deg >= 180.)
0055 deg -= 180.;
0056 if (deg >= 180. / 2.)
0057 deg = 180. - deg;
0058 return deg;
0059 }
0060
0061 inline double wrap_theta_rad(double rad) {
0062 rad = std::abs(rad);
0063 while (rad >= M_PI)
0064 rad -= M_PI;
0065 if (rad >= M_PI / 2.)
0066 rad = M_PI - rad;
0067 return rad;
0068 }
0069
0070
0071
0072 inline double deg_to_rad(double deg) {
0073 constexpr double factor = M_PI / 180.;
0074 return deg * factor;
0075 }
0076
0077 inline double rad_to_deg(double rad) {
0078 constexpr double factor = 180. / M_PI;
0079 return rad * factor;
0080 }
0081
0082
0083
0084 inline double calc_pt(int bits) {
0085 double pt = static_cast<double>(bits);
0086 pt = 0.5 * (pt - 1);
0087 return pt;
0088 }
0089
0090 inline int calc_pt_GMT(double val) {
0091 val = (val * 2) + 1;
0092 int gmt_pt = static_cast<int>(std::round(val));
0093 gmt_pt = (gmt_pt > 511) ? 511 : gmt_pt;
0094 return gmt_pt;
0095 }
0096
0097
0098
0099 inline double calc_eta(int bits) {
0100 double eta = static_cast<double>(bits);
0101 eta *= 0.010875;
0102 return eta;
0103 }
0104
0105
0106
0107
0108
0109
0110
0111
0112 inline double calc_eta_from_theta_rad(double theta_rad) {
0113 double eta = -1. * std::log(std::tan(theta_rad / 2.));
0114 return eta;
0115 }
0116
0117 inline double calc_eta_from_theta_deg(double theta_deg, int endcap) {
0118 double theta_rad = deg_to_rad(wrap_theta_deg(theta_deg));
0119 double eta = calc_eta_from_theta_rad(theta_rad);
0120 eta = (endcap == -1) ? -eta : eta;
0121 return eta;
0122 }
0123
0124 inline int calc_eta_GMT(double val) {
0125 val /= 0.010875;
0126 int gmt_eta = static_cast<int>(std::round(val));
0127 return gmt_eta;
0128 }
0129
0130
0131
0132 inline double calc_theta_deg_from_int(int theta_int) {
0133 double theta = static_cast<double>(theta_int);
0134 theta = theta * (45.0 - 8.5) / 128. + 8.5;
0135 return theta;
0136 }
0137
0138 inline double calc_theta_rad_from_int(int theta_int) { return deg_to_rad(calc_theta_deg_from_int(theta_int)); }
0139
0140 inline double calc_theta_rad(double eta) {
0141 double theta_rad = 2. * std::atan(std::exp(-1. * eta));
0142 return theta_rad;
0143 }
0144
0145 inline double calc_theta_deg(double eta) { return rad_to_deg(calc_theta_rad(eta)); }
0146
0147 inline int calc_theta_int(double theta, int endcap) {
0148 theta = (endcap == -1) ? (180. - theta) : theta;
0149 theta = (theta - 8.5) * 128. / (45.0 - 8.5);
0150 int theta_int = static_cast<int>(std::round(theta));
0151 return theta_int;
0152 }
0153
0154 inline int calc_theta_int_rpc(double theta, int endcap) {
0155 theta = (endcap == -1) ? (180. - theta) : theta;
0156 theta = (theta - 8.5) * (128. / 4.) / (45.0 - 8.5);
0157 int theta_int = static_cast<int>(std::round(theta));
0158 return theta_int;
0159 }
0160
0161 inline double calc_theta_rad_from_eta(double eta) {
0162 double theta = std::atan2(1.0, std::sinh(eta));
0163 return theta;
0164 }
0165
0166 inline double calc_theta_deg_from_eta(double eta) { return rad_to_deg(calc_theta_rad_from_eta(eta)); }
0167
0168
0169
0170 inline double calc_phi_glob_deg(double loc, int sector) {
0171 double glob = loc + 15. + (60. * (sector - 1));
0172 glob = (glob < 180.) ? glob : glob - 360.;
0173 return glob;
0174 }
0175
0176 inline double calc_phi_glob_rad(double loc, int sector) {
0177 return deg_to_rad(calc_phi_glob_deg(rad_to_deg(loc), sector));
0178 }
0179
0180 inline double calc_phi_loc_deg(int bits) {
0181 double loc = static_cast<double>(bits);
0182 loc = (loc / 60.) - 22.;
0183 return loc;
0184 }
0185
0186 inline double calc_phi_loc_rad(int bits) { return deg_to_rad(calc_phi_loc_deg(bits)); }
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 inline double calc_phi_loc_deg_from_glob(double glob, int sector) {
0200 glob = wrap_phi_deg(glob);
0201 double loc = glob - 15. - (60. * (sector - 1));
0202 return loc;
0203 }
0204
0205 inline int calc_phi_loc_int(double glob, int sector) {
0206 double loc = calc_phi_loc_deg_from_glob(glob, sector);
0207 loc = ((loc + 22.) < 0.) ? loc + 360. : loc;
0208 loc = (loc + 22.) * 60.;
0209 int phi_int = static_cast<int>(std::round(loc));
0210 return phi_int;
0211 }
0212
0213 inline int calc_phi_loc_int_rpc(double glob, int sector) {
0214 double loc = calc_phi_loc_deg_from_glob(glob, sector);
0215 loc = ((loc + 22.) < 0.) ? loc + 360. : loc;
0216 loc = (loc + 22.) * 60. / 4.;
0217 int phi_int = static_cast<int>(std::round(loc));
0218 return phi_int;
0219 }
0220
0221 inline double calc_phi_GMT_deg(int bits) {
0222 double phi = static_cast<double>(bits);
0223 phi = (phi * 360. / 576.) + (180. / 576.);
0224 return phi;
0225 }
0226
0227
0228
0229
0230
0231 inline double calc_phi_GMT_rad(int bits) { return deg_to_rad(calc_phi_GMT_deg(bits)); }
0232
0233 inline int calc_phi_GMT_int(double val) {
0234 val = wrap_phi_deg(val);
0235 val = (val - 180. / 576.) / (360. / 576.);
0236 int gmt_phi = static_cast<int>(std::round(val));
0237 return gmt_phi;
0238 }
0239
0240 }
0241
0242 #endif