ATLAS Offline Software
cfTotCov.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 // Calculates COVF(21) - symmetric 6x6 covariance matrix
6 // for combined (X,Y,Z,Px,Py,Pz) vector after vertex fit
7 //
8 //-----------------------------------------------------
11 #include "TrkVKalVrtCore/VtCFitE.h"
15 #include <cmath>
16 
17 namespace Trk {
18 //
19 // Function calculates complete error matrix ADER and derivatives
20 // of fitted track parameters with respect to initial ones.
21 // It calculates also combined momentum and (VxVyVzPxPyPz) covarinace
22 // Complete error matrix is recalculated here via getFullVrtCov,
23 // so CPU CONSUMING!!!
24 //--------------------------------------------------------------
25 
26 int afterFit(VKVertex *vk, double *ader, double * dcv, double * ptot, double * VrtMomCov, const VKalVrtControlBase* CONTROL )
27 {
28  int i,j;
29  double px,py,pz,pt,invR,cth;
30  double verr[6][6]={{0.}}; //for (i=0; i<6*6; i++) verr[i]=0;
31 
32  int NTRK = vk->TrackList.size();
33  int NVar = NTRK*3+3;
34  for (i=1; i<=6; ++i) {
35  for (j=1; j<=NVar ; ++j) dcv[i + j*6 - 7] = 0.;
36  }
37  cfsetdiag( 6, VrtMomCov, 100.);
38  ptot[0] = 0.;
39  ptot[1] = 0.;
40  ptot[2] = 0.;
41  double constBF = Trk::vkalMagFld::getMagFld(vk->refIterV,CONTROL) * Trk::vkalMagFld::getCnvCst() ;
42 
43  for (i = 1; i <= NTRK; ++i) {
44  VKTrack *trk=vk->TrackList[i-1].get();
45  invR = trk->fitP[2];
46  cth = 1. / tan(trk->fitP[0]);
47  pt = constBF / std::abs(invR);
48  px = pt * cos(trk->fitP[1]);
49  py = pt * sin(trk->fitP[1]);
50  pz = pt * cth;
51  ptot[0] += px;
52  ptot[1] += py;
53  ptot[2] += pz;
54  dcv[ (i*3 + 0)*6 + 5] = -pt * (cth * cth + 1); /* dPz/d(theta) */
55  dcv[ (i*3 + 1)*6 + 3] = -py; /* dPx/d(phi) */
56  dcv[ (i*3 + 1)*6 + 4] = px; /* dPy/d(phi) */
57  dcv[ (i*3 + 2)*6 + 3] = -px / invR; /* dPx/d(rho) */
58  dcv[ (i*3 + 2)*6 + 4] = -py / invR; /* dPy/d(rho) */
59  dcv[ (i*3 + 2)*6 + 5] = -pz / invR; /* dPz/d(rho) */
60  }
61  dcv[0] = 1.;
62  dcv[7] = 1.;
63  dcv[14] = 1.;
64  if(!ader)return 0;
65  int IERR=getFullVrtCov(vk, ader, dcv, verr); if (IERR) return IERR;
66  int ijk = 0;
67  for ( i=0; i<6; ++i) {
68  for (j=0; j<=i; ++j) {
69  VrtMomCov[ijk++] = verr[i][j];
70  }
71  }
72  return 0;
73 }
74 
75 // The same as afterFit(), but instead of fitted track parameters
76 // it uses guessed track parameters. ( it's needed for cascade)
77 // Complete error matrix is recalculated here via getFullVrtCov,
78 // so CPU CONSUMING!!!
79 //--------------------------------------------------------------------------------------------------
80 int afterFitWithIniPar(VKVertex *vk, double *ader, double * dcv, double * ptot, double * VrtMomCov, const VKalVrtControlBase* CONTROL )
81 {
82  int i,j;
83  double px,py,pz,pt,invR,cth;
84  double verr[6][6]={{0.}};
85 
86 
87  int NTRK = vk->TrackList.size();
88  int NVar = NTRK*3+3;
89  for (i=1; i<=6; ++i) {
90  for (j=1; j<=NVar ; ++j) dcv[i + j*6 - 7] = 0.;
91  }
92  cfsetdiag( 6, VrtMomCov, 10.);
93  ptot[0] = 0.;
94  ptot[1] = 0.;
95  ptot[2] = 0.;
96  double constBF = Trk::vkalMagFld::getMagFld(vk->refIterV,CONTROL) * Trk::vkalMagFld::getCnvCst() ;
97 
98  for (i = 1; i <= NTRK; ++i) {
99  VKTrack *trk=vk->TrackList[i-1].get();
100  invR = trk->iniP[2];
101  cth = 1. / tan(trk->iniP[0]);
102  pt = constBF / std::abs(invR);
103  px = pt * cos(trk->iniP[1]);
104  py = pt * sin(trk->iniP[1]);
105  pz = pt * cth;
106  ptot[0] += px;
107  ptot[1] += py;
108  ptot[2] += pz;
109  dcv[ (i*3 + 0)*6 + 5] = -pt * (cth * cth + 1); /* dPz/d(theta) */
110  dcv[ (i*3 + 1)*6 + 3] = -py; /* dPx/d(phi) */
111  dcv[ (i*3 + 1)*6 + 4] = px; /* dPy/d(phi) */
112  dcv[ (i*3 + 2)*6 + 3] = -px / invR; /* dPx/d(rho) */
113  dcv[ (i*3 + 2)*6 + 4] = -py / invR; /* dPy/d(rho) */
114  dcv[ (i*3 + 2)*6 + 5] = -pz / invR; /* dPz/d(rho) */
115  }
116  dcv[0] = 1.;
117  dcv[7] = 1.;
118  dcv[14] = 1.;
119  if(!ader)return 0;
120  int IERR=getFullVrtCov(vk, ader, dcv, verr); if (IERR) return IERR;
121  int ijk = 0;
122  for ( i=0; i<6; ++i) {
123  for (j=0; j<=i; ++j) {
124  VrtMomCov[ijk++] = verr[i][j];
125  }
126  }
127  return 0;
128 }
129 
130 } /* End of namespace */
131 
132 
CommonPars.h
Trk::py
@ py
Definition: ParamDefs.h:60
Trk::vkalMagFld::getMagFld
static void getMagFld(const double, const double, const double, double &, double &, double &, VKalVrtControlBase *)
Definition: VKalVrtBMag.cxx:24
test_pyathena.pt
pt
Definition: test_pyathena.py:11
Trk::VKVertex::refIterV
double refIterV[3]
Definition: TrkVKalVrtCoreBase.h:146
Trk::VKTrack
Definition: TrkVKalVrtCoreBase.h:64
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Trk::pz
@ pz
global momentum (cartesian)
Definition: ParamDefs.h:61
VKalVrtBMag.h
cfTotCov.h
Trk::VKTrack::fitP
double fitP[3]
Definition: TrkVKalVrtCoreBase.h:76
TrkVKalVrtCoreBase.h
Trk::VKVertex::TrackList
std::vector< std::unique_ptr< VKTrack > > TrackList
Definition: TrkVKalVrtCoreBase.h:167
Trk::vkalMagFld::getCnvCst
static double getCnvCst()
Definition: VKalVrtBMag.h:49
Trk::afterFit
int afterFit(VKVertex *vk, double *ader, double *dcv, double *ptot, double *VrtMomCov, const VKalVrtControlBase *CONTROL)
Definition: cfTotCov.cxx:26
Trk::getFullVrtCov
int getFullVrtCov(VKVertex *vk, double *ader, const double *dcv, double verr[6][6])
Definition: VtCFitE.cxx:25
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::px
@ px
Definition: ParamDefs.h:59
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::VKVertex
Definition: TrkVKalVrtCoreBase.h:128
VtCFitE.h
Trk::VKTrack::iniP
double iniP[3]
Definition: TrkVKalVrtCoreBase.h:83
Trk::VKalVrtControlBase
Definition: TrkVKalVrtCore.h:26
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Utilities.h
Trk::afterFitWithIniPar
int afterFitWithIniPar(VKVertex *vk, double *ader, double *dcv, double *ptot, double *VrtMomCov, const VKalVrtControlBase *CONTROL)
Definition: cfTotCov.cxx:80
Trk::cfsetdiag
void cfsetdiag(long int n, double *matr, double value) noexcept
Definition: Tracking/TrkVertexFitter/TrkVKalVrtCore/src/Utilities.cxx:236