ATLAS Offline Software
Loading...
Searching...
No Matches
CvtParametersBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Convert TrackParameters and NeutralParameters to internal VKalVrt parameters
6// and sets up common reference system for ALL tracks
7// even if in the beginning in was different
8//------------------------------------------------------------------
9// Header include
11//-------------------------------------------------
12// Other stuff
13//----
15
16namespace Trk {
17
18 //--------------------------------------------------------------------
19 // Extract TrackParameters
20 //
21
23 TrkVKalVrtFitter::CvtTrackParameters(const std::vector<const TrackParameters*>& InpTrk,
24 int& ntrk,
25 State& state) const
26 {
27
28 std::vector<const TrackParameters*>::const_iterator i_pbase;
29 AmgVector(5) VectPerig;
30 VectPerig.setZero();
31 Amg::Vector3D perGlobalPos,perGlobalVrt;
32 const Trk::Perigee* mPer=nullptr;
33
34 double tmp_refFrameX = 0, tmp_refFrameY = 0, tmp_refFrameZ = 0;
35 double rxyMin = 1000000.;
36
37 //
38 // ----- Set reference frame to (0.,0.,0.) == ATLAS frame
39 // ----- Magnetic field is taken in reference point
40 //
41 state.m_refFrameX=state.m_refFrameY=state.m_refFrameZ=0.;
42 state.m_fitField.setAtlasMagRefFrame( 0., 0., 0.);
43
44 if( m_InDetExtrapolator == nullptr ){
45 if(msgLvl(MSG::WARNING))msg()<< "No InDet extrapolator given. Can't use TrackParameters!!!" << endmsg;
46 return StatusCode::FAILURE;
47 }
48
49 //
50 // Cycle to determine common reference point for the fit
51 //
52 int counter =0;
53 state.m_trkControl.clear();
54 state.m_trkControl.reserve(InpTrk.size());
55 for (i_pbase = InpTrk.begin(); i_pbase != InpTrk.end(); ++i_pbase) {
56 // Global position of hit
57 perGlobalPos = (*i_pbase)->position();
58 // Crazy user protection
59 if(!(state.m_allowUltraDisplaced) && std::abs(perGlobalPos.z()) > m_IDsizeZ) return StatusCode::FAILURE;
60 if(!(state.m_allowUltraDisplaced) && perGlobalPos.perp() > m_IDsizeR) return StatusCode::FAILURE;
61 tmp_refFrameX += perGlobalPos.x();
62 tmp_refFrameY += perGlobalPos.y();
63 tmp_refFrameZ += perGlobalPos.z();
64
65 // Here we create structure to control material effects
66 TrkMatControl tmpMat;
67 tmpMat.trkSavedLocalVertex.setZero();
68 tmpMat.trkRefGlobPos = Amg::Vector3D(perGlobalPos.x(),
69 perGlobalPos.y(),
70 perGlobalPos.z());
71 // First measured point strategy
73 tmpMat.TrkPnt = (*i_pbase);
75 if(counter < (int)state.m_MassInputParticles.size()){
76 tmpMat.prtMass = state.m_MassInputParticles[counter];
77 }
78 tmpMat.TrkID = counter;
79 state.m_trkControl.push_back(tmpMat);
80 counter++;
81
82 if(perGlobalPos.perp() < rxyMin){
83 rxyMin=perGlobalPos.perp();
84 state.m_globalFirstHit=(*i_pbase);
85 }
86 }
87
88 if(counter == 0) return StatusCode::FAILURE;
89 // Reference frame for the fit based on hits positions
90 tmp_refFrameX /= counter;
91 tmp_refFrameY /= counter;
92 tmp_refFrameZ /= counter;
93 Amg::Vector3D refGVertex(tmp_refFrameX, tmp_refFrameY, tmp_refFrameZ);
94
95 double fx, fy, fz;
96
97 //
98 // Common reference frame is ready. Start extraction of parameters for fit.
99 // TracksParameters are extrapolated to common point and converted to Perigee
100 // This is needed for VKalVrtCore engine.
101 //
102
103 double CovVertTrk[15];
104 std::fill(CovVertTrk, CovVertTrk+15, 0.);
105
106 for (i_pbase = InpTrk.begin(); i_pbase != InpTrk.end(); ++i_pbase) {
107 long int TrkID=ntrk;
108 const TrackParameters* trkparO = (*i_pbase);
109
110 if(trkparO){
111 const Trk::TrackParameters* trkparN =
112 m_fitPropagator->myExtrapWithMatUpdate(TrkID,
113 trkparO,
114 &refGVertex,
115 state);
116 if(trkparN == nullptr) return StatusCode::FAILURE;
117 mPer = dynamic_cast<const Trk::Perigee*>(trkparN);
118 if(mPer == nullptr) {
119 delete trkparN;
120 return StatusCode::FAILURE;
121 }
122
123 VectPerig = mPer->parameters();
124 // Global position of perigee point
125 perGlobalPos = mPer->position();
126 // Global position of reference point
127 perGlobalVrt = mPer->associatedSurface().center();
128 // VK no good covariance matrix!
129 if( !convertAmg5SymMtx(mPer->covariance(), CovVertTrk) ){
130 delete trkparN;
131 return StatusCode::FAILURE;
132 }
133 delete trkparN;
134 }
135
136 state.m_refFrameX = state.m_refFrameY = state.m_refFrameZ = 0.;
137 // Restore ATLAS frame for safety
138 state.m_fitField.setAtlasMagRefFrame(0., 0., 0.);
139 // Magnetic field at perigee point
140 state.m_fitField.getMagFld(perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z(),
141 fx, fy, fz);
142 double effectiveBMAG=state.m_fitField.getEffField(fx, fy, fz, VectPerig[2], VectPerig[3]);
143 if(std::abs(effectiveBMAG) < 0.01) effectiveBMAG = 0.01;
144
145 VKalTransform(effectiveBMAG,
146 (double)VectPerig[0], (double)VectPerig[1],
147 (double)VectPerig[2], (double)VectPerig[3],
148 (double)VectPerig[4], CovVertTrk,
149 state.m_ich[ntrk], &state.m_apar[ntrk][0],
150 &state.m_awgt[ntrk][0]);
151
152 // Neutral track
153 if( trkparO==nullptr ) {
154 state.m_ich[ntrk]=0;
155 if(state.m_apar[ntrk][4]<0){
156 // Charge=0 is always equal to Charge=+1
157 state.m_apar[ntrk][4] = -state.m_apar[ntrk][4];
158 state.m_awgt[ntrk][10] = -state.m_awgt[ntrk][10];
159 state.m_awgt[ntrk][11] = -state.m_awgt[ntrk][11];
160 state.m_awgt[ntrk][12] = -state.m_awgt[ntrk][12];
161 state.m_awgt[ntrk][13] = -state.m_awgt[ntrk][13];
162 }
163 }
164 ntrk++;
165 if(ntrk>=NTrMaxVFit) return StatusCode::FAILURE;
166 }
167
168 //-------------- Finally setting new reference frame common for ALL tracks
169 state.m_refFrameX = tmp_refFrameX;
170 state.m_refFrameY = tmp_refFrameY;
171 state.m_refFrameZ = tmp_refFrameZ;
173
174 return StatusCode::SUCCESS;
175 }
176
177
178 StatusCode
179 TrkVKalVrtFitter::CvtNeutralParameters(const std::vector<const NeutralParameters*>& InpTrk,
180 int& ntrk,
181 State& state) const
182 {
183
184 std::vector<const NeutralParameters*>::const_iterator i_pbase;
185 AmgVector(5) VectPerig;
186 Amg::Vector3D perGlobalPos,perGlobalVrt;
187 const NeutralPerigee* mPerN = nullptr;
188 double CovVertTrk[15];
189 double tmp_refFrameX = 0, tmp_refFrameY = 0, tmp_refFrameZ = 0;
190 double rxyMin = 1000000.;
191
192 //
193 // ----- Set reference frame to (0.,0.,0.) == ATLAS frame
194 // ----- Magnetic field is taken in reference point
195 //
196 state.m_refFrameX = state.m_refFrameY = state.m_refFrameZ = 0.;
197 state.m_fitField.setAtlasMagRefFrame(0., 0., 0.);
198
199 if( m_InDetExtrapolator == nullptr ){
200 if(msgLvl(MSG::WARNING))msg()<< "No InDet extrapolator given. Can't use TrackParameters!!!" << endmsg;
201 return StatusCode::FAILURE;
202 }
203
204 //
205 // Cycle to determine common reference point for the fit
206 //
207 int counter = 0;
208 state.m_trkControl.clear();
209 state.m_trkControl.reserve(InpTrk.size());
210 for (i_pbase = InpTrk.begin(); i_pbase != InpTrk.end(); ++i_pbase) {
211 // Global position of hit
212 perGlobalPos = (*i_pbase)->position();
213 // Crazy user protection
214 if(std::abs(perGlobalPos.z()) > m_IDsizeZ) return StatusCode::FAILURE;
215 if(perGlobalPos.perp() > m_IDsizeR)return StatusCode::FAILURE;
216
217 tmp_refFrameX += perGlobalPos.x() ;
218 tmp_refFrameY += perGlobalPos.y() ;
219 tmp_refFrameZ += perGlobalPos.z() ;
220
221 // Here we create structure to control material effects
222 TrkMatControl tmpMat;
223 tmpMat.trkSavedLocalVertex.setZero();
224 // on track extrapolation
225 tmpMat.trkRefGlobPos = Amg::Vector3D(perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z());
226 // First measured point strategy
227 tmpMat.extrapolationType = 0;
228 //No reference point for neutral track for the moment !!!
229 tmpMat.TrkPnt = nullptr;
231 if(counter<(int)state.m_MassInputParticles.size()){
232 tmpMat.prtMass = state.m_MassInputParticles[counter];
233 }
234 tmpMat.TrkID = counter;
235 state.m_trkControl.push_back(tmpMat);
236 counter++;
237 if(perGlobalPos.perp()<rxyMin){
238 rxyMin = perGlobalPos.perp();
239 }
240 }
241
242 if(counter == 0) return StatusCode::FAILURE;
243 // Reference frame for the fit based on hits positions
244 tmp_refFrameX /= counter;
245 tmp_refFrameY /= counter;
246 tmp_refFrameZ /= counter;
247 Amg::Vector3D refGVertex (tmp_refFrameX, tmp_refFrameY, tmp_refFrameZ);
248
249 double fx,fy,fz;
250 //
251 // Common reference frame is ready. Start extraction of parameters for fit.
252 // TracksParameters are extrapolated to common point and converted to Perigee
253 // This is needed for VKalVrtCore engine.
254 //
255
256 for (i_pbase = InpTrk.begin(); i_pbase != InpTrk.end(); ++i_pbase) {
257 const Trk::NeutralParameters* neuparO = (*i_pbase);
258 if(neuparO == nullptr) return StatusCode::FAILURE;
259 const Trk::NeutralParameters* neuparN = m_fitPropagator->myExtrapNeutral(neuparO, &refGVertex);
260 mPerN = dynamic_cast<const Trk::NeutralPerigee*>(neuparN);
261 if(mPerN == nullptr) {
262 delete neuparN;
263 return StatusCode::FAILURE;
264 }
265
266 VectPerig = mPerN->parameters();
267 // Global position of perigee point
268 perGlobalPos = mPerN->position();
269 // Global position of reference point
270 perGlobalVrt = mPerN->associatedSurface().center();
271 // VK no good covariance matrix!
272 if( !convertAmg5SymMtx(mPerN->covariance(), CovVertTrk) ) {
273 delete mPerN;
274 return StatusCode::FAILURE;
275 }
276 delete neuparN;
277
278
279 state.m_refFrameX = state.m_refFrameY = state.m_refFrameZ = 0.;
280 // restore ATLAS frame for safety
281 state.m_fitField.setAtlasMagRefFrame( 0., 0., 0.);
282 // Magnetic field at perigee point
283 state.m_fitField.getMagFld(perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z(),
284 fx, fy, fz);
285 double effectiveBMAG=state.m_fitField.getEffField(fx, fy, fz, VectPerig[2], VectPerig[3]);
286 if(std::abs(effectiveBMAG) < 0.01) effectiveBMAG = 0.01;
287
288 VKalTransform(effectiveBMAG,
289 (double)VectPerig[0], (double)VectPerig[1],
290 (double)VectPerig[2], (double)VectPerig[3],
291 (double)VectPerig[4], CovVertTrk,
292 state.m_ich[ntrk], &state.m_apar[ntrk][0],
293 &state.m_awgt[ntrk][0]);
294
295 state.m_ich[ntrk]=0;
296 if(state.m_apar[ntrk][4]<0){
297 // Charge=0 is always equal to Charge=+1
298 state.m_apar[ntrk][4] = -state.m_apar[ntrk][4];
299 state.m_awgt[ntrk][10] = -state.m_awgt[ntrk][10];
300 state.m_awgt[ntrk][11] = -state.m_awgt[ntrk][11];
301 state.m_awgt[ntrk][12] = -state.m_awgt[ntrk][12];
302 state.m_awgt[ntrk][13] = -state.m_awgt[ntrk][13];
303 }
304 ntrk++;
305 if(ntrk>=NTrMaxVFit) return StatusCode::FAILURE;
306 }
307
308 //-------------- Finally setting new reference frame common for ALL tracks
309 state.m_refFrameX = tmp_refFrameX;
310 state.m_refFrameY = tmp_refFrameY;
311 state.m_refFrameZ = tmp_refFrameZ;
313
314 return StatusCode::SUCCESS;
315 }
316
317} // end of namespace bracket
#define endmsg
#define AmgVector(rows)
const Amg::Vector3D & position() const
Access method for the position.
virtual const S & associatedSurface() const override final
Access to the Surface method.
const Amg::Vector3D & center() const
Returns the center position of the Surface.
std::vector< double > m_MassInputParticles
double m_apar[NTrMaxVFit][5]
double m_awgt[NTrMaxVFit][15]
const TrackParameters * m_globalFirstHit
std::vector< TrkMatControl > m_trkControl
StatusCode CvtTrackParameters(const std::vector< const TrackParameters * > &InpTrk, int &ntrk, State &state) const
const IExtrapolator * m_InDetExtrapolator
Pointer to Extrapolator AlgTool.
bool convertAmg5SymMtx(const AmgSymMatrix(5) *, double[15]) const
void VKalTransform(double MAG, double A0V, double ZV, double PhiV, double ThetaV, double PInv, const double[15], long int &Charge, double[5], double[15]) const
Gaudi::Property< double > m_IDsizeZ
Gaudi::Property< bool > m_firstMeasuredPoint
VKalExtPropagator * m_fitPropagator
Gaudi::Property< double > m_IDsizeR
StatusCode CvtNeutralParameters(const std::vector< const NeutralParameters * > &InpTrk, int &ntrk, State &state) const
virtual void getMagFld(const double, const double, const double, double &, double &, double &) override
void setAtlasMagRefFrame(double, double, double)
double getEffField(double bx, double by, double bz, double phi, double theta)
Definition VKalVrtBMag.h:41
Eigen::Matrix< double, 3, 1 > Vector3D
::StatusCode StatusCode
StatusCode definition for legacy code.
constexpr double chargedPionMassInMeV
the mass of the charged pion (in MeV)
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
ParametersBase< NeutralParametersDim, Neutral > NeutralParameters
ParametersT< NeutralParametersDim, Neutral, PerigeeSurface > NeutralPerigee
ParametersBase< TrackParametersDim, Charged > TrackParameters
MsgStream & msg
Definition testRead.cxx:32