Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:02

0001 #include <cmath>
0002 
0003 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/TPUtils.h"
0004 
0005 namespace emtf::phase2::tp {
0006 
0007   // _______________________________________________________________________
0008   // radians <-> degrees
0009   float degToRad(float deg) {
0010     constexpr float factor = M_PI / 180.;
0011     return deg * factor;
0012   }
0013 
0014   float radToDeg(float rad) {
0015     constexpr float factor = 180. / M_PI;
0016 
0017     return rad * factor;
0018   }
0019 
0020   // _______________________________________________________________________
0021   // phi range: [-180..180] or [-pi..pi]
0022   float wrapPhiDeg(float deg) {
0023     float twopi = 360.;
0024     float recip = 1.0 / twopi;
0025 
0026     return deg - (std::round(deg * recip) * twopi);
0027   }
0028 
0029   float wrapPhiRad(float rad) {
0030     const float twopi = M_PI * 2.;
0031     const float recip = 1.0 / twopi;
0032 
0033     return rad - (std::round(rad * recip) * twopi);
0034   }
0035 
0036   // _______________________________________________________________________
0037   // theta
0038   float calcThetaRadFromEta(float eta) {
0039     float theta = std::atan2(1.0, std::sinh(eta));  // cot(theta) = sinh(eta)
0040 
0041     return theta;
0042   }
0043 
0044   float calcThetaDegFromEta(float eta) {
0045     float theta = radToDeg(calcThetaRadFromEta(eta));
0046 
0047     return theta;
0048   }
0049 
0050   float calcThetaRadFromInt(int theta_int) {
0051     float theta = degToRad(calcThetaDegFromInt(theta_int));
0052 
0053     return theta;
0054   }
0055 
0056   float calcThetaDegFromInt(int theta_int) {
0057     float theta = static_cast<float>(theta_int);
0058 
0059     theta = theta * (45.0 - 8.5) / 128. + 8.5;
0060 
0061     return theta;
0062   }
0063 
0064   int calcThetaInt(int endcap, float theta) {  // theta in deg [0..180], endcap [-1, +1]
0065     theta = (endcap == -1) ? (180. - theta) : theta;
0066     theta = (theta - 8.5) * 128. / (45.0 - 8.5);
0067 
0068     int theta_int = static_cast<int>(std::round(theta));
0069 
0070     theta_int = (theta_int <= 0) ? 1 : theta_int;  // protect against invalid value
0071 
0072     return theta_int;
0073   }
0074 
0075   // _______________________________________________________________________
0076   // phi
0077   float calcPhiGlobDegFromLoc(int sector, float loc) {  // loc in deg, sector [1..6]
0078     float glob = loc + 15. + (60. * (sector - 1));
0079 
0080     glob = (glob >= 180.) ? (glob - 360.) : glob;
0081 
0082     return glob;
0083   }
0084 
0085   float calcPhiGlobRadFromLoc(int sector, float loc) {  // loc in rad, sector [1..6]
0086     float glob = degToRad(calcPhiGlobDegFromLoc(sector, radToDeg(loc)));
0087 
0088     return glob;
0089   }
0090 
0091   float calcPhiLocDegFromInt(int phi_int) {
0092     float loc = static_cast<float>(phi_int);
0093 
0094     loc = (loc / 60.) - 22.;
0095 
0096     return loc;
0097   }
0098 
0099   float calcPhiLocRadFromInt(int phi_int) {
0100     float loc = degToRad(calcPhiLocDegFromInt(phi_int));
0101 
0102     return loc;
0103   }
0104 
0105   float calcPhiLocDegFromGlob(int sector, float glob) {  // glob in deg [-180..180], sector [1..6]
0106     glob = wrapPhiDeg(glob);
0107 
0108     float loc = glob - 15. - (60. * (sector - 1));
0109 
0110     return loc;
0111   }
0112 
0113   int calcPhiInt(int sector, float glob) {  // glob in deg [-180..180], sector [1..6]
0114     float loc = calcPhiLocDegFromGlob(sector, glob);
0115 
0116     loc = ((loc + 22.) < 0.) ? (loc + 360.) : loc;
0117     loc = (loc + 22.) * 60.;
0118 
0119     int phi_int = static_cast<int>(std::round(loc));
0120 
0121     return phi_int;
0122   }
0123 
0124 }  // namespace emtf::phase2::tp