00001 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
00002 #include <cassert>
00003
00004 std::vector<DetId> CaloSubdetectorTopology::getWindow(const DetId& id, const int& northSouthSize, const int& eastWestSize) const
00005 {
00006
00007 std::vector<DetId> cellsInWindow;
00008
00009 if (id.null())
00010 return cellsInWindow;
00011
00012
00013 DetId myTmpId(id);
00014 std::vector<std::pair<Coordinate,DetId> > fringe;
00015 fringe.push_back(std::pair<Coordinate,DetId>(Coordinate(0,0),myTmpId));
00016
00017 int halfWestEast = eastWestSize/2 ;
00018 int halfNorthSouth = northSouthSize/2 ;
00019
00020 std::vector<CellInfo> visited_cells;
00021 visited_cells.resize(northSouthSize * eastWestSize);
00022
00023 while (fringe.size() > 0)
00024 {
00025 std::pair<Coordinate,DetId> cur = fringe.back();
00026 fringe.pop_back();
00027
00028
00029 const CaloDirection directions[4] = { NORTH, SOUTH, EAST, WEST };
00030
00031 for (unsigned dirnum = 0; dirnum < 4; ++dirnum)
00032 {
00033 Coordinate neighbour = getNeighbourIndex(cur.first,directions[dirnum]);
00034
00035 if ( neighbour.first < -halfWestEast ||
00036 neighbour.first > halfWestEast ||
00037 neighbour.second < -halfNorthSouth ||
00038 neighbour.second > halfNorthSouth )
00039 continue;
00040
00041
00042
00043 unsigned int_index = neighbour.first + halfWestEast +
00044 eastWestSize * (neighbour.second + halfNorthSouth );
00045 assert(int_index < visited_cells.size());
00046
00047
00048 if (visited_cells[int_index].visited)
00049
00050 continue;
00051
00052
00053
00054 visited_cells[int_index].visited = true;
00055 std::vector<DetId> neighbourCells = getNeighbours(cur.second,directions[dirnum]);
00056
00057 if ( neighbourCells.size() == 1 )
00058 visited_cells[int_index].cell = neighbourCells[0];
00059 else if ( neighbourCells.size() == 0 )
00060 visited_cells[int_index].cell = DetId(0);
00061 else
00062 throw cms::Exception("getWindowError") << "Not supported subdetector for getWindow method";
00063
00064 if (!visited_cells[int_index].cell.null())
00065 fringe.push_back(std::pair<Coordinate,DetId>(neighbour,visited_cells[int_index].cell));
00066
00067 }
00068 }
00069
00070
00071 for (unsigned int i=0; i<visited_cells.size(); i++)
00072 if (!visited_cells[i].cell.null())
00073 cellsInWindow.push_back(visited_cells[i].cell);
00074
00075 return cellsInWindow;
00076 }