11 #include "GaudiKernel/EventContext.h"
24 inline double getRadiusOfCurvature(
const Trk::Perigee & myPerigee,
const double Bzfield) {
38 declareInterface<NewtonTrkDistanceFinder>(
this);
48 return StatusCode::SUCCESS;
53 return StatusCode::SUCCESS;
56 std::variant<TwoPoints, std::string>
62 const double a_cosphi0 = -
sin(a_phi0);
63 const double a_sinphi0 =
cos(a_phi0);
73 #ifdef TrkDistance_DEBUG
74 ATH_MSG_DEBUG(
"a_x0 " << a_x0 <<
" a_y0 " << a_y0 <<
" a_z0 " << a_z0 );
83 fieldCondObj->getInitializedCache (fieldCache);
85 double magnFieldVect[3];
90 fieldCache.
getField(posXYZ,magnFieldVect);
94 const double a_Bz=magnFieldVect[2]*299.792;
97 const double a_Rt = getRadiusOfCurvature(firsttrack.
getPerigee(),a_Bz);
100 #ifdef TrkDistance_DEBUG
101 ATH_MSG_DEBUG(
"a_Rt" << a_Rt <<
" a_cotantheta " << a_cotantheta );
102 ATH_MSG_DEBUG(
"Magnetic field at perigee is " << a_Bz <<
"GeV/mm " );
107 const double b_cosphi0 = -
sin(b_phi0);
108 const double b_sinphi0 =
cos(b_phi0);
118 #ifdef TrkDistance_DEBUG
119 ATH_MSG_DEBUG(
"b_x0 " << b_x0 <<
" b_y0 " << b_y0 <<
" b_z0 " << b_z0 );
127 fieldCache.
getField(posXYZ,magnFieldVect);
130 const double b_Bz = magnFieldVect[2]*299.792;
134 const double b_Rt = getRadiusOfCurvature(secondtrack.
getPerigee(),b_Bz);
137 #ifdef TrkDistance_DEBUG
138 ATH_MSG_DEBUG(
"b_Rt" << b_Rt <<
" b_cotantheta " << b_cotantheta );
139 ATH_MSG_DEBUG(
"Magnetic field at perigee is " << b_Bz <<
" GeV/mm " );
144 const double ab_Dx0 = a_x0-b_x0-a_Rt*a_cosphi0+b_Rt*b_cosphi0;
145 const double ab_Dy0 = a_y0-b_y0-a_Rt*a_sinphi0+b_Rt*b_sinphi0;
146 const double ab_Dz0 = a_z0-b_z0+a_Rt*a_cotantheta*a_phi0-b_Rt*b_cotantheta*b_phi0;
148 #ifdef TrkDistance_DEBUG
149 ATH_MSG_DEBUG(
"ab_Dx0 " << ab_Dx0 <<
" ab_Dy0 " << ab_Dy0 <<
" ab_Dz0 " << ab_Dz0 );
161 double a_cosphi = -
sin(a_phi);
162 double a_sinphi =
cos(a_phi);
163 double b_cosphi = -
sin(b_phi);
164 double b_sinphi =
cos(b_phi);
167 #ifdef TrkDistance_DEBUG
168 ATH_MSG_DEBUG(
"Beginning phi is a_phi: " << a_phi <<
" b_phi " << b_phi );
179 #ifdef TrkDistance_DEBUG
181 ATH_MSG_DEBUG(
"actual value of a_phi: " << a_phi <<
" of b_phi " << b_phi );
189 #ifdef TrkDistance_DEBUG
198 ATH_MSG_DEBUG(
"real Dx0 " << ab_Dx0+a_Rt*a_cosphi-b_Rt*b_cosphi );
199 ATH_MSG_DEBUG(
"real Dy0 " << ab_Dy0+a_Rt*a_sinphi-b_Rt*b_sinphi );
203 const double d1da_phi =
204 (ab_Dx0-b_Rt*b_cosphi)*(-a_Rt*a_sinphi)+
205 (ab_Dy0-b_Rt*b_sinphi)*a_cosphi*a_Rt+
206 (ab_Dz0-a_Rt*a_cotantheta*a_phi+b_Rt*b_cotantheta*b_phi)*(-a_Rt*a_cotantheta);
210 const double d1db_phi =
211 (ab_Dx0+a_Rt*a_cosphi)*b_Rt*b_sinphi-
212 (ab_Dy0+a_Rt*a_sinphi)*b_cosphi*b_Rt+
213 (ab_Dz0-a_Rt*a_cotantheta*a_phi+b_Rt*b_cotantheta*b_phi)*(+b_Rt*b_cotantheta);
217 const double d2da_phi2 =
218 (ab_Dx0-b_Rt*b_cosphi)*(-a_Rt*a_cosphi)+
219 (ab_Dy0-b_Rt*b_sinphi)*(-a_Rt*a_sinphi)+
220 +a_Rt*a_Rt*(a_cotantheta*a_cotantheta);
222 const double d2db_phi2 =
223 (ab_Dx0+a_Rt*a_cosphi)*(+b_Rt*b_cosphi)+
224 (ab_Dy0+a_Rt*a_sinphi)*(+b_Rt*b_sinphi)+
225 +b_Rt*b_Rt*(b_cotantheta*b_cotantheta);
228 const double d2da_phib_phi = -a_Rt*b_Rt*(a_sinphi*b_sinphi+a_cosphi*b_cosphi+a_cotantheta*b_cotantheta);
232 const double det = d2da_phi2*d2db_phi2-d2da_phib_phi*d2da_phib_phi;
235 #ifdef TrkDistance_DEBUG
236 ATH_MSG_DEBUG(
"d1da_phi " << d1da_phi <<
" d1db_phi " << d1db_phi <<
" d2da_phi2 " << d2da_phi2 <<
" d2db_phi2 " << d2db_phi2
237 <<
" d2da_phib_phi " << d2da_phib_phi <<
" det " <<
det );
244 return "Hessian is negative";
246 if (
det>0&&d2da_phi2<0) {
247 ATH_MSG_DEBUG(
"Hessian indicates a maximum: derivative will be zero but result incorrect" );
248 return "Maximum point found";
252 const double deltaa_phi = -(d2db_phi2*d1da_phi-d2da_phib_phi*d1db_phi)/
det;
253 const double deltab_phi = -(-d2da_phib_phi*d1da_phi+d2da_phi2*d1db_phi)/
det;
255 #ifdef TrkDistance_DEBUG
265 a_cosphi = -
sin(a_phi);
266 a_sinphi =
cos(a_phi);
267 b_cosphi = -
sin(b_phi);
268 b_sinphi =
cos(b_phi);
276 return "Could not find minimum distance: max loops number reached";
281 a_y0+a_Rt*(a_sinphi-a_sinphi0),
282 a_z0-a_Rt*(a_phi-a_phi0)*a_cotantheta),
284 b_y0+b_Rt*(b_sinphi-b_sinphi0),
285 b_z0-b_Rt*(b_phi-b_phi0)*b_cotantheta));