CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Geometry/CaloTopology/interface/CaloSubdetectorTopology.h

Go to the documentation of this file.
00001 #ifndef TOPOLOGY_CALOTOPOLOGY_CALOSUBDETECTORTOPOLOGY_H
00002 #define TOPOLOGY_CALOTOPOLOGY_CALOSUBDETECTORTOPOLOGY_H 1
00003 
00004 
00005 #include "DataFormats/DetId/interface/DetId.h"
00006 #include "Geometry/CaloTopology/interface/CaloDirection.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 
00009 #include <vector>
00018 class CaloSubdetectorTopology {
00019 public:
00021   CaloSubdetectorTopology() {};
00023   virtual ~CaloSubdetectorTopology() { }
00025   virtual bool valid(const DetId& /*id*/) const { return false; };
00027   virtual unsigned int detId2denseId(const DetId& /*id*/) const { return 0; }
00029   virtual DetId denseId2detId(unsigned int /*denseid*/) const { return DetId(0); }
00031   virtual unsigned int ncells() const { return 1; }
00033   virtual int topoVersion() const { return 0; }
00035   virtual bool denseIdConsistent(int topoVer) const { return topoVer==topoVersion(); }
00036 
00038   virtual std::vector<DetId> east(const DetId& id) const = 0;
00040   virtual std::vector<DetId> west(const DetId& id) const = 0;
00042   virtual std::vector<DetId> north(const DetId& id) const = 0;
00044   virtual std::vector<DetId> south(const DetId& id) const = 0;
00046   virtual std::vector<DetId> up(const DetId& id) const = 0;
00048   virtual std::vector<DetId> down(const DetId& id) const = 0;
00050   virtual std::vector<DetId> getNeighbours(const DetId& id, const CaloDirection& dir) const
00051     {
00052       std::vector<DetId> aNullVector;
00053       switch(dir)
00054         {
00055         case NONE:
00056           return aNullVector;
00057           break;
00058         case SOUTH:
00059           return south(id);
00060           break;
00061         case NORTH:
00062           return north(id);
00063           break;
00064         case EAST:
00065           return east(id);
00066           break;
00067         case WEST:
00068           return west(id);
00069           break;
00070         default:
00071           throw cms::Exception("getNeighboursError") << "Unsopported direction";
00072         }
00073       return aNullVector;
00074     }
00075 
00077   virtual std::vector<DetId> getWindow(const DetId& id, const int& northSouthSize, const int& eastWestSize) const;
00078 
00080   virtual std::vector<DetId> getAllNeighbours(const DetId& id) const
00081     {
00082       return getWindow(id,3,3);
00083     }
00084 
00085  protected:
00086   typedef std::pair<int,int> Coordinate;
00087 
00088   struct CellInfo
00089   {
00090     bool visited;
00091     
00092     DetId cell;
00093     
00094     CellInfo() : 
00095       visited(false)
00096     {
00097     }
00098     
00099     CellInfo(bool a_visited, const DetId &a_cell) : 
00100       visited(a_visited),
00101          cell(a_cell)
00102     {
00103     }
00104   };
00105 
00106   inline Coordinate getNeighbourIndex(const Coordinate &coord, const CaloDirection& dir) const
00107     {
00108       switch (dir)
00109         {
00110         case NORTH: return Coordinate(coord.first,coord.second + 1);
00111         case SOUTH: return Coordinate(coord.first,coord.second - 1);
00112           
00113         case EAST:  return Coordinate(coord.first + 1,coord.second);
00114         case WEST:  return Coordinate(coord.first - 1,coord.second);
00115           
00116         default:
00117           throw cms::Exception("getWindowError") << "Unsopported direction";
00118         }
00119     }
00120   
00121 };
00122 
00123 
00124 #endif