120 {
122 const AtlasFieldCacheCondObj* fieldCondObj{*readHandle};
125 return nullptr;
126 }
127 MagField::AtlasFieldCache fieldCache;
129
130 double magnFieldVect[3];
132 if(magnFieldVect[2] == 0 ){
133 ATH_MSG_DEBUG(
"Magnetic field in the Z direction is 0 -- propagate like a straight line");
135 }
136
138 if (thePerigee==nullptr)
139 {
141 " ImpactPoint3dEstimator didn't get a Perigee* as ParametersBase*: "
142 "cast not possible. Need to EXTRAPOLATE...");
143 Trk::PerigeeSurface perigeeSurface(*theVertex);
144 std::unique_ptr<const Trk::TrackParameters>
tmp =
146 ctx, *trackPerigee, perigeeSurface);
149 }
150 if (thePerigee == nullptr){
151 return nullptr;
152 }
153 }
154
155 ATH_MSG_VERBOSE(
" Now running ImpactPoint3dEstimator::Estimate3dIP" );
157 double dCosPhi0=-std::sin(
phi0);
158 double dSinPhi0=std::cos(
phi0);
161 double d0=thePerigee->parameters()[
Trk::d0];
162
163
164 double Bz=magnFieldVect[2]*299.792;
166
170
171 if (thePerigee!=trackPerigee) {
172 delete thePerigee;
173 thePerigee=nullptr;
174 }
175
176 double xc=theVertex->x();
177 double yc=theVertex->y();
178 double zc=theVertex->z();
179
180 double phiActual=
phi0;
181 double dCosPhiActual=-std::sin(phiActual);
182 double dSinPhiActual=std::cos(phiActual);
183
184 double secderivative=0.;
185 double derivative=0.;
186
187 int ncycle=0;
189
190 double deltaphi=0.;
191
192#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
193 std::cout << std::setprecision(25) << "actual distance before cycle is: " << std::hypot(x0-xc+Rt*dCosPhiActual,
194 y0-yc+Rt*dSinPhiActual,
195 z0-zc-Rt*cotTheta*phiActual) << std::endl;
196#endif
197
198 do {
199
200#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
201 ATH_MSG_VERBOSE(
"Cycle number: " << ncycle <<
" old phi: " << phiActual );
202#endif
203
204
205 derivative=(x0-xc)*(-Rt*dSinPhiActual)+(y0-yc)*Rt*dCosPhiActual+(
z0-zc-Rt*phiActual*cotTheta)*(-Rt*
cotTheta);
206 secderivative=Rt*(-(x0-xc)*dCosPhiActual-(y0-yc)*dSinPhiActual+Rt*
cotTheta*
cotTheta);
207#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
208 ATH_MSG_VERBOSE(
"derivative is: " << derivative <<
" sec derivative is: " << secderivative );
209#endif
210
211 deltaphi=-derivative/secderivative;
212
213#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
214 std::cout << std::setprecision(25) << "deltaphi: " << deltaphi << std::endl;
215#endif
216
217 phiActual+=deltaphi;
218 dCosPhiActual=-std::sin(phiActual);
219 dSinPhiActual=std::cos(phiActual);
220
221#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
222 ATH_MSG_VERBOSE(
"derivative is: " << derivative <<
" sec derivative is: " << secderivative );
223 std::cout << std::setprecision(25) << std::hypot(x0-xc+Rt*dCosPhiActual, y0-yc+Rt*dSinPhiActual,
224 z0-zc-Rt*cotTheta*phiActual) << std::endl;
225 ATH_MSG_VERBOSE(
"actual distance is: " << std::hypot(x0-xc+Rt*dCosPhiActual,
226 y0-yc+Rt*dSinPhiActual,
227 z0-zc-Rt*cotTheta*phiActual));
228#endif
229
230 if (secderivative<0) throw error::ImpactPoint3dEstimatorProblem("Second derivative is negative");
231
232 if (ncycle>
m_maxiterations)
throw error::ImpactPoint3dEstimatorProblem(
"Too many loops: could not find minimum distance to vertex");
233
234 ncycle+=1;
236#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
238#endif
240 }
241
242 } while (!isok);
243
244
245
249 if (distance==0.){
250 ATH_MSG_WARNING(
"DeltaR is zero in ImpactPoint3dEstimator::Estimate3dIP, returning nullptr");
251 return nullptr;
252 }
254
255
256
257
259
260 if ((DeltaR-DeltaRcorrected).
mag()>1e-4)
261 {
263 ATH_MSG_DEBUG( std::setprecision(10) <<
" DeltaR-DeltaRcorrected: " << (DeltaR-DeltaRcorrected).
mag() );
264 }
265
267
268
270
271 ATH_MSG_VERBOSE(
"final minimal distance is: " << std::hypot(x0-xc+Rt*dCosPhiActual,
272 y0-yc+Rt*dSinPhiActual,
273 z0-zc-Rt*cotTheta*phiActual));
274
276
277
278
279 ATH_MSG_VERBOSE(
"plane to which to extrapolate X " << DeltaRcorrected <<
" Y " << YDir <<
" Z " << MomentumDir );
280
282
283#ifdef IMPACTPOINT3DESTIMATOR_DEBUG
284 std::cout <<
"the translation is, directly from Transform3d: " << thePlane.getTranslation() <<
endmsg;
285#endif
286 return std::make_unique<PlaneSurface>(thePlane);
287 }
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