Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:51

0001 #ifndef RECOCALOTOOLS_NAVIGATION_CALONAVIGATOR_H
0002 #define RECOCALOTOOLS_NAVIGATION_CALONAVIGATOR_H 1
0003 
0004 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
0005 
0006 template <class T, class TOPO = CaloSubdetectorTopology>
0007 class CaloNavigator final {
0008 public:
0009   CaloNavigator(const T& home, const TOPO* topology) : myTopology_(topology) { setHome(home); }
0010 
0011   /// set the starting position
0012   inline void setHome(const T& startingPoint);
0013 
0014   /// set the starting position
0015   inline void setTopology(const TOPO*);
0016 
0017   /// set the starting position
0018   const TOPO* getTopology() const { return myTopology_; }
0019 
0020   /// move the navigator back to the starting point
0021   inline void home() const;
0022 
0023   /// get the current position
0024   T pos() const { return currentPoint_; }
0025 
0026   /// get the current position
0027   T operator*() const { return currentPoint_; }
0028 
0029   /// move the navigator north
0030   T north() const {
0031     currentPoint_ = myTopology_->goNorth(currentPoint_);
0032     return currentPoint_;
0033   };
0034 
0035   /// move the navigator south
0036   T south() const {
0037     currentPoint_ = myTopology_->goSouth(currentPoint_);
0038     return currentPoint_;
0039   };
0040 
0041   /// move the navigator east
0042   T east() const {
0043     currentPoint_ = myTopology_->goEast(currentPoint_);
0044     return currentPoint_;
0045   };
0046 
0047   /// move the navigator west
0048   T west() const {
0049     currentPoint_ = myTopology_->goWest(currentPoint_);
0050     return currentPoint_;
0051   };
0052 
0053   /// move the navigator west
0054   T up() const {
0055     currentPoint_ = myTopology_->goUp(currentPoint_);
0056     return currentPoint_;
0057   };
0058 
0059   /// move the navigator west
0060   T down() const {
0061     currentPoint_ = myTopology_->goDown(currentPoint_);
0062     return currentPoint_;
0063   };
0064 
0065   /// Free movement of arbitray steps
0066   T offsetBy(int deltaX, int deltaY) const {
0067     for (int x = 0; x < abs(deltaX) && currentPoint_ != T(0); x++) {
0068       if (deltaX > 0)
0069         east();
0070       else
0071         west();
0072     }
0073 
0074     for (int y = 0; y < abs(deltaY) && currentPoint_ != T(0); y++) {
0075       if (deltaY > 0)
0076         north();
0077       else
0078         south();
0079     }
0080 
0081     return currentPoint_;
0082   }
0083 
0084 protected:
0085   const TOPO* myTopology_;
0086   mutable T startingPoint_, currentPoint_;
0087 };
0088 
0089 template <class T, class TOPO>
0090 inline void CaloNavigator<T, TOPO>::setHome(const T& startingPoint) {
0091   startingPoint_ = startingPoint;
0092   home();
0093 }
0094 
0095 template <class T, class TOPO>
0096 inline void CaloNavigator<T, TOPO>::home() const {
0097   currentPoint_ = startingPoint_;
0098 }
0099 
0100 template <class T, class TOPO>
0101 inline void CaloNavigator<T, TOPO>::setTopology(const TOPO* topology) {
0102   if (myTopology_ == 0)
0103     myTopology_ = topology;
0104   else
0105     return;
0106 }
0107 
0108 #endif