CMS 3D CMS Logo

CellularAutomaton.cc
Go to the documentation of this file.
1 #include <queue>
2 
3 #include "CellularAutomaton.h"
4 
6  const std::vector<const HitDoublets *> & hitDoublets,
7  const TrackingRegion & region,
8  const float thetaCut,
9  const float phiCut,
10  const float hardPtCut)
11 {
12  int tsize = 0;
13  for (auto hd : hitDoublets) {
14  tsize += hd->size();
15  }
16  allCells.reserve(tsize);
17  unsigned int cellId = 0;
18  float ptmin = region.ptMin();
19  float region_origin_x = region.origin().x();
20  float region_origin_y = region.origin().y();
21  float region_origin_radius = region.originRBound();
22 
23  std::vector<bool> alreadyVisitedLayerPairs;
24  alreadyVisitedLayerPairs.resize(theLayerGraph.theLayerPairs.size());
25  for (auto visited : alreadyVisitedLayerPairs) {
26  visited = false;
27  }
28  for (int rootVertex : theLayerGraph.theRootLayers) {
29  std::queue<int> LayerPairsToVisit;
30 
31  for (int LayerPair : theLayerGraph.theLayers[rootVertex].theOuterLayerPairs) {
32  LayerPairsToVisit.push(LayerPair);
33  }
34 
35  unsigned int numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
36 
37  while (not LayerPairsToVisit.empty()) {
38  auto currentLayerPair = LayerPairsToVisit.front();
39  auto & currentLayerPairRef = theLayerGraph.theLayerPairs[currentLayerPair];
40  auto & currentInnerLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[0]];
41  auto & currentOuterLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[1]];
42  bool allInnerLayerPairsAlreadyVisited{true};
43 
44  for (auto innerLayerPair : currentInnerLayerRef.theInnerLayerPairs) {
45  allInnerLayerPairsAlreadyVisited &= alreadyVisitedLayerPairs[innerLayerPair];
46  }
47 
48  if (alreadyVisitedLayerPairs[currentLayerPair] == false and allInnerLayerPairsAlreadyVisited) {
49  const HitDoublets *doubletLayerPairId = hitDoublets[currentLayerPair];
50  auto numberOfDoublets = doubletLayerPairId->size();
51  currentLayerPairRef.theFoundCells[0] = cellId;
52  currentLayerPairRef.theFoundCells[1] = cellId + numberOfDoublets;
53  for (unsigned int i = 0; i < numberOfDoublets; ++i) {
54  allCells.emplace_back(doubletLayerPairId, i,
55  doubletLayerPairId->innerHitId(i),
56  doubletLayerPairId->outerHitId(i));
57 
58  currentOuterLayerRef.isOuterHitOfCell[doubletLayerPairId->outerHitId(i)].push_back(cellId);
59 
60  cellId++;
61 
62  auto & neigCells = currentInnerLayerRef.isOuterHitOfCell[doubletLayerPairId->innerHitId(i)];
63  allCells.back().checkAlignmentAndTag(
64  allCells, neigCells, ptmin, region_origin_x, region_origin_y,
65  region_origin_radius, thetaCut, phiCut, hardPtCut);
66  }
67  assert(cellId == currentLayerPairRef.theFoundCells[1]);
68  for (auto outerLayerPair : currentOuterLayerRef.theOuterLayerPairs) {
69  LayerPairsToVisit.push(outerLayerPair);
70  }
71 
72  alreadyVisitedLayerPairs[currentLayerPair] = true;
73  }
74  LayerPairsToVisit.pop();
75  numberOfLayerPairsToVisitAtThisDepth--;
76  if (numberOfLayerPairsToVisitAtThisDepth == 0) {
77  numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
78  }
79  }
80  }
81 }
82 
83 void CellularAutomaton::evolve(const unsigned int minHitsPerNtuplet)
84 {
85  allStatus.resize(allCells.size());
86 
87  unsigned int numberOfIterations = minHitsPerNtuplet - 2;
88  // keeping the last iteration for later
89  for (unsigned int iteration = 0; iteration < numberOfIterations - 1; ++iteration) {
90  for (auto & layerPair : theLayerGraph.theLayerPairs) {
91  for (auto i = layerPair.theFoundCells[0]; i < layerPair.theFoundCells[1]; ++i) {
92  allCells[i].evolve(i, allStatus);
93  }
94  }
95 
96  for (auto & layerPair : theLayerGraph.theLayerPairs) {
97  for (auto i = layerPair.theFoundCells[0]; i < layerPair.theFoundCells[1]; ++i) {
98  allStatus[i].updateState();
99  }
100  }
101  }
102 
103  // last iteration
104 
105  for (int rootLayerId : theLayerGraph.theRootLayers) {
106  for (int rootLayerPair : theLayerGraph.theLayers[rootLayerId].theOuterLayerPairs) {
107  auto foundCells = theLayerGraph.theLayerPairs[rootLayerPair].theFoundCells;
108  for (auto i = foundCells[0]; i < foundCells[1]; ++i) {
109  auto & cell = allStatus[i];
110  allCells[i].evolve(i, allStatus);
111  cell.updateState();
112  if (cell.isRootCell(minHitsPerNtuplet - 2)) {
113  theRootCells.push_back(i);
114  }
115  }
116  }
117  }
118 }
119 
120 void CellularAutomaton::findNtuplets(std::vector<CACell::CAntuplet> & foundNtuplets, const unsigned int minHitsPerNtuplet)
121 {
122  CACell::CAntuple tmpNtuplet;
123  tmpNtuplet.reserve(minHitsPerNtuplet);
124 
125  for (auto root_cell : theRootCells)
126  {
127  tmpNtuplet.clear();
128  tmpNtuplet.push_back(root_cell);
129  allCells[root_cell].findNtuplets(allCells, foundNtuplets, tmpNtuplet, minHitsPerNtuplet);
130  }
131 }
132 
134  std::vector<const HitDoublets *> const& hitDoublets,
135  std::vector<CACell::CAntuplet> & foundTriplets, TrackingRegion const& region,
136  const float thetaCut,
137  const float phiCut,
138  const float hardPtCut)
139 {
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(doubletLayerPairId, i,
184  doubletLayerPairId->innerHitId(i),
185  doubletLayerPairId->outerHitId(i));
186 
187  currentOuterLayerRef.isOuterHitOfCell[doubletLayerPairId->outerHitId(i)].push_back(cellId);
188 
189  cellId++;
190 
191  auto & neigCells = currentInnerLayerRef.isOuterHitOfCell[doubletLayerPairId->innerHitId(i)];
192  allCells.back().checkAlignmentAndPushTriplet(
193  allCells, neigCells, foundTriplets, ptmin, region_origin_x, region_origin_y,
194  region_origin_radius, thetaCut, phiCut, hardPtCut);
195  }
196  assert(cellId == currentLayerPairRef.theFoundCells[1]);
197  for (auto outerLayerPair : currentOuterLayerRef.theOuterLayerPairs) {
198  LayerPairsToVisit.push(outerLayerPair);
199  }
200 
201  alreadyVisitedLayerPairs[currentLayerPair] = true;
202  }
203  LayerPairsToVisit.pop();
204  numberOfLayerPairsToVisitAtThisDepth--;
205  if (numberOfLayerPairsToVisitAtThisDepth == 0) {
206  numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
207  }
208  }
209  }
210 }
float originRBound() const
bounds the particle vertex in the transverse plane
std::size_t size() const
void findNtuplets(std::vector< CACell::CAntuplet > &, const unsigned int)
void createAndConnectCells(const std::vector< const HitDoublets * > &, const TrackingRegion &, const float, const float, const float)
GlobalPoint const & origin() const
T y() const
Definition: PV3DBase.h:63
std::vector< CACellStatus > allStatus
std::vector< unsigned int > CAntuple
Definition: CACell.h:38
std::vector< CALayer > theLayers
Definition: CAGraph.h:53
int outerHitId(int i) const
std::vector< unsigned int > theRootCells
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:54
std::vector< CACell > allCells
float ptMin() const
minimal pt of interest
double ptmin
Definition: HydjetWrapper.h:90
std::vector< int > theRootLayers
Definition: CAGraph.h:55
int innerHitId(int i) const
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)
T x() const
Definition: PV3DBase.h:62
void evolve(const unsigned int)