CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/TrackingTools/TrajectoryState/interface/BasicTrajectoryState.h

Go to the documentation of this file.
00001 #ifndef BasicTrajectoryState_H
00002 #define BasicTrajectoryState_H
00003 
00004 #include "TrackingTools/TrajectoryState/interface/ProxyBase.h"
00005 #include "DataFormats/GeometrySurface/interface/ReferenceCounted.h"
00006 #include "TrackingTools/TrajectoryState/interface/CopyUsingClone.h"
00007 
00008 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryParameters.h"
00009 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryError.h"
00010 #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h"
00011 #include "TrackingTools/TrajectoryParametrization/interface/CartesianTrajectoryError.h"
00012 #include "TrackingTools/TrajectoryParametrization/interface/CurvilinearTrajectoryError.h"
00013 #include "TrackingTools/TrajectoryState/interface/SurfaceSideDefinition.h"
00014 
00015 #include <vector>
00016 
00017 
00018 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00019 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryParameters.h"
00020 #include "TrackingTools/TrajectoryParametrization/interface/LocalTrajectoryError.h"
00021 
00022 #include "DataFormats/GeometrySurface/interface/ReferenceCounted.h"
00023 
00024 #include "DataFormats/GeometryCommonDetAlgo/interface/DeepCopyPointer.h"
00025 #include "DataFormats/GeometrySurface/interface/Surface.h"
00026 #include "TrackingTools/TrajectoryParametrization/interface/TrajectoryStateExceptions.h"
00027 
00028 #include "FWCore/Utilities/interface/Visibility.h"
00029 #include "FWCore/Utilities/interface/Likely.h"
00030 
00032 #include <iostream>
00033 
00034 //class MagneticField;
00035 #include "MagneticField/Engine/interface/MagneticField.h"
00036 
00037 
00038 
00039 class TrajectoryStateOnSurface;
00040 
00041 
00048 class BasicTrajectoryState : public ReferenceCountedInEvent  {
00049 public:
00050 
00051   typedef BasicTrajectoryState                              BTSOS;
00052   typedef ProxyBase< BTSOS, CopyUsingClone<BTSOS> >         Proxy;
00053   typedef ReferenceCountingPointer<BasicTrajectoryState>    RCPtr;
00054   typedef SurfaceSideDefinition::SurfaceSide SurfaceSide;
00055 
00056 private:
00057   friend class ProxyBase< BTSOS, CopyUsingClone<BTSOS> >;
00058   friend class ReferenceCountingPointer<BasicTrajectoryState>;
00059 public:
00060 
00061   // default constructor : to make root happy
00062   BasicTrajectoryState(){}
00063 
00065   explicit BasicTrajectoryState(const Surface& aSurface);
00066 
00067   virtual ~BasicTrajectoryState();
00068 
00072   BasicTrajectoryState( const FreeTrajectoryState& fts,
00073                               const Surface& aSurface,
00074                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
00078   BasicTrajectoryState( const GlobalTrajectoryParameters& par,
00079                               const Surface& aSurface,
00080                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
00084   BasicTrajectoryState( const GlobalTrajectoryParameters& par,
00085                               const CartesianTrajectoryError& err,
00086                               const Surface& aSurface,
00087                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
00088 
00093   BasicTrajectoryState( const GlobalTrajectoryParameters& par,
00094                               const CurvilinearTrajectoryError& err,
00095                               const Surface& aSurface,
00096                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface,
00097                               double weight = 1.);
00102   BasicTrajectoryState( const GlobalTrajectoryParameters& par,
00103                               const CurvilinearTrajectoryError& err,
00104                               const Surface& aSurface,
00105                               double weight);
00109   BasicTrajectoryState( const LocalTrajectoryParameters& par,
00110                               const Surface& aSurface,
00111                               const MagneticField* field,
00112                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
00117   BasicTrajectoryState( const LocalTrajectoryParameters& par,
00118                               const LocalTrajectoryError& err,
00119                               const Surface& aSurface,
00120                               const MagneticField* field,
00121                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface,
00122                               double weight = 1.);
00127   BasicTrajectoryState( const LocalTrajectoryParameters& par,
00128                               const LocalTrajectoryError& err,
00129                               const Surface& aSurface,
00130                               const MagneticField* field,
00131                               double weight);
00132 
00133  
00134   bool isValid() const {
00135     return theFreeState || theLocalParametersValid;
00136   }
00137 
00138 
00139 // access global parameters/errors
00140   const GlobalTrajectoryParameters& globalParameters() const {
00141     return freeTrajectoryState(false)->parameters();
00142   }
00143   GlobalPoint globalPosition() const {
00144     return freeTrajectoryState(false)->position();
00145   }
00146   GlobalVector globalMomentum() const {
00147     return freeTrajectoryState(false)->momentum();
00148   }
00149   GlobalVector globalDirection() const {
00150     return freeTrajectoryState(false)->momentum().unit();
00151   }  
00152   TrackCharge charge() const {
00153     return freeTrajectoryState(false)->charge();
00154   }
00155   double signedInverseMomentum() const {
00156     return freeTrajectoryState(false)->signedInverseMomentum();
00157   }
00158   double transverseCurvature() const {
00159     return freeTrajectoryState(false)->transverseCurvature();
00160   }
00161 
00162   const CartesianTrajectoryError cartesianError() const {
00163     if unlikely(!hasError()) {
00164         missingError(" accesing cartesian error.");
00165         return CartesianTrajectoryError();
00166       }
00167     return freeTrajectoryState()->cartesianError();
00168   }
00169   const CurvilinearTrajectoryError& curvilinearError() const {
00170     if unlikely(!hasError()) {
00171         missingError(" accesing curvilinearerror.");
00172         static CurvilinearTrajectoryError crap;
00173         return crap;
00174       }
00175     return freeTrajectoryState()->curvilinearError();
00176   }
00177 
00178 
00179   FreeTrajectoryState* freeTrajectoryState(bool withErrors = true) const;
00180   
00181   const MagneticField *magneticField() const { return theField; }
00182 
00183 // access local parameters/errors
00184   const LocalTrajectoryParameters& localParameters() const {
00185     if unlikely(!isValid()) notValid();
00186     if unlikely(!theLocalParametersValid)
00187       createLocalParameters();
00188     return theLocalParameters;
00189   }
00190   LocalPoint localPosition() const {
00191     return localParameters().position();
00192   }
00193   LocalVector localMomentum() const {
00194     return localParameters().momentum();
00195   }
00196   LocalVector localDirection() const {
00197     return localMomentum().unit();
00198   }
00199 
00200   const LocalTrajectoryError& localError() const {
00201     if unlikely(!hasError()) {
00202         missingError(" accessing local error.");
00203         return theLocalError;
00204       }
00205     if unlikely(theLocalError.invalid()) createLocalError();
00206     return theLocalError;
00207   }
00208 
00209   const Surface& surface() const {
00210     return *theSurfaceP;
00211   }
00212 
00213   virtual double weight() const {return theWeight;} 
00214 
00215   void rescaleError(double factor);
00216 
00217 
00218 
00220   SurfaceSide surfaceSide() const {
00221     return theSurfaceSide;
00222   }
00223 
00224   bool hasError() const {
00225     return (theFreeState && theFreeState->hasError()) || theLocalError.valid();
00226   }
00227 
00228 
00229   virtual BasicTrajectoryState* clone() const=0;
00230 
00231   virtual bool canUpdateLocalParameters() const { return true; }
00232 
00233   virtual void update( const LocalTrajectoryParameters& p,
00234                        const Surface& aSurface,
00235                        const MagneticField* field,
00236                        const SurfaceSide side ) ;
00237 
00238   virtual void update( const LocalTrajectoryParameters& p,
00239                        const LocalTrajectoryError& err,
00240                        const Surface& aSurface,
00241                        const MagneticField* field,
00242                        const SurfaceSide side,
00243                        double weight ) ;
00244 
00245 public:
00246   virtual std::vector<TrajectoryStateOnSurface> components() const;
00247 
00248 private:
00249 
00250   static void notValid();
00251 
00252   
00253   void missingError(char const * where) const; // dso_internal;
00254 
00255 // create global parameters and errors from local
00256   void checkGlobalParameters() const dso_internal;
00257   void checkCurvilinError() const  dso_internal;
00258 
00259 // create local parameters and errors from global
00260   void createLocalParameters() const;
00261   // create local errors from global
00262   void createLocalError() const;
00263   void createLocalErrorFromCurvilinearError() const  dso_internal;
00264 
00265 private:
00266 
00267   mutable DeepCopyPointer<FreeTrajectoryState> theFreeState;
00268 
00269   mutable LocalTrajectoryError      theLocalError;
00270   mutable LocalTrajectoryParameters theLocalParameters;
00271 
00272   mutable bool theLocalParametersValid;
00273   mutable bool theGlobalParamsUp2Date;
00274 
00275  
00276   SurfaceSide theSurfaceSide;
00277   ConstReferenceCountingPointer<Surface> theSurfaceP;
00278 
00279   double theWeight;
00280   const MagneticField* theField;
00281 
00282 };
00283 
00284 #endif