CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
trackSelections.cc
Go to the documentation of this file.
1 #include "Math/VectorUtil.h"
2 #include <math.h>
4 
5 namespace HWWFunctions {
6 
7  // return a pair of d0, d0err of a ctf track with respect to a primary vertex
8  std::pair<double, double> trks_d0_pv (HWW& hww, int itrk, int ipv)
9  {
10  // assume the layout of the covariance matrix is (Vxx, Vxy, Vxz)
11  // (Vyx, Vyy, ...)
12  const double bx = hww.vtxs_position().at(ipv).x() ;
13  const double by = hww.vtxs_position().at(ipv).y() ;
14  const double vxx = hww.vtxs_covMatrix().at(ipv).at(0);
15  const double vxy = hww.vtxs_covMatrix().at(ipv).at(1);
16  const double vyy = hww.vtxs_covMatrix().at(ipv).at(4);
17 
18  const double phi = hww.trks_trk_p4().at(itrk).phi();
19  const double d0vtx = hww.trks_d0().at(itrk) - bx * sin(phi) + by * cos(phi);
20  const double d0err = hww.trks_d0Err().at(itrk);
21  const double phierr = hww.trks_phiErr().at(itrk);
22  const double d0phicov = hww.trks_d0phiCov().at(itrk);
23 
24  // we will let the optimizer take care of subexpression
25  // elimination for this one...
26  const double d0err2vtx = d0err * d0err
27  - 2 * (bx * cos(phi) + by * sin(phi)) * d0phicov
28  + (bx * cos(phi) + by * sin(phi)) * (bx * cos(phi) + by * sin(phi)) * phierr * phierr
29  + sin(phi) * sin(phi) * vxx + cos(phi) * cos(phi) * vyy
30  - 2 * sin(phi) * cos(phi) * vxy;
31  if (d0err2vtx >= 0)
32  return std::pair<double, double>(d0vtx, sqrt(d0err2vtx));
33 
34  edm::LogError("NegativeValue") << "Oh no! sigma^2(d0corr) < 0!";
35  return std::pair<double, double>(d0vtx, -sqrt(-d0err2vtx));
36  }
37 
38  // return a pair of d0, d0err of a gsf track with respect to a primary vertex
39  std::pair<double , double> gsftrks_d0_pv (HWW& hww, int itrk, int ipv)
40  {
41  // assume the layout of the covariance matrix is (Vxx, Vxy, Vxz)
42  // (Vyx, Vyy, ...)
43  const double bx = hww.vtxs_position().at(ipv).x() ;
44  const double by = hww.vtxs_position().at(ipv).y() ;
45  const double vxx = hww.vtxs_covMatrix().at(ipv).at(0);
46  const double vxy = hww.vtxs_covMatrix().at(ipv).at(1);
47  const double vyy = hww.vtxs_covMatrix().at(ipv).at(4);
48 
49  const double phi = hww.gsftrks_p4().at(itrk).phi();
50  const double d0vtx = hww.gsftrks_d0().at(itrk) - bx * sin(phi) + by * cos(phi);
51  const double d0err = hww.gsftrks_d0Err().at(itrk);
52  const double phierr = hww.gsftrks_phiErr().at(itrk);
53  const double d0phicov = hww.gsftrks_d0phiCov().at(itrk);
54 
55  // we will let the optimizer take care of subexpression
56  // elimination for this one...
57  const double d0err2vtx = d0err * d0err
58  - 2 * (bx * cos(phi) + by * sin(phi)) * d0phicov
59  + (bx * cos(phi) + by * sin(phi)) * (bx * cos(phi) + by * sin(phi)) * phierr * phierr
60  + sin(phi) * sin(phi) * vxx + cos(phi) * cos(phi) * vyy
61  - 2 * sin(phi) * cos(phi) * vxy;
62  if (d0err2vtx >= 0)
63  return std::pair<double, double>(d0vtx, sqrt(d0err2vtx));
64 
65  edm::LogError("NegativeValue") << "Oh no! sigma^2(d0corr) < 0!";
66  return std::pair<double, double>(d0vtx, -sqrt(-d0err2vtx));
67  }
68 
69  // return a pair of dz, dzerr of a ctf track with respect to a primary vertex
70  std::pair<double, double> trks_dz_pv (HWW& hww, int itrk, int ipv)
71  {
72 
73 
74  LorentzVector pv = hww.vtxs_position().at(ipv);
75  double pvxErr = hww.vtxs_xError().at(ipv) ;
76  double pvyErr = hww.vtxs_yError().at(ipv) ;
77  double pvzErr = hww.vtxs_zError().at(ipv) ;
78  double phi = hww.trks_trk_p4().at(itrk).phi();
79  double theta = hww.trks_trk_p4().at(itrk).theta();
80  double ddzdpvx = cos(phi)*1./tan(theta);
81  double ddzdpvy = sin(phi)*1./tan(theta);
82  double ddzdphi = -1*pv.x()*sin(phi)*1./tan(theta) + pv.y()*cos(phi)*1./tan(theta);
83  double ddzdtheta = -1*1/sin(theta)*1/sin(theta) * (pv.x()*cos(phi) + pv.y()*sin(phi));
84 
85  ddzdpvx *= ddzdpvx;
86  ddzdpvy *= ddzdpvy;
87  ddzdphi *= ddzdphi;
88  ddzdtheta *= ddzdtheta;
89 
90  double z0Err = hww.trks_z0Err().at(itrk);
91  double phiErr = hww.trks_phiErr().at(itrk);
92  double thetaErr = hww.trks_etaErr().at(itrk)*sin(theta);
93 
94  z0Err *= z0Err;
95  phiErr *= phiErr;
96  thetaErr *= thetaErr;
97  pvxErr *= pvxErr;
98  pvyErr *= pvyErr;
99  pvzErr *= pvzErr;
100 
101  double value = hww.trks_z0().at(itrk) - pv.z() + (pv.x()*cos(phi) + pv.y()*sin(phi) )*1./tan(theta);
102 
103  //note that the error does not account for correlations since we do not store the track covariance matrix
104  double error = sqrt(z0Err + pvzErr + ddzdpvx*pvxErr + ddzdpvy*pvyErr + ddzdphi*phiErr + ddzdtheta*thetaErr);
105 
106  return std::pair<double, double>(value, error);
107  }
108 
109  std::pair<double, double> gsftrks_dz_pv (HWW& hww, int itrk, int ipv)
110  {
111  LorentzVector pv = hww.vtxs_position().at(ipv);
112  double pvxErr = hww.vtxs_xError().at(ipv) ;
113  double pvyErr = hww.vtxs_yError().at(ipv) ;
114  double pvzErr = hww.vtxs_zError().at(ipv) ;
115 
116  //LorentzVector tkp = hww.gsftrks_p4().at(itrk);
117  //LorentzVector tkv = hww.gsftrks_vertex_p4().at(itrk);
118 
119  double phi = hww.gsftrks_p4().at(itrk).phi();
120  double theta = hww.gsftrks_p4().at(itrk).theta();
121 
122  double ddzdpvx = cos(phi)*1./tan(theta);
123  double ddzdpvy = sin(phi)*1./tan(theta);
124  double ddzdphi = -1*pv.x()*sin(phi)*1./tan(theta) + pv.y()*cos(phi)*1./tan(theta);
125  double ddzdtheta = -1*1/sin(theta)*1/sin(theta) * (pv.x()*cos(phi) + pv.y()*sin(phi));
126 
127  ddzdpvx *= ddzdpvx;
128  ddzdpvy *= ddzdpvy;
129  ddzdphi *= ddzdphi;
130  ddzdtheta *= ddzdtheta;
131 
132  double z0Err = hww.gsftrks_z0Err().at(itrk);
133  double phiErr = hww.gsftrks_phiErr().at(itrk);
134  double thetaErr = hww.gsftrks_etaErr().at(itrk)*sin(theta);
135 
136  z0Err *= z0Err;
137  phiErr *= phiErr;
138  thetaErr *= thetaErr;
139  pvxErr *= pvxErr;
140  pvyErr *= pvyErr;
141  pvzErr *= pvzErr;
142 
143  double value = hww.gsftrks_z0().at(itrk) - pv.z() + (pv.x()*cos(phi) + pv.y()*sin(phi) )*1./tan(theta);
144 
145  //note that the error does not account for correlations since we do not store the track covariance matrix
146  double error = sqrt(z0Err + pvzErr + ddzdpvx*pvxErr + ddzdpvy*pvyErr + ddzdphi*phiErr + ddzdtheta*thetaErr);
147 
148  return std::pair<double, double>(value, error);
149  }
150 
151 }
std::vector< float > & trks_phiErr()
Definition: HWW.cc:83
std::vector< float > & gsftrks_phiErr()
Definition: HWW.cc:705
std::vector< float > & gsftrks_d0Err()
Definition: HWW.cc:701
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< LorentzVector > & trks_trk_p4()
Definition: HWW.cc:39
std::vector< float > & gsftrks_z0Err()
Definition: HWW.cc:713
Geom::Theta< T > theta() const
std::vector< std::vector< float > > & vtxs_covMatrix()
Definition: HWW.cc:33
std::vector< float > & trks_d0()
Definition: HWW.cc:55
std::vector< float > & vtxs_zError()
Definition: HWW.cc:29
std::vector< float > & gsftrks_etaErr()
Definition: HWW.cc:721
std::vector< float > & trks_z0Err()
Definition: HWW.cc:71
std::pair< double, double > gsftrks_dz_pv(HWW &, int itrk, int ipv)
std::vector< float > & trks_z0()
Definition: HWW.cc:67
std::pair< double, double > trks_d0_pv(HWW &, int itrk, int ipv)
T sqrt(T t)
Definition: SSEVec.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
std::vector< LorentzVector > & vtxs_position()
Definition: HWW.cc:5
std::vector< float > & gsftrks_d0phiCov()
Definition: HWW.cc:709
Definition: HWW.h:12
std::vector< float > & trks_d0phiCov()
Definition: HWW.cc:87
std::vector< float > & trks_etaErr()
Definition: HWW.cc:75
std::vector< float > & gsftrks_d0()
Definition: HWW.cc:697
std::vector< float > & vtxs_xError()
Definition: HWW.cc:21
std::pair< double, double > trks_dz_pv(HWW &, int itrk, int ipv)
Geom::Phi< T > phi() const
std::vector< LorentzVector > & gsftrks_p4()
Definition: HWW.cc:689
std::pair< double, double > gsftrks_d0_pv(HWW &, int itrk, int ipv)
std::vector< float > & trks_d0Err()
Definition: HWW.cc:79
std::vector< float > & vtxs_yError()
Definition: HWW.cc:25
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > LorentzVector
Definition: pfjetMVAtools.h:10
std::vector< float > & gsftrks_z0()
Definition: HWW.cc:717