CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SignedImpactParameter3D.cc
Go to the documentation of this file.
2 
8 
9 #include "CLHEP/Vector/ThreeVector.h"
10 #include "CLHEP/Vector/LorentzVector.h"
11 #include "CLHEP/Matrix/Vector.h"
12 #include <string>
13 
14 using namespace std;
15 using namespace reco;
16 
17 pair<bool,Measurement1D> SignedImpactParameter3D::apply(const TransientTrack & transientTrack,
18  const GlobalVector & direction, const Vertex & vertex)
19  const {
20 
21  double theValue=0.;
22  double theError=0.;
23  bool theIsValid=false;
24 
26 
27  if ( !TSOS.isValid() ) {
28  cout << "====>>>> SignedImpactParameter3D::apply : TSOS not valid = " << TSOS.isValid() << endl ;
29  return pair<bool,Measurement1D>(theIsValid,Measurement1D(0.,0.)) ;
30  }
31 
33 
34  GlobalVector JetDirection(direction);
35 
36  TrajectoryStateOnSurface theTSOS = closestApproachToJet(*FTS, vertex, JetDirection,transientTrack.field());
37  theIsValid= theTSOS.isValid();
38 
39  if(theIsValid){
40 
41  GlobalVector D = distance(theTSOS, vertex, JetDirection);
42  GlobalVector J = JetDirection.unit();
43  GlobalPoint vertexPosition(vertex.x(),vertex.y(),vertex.z());
44  double theDistanceAlongJetAxis = J.dot(theTSOS.globalPosition()-vertexPosition);
45  theValue = D.mag()*(theDistanceAlongJetAxis/abs(theDistanceAlongJetAxis));
46 
47 
48  GlobalVector DD = D.unit();
49  GlobalPoint T0 = theTSOS.globalPosition();
50  GlobalVector T1 = theTSOS.globalMomentum();
51  GlobalVector TT1 = T1.unit();
52  GlobalVector Xi(T0.x()-vertex.position().x(),T0.y()-vertex.position().y(),T0.z()-vertex.position().z());
53 
54 
55  AlgebraicVector6 deriv;
56  AlgebraicVector3 deriv_v;
57 
58  deriv_v[0] = - DD.x();
59  deriv_v[1] = - DD.y();
60  deriv_v[2] = - DD.z();
61 
62  deriv[0] = DD.x();
63  deriv[1] = DD.y();
64  deriv[2] = DD.z();
65  deriv[3] = - (TT1.dot(Xi)*DD.x())/T1.mag();
66  deriv[4] = - (TT1.dot(Xi)*DD.y())/T1.mag();
67  deriv[5] = - (TT1.dot(Xi)*DD.z())/T1.mag();
68 
69  double E1 = ROOT::Math::Similarity(deriv , theTSOS.cartesianError().matrix());
70  double E2 = ROOT::Math::Similarity(deriv_v , vertex.covariance());
71 // double E2 = RecoVertex::convertError(vertex.covariance()).matrix().similarity(deriv_v);
72 // double E2 = 0.; // no vertex error because of stupid use of hundreds of different types for same thing
73  theError = sqrt(E1+E2);
74 
75  Measurement1D A(theValue, theError);
76 
77  return pair<bool,Measurement1D>(theIsValid,A);
78  }
79  else {
80  return pair<bool,Measurement1D>(theIsValid,Measurement1D(0.,0.));
81  }// endif (isValid)
82 }
83 
84 
85 
87 
88  GlobalVector J =aJetDirection.unit();
89 
90  Line::PositionType pos(GlobalPoint(vertex.x(),vertex.y(),vertex.z()));
92  Line Jet(pos,dir);
93 
95 
96  return TETL.extrapolate(aFTS, Jet);
97 }
98 
99 GlobalVector SignedImpactParameter3D::distance(const TrajectoryStateOnSurface & aTSOS, const Vertex & vertex, const GlobalVector & aJetDirection) {
100 
101  Line::PositionType pos2(aTSOS.globalPosition());
103  Line T(pos2,dir2);
104 
105  GlobalPoint X = GlobalPoint(vertex.x(),vertex.y(),vertex.z()); // aVertex.position();
106 
107  GlobalVector D = T.distance(X);
108 
109  return D;
110 }
111 
112 pair<double,Measurement1D> SignedImpactParameter3D::distanceWithJetAxis(const TransientTrack & track, const GlobalVector & direction, const Vertex & vertex) {
113  double theDistanceAlongJetAxis(0.);
114  double theDistanceToJetAxis(0.);
115  double theLDist_err(0.);
117 
118  if ( !TSOS.isValid() ) {
119  cout << "====>>>> SignedImpactParameter3D::distanceWithJetAxis : TSOS not valid = " << TSOS.isValid() << endl ;
120  return pair<double,Measurement1D> (theDistanceAlongJetAxis,Measurement1D(theDistanceToJetAxis,theLDist_err));
121  }
122 
124 
125  GlobalVector jetDirection(direction);
126 
127  //
128  // Check whether the track has been used in the vertex
129  //
130 
131  //FIXME
132  float weight=0.;//vertex.trackWeight(aRecTrack);
133 
134  TrajectoryStateOnSurface stateAtOrigin = track.impactPointState();
135  TrajectoryStateOnSurface aTSOS = closestApproachToJet(*FTS, vertex, jetDirection, track.field());
136  bool isValid= stateAtOrigin.isValid();
137  // bool IsValid= aTSOS.isValid();
138 
139  if(isValid){
140 
141  //get the Track line at origin
142  Line::PositionType pos(stateAtOrigin.globalPosition());
143  Line::DirectionType dir((stateAtOrigin.globalMomentum()).unit());
144  Line track(pos,dir);
145  // get the Jet line
146  // Vertex vertex(vertex);
147  GlobalVector jetVector = jetDirection.unit();
148  Line::PositionType pos2(GlobalPoint(vertex.x(),vertex.y(),vertex.z()));
149  Line::DirectionType dir2(jetVector);
150  Line jet(pos2,dir2);
151  // now compute the distance between the two lines
152  // If the track has been used to refit the Primary vertex then sign it positively, otherwise negative
153 
154  theDistanceToJetAxis = (jet.distance(track)).mag();
155  if (weight<1) theDistanceToJetAxis= -theDistanceToJetAxis;
156 
157  // ... and the flight distance along the Jet axis.
158  GlobalPoint V = jet.position();
159  GlobalVector Q = dir - jetVector.dot(dir) * jetVector;
160  GlobalVector P = jetVector - jetVector.dot(dir) * dir;
161  theDistanceAlongJetAxis = P.dot(V-pos)/Q.dot(dir);
162 
163  //
164  // get the covariance matrix of the vertex and compute the error on theDistanceToJetAxis
165  //
166 
168 
169  // build the vector of closest approach between lines
170 
171  GlobalVector H((jetVector.cross(dir).unit()));
172 
173  CLHEP::HepVector Hh(3);
174  Hh[0] = H.x();
175  Hh[1] = H.y();
176  Hh[2] = H.z();
177 
178  // theLDist_err = sqrt(vertexError.similarity(Hh));
179 
180  // cout << "distance to jet axis : "<< theDistanceToJetAxis <<" and error : "<< theLDist_err<<endl;
181  // Now the impact parameter ...
182 
183 /* GlobalPoint T0 = track.position();
184  GlobalVector D = (T0-V)- (T0-V).dot(dir) * dir;
185  double IP = D.mag();
186  GlobalVector Dold = distance(aTSOS, aJet.vertex(), jetDirection);
187  double IPold = Dold.mag();
188 */
189 
190 
191 
192  }
193  Measurement1D DTJA(theDistanceToJetAxis,theLDist_err);
194 
195  return pair<double,Measurement1D> (theDistanceAlongJetAxis,DTJA);
196 }
Definition: Line.h:10
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
double y() const
y coordinate
Definition: Vertex.h:110
Base class for all types of Jets.
Definition: Jet.h:20
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
const CartesianTrajectoryError cartesianError() const
T y() const
Definition: PV3DBase.h:63
static TrajectoryStateOnSurface closestApproachToJet(const FreeTrajectoryState &, const reco::Vertex &, const GlobalVector &, const MagneticField *)
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const Line &L) const
extrapolation from FreeTrajectoryState
#define X(str)
Definition: MuonsGrabber.cc:48
GlobalPoint globalPosition() const
#define P
PreciseFloatType< T, U >::Type dot(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:107
TrajectoryStateOnSurface closestApproachToJet(const TrajectoryStateOnSurface &state, const reco::Vertex &vertex, const GlobalVector &aJetDirection, const MagneticField *field)
Definition: IPTools.cc:177
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
const Point & position() const
position
Definition: Vertex.h:106
ROOT::Math::SVector< double, 6 > AlgebraicVector6
GlobalVector distance(const Line &aLine) const
Definition: Line.h:38
PositionType position() const
Definition: Line.h:26
T mag() const
Definition: PV3DBase.h:67
FreeTrajectoryState const * freeTrajectoryState(bool withErrors=true) const
string unit
Definition: csvLumiCalc.py:46
T sqrt(T t)
Definition: SSEVec.h:48
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:119
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
const AlgebraicSymMatrix66 & matrix() const
Vector3DBase unit() const
Definition: Vector3DBase.h:57
double x() const
x coordinate
Definition: Vertex.h:108
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:150
static GlobalVector distance(const TrajectoryStateOnSurface &, const reco::Vertex &, const GlobalVector &)
GlobalVector globalMomentum() const
static std::pair< double, Measurement1D > distanceWithJetAxis(const reco::TransientTrack &transientTrack, const GlobalVector &direction, const reco::Vertex &vertex)
tuple cout
Definition: gather_cfg.py:121
TrajectoryStateOnSurface impactPointState() const
dbl *** dir
Definition: mlp_gen.cc:35
int weight
Definition: histoStyle.py:50
long double T
T x() const
Definition: PV3DBase.h:62
std::pair< bool, Measurement1D > apply(const reco::TransientTrack &, const GlobalVector &direction, const reco::Vertex &vertex) const