ATLAS Offline Software
Loading...
Searching...
No Matches
AlphaBetaEstimate.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "AlphaBetaEstimate.h"
6
7#include <cmath>
8
10
12
13
14// --------------------------------------------------------------------------------
15// --------------------------------------------------------------------------------
16
18 const std::string& name,
19 const IInterface* parent):
20 AthAlgTool(type, name, parent)
21{
22}
23
24// --------------------------------------------------------------------------------
25// --------------------------------------------------------------------------------
26
28 const TrigL2MuonSA::PtEndcapLUTSvc* ptEndcapLUTSvc)
29{
30 m_use_mcLUT = use_mcLUT;
31 m_ptEndcapLUT = ptEndcapLUTSvc->ptEndcapLUT();
32}
33
34// --------------------------------------------------------------------------------
35// --------------------------------------------------------------------------------
36
38 TrigL2MuonSA::TgcFitResult& tgcFitResult,
39 TrigL2MuonSA::TrackPattern& trackPattern,
40 const TrigL2MuonSA::MuonRoad& /*muonRoad*/) const
41{
42 const int MAX_STATION = 6;
43 const double PHI_RANGE = 12./(M_PI/8.);
44
45 // computing ALPHA, BETA and RADIUS
46 float InnerSlope = 0;
47 float MiddleSlope = 0;
48 float MiddleIntercept = 0;
49 float InnerR = 0;
50 float InnerZ = 0;
51 float EER = 0;//ee
52 float EEZ = 0;//ee
53 float MiddleR = 0;
54 float MiddleZ = 0;
55 float OuterR = 0;
56 float OuterZ = 0;
57 float EBIR = 0;//endcap barrel inner
58 float EBIZ = 0;//endcap barrel inner
59 // float CSCSlope = 0;//csc currrently not used for gamma-pt
60 float CSCR = 0;//csc
61 float CSCZ = 0;//csc
62
63 // set etaMap and phi
64 double phi = 0.;
65 double phim = 0.;
66
67 TrigL2MuonSA::SuperPoint* superPoint;
68
69 for (int i_station=0; i_station<MAX_STATION; i_station++) {
70
71 int chamber = 0;
72 if ( i_station == 0 ) chamber = xAOD::L2MuonParameters::Chamber::EndcapInner;
73 if ( i_station == 1 ) chamber = xAOD::L2MuonParameters::Chamber::EndcapMiddle;
74 if ( i_station == 2 ) chamber = xAOD::L2MuonParameters::Chamber::EndcapOuter;
75 if ( i_station == 3 ) chamber = xAOD::L2MuonParameters::Chamber::EndcapExtra;
76 if ( i_station == 4 ) chamber = xAOD::L2MuonParameters::Chamber::BarrelInner;
77 if ( i_station == 5 ) chamber = xAOD::L2MuonParameters::Chamber::CSC;
78 superPoint = &(trackPattern.superPoints[chamber]);
79
80 if ( superPoint->Npoint > 2 && superPoint->R > 0.) {
81 if (chamber==3) {
82 InnerSlope = superPoint->Alin;
83 InnerR = superPoint->R;
84 InnerZ = superPoint->Z;
85 } if ( chamber==4 ) {
86 MiddleSlope = superPoint->Alin;
87 MiddleIntercept = superPoint->R - MiddleSlope*superPoint->Z;
88 MiddleR = superPoint->R;
89 MiddleZ = superPoint->Z;
90 } if ( chamber==5 ) {
91 OuterR = superPoint->R;
92 OuterZ = superPoint->Z;
93 } if ( chamber==6 ) {
94 EER = superPoint->R;
95 EEZ = superPoint->Z;
96 } if ( chamber==0 ) {//barrel inner
97 EBIR = superPoint->R;
98 EBIZ = superPoint->Z;
99 } if ( chamber==7 ) {//csc
100 //CSCSlope = superPoint->Alin; //currently not used
101 CSCR = superPoint->R;
102 CSCZ = superPoint->Z;
103 }
104 phim = superPoint->Phim;
105 }
106 } // end loop for stations
107
108 if (tgcFitResult.isSuccess) {
109 // TGC data properly read
110
111 double phi1 = tgcFitResult.tgcMid1[1];
112 double phi2 = tgcFitResult.tgcMid2[1];
113 if ( isZero(tgcFitResult.tgcMid1[3]) || isZero(tgcFitResult.tgcMid2[3]) ) {
114 if ( !isZero(tgcFitResult.tgcMid1[3]) ) phi = phi1;
115 if ( !isZero(tgcFitResult.tgcMid2[3]) ) phi = phi2;
116 } else if( phi1*phi2 < 0 && std::abs(phi1)>(M_PI/2.) ) {
117 double tmp1 = (phi1>0)? phi1 - M_PI : phi1 + M_PI;
118 double tmp2 = (phi2>0)? phi2 - M_PI : phi2 + M_PI;
119 double tmp = (tmp1+tmp2)/2.;
120 phi = (tmp>0.)? tmp - M_PI : tmp + M_PI;
121 } else {
122 phi = (phi2+phi1)/2.;
123 }
124
125 if ( isZero(MiddleZ) ) {
126 if ( !isZero(tgcFitResult.tgcMid1[0]) && !isZero(tgcFitResult.tgcMid2[0]) ) {
127 trackPattern.etaMap = (tgcFitResult.tgcMid1[0]+tgcFitResult.tgcMid2[0])/2;
128 } else {
129 trackPattern.etaMap = (tgcFitResult.tgcMid1[0]!=0)?
130 tgcFitResult.tgcMid1[0] : tgcFitResult.tgcMid2[0];
131 }
132 }
133
134 double etaInner = 0.;
135 double etaMiddle = 0.;
136 if ( !isZero(MiddleZ) ) {
137 double theta = std::atan(MiddleR/std::abs(MiddleZ));
138 etaMiddle = -std::log(std::tan(theta/2.))*MiddleZ/std::abs(MiddleZ);
139 }
140
141 if ( !isZero(InnerZ) ) {
142 double theta = std::atan(InnerR/std::abs(InnerZ));
143 etaInner = -std::log(std::tan(theta/2.))*InnerZ/std::abs(InnerZ);
144 }
145
146 if ( !isZero(MiddleZ) ) trackPattern.etaMap = etaMiddle;
147 else if ( !isZero(InnerZ) ) trackPattern.etaMap = etaInner;
148 if ( !isZero(tgcFitResult.tgcInn[3]) ) phi = tgcFitResult.tgcInn[1];
149
150 if ( phim > M_PI+0.1 ) phim = phim - 2*M_PI;
151 if ( phim >= 0 ) trackPattern.phiMap = (phi>=0.)? phi - phim : phim - std::abs(phi);
152 else trackPattern.phiMap = phi - phim;
153
154 int Octant = (int)(tgcFitResult.tgcMid1[1] / (M_PI/4.));
155 double PhiInOctant = std::abs(tgcFitResult.tgcMid1[1] - Octant * (M_PI/4.));
156 if (PhiInOctant > (M_PI/8.)) PhiInOctant = (M_PI/4.) - PhiInOctant;
157
158 trackPattern.endcapBeta = 0.0;
159 trackPattern.phiMS = phi;
160 trackPattern.pt = std::abs(tgcFitResult.tgcPT);
161 trackPattern.charge = (tgcFitResult.tgcPT!=0.0)? tgcFitResult.tgcPT/std::abs(tgcFitResult.tgcPT) : +1;
162
163 trackPattern.phiBin = static_cast<int>(PhiInOctant * PHI_RANGE);
164 trackPattern.etaBin = static_cast<int>((std::abs(tgcFitResult.tgcMid1[0])-1.)/0.05);
165
166 double phiEE = (tgcFitResult.tgcMid1[1]>0) ? tgcFitResult.tgcMid1[1] : tgcFitResult.tgcMid1[1] + 2*M_PI;
167 trackPattern.phiBinEE = static_cast<int> (phiEE*96/M_PI);
168
169 } else {
170 // TGC data readout problem -> use RoI (eta, phi) and assume straight track
171
172 trackPattern.etaMap = p_roids->eta();
173 phi = p_roids->phi();
174
175 if ( phim > M_PI+0.1 ) phim = phim - 2*M_PI;
176 if ( phim >= 0 ) trackPattern.phiMap = (phi>=0.)? phi - phim : phim - std::abs(phi);
177 else trackPattern.phiMap = phi - phim;
178
179 int Octant = (int)(p_roids->phi() / (M_PI/4.));
180 double PhiInOctant = std::abs(p_roids->phi() - Octant * (M_PI/4.));
181 if (PhiInOctant > (M_PI/8.)) PhiInOctant = (M_PI/4.) - PhiInOctant;
182
183 trackPattern.endcapBeta = 0.0;
184 trackPattern.phiMS = phi;
185 trackPattern.pt = 0;
186 trackPattern.charge = 0;
187
188 trackPattern.phiBin = static_cast<int>(PhiInOctant * PHI_RANGE);
189 trackPattern.etaBin = static_cast<int>((std::abs(p_roids->eta())-1.)/0.05);
190
191 double phiEE = (p_roids->phi()>0) ? p_roids->phi() : p_roids->phi() + 2*M_PI;
192 trackPattern.phiBinEE = static_cast<int> (phiEE*96/M_PI);
193
194 }
195
196 if (!isZero(MiddleZ) && !isZero(OuterZ)) {
197 double slope = (OuterR-MiddleR)/(OuterZ-MiddleZ);
198 double inter = MiddleR - slope*MiddleZ;
199
200 trackPattern.endcapAlpha = (*m_ptEndcapLUT)->alpha(MiddleZ,MiddleR,OuterZ,OuterR);
201 trackPattern.slope = slope;
202 trackPattern.intercept = inter;
203 if (!isZero(InnerR)) {
204 trackPattern.endcapBeta = std::abs( std::atan(InnerSlope) - std::atan(slope) );
205 trackPattern.deltaR = slope * InnerZ + MiddleIntercept - InnerR;
206 double sign = trackPattern.deltaR / std::abs(trackPattern.deltaR);
207 trackPattern.endcapRadius = computeRadius(InnerSlope, InnerR, InnerZ,
208 slope, MiddleR, MiddleZ,
209 sign);
210 }
211 if (!isZero(CSCZ)) {
212 if(trackPattern.large_dPhidZ && (6==trackPattern.phiBin || 7==trackPattern.phiBin) ){
213 trackPattern.cscGamma = std::abs( std::atan( (MiddleR-CSCR)/(MiddleZ-CSCZ) ) - std::atan(MiddleSlope) );
214 }else{
215 double OuterR_modified=OuterR*trackPattern.outerCorFactor;//assume dphidz=0
216 double slope_modified=(OuterR_modified-MiddleR)/(OuterZ-MiddleZ);
217 trackPattern.cscGamma = std::abs( std::atan( (MiddleR-CSCR)/(MiddleZ-CSCZ) ) - std::atan(slope_modified) );
218 ATH_MSG_DEBUG("OuterR_modified=" << OuterR_modified << " slope_modified=" << slope_modified);
219 }
220 }
221 } else {
222 if( trackPattern.pt >= 8. || !tgcFitResult.isSuccess) {
223 if(!isZero(MiddleZ)) {
224 double Ze = MiddleZ+(std::abs(MiddleZ)/MiddleZ)*1000.;
225 double Re = MiddleSlope*(Ze) + MiddleIntercept;
226
227 trackPattern.endcapAlpha = (*m_ptEndcapLUT)->alpha(MiddleZ,MiddleR,Ze,Re);
228 trackPattern.slope = MiddleSlope;
229 trackPattern.intercept = MiddleIntercept;
230 }
231 }
232
233 if (!isZero(MiddleZ) && !isZero(InnerZ)) {
234 trackPattern.endcapBeta = std::abs( std::atan(InnerSlope) - std::atan(MiddleSlope) );
235 trackPattern.deltaR = MiddleSlope*InnerZ + MiddleIntercept - InnerR;
236 double sign = trackPattern.deltaR / std::abs(trackPattern.deltaR);
237 trackPattern.endcapRadius = computeRadius(InnerSlope, InnerR, InnerZ,
238 MiddleSlope, MiddleR, MiddleZ,
239 sign);
240 }
241 if(!isZero(MiddleZ) && !isZero(CSCZ)){
242 trackPattern.cscGamma = std::abs( std::atan( (MiddleR-CSCR)/(MiddleZ-CSCZ) ) - std::atan(MiddleSlope) );
243 }
244 }
245
246 double distance=9999;//distance between track and IP
247 if (std::abs(EEZ)>10000 && std::abs(EEZ)<10600){//Small
248 if ( (!isZero(EBIZ) && !isZero(EEZ)) && !isZero(MiddleZ) ){
249 trackPattern.endcapRadius3P = computeRadius3Points(EBIZ, EBIR, EEZ, EER, MiddleZ, MiddleR);
250 distance = calcDistance(EBIZ, EBIR, EEZ, EER, MiddleZ, MiddleR);
251 }
252 }
253 if (std::abs(EEZ)>10600 && std::abs(EEZ)<12000){//Large
254 if ( (!isZero(InnerZ) && !isZero(EEZ)) && !isZero(MiddleZ) ){
255 trackPattern.endcapRadius3P = computeRadius3Points(InnerZ, InnerR, EEZ, EER, MiddleZ, MiddleR);
256 distance = calcDistance(InnerZ, InnerR, EEZ, EER, MiddleZ, MiddleR);
257 }
258 }
259 if (distance>500) trackPattern.endcapRadius3P=0;//Reconstruction may fail
260
261 ATH_MSG_DEBUG("... alpha/beta/endcapRadius/cscGamma/charge/s_address="
262 << trackPattern.endcapAlpha << "/" << trackPattern.endcapBeta << "/" << trackPattern.endcapRadius3P << "/"
263 << trackPattern.cscGamma << "/" << trackPattern.charge << "/" << trackPattern.s_address );
264 //
265 return StatusCode::SUCCESS;
266}
267
268// --------------------------------------------------------------------------------
269// --------------------------------------------------------------------------------
270
271double TrigL2MuonSA::AlphaBetaEstimate::computeRadius(double InnerSlope, double InnerR, double InnerZ,
272 double MiddleSlope, double MiddleR, double MiddleZ,
273 double sign) const
274{
275 double cr1 = 0.080/400;
276 double cr2 = cr1;
277 double x1 = InnerZ;
278 if (std::abs(x1)>=0.1) {
279 double x2 = MiddleZ;
280 double y1 = InnerR;
281 double y2 = MiddleR;
282 double A1 = InnerSlope;
283 double A2 = MiddleSlope;
284 if (!(std::abs(MiddleSlope+999)<0.1)) {
285 A2 = MiddleSlope;
286 cr2 = cr1/10;
287 }
288
289 // find centre of circonference
290 double xm = (x1+x2)/2.;
291 double ym = (y1+y2)/2.;
292 double c1 = (x2-x1)*xm+(y2-y1)*ym;
293 double c2_1 = -x1-A1*y1;
294 double c2_2 = -x2-A2*y2;
295 double yR1 = (-c1-c2_1*(x2-x1))/(A1*(x2-x1)-(y2-y1));
296 double yR2 = (-c1-c2_2*(x2-x1))/(A2*(x2-x1)-(y2-y1));
297 double xR1 = -A1*yR1-c2_1;
298 double xR2 = -A2*yR2-c2_2;
299
300 double xR = ((1./cr1)*xR1+(1./cr2)*xR2)/((1./cr1)+(1./cr2));
301 double yR = ((1./cr1)*yR1+(1./cr2)*yR2)/((1./cr1)+(1./cr2));
302 double radius = 0.5*(std::sqrt((xR-x1)*(xR-x1)+(yR-y1)*(yR-y1))+std::sqrt((xR-x2)*(xR-x2)+(yR-y2)*(yR-y2)));
303 return sign * radius;
304 }
305
306 return 0.;
307}
308
309double TrigL2MuonSA::AlphaBetaEstimate::computeRadius3Points(double InnerZ, double InnerR,
310 double EEZ, double EER,
311 double MiddleZ, double MiddleR)
312const {
313 double radius_EE;
314
315 double a3;
316
317 double m = 0.;
318 double cost = 0.;
319 double x0 = 0., y0 = 0., x2 = 0., y2 = 0., x3 = 0., y3 = 0.;
320 double tm = 0.;
321
322 a3 = ( MiddleZ - InnerZ ) / ( MiddleR - InnerR );
323
324 m = a3;
325 cost = std::cos(std::atan(m));
326 x2 = EER - InnerR;
327 y2 = EEZ - InnerZ;
328 x3 = MiddleR - InnerR;
329 y3 = MiddleZ - InnerZ;
330
331 tm = x2;
332 x2 = ( x2 + y2*m)*cost;
333 y2 = (-tm*m + y2 )*cost;
334
335 tm = x3;
336 x3 = ( x3 + y3*m)*cost;
337 y3 = (-tm*m + y3 )*cost;
338
339 x0 = x3/2.;
340 y0 = (y2*y2 + x2*x2 -x2*x3)/(2*y2);
341
342 radius_EE = std::sqrt(x0*x0 + y0*y0);
343 return radius_EE;
344}
345
346double TrigL2MuonSA::AlphaBetaEstimate::calcDistance(double x1,double y1,double x2,double y2,double x3,double y3) const {
347 double xm1=(x1+x2)/2;
348 double xm2=(x2+x3)/2;
349 double ym1=(y1+y2)/2;
350 double ym2=(y2+y3)/2;
351 double a1=(x1-x2)/(y2-y1);
352 double a2=(x2-x3)/(y3-y2);
353 double x0=(a2*xm2-a1*xm1-ym2+ym1)/(a2-a1);//center of circle
354 double y0=a1*(x0-xm1)+ym1;//center of circle
355 double a = (x0-x1)/(y1-y0);//slope of sessen
356 double b = y1+x1*(x1-x0)/(y1-y0);//intercept of sessen
357 double d=std::abs(b)/std::sqrt(a*a+1);
358 return d;
359}
#define M_PI
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_MSG_DEBUG(x)
static Double_t a
int sign(int a)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
virtual double phi() const override final
Methods to retrieve data members.
virtual double eta() const override final
double computeRadius3Points(double InnerZ, double InnerR, double EEZ, double EER, double MiddleZ, double MiddleR) const
const ToolHandle< PtEndcapLUT > * m_ptEndcapLUT
StatusCode setAlphaBeta(const TrigRoiDescriptor *p_roids, TrigL2MuonSA::TgcFitResult &tgcFitResult, TrigL2MuonSA::TrackPattern &trackPattern, const TrigL2MuonSA::MuonRoad &muonRoad) const
double computeRadius(double InnerSlope, double InnerR, double InnerZ, double MiddleSlope, double MiddleR, double MiddleZ, double sign) const
bool isZero(float value, float tolerance=1e-5) const
double calcDistance(double x1, double y1, double x2, double y2, double x3, double y3) const
AlphaBetaEstimate(const std::string &type, const std::string &name, const IInterface *parent)
void setMCFlag(bool use_mcLUT, const TrigL2MuonSA::PtEndcapLUTSvc *ptEndcapLUTSvc)
const ToolHandle< PtEndcapLUT > * ptEndcapLUT(void) const
TrigL2MuonSA::SuperPoint superPoints[s_NCHAMBER]
Definition TrackData.h:60
nope - should be used for standalone also, perhaps need to protect the class def bits ifndef XAOD_ANA...
int cost(std::vector< std::string > &files, node &n, const std::string &directory="", bool deleteref=false, bool relocate=false)
Definition hcg.cxx:922
@ BarrelInner
Inner station in the barrel spectrometer.
@ EndcapOuter
Outer station in the endcap spectrometer.
@ CSC
CSC measurement point.
@ EndcapMiddle
Middle station in the endcap spectrometer.
@ EndcapExtra
Extra station in the endcap spectrometer.
@ EndcapInner
Inner station in the endcap spectrometer.