ATLAS Offline Software
CvtTrackParticle.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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,BMAG_FIXED;
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(fabs(perGlobalPos.z()) > m_IDsizeZ)return StatusCode::FAILURE; // Crazy user protection
55  if( 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;
64  tmpMat.prtMass = 139.5702;
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, BMAG_FIXED); // at the track perigee point
93  if(fabs(BMAG_FIXED) < 0.01) BMAG_FIXED=0.01;
94 //
95 //--- Move ref. frame to the track common point refGVertex
96 // Small beamline inclination doesn't change track covariance matrix
97  AmgSymMatrix(5) tmpCov = AmgSymMatrix(5)(*(mPer->covariance()));
98  const Perigee tmpPer(mPer->position(),mPer->momentum(),mPer->charge(),surfGRefPoint,std::move(tmpCov));
99  VectPerig = tmpPer.parameters();
100 //--- Transform to internal parametrisation
101  VKalTransform( BMAG_FIXED, (double)VectPerig[0], (double)VectPerig[1],
102  (double)VectPerig[2], (double)VectPerig[3], (double)VectPerig[4], CovVertTrk,
103  state.m_ich[ntrk],&state.m_apar[ntrk][0],&state.m_awgt[ntrk][0]);
104 //
105  ntrk++;
106  if(ntrk>=NTrMaxVFit) {
107  return StatusCode::FAILURE;
108  }
109  }
110 //-------------- Finally setting new reference frame common for ALL tracks
111  state.m_refFrameX=tmp_refFrameX;
112  state.m_refFrameY=tmp_refFrameY;
113  state.m_refFrameZ=tmp_refFrameZ;
115 
116  return StatusCode::SUCCESS;
117  }
118 
119 //--------------------------------------------------------------------
120 // Extract xAOD::NeutralParticles
121 //
122 
123  StatusCode
124  TrkVKalVrtFitter::CvtNeutralParticle(const std::vector<const xAOD::NeutralParticle*>& InpTrk,
125  int& ntrk,
126  State& state) const
127  {
128  std::vector<const xAOD::NeutralParticle*>::const_iterator i_ntrk;
129  AmgVector(5) VectPerig; VectPerig.setZero();
130  const NeutralPerigee* mPer=nullptr;
131  double CovVertTrk[15]; std::fill(CovVertTrk,CovVertTrk+15,0.);
132  double tmp_refFrameX=0, tmp_refFrameY=0, tmp_refFrameZ=0;
133  double fx,fy,BMAG_FIXED;
134 //
135 // ----- Set reference frame to (0.,0.,0.) == ATLAS frame
136 // ----- Magnetic field is taken in reference point
137 //
138  state.m_refFrameX=state.m_refFrameY=state.m_refFrameZ=0.;
139  state.m_fitField.setAtlasMagRefFrame( 0., 0., 0.);
140 //
141 // Cycle to determine common reference point for the fit
142 //
143  int counter =0;
144  Amg::Vector3D perGlobalPos;
145  state.m_trkControl.clear(); state.m_trkControl.reserve(InpTrk.size());
146  for (i_ntrk = InpTrk.begin(); i_ntrk != InpTrk.end(); ++i_ntrk) {
147 //-- (Measured)Perigee in xAOD::NeutralParticle
148  mPer = &(*i_ntrk)->perigeeParameters();
149  if( mPer==nullptr ) continue; // No perigee!!!
150  perGlobalPos = mPer->position(); //Global position of perigee point
151  if(fabs(perGlobalPos.z()) > m_IDsizeZ)return StatusCode::FAILURE; // Crazy user protection
152  if( perGlobalPos.perp() > m_IDsizeR)return StatusCode::FAILURE;
153  tmp_refFrameX += perGlobalPos.x() ; // Reference system calculation
154  tmp_refFrameY += perGlobalPos.y() ; // Use hit position itself to get more precise
155  tmp_refFrameZ += perGlobalPos.z() ; // magnetic field
156  TrkMatControl tmpMat;
157  tmpMat.trkSavedLocalVertex.setZero();
158  tmpMat.trkRefGlobPos=Amg::Vector3D( perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z());
159  tmpMat.extrapolationType=2; // Perigee point strategy
160  tmpMat.TrkPnt=nullptr; //No reference point for neutral particle for the moment
161  tmpMat.prtMass = 139.5702;
162  if(counter<(int)state.m_MassInputParticles.size())tmpMat.prtMass = state.m_MassInputParticles[counter];
163  tmpMat.TrkID=counter; state.m_trkControl.push_back(tmpMat);
164  counter++;
165  }
166  if(counter == 0) return StatusCode::FAILURE;
167  tmp_refFrameX /= counter; // Reference frame for the fit
168  tmp_refFrameY /= counter;
169  tmp_refFrameZ /= counter;
170  Amg::Vector3D refGVertex (tmp_refFrameX, tmp_refFrameY, tmp_refFrameZ);
171  PerigeeSurface surfGRefPoint( refGVertex ); // Reference perigee surface for current fit
172 //
173 //std::cout.setf( std::ios::scientific); std::cout.precision(5);
174 //std::cout<<" VK ref.frame="<<tmp_refFrameX<<", "<<tmp_refFrameY<<", "<<tmp_refFrameZ<<'\n';
175 //
176 // Common reference frame is ready. Start extraction of parameters for fit.
177 //
178 
179  state.m_refFrameX=state.m_refFrameY=state.m_refFrameZ=0.; //set ATLAS frame
180  state.m_fitField.setAtlasMagRefFrame( 0., 0., 0.); //set ATLAS frame
181  for (i_ntrk = InpTrk.begin(); i_ntrk != InpTrk.end(); ++i_ntrk) {
182 //
183 //-- (Measured)Perigee in TrackParticle
184 //
185  mPer = &(*i_ntrk)->perigeeParameters();
186  if( mPer==nullptr ) continue; // No perigee!!!
187  perGlobalPos = mPer->position(); //Global position of perigee point
188  if( !convertAmg5SymMtx(mPer->covariance(), CovVertTrk) ) return StatusCode::FAILURE; //VK no good covariance matrix!;
189  state.m_fitField.getMagFld( perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z(), // Magnetic field
190  fx, fy, BMAG_FIXED); // at track perigee point
191  if(fabs(BMAG_FIXED) < 0.01) BMAG_FIXED=0.01;
192 
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  VKalTransform( BMAG_FIXED, (double)VectPerig[0], (double)VectPerig[1],
202  (double)VectPerig[2], (double)VectPerig[3], (double)VectPerig[4], CovVertTrk,
203  state.m_ich[ntrk],&state.m_apar[ntrk][0],&state.m_awgt[ntrk][0]);
204  state.m_ich[ntrk]=0;
205  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
206  state.m_awgt[ntrk][10] = -state.m_awgt[ntrk][10];
207  state.m_awgt[ntrk][11] = -state.m_awgt[ntrk][11];
208  state.m_awgt[ntrk][12] = -state.m_awgt[ntrk][12];
209  state.m_awgt[ntrk][13] = -state.m_awgt[ntrk][13]; }
210 
211  ntrk++;
212  if(ntrk>=NTrMaxVFit) {
213  return StatusCode::FAILURE;
214  }
215  }
216 //-------------- Finally setting new reference frame common for ALL tracks
217  state.m_refFrameX=tmp_refFrameX;
218  state.m_refFrameY=tmp_refFrameY;
219  state.m_refFrameZ=tmp_refFrameZ;
221  return StatusCode::SUCCESS;
222  }
223 
224 //----------------------------------------------------------------------------------------------------------
225 
227  {
228  const Perigee* mPer = nullptr;
229  if(i_ntrk->surfaceType()==Trk::SurfaceType::Perigee && i_ntrk->covariance()!= nullptr ) {
230  mPer = dynamic_cast<const Perigee*> (i_ntrk);
231  }
232  return mPer;
233  }
234 
235 
236 } // end of namespace bracket indexOfParameterAtPosition
Trk::TrkVKalVrtFitter::State
Definition: TrkVKalVrtFitter.h:382
Trk::TrkVKalVrtFitter::CvtNeutralParticle
StatusCode CvtNeutralParticle(const std::vector< const xAOD::NeutralParticle * > &list, int &ntrk, State &state) const
Definition: CvtTrackParticle.cxx:124
Trk::TrkVKalVrtFitter::State::m_refFrameZ
double m_refFrameZ
Definition: TrkVKalVrtFitter.h:390
TrackParameters.h
Trk::TrkVKalVrtFitter::State::m_refFrameX
double m_refFrameX
Definition: TrkVKalVrtFitter.h:388
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:366
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:365
Trk::TrkVKalVrtFitter::TrkMatControl::extrapolationType
int extrapolationType
Definition: TrkVKalVrtFitter.h:362
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:364
Trk::TrkVKalVrtFitter::TrkMatControl
Definition: TrkVKalVrtFitter.h:359
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:361
TrkVKalVrtFitter.h
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
Trk::TrkVKalVrtFitter::m_IDsizeR
SimpleProperty< double > m_IDsizeR
Definition: TrkVKalVrtFitter.h:326
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:391
Trk::TrkVKalVrtFitter::State::m_awgt
double m_awgt[NTrMaxVFit][15]
Definition: TrkVKalVrtFitter.h:397
Trk::TrkVKalVrtFitter::m_IDsizeZ
SimpleProperty< double > m_IDsizeZ
Definition: TrkVKalVrtFitter.h:327
TrkVKalVrtCore.h
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::TrkVKalVrtFitter::State::m_MassInputParticles
std::vector< double > m_MassInputParticles
Definition: TrkVKalVrtFitter.h:438
Trk::TrkVKalVrtFitter::GetPerigee
static const Perigee * GetPerigee(const TrackParameters *i_ntrk)
Definition: CvtTrackParticle.cxx:226
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
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:401
Trk::TrkVKalVrtFitter::TrkMatControl::TrkID
int TrkID
Definition: TrkVKalVrtFitter.h:363
Trk::TrkVKalVrtFitter::State::m_ich
long int m_ich[NTrMaxVFit]
Definition: TrkVKalVrtFitter.h:398
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:389
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:396