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 12 of file CellularAutomaton.h.

Constructor & Destructor Documentation

◆ CellularAutomaton()

CellularAutomaton::CellularAutomaton ( CAGraph graph)
inline

Definition at line 14 of file CellularAutomaton.h.

14 : theLayerGraph(graph) {}

Member Function Documentation

◆ createAndConnectCells()

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

Definition at line 5 of file CellularAutomaton.cc.

9  {
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 }

References allCells, cms::cuda::assert(), mps_fire::i, HitDoublets::innerHitId(), HitDoublets::outerHitId(), ptmin, HLT_2018_cff::region, HitDoublets::size(), theLayerGraph, CAGraph::theLayerPairs, CAGraph::theLayers, CAGraph::theRootLayers, and class-composition::visited.

Referenced by CAHitQuadrupletGenerator::hitNtuplets().

◆ evolve()

void CellularAutomaton::evolve ( const unsigned int  minHitsPerNtuplet)

Definition at line 86 of file CellularAutomaton.cc.

86  {
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 }

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

Referenced by CAHitQuadrupletGenerator::hitNtuplets().

◆ findNtuplets()

void CellularAutomaton::findNtuplets ( std::vector< CACell::CAntuplet > &  foundNtuplets,
const unsigned int  minHitsPerNtuplet 
)

Definition at line 122 of file CellularAutomaton.cc.

123  {
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 }

References allCells, and theRootCells.

Referenced by CAHitQuadrupletGenerator::hitNtuplets().

◆ findTriplets()

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 134 of file CellularAutomaton.cc.

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(
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 }

References allCells, cms::cuda::assert(), mps_fire::i, HitDoublets::innerHitId(), HitDoublets::outerHitId(), ptmin, HLT_2018_cff::region, HitDoublets::size(), theLayerGraph, CAGraph::theLayerPairs, CAGraph::theLayers, CAGraph::theRootLayers, and class-composition::visited.

Referenced by CAHitTripletGenerator::hitNtuplets().

◆ getAllCells()

std::vector<CACell>& CellularAutomaton::getAllCells ( )
inline

Definition at line 16 of file CellularAutomaton.h.

16 { return allCells; }

References allCells.

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

Member Data Documentation

◆ allCells

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

◆ allStatus

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

Definition at line 34 of file CellularAutomaton.h.

Referenced by evolve().

◆ theLayerGraph

CAGraph& CellularAutomaton::theLayerGraph
private

Definition at line 31 of file CellularAutomaton.h.

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

◆ theNtuplets

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

Definition at line 37 of file CellularAutomaton.h.

◆ theRootCells

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

Definition at line 36 of file CellularAutomaton.h.

Referenced by evolve(), and findNtuplets().

mps_fire.i
i
Definition: mps_fire.py:355
cms::cuda::assert
assert(be >=bs)
CAGraph::theRootLayers
std::vector< int > theRootLayers
Definition: CAGraph.h:47
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
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
CellularAutomaton::allCells
std::vector< CACell > allCells
Definition: CellularAutomaton.h:33
CACell::CAntuple
std::vector< unsigned int > CAntuple
Definition: CACell.h:29
align_cfg.iteration
iteration
Definition: align_cfg.py:5