120 {
122 const AtlasFieldCacheCondObj* fieldCondObj{*readHandle};
123
124 MagField::AtlasFieldCache fieldCache;
126
127 double magnFieldVect[3];
129 if(magnFieldVect[2] == 0 ){
130 ATH_MSG_DEBUG(
"Magnetic field in the Z direction is 0 -- propagate like a straight line");
132 }
133
135 if (thePerigee==nullptr)
136 {
138 " ImpactPoint3dEstimator didn't get a Perigee* as ParametersBase*: "
139 "cast not possible. Need to EXTRAPOLATE...");
140 Trk::PerigeeSurface perigeeSurface(*theVertex);
141 std::unique_ptr<const Trk::TrackParameters>
tmp =
143 ctx, *trackPerigee, perigeeSurface);
146 }
147 if (thePerigee == nullptr){
148 return nullptr;
149 }
150 }
151
152 ATH_MSG_VERBOSE(
" Now running ImpactPoint3dEstimator::Estimate3dIP" );
154 double dCosPhi0=-std::sin(
phi0);
155 double dSinPhi0=std::cos(
phi0);
158 double d0=thePerigee->parameters()[
Trk::d0];
159
160
161 double Bz=magnFieldVect[2]*299.792;
163
167
168 if (thePerigee!=trackPerigee) {
169 delete thePerigee;
170 thePerigee=nullptr;
171 }
172
173 double xc=theVertex->x();
174 double yc=theVertex->y();
175 double zc=theVertex->z();
176
177 double phiActual=
phi0;
178 double dCosPhiActual=-std::sin(phiActual);
179 double dSinPhiActual=std::cos(phiActual);
180
181 double secderivative=0.;
182 double derivative=0.;
183
184 int ncycle=0;
186
187 double deltaphi=0.;
188
189#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
190 std::cout << std::setprecision(25) << "actual distance before cycle is: " << std::hypot(x0-xc+Rt*dCosPhiActual,
191 y0-yc+Rt*dSinPhiActual,
192 z0-zc-Rt*cotTheta*phiActual) << std::endl;
193#endif
194
195 do {
196
197#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
198 ATH_MSG_VERBOSE(
"Cycle number: " << ncycle <<
" old phi: " << phiActual );
199#endif
200
201
202 derivative=(x0-xc)*(-Rt*dSinPhiActual)+(y0-yc)*Rt*dCosPhiActual+(
z0-zc-Rt*phiActual*cotTheta)*(-Rt*
cotTheta);
203 secderivative=Rt*(-(x0-xc)*dCosPhiActual-(y0-yc)*dSinPhiActual+Rt*
cotTheta*
cotTheta);
204#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
205 ATH_MSG_VERBOSE(
"derivative is: " << derivative <<
" sec derivative is: " << secderivative );
206#endif
207
208 deltaphi=-derivative/secderivative;
209
210#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
211 std::cout << std::setprecision(25) << "deltaphi: " << deltaphi << std::endl;
212#endif
213
214 phiActual+=deltaphi;
215 dCosPhiActual=-std::sin(phiActual);
216 dSinPhiActual=std::cos(phiActual);
217
218#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
219 ATH_MSG_VERBOSE(
"derivative is: " << derivative <<
" sec derivative is: " << secderivative );
220 std::cout << std::setprecision(25) << std::hypot(x0-xc+Rt*dCosPhiActual, y0-yc+Rt*dSinPhiActual,
221 z0-zc-Rt*cotTheta*phiActual) << std::endl;
222 ATH_MSG_VERBOSE(
"actual distance is: " << std::hypot(x0-xc+Rt*dCosPhiActual,
223 y0-yc+Rt*dSinPhiActual,
224 z0-zc-Rt*cotTheta*phiActual));
225#endif
226
227 if (secderivative<0) throw error::ImpactPoint3dEstimatorProblem("Second derivative is negative");
228
229 if (ncycle>
m_maxiterations)
throw error::ImpactPoint3dEstimatorProblem(
"Too many loops: could not find minimum distance to vertex");
230
231 ncycle+=1;
233#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
235#endif
237 }
238
239 } while (!isok);
240
241
242
246 if (distance==0.){
247 ATH_MSG_WARNING(
"DeltaR is zero in ImpactPoint3dEstimator::Estimate3dIP, returning nullptr");
248 return nullptr;
249 }
251
252
253
254
256
257 if ((DeltaR-DeltaRcorrected).
mag()>1e-4)
258 {
260 ATH_MSG_DEBUG( std::setprecision(10) <<
" DeltaR-DeltaRcorrected: " << (DeltaR-DeltaRcorrected).
mag() );
261 }
262
264
265
267
268 ATH_MSG_VERBOSE(
"final minimal distance is: " << std::hypot(x0-xc+Rt*dCosPhiActual,
269 y0-yc+Rt*dSinPhiActual,
270 z0-zc-Rt*cotTheta*phiActual));
271
273
274
275
276 ATH_MSG_VERBOSE(
"plane to which to extrapolate X " << DeltaRcorrected <<
" Y " << YDir <<
" Z " << MomentumDir );
277
279
280#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
281 std::cout <<
"the translation is, directly from Transform3d: " << thePlane.getTranslation() <<
endmsg;
282#endif
283 return std::make_unique<PlaneSurface>(thePlane);
284 }
Scalar mag() const
mag method
#define ATH_MSG_WARNING(x)
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d or 3-d position.
void getField(const double *ATH_RESTRICT xyz, double *ATH_RESTRICT bxyz, double *ATH_RESTRICT deriv=nullptr)
get B field value at given position xyz[3] is in mm, bxyz[3] is in kT if deriv[9] is given,...
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCacheCondObjInputKey
virtual const Surface & associatedSurface() const override=0
Access to the Surface associated to the Parameters.
virtual const S & associatedSurface() const override final
Access to the Surface method.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
Eigen::Affine3d Transform3D
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Eigen::Matrix< double, 3, 1 > Vector3D
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee