ATLAS Offline Software
CvtParametersBase.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 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 
17 namespace 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(std::abs(perGlobalPos.z()) > m_IDsizeZ) return StatusCode::FAILURE;
61  if(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
73  tmpMat.extrapolationType = m_firstMeasuredPoint ? 0 : 1;
74  tmpMat.TrkPnt = (*i_pbase);
75  tmpMat.prtMass = 139.5702;
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  //Rotation parameters in case of rotation use
97  double fx, fy, fz, BMAG_FIXED;
98  state.m_fitField.getMagFld(tmp_refFrameX, tmp_refFrameY, tmp_refFrameZ,
99  fx, fy, fz);
100 
101  //
102  // Common reference frame is ready. Start extraction of parameters for fit.
103  // TracksParameters are extrapolated to common point and converted to Perigee
104  // This is needed for VKalVrtCore engine.
105  //
106 
107  double CovVertTrk[15];
108  std::fill(CovVertTrk, CovVertTrk+15, 0.);
109 
110  for (i_pbase = InpTrk.begin(); i_pbase != InpTrk.end(); ++i_pbase) {
111  long int TrkID=ntrk;
112  const TrackParameters* trkparO = (*i_pbase);
113 
114  if(trkparO){
115  const Trk::TrackParameters* trkparN =
117  trkparO,
118  &refGVertex,
119  state);
120  if(trkparN == nullptr) return StatusCode::FAILURE;
121  mPer = dynamic_cast<const Trk::Perigee*>(trkparN);
122  if(mPer == nullptr) {
123  delete trkparN;
124  return StatusCode::FAILURE;
125  }
126 
127  VectPerig = mPer->parameters();
128  // Global position of perigee point
129  perGlobalPos = mPer->position();
130  // Global position of reference point
131  perGlobalVrt = mPer->associatedSurface().center();
132  // VK no good covariance matrix!
133  if( !convertAmg5SymMtx(mPer->covariance(), CovVertTrk) ) return StatusCode::FAILURE;
134  delete trkparN;
135  }
136 
137  state.m_refFrameX = state.m_refFrameY = state.m_refFrameZ = 0.;
138  // Restore ATLAS frame for safety
139  state.m_fitField.setAtlasMagRefFrame(0., 0., 0.);
140  // Magnetic field at perigee point
141  state.m_fitField.getMagFld(perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z(),
142  fx, fy, BMAG_FIXED);
143  if(std::abs(BMAG_FIXED) < 0.01) BMAG_FIXED = 0.01;
144 
145  VKalTransform(BMAG_FIXED,
146  (double)VectPerig[0], (double)VectPerig[1],
147  (double)VectPerig[2], (double)VectPerig[3],
148  (double)VectPerig[4], CovVertTrk,
149  state.m_ich[ntrk], &state.m_apar[ntrk][0],
150  &state.m_awgt[ntrk][0]);
151 
152  // Neutral track
153  if( trkparO==nullptr ) {
154  state.m_ich[ntrk]=0;
155  if(state.m_apar[ntrk][4]<0){
156  // Charge=0 is always equal to Charge=+1
157  state.m_apar[ntrk][4] = -state.m_apar[ntrk][4];
158  state.m_awgt[ntrk][10] = -state.m_awgt[ntrk][10];
159  state.m_awgt[ntrk][11] = -state.m_awgt[ntrk][11];
160  state.m_awgt[ntrk][12] = -state.m_awgt[ntrk][12];
161  state.m_awgt[ntrk][13] = -state.m_awgt[ntrk][13];
162  }
163  }
164  ntrk++;
165  if(ntrk>=NTrMaxVFit) return StatusCode::FAILURE;
166  }
167 
168  //-------------- Finally setting new reference frame common for ALL tracks
169  state.m_refFrameX = tmp_refFrameX;
170  state.m_refFrameY = tmp_refFrameY;
171  state.m_refFrameZ = tmp_refFrameZ;
173 
174  return StatusCode::SUCCESS;
175  }
176 
177 
178  StatusCode
179  TrkVKalVrtFitter::CvtNeutralParameters(const std::vector<const NeutralParameters*>& InpTrk,
180  int& ntrk,
181  State& state) const
182  {
183 
184  std::vector<const NeutralParameters*>::const_iterator i_pbase;
185  AmgVector(5) VectPerig;
186  Amg::Vector3D perGlobalPos,perGlobalVrt;
187  const NeutralPerigee* mPerN = nullptr;
188  double CovVertTrk[15];
189  double tmp_refFrameX = 0, tmp_refFrameY = 0, tmp_refFrameZ = 0;
190  double rxyMin = 1000000.;
191 
192  //
193  // ----- Set reference frame to (0.,0.,0.) == ATLAS frame
194  // ----- Magnetic field is taken in reference point
195  //
196  state.m_refFrameX = state.m_refFrameY = state.m_refFrameZ = 0.;
197  state.m_fitField.setAtlasMagRefFrame(0., 0., 0.);
198 
199  if( m_InDetExtrapolator == nullptr ){
200  if(msgLvl(MSG::WARNING))msg()<< "No InDet extrapolator given. Can't use TrackParameters!!!" << endmsg;
201  return StatusCode::FAILURE;
202  }
203 
204  //
205  // Cycle to determine common reference point for the fit
206  //
207  int counter = 0;
208  state.m_trkControl.clear();
209  state.m_trkControl.reserve(InpTrk.size());
210  for (i_pbase = InpTrk.begin(); i_pbase != InpTrk.end(); ++i_pbase) {
211  // Global position of hit
212  perGlobalPos = (*i_pbase)->position();
213  // Crazy user protection
214  if(std::abs(perGlobalPos.z()) > m_IDsizeZ) return StatusCode::FAILURE;
215  if(perGlobalPos.perp() > m_IDsizeR)return StatusCode::FAILURE;
216 
217  tmp_refFrameX += perGlobalPos.x() ;
218  tmp_refFrameY += perGlobalPos.y() ;
219  tmp_refFrameZ += perGlobalPos.z() ;
220 
221  // Here we create structure to control material effects
222  TrkMatControl tmpMat;
223  tmpMat.trkSavedLocalVertex.setZero();
224  // on track extrapolation
225  tmpMat.trkRefGlobPos = Amg::Vector3D(perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z());
226  // First measured point strategy
227  tmpMat.extrapolationType = 0;
228  //No reference point for neutral track for the moment !!!
229  tmpMat.TrkPnt = nullptr;
230  tmpMat.prtMass = 139.5702;
231  if(counter<(int)state.m_MassInputParticles.size()){
232  tmpMat.prtMass = state.m_MassInputParticles[counter];
233  }
234  tmpMat.TrkID = counter;
235  state.m_trkControl.push_back(tmpMat);
236  counter++;
237  if(perGlobalPos.perp()<rxyMin){
238  rxyMin = perGlobalPos.perp();
239  state.m_globalFirstHit=nullptr;
240  }
241  }
242 
243  if(counter == 0) return StatusCode::FAILURE;
244  // Reference frame for the fit based on hits positions
245  tmp_refFrameX /= counter;
246  tmp_refFrameY /= counter;
247  tmp_refFrameZ /= counter;
248  Amg::Vector3D refGVertex (tmp_refFrameX, tmp_refFrameY, tmp_refFrameZ);
249 
250  // Rotation parameters in case of rotation use
251  double fx,fy,fz,BMAG_FIXED;
252  state.m_fitField.getMagFld(tmp_refFrameX, tmp_refFrameY, tmp_refFrameZ,
253  fx, fy, fz);
254 
255  //
256  // Common reference frame is ready. Start extraction of parameters for fit.
257  // TracksParameters are extrapolated to common point and converted to Perigee
258  // This is needed for VKalVrtCore engine.
259  //
260 
261  for (i_pbase = InpTrk.begin(); i_pbase != InpTrk.end(); ++i_pbase) {
262  const Trk::NeutralParameters* neuparO = (*i_pbase);
263  if(neuparO == nullptr) return StatusCode::FAILURE;
264  const Trk::NeutralParameters* neuparN = m_fitPropagator->myExtrapNeutral(neuparO, &refGVertex);
265  mPerN = dynamic_cast<const Trk::NeutralPerigee*>(neuparN);
266  if(mPerN == nullptr) {
267  delete neuparN;
268  return StatusCode::FAILURE;
269  }
270 
271  VectPerig = mPerN->parameters();
272  // Global position of perigee point
273  perGlobalPos = mPerN->position();
274  // Global position of reference point
275  perGlobalVrt = mPerN->associatedSurface().center();
276  // VK no good covariance matrix!
277  if( !convertAmg5SymMtx(mPerN->covariance(), CovVertTrk) ) return StatusCode::FAILURE;
278  delete neuparN;
279 
280  state.m_refFrameX = state.m_refFrameY = state.m_refFrameZ = 0.;
281  // restore ATLAS frame for safety
282  state.m_fitField.setAtlasMagRefFrame( 0., 0., 0.);
283  // Magnetic field at perigee point
284  state.m_fitField.getMagFld(perGlobalPos.x(), perGlobalPos.y(), perGlobalPos.z(),
285  fx, fy, BMAG_FIXED);
286  if(std::abs(BMAG_FIXED) < 0.01) BMAG_FIXED = 0.01;
287 
288  VKalTransform(BMAG_FIXED,
289  (double)VectPerig[0], (double)VectPerig[1],
290  (double)VectPerig[2], (double)VectPerig[3],
291  (double)VectPerig[4], CovVertTrk,
292  state.m_ich[ntrk], &state.m_apar[ntrk][0],
293  &state.m_awgt[ntrk][0]);
294 
295  state.m_ich[ntrk]=0;
296  if(state.m_apar[ntrk][4]<0){
297  // Charge=0 is always equal to Charge=+1
298  state.m_apar[ntrk][4] = -state.m_apar[ntrk][4];
299  state.m_awgt[ntrk][10] = -state.m_awgt[ntrk][10];
300  state.m_awgt[ntrk][11] = -state.m_awgt[ntrk][11];
301  state.m_awgt[ntrk][12] = -state.m_awgt[ntrk][12];
302  state.m_awgt[ntrk][13] = -state.m_awgt[ntrk][13];
303  }
304  ntrk++;
305  if(ntrk>=NTrMaxVFit) return StatusCode::FAILURE;
306  }
307 
308  //-------------- Finally setting new reference frame common for ALL tracks
309  state.m_refFrameX = tmp_refFrameX;
310  state.m_refFrameY = tmp_refFrameY;
311  state.m_refFrameZ = tmp_refFrameZ;
313 
314  return StatusCode::SUCCESS;
315  }
316 
317 } // end of namespace bracket
Trk::TrkVKalVrtFitter::State
Definition: TrkVKalVrtFitter.h:382
Trk::TrkVKalVrtFitter::State::m_globalFirstHit
const TrackParameters * m_globalFirstHit
Definition: TrkVKalVrtFitter.h:406
Trk::TrkVKalVrtFitter::CvtNeutralParameters
StatusCode CvtNeutralParameters(const std::vector< const NeutralParameters * > &InpTrk, int &ntrk, State &state) const
Definition: CvtParametersBase.cxx:179
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::m_InDetExtrapolator
const IExtrapolator * m_InDetExtrapolator
Pointer to Extrapolator AlgTool.
Definition: TrkVKalVrtFitter.h:470
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::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::TrkVKalVrtFitter::CvtTrackParameters
StatusCode CvtTrackParameters(const std::vector< const TrackParameters * > &InpTrk, int &ntrk, State &state) const
Definition: CvtParametersBase.cxx:24
Trk::TrkVKalVrtFitter::TrkMatControl::prtMass
double prtMass
Definition: TrkVKalVrtFitter.h:365
Trk::TrkVKalVrtFitter::TrkMatControl::extrapolationType
int extrapolationType
Definition: TrkVKalVrtFitter.h:362
Trk::TrkVKalVrtFitter::m_fitPropagator
VKalExtPropagator * m_fitPropagator
Definition: TrkVKalVrtFitter.h:469
Trk::VKalAtlasMagFld::getMagFld
virtual void getMagFld(const double, const double, const double, double &, double &, double &) override
Definition: VKalAtlasMagFld.cxx:61
Trk::VKalExtPropagator::myExtrapWithMatUpdate
const TrackParameters * myExtrapWithMatUpdate(long int TrkID, const TrackParameters *inpPer, Amg::Vector3D *endPoint, const IVKalState &istate) const
Definition: VKalExtPropagator.cxx:198
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::ParametersT::associatedSurface
virtual const S & associatedSurface() const override final
Access to the Surface method.
Trk::TrkVKalVrtFitter::m_IDsizeR
SimpleProperty< double > m_IDsizeR
Definition: TrkVKalVrtFitter.h:326
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
Trk::ParametersBase
Definition: ParametersBase.h:55
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::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::VKalExtPropagator::myExtrapNeutral
const NeutralParameters * myExtrapNeutral(const NeutralParameters *inpPer, Amg::Vector3D *endPoint) const
Definition: VKalExtPropagator.cxx:416
Trk::TrkVKalVrtFitter::State::m_refFrameY
double m_refFrameY
Definition: TrkVKalVrtFitter.h:389
Trk::NTrMaxVFit
@ NTrMaxVFit
Definition: TrkVKalVrtFitter.h:35
test_pyathena.counter
counter
Definition: test_pyathena.py:15
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Trk::TrkVKalVrtFitter::m_firstMeasuredPoint
SimpleProperty< bool > m_firstMeasuredPoint
Definition: TrkVKalVrtFitter.h:339
Trk::TrkVKalVrtFitter::State::m_apar
double m_apar[NTrMaxVFit][5]
Definition: TrkVKalVrtFitter.h:396