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 CACut &thetaCut,
8  const CACut &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 
43  thetaCut.getCutsByInnerLayer(currentInnerLayerRef.seqNum(), currentOuterLayerRef.seqNum());
45  phiCut.getCutsByInnerLayer(currentInnerLayerRef.seqNum(), currentOuterLayerRef.seqNum());
46 
47  for (auto innerLayerPair : currentInnerLayerRef.theInnerLayerPairs) {
48  allInnerLayerPairsAlreadyVisited &= alreadyVisitedLayerPairs[innerLayerPair];
49  }
50 
51  if (alreadyVisitedLayerPairs[currentLayerPair] == false and allInnerLayerPairsAlreadyVisited) {
52  const HitDoublets *doubletLayerPairId = hitDoublets[currentLayerPair];
53  auto numberOfDoublets = doubletLayerPairId->size();
54  currentLayerPairRef.theFoundCells[0] = cellId;
55  currentLayerPairRef.theFoundCells[1] = cellId + numberOfDoublets;
56  for (unsigned int i = 0; i < numberOfDoublets; ++i) {
57  allCells.emplace_back(
58  doubletLayerPairId, i, doubletLayerPairId->innerHitId(i), doubletLayerPairId->outerHitId(i));
59 
60  currentOuterLayerRef.isOuterHitOfCell[doubletLayerPairId->outerHitId(i)].push_back(cellId);
61 
62  cellId++;
63 
64  auto &neigCells = currentInnerLayerRef.isOuterHitOfCell[doubletLayerPairId->innerHitId(i)];
65  allCells.back().checkAlignmentAndTag(allCells,
66  neigCells,
67  ptmin,
68  region_origin_x,
69  region_origin_y,
70  region_origin_radius,
71  caThetaCut,
72  caPhiCut,
73  hardPtCut);
74  }
75  assert(cellId == currentLayerPairRef.theFoundCells[1]);
76  for (auto outerLayerPair : currentOuterLayerRef.theOuterLayerPairs) {
77  LayerPairsToVisit.push(outerLayerPair);
78  }
79 
80  alreadyVisitedLayerPairs[currentLayerPair] = true;
81  }
82  LayerPairsToVisit.pop();
83  numberOfLayerPairsToVisitAtThisDepth--;
84  if (numberOfLayerPairsToVisitAtThisDepth == 0) {
85  numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
86  }
87  }
88  }
89 }
90 
91 void CellularAutomaton::evolve(const unsigned int minHitsPerNtuplet) {
92  allStatus.resize(allCells.size());
93 
94  unsigned int numberOfIterations = minHitsPerNtuplet - 2;
95  // keeping the last iteration for later
96  for (unsigned int iteration = 0; iteration < numberOfIterations - 1; ++iteration) {
97  for (auto &layerPair : theLayerGraph.theLayerPairs) {
98  for (auto i = layerPair.theFoundCells[0]; i < layerPair.theFoundCells[1]; ++i) {
99  allCells[i].evolve(i, allStatus);
100  }
101  }
102 
103  for (auto &layerPair : theLayerGraph.theLayerPairs) {
104  for (auto i = layerPair.theFoundCells[0]; i < layerPair.theFoundCells[1]; ++i) {
105  allStatus[i].updateState();
106  }
107  }
108  }
109 
110  // last iteration
111 
112  for (int rootLayerId : theLayerGraph.theRootLayers) {
113  for (int rootLayerPair : theLayerGraph.theLayers[rootLayerId].theOuterLayerPairs) {
114  auto foundCells = theLayerGraph.theLayerPairs[rootLayerPair].theFoundCells;
115  for (auto i = foundCells[0]; i < foundCells[1]; ++i) {
116  auto &cell = allStatus[i];
117  allCells[i].evolve(i, allStatus);
118  cell.updateState();
119  if (cell.isRootCell(minHitsPerNtuplet - 2)) {
120  theRootCells.push_back(i);
121  }
122  }
123  }
124  }
125 }
126 
127 void CellularAutomaton::findNtuplets(std::vector<CACell::CAntuplet> &foundNtuplets,
128  const unsigned int minHitsPerNtuplet) {
129  CACell::CAntuple tmpNtuplet;
130  tmpNtuplet.reserve(minHitsPerNtuplet);
131 
132  for (auto root_cell : theRootCells) {
133  tmpNtuplet.clear();
134  tmpNtuplet.push_back(root_cell);
135  allCells[root_cell].findNtuplets(allCells, foundNtuplets, tmpNtuplet, minHitsPerNtuplet);
136  }
137 }
138 
139 void CellularAutomaton::findTriplets(std::vector<const HitDoublets *> const &hitDoublets,
140  std::vector<CACell::CAntuplet> &foundTriplets,
141  TrackingRegion const &region,
142  const CACut &thetaCut,
143  const CACut &phiCut,
144  const float hardPtCut) {
145  int tsize = 0;
146  for (auto hd : hitDoublets) {
147  tsize += hd->size();
148  }
149  allCells.reserve(tsize);
150 
151  unsigned int cellId = 0;
152  float ptmin = region.ptMin();
153  float region_origin_x = region.origin().x();
154  float region_origin_y = region.origin().y();
155  float region_origin_radius = region.originRBound();
156 
157  std::vector<bool> alreadyVisitedLayerPairs;
158  alreadyVisitedLayerPairs.resize(theLayerGraph.theLayerPairs.size());
159  for (auto visited : alreadyVisitedLayerPairs) {
160  visited = false;
161  }
162  for (int rootVertex : theLayerGraph.theRootLayers) {
163  std::queue<int> LayerPairsToVisit;
164 
165  for (int LayerPair : theLayerGraph.theLayers[rootVertex].theOuterLayerPairs) {
166  LayerPairsToVisit.push(LayerPair);
167  }
168 
169  unsigned int numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
170 
171  while (not LayerPairsToVisit.empty()) {
172  auto currentLayerPair = LayerPairsToVisit.front();
173  auto &currentLayerPairRef = theLayerGraph.theLayerPairs[currentLayerPair];
174  auto &currentInnerLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[0]];
175  auto &currentOuterLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[1]];
176  bool allInnerLayerPairsAlreadyVisited{true};
177 
178  CACut::CAValuesByInnerLayerIds caThetaCut =
179  thetaCut.getCutsByInnerLayer(currentInnerLayerRef.seqNum(), currentOuterLayerRef.seqNum());
181  phiCut.getCutsByInnerLayer(currentInnerLayerRef.seqNum(), currentOuterLayerRef.seqNum());
182 
183  for (auto innerLayerPair : currentInnerLayerRef.theInnerLayerPairs) {
184  allInnerLayerPairsAlreadyVisited &= alreadyVisitedLayerPairs[innerLayerPair];
185  }
186 
187  if (alreadyVisitedLayerPairs[currentLayerPair] == false and allInnerLayerPairsAlreadyVisited) {
188  const HitDoublets *doubletLayerPairId = hitDoublets[currentLayerPair];
189  auto numberOfDoublets = doubletLayerPairId->size();
190  currentLayerPairRef.theFoundCells[0] = cellId;
191  currentLayerPairRef.theFoundCells[1] = cellId + numberOfDoublets;
192  for (unsigned int i = 0; i < numberOfDoublets; ++i) {
193  allCells.emplace_back(
194  doubletLayerPairId, i, doubletLayerPairId->innerHitId(i), doubletLayerPairId->outerHitId(i));
195 
196  currentOuterLayerRef.isOuterHitOfCell[doubletLayerPairId->outerHitId(i)].push_back(cellId);
197 
198  cellId++;
199 
200  auto &neigCells = currentInnerLayerRef.isOuterHitOfCell[doubletLayerPairId->innerHitId(i)];
201  allCells.back().checkAlignmentAndPushTriplet(allCells,
202  neigCells,
203  foundTriplets,
204  ptmin,
205  region_origin_x,
206  region_origin_y,
207  region_origin_radius,
208  caThetaCut,
209  caPhiCut,
210  hardPtCut);
211  }
212  assert(cellId == currentLayerPairRef.theFoundCells[1]);
213  for (auto outerLayerPair : currentOuterLayerRef.theOuterLayerPairs) {
214  LayerPairsToVisit.push(outerLayerPair);
215  }
216 
217  alreadyVisitedLayerPairs[currentLayerPair] = true;
218  }
219  LayerPairsToVisit.pop();
220  numberOfLayerPairsToVisitAtThisDepth--;
221  if (numberOfLayerPairsToVisitAtThisDepth == 0) {
222  numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
223  }
224  }
225  }
226 }
void findNtuplets(std::vector< CACell::CAntuplet > &, const unsigned int)
assert(be >=bs)
Definition: CACut.h:16
std::vector< CACellStatus > allStatus
std::vector< unsigned int > CAntuple
Definition: CACell.h:30
std::size_t size() const
std::vector< CALayer > theLayers
Definition: CAGraph.h:59
std::vector< unsigned int > theRootCells
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:60
int outerHitId(int i) const
std::vector< CACell > allCells
double ptmin
Definition: HydjetWrapper.h:86
void createAndConnectCells(const std::vector< const HitDoublets *> &, const TrackingRegion &, const CACut &, const CACut &, const float)
std::vector< int > theRootLayers
Definition: CAGraph.h:61
CAValuesByInnerLayerIds getCutsByInnerLayer(int layerIds1, int layerIds2) const
Definition: CACut.h:139
void findTriplets(const std::vector< const HitDoublets *> &hitDoublets, std::vector< CACell::CAntuplet > &foundTriplets, const TrackingRegion &region, const CACut &thetaCut, const CACut &phiCut, const float hardPtCut)
void evolve(const unsigned int)
int innerHitId(int i) const