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 ( CAGraph graph)
inline

Definition at line 15 of file CellularAutomaton.h.

16  : theLayerGraph(graph)
17  { }

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

References allCells, mps_fire::i, HitDoublets::innerHitId(), TrackingRegion::origin(), TrackingRegion::originRBound(), HitDoublets::outerHitId(), TrackingRegion::ptMin(), 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().

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 }
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:53
int outerHitId(int i) const
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
T x() const
Definition: PV3DBase.h:62
void CellularAutomaton::evolve ( const unsigned int  minHitsPerNtuplet)

Definition at line 83 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().

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 }
std::vector< CACellStatus > allStatus
std::vector< CALayer > theLayers
Definition: CAGraph.h:53
std::vector< unsigned int > theRootCells
std::vector< CALayerPair > theLayerPairs
Definition: CAGraph.h:54
std::vector< CACell > allCells
std::vector< int > theRootLayers
Definition: CAGraph.h:55
void CellularAutomaton::findNtuplets ( std::vector< CACell::CAntuplet > &  foundNtuplets,
const unsigned int  minHitsPerNtuplet 
)

Definition at line 120 of file CellularAutomaton.cc.

References allCells, and theRootCells.

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

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 }
std::vector< unsigned int > CAntuple
Definition: CACell.h:38
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 133 of file CellularAutomaton.cc.

References allCells, mps_fire::i, HitDoublets::innerHitId(), TrackingRegion::origin(), TrackingRegion::originRBound(), HitDoublets::outerHitId(), TrackingRegion::ptMin(), 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().

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
GlobalPoint const & origin() const
T y() const
Definition: PV3DBase.h:63
std::vector< CALayer > theLayers
Definition: CAGraph.h:53
int outerHitId(int i) const
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
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 33 of file CellularAutomaton.h.

Referenced by evolve().

CAGraph& CellularAutomaton::theLayerGraph
private

Definition at line 30 of file CellularAutomaton.h.

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

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

Definition at line 36 of file CellularAutomaton.h.

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

Definition at line 35 of file CellularAutomaton.h.

Referenced by evolve(), and findNtuplets().