CMS 3D CMS Logo

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