ATLAS Offline Software
Loading...
Searching...
No Matches
CvtTrackParticle.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 TrackParticle parameters 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
12//-------------------------------------------------
13// Other stuff
14//----
17//----
18#include <iostream>
19
20namespace Trk {
21
22//--------------------------------------------------------------------
23// Extract xAOD::TrackParticles
24//
25
27 TrkVKalVrtFitter::CvtTrackParticle(std::span<const xAOD::TrackParticle* const> InpTrk,
28 int& ntrk,
29 State& state) const
30 {
31
32 AmgVector(5) VectPerig; VectPerig.setZero();
33 const Trk::Perigee* mPer=nullptr;
34 double CovVertTrk[15]; std::fill(CovVertTrk,CovVertTrk+15,0.);
35 double tmp_refFrameX=0, tmp_refFrameY=0, tmp_refFrameZ=0;
36 double fx,fy,fz;
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// Cycle to determine common reference point for the fit
45//
46 int counter =0;
47 Amg::Vector3D perGlobalPos;
48 state.m_trkControl.clear(); state.m_trkControl.reserve(InpTrk.size());
49 for (auto i_ntrk = InpTrk.begin(); i_ntrk != InpTrk.end(); ++i_ntrk) {
50//-- (Measured)Perigee in xAOD::TrackParticle
51 mPer = &(*i_ntrk)->perigeeParameters();
52 if( mPer==nullptr ) continue; // No perigee!!!
53 perGlobalPos = mPer->position(); //Global position of perigee point
54 if(!(state.m_allowUltraDisplaced) && std::abs(perGlobalPos.z()) > m_IDsizeZ)return StatusCode::FAILURE; // Crazy user protection
55 if(!(state.m_allowUltraDisplaced) && perGlobalPos.perp() > m_IDsizeR)return StatusCode::FAILURE;
56 tmp_refFrameX += perGlobalPos.x() ; // Reference system calculation
57 tmp_refFrameY += perGlobalPos.y() ; // Use hit position itself to get more precise
58 tmp_refFrameZ += perGlobalPos.z() ; // magnetic field
59 TrkMatControl tmpMat;
60 tmpMat.trkSavedLocalVertex.setZero();
61 tmpMat.trkRefGlobPos=Amg::Vector3D( perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z());
62 tmpMat.extrapolationType=2; // Perigee point strategy
63 tmpMat.TrkPnt=mPer;
65 if(counter<(int)state.m_MassInputParticles.size())tmpMat.prtMass = state.m_MassInputParticles[counter];
66 tmpMat.TrkID=counter; state.m_trkControl.push_back(tmpMat);
67 counter++;
68 }
69 if(counter == 0) return StatusCode::FAILURE;
70 tmp_refFrameX /= counter; // Reference frame for the fit
71 tmp_refFrameY /= counter;
72 tmp_refFrameZ /= counter;
73 Amg::Vector3D refGVertex (tmp_refFrameX, tmp_refFrameY, tmp_refFrameZ);
74
75 PerigeeSurface surfGRefPoint( refGVertex ); // Reference perigee surface for current fit
76//
77//std::cout.setf( std::ios::scientific); std::cout.precision(9);
78//std::cout<<" VK ref.frame="<<tmp_refFrameX<<", "<<tmp_refFrameY<<", "<<tmp_refFrameZ<<'\n';
79//
80// Common reference frame is ready. Start extraction of parameters for fit.
81//
82
83 for (auto i_ntrk = InpTrk.begin(); i_ntrk != InpTrk.end(); ++i_ntrk) {
84//
85//-- (Measured)Perigee in TrackParticle
86//
87 mPer = &(*i_ntrk)->perigeeParameters();
88 if( mPer==nullptr ) continue; // No perigee!!!
89 perGlobalPos = mPer->position(); //Global position of perigee point
90 if( !convertAmg5SymMtx(mPer->covariance(), CovVertTrk) ) return StatusCode::FAILURE; //VK no good covariance matrix!;
91 state.m_fitField.getMagFld( perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z(), // Magnetic field
92 fx, fy, fz); // at the track perigee point
93//
94//--- Move ref. frame to the track common point refGVertex
95// Small beamline inclination doesn't change track covariance matrix
96 AmgSymMatrix(5) tmpCov = AmgSymMatrix(5)(*(mPer->covariance()));
97 const Perigee tmpPer(mPer->position(),mPer->momentum(),mPer->charge(),surfGRefPoint,std::move(tmpCov));
98 VectPerig = tmpPer.parameters();
99
100 double effectiveBMAG=state.m_fitField.getEffField(fx, fy, fz, VectPerig[2], VectPerig[3]);
101 if(fabs(effectiveBMAG) < 0.01) effectiveBMAG=0.01;
102//--- Transform to internal parametrisation
103 VKalTransform( effectiveBMAG, (double)VectPerig[0], (double)VectPerig[1],
104 (double)VectPerig[2], (double)VectPerig[3], (double)VectPerig[4], CovVertTrk,
105 state.m_ich[ntrk],&state.m_apar[ntrk][0],&state.m_awgt[ntrk][0]);
106//
107 ntrk++;
108 if(ntrk>=NTrMaxVFit) {
109 return StatusCode::FAILURE;
110 }
111 }
112//-------------- Finally setting new reference frame common for ALL tracks
113 state.m_refFrameX=tmp_refFrameX;
114 state.m_refFrameY=tmp_refFrameY;
115 state.m_refFrameZ=tmp_refFrameZ;
117
118 return StatusCode::SUCCESS;
119 }
120
121//--------------------------------------------------------------------
122// Extract xAOD::NeutralParticles
123//
124
125 StatusCode
126 TrkVKalVrtFitter::CvtNeutralParticle(const std::vector<const xAOD::NeutralParticle*>& InpTrk,
127 int& ntrk,
128 State& state) const
129 {
130 std::vector<const xAOD::NeutralParticle*>::const_iterator i_ntrk;
131 AmgVector(5) VectPerig; VectPerig.setZero();
132 const NeutralPerigee* mPer=nullptr;
133 double CovVertTrk[15]; std::fill(CovVertTrk,CovVertTrk+15,0.);
134 double tmp_refFrameX=0, tmp_refFrameY=0, tmp_refFrameZ=0;
135 double fx,fy,fz;
136//
137// ----- Set reference frame to (0.,0.,0.) == ATLAS frame
138// ----- Magnetic field is taken in reference point
139//
140 state.m_refFrameX=state.m_refFrameY=state.m_refFrameZ=0.;
141 state.m_fitField.setAtlasMagRefFrame( 0., 0., 0.);
142//
143// Cycle to determine common reference point for the fit
144//
145 int counter =0;
146 Amg::Vector3D perGlobalPos;
147 state.m_trkControl.clear(); state.m_trkControl.reserve(InpTrk.size());
148 for (i_ntrk = InpTrk.begin(); i_ntrk != InpTrk.end(); ++i_ntrk) {
149//-- (Measured)Perigee in xAOD::NeutralParticle
150 mPer = &(*i_ntrk)->perigeeParameters();
151 if( mPer==nullptr ) continue; // No perigee!!!
152 perGlobalPos = mPer->position(); //Global position of perigee point
153 if(fabs(perGlobalPos.z()) > m_IDsizeZ)return StatusCode::FAILURE; // Crazy user protection
154 if( perGlobalPos.perp() > m_IDsizeR)return StatusCode::FAILURE;
155 tmp_refFrameX += perGlobalPos.x() ; // Reference system calculation
156 tmp_refFrameY += perGlobalPos.y() ; // Use hit position itself to get more precise
157 tmp_refFrameZ += perGlobalPos.z() ; // magnetic field
158 TrkMatControl tmpMat;
159 tmpMat.trkSavedLocalVertex.setZero();
160 tmpMat.trkRefGlobPos=Amg::Vector3D( perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z());
161 tmpMat.extrapolationType=2; // Perigee point strategy
162 tmpMat.TrkPnt=nullptr; //No reference point for neutral particle for the moment
164 if(counter<(int)state.m_MassInputParticles.size())tmpMat.prtMass = state.m_MassInputParticles[counter];
165 tmpMat.TrkID=counter; state.m_trkControl.push_back(tmpMat);
166 counter++;
167 }
168 if(counter == 0) return StatusCode::FAILURE;
169 tmp_refFrameX /= counter; // Reference frame for the fit
170 tmp_refFrameY /= counter;
171 tmp_refFrameZ /= counter;
172 Amg::Vector3D refGVertex (tmp_refFrameX, tmp_refFrameY, tmp_refFrameZ);
173 PerigeeSurface surfGRefPoint( refGVertex ); // Reference perigee surface for current fit
174//
175//std::cout.setf( std::ios::scientific); std::cout.precision(5);
176//std::cout<<" VK ref.frame="<<tmp_refFrameX<<", "<<tmp_refFrameY<<", "<<tmp_refFrameZ<<'\n';
177//
178// Common reference frame is ready. Start extraction of parameters for fit.
179//
180
181 state.m_refFrameX=state.m_refFrameY=state.m_refFrameZ=0.; //set ATLAS frame
182 state.m_fitField.setAtlasMagRefFrame( 0., 0., 0.); //set ATLAS frame
183 for (i_ntrk = InpTrk.begin(); i_ntrk != InpTrk.end(); ++i_ntrk) {
184//
185//-- (Measured)Perigee in TrackParticle
186//
187 mPer = &(*i_ntrk)->perigeeParameters();
188 if( mPer==nullptr ) continue; // No perigee!!!
189 perGlobalPos = mPer->position(); //Global position of perigee point
190 if( !convertAmg5SymMtx(mPer->covariance(), CovVertTrk) ) return StatusCode::FAILURE; //VK no good covariance matrix!;
191 state.m_fitField.getMagFld( perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z(), // Magnetic field
192 fx, fy, fz); // at track perigee point
193//
194//--- Move ref. frame to the track common point refGVertex
195// Small beamline inclination doesn't change track covariance matrix
196//
197 AmgSymMatrix(5) tmpCov = AmgSymMatrix(5)(*(mPer->covariance()));
198 const Perigee tmpPer(mPer->position(),mPer->momentum(),mPer->charge(),surfGRefPoint,std::move(tmpCov));
199 VectPerig = tmpPer.parameters();
200 //--- Transform to internal parametrisation
201 double effectiveBMAG=state.m_fitField.getEffField(fx, fy, fz, VectPerig[2], VectPerig[3]);
202 if(fabs(effectiveBMAG) < 0.01) effectiveBMAG=0.01;
203 VKalTransform( effectiveBMAG, (double)VectPerig[0], (double)VectPerig[1],
204 (double)VectPerig[2], (double)VectPerig[3], (double)VectPerig[4], CovVertTrk,
205 state.m_ich[ntrk],&state.m_apar[ntrk][0],&state.m_awgt[ntrk][0]);
206 state.m_ich[ntrk]=0;
207 if(state.m_apar[ntrk][4]<0){ state.m_apar[ntrk][4] = -state.m_apar[ntrk][4]; // Charge=0 is always equal to Charge=+1
208 state.m_awgt[ntrk][10] = -state.m_awgt[ntrk][10];
209 state.m_awgt[ntrk][11] = -state.m_awgt[ntrk][11];
210 state.m_awgt[ntrk][12] = -state.m_awgt[ntrk][12];
211 state.m_awgt[ntrk][13] = -state.m_awgt[ntrk][13]; }
212
213 ntrk++;
214 if(ntrk>=NTrMaxVFit) {
215 return StatusCode::FAILURE;
216 }
217 }
218//-------------- Finally setting new reference frame common for ALL tracks
219 state.m_refFrameX=tmp_refFrameX;
220 state.m_refFrameY=tmp_refFrameY;
221 state.m_refFrameZ=tmp_refFrameZ;
223 return StatusCode::SUCCESS;
224 }
225
226//----------------------------------------------------------------------------------------------------------
227
229 {
230 const Perigee* mPer = nullptr;
231 if(i_ntrk->surfaceType()==Trk::SurfaceType::Perigee && i_ntrk->covariance()!= nullptr ) {
232 mPer = dynamic_cast<const Perigee*> (i_ntrk);
233 }
234 return mPer;
235 }
236
237
238} // end of namespace bracket indexOfParameterAtPosition
#define AmgSymMatrix(dim)
#define AmgVector(rows)
const Amg::Vector3D & momentum() const
Access method for the momentum.
virtual constexpr SurfaceType surfaceType() const override=0
Returns the Surface Type enum for the surface used to define the derived class.
const Amg::Vector3D & position() const
Access method for the position.
double charge() const
Returns the charge.
Class describing the Line to which the Perigee refers to.
std::vector< double > m_MassInputParticles
double m_apar[NTrMaxVFit][5]
double m_awgt[NTrMaxVFit][15]
std::vector< TrkMatControl > m_trkControl
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
static const Perigee * GetPerigee(const TrackParameters *i_ntrk)
StatusCode CvtTrackParticle(std::span< const xAOD::TrackParticle *const > list, int &ntrk, State &state) const
Gaudi::Property< double > m_IDsizeR
StatusCode CvtNeutralParticle(const std::vector< const xAOD::NeutralParticle * > &list, 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
ParametersT< NeutralParametersDim, Neutral, PerigeeSurface > NeutralPerigee
ParametersBase< TrackParametersDim, Charged > TrackParameters