CMS 3D CMS Logo

CaloSubdetectorTopology.cc
Go to the documentation of this file.
2 #include <cassert>
3 
4 std::vector<DetId> CaloSubdetectorTopology::getWindow(const DetId& id,
5  const int& northSouthSize,
6  const int& eastWestSize) const {
7  std::vector<DetId> cellsInWindow;
8  // check pivot
9  if (id.null())
10  return cellsInWindow;
11 
12  //
13  DetId myTmpId(id);
14  std::vector<std::pair<Coordinate, DetId> > fringe;
15  fringe.emplace_back(std::pair<Coordinate, DetId>(Coordinate(0, 0), myTmpId));
16 
17  int halfWestEast = eastWestSize / 2;
18  int halfNorthSouth = northSouthSize / 2;
19 
20  std::vector<CellInfo> visited_cells;
21  visited_cells.resize(northSouthSize * eastWestSize);
22 
23  while (!fringe.empty()) {
24  std::pair<Coordinate, DetId> cur = fringe.back();
25  fringe.pop_back();
26 
27  // check all four neighbours
28  const CaloDirection directions[4] = {NORTH, SOUTH, EAST, WEST};
29 
30  for (auto direction : directions) {
31  Coordinate neighbour = getNeighbourIndex(cur.first, direction);
32  //If outside the window range
33  if (neighbour.first < -halfWestEast || neighbour.first > halfWestEast || neighbour.second < -halfNorthSouth ||
34  neighbour.second > halfNorthSouth)
35  continue;
36 
37  //Found integer index in the matrix
38  unsigned int_index = neighbour.first + halfWestEast + eastWestSize * (neighbour.second + halfNorthSouth);
39  assert(int_index < visited_cells.size());
40 
41  // check whether we have seen this neighbour already
42  if (visited_cells[int_index].visited)
43  // we have seen this one already
44  continue;
45 
46  // a new cell, get the DetId of the neighbour, mark it
47  // as visited and add it to the fringe
48  visited_cells[int_index].visited = true;
49  std::vector<DetId> neighbourCells = getNeighbours(cur.second, direction);
50 
51  if (neighbourCells.size() == 1)
52  visited_cells[int_index].cell = neighbourCells[0];
53  else if (neighbourCells.empty())
54  visited_cells[int_index].cell = DetId(0);
55  else
56  throw cms::Exception("getWindowError") << "Not supported subdetector for getWindow method";
57 
58  if (!visited_cells[int_index].cell.null())
59  fringe.emplace_back(std::pair<Coordinate, DetId>(neighbour, visited_cells[int_index].cell));
60 
61  } // loop over all possible directions
62  } // while some cells are left on the fringe
63 
64  for (auto& visited_cell : visited_cells)
65  if (!visited_cell.cell.null())
66  cellsInWindow.emplace_back(visited_cell.cell);
67 
68  return cellsInWindow;
69 }
CaloDirection
CaloDirection
Codes the local directions in the cell lattice.
Definition: CaloDirection.h:9
cms::cuda::assert
assert(be >=bs)
DetId
Definition: DetId.h:17
directions
directions
Definition: DeviationsFromFileSensor2D.cc:15
EAST
Definition: CaloDirection.h:14
NORTH
Definition: CaloDirection.h:18
class-composition.visited
visited
Definition: class-composition.py:74
CaloSubdetectorTopology::getNeighbours
virtual std::vector< DetId > getNeighbours(const DetId &id, const CaloDirection &dir) const
Definition: CaloSubdetectorTopology.h:77
CaloSubdetectorTopology::getNeighbourIndex
Coordinate getNeighbourIndex(const Coordinate &coord, const CaloDirection &dir) const
Definition: CaloSubdetectorTopology.h:120
CaloSubdetectorTopology::getWindow
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
Definition: CaloSubdetectorTopology.cc:4
CaloSubdetectorTopology.h
WEST
Definition: CaloDirection.h:15
Exception
Definition: hltDiff.cc:246
CaloSubdetectorTopology::Coordinate
std::pair< int, int > Coordinate
Definition: CaloSubdetectorTopology.h:108
SOUTH
Definition: CaloDirection.h:11