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