Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:17

0001 #ifndef TOPOLOGY_CALOTOPOLOGY_CALOSUBDETECTORTOPOLOGY_H
0002 #define TOPOLOGY_CALOTOPOLOGY_CALOSUBDETECTORTOPOLOGY_H 1
0003 
0004 #include "DataFormats/DetId/interface/DetId.h"
0005 #include "Geometry/CaloTopology/interface/CaloDirection.h"
0006 #include "FWCore/Utilities/interface/Exception.h"
0007 
0008 #include <vector>
0009 
0010 /** \class CaloSubdetectorTopology
0011       
0012 $Revision: 1.7 $
0013 \author P.Meridiani INFN Roma1
0014 \author J. Mans - Minnesota
0015 */
0016 
0017 class CaloSubdetectorTopology {
0018 public:
0019   /// standard constructor
0020   CaloSubdetectorTopology(){};
0021   /// virtual destructor
0022   virtual ~CaloSubdetectorTopology() {}
0023   /// is this detid present in the Topology?
0024   virtual bool valid(const DetId& /*id*/) const { return false; };
0025   /// return a linear packed id
0026   virtual unsigned int detId2denseId(const DetId& /*id*/) const { return 0; }
0027   /// return a linear packed id
0028   virtual DetId denseId2detId(unsigned int /*denseid*/) const { return DetId(0); }
0029   /// return a count of valid cells (for dense indexing use)
0030   virtual unsigned int ncells() const { return 1; }
0031   /// return a version which identifies the given topology
0032   virtual int topoVersion() const { return 0; }
0033   /// return whether this topology is consistent with the numbering in the given topology
0034   virtual bool denseIdConsistent(int topoVer) const { return topoVer == topoVersion(); }
0035 
0036   /** Get the neighbors of the given cell in east direction*/
0037   virtual std::vector<DetId> east(const DetId& id) const = 0;
0038   /** Get the neighbors of the given cell in west direction*/
0039   virtual std::vector<DetId> west(const DetId& id) const = 0;
0040   /** Get the neighbors of the given cell in north direction*/
0041   virtual std::vector<DetId> north(const DetId& id) const = 0;
0042   /** Get the neighbors of the given cell in south direction*/
0043   virtual std::vector<DetId> south(const DetId& id) const = 0;
0044   /** Get the neighbors of the given cell in up direction (outward)*/
0045   virtual std::vector<DetId> up(const DetId& id) const = 0;
0046   /** Get the neighbors of the given cell in down direction (inward)*/
0047   virtual std::vector<DetId> down(const DetId& id) const = 0;
0048 
0049   // interface valid for most subdetectors
0050   // see for instance RecoCaloTools/Navigation/interface/CaloNavigator.h
0051   virtual DetId goEast(const DetId& id) const {
0052     std::vector<DetId> ids = east(id);
0053     return ids.empty() ? DetId() : ids[0];
0054   }
0055   virtual DetId goWest(const DetId& id) const {
0056     std::vector<DetId> ids = west(id);
0057     return ids.empty() ? DetId() : ids[0];
0058   }
0059   virtual DetId goNorth(const DetId& id) const {
0060     std::vector<DetId> ids = north(id);
0061     return ids.empty() ? DetId() : ids[0];
0062   }
0063   virtual DetId goSouth(const DetId& id) const {
0064     std::vector<DetId> ids = south(id);
0065     return ids.empty() ? DetId() : ids[0];
0066   }
0067   virtual DetId goUp(const DetId& id) const {
0068     std::vector<DetId> ids = up(id);
0069     return ids.empty() ? DetId() : ids[0];
0070   }
0071   virtual DetId goDown(const DetId& id) const {
0072     std::vector<DetId> ids = down(id);
0073     return ids.empty() ? DetId() : ids[0];
0074   }
0075 
0076   /** Get the neighbors of the given cell given direction*/
0077   virtual std::vector<DetId> getNeighbours(const DetId& id, const CaloDirection& dir) const {
0078     std::vector<DetId> aNullVector;
0079     switch (dir) {
0080       case NONE:
0081         return aNullVector;
0082         break;
0083       case SOUTH:
0084         return south(id);
0085         break;
0086       case NORTH:
0087         return north(id);
0088         break;
0089       case EAST:
0090         return east(id);
0091         break;
0092       case WEST:
0093         return west(id);
0094         break;
0095       default:
0096         throw cms::Exception("getNeighboursError") << "Unsopported direction";
0097     }
0098     return aNullVector;
0099   }
0100 
0101   /** Get the neighbors of the given cell in a window of given size*/
0102   virtual std::vector<DetId> getWindow(const DetId& id, const int& northSouthSize, const int& eastWestSize) const;
0103 
0104   /** Get all the neighbors of the given cell*/
0105   virtual std::vector<DetId> getAllNeighbours(const DetId& id) const { return getWindow(id, 3, 3); }
0106 
0107 protected:
0108   typedef std::pair<int, int> Coordinate;
0109 
0110   struct CellInfo {
0111     bool visited;
0112 
0113     DetId cell;
0114 
0115     CellInfo() : visited(false) {}
0116 
0117     CellInfo(bool a_visited, const DetId& a_cell) : visited(a_visited), cell(a_cell) {}
0118   };
0119 
0120   inline Coordinate getNeighbourIndex(const Coordinate& coord, const CaloDirection& dir) const {
0121     switch (dir) {
0122       case NORTH:
0123         return Coordinate(coord.first, coord.second + 1);
0124       case SOUTH:
0125         return Coordinate(coord.first, coord.second - 1);
0126 
0127       case EAST:
0128         return Coordinate(coord.first + 1, coord.second);
0129       case WEST:
0130         return Coordinate(coord.first - 1, coord.second);
0131 
0132       default:
0133         throw cms::Exception("getWindowError") << "Unsopported direction";
0134     }
0135   }
0136 };
0137 
0138 #endif