CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
CellularAutomaton Class Reference

#include <CellularAutomaton.h>

Public Member Functions

 CellularAutomaton (CAGraph &graph)
 
void createAndConnectCells (const std::vector< const HitDoublets * > &, const TrackingRegion &, const float, const float, const float)
 
void evolve (const unsigned int)
 
void findNtuplets (std::vector< CACell::CAntuplet > &, const unsigned int)
 
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)
 
std::vector< CACell > & getAllCells ()
 

Private Attributes

std::vector< CACellallCells
 
std::vector< CACellStatusallStatus
 
CAGraphtheLayerGraph
 
std::vector< std::vector< CACell * > > theNtuplets
 
std::vector< unsigned int > theRootCells
 

Detailed Description

Definition at line 8 of file CellularAutomaton.h.

Constructor & Destructor Documentation

CellularAutomaton::CellularAutomaton ( CAGraph graph)
inline

Definition at line 11 of file CellularAutomaton.h.

12  : theLayerGraph(graph)
13  {
14 
15  }

Member Function Documentation

void CellularAutomaton::createAndConnectCells ( const std::vector< const HitDoublets * > &  hitDoublets,
const TrackingRegion region,
const float  thetaCut,
const float  phiCut,
const float  hardPtCut 
)

Definition at line 6 of file CellularAutomaton.cc.

References allCells, mps_fire::i, HitDoublets::innerHitId(), TrackingRegion::origin(), TrackingRegion::originRBound(), HitDoublets::outerHitId(), TrackingRegion::ptMin(), HitDoublets::size(), theLayerGraph, CAGraph::theLayerPairs, CAGraph::theLayers, CAGraph::theRootLayers, class-composition::visited, PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

Referenced by getAllCells(), and CAHitQuadrupletGenerator::hitNtuplets().

8 {
9  int tsize=0;
10  for ( auto hd : hitDoublets) tsize+=hd->size();
11  allCells.reserve(tsize);
12  unsigned int cellId = 0;
13  float ptmin = region.ptMin();
14  float region_origin_x = region.origin().x();
15  float region_origin_y = region.origin().y();
16  float region_origin_radius = region.originRBound();
17 
18  std::vector<bool> alreadyVisitedLayerPairs;
19  alreadyVisitedLayerPairs.resize(theLayerGraph.theLayerPairs.size());
20  for (auto visited : alreadyVisitedLayerPairs)
21  {
22  visited = false;
23  }
24  for (int rootVertex : theLayerGraph.theRootLayers)
25  {
26 
27  std::queue<int> LayerPairsToVisit;
28 
29  for (int LayerPair : theLayerGraph.theLayers[rootVertex].theOuterLayerPairs)
30  {
31  LayerPairsToVisit.push(LayerPair);
32 
33  }
34 
35  unsigned int numberOfLayerPairsToVisitAtThisDepth =
36  LayerPairsToVisit.size();
37 
38  while (!LayerPairsToVisit.empty())
39  {
40  auto currentLayerPair = LayerPairsToVisit.front();
41  auto & currentLayerPairRef = theLayerGraph.theLayerPairs[currentLayerPair];
42  auto & currentInnerLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[0]];
43  auto & currentOuterLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[1]];
44  bool allInnerLayerPairsAlreadyVisited { true };
45 
46  for (auto innerLayerPair : currentInnerLayerRef.theInnerLayerPairs)
47  {
48  allInnerLayerPairsAlreadyVisited &=
49  alreadyVisitedLayerPairs[innerLayerPair];
50  }
51 
52  if (alreadyVisitedLayerPairs[currentLayerPair] == false
53  && allInnerLayerPairsAlreadyVisited)
54  {
55 
56  const HitDoublets* doubletLayerPairId =
57  hitDoublets[currentLayerPair];
58  auto numberOfDoublets = doubletLayerPairId->size();
59  currentLayerPairRef.theFoundCells[0] = cellId;
60  currentLayerPairRef.theFoundCells[1] = cellId+numberOfDoublets;
61  for (unsigned int i = 0; i < numberOfDoublets; ++i)
62  {
63  allCells.emplace_back(doubletLayerPairId, i,
64  doubletLayerPairId->innerHitId(i),
65  doubletLayerPairId->outerHitId(i));
66 
67 
68  currentOuterLayerRef.isOuterHitOfCell[doubletLayerPairId->outerHitId(i)].push_back(cellId);
69 
70  cellId++;
71 
72  auto & neigCells = currentInnerLayerRef.isOuterHitOfCell[doubletLayerPairId->innerHitId(i)];
73  allCells.back().checkAlignmentAndTag(allCells,
74  neigCells, ptmin, region_origin_x,
75  region_origin_y, region_origin_radius, thetaCut,
76  phiCut, hardPtCut
77  );
78 
79 
80  }
81  assert(cellId==currentLayerPairRef.theFoundCells[1]);
82  for (auto outerLayerPair : currentOuterLayerRef.theOuterLayerPairs)
83  {
84  LayerPairsToVisit.push(outerLayerPair);
85  }
86 
87  alreadyVisitedLayerPairs[currentLayerPair] = true;
88  }
89  LayerPairsToVisit.pop();
90  numberOfLayerPairsToVisitAtThisDepth--;
91  if (numberOfLayerPairsToVisitAtThisDepth == 0)
92  {
93  numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
94  }
95 
96  }
97 
98  }
99 
100 }
float originRBound() const
bounds the particle vertex in the transverse plane
std::size_t size() const
GlobalPoint const & origin() const
T y() const
Definition: PV3DBase.h:63
std::vector< CALayer > theLayers
Definition: CAGraph.h:63
int outerHitId(int i) const
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:64
std::vector< CACell > allCells
float ptMin() const
minimal pt of interest
std::vector< int > theRootLayers
Definition: CAGraph.h:65
int innerHitId(int i) const
T x() const
Definition: PV3DBase.h:62
void CellularAutomaton::evolve ( const unsigned int  minHitsPerNtuplet)

Definition at line 102 of file CellularAutomaton.cc.

References allCells, allStatus, mps_fire::i, align_cfg::iteration, theLayerGraph, CAGraph::theLayerPairs, CAGraph::theLayers, theRootCells, and CAGraph::theRootLayers.

Referenced by getAllCells(), and CAHitQuadrupletGenerator::hitNtuplets().

103 {
104  allStatus.resize(allCells.size());
105 
106 
107  unsigned int numberOfIterations = minHitsPerNtuplet - 2;
108  // keeping the last iteration for later
109  for (unsigned int iteration = 0; iteration < numberOfIterations - 1;
110  ++iteration)
111  {
112  for (auto& layerPair : theLayerGraph.theLayerPairs)
113  {
114  for (auto i =layerPair.theFoundCells[0]; i<layerPair.theFoundCells[1]; ++i)
115  {
116  allCells[i].evolve(i,allStatus);
117  }
118  }
119 
120  for (auto& layerPair : theLayerGraph.theLayerPairs)
121  {
122  for (auto i =layerPair.theFoundCells[0]; i<layerPair.theFoundCells[1]; ++i)
123  {
124  allStatus[i].updateState();
125  }
126  }
127 
128  }
129 
130  //last iteration
131 
132 
133  for(int rootLayerId : theLayerGraph.theRootLayers)
134  {
135  for(int rootLayerPair: theLayerGraph.theLayers[rootLayerId].theOuterLayerPairs)
136  {
137  auto foundCells = theLayerGraph.theLayerPairs[rootLayerPair].theFoundCells;
138  for (auto i =foundCells[0]; i<foundCells[1]; ++i)
139  {
140  auto & cell = allStatus[i];
141  allCells[i].evolve(i,allStatus);
142  cell.updateState();
143  if (cell.isRootCell(minHitsPerNtuplet - 2))
144  {
145  theRootCells.push_back(i);
146  }
147  }
148  }
149  }
150 
151 }
std::vector< CACellStatus > allStatus
std::vector< CALayer > theLayers
Definition: CAGraph.h:63
std::vector< unsigned int > theRootCells
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:64
std::vector< CACell > allCells
std::vector< int > theRootLayers
Definition: CAGraph.h:65
void CellularAutomaton::findNtuplets ( std::vector< CACell::CAntuplet > &  foundNtuplets,
const unsigned int  minHitsPerNtuplet 
)

Definition at line 153 of file CellularAutomaton.cc.

References allCells, and theRootCells.

Referenced by getAllCells(), and CAHitQuadrupletGenerator::hitNtuplets().

156 {
157  CACell::CAntuple tmpNtuplet;
158  tmpNtuplet.reserve(minHitsPerNtuplet);
159 
160  for (auto root_cell : theRootCells)
161  {
162  tmpNtuplet.clear();
163  tmpNtuplet.push_back(root_cell);
164  allCells[root_cell].findNtuplets(allCells,foundNtuplets, tmpNtuplet, minHitsPerNtuplet);
165  }
166 
167 }
std::vector< unsigned int > CAntuple
Definition: CACell.h:39
std::vector< unsigned int > theRootCells
std::vector< CACell > allCells
void CellularAutomaton::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 at line 170 of file CellularAutomaton.cc.

References allCells, mps_fire::i, HitDoublets::innerHitId(), TrackingRegion::origin(), TrackingRegion::originRBound(), HitDoublets::outerHitId(), TrackingRegion::ptMin(), HitDoublets::size(), theLayerGraph, CAGraph::theLayerPairs, CAGraph::theLayers, CAGraph::theRootLayers, class-composition::visited, PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

Referenced by getAllCells(), and CAHitTripletGenerator::hitNtuplets().

172 {
173  int tsize=0;
174  for ( auto hd : hitDoublets) tsize+=hd->size();
175  allCells.reserve(tsize);
176 
177  unsigned int cellId = 0;
178  float ptmin = region.ptMin();
179  float region_origin_x = region.origin().x();
180  float region_origin_y = region.origin().y();
181  float region_origin_radius = region.originRBound();
182 
183  std::vector<bool> alreadyVisitedLayerPairs;
184  alreadyVisitedLayerPairs.resize(theLayerGraph.theLayerPairs.size());
185  for (auto visited : alreadyVisitedLayerPairs)
186  {
187  visited = false;
188  }
189  for (int rootVertex : theLayerGraph.theRootLayers)
190  {
191 
192  std::queue<int> LayerPairsToVisit;
193 
194  for (int LayerPair : theLayerGraph.theLayers[rootVertex].theOuterLayerPairs)
195  {
196  LayerPairsToVisit.push(LayerPair);
197 
198  }
199 
200  unsigned int numberOfLayerPairsToVisitAtThisDepth =
201  LayerPairsToVisit.size();
202 
203  while (!LayerPairsToVisit.empty())
204  {
205  auto currentLayerPair = LayerPairsToVisit.front();
206  auto & currentLayerPairRef = theLayerGraph.theLayerPairs[currentLayerPair];
207  auto & currentInnerLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[0]];
208  auto & currentOuterLayerRef = theLayerGraph.theLayers[currentLayerPairRef.theLayers[1]];
209  bool allInnerLayerPairsAlreadyVisited { true };
210 
211  for (auto innerLayerPair : currentInnerLayerRef.theInnerLayerPairs)
212  {
213  allInnerLayerPairsAlreadyVisited &=
214  alreadyVisitedLayerPairs[innerLayerPair];
215  }
216 
217  if (alreadyVisitedLayerPairs[currentLayerPair] == false
218  && allInnerLayerPairsAlreadyVisited)
219  {
220 
221  const HitDoublets* doubletLayerPairId =
222  hitDoublets[currentLayerPair];
223  auto numberOfDoublets = doubletLayerPairId->size();
224  currentLayerPairRef.theFoundCells[0] = cellId;
225  currentLayerPairRef.theFoundCells[1] = cellId+numberOfDoublets;
226  for (unsigned int i = 0; i < numberOfDoublets; ++i)
227  {
228  allCells.emplace_back(doubletLayerPairId, i,
229  doubletLayerPairId->innerHitId(i),
230  doubletLayerPairId->outerHitId(i));
231 
232 
233  currentOuterLayerRef.isOuterHitOfCell[doubletLayerPairId->outerHitId(i)].push_back(cellId);
234 
235  cellId++;
236 
237  auto & neigCells = currentInnerLayerRef.isOuterHitOfCell[doubletLayerPairId->innerHitId(i)];
238  allCells.back().checkAlignmentAndPushTriplet(allCells,
239  neigCells, foundTriplets, ptmin, region_origin_x,
240  region_origin_y, region_origin_radius, thetaCut,
241  phiCut, hardPtCut
242  );
243  }
244  assert(cellId==currentLayerPairRef.theFoundCells[1]);
245 
246 
247  for (auto outerLayerPair : currentOuterLayerRef.theOuterLayerPairs)
248  {
249  LayerPairsToVisit.push(outerLayerPair);
250  }
251 
252  alreadyVisitedLayerPairs[currentLayerPair] = true;
253  }
254  LayerPairsToVisit.pop();
255  numberOfLayerPairsToVisitAtThisDepth--;
256  if (numberOfLayerPairsToVisitAtThisDepth == 0)
257  {
258  numberOfLayerPairsToVisitAtThisDepth = LayerPairsToVisit.size();
259  }
260 
261  }
262 
263  }
264 
265 }
float originRBound() const
bounds the particle vertex in the transverse plane
std::size_t size() const
GlobalPoint const & origin() const
T y() const
Definition: PV3DBase.h:63
std::vector< CALayer > theLayers
Definition: CAGraph.h:63
int outerHitId(int i) const
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:64
std::vector< CACell > allCells
float ptMin() const
minimal pt of interest
std::vector< int > theRootLayers
Definition: CAGraph.h:65
int innerHitId(int i) const
T x() const
Definition: PV3DBase.h:62
std::vector<CACell>& CellularAutomaton::getAllCells ( )
inline

Member Data Documentation

std::vector<CACell> CellularAutomaton::allCells
private
std::vector<CACellStatus> CellularAutomaton::allStatus
private

Definition at line 31 of file CellularAutomaton.h.

Referenced by evolve().

CAGraph& CellularAutomaton::theLayerGraph
private

Definition at line 28 of file CellularAutomaton.h.

Referenced by createAndConnectCells(), evolve(), and findTriplets().

std::vector<std::vector<CACell*> > CellularAutomaton::theNtuplets
private

Definition at line 34 of file CellularAutomaton.h.

std::vector<unsigned int> CellularAutomaton::theRootCells
private

Definition at line 33 of file CellularAutomaton.h.

Referenced by evolve(), and findNtuplets().