CMS 3D CMS Logo

CellularAutomaton.cc
Go to the documentation of this file.
1 #include <queue>
2 
3 #include "CellularAutomaton.h"
4 
5 void CellularAutomaton::createAndConnectCells(const std::vector<const HitDoublets *> &hitDoublets,
6  const TrackingRegion &region,
7  const float thetaCut,
8  const float phiCut,
9  const float hardPtCut) {
10  int tsize = 0;
11  for (auto hd : hitDoublets) {
12  tsize += hd->size();
13  }
14  allCells.reserve(tsize);
15  unsigned int cellId = 0;
16  float ptmin = region.ptMin();
17  float region_origin_x = region.origin().x();
18  float region_origin_y = region.origin().y();
19  float region_origin_radius = region.originRBound();
20 
21  std::vector<bool> alreadyVisitedLayerPairs;
22  alreadyVisitedLayerPairs.resize(theLayerGraph.theLayerPairs.size());
23  for (auto visited : alreadyVisitedLayerPairs) {
24  visited = false;
25  }
26  for (int rootVertex : theLayerGraph.theRootLayers) {
27  std::queue<int> LayerPairsToVisit;
28 
29  for (int LayerPair : theLayerGraph.theLayers[rootVertex].theOuterLayerPairs) {
30  LayerPairsToVisit.push(LayerPair);
31  }
32 
33  unsigned int numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
34 
35  while (not LayerPairsToVisit.empty()) {
36  auto currentLayerPair = LayerPairsToVisit.front();
37  auto &currentLayerPairRef = theLayerGraph.theLayerPairs[currentLayerPair];
38  auto &currentInnerLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[0]];
39  auto &currentOuterLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[1]];
40  bool allInnerLayerPairsAlreadyVisited{true};
41 
42  for (auto innerLayerPair : currentInnerLayerRef.theInnerLayerPairs) {
43  allInnerLayerPairsAlreadyVisited &= alreadyVisitedLayerPairs[innerLayerPair];
44  }
45 
46  if (alreadyVisitedLayerPairs[currentLayerPair] == false and allInnerLayerPairsAlreadyVisited) {
47  const HitDoublets *doubletLayerPairId = hitDoublets[currentLayerPair];
48  auto numberOfDoublets = doubletLayerPairId->size();
49  currentLayerPairRef.theFoundCells[0] = cellId;
50  currentLayerPairRef.theFoundCells[1] = cellId + numberOfDoublets;
51  for (unsigned int i = 0; i < numberOfDoublets; ++i) {
52  allCells.emplace_back(
53  doubletLayerPairId, i, doubletLayerPairId->innerHitId(i), doubletLayerPairId->outerHitId(i));
54 
55  currentOuterLayerRef.isOuterHitOfCell[doubletLayerPairId->outerHitId(i)].push_back(cellId);
56 
57  cellId++;
58 
59  auto &neigCells = currentInnerLayerRef.isOuterHitOfCell[doubletLayerPairId->innerHitId(i)];
60  allCells.back().checkAlignmentAndTag(allCells,
61  neigCells,
62  ptmin,
63  region_origin_x,
64  region_origin_y,
65  region_origin_radius,
66  thetaCut,
67  phiCut,
68  hardPtCut);
69  }
70  assert(cellId == currentLayerPairRef.theFoundCells[1]);
71  for (auto outerLayerPair : currentOuterLayerRef.theOuterLayerPairs) {
72  LayerPairsToVisit.push(outerLayerPair);
73  }
74 
75  alreadyVisitedLayerPairs[currentLayerPair] = true;
76  }
77  LayerPairsToVisit.pop();
78  numberOfLayerPairsToVisitAtThisDepth--;
79  if (numberOfLayerPairsToVisitAtThisDepth == 0) {
80  numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
81  }
82  }
83  }
84 }
85 
86 void CellularAutomaton::evolve(const unsigned int minHitsPerNtuplet) {
87  allStatus.resize(allCells.size());
88 
89  unsigned int numberOfIterations = minHitsPerNtuplet - 2;
90  // keeping the last iteration for later
91  for (unsigned int iteration = 0; iteration < numberOfIterations - 1; ++iteration) {
92  for (auto &layerPair : theLayerGraph.theLayerPairs) {
93  for (auto i = layerPair.theFoundCells[0]; i < layerPair.theFoundCells[1]; ++i) {
94  allCells[i].evolve(i, allStatus);
95  }
96  }
97 
98  for (auto &layerPair : theLayerGraph.theLayerPairs) {
99  for (auto i = layerPair.theFoundCells[0]; i < layerPair.theFoundCells[1]; ++i) {
100  allStatus[i].updateState();
101  }
102  }
103  }
104 
105  // last iteration
106 
107  for (int rootLayerId : theLayerGraph.theRootLayers) {
108  for (int rootLayerPair : theLayerGraph.theLayers[rootLayerId].theOuterLayerPairs) {
109  auto foundCells = theLayerGraph.theLayerPairs[rootLayerPair].theFoundCells;
110  for (auto i = foundCells[0]; i < foundCells[1]; ++i) {
111  auto &cell = allStatus[i];
112  allCells[i].evolve(i, allStatus);
113  cell.updateState();
114  if (cell.isRootCell(minHitsPerNtuplet - 2)) {
115  theRootCells.push_back(i);
116  }
117  }
118  }
119  }
120 }
121 
122 void CellularAutomaton::findNtuplets(std::vector<CACell::CAntuplet> &foundNtuplets,
123  const unsigned int minHitsPerNtuplet) {
124  CACell::CAntuple tmpNtuplet;
125  tmpNtuplet.reserve(minHitsPerNtuplet);
126 
127  for (auto root_cell : theRootCells) {
128  tmpNtuplet.clear();
129  tmpNtuplet.push_back(root_cell);
130  allCells[root_cell].findNtuplets(allCells, foundNtuplets, tmpNtuplet, minHitsPerNtuplet);
131  }
132 }
133 
134 void CellularAutomaton::findTriplets(std::vector<const HitDoublets *> const &hitDoublets,
135  std::vector<CACell::CAntuplet> &foundTriplets,
136  TrackingRegion const &region,
137  const float thetaCut,
138  const float phiCut,
139  const float hardPtCut) {
140  int tsize = 0;
141  for (auto hd : hitDoublets) {
142  tsize += hd->size();
143  }
144  allCells.reserve(tsize);
145 
146  unsigned int cellId = 0;
147  float ptmin = region.ptMin();
148  float region_origin_x = region.origin().x();
149  float region_origin_y = region.origin().y();
150  float region_origin_radius = region.originRBound();
151 
152  std::vector<bool> alreadyVisitedLayerPairs;
153  alreadyVisitedLayerPairs.resize(theLayerGraph.theLayerPairs.size());
154  for (auto visited : alreadyVisitedLayerPairs) {
155  visited = false;
156  }
157  for (int rootVertex : theLayerGraph.theRootLayers) {
158  std::queue<int> LayerPairsToVisit;
159 
160  for (int LayerPair : theLayerGraph.theLayers[rootVertex].theOuterLayerPairs) {
161  LayerPairsToVisit.push(LayerPair);
162  }
163 
164  unsigned int numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
165 
166  while (not LayerPairsToVisit.empty()) {
167  auto currentLayerPair = LayerPairsToVisit.front();
168  auto &currentLayerPairRef = theLayerGraph.theLayerPairs[currentLayerPair];
169  auto &currentInnerLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[0]];
170  auto &currentOuterLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[1]];
171  bool allInnerLayerPairsAlreadyVisited{true};
172 
173  for (auto innerLayerPair : currentInnerLayerRef.theInnerLayerPairs) {
174  allInnerLayerPairsAlreadyVisited &= alreadyVisitedLayerPairs[innerLayerPair];
175  }
176 
177  if (alreadyVisitedLayerPairs[currentLayerPair] == false and allInnerLayerPairsAlreadyVisited) {
178  const HitDoublets *doubletLayerPairId = hitDoublets[currentLayerPair];
179  auto numberOfDoublets = doubletLayerPairId->size();
180  currentLayerPairRef.theFoundCells[0] = cellId;
181  currentLayerPairRef.theFoundCells[1] = cellId + numberOfDoublets;
182  for (unsigned int i = 0; i < numberOfDoublets; ++i) {
183  allCells.emplace_back(
184  doubletLayerPairId, i, doubletLayerPairId->innerHitId(i), doubletLayerPairId->outerHitId(i));
185 
186  currentOuterLayerRef.isOuterHitOfCell[doubletLayerPairId->outerHitId(i)].push_back(cellId);
187 
188  cellId++;
189 
190  auto &neigCells = currentInnerLayerRef.isOuterHitOfCell[doubletLayerPairId->innerHitId(i)];
191  allCells.back().checkAlignmentAndPushTriplet(allCells,
192  neigCells,
193  foundTriplets,
194  ptmin,
195  region_origin_x,
196  region_origin_y,
197  region_origin_radius,
198  thetaCut,
199  phiCut,
200  hardPtCut);
201  }
202  assert(cellId == currentLayerPairRef.theFoundCells[1]);
203  for (auto outerLayerPair : currentOuterLayerRef.theOuterLayerPairs) {
204  LayerPairsToVisit.push(outerLayerPair);
205  }
206 
207  alreadyVisitedLayerPairs[currentLayerPair] = true;
208  }
209  LayerPairsToVisit.pop();
210  numberOfLayerPairsToVisitAtThisDepth--;
211  if (numberOfLayerPairsToVisitAtThisDepth == 0) {
212  numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
213  }
214  }
215  }
216 }
mps_fire.i
i
Definition: mps_fire.py:355
CellularAutomaton::evolve
void evolve(const unsigned int)
Definition: CellularAutomaton.cc:86
cms::cuda::assert
assert(be >=bs)
CAGraph::theRootLayers
std::vector< int > theRootLayers
Definition: CAGraph.h:47
CellularAutomaton::createAndConnectCells
void createAndConnectCells(const std::vector< const HitDoublets * > &, const TrackingRegion &, const float, const float, const float)
Definition: CellularAutomaton.cc:5
CAGraph::theLayerPairs
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:46
HitDoublets::size
std::size_t size() const
Definition: RecHitsSortedInPhi.h:137
CellularAutomaton::theLayerGraph
CAGraph & theLayerGraph
Definition: CellularAutomaton.h:31
class-composition.visited
visited
Definition: class-composition.py:74
CellularAutomaton::allStatus
std::vector< CACellStatus > allStatus
Definition: CellularAutomaton.h:34
HitDoublets
Definition: RecHitsSortedInPhi.h:124
CellularAutomaton::theRootCells
std::vector< unsigned int > theRootCells
Definition: CellularAutomaton.h:36
HitDoublets::outerHitId
int outerHitId(int i) const
Definition: RecHitsSortedInPhi.h:149
CellularAutomaton::findTriplets
void findTriplets(const std::vector< const HitDoublets * > &hitDoublets, std::vector< CACell::CAntuplet > &foundTriplets, const TrackingRegion &region, const float thetaCut, const float phiCut, const float hardPtCut)
Definition: CellularAutomaton.cc:134
CAGraph::theLayers
std::vector< CALayer > theLayers
Definition: CAGraph.h:45
HLT_2018_cff.region
region
Definition: HLT_2018_cff.py:81479
HitDoublets::innerHitId
int innerHitId(int i) const
Definition: RecHitsSortedInPhi.h:148
ptmin
double ptmin
Definition: HydjetWrapper.h:84
TrackingRegion
Definition: TrackingRegion.h:38
CellularAutomaton::allCells
std::vector< CACell > allCells
Definition: CellularAutomaton.h:33
CACell::CAntuple
std::vector< unsigned int > CAntuple
Definition: CACell.h:29
CellularAutomaton::findNtuplets
void findNtuplets(std::vector< CACell::CAntuplet > &, const unsigned int)
Definition: CellularAutomaton.cc:122
align_cfg.iteration
iteration
Definition: align_cfg.py:5
CellularAutomaton.h