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 CACut &, const CACut &, 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 CACut &thetaCut, const CACut &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 CACut thetaCut,
const CACut phiCut,
const float  hardPtCut 
)

Definition at line 5 of file CellularAutomaton.cc.

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

Referenced by CAHitQuadrupletGenerator::hitNtuplets().

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 
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 }
assert(be >=bs)
std::size_t size() const
std::vector< CALayer > theLayers
Definition: CAGraph.h:59
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:60
int outerHitId(int i) const
std::vector< CACell > allCells
double ptmin
Definition: HydjetWrapper.h:84
std::vector< int > theRootLayers
Definition: CAGraph.h:61
CAValuesByInnerLayerIds getCutsByInnerLayer(int layerIds1, int layerIds2) const
Definition: CACut.h:139
int innerHitId(int i) const

◆ evolve()

void CellularAutomaton::evolve ( const unsigned int  minHitsPerNtuplet)

Definition at line 91 of file CellularAutomaton.cc.

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

Referenced by CAHitQuadrupletGenerator::hitNtuplets().

91  {
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 }
std::vector< CACellStatus > allStatus
std::vector< CALayer > theLayers
Definition: CAGraph.h:59
std::vector< unsigned int > theRootCells
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:60
std::vector< CACell > allCells
std::vector< int > theRootLayers
Definition: CAGraph.h:61

◆ findNtuplets()

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

Definition at line 127 of file CellularAutomaton.cc.

References allCells, foundNtuplets, HLT_2022v12_cff::minHitsPerNtuplet, and theRootCells.

Referenced by CAHitQuadrupletGenerator::hitNtuplets().

128  {
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 }
std::vector< unsigned int > CAntuple
Definition: CACell.h:30
std::vector< unsigned int > theRootCells
std::vector< CACell > allCells
auto const & foundNtuplets

◆ findTriplets()

void CellularAutomaton::findTriplets ( const std::vector< const HitDoublets *> &  hitDoublets,
std::vector< CACell::CAntuplet > &  foundTriplets,
const TrackingRegion region,
const CACut thetaCut,
const CACut phiCut,
const float  hardPtCut 
)

Definition at line 139 of file CellularAutomaton.cc.

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

Referenced by CAHitTripletGenerator::hitNtuplets().

144  {
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 }
assert(be >=bs)
std::size_t size() const
std::vector< CALayer > theLayers
Definition: CAGraph.h:59
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:60
int outerHitId(int i) const
std::vector< CACell > allCells
double ptmin
Definition: HydjetWrapper.h:84
std::vector< int > theRootLayers
Definition: CAGraph.h:61
CAValuesByInnerLayerIds getCutsByInnerLayer(int layerIds1, int layerIds2) const
Definition: CACut.h:139
int innerHitId(int i) const

◆ getAllCells()

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

Definition at line 16 of file CellularAutomaton.h.

References allCells.

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

16 { return allCells; }
std::vector< CACell > allCells

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().