CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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/GCC11Compatibility.h"
00029 
00031 // #include <iostream>
00032 
00033 //class MagneticField;
00034 #include "MagneticField/Engine/interface/MagneticField.h"
00035 
00036 
00037 
00038 class TrajectoryStateOnSurface;
00039 
00040 
00041 #ifdef DO_BTSCount
00042 class BTSCount {
00043 public:
00044   BTSCount(){}
00045   virtual ~BTSCount();
00046   BTSCount(BTSCount const &){} 
00047 
00048   static unsigned int  maxReferences;
00049   static unsigned long long  aveReferences;
00050   static unsigned long long  toteReferences;
00051 
00052   void addReference() const { ++referenceCount_ ; referenceMax_ = std::max(referenceMax_, referenceCount_); }
00053   void removeReference() const { 
00054     if( 0 == --referenceCount_ ) {
00055       delete const_cast<BTSCount*>(this);
00056     }
00057   }
00058   
00059   unsigned int references() const {return referenceCount_;}
00060 private :
00061 #ifdef CMS_NOCXX11
00062   mutable unsigned int referenceCount_;
00063   mutable unsigned int referenceMax_;
00064 #else
00065   mutable unsigned int referenceCount_=0;
00066   mutable unsigned int referenceMax_ =0;
00067 #endif
00068 };
00069 #else
00070 typedef ReferenceCountedInEvent  BTSCount;
00071 #endif
00072 
00079 class BasicTrajectoryState : public BTSCount {
00080   public:
00081 
00082   typedef BasicTrajectoryState                              BTSOS;
00083   typedef ProxyBase< BTSOS, CopyUsingClone<BTSOS> >         Proxy;
00084   typedef ReferenceCountingPointer<BasicTrajectoryState>    RCPtr;
00085   typedef SurfaceSideDefinition::SurfaceSide SurfaceSide;
00086   typedef Surface SurfaceType;
00087 
00088 private:
00089   friend class ProxyBase< BTSOS, CopyUsingClone<BTSOS> >;
00090   friend class ReferenceCountingPointer<BasicTrajectoryState>;
00091 public:
00092 
00093   // default constructor : to make root happy
00094   BasicTrajectoryState() : theValid(false), theWeight(0){}
00095 
00097   explicit BasicTrajectoryState(const SurfaceType& aSurface);
00098 
00099   virtual ~BasicTrajectoryState();
00100 
00104   BasicTrajectoryState( const FreeTrajectoryState& fts,
00105                               const SurfaceType& aSurface,
00106                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
00110   BasicTrajectoryState( const GlobalTrajectoryParameters& par,
00111                               const SurfaceType& aSurface,
00112                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
00116   BasicTrajectoryState( const GlobalTrajectoryParameters& par,
00117                               const CartesianTrajectoryError& err,
00118                               const SurfaceType& aSurface,
00119                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
00120 
00125   BasicTrajectoryState( const GlobalTrajectoryParameters& par,
00126                               const CurvilinearTrajectoryError& err,
00127                               const SurfaceType& aSurface,
00128                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface,
00129                               double weight = 1.);
00134   BasicTrajectoryState( const GlobalTrajectoryParameters& par,
00135                               const CurvilinearTrajectoryError& err,
00136                               const SurfaceType& aSurface,
00137                               double weight);
00141   BasicTrajectoryState( const LocalTrajectoryParameters& par,
00142                               const SurfaceType& aSurface,
00143                               const MagneticField* field,
00144                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface);
00149   BasicTrajectoryState( const LocalTrajectoryParameters& par,
00150                               const LocalTrajectoryError& err,
00151                               const SurfaceType& aSurface,
00152                               const MagneticField* field,
00153                               const SurfaceSide side = SurfaceSideDefinition::atCenterOfSurface,
00154                               double weight = 1.);
00159   BasicTrajectoryState( const LocalTrajectoryParameters& par,
00160                               const LocalTrajectoryError& err,
00161                               const SurfaceType& aSurface,
00162                               const MagneticField* field,
00163                               double weight);
00164 
00165   bool isValid() const { return theValid; }
00166 
00167 
00168 // access global parameters/errors
00169   const GlobalTrajectoryParameters& globalParameters() const {
00170     return theFreeState.parameters();
00171   }
00172   GlobalPoint globalPosition() const {
00173     return theFreeState.position();
00174   }
00175   GlobalVector globalMomentum() const {
00176     return theFreeState.momentum();
00177   }
00178   GlobalVector globalDirection() const {
00179     return theFreeState.momentum().unit();
00180   }  
00181   TrackCharge charge() const {
00182     return theFreeState.charge();
00183   }
00184   double signedInverseMomentum() const {
00185     return theFreeState.signedInverseMomentum();
00186   }
00187   double transverseCurvature() const {
00188     return theFreeState.transverseCurvature();
00189   }
00190 
00191   const CartesianTrajectoryError cartesianError() const {
00192     if unlikely(!hasError()) {
00193         missingError(" accesing cartesian error.");
00194         return CartesianTrajectoryError();
00195       }
00196     return freeTrajectoryState(true)->cartesianError();
00197   }
00198   const CurvilinearTrajectoryError& curvilinearError() const {
00199     if unlikely(!hasError()) {
00200         missingError(" accesing curvilinearerror.");
00201         static CurvilinearTrajectoryError crap;
00202         return crap;
00203       }
00204     return freeTrajectoryState(true)->curvilinearError();
00205   }
00206 
00207 
00208 
00209   FreeTrajectoryState* freeTrajectoryState(bool withErrors=true) const {
00210     if unlikely(!isValid()) notValid();
00211     if(withErrors && hasError()) { // this is the right thing
00212       checkCurvilinError();
00213     }
00214     return &theFreeState;
00215   }
00216 
00217   
00218   const MagneticField *magneticField() const { return &theFreeState.parameters().magneticField(); }
00219 
00220 // access local parameters/errors
00221   const LocalTrajectoryParameters& localParameters() const {
00222     if unlikely(!isValid()) notValid();
00223     if unlikely(!theLocalParametersValid)
00224       createLocalParameters();
00225     return theLocalParameters;
00226   }
00227   LocalPoint localPosition() const {
00228     return localParameters().position();
00229   }
00230   LocalVector localMomentum() const {
00231     return localParameters().momentum();
00232   }
00233   LocalVector localDirection() const {
00234     return localMomentum().unit();
00235   }
00236 
00237   const LocalTrajectoryError& localError() const {
00238     if unlikely(!hasError()) {
00239         missingError(" accessing local error.");
00240         return theLocalError;
00241       }
00242     if unlikely(theLocalError.invalid()) createLocalError();
00243     return theLocalError;
00244   }
00245 
00246   const SurfaceType& surface() const {
00247     return *theSurfaceP;
00248   }
00249 
00250   double weight() const {return theWeight;} 
00251 
00252   void rescaleError(double factor);
00253 
00254 
00255 
00257   SurfaceSide surfaceSide() const {
00258     return theSurfaceSide;
00259   }
00260 
00261   bool hasError() const {
00262     return theFreeState.hasError() || theLocalError.valid();
00263   }
00264 
00265 
00266   virtual BasicTrajectoryState* clone() const=0;
00267 
00268   virtual bool canUpdateLocalParameters() const { return true; }
00269 
00270   virtual void update( const LocalTrajectoryParameters& p,
00271                        const SurfaceType& aSurface,
00272                        const MagneticField* field,
00273                        const SurfaceSide side ) ;
00274 
00275   virtual void update( const LocalTrajectoryParameters& p,
00276                        const LocalTrajectoryError& err,
00277                        const SurfaceType& aSurface,
00278                        const MagneticField* field,
00279                        const SurfaceSide side,
00280                        double weight ) ;
00281 
00282 public:
00283   virtual std::vector<TrajectoryStateOnSurface> components() const;
00284 
00285 private:
00286 
00287   static void notValid();
00288 
00289   
00290   void missingError(char const * where) const; // dso_internal;
00291 
00292   // create global errors from local
00293   void checkCurvilinError() const; //  dso_internal;
00294   
00295   // create local parameters and errors from global
00296   void createLocalParameters() const;
00297   // create local errors from global
00298   void createLocalError() const;
00299   void createLocalErrorFromCurvilinearError() const  dso_internal;
00300   
00301 private:
00302 
00303   mutable FreeTrajectoryState theFreeState;
00304 
00305   mutable LocalTrajectoryError      theLocalError;
00306   mutable LocalTrajectoryParameters theLocalParameters;
00307 
00308   mutable bool theLocalParametersValid;
00309   mutable bool theValid;
00310 
00311  
00312   SurfaceSide theSurfaceSide;
00313   ConstReferenceCountingPointer<SurfaceType> theSurfaceP;
00314 
00315   double theWeight;
00316 
00317 };
00318 
00319 #endif