CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/TrackingTools/TrajectoryState/src/TrajectoryStateTransform.cc

Go to the documentation of this file.
00001 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00002 #include "DataFormats/TrackReco/interface/Track.h" 
00003 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00004 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h" 
00005 #include "DataFormats/GeometrySurface/interface/Surface.h" 
00006 #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h"
00007 #include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
00008 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00009 
00010 
00011 namespace trajectoryStateTransform {
00012 
00013   using namespace SurfaceSideDefinition;
00014   
00015   PTrajectoryStateOnDet 
00016   persistentState( const TrajectoryStateOnSurface& ts,
00017                    unsigned int detid)
00018   {
00019     int surfaceSide = static_cast<int>(ts.surfaceSide());
00020     
00021     if (ts.hasError()) {
00022       AlgebraicSymMatrix55 m = ts.localError().matrix();
00023       
00024       int dim = 5; 
00025       float localErrors[15];
00026       
00027       int k = 0;
00028       for (int i=0; i<dim; i++) {
00029         for (int j=0; j<=i; j++) {
00030           localErrors[k++] = m(i,j);
00031         }
00032       }
00033     return PTrajectoryStateOnDet(ts.localParameters(),
00034                                  localErrors, detid,
00035                                  surfaceSide);
00036     }
00037     return PTrajectoryStateOnDet(ts.localParameters(),
00038                                  detid,
00039                                  surfaceSide);
00040   }
00041   
00042   TrajectoryStateOnSurface 
00043   transientState( const PTrajectoryStateOnDet& ts,
00044                   const Surface* surface,
00045                   const MagneticField* field)
00046   {
00047     AlgebraicSymMatrix55 m;
00048     bool errInv=true;
00049     if (ts.hasError()) {
00050       errInv = false;
00051       int dim = 5;
00052       int k = 0;
00053       for (int i=0; i<dim; i++) {
00054         for (int j=0; j<=i; j++) {
00055           m(i,j) = ts.error(k++);       // NOTE: here we do a cast float => double.     
00056         }
00057       }
00058     }
00059     
00060     
00061     return TrajectoryStateOnSurface( ts.parameters(),
00062                                      errInv ? LocalTrajectoryError(InvalidError()) : LocalTrajectoryError(m),
00063                                      *surface, field,
00064                                      static_cast<SurfaceSide>(ts.surfaceSide()));
00065     
00066 }
00067   
00068   FreeTrajectoryState initialFreeState( const reco::Track& tk,
00069                                         const MagneticField* field) 
00070   {
00071     Basic3DVector<float> pos( tk.vertex());
00072     GlobalPoint gpos( pos);
00073     Basic3DVector<float> mom( tk.momentum());
00074   GlobalVector gmom( mom);
00075   GlobalTrajectoryParameters par( gpos, gmom, tk.charge(), field);
00076   CurvilinearTrajectoryError err( tk.covariance());
00077   return FreeTrajectoryState( par, err);
00078   }
00079   
00080   FreeTrajectoryState innerFreeState( const reco::Track& tk,
00081                                       const MagneticField* field)
00082   {
00083     Basic3DVector<float> pos( tk.innerPosition());
00084     GlobalPoint gpos( pos);
00085     Basic3DVector<float> mom( tk.innerMomentum());
00086     GlobalVector gmom( mom);
00087     GlobalTrajectoryParameters par( gpos, gmom, tk.charge(), field);
00088     CurvilinearTrajectoryError err( tk.extra()->innerStateCovariance());
00089     return FreeTrajectoryState( par, err);
00090   }
00091 
00092   
00093   FreeTrajectoryState outerFreeState( const reco::Track& tk,
00094                                       const MagneticField* field)
00095   {
00096     Basic3DVector<float> pos( tk.outerPosition());
00097     GlobalPoint gpos( pos);
00098     Basic3DVector<float> mom( tk.outerMomentum());
00099     GlobalVector gmom( mom);
00100     GlobalTrajectoryParameters par( gpos, gmom, tk.charge(), field);
00101     CurvilinearTrajectoryError err( tk.extra()->outerStateCovariance());
00102     return FreeTrajectoryState( par, err);
00103   }
00104 
00105   
00106   TrajectoryStateOnSurface innerStateOnSurface( const reco::Track& tk, 
00107                                                 const TrackingGeometry& geom,
00108                                                 const MagneticField* field)
00109   {
00110     const Surface& surface = geom.idToDet( DetId( tk.extra()->innerDetId()))->surface();
00111     return TrajectoryStateOnSurface( innerFreeState( tk, field), surface);
00112   }
00113   
00114   TrajectoryStateOnSurface outerStateOnSurface( const reco::Track& tk, 
00115                                                 const TrackingGeometry& geom,
00116                                                 const MagneticField* field)
00117   {
00118     const Surface& surface = geom.idToDet( DetId( tk.extra()->outerDetId()))->surface();
00119     return TrajectoryStateOnSurface( outerFreeState( tk, field), surface);
00120   }
00121   
00122 }