ATLAS Offline Software
cfMassErr.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 //Calculate mass and mass error for any subset of tracks
9 #include <cmath>
10 #include <array>
11 #include <cfenv>
12 
13 namespace Trk {
14 
15 
16 void cfmasserr(VKVertex * vk, const int *list, double BMAG, double *MASS, double *sigM)
17 {
18  int NTRK=vk->TrackList.size();
19  //Deliberately not using make_unique
20  std::unique_ptr < double[] > deriv(new double[3*NTRK+3]);
21  double ptot[4]={0.};
22  std::vector< std::array<double,6> > pmom(NTRK);
23  double dm2dpx, dm2dpy, dm2dpz, ee, pt, px, py, pz, cth;
24 
25  double constBF = BMAG * vkalMagCnvCst ;
26 
27  for(int it=0; it<NTRK; it++){
28  if (list[it]) {
29  pmom[it][4] = pt = constBF / std::abs(vk->TrackList[it]->fitP[2]);
30  pmom[it][5] = cth = 1. /tan(vk->TrackList[it]->fitP[0]);
31  pmom[it][0] = px = pt * cos(vk->TrackList[it]->fitP[1]);
32  pmom[it][1] = py = pt * sin(vk->TrackList[it]->fitP[1]);
33  pmom[it][2] = pz = pt * cth;
34  double mmm=vk->TrackList[it]->getMass();
35  pmom[it][3] = sqrt(px*px + py*py + pz*pz + mmm*mmm);
36  ptot[0] += px;
37  ptot[1] += py;
38  ptot[2] += pz;
39  ptot[3] += pmom[it][3];
40  }
41  }
42 
43  for(int it = 0; it < NTRK; ++it) {
44  if (list[it]) {
45  pt = pmom[it][4];
46  cth= pmom[it][5];
47  px = pmom[it][0];
48  py = pmom[it][1];
49  pz = pmom[it][2];
50  ee = pmom[it][3];
51  dm2dpx = (ptot[3] / ee * px - ptot[0]) * 2.;
52  dm2dpy = (ptot[3] / ee * py - ptot[1]) * 2.;
53  dm2dpz = (ptot[3] / ee * pz - ptot[2]) * 2.;
54  deriv[it*3 + 0] = dm2dpz * ((-pt) * (cth * cth + 1.)); /* d(M2)/d(Theta) */
55  deriv[it*3 + 1] = -dm2dpx * py + dm2dpy * px; /* d(M2)/d(Phi) */
56  deriv[it*3 + 2] = (-dm2dpx * px - dm2dpy*py - dm2dpz*pz)/vk->TrackList[it]->fitP[2]; /* d(M2)/d(Rho) */
57  } else {
58  deriv[it*3 + 0] = deriv[it*3 + 1] = deriv[it*3 + 2] = 0.;
59  }
60  }
61 //----
62  double covM2=0.;
63  for(int i=0; i<NTRK*3; i++){
64  double tmp=0.;
65  for(int j=0; j<NTRK*3; j++){
66  tmp += ARR2D_FS(vk->ader, vkalNTrkM*3+3, i+3, j+3) *deriv[j];
67  }
68  tmp *= deriv[i];
69  if(std::isnan(tmp)) {tmp=0.;}
70  if(std::isinf(tmp)) {tmp=0.;}
71  covM2 += tmp;
72  }
73  std::feclearexcept(FE_ALL_EXCEPT);
74  if(covM2<1.e-10)covM2=1.e-10;
75 //----
76  (*MASS) = (ptot[3]-ptot[2])*(ptot[3]+ptot[2])-ptot[1]*ptot[1]-ptot[0]*ptot[0];
77  if((*MASS)<1.e-10) (*MASS) = 1.e-10;
78  (*MASS) = sqrt(*MASS);
79  (*sigM) = sqrt(covM2) / 2. / (*MASS);
80 }
81 
82 
83 void cfmasserrold_(const long int ntrk, long int *list, double *parfs,
84  double *ams, double *deriv, double BMAG, double *dm, double *sigm)
85 {
86  int i__;
87  double ptot[4];
88  double constB, dm2dpx, dm2dpy, dm2dpz, ee, pt, px, py, pz, cth;
89 
90  --deriv;
91  --ams;
92  parfs -= 4;
93  --list;
94 
95  /* Function Body */
96  ptot[0] = 0.;
97  ptot[1] = 0.;
98  ptot[2] = 0.;
99  ptot[3] = 0.;
100 
101  constB = BMAG * vkalMagCnvCst ;
102 
103  int i3;
104  for (i__ = 1; i__ <= ntrk; ++i__) {
105  if (list[i__] == 1) {
106  i3 = i__ * 3;
107  pt = std::abs(parfs[i3 + 3]);
108  pt = constB / pt;
109  cth = 1. /tan(parfs[i3 + 1]);
110  px = pt * cos(parfs[i3 + 2]);
111  py = pt * sin(parfs[i3 + 2]);
112  pz = pt * cth;
113  ptot[0] += px;
114  ptot[1] += py;
115  ptot[2] += pz;
116  ptot[3] += sqrt(px*px + py*py + pz*pz + ams[i__]*ams[i__]);
117  }
118  }
119 
120 
121  for (i__ = 1; i__ <= ntrk; ++i__) {
122  i3 = i__ * 3;
123  if (list[i__] == 1) {
124  pt = std::abs(parfs[i3+3]);
125  pt = constB / pt;
126  cth = 1. / tan(parfs[i3+1]);
127  px = pt * cos(parfs[i3+2]);
128  py = pt * sin(parfs[i3+2]);
129  pz = pt * cth;
130  ee = sqrt(px*px + py*py + pz*pz + ams[i__]*ams[i__]);
131  dm2dpx = (ptot[3] / ee * px - ptot[0]) * 2.;
132  dm2dpy = (ptot[3] / ee * py - ptot[1]) * 2.;
133  dm2dpz = (ptot[3] / ee * pz - ptot[2]) * 2.;
134  deriv[i3 + 1] = dm2dpz * ((-pt) * (cth * cth + 1.)); /* d(M2)/d(Theta) */
135  deriv[i3 + 2] = -dm2dpx * py + dm2dpy * px; /* d(M2)/d(Phi) */
136  deriv[i3 + 3] = (-dm2dpx * px - dm2dpy*py - dm2dpz*pz)/ parfs[i3+3]; /* d(M2)/d(Rho) */
137 /* cc Std derivatives-------------------------------------------*/
138 /* DCV(6,I*3+1)=-PT*(1+CTH**2) ! dPz/d(theta)*/
139 /* DCV(4,I*3+2)=-PY ! dPx/d(phi) */
140 /* DCV(5,I*3+2)= PX ! dPy/d(phi) */
141 /* DCV(4,I*3+3)=-PX/PARFS(3,I) ! dPx/d(rho) */
142 /* DCV(5,I*3+3)=-PY/PARFS(3,I) ! dPy/d(rho) */
143 /* DCV(6,I*3+3)=-PZ/PARFS(3,I) ! dPz/d(rho) */
144 /* d(M2)/d(Rho) */
145  } else {
146  deriv[i3 + 1] = 0.;
147  deriv[i3 + 2] = 0.;
148  deriv[i3 + 3] = 0.;
149  }
150  }
151  deriv[1] = 0.;
152  deriv[2] = 0.;
153  deriv[3] = 0.;
154  double covarm2=ptot[3]; //To avoid compiler warning
155  //cferrany_(ntrk, &deriv[1], &covarm2);
156  (*dm) = (ptot[3]-ptot[2])*(ptot[3]+ptot[2])-ptot[1]*ptot[1]-ptot[0]*ptot[0];
157  if((*dm)<1.e-6) (*dm) = 1.e-6;
158  (*dm) = sqrt(*dm);
159  (*sigm) = sqrt(covarm2) / 2. / (*dm);
160 }
161 
162 
163 
164 } /* End of namespace */
165 
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
CommonPars.h
Trk::py
@ py
Definition: ParamDefs.h:60
skel.it
it
Definition: skel.GENtoEVGEN.py:396
test_pyathena.pt
pt
Definition: test_pyathena.py:11
Trk::VKVertex::ader
double ader[(3 *vkalNTrkM+3) *(3 *vkalNTrkM+3)]
Definition: TrkVKalVrtCoreBase.h:188
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
Trk::pz
@ pz
global momentum (cartesian)
Definition: ParamDefs.h:61
Trk::cfmasserrold_
void cfmasserrold_(const long int ntrk, long int *list, double *parfs, double *ams, double *deriv, double BMAG, double *dm, double *sigm)
Definition: cfMassErr.cxx:83
TrkVKalVrtCoreBase.h
Trk::VKVertex::TrackList
std::vector< std::unique_ptr< VKTrack > > TrackList
Definition: TrkVKalVrtCoreBase.h:167
lumiFormat.i
int i
Definition: lumiFormat.py:85
vkalMagCnvCst
#define vkalMagCnvCst
Definition: CommonPars.h:23
Trk::cfmasserr
void cfmasserr(VKVertex *vk, const int *list, double BMAG, double *MASS, double *sigM)
Definition: cfMassErr.cxx:16
Trk::px
@ px
Definition: ParamDefs.h:59
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ReadCellNoiseFromCool.dm
dm
Definition: ReadCellNoiseFromCool.py:235
ARR2D_FS
#define ARR2D_FS(name, N, i, j)
Definition: CommonPars.h:29
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
vkalNTrkM
#define vkalNTrkM
Definition: CommonPars.h:22
cfMassErr.h
Trk::VKVertex
Definition: TrkVKalVrtCoreBase.h:128
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36