ATLAS Offline Software
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 
20 namespace 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
Trk::TrkVKalVrtFitter::State
Definition: TrkVKalVrtFitter.h:387
Trk::TrkVKalVrtFitter::CvtNeutralParticle
StatusCode CvtNeutralParticle(const std::vector< const xAOD::NeutralParticle * > &list, int &ntrk, State &state) const
Definition: CvtTrackParticle.cxx:126
Trk::TrkVKalVrtFitter::State::m_refFrameZ
double m_refFrameZ
Definition: TrkVKalVrtFitter.h:395
TrackParameters.h
Trk::TrkVKalVrtFitter::State::m_refFrameX
double m_refFrameX
Definition: TrkVKalVrtFitter.h:393
Trk::TrkVKalVrtFitter::VKalTransform
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
Definition: VKalTransform.cxx:59
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
Trk::TrkVKalVrtFitter::TrkMatControl::trkSavedLocalVertex
Amg::Vector3D trkSavedLocalVertex
Definition: TrkVKalVrtFitter.h:371
Trk::ParametersBase::surfaceType
constexpr virtual SurfaceType surfaceType() const override=0
Returns the Surface Type enum for the surface used to define the derived class.
Trk::TrkVKalVrtFitter::TrkMatControl::prtMass
double prtMass
Definition: TrkVKalVrtFitter.h:370
Trk::TrkVKalVrtFitter::TrkMatControl::extrapolationType
int extrapolationType
Definition: TrkVKalVrtFitter.h:367
Trk::TrkVKalVrtFitter::m_IDsizeR
Gaudi::Property< double > m_IDsizeR
Definition: TrkVKalVrtFitter.h:326
Trk::VKalAtlasMagFld::getMagFld
virtual void getMagFld(const double, const double, const double, double &, double &, double &) override
Definition: VKalAtlasMagFld.cxx:61
NeutralParameters.h
Trk::TrkVKalVrtFitter::TrkMatControl::TrkPnt
const TrackParameters * TrkPnt
Definition: TrkVKalVrtFitter.h:369
Trk::TrkVKalVrtFitter::TrkMatControl
Definition: TrkVKalVrtFitter.h:364
Trk::TrkVKalVrtFitter::convertAmg5SymMtx
bool convertAmg5SymMtx(const AmgSymMatrix(5) *, double[15]) const
Definition: VKalTransform.cxx:26
Trk::TrkVKalVrtFitter::TrkMatControl::trkRefGlobPos
Amg::Vector3D trkRefGlobPos
Definition: TrkVKalVrtFitter.h:366
TrkVKalVrtFitter.h
ParticleConstants::PDG2011::chargedPionMassInMeV
constexpr double chargedPionMassInMeV
the mass of the charged pion (in MeV)
Definition: ParticleConstants.h:41
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
Trk::TrkVKalVrtFitter::State::m_trkControl
std::vector< TrkMatControl > m_trkControl
Definition: TrkVKalVrtFitter.h:396
Trk::TrkVKalVrtFitter::State::m_awgt
double m_awgt[NTrMaxVFit][15]
Definition: TrkVKalVrtFitter.h:402
TrkVKalVrtCore.h
Trk::TrkVKalVrtFitter::State::m_allowUltraDisplaced
bool m_allowUltraDisplaced
Definition: TrkVKalVrtFitter.h:435
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::baseMagFld::getEffField
double getEffField(double bx, double by, double bz, double phi, double theta)
Definition: VKalVrtBMag.h:41
Trk::TrkVKalVrtFitter::State::m_MassInputParticles
std::vector< double > m_MassInputParticles
Definition: TrkVKalVrtFitter.h:444
Trk::TrkVKalVrtFitter::GetPerigee
static const Perigee * GetPerigee(const TrackParameters *i_ntrk)
Definition: CvtTrackParticle.cxx:228
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::SurfaceType::Perigee
@ Perigee
Trk::TrkVKalVrtFitter::State::m_fitField
VKalAtlasMagFld m_fitField
Definition: TrkVKalVrtFitter.h:406
Trk::TrkVKalVrtFitter::TrkMatControl::TrkID
int TrkID
Definition: TrkVKalVrtFitter.h:368
Trk::TrkVKalVrtFitter::State::m_ich
long int m_ich[NTrMaxVFit]
Definition: TrkVKalVrtFitter.h:403
Trk::VKalAtlasMagFld::setAtlasMagRefFrame
void setAtlasMagRefFrame(double, double, double)
Definition: VKalAtlasMagFld.cxx:52
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::TrkVKalVrtFitter::State::m_refFrameY
double m_refFrameY
Definition: TrkVKalVrtFitter.h:394
lumiFormat.fill
fill
Definition: lumiFormat.py:104
Trk::NTrMaxVFit
@ NTrMaxVFit
Definition: TrkVKalVrtFitter.h:35
Trk::TrkVKalVrtFitter::CvtTrackParticle
StatusCode CvtTrackParticle(std::span< const xAOD::TrackParticle *const > list, int &ntrk, State &state) const
Definition: CvtTrackParticle.cxx:27
test_pyathena.counter
counter
Definition: test_pyathena.py:15
Trk::TrkVKalVrtFitter::State::m_apar
double m_apar[NTrMaxVFit][5]
Definition: TrkVKalVrtFitter.h:401
Trk::TrkVKalVrtFitter::m_IDsizeZ
Gaudi::Property< double > m_IDsizeZ
Definition: TrkVKalVrtFitter.h:327