CMS 3D CMS Logo

BasicSingleTrajectoryState.h

Go to the documentation of this file.
00001 #ifndef BasicSingleTrajectoryState_H
00002 #define BasicSingleTrajectoryState_H
00003 
00004 #include "TrackingTools/TrajectoryState/interface/BasicTrajectoryState.h"
00005 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00006 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryParameters.h"
00007 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryError.h"
00008 
00009 #include "DataFormats/GeometrySurface/interface/ReferenceCounted.h"
00010 
00011 #include "DataFormats/GeometryCommonDetAlgo/interface/DeepCopyPointer.h"
00012 #include "DataFormats/GeometrySurface/interface/Surface.h"
00013 #include "TrackingTools/TrajectoryParametrization/interface/TrajectoryStateExceptions.h"
00014 
00016 #include <iostream>
00017 
00018 class MagneticField;
00019 
00023 class BasicSingleTrajectoryState : public BasicTrajectoryState {
00024 public:
00025 
00029   BasicSingleTrajectoryState( const FreeTrajectoryState& fts,
00030                               const Surface& aSurface,
00031                               const SurfaceSide side = atCenterOfSurface);
00035   BasicSingleTrajectoryState( const GlobalTrajectoryParameters& par,
00036                               const Surface& aSurface,
00037                               const SurfaceSide side = atCenterOfSurface);
00041   BasicSingleTrajectoryState( const GlobalTrajectoryParameters& par,
00042                               const CartesianTrajectoryError& err,
00043                               const Surface& aSurface,
00044                               const SurfaceSide side = atCenterOfSurface);
00049   BasicSingleTrajectoryState( const GlobalTrajectoryParameters& par,
00050                               const CurvilinearTrajectoryError& err,
00051                               const Surface& aSurface,
00052                               const SurfaceSide side = atCenterOfSurface,
00053                               double weight = 1.);
00058   BasicSingleTrajectoryState( const GlobalTrajectoryParameters& par,
00059                               const CurvilinearTrajectoryError& err,
00060                               const Surface& aSurface,
00061                               double weight);
00065   BasicSingleTrajectoryState( const LocalTrajectoryParameters& par,
00066                               const Surface& aSurface,
00067                               const MagneticField* field,
00068                               const SurfaceSide side = atCenterOfSurface);
00073   BasicSingleTrajectoryState( const LocalTrajectoryParameters& par,
00074                               const LocalTrajectoryError& err,
00075                               const Surface& aSurface,
00076                               const MagneticField* field,
00077                               const SurfaceSide side = atCenterOfSurface,
00078                               double weight = 1.);
00083   BasicSingleTrajectoryState( const LocalTrajectoryParameters& par,
00084                               const LocalTrajectoryError& err,
00085                               const Surface& aSurface,
00086                               const MagneticField* field,
00087                               double weight);
00088 
00090   BasicSingleTrajectoryState(const Surface& aSurface);
00091 
00092   virtual ~BasicSingleTrajectoryState();
00093 
00094   bool isValid() const {
00095     return theFreeState || theLocalParametersValid;
00096   }
00097 
00098   bool hasError() const {
00099     return (theFreeState && theFreeState->hasError()) || theLocalErrorValid;
00100   }
00101 
00102 // access global parameters/errors
00103   const GlobalTrajectoryParameters& globalParameters() const {
00104     return freeTrajectoryState(false)->parameters();
00105   }
00106   GlobalPoint globalPosition() const {
00107     return freeTrajectoryState(false)->position();
00108   }
00109   GlobalVector globalMomentum() const {
00110     return freeTrajectoryState(false)->momentum();
00111   }
00112   GlobalVector globalDirection() const {
00113     return freeTrajectoryState(false)->momentum().unit();
00114   }  
00115   TrackCharge charge() const {
00116     return freeTrajectoryState(false)->charge();
00117   }
00118   double signedInverseMomentum() const {
00119     return freeTrajectoryState(false)->signedInverseMomentum();
00120   }
00121   double transverseCurvature() const {
00122     return freeTrajectoryState(false)->transverseCurvature();
00123   }
00124   const CartesianTrajectoryError& cartesianError() const {
00125     if(!hasError()) throw TrajectoryStateException(
00126      "TrajectoryStateOnSurface: attempt to access cartesian errors when none available");
00127     return freeTrajectoryState()->cartesianError();
00128   }
00129   const CurvilinearTrajectoryError& curvilinearError() const {
00130     if(!hasError()) throw TrajectoryStateException(
00131      "TrajectoryStateOnSurface: attempt to access curvilinear errors when none available");
00132     return freeTrajectoryState()->curvilinearError();
00133   }
00134   FreeTrajectoryState* freeTrajectoryState(bool withErrors = true) const {
00135     if(!isValid()) throw TrajectoryStateException(
00136       "TrajectoryStateOnSurface is invalid and cannot return any parameters");
00137     checkGlobalParameters();
00138     //if(hasError()) { // let's start like this to see if we alloc less
00139     if(withErrors && hasError()) { // this is the right thing
00140       checkCartesianError();
00141       checkCurvilinError();
00142     }
00143     return &(*theFreeState);
00144   }
00145   
00146   const MagneticField *magneticField() const { return theField; }
00147 
00148 // access local parameters/errors
00149   const LocalTrajectoryParameters& localParameters() const {
00150     if (!isValid()) throw TrajectoryStateException(
00151       "TrajectoryStateOnSurface is invalid and cannot return any parameters");
00152     if (!theLocalParametersValid)
00153       createLocalParameters();
00154     return theLocalParameters;
00155   }
00156   LocalPoint localPosition() const {
00157     return localParameters().position();
00158   }
00159   LocalVector localMomentum() const {
00160     return localParameters().momentum();
00161   }
00162   LocalVector localDirection() const {
00163     return localMomentum().unit();
00164   }
00165   const LocalTrajectoryError& localError() const {
00166     if (!hasError()) throw TrajectoryStateException(
00167       "TrajectoryStateOnSurface: attempt to access errors when none available");
00168     if (!theLocalErrorValid)
00169       createLocalError();
00170     return theLocalError;
00171   }
00172 
00173   const Surface& surface() const {
00174     return *theSurfaceP;
00175   }
00176 
00177   virtual double weight() const {return theWeight;} 
00178 
00179   void rescaleError(double factor) {
00180     if (!hasError()) throw TrajectoryStateException(
00181       "TrajectoryStateOnSurface: attempt to access errors when none available");
00182     if (theLocalErrorValid) theLocalError *= (factor*factor);
00183     if (theFreeState)
00184       theFreeState->rescaleError(factor);
00185   }
00186 
00187   BasicSingleTrajectoryState* clone() const {
00188     return new BasicSingleTrajectoryState(*this);
00189   }
00190 
00192   virtual SurfaceSide surfaceSide() const {
00193     return theSurfaceSide;
00194   }
00195 
00196 private:
00197 
00198 // create global parameters and errors from local
00199   void checkGlobalParameters() const;
00200   void checkCurvilinError() const;
00201   void checkCartesianError() const;
00202 
00203 // create local parameters and errors from global
00204   void createLocalParameters() const;
00205   // create local errors from global
00206   void createLocalError() const;
00207   void createLocalErrorFromCartesianError() const;
00208   void createLocalErrorFromCurvilinearError() const;
00209 
00210 private:
00211 
00212   mutable DeepCopyPointer<FreeTrajectoryState> theFreeState;
00213 
00214   mutable bool theGlobalParamsUp2Date;
00215   mutable bool theCartesianErrorUp2Date;
00216   mutable bool theCurvilinErrorUp2Date;
00217 
00218   mutable LocalTrajectoryParameters theLocalParameters;
00219   mutable LocalTrajectoryError      theLocalError;
00220   mutable bool                      theLocalParametersValid;
00221   mutable bool                      theLocalErrorValid;
00222 
00223   ConstReferenceCountingPointer<Surface> theSurfaceP;
00224   const SurfaceSide theSurfaceSide;
00225   double theWeight;
00226   const MagneticField* theField;
00227 
00228 };
00229 
00230 #endif

Generated on Tue Jun 9 17:48:35 2009 for CMSSW by  doxygen 1.5.4