ATLAS Offline Software
VKalVrtFitSvc.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 // Header include
8 #include "TrkVKalVrtCore/CFit.h"
10 #include "TrkVKalVrtCore/cfPEst.h"
11 //-------------------------------------------------
12 // Other stuff
13 #include "GaudiKernel/IChronoStatSvc.h"
14 //
15 #include <algorithm>
16 #include <cmath>
17 
18  namespace Trk {
19 
20 //__________________________________________________________________________
21 //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
22 // Interface
23 //
24 
25  StatusCode TrkVKalVrtFitter::VKalVrtFit(const std::vector<const Perigee*>& InpPerigee,
27  TLorentzVector& Momentum,
28  long int& Charge,
29  dvect& ErrorMatrix,
30  dvect& Chi2PerTrk,
31  std::vector< std::vector<double> >& TrkAtVrt,
32  double& Chi2,
33  IVKalState& istate,
34  bool ifCovV0 /*= false*/) const
35 {
36  assert(dynamic_cast<State*> (&istate)!=nullptr);
37  State& state = static_cast<State&> (istate);
38 //
39 //------ extract information about selected tracks
40 //
41 
42  int ntrk=0;
43  StatusCode sc = CvtPerigee(InpPerigee, ntrk, state);
44  if(sc.isFailure())return StatusCode::FAILURE;
45 
46  int ierr = VKalVrtFit3( ntrk, Vertex, Momentum, Charge, ErrorMatrix,
47  Chi2PerTrk, TrkAtVrt,Chi2, state, ifCovV0 ) ;
48  if (ierr) return StatusCode::FAILURE;
49  return StatusCode::SUCCESS;
50 }
51 
52 
53 
54 StatusCode TrkVKalVrtFitter::VKalVrtFit(const std::vector<const xAOD::TrackParticle*> & InpTrkC,
55  const std::vector<const xAOD::NeutralParticle*> & InpTrkN,
57  TLorentzVector& Momentum,
58  long int& Charge,
59  dvect& ErrorMatrix,
60  dvect& Chi2PerTrk,
61  std::vector< std::vector<double> >& TrkAtVrt,
62  double& Chi2,
63  IVKalState& istate,
64  bool ifCovV0 /*= false*/) const
65 {
66  assert(dynamic_cast<State*> (&istate)!=nullptr);
67  State& state = static_cast<State&> (istate);
68 
69 //
70 //------ extract information about selected tracks
71 //
72  int ntrk=0;
73 
74  // The tmpInputC will be not owning just holding plain ptr
75  // the ownership is handled via the TParamOwner
76  // and is unique_ptr so we do not leak
77  std::vector<const TrackParameters*> tmpInputC(0);
78  std::vector<std::unique_ptr<const TrackParameters>> TParamOwner(0);
79  StatusCode sc;
80  double closestHitR=1.e6; //VK needed for FirstMeasuredPointLimit if this hit itself is absent
81  if(m_firstMeasuredPoint){ //First measured point strategy
82  //------
83  if(!InpTrkC.empty()){
84  if( m_InDetExtrapolator == nullptr ){
85  if(msgLvl(MSG::WARNING))msg()<< "No InDet extrapolator given."<<
86  "Can't use FirstMeasuredPoint with xAOD::TrackParticle!!!" << endmsg;
87  return StatusCode::FAILURE;
88  }
89  std::vector<const xAOD::TrackParticle*>::const_iterator i_ntrk;
90  if(msgLvl(MSG::DEBUG))msg()<< "Start FirstMeasuredPoint handling"<<'\n';
91  unsigned int indexFMP;
92  for (i_ntrk = InpTrkC.begin(); i_ntrk < InpTrkC.end(); ++i_ntrk) {
93  if ((*i_ntrk)->indexOfParameterAtPosition(indexFMP, xAOD::FirstMeasurement)){
94  if(msgLvl(MSG::DEBUG))msg()<< "FirstMeasuredPoint on track is discovered. Use it."<<'\n';
95  // create parameters
96  TParamOwner.emplace_back(std::make_unique<CurvilinearParameters>(
97  (*i_ntrk)->curvilinearParameters(indexFMP)));
98  //For the last one we created, push also a not owning / view ptr to tmpInputC
99  tmpInputC.push_back((TParamOwner.back()).get());
100  }else{
101  if(msgLvl(MSG::DEBUG)){
102  msg()<< "FirstMeasuredPoint on track is absent."<<
103  "Try extrapolation from Perigee to FisrtMeasuredPoint radius"<<endmsg;
104  }
105 
106  TParamOwner.emplace_back(m_fitPropagator->myxAODFstPntOnTrk((*i_ntrk)));
107  //For the last one we created, push also a not owning / view ptr to tmpInputC
108  tmpInputC.push_back((TParamOwner.back()).get());
109 
110  if( (*i_ntrk)->radiusOfFirstHit() < closestHitR ) {
111  closestHitR=(*i_ntrk)->radiusOfFirstHit();
112  }
113  if(tmpInputC[tmpInputC.size()-1]==nullptr){
114  //Extrapolation failure
115  if(msgLvl(MSG::WARNING)){
116  msg()<< "InDetExtrapolator can't etrapolate xAOD::TrackParticle Perigee "<<
117  "to FirstMeasuredPoint radius! Stop vertex fit!" << endmsg;
118  }
119  return StatusCode::FAILURE;
120  }
121  }
122  }
123  sc=CvtTrackParameters(tmpInputC,ntrk,state);
124  if(sc.isFailure()){
125  return StatusCode::FAILURE;
126  }
127  }
128  }else{
129  if(!InpTrkC.empty()) {
130  sc=CvtTrackParticle(InpTrkC,ntrk,state);
131  }
132  }
133  if(sc.isFailure())return StatusCode::FAILURE;
134  if(!InpTrkN.empty()){sc=CvtNeutralParticle(InpTrkN,ntrk,state); if(sc.isFailure())return StatusCode::FAILURE;}
135  //--
136  int ierr = VKalVrtFit3( ntrk, Vertex, Momentum, Charge, ErrorMatrix, Chi2PerTrk, TrkAtVrt, Chi2, state, ifCovV0 ) ;
137  if (ierr) return StatusCode::FAILURE;
138  //
139  //-- Check vertex position with respect to first measured hit and refit with plane constraint if needed
140  state.m_planeCnstNDOF = 0;
141  if(m_firstMeasuredPointLimit && !ierr){
142  Amg::Vector3D cnstRefPoint(0.,0.,0.);
143  //----------- Use as reference either hit(state.m_globalFirstHit) or its radius(closestHitR) if hit is absent
144  if(state.m_globalFirstHit)cnstRefPoint=state.m_globalFirstHit->position();
145  else if(closestHitR < 1.e6){
146  Amg::Vector3D unitMom=Amg::Vector3D(Momentum.Vect().Unit().x(),Momentum.Vect().Unit().y(),Momentum.Vect().Unit().z());
147  if((Vertex+unitMom).perp() < Vertex.perp()) unitMom=-unitMom;
148  cnstRefPoint=Vertex+(closestHitR-Vertex.perp())*unitMom;
149  }
150  //------------
151  if(Vertex.perp()>cnstRefPoint.perp() && cnstRefPoint.perp()>0.){
152  if(msgLvl(MSG::DEBUG))msg(MSG::DEBUG)<<"Vertex behind first measured point is detected. Constraint is applied!"<<endmsg;
153  state.m_planeCnstNDOF = 1; // Additional NDOF due to plane constraint
154  double pp[3]={Momentum.Px()/Momentum.Rho(),Momentum.Py()/Momentum.Rho(),Momentum.Pz()/Momentum.Rho()};
155  double D= pp[0]*(cnstRefPoint.x()-state.m_refFrameX)
156  +pp[1]*(cnstRefPoint.y()-state.m_refFrameY)
157  +pp[2]*(cnstRefPoint.z()-state.m_refFrameZ);
158  state.m_vkalFitControl.setUsePlaneCnst( pp[0], pp[1], pp[2], D);
159  std::vector<double> saveApproxV(3,0.); state.m_ApproximateVertex.swap(saveApproxV);
160  state.m_ApproximateVertex[0]=cnstRefPoint.x();
161  state.m_ApproximateVertex[1]=cnstRefPoint.y();
162  state.m_ApproximateVertex[2]=cnstRefPoint.z();
163  ierr = VKalVrtFit3( ntrk, Vertex, Momentum, Charge, ErrorMatrix, Chi2PerTrk, TrkAtVrt, Chi2, state, ifCovV0 );
164  state.m_vkalFitControl.setUsePlaneCnst(0.,0.,0.,0.);
165  if (ierr) { // refit without plane cnst
166  ierr = VKalVrtFit3(ntrk,Vertex,Momentum,Charge,ErrorMatrix,Chi2PerTrk,TrkAtVrt,Chi2, state, ifCovV0); // if fit with it failed
167  state.m_planeCnstNDOF = 0;
168  }
169  state.m_ApproximateVertex.swap(saveApproxV);
170  }
171  }
172  //--
173  if (ierr) return StatusCode::FAILURE;
174  return StatusCode::SUCCESS;
175 }
176 
177 
178 StatusCode TrkVKalVrtFitter::VKalVrtFit(const std::vector<const TrackParameters*> & InpTrkC,
179  const std::vector<const NeutralParameters*> & InpTrkN,
181  TLorentzVector& Momentum,
182  long int& Charge,
183  dvect& ErrorMatrix,
184  dvect& Chi2PerTrk,
185  std::vector< std::vector<double> >& TrkAtVrt,
186  double& Chi2,
187  IVKalState& istate,
188  bool ifCovV0 /*= false*/) const
189 {
190  assert(dynamic_cast<State*> (&istate)!=nullptr);
191  State& state = static_cast<State&> (istate);
192 
193 //
194 //------ extract information about selected tracks
195 //
196  int ntrk=0;
197  StatusCode sc;
198  if(!InpTrkC.empty()){
199  sc=CvtTrackParameters(InpTrkC,ntrk,state);
200  if(sc.isFailure())return StatusCode::FAILURE;
201  }
202  if(!InpTrkN.empty()){
203  sc=CvtNeutralParameters(InpTrkN,ntrk,state);
204  if(sc.isFailure())return StatusCode::FAILURE;
205  }
206 
207  if(state.m_ApproximateVertex.empty() && state.m_globalFirstHit){ //Initial guess if absent
208  state.m_ApproximateVertex.reserve(3);
209  state.m_ApproximateVertex.push_back(state.m_globalFirstHit->position().x());
210  state.m_ApproximateVertex.push_back(state.m_globalFirstHit->position().y());
211  state.m_ApproximateVertex.push_back(state.m_globalFirstHit->position().z());
212  }
213  int ierr = VKalVrtFit3( ntrk, Vertex, Momentum, Charge, ErrorMatrix, Chi2PerTrk, TrkAtVrt,Chi2, state, ifCovV0 ) ;
214  if (ierr) return StatusCode::FAILURE;
215 //
216 //-- Check vertex position with respect to first measured hit and refit with plane constraint if needed
217  state.m_planeCnstNDOF = 0;
218  if(state.m_globalFirstHit && m_firstMeasuredPointLimit && !ierr){
219  if(Vertex.perp()>state.m_globalFirstHit->position().perp()){
220  if(msgLvl(MSG::DEBUG))msg(MSG::DEBUG)<<"Vertex behind first measured point is detected. Constraint is applied!"<<endmsg;
221  state.m_planeCnstNDOF = 1; // Additional NDOF due to plane constraint
222  double pp[3]={Momentum.Px()/Momentum.Rho(),Momentum.Py()/Momentum.Rho(),Momentum.Pz()/Momentum.Rho()};
223  double D= pp[0]*(state.m_globalFirstHit->position().x()-state.m_refFrameX)
224  +pp[1]*(state.m_globalFirstHit->position().y()-state.m_refFrameY)
225  +pp[2]*(state.m_globalFirstHit->position().z()-state.m_refFrameZ);
226  state.m_vkalFitControl.setUsePlaneCnst( pp[0], pp[1], pp[2], D);
227  std::vector<double> saveApproxV(3,0.); state.m_ApproximateVertex.swap(saveApproxV);
228  state.m_ApproximateVertex[0]=state.m_globalFirstHit->position().x();
229  state.m_ApproximateVertex[1]=state.m_globalFirstHit->position().y();
230  state.m_ApproximateVertex[2]=state.m_globalFirstHit->position().z();
231  ierr = VKalVrtFit3( ntrk, Vertex, Momentum, Charge, ErrorMatrix, Chi2PerTrk, TrkAtVrt,Chi2, state, ifCovV0 ) ;
232  state.m_vkalFitControl.setUsePlaneCnst(0.,0.,0.,0.);
233  if (ierr) { // refit without plane cnst
234  ierr = VKalVrtFit3(ntrk,Vertex,Momentum,Charge,ErrorMatrix,Chi2PerTrk,TrkAtVrt,Chi2, state, ifCovV0 ) ; // if fit with it failed
235  state.m_planeCnstNDOF = 0;
236  }
237  state.m_ApproximateVertex.swap(saveApproxV);
238  }
239  }
240  if (ierr) return StatusCode::FAILURE;
241  return StatusCode::SUCCESS;
242 }
243 
244 
245 
246 
247 
248 
249 //--------------------------------------------------------------------------------------------------
250 // Main code
251 //
254  TLorentzVector& Momentum,
255  long int& Charge,
257  dvect& Chi2PerTrk,
258  std::vector< std::vector<double> >& TrkAtVrt,
259  double& Chi2,
260  State& state,
261  bool ifCovV0) const
262 {
263 //
264 //------ Variables and arrays needed for fitting kernel
265 //
266  int ierr,i;
267  double xyz0[3],covf[21],chi2f=-10.;
268  double ptot[4]={0.};
269  double xyzfit[3]={0.};
270 //
271 //--- Set field value at (0.,0.,0.) - some safety
272 //
273  double Bx,By,Bz;
274  state.m_fitField.getMagFld(-state.m_refFrameX,-state.m_refFrameY,-state.m_refFrameZ,Bx,By,Bz);
275 //
276 //------ Fit option setting
277 //
278  VKalVrtConfigureFitterCore(ntrk, state);
279 //
280 //------ Fit itself
281 //
282  state.m_FitStatus=0;
283  state.m_vkalFitControl.renewFullCovariance(nullptr); //
284  state.m_vkalFitControl.setVertexMass(-1.);
286  if(state.m_ApproximateVertex.size()==3 && fabs(state.m_ApproximateVertex[2])<m_IDsizeZ &&
288  {
289  xyz0[0]=(double)state.m_ApproximateVertex[0] - state.m_refFrameX;
290  xyz0[1]=(double)state.m_ApproximateVertex[1] - state.m_refFrameY;
291  xyz0[2]=(double)state.m_ApproximateVertex[2] - state.m_refFrameZ;
292  } else {
293  xyz0[0]=xyz0[1]=xyz0[2]=0.;
294  }
295  double par0[NTrMaxVFit][3]; //used only for fit preparation
296  Trk::cfpest( ntrk, xyz0, state.m_ich, state.m_apar, par0);
297 
298  Chi2PerTrk.resize (ntrk);
299  ierr=Trk::CFit( &state.m_vkalFitControl, ifCovV0, ntrk, state.m_ich, xyz0, par0, state.m_apar, state.m_awgt,
300  xyzfit, state.m_parfs, ptot, covf, chi2f,
301  Chi2PerTrk.data());
302 
303  if(msgLvl(MSG::DEBUG))msg(MSG::DEBUG) << "VKalVrt fit status="<<ierr<<" Chi2="<<chi2f<<endmsg;
304 
305  Chi2 = 100000000.;
306  if(ierr){
307  return ierr;
308  }
309  if(ptot[0]*ptot[0]+ptot[1]*ptot[1] == 0.) return -5; // Bad (divergent) fit
310 //
311 // Postfit operation. Creation of array for different error calculations and full error matrix copy
312 //
313  state.m_FitStatus=ntrk;
314  if(ifCovV0 && state.m_vkalFitControl.getFullCovariance()){ //If full fit error matrix is returned by VKalVrtCORE
315  int SymCovMtxSize=(3*ntrk+3)*(3*ntrk+4)/2;
316  state.m_ErrMtx.assign (state.m_vkalFitControl.getFullCovariance(),
317  state.m_vkalFitControl.getFullCovariance()+SymCovMtxSize);
318  state.m_vkalFitControl.renewFullCovariance(nullptr);
319  ErrorMatrix.clear(); ErrorMatrix.reserve(21); ErrorMatrix.assign(covf,covf+21);
320  } else {
321  ErrorMatrix.clear(); ErrorMatrix.reserve(6); ErrorMatrix.assign(covf,covf+6);
322  }
323 //---------------------------------------------------------------------------
324  Momentum.SetPxPyPzE( ptot[0], ptot[1], ptot[2], ptot[3] );
325  Chi2 = (double) chi2f;
326 
327  Vertex[0]= xyzfit[0] + state.m_refFrameX;
328  Vertex[1]= xyzfit[1] + state.m_refFrameY;
329  Vertex[2]= xyzfit[2] + state.m_refFrameZ;
330 
331  if(Vertex.perp()>m_IDsizeR || std::abs(Vertex.z())>m_IDsizeZ)return -5; // Solution outside acceptable volume due to divergence
332 
333  state.m_save_xyzfit[0]=xyzfit[0]; // saving of vertex position
334  state.m_save_xyzfit[1]=xyzfit[1]; // for full error matrix
335  state.m_save_xyzfit[2]=xyzfit[2];
336 //
337 // ------ Magnetic field in fitted vertex
338 //
339  double fx,fy,BMAG_CUR;
340  state.m_fitField.getMagFld(xyzfit[0] ,xyzfit[1] ,xyzfit[2] ,fx,fy,BMAG_CUR);
341  if(fabs(BMAG_CUR) < 0.01) BMAG_CUR=0.01; // Safety
342 
343  Charge=0; for(i=0; i<ntrk; i++){Charge+=state.m_ich[i];};
344  Charge=-Charge; //VK 30.11.2009 Change sign acoording to ATLAS
345 
346 
347  TrkAtVrt.clear(); TrkAtVrt.reserve(ntrk);
348  for(i=0; i<ntrk; i++){
349  std::vector<double> TrkPar(3);
350  VKalToTrkTrack(BMAG_CUR,(double)state.m_parfs[i][0],(double)state.m_parfs[i][1],(double) state.m_parfs[i][2],
351  TrkPar[0],TrkPar[1],TrkPar[2]);
352  TrkPar[2] = -TrkPar[2]; // Change of sign needed
353  TrkAtVrt.push_back( TrkPar );
354  }
355  return 0;
356  }
357 
358 
359 
360 // Converts Vertex, Mom, CovVrtMom in GLOBAL SYSTEM into perigee
361 //
362 //
363 
365  const TLorentzVector& Momentum,
366  const dvect& CovVrtMom,
367  const long int& Charge,
368  dvect& Perigee,
369  dvect& CovPerigee,
370  IVKalState& istate) const
371  {
372  assert(dynamic_cast<State*> (&istate)!=nullptr);
373  State& state = static_cast<State&> (istate);
374  int i,j,ij;
375  double Vrt[3],PMom[4],Cov0[21],Per[5],CovPer[15];
376 
377  for(i=0; i<3; i++) Vrt[i]=Vertex[i];
378  for(i=0; i<3; i++) PMom[i]=Momentum[i];
379  for(ij=i=0; i<6; i++){
380  for(j=0; j<=i; j++){
381  Cov0[ij]=CovVrtMom[ij];
382  ij++;
383  }
384  }
385  state.m_refFrameX=state.m_refFrameY=state.m_refFrameZ=0.; //VK Work in ATLAS ref frame ONLY!!!
386  long int vkCharge=-Charge; //VK 30.11.2009 Change sign according to ATLAS
387 //
388 // ------ Magnetic field in vertex
389 //
390  double fx,fy,BMAG_CUR;
391  state.m_fitField.getMagFld(Vrt[0], Vrt[1], Vrt[2] ,fx,fy,BMAG_CUR);
392  if(fabs(BMAG_CUR) < 0.01) BMAG_CUR=0.01; // Safety
393 
394  Trk::xyztrp( vkCharge, Vrt, PMom, Cov0, BMAG_CUR, Per, CovPer );
395 
396  Perigee.clear();
397  CovPerigee.clear();
398 
399  for(i=0; i<5; i++) Perigee.push_back((double)Per[i]);
400  for(i=0; i<15; i++) CovPerigee.push_back((double)CovPer[i]);
401 
402  return StatusCode::SUCCESS;
403  }
404 
405 
406  void TrkVKalVrtFitter::VKalToTrkTrack( double curBMAG, double vp1, double vp2, double vp3,
407  double& tp1, double& tp2, double& tp3) const
408 //tp - ATLAS parameters, vp - VKalVrt parameters//
409  { tp1= vp2; //phi angle
410  tp2= vp1; //theta angle
411  tp3= vp3 * std::sin( vp1 ) /(m_CNVMAG*curBMAG);
412  constexpr double pi = M_PI;
413  // -pi < phi < pi range
414  while ( tp1 > pi) tp1 -= 2.*pi;
415  while ( tp1 <-pi) tp1 += 2.*pi;
416  // 0 < Theta < pi range
417  while ( tp2 > pi) tp2 -= 2.*pi;
418  while ( tp2 <-pi) tp2 += 2.*pi;
419  if ( tp2 < 0.) {
420  tp2 = fabs(tp2); tp1 += pi;
421  while ( tp1 > pi) tp1 -= 2.*pi;
422  }
423 
424  }
425 
426 
427 /* Returns a complete error matrix after fit
428  useMom=0 def (V,Perigee1,Perigee2....PerigeeNTrk)
429  useMom=1 (V,PxPyPz1,PxPyPz2....PxPyPzNTrk)
430 */
431 
432 
433  StatusCode
434  TrkVKalVrtFitter::VKalGetFullCov( long int NTrk, dvect& CovVrtTrk,
435  IVKalState& istate,
436  bool useMom) const
437  {
438  assert(dynamic_cast<State*> (&istate)!=nullptr);
439  State& state = static_cast<State&> (istate);
440  if(!state.m_FitStatus) return StatusCode::FAILURE;
441  if(NTrk<1) return StatusCode::FAILURE;
442  if(NTrk>NTrMaxVFit) return StatusCode::FAILURE;
443  if(state.m_ErrMtx.empty()) return StatusCode::FAILURE; //Now error matrix is taken from CORE in VKalVrtFit3.
444 //
445 // ------ Magnetic field access
446 //
447  double fx,fy,BMAG_CUR;
448  state.m_fitField.getMagFld(state.m_save_xyzfit[0],state.m_save_xyzfit[1],state.m_save_xyzfit[2],fx,fy,BMAG_CUR);
449  if(fabs(BMAG_CUR) < 0.01) BMAG_CUR=0.01; // Safety
450 //
451 // ------ Base code
452 //
453  int i,j,ik,jk,ip,iTrk;
454  int DIM=3*NTrk+3; //Current size of full covariance matrix
455  std::vector<std::vector<double> > Deriv (DIM);
456  for (std::vector<double>& v : Deriv) v.resize (DIM);
457  std::vector<double> CovMtxOld(DIM*DIM);
458 
459 
460  CovVrtTrk.resize(DIM*(DIM+1)/2);
461 
462  ip=0;
463  for( i=0; i<DIM;i++) {
464  for( j=0; j<=i; j++) {
465  CovMtxOld[i*DIM+j]=CovMtxOld[j*DIM+i]=state.m_ErrMtx[ip++];
466  }
467  }
468 
469  //delete [] ErrMtx;
470 
471  for(i=0;i<DIM;i++){ for(j=0;j<DIM;j++) {Deriv[i][j]=0.;}}
472  Deriv[0][0]= 1.;
473  Deriv[1][1]= 1.;
474  Deriv[2][2]= 1.;
475 
476  int iSt=0;
477  double Theta,invR,Phi;
478  for( iTrk=0; iTrk<NTrk; iTrk++){
479  Theta=state.m_parfs[iTrk][0];
480  Phi =state.m_parfs[iTrk][1];
481  invR =state.m_parfs[iTrk][2];
482  /*-----------*/
483  /* dNew/dOld */
484  iSt = 3 + iTrk*3;
485  if( !useMom ){
486  Deriv[iSt ][iSt+1] = 1; // Phi <-> Theta
487  Deriv[iSt+1][iSt ] = 1; // Phi <-> Theta
488  Deriv[iSt+2][iSt ] = -(cos(Theta)/(m_CNVMAG*BMAG_CUR)) * invR ; // d1/p / dTheta
489  Deriv[iSt+2][iSt+2] = -(sin(Theta)/(m_CNVMAG*BMAG_CUR)) ; // d1/p / d1/R
490  }else{
491  double pt=(m_CNVMAG*BMAG_CUR)/fabs(invR);
492  double px=pt*cos(Phi);
493  double py=pt*sin(Phi);
494  double pz=pt/tan(Theta);
495  Deriv[iSt ][iSt ]= 0; //dPx/dTheta
496  Deriv[iSt ][iSt+1]= -py; //dPx/dPhi
497  Deriv[iSt ][iSt+2]= -px/invR; //dPx/dinvR
498 
499  Deriv[iSt+1][iSt ]= 0; //dPy/dTheta
500  Deriv[iSt+1][iSt+1]= px; //dPy/dPhi
501  Deriv[iSt+1][iSt+2]= -py/invR; //dPy/dinvR
502 
503  Deriv[iSt+2][iSt ]= -pt/sin(Theta)/sin(Theta); //dPz/dTheta
504  Deriv[iSt+2][iSt+1]= 0; //dPz/dPhi
505  Deriv[iSt+2][iSt+2]= -pz/invR; //dPz/dinvR
506  }
507  }
508 //---------- Only upper half if filled and saved
509  int ipnt=0;
510  double tmp, tmpTmp;
511  for(i=0;i<DIM;i++){
512  for(j=0;j<=i;j++){
513  tmp=0.;
514  for(ik=0;ik<DIM;ik++){
515  if(Deriv[i][ik] == 0.) continue;
516  tmpTmp=0;
517  for(jk=DIM-1;jk>=0;jk--){
518  if(Deriv[j][jk] == 0.) continue;
519  tmpTmp += CovMtxOld[ik*DIM+jk]*Deriv[j][jk];
520  }
521  tmp += Deriv[i][ik]*tmpTmp;
522  }
523  CovVrtTrk[ipnt++]=tmp;
524  }}
525 
526  return StatusCode::SUCCESS;
527 
528  }
529 
530 
531 
532 
533 
534  StatusCode TrkVKalVrtFitter::VKalGetMassError( double& dM, double& MassError,
535  const IVKalState& istate) const
536  {
537  assert(dynamic_cast<const State*> (&istate)!=nullptr);
538  const State& state = static_cast<const State&> (istate);
539  if(!state.m_FitStatus) return StatusCode::FAILURE;
540  dM = state.m_vkalFitControl.getVertexMass();
541  MassError = state.m_vkalFitControl.getVrtMassError();
542  return StatusCode::SUCCESS;
543  }
544 
545 
547  const IVKalState& istate) const
548  {
549  assert(dynamic_cast<const State*> (&istate)!=nullptr);
550  const State& state = static_cast<const State&> (istate);
551  if(!state.m_FitStatus) return StatusCode::FAILURE; // no fit made
552  trkWeights.clear();
553 
554  int NTRK=state.m_FitStatus;
555 
556  for (int i=0; i<NTRK; i++) trkWeights.push_back(state.m_vkalFitControl.vk_forcft.robres[i]);
557 
558  return StatusCode::SUCCESS;
559  }
560 
561 
563  {
564  if(!state.m_FitStatus) return 0;
565  int NDOF=2*state.m_FitStatus-3;
566  if(state.m_usePointingCnst) { NDOF+=2; }
567  else if(state.m_useZPointingCnst) { NDOF+=1; }
568  if( state.m_usePassNear || state.m_usePassWithTrkErr ) { NDOF+= 2; }
569 
570  if( state.m_massForConstraint>0. ) { NDOF+=1; }
571  if( !state.m_partMassCnst.empty() ) { NDOF+= state.m_partMassCnst.size(); }
572  if( state.m_useAprioriVertex ) { NDOF+= 3; }
573  if( state.m_usePhiCnst ) { NDOF+=1; }
574  if( state.m_useThetaCnst ) { NDOF+=1; }
575  return NDOF;
576  }
577 
578 }
Trk::TrkVKalVrtFitter::State
Definition: TrkVKalVrtFitter.h:382
Trk::TrkVKalVrtFitter::VKalVrtFit
virtual StatusCode VKalVrtFit(const std::vector< const xAOD::TrackParticle * > &, const std::vector< const xAOD::NeutralParticle * > &, Amg::Vector3D &Vertex, TLorentzVector &Momentum, long int &Charge, dvect &ErrorMatrix, dvect &Chi2PerTrk, std::vector< std::vector< double >> &TrkAtVrt, double &Chi2, IVKalState &istate, bool ifCovV0=false) const override final
Trk::Vertex
Definition: Tracking/TrkEvent/VxVertex/VxVertex/Vertex.h:26
Trk::py
@ py
Definition: ParamDefs.h:60
Trk::TrkVKalVrtFitter::CvtNeutralParameters
StatusCode CvtNeutralParameters(const std::vector< const NeutralParameters * > &InpTrk, int &ntrk, State &state) const
Definition: CvtParametersBase.cxx:179
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_useZPointingCnst
bool m_useZPointingCnst
Definition: TrkVKalVrtFitter.h:426
Trk::VKContraintType::Theta
@ Theta
Trk::TrkVKalVrtFitter::State::m_refFrameZ
double m_refFrameZ
Definition: TrkVKalVrtFitter.h:390
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition: Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
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
perp
Scalar perp() const
perp method - perpenticular length
Definition: AmgMatrixBasePlugin.h:44
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::CvtTrackParameters
StatusCode CvtTrackParameters(const std::vector< const TrackParameters * > &InpTrk, int &ntrk, State &state) const
Definition: CvtParametersBase.cxx:24
test_pyathena.pt
pt
Definition: test_pyathena.py:11
Trk::VKalVrtControl::setVrtMassError
void setVrtMassError(double error)
Definition: TrkVKalVrtCore.h:76
Trk::VKalVrtControl::getVrtMassError
double getVrtMassError() const
Definition: TrkVKalVrtCore.h:78
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::TrkVKalVrtFitter::m_fitPropagator
VKalExtPropagator * m_fitPropagator
Definition: TrkVKalVrtFitter.h:469
CFit.h
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
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
Phi
@ Phi
Definition: RPCdef.h:8
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Trk::pz
@ pz
global momentum (cartesian)
Definition: ParamDefs.h:61
Trk::TrkVKalVrtFitter::State::m_FitStatus
int m_FitStatus
Definition: TrkVKalVrtFitter.h:410
Trk::TrkVKalVrtFitter::VKalGetNDOF
static int VKalGetNDOF(const State &state)
Definition: VKalVrtFitSvc.cxx:562
Trk::TrkVKalVrtFitter::State::m_save_xyzfit
double m_save_xyzfit[3]
Definition: TrkVKalVrtFitter.h:408
Trk::TrkVKalVrtFitter::VKalGetFullCov
virtual StatusCode VKalGetFullCov(long int, dvect &CovMtx, IVKalState &istate, bool=false) const override final
Definition: VKalVrtFitSvc.cxx:434
Trk::TrkVKalVrtFitter::State::m_partMassCnst
std::vector< double > m_partMassCnst
Definition: TrkVKalVrtFitter.h:434
Trk::TrkVKalVrtFitter::State::m_vkalFitControl
VKalVrtControl m_vkalFitControl
Definition: TrkVKalVrtFitter.h:402
Trk::dvect
std::vector< double > dvect
Definition: TrkVKalVrtFitter.h:36
pi
#define pi
Definition: TileMuonFitter.cxx:65
TrkVKalVrtFitter.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Trk::ErrorMatrix
Definition: ErrorMatrixCnv_p1.h:25
Trk::TrkVKalVrtFitter::VKalGetMassError
virtual StatusCode VKalGetMassError(double &Mass, double &MassError, const IVKalState &istate) const override final
Definition: VKalVrtFitSvc.cxx:534
Trk::VKalExtPropagator::myxAODFstPntOnTrk
const Perigee * myxAODFstPntOnTrk(const xAOD::TrackParticle *xprt) const
Definition: VKalExtPropagator.cxx:433
Trk::VKalVrtControl::setVertexMass
void setVertexMass(double mass)
Definition: TrkVKalVrtCore.h:75
Trk::TrkVKalVrtFitter::m_CNVMAG
double m_CNVMAG
Definition: TrkVKalVrtFitter.h:466
Trk::TrkVKalVrtFitter::m_IDsizeR
SimpleProperty< double > m_IDsizeR
Definition: TrkVKalVrtFitter.h:326
Trk::TrkVKalVrtFitter::State::m_useThetaCnst
bool m_useThetaCnst
Definition: TrkVKalVrtFitter.h:423
Trk::xyztrp
void xyztrp(const long int ich, double *vrt0, double *pv0, double *covi, double BMAG, double *paro, double *errt)
Definition: XYZtrp.cxx:16
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAOD::FirstMeasurement
@ FirstMeasurement
Parameter defined at the position of the 1st measurement.
Definition: TrackingPrimitives.h:213
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
Trk::NTrMaxVFit
@ NTrMaxVFit
Definition: TrkVKalVrtFitter.h:35
MuonR4::State
CalibratedSpacePoint::State State
Definition: SpacePointCalibrator.cxx:24
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::px
@ px
Definition: ParamDefs.h:59
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
Trk::TrkVKalVrtFitter::State::m_useAprioriVertex
bool m_useAprioriVertex
Definition: TrkVKalVrtFitter.h:422
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
Trk::VKalVrtControl::renewFullCovariance
void renewFullCovariance(double *)
Definition: TrkVKalVrtCoreBase.cxx:311
Trk::cfpest
void cfpest(int ntrk, double *xyz, long int *ich, double(*parst)[5], double(*parf)[3])
Definition: cfPEst.cxx:10
dvect
std::vector< double > dvect
Definition: InDetVKalVxInJetTool.h:83
Trk::TrkVKalVrtFitter::State::m_usePhiCnst
bool m_usePhiCnst
Definition: TrkVKalVrtFitter.h:424
Trk::TrkVKalVrtFitter::m_firstMeasuredPointLimit
SimpleProperty< bool > m_firstMeasuredPointLimit
Definition: TrkVKalVrtFitter.h:340
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::VKalVrtControl::getFullCovariance
const double * getFullCovariance() const
Definition: TrkVKalVrtCore.h:73
Trk::TrkVKalVrtFitter::State::m_fitField
VKalAtlasMagFld m_fitField
Definition: TrkVKalVrtFitter.h:401
Trk::TrkVKalVrtFitter::State::m_usePassNear
bool m_usePassNear
Definition: TrkVKalVrtFitter.h:427
Trk::TrkVKalVrtFitter::State::m_ich
long int m_ich[NTrMaxVFit]
Definition: TrkVKalVrtFitter.h:398
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::TrkVKalVrtFitter::VKalGetTrkWeights
virtual StatusCode VKalGetTrkWeights(dvect &Weights, const IVKalState &istate) const override final
Definition: VKalVrtFitSvc.cxx:546
Trk::TrkVKalVrtFitter::VKalVrtFit3
int VKalVrtFit3(int ntrk, Amg::Vector3D &Vertex, TLorentzVector &Momentum, long int &Charge, dvect &ErrorMatrix, dvect &Chi2PerTrk, std::vector< std::vector< double >> &TrkAtVrt, double &Chi2, State &state, bool ifCovV0) const
Definition: VKalVrtFitSvc.cxx:252
Trk::TrkVKalVrtFitter::State::m_refFrameY
double m_refFrameY
Definition: TrkVKalVrtFitter.h:389
Trk::TrkVKalVrtFitter::State::m_usePassWithTrkErr
bool m_usePassWithTrkErr
Definition: TrkVKalVrtFitter.h:428
Trk::IVKalState
Definition: IVKalState.h:21
Trk::TrkVKalVrtFitter::State::m_parfs
double m_parfs[NTrMaxVFit][3]
Definition: TrkVKalVrtFitter.h:399
Trk::TrkVKalVrtFitter::State::m_ApproximateVertex
std::vector< double > m_ApproximateVertex
Definition: TrkVKalVrtFitter.h:420
Trk::VKalVrtControl::getVertexMass
double getVertexMass() const
Definition: TrkVKalVrtCore.h:77
DEBUG
#define DEBUG
Definition: page_access.h:11
Trk::TrkVKalVrtFitter::VKalVrtConfigureFitterCore
void VKalVrtConfigureFitterCore(int NTRK, State &state) const
Definition: SetFitOptions.cxx:17
XYZtrp.h
Trk::CFit
int CFit(VKalVrtControl *FitCONTROL, int ifCovV0, int NTRK, long int *ich, double xyz0[3], double(*par0)[3], double(*inp_Trk5)[5], double(*inp_CovTrk5)[15], double xyzfit[3], double(*parfs)[3], double ptot[4], double covf[21], double &chi2, double *chi2tr)
Definition: CFit.cxx:429
Trk::TrkVKalVrtFitter::State::m_massForConstraint
double m_massForConstraint
Definition: TrkVKalVrtFitter.h:433
Trk::TrkVKalVrtFitter::VKalVrtCvtTool
virtual StatusCode VKalVrtCvtTool(const Amg::Vector3D &Vertex, const TLorentzVector &Momentum, const dvect &CovVrtMom, const long int &Charge, dvect &Perigee, dvect &CovPerigee, IVKalState &istate) const override final
Definition: VKalVrtFitSvc.cxx:364
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Trk::TrkVKalVrtFitter::CvtTrackParticle
StatusCode CvtTrackParticle(std::span< const xAOD::TrackParticle *const > list, int &ntrk, State &state) const
Definition: CvtTrackParticle.cxx:27
cfPEst.h
Trk::VKalVrtControl::vk_forcft
ForCFT vk_forcft
Definition: TrkVKalVrtCore.h:91
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Trk::TrkVKalVrtFitter::m_firstMeasuredPoint
SimpleProperty< bool > m_firstMeasuredPoint
Definition: TrkVKalVrtFitter.h:339
Trk::ForCFT::robres
double robres[vkalNTrkM]
Definition: ForCFT.h:45
Trk::TrkVKalVrtFitter::State::m_usePointingCnst
bool m_usePointingCnst
Definition: TrkVKalVrtFitter.h:425
Trk::TrkVKalVrtFitter::State::m_apar
double m_apar[NTrMaxVFit][5]
Definition: TrkVKalVrtFitter.h:396
Trk::TrkVKalVrtFitter::State::m_ErrMtx
std::vector< double > m_ErrMtx
Definition: TrkVKalVrtFitter.h:417
Trk::v
@ v
Definition: ParamDefs.h:78