CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SeedFinder.h
Go to the documentation of this file.
1 #ifndef FASTSIMULATION_TRACKING_SEEDFINDER_H
2 #define FASTSIMULATION_TRACKING_SEEDFINDER_H
3 
4 // system
5 #include <vector>
6 #include <functional>
7 
8 // fastsim tracking
11 
12 class TrackerTopology;
13 class FastTrackerRecHit;
14 
16 {
17 
18 public:
19  typedef std::function<bool(const std::vector<const FastTrackerRecHit *>& hits)> Selector;
20 private:
24 
25 public:
26  SeedFinder(const SeedingTree<TrackingLayer>& seedingTree,const TrackerTopology & trackerTopology)
27  : _seedingTree(seedingTree)
28  , _trackerTopology(&trackerTopology)
29  {
30  _selector=[](const std::vector<const FastTrackerRecHit*>& hits) -> bool
31  {
32  return true;
33  };
34  }
35 
36  void setHitSelector(Selector selector)
37  {
38  _selector = selector;
39  }
40 
41  std::vector<unsigned int> getSeed(const std::vector<const FastTrackerRecHit *>& trackerRecHits) const
42  {
43  std::vector<int> hitIndicesInTree(_seedingTree.numberOfNodes(),-1);
44  //A SeedingNode is associated by its index to this list. The list stores the indices of the hits in 'trackerRecHits'
45  /* example
46  SeedingNode | hit index | hit
47  -------------------------------------------------------------------------------
48  index= 0: [BPix1] | hitIndicesInTree[0] (=1) | trackerRecHits[1]
49  index= 1: -- [BPix2] | hitIndicesInTree[1] (=3) | trackerRecHits[3]
50  index= 2: -- -- [BPix3] | hitIndicesInTree[2] (=4) | trackerRecHits[4]
51  index= 3: -- -- [FPix1_pos] | hitIndicesInTree[3] (=6) | trackerRecHits[6]
52  index= 4: -- -- [FPix1_neg] | hitIndicesInTree[4] (=7) | trackerRecHits[7]
53 
54  The implementation has been chosen such that the tree only needs to be build once upon construction.
55  */
56  std::vector<TrajectorySeedHitCandidate> seedHitCandidates;
57  for(const FastTrackerRecHit * trackerRecHit : trackerRecHits){
58  TrajectorySeedHitCandidate seedHitCandidate(trackerRecHit,_trackerTopology);
59  seedHitCandidates.push_back(std::move(seedHitCandidate));
60  }
61  return iterateHits(0,seedHitCandidates,hitIndicesInTree,true);
62 
63  //TODO: create pairs of TrackingLayer -> remove TrajectorySeedHitCandidate class
64  }
65 
66 
68  const std::vector<TrajectorySeedHitCandidate>& trackerRecHits,
69  std::vector<int>& hitIndicesInTree,
70  const SeedingNode<TrackingLayer>* node, unsigned int trackerHit) const
71  {
72  if (!node->getParent() || hitIndicesInTree[node->getParent()->getIndex()]>=0)
73  {
74  if (hitIndicesInTree[node->getIndex()]<0)
75  {
76  const TrajectorySeedHitCandidate& currentTrackerHit = trackerRecHits[trackerHit];
77  if (currentTrackerHit.getTrackingLayer()!=node->getData())
78  {
79  return nullptr;
80  }
81 
82  //fill vector of Hits from node to root to be passed to the selector function
83  std::vector<const FastTrackerRecHit*> seedCandidateHitList(node->getDepth()+1);
84  seedCandidateHitList[node->getDepth()]=currentTrackerHit.hit();
85  const SeedingNode<TrackingLayer>* parentNode = node->getParent();
86  while (parentNode!=nullptr)
87  {
88  seedCandidateHitList[parentNode->getDepth()]=trackerRecHits[hitIndicesInTree[parentNode->getIndex()]].hit();
89  parentNode = parentNode->getParent();
90  }
91 
92  if (!_selector(seedCandidateHitList))
93  {
94  return nullptr;
95  }
96 
97  hitIndicesInTree[node->getIndex()]=trackerHit;
98  if (node->getChildrenSize()==0)
99  {
100  return node;
101  }
102 
103  return nullptr;
104  }
105  else
106  {
107  for (unsigned int ichild = 0; ichild<node->getChildrenSize(); ++ichild)
108  {
109  const SeedingNode<TrackingLayer>* seed = insertHit(trackerRecHits,hitIndicesInTree,node->getChild(ichild),trackerHit);
110  if (seed)
111  {
112  return seed;
113  }
114  }
115  }
116  }
117  return nullptr;
118  }
119 
120  std::vector<unsigned int> iterateHits(
121  unsigned int start,
122  const std::vector<TrajectorySeedHitCandidate>& trackerRecHits,
123  std::vector<int> hitIndicesInTree,
124  bool processSkippedHits) const
125  {
126  for (unsigned int irecHit = start; irecHit<trackerRecHits.size(); ++irecHit)
127  {
128 
129  // only accept hits that are on one of the requested layers
130  if(_seedingTree.getSingleSet().find(trackerRecHits[irecHit].getTrackingLayer())==_seedingTree.getSingleSet().end())
131  {
132  continue;
133  }
134 
135  unsigned int currentHitIndex=irecHit;
136 
137  for (unsigned int inext=currentHitIndex+1; inext< trackerRecHits.size(); ++inext)
138  {
139  //if multiple hits are on the same layer -> follow all possibilities by recusion
140  if (trackerRecHits[currentHitIndex].getTrackingLayer()==trackerRecHits[inext].getTrackingLayer())
141  {
142  if (processSkippedHits)
143  {
144  //recusively call the method again with hit 'inext' but skip all following on the same layer though 'processSkippedHits=false'
145  std::vector<unsigned int> seedHits = iterateHits(
146  inext,
147  trackerRecHits,
148  hitIndicesInTree,
149  false
150  );
151  if (seedHits.size()>0)
152  {
153  return seedHits;
154  }
155  }
156  irecHit+=1;
157  }
158  else
159  {
160  break;
161  }
162  }
163 
164  //processSkippedHits=true
165 
166  const SeedingNode<TrackingLayer>* seedNode = nullptr;
167  for (unsigned int iroot=0; seedNode==nullptr && iroot<_seedingTree.numberOfRoots(); ++iroot)
168  {
169  seedNode=insertHit(trackerRecHits,hitIndicesInTree,_seedingTree.getRoot(iroot), currentHitIndex);
170  }
171  if (seedNode)
172  {
173  std::vector<unsigned int> seedIndices(seedNode->getDepth()+1);
174  while (seedNode)
175  {
176  seedIndices[seedNode->getDepth()]=hitIndicesInTree[seedNode->getIndex()];
177  seedNode=seedNode->getParent();
178  }
179  return seedIndices;
180  }
181 
182  }
183 
184  return std::vector<unsigned int>();
185  }
186 };
187 
188 #endif
189 
Selector _selector
Definition: SeedFinder.h:21
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
const SingleSet & getSingleSet() const
Definition: SeedingTree.h:203
const DATA & getData() const
Definition: SeedingTree.h:136
unsigned int getChildrenSize() const
Definition: SeedingTree.h:121
const SeedingNode< TrackingLayer > * insertHit(const std::vector< TrajectorySeedHitCandidate > &trackerRecHits, std::vector< int > &hitIndicesInTree, const SeedingNode< TrackingLayer > *node, unsigned int trackerHit) const
Definition: SeedFinder.h:67
unsigned int getDepth() const
Definition: SeedingTree.h:84
const SeedingNode * getParent() const
Definition: SeedingTree.h:112
unsigned int numberOfNodes() const
Definition: SeedingTree.h:226
unsigned int numberOfRoots() const
Definition: SeedingTree.h:221
def move
Definition: eostools.py:510
std::vector< unsigned int > getSeed(const std::vector< const FastTrackerRecHit * > &trackerRecHits) const
Definition: SeedFinder.h:41
SeedFinder(const SeedingTree< TrackingLayer > &seedingTree, const TrackerTopology &trackerTopology)
Definition: SeedFinder.h:26
Functor that operates on &lt;T&gt;
Definition: Selector.h:24
std::vector< unsigned int > iterateHits(unsigned int start, const std::vector< TrajectorySeedHitCandidate > &trackerRecHits, std::vector< int > hitIndicesInTree, bool processSkippedHits) const
Definition: SeedFinder.h:120
const SeedingTree< TrackingLayer > & _seedingTree
Definition: SeedFinder.h:22
const SeedingNode< DATA > * getRoot(unsigned int i) const
Definition: SeedingTree.h:231
void setHitSelector(Selector selector)
Definition: SeedFinder.h:36
const FastTrackerRecHit * hit() const
The Hit itself.
unsigned int getIndex() const
Definition: SeedingTree.h:107
const TrackingLayer & getTrackingLayer() const
const SeedingNode< DATA > * getChild(unsigned int ichild) const
Definition: SeedingTree.h:126
const TrackerTopology * _trackerTopology
Definition: SeedFinder.h:23