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>
00010
00011 #include "FWCore/Utilities/interface/GCC11Compatibility.h"
00012
00021 class CaloSubdetectorTopology {
00022 public:
00024 CaloSubdetectorTopology() {};
00026 virtual ~CaloSubdetectorTopology() { }
00028 virtual bool valid(const DetId& ) const { return false; };
00030 virtual unsigned int detId2denseId(const DetId& ) const { return 0; }
00032 virtual DetId denseId2detId(unsigned int ) const { return DetId(0); }
00034 virtual unsigned int ncells() const { return 1; }
00036 virtual int topoVersion() const { return 0; }
00038 virtual bool denseIdConsistent(int topoVer) const { return topoVer==topoVersion(); }
00039
00041 virtual std::vector<DetId> east(const DetId& id) const = 0;
00043 virtual std::vector<DetId> west(const DetId& id) const = 0;
00045 virtual std::vector<DetId> north(const DetId& id) const = 0;
00047 virtual std::vector<DetId> south(const DetId& id) const = 0;
00049 virtual std::vector<DetId> up(const DetId& id) const = 0;
00051 virtual std::vector<DetId> down(const DetId& id) const = 0;
00052
00053
00054
00055 virtual DetId goEast(const DetId& id) const {
00056 std::vector<DetId> ids = east(id);
00057 return ids.empty() ? DetId() : ids[0];
00058 }
00059 virtual DetId goWest(const DetId& id) const {
00060 std::vector<DetId> ids = west(id);
00061 return ids.empty() ? DetId() : ids[0];
00062 }
00063 virtual DetId goNorth(const DetId& id) const {
00064 std::vector<DetId> ids = north(id);
00065 return ids.empty() ? DetId() : ids[0];
00066 }
00067 virtual DetId goSouth(const DetId& id) const {
00068 std::vector<DetId> ids = south(id);
00069 return ids.empty() ? DetId() : ids[0];
00070 }
00071 virtual DetId goUp(const DetId& id) const {
00072 std::vector<DetId> ids = up(id);
00073 return ids.empty() ? DetId() : ids[0];
00074 }
00075 virtual DetId goDown(const DetId& id) const {
00076 std::vector<DetId> ids = down(id);
00077 return ids.empty() ? DetId() : ids[0];
00078 }
00079
00080
00082 virtual std::vector<DetId> getNeighbours(const DetId& id, const CaloDirection& dir) const
00083 {
00084 std::vector<DetId> aNullVector;
00085 switch(dir)
00086 {
00087 case NONE:
00088 return aNullVector;
00089 break;
00090 case SOUTH:
00091 return south(id);
00092 break;
00093 case NORTH:
00094 return north(id);
00095 break;
00096 case EAST:
00097 return east(id);
00098 break;
00099 case WEST:
00100 return west(id);
00101 break;
00102 default:
00103 throw cms::Exception("getNeighboursError") << "Unsopported direction";
00104 }
00105 return aNullVector;
00106 }
00107
00109 virtual std::vector<DetId> getWindow(const DetId& id, const int& northSouthSize, const int& eastWestSize) const;
00110
00112 virtual std::vector<DetId> getAllNeighbours(const DetId& id) const
00113 {
00114 return getWindow(id,3,3);
00115 }
00116
00117 protected:
00118 typedef std::pair<int,int> Coordinate;
00119
00120 struct CellInfo
00121 {
00122 bool visited;
00123
00124 DetId cell;
00125
00126 CellInfo() :
00127 visited(false)
00128 {
00129 }
00130
00131 CellInfo(bool a_visited, const DetId &a_cell) :
00132 visited(a_visited),
00133 cell(a_cell)
00134 {
00135 }
00136 };
00137
00138 inline Coordinate getNeighbourIndex(const Coordinate &coord, const CaloDirection& dir) const
00139 {
00140 switch (dir)
00141 {
00142 case NORTH: return Coordinate(coord.first,coord.second + 1);
00143 case SOUTH: return Coordinate(coord.first,coord.second - 1);
00144
00145 case EAST: return Coordinate(coord.first + 1,coord.second);
00146 case WEST: return Coordinate(coord.first - 1,coord.second);
00147
00148 default:
00149 throw cms::Exception("getWindowError") << "Unsopported direction";
00150 }
00151 }
00152
00153 };
00154
00155
00156 #endif