ATLAS Offline Software
CvtPerigee.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Convert TrkTrack 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 //------------------------------------------------------------------
10 // Header include
13 
14 #include <iostream>
15 
16 namespace Trk{
17 
18  //--------------------------------------------------------------------
19  //
20  // Use perigee ONLY!!!
21  // Then in normal conditions reference frame is always (0,0,0)
22  //
23 
25  TrkVKalVrtFitter::CvtPerigee(const std::vector<const Perigee*>& InpPerigee,
26  int& ntrk,
27  State& state) const
28  {
29 
30  double tmp_refFrameX = 0, tmp_refFrameY = 0, tmp_refFrameZ = 0;
31 
32  //
33  // ----- Set reference frame to (0.,0.,0.) == ATLAS frame
34  // ----- Magnetic field is taken in reference point
35  //
36  state.m_refFrameX = state.m_refFrameY = state.m_refFrameZ = 0.;
37  state.m_fitField.setAtlasMagRefFrame( 0., 0., 0.);
38 
39  //
40  // Cycle to determine common reference point for the fit
41  //
42  int counter =0;
43  state.m_trkControl.clear();
44  for (const auto& mPer : InpPerigee) {
45  if( mPer == nullptr ){ continue; }
46 
47  // Global position of perigee point
48  Amg::Vector3D perGlobalPos = mPer->position();
49  // Crazy user protection
50  if(std::abs(perGlobalPos.z()) > m_IDsizeZ) return StatusCode::FAILURE;
51  if(perGlobalPos.perp() > m_IDsizeR) return StatusCode::FAILURE;
52 
53  // Reference system calculation
54  // Use hit position itself to get more precise magnetic field
55  tmp_refFrameX += perGlobalPos.x() ;
56  tmp_refFrameY += perGlobalPos.y() ;
57  tmp_refFrameZ += perGlobalPos.z() ;
58 
59  TrkMatControl tmpMat;
60  tmpMat.trkRefGlobPos = Amg::Vector3D(perGlobalPos.x(),
61  perGlobalPos.y(),
62  perGlobalPos.z());
63  // Perigee point strategy
64  tmpMat.extrapolationType = 2;
65  tmpMat.TrkPnt = mPer;
66  tmpMat.prtMass = 139.5702;
67  if(counter < static_cast<int>(state.m_MassInputParticles.size())){
68  tmpMat.prtMass = state.m_MassInputParticles[counter];
69  }
70  tmpMat.trkSavedLocalVertex.setZero();
71  tmpMat.TrkID=counter;
72  state.m_trkControl.push_back(tmpMat);
73  counter++;
74  }
75 
76  if(counter == 0) return StatusCode::FAILURE;
77 
78  // Reference frame for the fit
79  tmp_refFrameX /= counter;
80  tmp_refFrameY /= counter;
81  tmp_refFrameZ /= counter;
82 
83  //
84  // Common reference frame is ready. Start extraction of parameters for fit.
85  //
86  double fx = 0., fy = 0., BMAG_FIXED = 0.;
87  for (const auto& mPer : InpPerigee) {
88  if(mPer == nullptr){ continue; }
89  AmgVector(5) VectPerig = mPer->parameters();
90  // Global position of perigee point
91  Amg::Vector3D perGlobalPos = mPer->position();
92  // Global position of reference point
93  Amg::Vector3D perGlobalVrt = mPer->associatedSurface().center();
94  // Restore ATLAS frame
95  state.m_refFrameX = state.m_refFrameY = state.m_refFrameZ = 0.;
96  state.m_fitField.setAtlasMagRefFrame(0., 0., 0.);
97  // Magnetic field at perigee point
98  state.m_fitField.getMagFld(perGlobalPos.x(),
99  perGlobalPos.y(),
100  perGlobalPos.z(),
101  fx, fy, BMAG_FIXED);
102  if(std::abs(BMAG_FIXED) < 0.01) BMAG_FIXED = 0.01;
103 
104  double CovVertTrk[15];
105  std::fill(CovVertTrk,CovVertTrk+15,0.);
106  // No good covariance matrix!
107  if(!convertAmg5SymMtx(mPer->covariance(), CovVertTrk)) return StatusCode::FAILURE;
108  VKalTransform(BMAG_FIXED,
109  static_cast<double>(VectPerig(0)),
110  static_cast<double>(VectPerig(1)),
111  static_cast<double>(VectPerig(2)),
112  static_cast<double>(VectPerig(3)),
113  static_cast<double>(VectPerig(4)),
114  CovVertTrk,
115  state.m_ich[ntrk], &state.m_apar[ntrk][0],
116  &state.m_awgt[ntrk][0]);
117 
118  // Check if propagation to common reference point is needed and make it
119  // initial track reference position
120  state.m_refFrameX=perGlobalVrt.x();
121  state.m_refFrameY=perGlobalVrt.y();
122  state.m_refFrameZ=perGlobalVrt.z();
124  state.m_refFrameY,
125  state.m_refFrameZ);
126  double dX = tmp_refFrameX-perGlobalVrt.x();
127  double dY = tmp_refFrameY-perGlobalVrt.y();
128  double dZ = tmp_refFrameZ-perGlobalVrt.z();
129  if(std::abs(dX)+std::abs(dY)+std::abs(dZ) != 0.) {
130  double pari[5], covi[15];
131  double vrtini[3] = {0.,0.,0.};
132  double vrtend[3] = {dX,dY,dZ};
133  for(int i=0; i<5; i++) pari[i] = state.m_apar[ntrk][i];
134  for(int i=0; i<15;i++) covi[i] = state.m_awgt[ntrk][i];
135  long int Charge = (long int) mPer->charge();
136  long int TrkID = ntrk;
137  Trk::vkalPropagator::Propagate(TrkID, Charge, pari, covi,
138  vrtini, vrtend, &state.m_apar[ntrk][0],
139  &state.m_awgt[ntrk][0],
140  &state.m_vkalFitControl);
141  }
142 
143  ntrk++;
144  if(ntrk>=NTrMaxVFit) return StatusCode::FAILURE;
145  }
146 
147  //-------------- Finally setting new reference frame common for ALL tracks
148  state.m_refFrameX = tmp_refFrameX;
149  state.m_refFrameY = tmp_refFrameY;
150  state.m_refFrameZ = tmp_refFrameZ;
152  state.m_refFrameY,
153  state.m_refFrameZ);
154 
155  return StatusCode::SUCCESS;
156  }
157 
158  std::unique_ptr<Perigee>
159  TrkVKalVrtFitter::CreatePerigee(const std::vector<double>& VKPerigee,
160  const std::vector<double>& VKCov,
161  IVKalState& istate) const
162  {
163  assert(dynamic_cast<const State*> (&istate)!=nullptr);
164  State& state = static_cast<State&> (istate);
165  return CreatePerigee(0., 0., 0., VKPerigee, VKCov, state);
166  }
167 
168  // Function creates a Trk::Perigee on the heap
169  // Don't forget to remove it after use
170  // vX,vY,vZ are in LOCAL SYSTEM with respect to refGVertex
171  std::unique_ptr<Perigee>
172  TrkVKalVrtFitter::CreatePerigee(double vX, double vY, double vZ,
173  const std::vector<double>& VKPerigee,
174  const std::vector<double>& VKCov,
175  State& state) const
176  {
177 
178  // ------ Magnetic field access
179  double fx = 0., fy = 0., BMAG_CUR = 0.;
180  state.m_fitField.getMagFld(vX,vY,vZ,fx,fy,BMAG_CUR);
181  if(std::abs(BMAG_CUR) < 0.01) BMAG_CUR=0.01; //safety
182 
183  double TrkP3 = 0., TrkP4 = 0., TrkP5 = 0.;
184  VKalToTrkTrack(BMAG_CUR, VKPerigee[2], VKPerigee[3], VKPerigee[4],
185  TrkP3, TrkP4, TrkP5);
186  double TrkP1 = -VKPerigee[0];
187  double TrkP2 = VKPerigee[1];
188  TrkP5 = -TrkP5;
190  AmgSymMatrix(5) CovMtx;
191  double Deriv[5][5],CovMtxOld[5][5];
192  for(int i=0; i<5; i++){
193  for(int j=0; j<5; j++){
194  Deriv[i][j]=0.;
195  CovMtxOld[i][j]=0.;
196  }
197  }
198  Deriv[0][0] = -1.;
199  Deriv[1][1] = 1.;
200  Deriv[2][3] = 1.;
201  Deriv[3][2] = 1.;
202  Deriv[4][2] = (std::cos(VKPerigee[2])/(m_CNVMAG*BMAG_CUR)) * VKPerigee[4];
203  Deriv[4][4] = -(std::sin(VKPerigee[2])/(m_CNVMAG*BMAG_CUR));
204 
205  CovMtxOld[0][0] = VKCov[0];
206  CovMtxOld[0][1] = CovMtxOld[1][0] = VKCov[1];
207  CovMtxOld[1][1] = VKCov[2];
208  CovMtxOld[0][2] = CovMtxOld[2][0] = VKCov[3];
209  CovMtxOld[1][2] = CovMtxOld[2][1] = VKCov[4];
210  CovMtxOld[2][2] = VKCov[5];
211  CovMtxOld[0][3] = CovMtxOld[3][0] = VKCov[6];
212  CovMtxOld[1][3] = CovMtxOld[3][1] = VKCov[7];
213  CovMtxOld[2][3] = CovMtxOld[3][2] = VKCov[8];
214  CovMtxOld[3][3] = VKCov[9];
215  CovMtxOld[0][4] = CovMtxOld[4][0] = VKCov[10];
216  CovMtxOld[1][4] = CovMtxOld[4][1] = VKCov[11];
217  CovMtxOld[2][4] = CovMtxOld[4][2] = VKCov[12];
218  CovMtxOld[3][4] = CovMtxOld[4][3] = VKCov[13];
219  CovMtxOld[4][4] = VKCov[14];
220 
221  for(int i=0; i<5; i++){
222  for(int j=i; j<5; j++){
223  double tmp=0.;
224  for(int ik=4; ik>=0; ik--){
225  if(Deriv[i][ik]==0.)continue;
226  for(int jk=4; jk>=0; jk--){
227  if(Deriv[j][jk]==0.)continue;
228  tmp += Deriv[i][ik]*CovMtxOld[ik][jk]*Deriv[j][jk];
229  }
230  }
231  CovMtx(i,j) = CovMtx(j,i)=tmp;
232  }
233  }
234 
235  auto surface = PerigeeSurface(Amg::Vector3D(state.m_refFrameX+vX,
236  state.m_refFrameY+vY,
237  state.m_refFrameZ+vZ));
238 
239  return std::make_unique<Perigee>(TrkP1, TrkP2, TrkP3, TrkP4, TrkP5,
240  surface,
241  std::move(CovMtx));
242  }
243 
244 } // end of namespace
245 
246 
247 
Trk::TrkVKalVrtFitter::State
Definition: TrkVKalVrtFitter.h:382
Trk::TrkVKalVrtFitter::State::m_refFrameZ
double m_refFrameZ
Definition: TrkVKalVrtFitter.h:390
Trk::TrkVKalVrtFitter::State::m_refFrameX
double m_refFrameX
Definition: TrkVKalVrtFitter.h:388
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Trk::TrkVKalVrtFitter::CreatePerigee
virtual std::unique_ptr< Trk::Perigee > CreatePerigee(const std::vector< double > &VKPerigee, const std::vector< double > &VKCov, IVKalState &istate) const override final
Definition: CvtPerigee.cxx:159
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::TrkVKalVrtFitter::TrkMatControl::trkSavedLocalVertex
Amg::Vector3D trkSavedLocalVertex
Definition: TrkVKalVrtFitter.h:366
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
Trk::TrkVKalVrtFitter::CvtPerigee
StatusCode CvtPerigee(const std::vector< const Perigee * > &list, int &ntrk, State &state) const
Definition: CvtPerigee.cxx:25
Trk::TrkVKalVrtFitter::TrkMatControl::TrkPnt
const TrackParameters * TrkPnt
Definition: TrkVKalVrtFitter.h:364
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
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
Trk::TrkVKalVrtFitter::State::m_vkalFitControl
VKalVrtControl m_vkalFitControl
Definition: TrkVKalVrtFitter.h:402
TrkVKalVrtFitter.h
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
Trk::vkalPropagator::Propagate
static void Propagate(long int TrkID, long int Charge, double *ParOld, double *CovOld, double *RefStart, double *RefEnd, double *ParNew, double *CovNew, VKalVrtControlBase *FitControl=0)
Definition: Propagator.cxx:127
Trk::TrkVKalVrtFitter::m_CNVMAG
double m_CNVMAG
Definition: TrkVKalVrtFitter.h:466
Trk::TrkVKalVrtFitter::m_IDsizeR
SimpleProperty< double > m_IDsizeR
Definition: TrkVKalVrtFitter.h:326
lumiFormat.i
int i
Definition: lumiFormat.py:85
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::NTrMaxVFit
@ NTrMaxVFit
Definition: TrkVKalVrtFitter.h:35
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
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
Trk::TrkVKalVrtFitter::State::m_MassInputParticles
std::vector< double > m_MassInputParticles
Definition: TrkVKalVrtFitter.h:438
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::TrkVKalVrtFitter::VKalToTrkTrack
void VKalToTrkTrack(double curBMAG, double vp1, double vp2, double vp3, double &tp1, double &tp2, double &tp3) const
Definition: VKalVrtFitSvc.cxx:406
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::IVKalState
Definition: IVKalState.h:21
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
test_pyathena.counter
counter
Definition: test_pyathena.py:15
Trk::TrkVKalVrtFitter::State::m_apar
double m_apar[NTrMaxVFit][5]
Definition: TrkVKalVrtFitter.h:396