CMS 3D CMS Logo

IntermediateHitTriplets.h
Go to the documentation of this file.
1 #ifndef RecoPixelVertexing_PixelTriplets_IntermediateHitTriplets_h
2 #define RecoPixelVertexing_PixelTriplets_IntermediateHitTriplets_h
3 
8 
23 public:
24  using LayerPair = std::tuple<SeedingLayerSetsHits::LayerIndex, SeedingLayerSetsHits::LayerIndex>;
25  using LayerTriplet =
26  std::tuple<SeedingLayerSetsHits::LayerIndex, SeedingLayerSetsHits::LayerIndex, SeedingLayerSetsHits::LayerIndex>;
28 
30 
40  public:
43 
44  void setTripletsEnd(unsigned int end) { tripletsEnd_ = end; }
45 
46  const LayerTriplet &layerTriplet() const { return layerTriplet_; }
47 
48  unsigned int tripletsBegin() const { return tripletsBegin_; }
49  unsigned int tripletsEnd() const { return tripletsEnd_; }
50 
51  private:
53  unsigned int tripletsBegin_;
54  unsigned int tripletsEnd_;
55  };
56 
58 
64  public:
65  using const_iterator = std::vector<OrderedHitTriplet>::const_iterator;
66 
67  LayerHitTriplets(const IntermediateHitTriplets *hitSets, const PLayerHitTriplets *layerTriplet)
68  : hitSets_(hitSets), layerTriplet_(layerTriplet) {}
69 
70  using TripletRange =
71  std::pair<std::vector<OrderedHitTriplet>::const_iterator, std::vector<OrderedHitTriplet>::const_iterator>;
72 
76 
78  const_iterator cbegin() const { return begin(); }
80  const_iterator cend() const { return end(); }
81 
82  private:
85  };
86 
88 
100  public:
101  using PLayerHitTripletsConstIterator = std::vector<PLayerHitTriplets>::const_iterator;
102  using TripletConstIterator = std::vector<OrderedHitTriplet>::const_iterator;
103 
105  public:
108  using difference_type = internal_iterator_type::difference_type;
109 
110  struct end_tag {};
111 
115  const_iterator(const IntermediateHitTriplets *hitSets, const RegionLayerSets *regionLayerSets)
116  : hitSets_(hitSets), regionLayerSets_(regionLayerSets), iter_(regionLayerSets->layerSetsBegin()) {
117  assert(regionLayerSets->layerSetsBegin() != regionLayerSets->layerSetsEnd());
118  }
119 
125  const_iterator(const IntermediateHitTriplets *hitSets, const RegionLayerSets *regionLayerSets, end_tag)
126  : iter_(regionLayerSets->layerSetsEnd()) {}
127 
128  value_type operator*() const { return value_type(hitSets_, &(*iter_)); }
129 
131  ++iter_;
132  return *this;
133  }
134 
136  const_iterator clone(*this);
137  operator++();
138  return clone;
139  }
140 
141  bool operator==(const const_iterator &other) const { return iter_ == other.iter_; }
142  bool operator!=(const const_iterator &other) const { return !operator==(other); }
143 
144  private:
148  };
149 
151  const LayerHitMapCache *cache,
152  const IntermediateHitTriplets *hitSets,
153  PLayerHitTripletsConstIterator tripletBegin,
155  : region_(region), cache_(cache), hitSets_(hitSets), layerSetsBegin_(tripletBegin), layerSetsEnd_(tripletEnd) {}
156 
157  const TrackingRegion &region() const { return *region_; }
158  const LayerHitMapCache &layerHitMapCache() const { return *cache_; }
160 
163  return const_iterator(hitSets_, this);
164  else
165  return end();
166  }
167  const_iterator cbegin() const { return begin(); }
168  const_iterator end() const { return const_iterator(hitSets_, this, const_iterator::end_tag()); }
169  const_iterator cend() const { return end(); }
170 
171  // used internally by the LayerHitTriplets helper class
174 
175  private:
176  const TrackingRegion *region_ = nullptr;
177  const LayerHitMapCache *cache_ = nullptr;
181  };
182 
184 
187 
189 
191  class RegionFiller {
192  public:
193  RegionFiller() : obj_(nullptr) {}
195 
196  ~RegionFiller() = default;
197 
198  bool valid() const { return obj_ != nullptr; }
199 
200  LayerHitMapCache &layerHitMapCache() { return obj_->regions_.back().layerHitMapCache(); }
201 
202  void addTriplets(const LayerPair &layerPair,
203  const std::vector<SeedingLayerSetsHits::SeedingLayer> &thirdLayers,
204  const OrderedHitTriplets &triplets,
205  const std::vector<int> &thirdLayerIndex,
206  const std::vector<size_t> &permutations) {
207  assert(triplets.size() == thirdLayerIndex.size());
208  assert(triplets.size() == permutations.size());
209 
210  if (triplets.empty()) {
211  return;
212  }
213 
214  int prevLayer = -1;
215  for (size_t i = 0, size = permutations.size(); i < size; ++i) {
216  // We go through the 'triplets' in the order defined by
217  // 'permutations', which is sorted such that we first go through
218  // triplets from (3rd) layer 0, then layer 1 and so on.
219  const size_t realIndex = permutations[i];
220 
221  const int layer = thirdLayerIndex[realIndex];
222  if (layer != prevLayer) {
223  prevLayer = layer;
224  obj_->layerTriplets_.emplace_back(
225  LayerTriplet(std::get<0>(layerPair), std::get<1>(layerPair), thirdLayers[layer].index()),
226  obj_->hitTriplets_.size());
227  }
228 
229  obj_->hitTriplets_.emplace_back(triplets[realIndex]);
230  obj_->layerTriplets_.back().setTripletsEnd(obj_->hitTriplets_.size());
231  }
232 
233  obj_->regions_.back().setLayerSetsEnd(obj_->layerTriplets_.size());
234  }
235 
236  private:
238  };
239 
240  // allows declaring local variables with auto
241  static RegionFiller dummyFiller() { return RegionFiller(); }
242 
244 
247  IntermediateHitTriplets(const IntermediateHitTriplets &rh); // only to make ROOT dictionary generation happy
250  ~IntermediateHitTriplets() = default;
251 
252  void reserve(size_t nregions, size_t nlayersets, size_t ntriplets) {
253  regions_.reserve(nregions);
254  layerTriplets_.reserve(nregions * nlayersets);
255  hitTriplets_.reserve(ntriplets);
256  }
257 
258  void shrink_to_fit() {
259  regions_.shrink_to_fit();
260  layerTriplets_.shrink_to_fit();
261  hitTriplets_.shrink_to_fit();
262  }
263 
265  regions_.emplace_back(region, layerTriplets_.size());
266  return RegionFiller(this);
267  }
268 
270  bool empty() const { return regions_.empty(); }
271  size_t regionSize() const { return regions_.size(); }
272  size_t tripletsSize() const { return hitTriplets_.size(); }
273 
274  const_iterator begin() const { return const_iterator(this, regions_.begin()); }
275  const_iterator cbegin() const { return begin(); }
276  const_iterator end() const { return const_iterator(this, regions_.end()); }
277  const_iterator cend() const { return end(); }
278 
279  // used internally by all the helper classes
280  std::vector<RegionIndex>::const_iterator regionsBegin() const { return regions_.begin(); }
281  std::vector<RegionIndex>::const_iterator regionsEnd() const { return regions_.end(); }
282  std::vector<PLayerHitTriplets>::const_iterator layerSetsBegin() const { return layerTriplets_.begin(); }
283  std::vector<PLayerHitTriplets>::const_iterator layerSetsEnd() const { return layerTriplets_.end(); }
284  std::vector<OrderedHitTriplet>::const_iterator tripletsBegin() const { return hitTriplets_.begin(); }
285  std::vector<OrderedHitTriplet>::const_iterator tripletsEnd() const { return hitTriplets_.end(); }
286 
287 private:
289 
290  std::vector<RegionIndex> regions_;
291  std::vector<PLayerHitTriplets>
293  std::vector<OrderedHitTriplet> hitTriplets_;
294 };
295 
296 #endif
size
Write out results.
std::vector< PLayerHitTriplets >::const_iterator layerSetsBegin() const
static RegionFiller dummyFiller()
LayerHitTriplets(const IntermediateHitTriplets *hitSets, const PLayerHitTriplets *layerTriplet)
std::vector< RegionIndex >::const_iterator regionsEnd() const
const_iterator(const IntermediateHitTriplets *hitSets, const RegionLayerSets *regionLayerSets, end_tag)
std::vector< PLayerHitTriplets >::const_iterator layerSetsEnd() const
std::tuple< SeedingLayerSetsHits::LayerIndex, SeedingLayerSetsHits::LayerIndex, SeedingLayerSetsHits::LayerIndex > LayerTriplet
const_iterator cbegin() const
SeedingLayerSetsHits::LayerIndex outerLayerIndex() const
IntermediateHitTriplets(const SeedingLayerSetsHits *seedingLayers)
const_iterator end() const
std::vector< OrderedHitTriplet >::const_iterator const_iterator
SeedingLayerSetsHits::LayerIndex middleLayerIndex() const
assert(be >=bs)
constexpr std::array< uint8_t, layerIndexSize > layer
const LayerHitMapCache & layerHitMapCache() const
std::vector< PLayerHitTriplets >::const_iterator PLayerHitTripletsConstIterator
void addTriplets(const LayerPair &layerPair, const std::vector< SeedingLayerSetsHits::SeedingLayer > &thirdLayers, const OrderedHitTriplets &triplets, const std::vector< int > &thirdLayerIndex, const std::vector< size_t > &permutations)
RegionLayerSets(const TrackingRegion *region, const LayerHitMapCache *cache, const IntermediateHitTriplets *hitSets, PLayerHitTripletsConstIterator tripletBegin, PLayerHitTripletsConstIterator tripletEnd)
PLayerHitTripletsConstIterator layerSetsBegin() const
IntermediateHitTriplets & operator=(IntermediateHitTriplets &&)=default
std::vector< OrderedHitTriplet >::const_iterator tripletsEnd() const
std::tuple< SeedingLayerSetsHits::LayerIndex, SeedingLayerSetsHits::LayerIndex > LayerPair
std::vector< RegionIndex > regions_
Pointer to SeedingLayerSetsHits (owned elsewhere)
void reserve(size_t nregions, size_t nlayersets, size_t ntriplets)
const PLayerHitTripletsConstIterator layerSetsBegin_
std::vector< OrderedHitTriplet >::const_iterator TripletConstIterator
const SeedingLayerSetsHits & seedingLayerHits() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
RegionFiller beginRegion(const TrackingRegion *region)
const_iterator begin() const
const SeedingLayerSetsHits * seedingLayers_
RegionFiller(IntermediateHitTriplets *obj)
def cache(function)
Definition: utilities.py:3
const_iterator(const IntermediateHitTriplets *hitSets, const RegionLayerSets *regionLayerSets)
Helper class enforcing correct way of filling the doublets of a region.
std::pair< std::vector< OrderedHitTriplet >::const_iterator, std::vector< OrderedHitTriplet >::const_iterator > TripletRange
const PLayerHitTripletsConstIterator layerSetsEnd_
std::vector< PLayerHitTriplets > layerTriplets_
Container of regions, each element has indices pointing to layerTriplets_.
const_iterator cend() const
ihd::const_iterator< RegionLayerSets, IntermediateHitTriplets > const_iterator
Iterator over regions.
SeedingLayerSetsHits::LayerIndex innerLayerIndex() const
std::vector< OrderedHitTriplet > hitTriplets_
Container of layer triplets, each element has indices pointing to hitTriplets_.
PLayerHitTriplets(const LayerTriplet &layerTriplet, unsigned int tripletsBegin)
std::vector< OrderedHitTriplet >::const_iterator tripletsBegin() const
unsigned int size() const override
PLayerHitTripletsConstIterator layerSetsEnd() const
~IntermediateHitTriplets()=default
std::vector< RegionIndex >::const_iterator regionsBegin() const