CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SignedTransverseImpactParameter.cc
Go to the documentation of this file.
2 
9 
10 #include "CLHEP/Vector/ThreeVector.h"
11 #include "CLHEP/Vector/LorentzVector.h"
12 #include "CLHEP/Matrix/Vector.h"
13 #include <string>
14 
16 
17 using namespace std;
18 using namespace reco;
19 
20 pair<bool,Measurement1D> SignedTransverseImpactParameter::apply(const TransientTrack & track,
21  const GlobalVector & direction, const Vertex & vertex)
22  const {
23 
24  TrajectoryStateOnSurface stateOnSurface = track.impactPointState();
25 
26  const FreeTrajectoryState * FTS = stateOnSurface.freeState(); //aRecTrack.stateAtFirstPoint().freeTrajectoryState());
27 
28  GlobalPoint vertexPosition(vertex.x(),vertex.y(),vertex.z());
29 
30  double theValue=0.;
31  double theError=0.;
33  TrajectoryStateOnSurface TSOS = TIPE.extrapolate(*FTS, vertexPosition);
34 
35  if(!TSOS.isValid()){
36  theValue=0.;
37  theError=0.;
38  }
39  else{
40 
41  GlobalPoint D0(TSOS.globalPosition());
42 
43  GlobalVector DD0(D0.x()-vertex.x(),D0.y()-vertex.y(),0.);
44  GlobalVector JetDir(direction);
45  double ps = DD0.dot(JetDir);
46  theValue = DD0.mag()*(ps/abs(ps));
47 
48  //error calculation
49 
50  AlgebraicVector6 deriv;
51  AlgebraicVector3 deriv_v;
52  GlobalVector dd0 = DD0.unit();//check
53 
54  deriv_v[0] = - dd0.x();
55  deriv_v[1] = - dd0.y();
56  deriv_v[2] = - dd0.z();
57 
58  deriv[0] = dd0.x();
59  deriv[1] = dd0.y();
60  deriv[2] = dd0.z();
61  deriv[3] = 0.;
62  deriv[4] = 0.;
63  deriv[5] = 0.;
64  //cout << TSOS.cartesianError().matrix() << endl;
65  //cout << deriv << endl;
66  double E1 = ROOT::Math::Similarity(deriv,TSOS.cartesianError().matrix());
67  double E2 = ROOT::Math::Similarity(deriv_v,vertex.covariance());
68  // (aJet.vertex().positionError().matrix()).similarity(deriv_v);
69  theError = sqrt(E1+E2);
70  LogDebug("BTagTools") << "Tk error : " << E1 << " , Vtx error : " << E2 << " tot : " << theError;
71 
72  }//end if
73 
74  bool x = true;
75 
76  Measurement1D A(theValue, theError);
77  return pair<bool,Measurement1D>(x,A);
78 }// end constructor declaration
79 
80 
81 
82 pair<bool,Measurement1D> SignedTransverseImpactParameter::zImpactParameter ( const TransientTrack & track,
83  const GlobalVector & direction, const Vertex & vertex) const {
84 
87 
88  if ( !TSOS.isValid() ) {
89  LogDebug("BTagTools") << "====>>>> SignedTransverseImpactParameter::zImpactParameter : TSOS not valid" ;
90  return pair<bool,Measurement1D> (false,Measurement1D(0.0,0.0)) ;
91  }
92 
93  GlobalPoint PV(vertex.x(),vertex.y(),vertex.z());
94  TrajectoryStateOnSurface statePCA = TIPE.extrapolate( TSOS , PV ) ;
95 
96  if ( !statePCA.isValid() ) {
97  LogDebug("BTagTools") << "====>>>> SignedTransverseImpactParameter::zImpactParameter : statePCA not valid" ;
98  return pair<bool,Measurement1D> (false,Measurement1D(0.0,0.0)) ;
99  }
100 
101  GlobalPoint PCA = statePCA.globalPosition() ;
102 
103  // sign as in rphi
104  GlobalVector PVPCA ( PCA.x()-PV.x() , PCA.y()-PV.y() , 0. );
105  GlobalVector JetDir(direction);
106  double sign = PVPCA.dot(JetDir);
107  sign /= fabs(sign) ;
108 
109  // z IP
110  double deltaZ = fabs(PCA.z()-PV.z()) * sign ;
111 
112  // error
113  double errPvZ2 = vertex.covariance()(2,2) ;
114  //CW cout << "CW number or rows and columns : " << statePCA.cartesianError().matrix().num_row() << " , "
115  //CW << statePCA.cartesianError().matrix().num_col() << endl ;
116  double errTrackZ2 = statePCA.cartesianError().matrix()(2,2) ;
117  double errZ = sqrt ( errPvZ2 + errTrackZ2 ) ;
118 
119  // CW alt. -> gives the same!!
120  // double errTZAlt = statePCA.localError().matrix()[4][4] ;
121  //CW
122 
123  return pair<bool,Measurement1D> ( true , Measurement1D( deltaZ , errZ ) ) ;
124 }
#define LogDebug(id)
std::pair< bool, Measurement1D > apply(const reco::TransientTrack &, const GlobalVector &, const reco::Vertex &) const
double y() const
y coordinate
Definition: Vertex.h:110
Divides< arg, void > D0
Definition: Factorize.h:143
double sign(double x)
T y() const
Definition: PV3DBase.h:63
const MagneticField * field() const
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:123
std::pair< bool, Measurement1D > zImpactParameter(const reco::TransientTrack &, const GlobalVector &, const reco::Vertex &) const
ROOT::Math::SVector< double, 6 > AlgebraicVector6
T x() const
Cartesian x coordinate.
T sqrt(T t)
Definition: SSEVec.h:48
FreeTrajectoryState const * freeState(bool withErrors=true) const
T z() const
Definition: PV3DBase.h:64
ROOT::Math::SVector< double, 3 > AlgebraicVector3
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double z() const
y coordinate
Definition: Vertex.h:112
Vector3DBase unit() const
Definition: Vector3DBase.h:57
double x() const
x coordinate
Definition: Vertex.h:108
TrajectoryStateOnSurface impactPointState() const
T x() const
Definition: PV3DBase.h:62