ATLAS Offline Software
Loading...
Searching...
No Matches
FPGATrackSimKeyLayerTool.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
4
5//
6//
7// Tool for doing Key Layer Math
8//
9//
10
11std::pair<double, double> FPGATrackSimKeyLayerTool::getXY(double r, double phi) const
12{
13 return std::pair<double, double>(r * cos(phi), r * sin(phi));
14}
15
16std::pair<double, double> FPGATrackSimKeyLayerTool::getRotationAngles(const std::pair<double, double>& xy1, const std::pair<double, double>& xy2) const
17{
18 double dr12x = xy2.first - xy1.first;
19 double dr12y = xy2.second - xy1.second;
20 double dr12mag = std::hypot(dr12x, dr12y);
21 double cos_rot = dr12y / dr12mag;
22 double sin_rot = -dr12x / dr12mag;
23 return std::pair<double, double>(cos_rot, sin_rot);
24}
25
26std::pair<double, double> FPGATrackSimKeyLayerTool::rotateXY(const std::pair<double, double>& xy, const std::pair<double, double>& ang) const
27{
28 return std::pair<double, double>(xy.first * ang.first + xy.second * ang.second,
29 -xy.first * ang.second + xy.second * ang.first);
30}
31
33{
35
36 auto xy1 = getXY(m_R1, keypars.phi1);
37 auto xy2 = getXY(m_R2, keypars.phi2);
38
39 result.rotang = getRotationAngles(xy1, xy2);
40 result.xy1p = rotateXY(xy1, result.rotang);
41 result.xy2p = rotateXY(xy2, result.rotang);
42 result.y = result.xy2p.second - result.xy1p.second;
43
44 return result;
45}
46
47std::pair<double, double> FPGATrackSimKeyLayerTool::getRotatedHit(const std::pair<double, double>& rotang, double rHit, double phiHit) const
48{
49 auto xyh = getXY(rHit, phiHit);
50 return rotateXY(xyh, rotang);
51}
52
54{
55 KeyLyrPars retv;
60
62 if (Rinv != 0)
63 {
64 double R = 1 / Rinv;
65 auto xy1 = getXY(m_R1, retv.phi1);
66 auto xy2 = getXY(m_R2, retv.phi2);
67 double ysqr = (xy2.first - xy1.first) * (xy2.first - xy1.first) + (xy2.second - xy1.second) * (xy2.second - xy1.second);
68 double sign = (R > 0) - (R < 0);
69 retv.xm = -1 * sign * (std::abs(R) - sqrt(R * R - ysqr / 4.0));
70 }
71 else
72 {
73 retv.xm = 0;
74 }
75
76 return retv;
77}
78
80{
81
83 pars[FPGATrackSimTrackPars::IZ0] = (keypars.z1 * m_R2 - keypars.z2 * m_R1) / (m_R2 - m_R1);
85
86 // This is the exact math which is a bit messy
87 // if you want the math contact lipeles@sas.upenn.edu
88
89 double xm = keypars.xm;
90
91 auto rotated_coords = getRotatedConfig(keypars);
92 auto xy1p = rotated_coords.xy1p;
93 auto rotang = rotated_coords.rotang;
94 auto y = rotated_coords.y;
95
96 // reverse rotation
97 auto revang = rotang;
98 revang.second = -rotang.second;
99
100 if (xm != 0)
101 {
102 double Rinv = 2 * xm / (xm * xm + (y / 2) * (y / 2));
103 double d = (y * y / 4.0 - xm * xm) / (2.0 * xm);
104 double sign = (xm > 0) - (xm < 0);
105
107
108
109 std::pair<double, double> xycp(-d + xy1p.first, y / 2.0 + xy1p.second);
110
111 pars[FPGATrackSimTrackPars::ID0] = -1 * sign * (std::abs(1 / Rinv) - std::hypot(xycp.first, xycp.second));
112
113 auto xyc = rotateXY(xycp, revang);
114
115 pars[FPGATrackSimTrackPars::IPHI] = std::atan2(sign * -xyc.first, sign * xyc.second);
116 }
117 else
118 {
119 pars[FPGATrackSimTrackPars::IHIP] = 0.0;
120 pars[FPGATrackSimTrackPars::ID0] = -1 * xy1p.first;
121 pars[FPGATrackSimTrackPars::IPHI] = std::atan2(rotang.first, -rotang.second);
122 }
123
124 return pars;
125}
126
127double FPGATrackSimKeyLayerTool::zExpected(const KeyLyrPars& keypars, double r) const
128{
129 return (keypars.z2 - keypars.z1) / (m_R2 - m_R1) * (r - m_R1) + keypars.z1;
130}
131
132// takes hit position and calculated what xm should be for that hit
133double FPGATrackSimKeyLayerTool::xmForHit(const KeyLyrPars& keypars, double rHit, double phiHit) const
134{
135 auto rotated_coords = getRotatedConfig(keypars);
136 auto xy1p = rotated_coords.xy1p;
137 auto rotang = rotated_coords.rotang;
138 auto y = rotated_coords.y;
139
140 auto xyhp = getRotatedHit(rotang, rHit, phiHit);
141 double xh = xyhp.first - xy1p.first;
142 double yh = xyhp.second - xy1p.second;
143
144 // use taylor expanded xm calculation
145 double sign = ((yh > 0) && (yh < y)) ? 1 : -1;
146 if ((std::abs(yh) < std::abs(xh)) || (std::abs(y - yh) < std::abs(xh)))
147 {
148 return ((xh > 0) ? 1 : -1) * 100000;
149 }
150
151 double xm_taylor = sign * y * y / (y * y - 4 * xh * xh - 4 * (yh - y / 2.0) * (yh - y / 2.0)) * xh;
152
153 return xm_taylor;
154}
155
156// Find shift from nominal track to hit in the "x" direction
157double FPGATrackSimKeyLayerTool::deltaX(const KeyLyrPars& keypars, double rHit, double phiHit) const
158{
159 auto rotated_coords = getRotatedConfig(keypars);
160
161 auto rotang = rotated_coords.rotang;
162
163 auto xyhp = getRotatedHit(rotang, rHit, phiHit);
164
165 double xh = xyhp.first-rotated_coords.xy1p.first;
166
167 return xh - xExpected(keypars,rHit, phiHit);
168}
169
170// Find shift from nominal track to hit in the "x" direction
171double FPGATrackSimKeyLayerTool::xExpected(const KeyLyrPars& keypars, double rHit, double phiHit) const
172{
173 auto rotated_coords = getRotatedConfig(keypars);
174
175 auto rotang = rotated_coords.rotang;
176 auto y = rotated_coords.y;
177
178 auto xyhp = getRotatedHit(rotang, rHit, phiHit);
179
180 double yh = xyhp.second-rotated_coords.xy1p.second;
181
182 return keypars.xm * (keypars.xm * keypars.xm + yh * (y - yh)) / (keypars.xm * keypars.xm + (y / 2) * (y / 2));
183}
184
185
Scalar phi() const
phi method
Binning Classes for BinTool.
int sign(int a)
#define y
static double phiFromPars(double r, const FPGATrackSimTrackPars &pars)
static constexpr double CurvatureConstant
static double zFromPars(double r, const FPGATrackSimTrackPars &pars)
static double EtaFromTheta(double theta)
double deltaX(const KeyLyrPars &keypars, double rHit, double phiHit) const
rotatedConfig getRotatedConfig(const KeyLyrPars &keypars) const
std::pair< double, double > getXY(double r, double phi) const
KeyLyrPars trackParsToKeyPars(const FPGATrackSimTrackPars &pars) const
double xExpected(const KeyLyrPars &keypars, double rHit, double phiHit) const
std::pair< double, double > getRotatedHit(const std::pair< double, double > &rotang, double rHit, double phiHit) const
std::pair< double, double > rotateXY(const std::pair< double, double > &xy, const std::pair< double, double > &ang) const
FPGATrackSimTrackPars keyParsToTrackPars(const KeyLyrPars &keypars) const
double zExpected(const KeyLyrPars &keypars, double r) const
std::pair< double, double > getRotationAngles(const std::pair< double, double > &xy1, const std::pair< double, double > &xy2) const
double xmForHit(const KeyLyrPars &keypars, double rHit, double phiHit) const
int r
Definition globals.cxx:22