00001 #include "DataFormats/GeometrySurface/interface/Line.h"
00002
00003 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00004 #include "TrackingTools/GeomPropagators/interface/AnalyticalTrajectoryExtrapolatorToLine.h"
00005 #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
00006 #include "RecoBTag/BTagTools/interface/SignedImpactParameter3D.h"
00007 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00008
00009 #include "CLHEP/Vector/ThreeVector.h"
00010 #include "CLHEP/Vector/LorentzVector.h"
00011 #include "CLHEP/Matrix/Vector.h"
00012 #include <string>
00013
00014 using namespace std;
00015 using namespace reco;
00016
00017 pair<bool,Measurement1D> SignedImpactParameter3D::apply(const TransientTrack & transientTrack,
00018 const GlobalVector & direction, const Vertex & vertex)
00019 const {
00020
00021 double theValue=0.;
00022 double theError=0.;
00023 bool theIsValid=false;
00024
00025 TrajectoryStateOnSurface TSOS = transientTrack.impactPointState();
00026
00027 if ( !TSOS.isValid() ) {
00028 cout << "====>>>> SignedImpactParameter3D::apply : TSOS not valid = " << TSOS.isValid() << endl ;
00029 return pair<bool,Measurement1D>(theIsValid,Measurement1D(0.,0.)) ;
00030 }
00031
00032 FreeTrajectoryState * FTS = TSOS.freeTrajectoryState();
00033
00034 GlobalVector JetDirection(direction);
00035
00036 TrajectoryStateOnSurface theTSOS = closestApproachToJet(*FTS, vertex, JetDirection,transientTrack.field());
00037 theIsValid= theTSOS.isValid();
00038
00039 if(theIsValid){
00040
00041 GlobalVector D = distance(theTSOS, vertex, JetDirection);
00042 GlobalVector J = JetDirection.unit();
00043 GlobalPoint vertexPosition(vertex.x(),vertex.y(),vertex.z());
00044 double theDistanceAlongJetAxis = J.dot(theTSOS.globalPosition()-vertexPosition);
00045 theValue = D.mag()*(theDistanceAlongJetAxis/abs(theDistanceAlongJetAxis));
00046
00047
00048 GlobalVector DD = D.unit();
00049 GlobalPoint T0 = theTSOS.globalPosition();
00050 GlobalVector T1 = theTSOS.globalMomentum();
00051 GlobalVector TT1 = T1.unit();
00052 GlobalVector Xi(T0.x()-vertex.position().x(),T0.y()-vertex.position().y(),T0.z()-vertex.position().z());
00053
00054
00055 AlgebraicVector6 deriv;
00056 AlgebraicVector3 deriv_v;
00057
00058 deriv_v[0] = - DD.x();
00059 deriv_v[1] = - DD.y();
00060 deriv_v[2] = - DD.z();
00061
00062 deriv[0] = DD.x();
00063 deriv[1] = DD.y();
00064 deriv[2] = DD.z();
00065 deriv[3] = - (TT1.dot(Xi)*DD.x())/T1.mag();
00066 deriv[4] = - (TT1.dot(Xi)*DD.y())/T1.mag();
00067 deriv[5] = - (TT1.dot(Xi)*DD.z())/T1.mag();
00068
00069 double E1 = ROOT::Math::Similarity(deriv , theTSOS.cartesianError().matrix());
00070 double E2 = ROOT::Math::Similarity(deriv_v , vertex.covariance());
00071
00072
00073 theError = sqrt(E1+E2);
00074
00075 Measurement1D A(theValue, theError);
00076
00077 return pair<bool,Measurement1D>(theIsValid,A);
00078 }
00079 else {
00080 return pair<bool,Measurement1D>(theIsValid,Measurement1D(0.,0.));
00081 }
00082 }
00083
00084
00085
00086 TrajectoryStateOnSurface SignedImpactParameter3D::closestApproachToJet(const FreeTrajectoryState & aFTS,const Vertex & vertex, const GlobalVector& aJetDirection,const MagneticField * field) {
00087
00088 GlobalVector J =aJetDirection.unit();
00089
00090 Line::PositionType pos(GlobalPoint(vertex.x(),vertex.y(),vertex.z()));
00091 Line::DirectionType dir(J);
00092 Line Jet(pos,dir);
00093
00094 AnalyticalTrajectoryExtrapolatorToLine TETL(field);
00095
00096 return TETL.extrapolate(aFTS, Jet);
00097 }
00098
00099 GlobalVector SignedImpactParameter3D::distance(const TrajectoryStateOnSurface & aTSOS, const Vertex & vertex, const GlobalVector & aJetDirection) {
00100
00101 Line::PositionType pos2(aTSOS.globalPosition());
00102 Line::DirectionType dir2((aTSOS.globalMomentum()).unit());
00103 Line T(pos2,dir2);
00104
00105 GlobalPoint X = GlobalPoint(vertex.x(),vertex.y(),vertex.z());
00106
00107 GlobalVector D = T.distance(X);
00108
00109 return D;
00110 }
00111
00112 pair<double,Measurement1D> SignedImpactParameter3D::distanceWithJetAxis(const TransientTrack & track, const GlobalVector & direction, const Vertex & vertex) {
00113 double theDistanceAlongJetAxis(0.);
00114 double theDistanceToJetAxis(0.);
00115 double theLDist_err(0.);
00116 TrajectoryStateOnSurface TSOS = track.impactPointState();
00117
00118 if ( !TSOS.isValid() ) {
00119 cout << "====>>>> SignedImpactParameter3D::distanceWithJetAxis : TSOS not valid = " << TSOS.isValid() << endl ;
00120 return pair<double,Measurement1D> (theDistanceAlongJetAxis,Measurement1D(theDistanceToJetAxis,theLDist_err));
00121 }
00122
00123 FreeTrajectoryState * FTS = TSOS.freeTrajectoryState();
00124
00125 GlobalVector jetDirection(direction);
00126
00127
00128
00129
00130
00131
00132 float weight=0.;
00133
00134 TrajectoryStateOnSurface stateAtOrigin = track.impactPointState();
00135 TrajectoryStateOnSurface aTSOS = closestApproachToJet(*FTS, vertex, jetDirection, track.field());
00136 bool isValid= stateAtOrigin.isValid();
00137
00138
00139 if(isValid){
00140
00141
00142 Line::PositionType pos(stateAtOrigin.globalPosition());
00143 Line::DirectionType dir((stateAtOrigin.globalMomentum()).unit());
00144 Line track(pos,dir);
00145
00146
00147 GlobalVector jetVector = jetDirection.unit();
00148 Line::PositionType pos2(GlobalPoint(vertex.x(),vertex.y(),vertex.z()));
00149 Line::DirectionType dir2(jetVector);
00150 Line jet(pos2,dir2);
00151
00152
00153
00154 theDistanceToJetAxis = (jet.distance(track)).mag();
00155 if (weight<1) theDistanceToJetAxis= -theDistanceToJetAxis;
00156
00157
00158 GlobalPoint V = jet.position();
00159 GlobalVector Q = dir - jetVector.dot(dir) * jetVector;
00160 GlobalVector P = jetVector - jetVector.dot(dir) * dir;
00161 theDistanceAlongJetAxis = P.dot(V-pos)/Q.dot(dir);
00162
00163
00164
00165
00166
00168
00169
00170
00171 GlobalVector H((jetVector.cross(dir).unit()));
00172
00173 CLHEP::HepVector Hh(3);
00174 Hh[0] = H.x();
00175 Hh[1] = H.y();
00176 Hh[2] = H.z();
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 }
00193 Measurement1D DTJA(theDistanceToJetAxis,theLDist_err);
00194
00195 return pair<double,Measurement1D> (theDistanceAlongJetAxis,DTJA);
00196 }