00001 #include "PixelTrackBuilder.h"
00002
00003
00004 #include "DataFormats/GeometrySurface/interface/LocalError.h"
00005 #include "DataFormats/GeometrySurface/interface/BoundPlane.h"
00006 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00007
00008 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryError.h"
00009 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryParameters.h"
00010 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00011
00012 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
00013 #include "TrackingTools/PatternTools/interface/TransverseImpactPointExtrapolator.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "DataFormats/TrackReco/interface/TrackBase.h"
00016
00017 #include <sstream>
00018 using namespace std;
00019 using namespace reco;
00020
00021
00022 template <class T> T sqr( T t) {return t*t;}
00023
00024 reco::Track * PixelTrackBuilder::build(
00025 const Measurement1D & pt,
00026 const Measurement1D & phi,
00027 const Measurement1D & cotTheta,
00028 const Measurement1D & tip,
00029 const Measurement1D & zip,
00030 float chi2,
00031 int charge,
00032 const std::vector<const TrackingRecHit* >& hits,
00033 const MagneticField * mf) const
00034 {
00035
00036 LogDebug("PixelTrackBuilder::build");
00037 LogTrace("")<<"reconstructed TRIPLET kinematics:\n"<<print(pt,phi,cotTheta,tip,zip,chi2,charge);
00038
00039 float sinTheta = 1/sqrt(1+sqr(cotTheta.value()));
00040 float cosTheta = cotTheta.value()*sinTheta;
00041 int tipSign = tip.value() > 0 ? 1 : -1;
00042
00043 AlgebraicSymMatrix m(5,0);
00044 float invPtErr = 1./sqr(pt.value()) * pt.error();
00045 m[0][0] = sqr(sinTheta) * (
00046 sqr(invPtErr)
00047 + sqr(cotTheta.error()/pt.value()*cosTheta * sinTheta)
00048 );
00049 m[0][2] = sqr( cotTheta.error()) * cosTheta * sqr(sinTheta) / pt.value();
00050 m[1][1] = sqr( phi.error() );
00051 m[2][2] = sqr( cotTheta.error());
00052 m[3][3] = sqr( tip.error() );
00053 m[4][4] = sqr( zip.error() );
00054 LocalTrajectoryError error(m);
00055
00056 LocalTrajectoryParameters lpar(
00057 LocalPoint(tipSign*tip.value(), -tipSign*zip.value(), 0),
00058 LocalVector(0., -tipSign*pt.value()*cotTheta.value(), pt.value()),
00059 charge);
00060
00061 Surface::RotationType rot(
00062 sin(phi.value())*tipSign, -cos(phi.value())*tipSign, 0,
00063 0, 0, -1*tipSign,
00064 cos(phi.value()), sin(phi.value()), 0);
00065 BoundPlane * impPointPlane = new BoundPlane(GlobalPoint(0.,0.,0.), rot);
00066
00067 TrajectoryStateOnSurface impactPointState( lpar , error, *impPointPlane, mf, 1.0);
00068
00069
00070 LogTrace("")<<"constructed TSOS :\n"<<print(impactPointState);
00071
00072 int ndof = 2*hits.size()-5;
00073 GlobalPoint vv = impactPointState.globalPosition();
00074 math::XYZPoint pos( vv.x(), vv.y(), vv.z() );
00075 GlobalVector pp = impactPointState.globalMomentum();
00076 math::XYZVector mom( pp.x(), pp.y(), pp.z() );
00077
00078 reco::Track * track = new reco::Track( chi2, ndof, pos, mom,
00079 impactPointState.charge(), impactPointState.curvilinearError());
00080
00081 LogTrace("") <<"RECONSTRUCTED TRACK:\n"<< print(*track)<<std::endl;;
00082
00083 return track;
00084 }
00085
00086 std::string PixelTrackBuilder::print(
00087 const Measurement1D & pt,
00088 const Measurement1D & phi,
00089 const Measurement1D & cotTheta,
00090 const Measurement1D & tip,
00091 const Measurement1D & zip,
00092 float chi2,
00093 int charge) const
00094 {
00095 ostringstream str;
00096 str <<"\t pt: " << pt.value() <<"+/-"<<pt.error()
00097 <<"\t phi: " << phi.value() <<"+/-"<<phi.error()
00098 <<"\t cot: " << cotTheta.value() <<"+/-"<<cotTheta.error()
00099 <<"\t tip: " << tip.value() <<"+/-"<<tip.error()
00100 <<"\t zip: " << zip.value() <<"+/-"<<zip.error()
00101 <<"\t charge: " << charge;
00102 return str.str();
00103 }
00104
00105 std::string PixelTrackBuilder::print(const reco::Track & track) const
00106 {
00107
00108 Measurement1D phi( track.phi(), track.phiError());
00109
00110 float theta = track.theta();
00111 float cosTheta = cos(theta);
00112 float sinTheta = sin(theta);
00113 float errLambda2 = sqr( track.lambdaError() );
00114 Measurement1D cotTheta(cosTheta/sinTheta, sqrt(errLambda2)/sqr(sinTheta));
00115
00116 float pt_v = track.pt();
00117 float errInvP2 = sqr(track.qoverpError());
00118 float covIPtTheta = track.covariance(TrackBase::i_qoverp, TrackBase::i_lambda);
00119 float errInvPt2 = ( errInvP2
00120 + sqr(cosTheta/pt_v)*errLambda2
00121 + 2*(cosTheta/pt_v)*covIPtTheta
00122 ) / sqr(sinTheta);
00123 Measurement1D pt(pt_v, sqr(pt_v)*sqrt(errInvPt2));
00124
00125 Measurement1D tip(track.d0(), track.d0Error());
00126
00127 Measurement1D zip(track.dz(), track.dzError());
00128
00129 return print(pt, phi, cotTheta, tip, zip, track.chi2(), track.charge());
00130 }
00131
00132 std::string PixelTrackBuilder::print(const TrajectoryStateOnSurface & state) const
00133 {
00134
00135 float pt_v = state.globalMomentum().perp();
00136 float phi_v = state.globalMomentum().phi();
00137 float theta_v = state.globalMomentum().theta();
00138
00139 CurvilinearTrajectoryError curv = state.curvilinearError();
00140 float errPhi2 = curv.matrix()(3,3);
00141 float errLambda2 = curv.matrix()(2,2);
00142 float errInvP2 = curv.matrix()(1,1);
00143 float covIPtTheta = curv.matrix()(1,2);
00144 float cosTheta = cos(theta_v);
00145 float sinTheta = sin(theta_v);
00146 float errInvPt2 = ( errInvP2
00147 + sqr(cosTheta/pt_v)*errLambda2
00148 + 2*(cosTheta/pt_v)*covIPtTheta) / sqr(sinTheta);
00149 float errCotTheta = sqrt(errLambda2)/sqr(sinTheta) ;
00150 Measurement1D pt(pt_v, sqr(pt_v) * sqrt(errInvPt2));
00151 Measurement1D phi(phi_v, sqrt(errPhi2) );
00152 Measurement1D cotTheta(cosTheta/sinTheta, errCotTheta);
00153
00154 float zip_v = state.globalPosition().z();
00155 float zip_e = sqrt( state.localError().matrix()(5,5));
00156 Measurement1D zip(zip_v, zip_e);
00157
00158 float tip_v = state.localPosition().x();
00159 int tip_sign = (state.localMomentum().y()*cotTheta.value() > 0) ? -1 : 1;
00160 float tip_e = sqrt( state.localError().matrix()(4,4) );
00161 Measurement1D tip( tip_sign*tip_v, tip_e);
00162
00163 return print(pt, phi, cotTheta, tip, zip, 0., state.charge());
00164 }
00165
00166 void PixelTrackBuilder::checkState(const TrajectoryStateOnSurface & state, const MagneticField* mf) const
00167 {
00168 LogTrace("")<<" *** PixelTrackBuilder::checkState: ";
00169 LogTrace("")<<"INPUT, ROTATION" << endl<<state.surface().rotation();
00170 LogTrace("")<<"INPUT, TSOS:"<<endl<<state;
00171
00172 TransverseImpactPointExtrapolator tipe(mf);
00173 TrajectoryStateOnSurface test= tipe.extrapolate(state, GlobalPoint(0,0,0) );
00174 LogTrace("")<<"CHECK-1 ROTATION" << endl<<"\n"<<test.surface().rotation();
00175 LogTrace("")<<"CHECK-1 TSOS" << endl<<test;
00176
00177 TSCPBuilderNoMaterial tscpBuilder;
00178 TrajectoryStateClosestToPoint tscp =
00179 tscpBuilder(*(state.freeState()), GlobalPoint(0,0,0) );
00180 FreeTrajectoryState fs = tscp.theState();
00181 LogTrace("")<<"CHECK-2 FTS: " << fs;
00182 }