CMS 3D CMS Logo

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