Base_Navigator.h

Go to the documentation of this file.
00001 //     Authors:
00002 // Anselmo Cervera, Juan J. Gomez-Cadenas and Jose Angel Hernando
00003 
00004 #ifndef Navigator_h
00005 #define Navigator_h 1
00006 
00007 #include <assert.h>
00008 
00009 #include "Kalman/Interface_IModel.h"
00010 #include "Kalman/Interface_IModelConverter.h"
00011 #include "Kalman/Interface_IVolumeIntersector.h"
00012 #include "Kalman/Interface_IModelSurfaceIntersector.h"
00013 #include "Kalman/Interface_ITrajectory.h"
00014 #include "Kalman/Base_Setup.h"
00015 
00016 
00017 //! This is the machine that operate Trajectories, Points and States
00018 //! This machine can:
00019 //!     -Fit a trajectory using a IFitter.
00020 //!     -Propagate an state using a IPropagator (belonging to the model)
00021 //!     -Project states or points using a IProjector. (belonging tothe model)
00022 //! The User can set a Fitter to fit trajectories.
00023 //! The User can set a Trajectory Model to be use by the fitter
00024 
00025 
00026 class Navigator
00027 {
00028 public:
00029       
00030   
00031   //! default constructor
00032   Navigator(){m_verbosity = 0;}
00033 
00034   //! constructor with selection of Model in a unique volume
00035   Navigator(std::string Model) { std::cout << "NavigatorB constructor called with " << Model << std::endl; } //ME added warning cout
00036   
00037   //! default destructor
00038   virtual ~Navigator(){};
00039 
00040 
00041   //-------------  Model  with respect to a Volume-----------------------------
00042 
00043   //! add a model to the list
00044   void addVolumeIntersector(std::string volumeType, IVolumeIntersector* p)
00045     {m_volumeIntersectorMap[volumeType]=p;}  
00046 
00047   bool enterInVolume(const IState& iniState, 
00048                  const std::vector<std::string> nextVolVector, 
00049                  const std::string thisModelName, 
00050                  int sens,
00051                  std::string& nextVolName, 
00052                  ISurface& intersectedSurf,
00053                  HyperVector& runHV);
00054 
00055   bool exitFromVolume(const IState& iniState, 
00056                   const std::string thisVolName, 
00057                   const std::string thisModelName, 
00058                   int sens,
00059                   ISurface& intersectedSurf,
00060                   HyperVector& runHV);
00061 
00062   //! compute the running sens
00063   int computeSens(const IState& iniState, const ISurface& endSurf) const;  
00064 
00065   //--------------- INTERPRETATION OF STATE PARAMETERS ------------------------------
00066 
00067   //! interpretation of states
00068   const EVector directionVector(const IState& state) 
00069     {return model(state.modelName()).directionVector(state);}  
00070   const EVector positionVector(const IState& state)  
00071     {return model(state.modelName()).positionVector(state);}  
00072   const EMatrix directionMatrix(const IState& state) 
00073     {return model(state.modelName()).directionMatrix(state);}  
00074   const EMatrix positionMatrix(const IState& state) 
00075     {return model(state.modelName()).positionMatrix(state);}  
00076   const EVector momentumVector(const IState& state) 
00077     {return model(state.modelName()).momentumVector(state);}  
00078   const EMatrix momentumMatrix(const IState& state) 
00079     {return model(state.modelName()).momentumMatrix(state);}  
00080   const double momentum(const IState& state) 
00081     {return model(state.modelName()).momentum(state);}  
00082   const double momentumError2(const IState& state) 
00083     {return model(state.modelName()).momentumError2(state);}  
00084   const double charge(const IState& state) 
00085     {return model(state.modelName()).charge(state);}  
00086 
00087 
00088   //! interpretation of vertex parameters
00089   const EVector directionVectorVertex(const IState& state) 
00090     {return model(state.modelName()).directionVectorVertex(state);}  
00091   const EVector positionVectorVertex(const IState& state)  
00092     {return model(state.modelName()).positionVectorVertex(state);}  
00093   const EMatrix directionMatrixVertex(const IState& state) 
00094     {return model(state.modelName()).directionMatrixVertex(state);}  
00095   const EMatrix positionMatrixVertex(const IState& state) 
00096     {return model(state.modelName()).positionMatrixVertex(state);}  
00097   const EVector momentumVectorVertex(const IState& state) 
00098     {return model(state.modelName()).momentumVectorVertex(state);}  
00099   const EMatrix momentumMatrixVertex(const IState& state) 
00100     {return model(state.modelName()).momentumMatrixVertex(state);}  
00101 
00102   const EMatrix positionMomentumMatrixVertex(const IState& state) 
00103     {return model(state.modelName()).positionMomentumMatrixVertex(state);}  
00104 
00105 
00106   //-------------  MODELS ----------------------------------------------------
00107 
00108   //! add a model to the list
00109   void addModel(std::string name, IModel* p)
00110     { p->setVerbosity(m_verbosity);
00111       p->setName(name); 
00112       m_modelMap[name]=p;
00113     }  
00114 
00115   //! add a model to the list whith specific properties
00116   void addModel(std::string name, IModel* p, void* prop)
00117     { p->setModelProperties(prop);
00118       p->setVerbosity(m_verbosity);
00119       p->setName(name); 
00120       m_modelMap[name]=p;
00121     }  
00122 
00123 
00124 
00125   //! returns specific model properties 
00126   std::string modelProperties(std::string modelName)
00127     {return m_modelMap[modelName]->modelProperties();}
00128   //! set properties of the model in the case there is a choice
00129   void setModelProperties(std::string modelName, void* prop)
00130      {m_modelMap[modelName]->setModelProperties(prop);} 
00131 
00132   //! Returns the model name in a given volume
00133   std::string modelNameInVolume(std::string volName) {return volume(volName).modelName();}
00134   
00135   //-------  PROJECTOR, PROPAGATOR AND NOISER ARE CONTAINED IN THE MODELS
00136 
00137   //! add a projector to the model
00138   void addModelProjector(std::string modelName,std::string name, IProjector* p) 
00139       {m_modelMap[modelName]->addProjector(name,p);}
00140 
00141   //! project the state of the point 
00142   bool project(IPoint& point)
00143     {return m_modelMap[ point.modelName() ]->project(point);} 
00144   
00145   //!   Project the dynamic vector
00146   EVector projectionVector(const IState& state, const IMeasurement& meas)
00147     {return m_modelMap[state.modelName() ]->projectionVector(state, meas);}  
00148 
00149 
00150 
00151   //!   Project the dynamic matrix
00152   EMatrix projectionMatrix(const IState& state, const IMeasurement& meas)
00153     {return m_modelMap[ state.modelName() ]->projectionMatrix(state, meas);}  
00154 
00155   //!   Project the dynamicHV
00156   HyperVector projectionHV(const IState& state, const IMeasurement& meas)
00157     {return m_modelMap[ state.modelName() ]->projectionHV(state, meas);}
00158 
00159 
00160 
00161   //! returns the H matrix for the state
00162   EMatrix HMatrix(const IState& state, const IMeasurement& meas)
00163     {return m_modelMap[state.modelName() ]->HMatrix(state, meas);}  
00164 
00165 
00166   //! Returns the A matrix (dx/dr) for the Kalman vertex fit
00167   EMatrix AMatrix(const IState& state, const IMeasurement& meas)
00168     {return m_modelMap[ state.modelName() ]->AMatrix(state, meas);}
00169 
00170   //! Returns the B matrix (dx/dp) for the Kalman vertex fit
00171   EMatrix BMatrix(const IState& state, const IMeasurement& meas)
00172     {return m_modelMap[ state.modelName() ]->BMatrix(state, meas);}
00173 
00174 
00175   //! Returns the c0 vector  for the Kalman vertex fit
00176   EVector c0(const IState& state, const IMeasurement& meas)
00177     {return m_modelMap[ state.modelName() ]->c0(state, meas);}
00178 
00179 
00180   
00181   EMatrix measurementProjector(const IState& state, const IMeasurement& meas)
00182     {return m_modelMap[ state.modelName() ]->measurementProjector(state, meas);}
00183 
00184   //--------
00185 
00186 
00187   //! returns the propagator name
00188   std::string modelPropagatorName(std::string modelName) 
00189     {return m_modelMap[modelName]->propagatorName();}
00190   //! add a propagator to the model
00191   void addModelPropagator(std::string modelName,std::string name, IPropagator* p) 
00192     {m_modelMap[modelName]->addPropagator(name,p);}
00193   //! set the propagator to the model
00194   void setModelPropagator(std::string modelName,std::string name) 
00195     {m_modelMap[modelName]->setPropagator(name);}
00196 
00197 
00198   //!   If the Propagator it is linear returns the F matrix
00199   //!   (if not returns the 1st term of Taylor expansion)
00200   EMatrix FMatrix()  {return m_F;}
00201   
00202   //!   Returns the matrix of random extra errors added to the state during the
00203   //!   progation (null if non). This matrix is calculated by the Noiser.
00204   EMatrix QMatrix() {return m_Q;}
00205   
00206 
00207 
00208   //! Propagate an state to a surface
00209   //! It compute the dynamicHV and the runningHV in the new surface, set the values in the state
00210   //! It has the extra possibility of propagate an state with a different model
00211 
00212   bool propagate(const IState& iniState,
00213              const ISurface& surface, 
00214              IState& finalState);
00215   
00216   bool propagate(const ITrajectory& traj,
00217              const ISurface& surface, 
00218              IState& finalState);
00219   
00220 
00221 
00222   //!  Returns the dynamicHV of the state when propagate an state to a surface
00223   HyperVector propagateDynamicHV(const IState& ini, const ISurface& is);
00224 
00225   //!  Computes the running HyperVector to a given surface
00226   HyperVector propagateRunningHV(const IState& iniState, const ISurface& surf);
00227 
00228   //! Computes the path length between a state and a surface
00229   bool pathLength(const IState& state, const ISurface& surf, HyperDouble& hd);
00230   bool pathLength(const IState& state, std::string logObjectName, HyperDouble& hd);
00231 
00232 
00233   //! Computes the path length from the beginning to the end of a trjectory
00234   //! (firstPointUsed to lastPointUsed)
00235   //! It also compute the partial length from the firstPointUsed to the i-th point
00236   void computePathLength(ITrajectory& traj);  
00237 
00238   //! Computes the path length from the firstPointUsed to a given surface 
00239   bool pathLength(ITrajectory& traj, const ISurface& endSurf, HyperDouble& length);
00240 
00241   //! Computes the path length from the firstPointUsed to the entrance of a logical object
00242   bool pathLength(ITrajectory& traj, std::string logObjectName, HyperDouble& length);
00243  
00244   //! Computes the path length from the one surface to another provided a fitted trajectory
00245   bool pathLength(ITrajectory& traj, 
00246               const ISurface& iniSurf, 
00247               const ISurface& endSurf, 
00248               HyperDouble& length);  
00249 
00250 
00251   // computes the path lentgh between a state and a straight line, 
00252   // providing rl0 and ul0 such that rl = rl0 + ul0*s
00253   double pathLengthToStraightLine(const IState& iniS, 
00254                   const EVector& rl0,
00255                   const EVector& ul0)
00256     {return model(iniS.modelName()).pathLengthToStraightLine(iniS,rl0,ul0);}
00257 
00258 
00259   /*
00260   //! set propagator verbosity 
00261   void setPropagatorVerbosity(std::string modelName, int v)
00262     {m_modelMap[modelName]->setPropagatorVerbosity(v);}
00263   //! returns specific propagator properties
00264   std::string propagatorProperties(std::string modelName)
00265     {return m_modelMap[modelName]->propagatorProperties();}
00266   //! set properties of the propagator in the case there is a choice
00267   void setPropagatorProperties(std::string modelName, void* prop)
00268      {m_modelMap[modelName]->setPropagatorProperties(prop);} 
00269   */
00270 
00271 
00272   //-------------
00273 
00274   //! add a noiser to the model
00275   void addModelNoiser(std::string modelName, std::string name, INoiser* p) 
00276     {m_modelMap[modelName]->addNoiser(name, p);}
00277   //! set is/(is not) used 
00278   void setModelNoiserIsUsed(std::string modelName, std::string name, bool flag) 
00279     {m_modelMap[modelName]->setNoiserIsUsed(name,flag);}
00280 
00281   //--------------
00282 
00283   //! add a model converter
00284   void addModelConverter(std::string firstModel, std::string secondModel, IModelConverter* mc) {
00285     mc->setFirstModel(firstModel); mc->setSecondModel(secondModel); 
00286     m_modelConverterVector.push_back(mc);
00287   }
00288   
00289 
00290   //! converts state from a model to another
00291   bool convertModelState(std::string modelName, IState& state);
00292 
00293     
00294   //! convers a square matrix from a model to another
00295   EMatrix convertModelFMatrix(std::string iniModel, 
00296                       IState& iniS, IState& endS);
00297 
00298 
00299 
00300   //------------
00301 
00302   //! add a SurfaceIntersector to the model
00303   void addModelSurfaceIntersector(std::string modelName, 
00304                       std::string name, 
00305                       IModelSurfaceIntersector* p) 
00306     {m_modelMap[modelName]->addSurfaceIntersector(name,p);}
00307 
00308 
00309   //! builds a surface normal to the trajectory and computes the natural parameter 
00310   bool naturalHVAtNormalSurface(const IState& prevState, 
00311                     const HyperVector& measHV,
00312                     const std::string surfType,
00313                     ISurface& surf,
00314                     HyperVector& natHV)
00315     {return m_modelMap[prevState.modelName()]->naturalHVAtNormalSurface(prevState,
00316                                     measHV,
00317                                     surfType,
00318                                     surf,
00319                                     natHV);}
00320 
00321 
00322   //! build the surface normal to the running direction 
00323   void runningSurface(const IMeasurement& meas,
00324                   ISurface& surf);
00325   void runningSurface(const IMeasurement& meas,
00326                   const std::string modelName,
00327                   ISurface& surf);
00328 
00329 
00330   //! Computes the surface in which the residual will be calculated (according to surfacePropagation()) and
00331   //! set it to the point 
00332   bool computeResidualSurface(const IState& iniS,
00333                       const IMeasurement& meas,
00334                       ISurface& surf);
00335 
00336 
00337   //! returns the residual surface type
00338   void setResidualSurfaceType(std::string type) {m_residualSurfaceType = type;}
00339   std::string residualSurfaceType() const {return m_residualSurfaceType;}
00340 
00341   
00342   //! Computes the residual and set it to the point 
00343   void computeResidual(IPoint& point);
00344 
00345 
00346   //---------------- SETUP ---------------------
00347 
00348   //! set the setup 
00349   void setSetup(Setup& p){m_setup = &p;}
00350 
00351   //! Returns a reference to the volume
00352     IVolume& volume(std::string name="") const
00353        {return setup().volume(name);} 
00354 
00355 
00356   //---------- UTILITIES ------------------------
00357 
00358   //! returns the closest point to a surface
00359   IPoint& closestPointToSurface (const ITrajectory& traj, const ISurface& surf) const;
00360   IPoint& closestUpdatedPointToSurface (const ITrajectory& traj, const ISurface& surf) const;
00361 
00362   //! returns the closest point to a measurement
00363   IPoint& closestUpdatedPointToMeasurement(const ITrajectory& traj, const IMeasurement& meas) const;
00364 
00365   double distanceFromPointToSurface(const IPoint& point, const ISurface& surf) const;
00366   double distanceFromPointToMeasurement(const IPoint& point, const IMeasurement& meas) const;
00367 
00368   //--------------- GENERAL ------------------
00369 
00370   //! get dimension of the dynamic vector for a given model
00371   const int dynamicNdim(std::string modelName) {return m_modelMap[modelName]->dynamicNdim();}
00372   
00373   //! get dimension of the measurement for a given model 
00374   const int measNdim(std::string modelName) {return m_modelMap[modelName]->measNdim();}
00375   
00376   //! returns a reference to the setup
00377   Setup& setup() const {return *m_setup;}
00378   
00379   //! set navigator verbosity 
00380   void setVerbosity(int v);
00381   //! return navigator verbosity 
00382   int verbosity() const {return m_verbosity;}  
00383 
00384 
00385 
00386   //-------- DUMPING FUNCTIONS ---------------
00387 
00388   void dumpPropagation(std::string volIni, std::string volFinal);
00389 
00390   //! list the available options
00391   void menu();
00392 
00393   //! returns a reference to the model  //TODO
00394   IModel& model(std::string modelName) {return *m_modelMap[modelName];}
00395 
00396  protected:
00397   
00398   //! returns a reference to the model converter
00399   IModelConverter& modelConverter(std::string iniModel, std::string finalModel); 
00400  
00401   //! returns the volume intersector
00402   IVolumeIntersector& volumeIntersector(std::string volType){ 
00403     if (volumeIntersectorExists(volType))
00404       return *m_volumeIntersectorMap[volType];      
00405     else if (setup().volumeDefinitionExists(volType) && 
00406          volumeIntersectorExists(setup().volumeDefinition(volType).type()))
00407       return *m_volumeIntersectorMap[setup().volumeDefinition(volType).type()];      
00408     else{
00409       cout << "FATAL ERROR: No volume intersector  "+ volType +"  defined" << endl;
00410       assert(false);
00411     }
00412   }
00413 
00414   //! check if model exists 
00415   bool modelExists(std::string name){
00416     if (m_modelMap.count(name) != 0) return true;
00417     else return false;
00418   } 
00419 
00420 
00421   //! check if the volumeIntersector exists for a give surface type 
00422   bool volumeIntersectorExists(std::string type){
00423     if (m_volumeIntersectorMap.count(type) != 0) return true;
00424     else return false;
00425   } 
00426 
00427 
00428  protected:
00429 
00430   // setup in use:from the manager
00431   Setup* m_setup;
00432 
00433   // models
00434   std::map<std::string, IModel*> m_modelMap;
00435 
00436   // model converters
00437   std::vector<IModelConverter*> m_modelConverterVector;
00438 
00439   // intersectors
00440   std::map<std::string, IVolumeIntersector*> m_volumeIntersectorMap;
00441 
00442   // Verbosity
00443   int m_verbosity; 
00444 
00445   //! the F matrix of the last propagation  
00446   EMatrix m_F;
00447   
00448   //! The Q matrix of the last propagation
00449   EMatrix m_Q;
00450 
00451   std::string m_residualSurfaceType;
00452 };
00453 #endif
00454 
00455 
00456 
00457 

Generated on Mon Nov 23 08:01:43 2009 for MIPP(E907) by  doxygen 1.4.7