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:
25  SeedingLayerSetsHits::LayerIndex>;
28  SeedingLayerSetsHits::LayerIndex>;
30 
32 
42  public:
44  layerTriplet_(layerTriplet),
45  tripletsBegin_(tripletsBegin), tripletsEnd_(tripletsBegin)
46  {}
47 
48  void setTripletsEnd(unsigned int end) { tripletsEnd_ = end; }
49 
50  const LayerTriplet& layerTriplet() const { return layerTriplet_; }
51 
52  unsigned int tripletsBegin() const { return tripletsBegin_; }
53  unsigned int tripletsEnd() const { return tripletsEnd_; }
54 
55  private:
57  unsigned int tripletsBegin_;
58  unsigned int tripletsEnd_;
59  };
60 
62 
68  public:
69  using const_iterator = std::vector<OrderedHitTriplet>::const_iterator;
70 
73  hitSets_(hitSets),
74  layerTriplet_(layerTriplet)
75  {}
76 
77  using TripletRange = std::pair<std::vector<OrderedHitTriplet>::const_iterator,
78  std::vector<OrderedHitTriplet>::const_iterator>;
79 
80  SeedingLayerSetsHits::LayerIndex innerLayerIndex() const { return std::get<0>(layerTriplet_->layerTriplet()); }
81  SeedingLayerSetsHits::LayerIndex middleLayerIndex() const { return std::get<1>(layerTriplet_->layerTriplet()); }
82  SeedingLayerSetsHits::LayerIndex outerLayerIndex() const { return std::get<2>(layerTriplet_->layerTriplet()); }
83 
84  const_iterator begin() const { return hitSets_->tripletsBegin() + layerTriplet_->tripletsBegin(); }
85  const_iterator cbegin() const { return begin(); }
86  const_iterator end() const { return hitSets_->tripletsBegin() + layerTriplet_->tripletsEnd(); }
87  const_iterator cend() const { return end(); }
88 
89  private:
92  };
93 
95 
107  public:
108  using PLayerHitTripletsConstIterator = std::vector<PLayerHitTriplets>::const_iterator;
109  using TripletConstIterator = std::vector<OrderedHitTriplet>::const_iterator;
110 
112  public:
115  using difference_type = internal_iterator_type::difference_type;
116 
117  struct end_tag {};
118 
122  const_iterator(const IntermediateHitTriplets *hitSets, const RegionLayerSets *regionLayerSets):
123  hitSets_(hitSets),
124  regionLayerSets_(regionLayerSets),
125  iter_(regionLayerSets->layerSetsBegin())
126  {
127  assert(regionLayerSets->layerSetsBegin() != regionLayerSets->layerSetsEnd());
128  }
129 
135  const_iterator(const IntermediateHitTriplets *hitSets, const RegionLayerSets *regionLayerSets, end_tag):
136  iter_(regionLayerSets->layerSetsEnd())
137  {}
138 
140  return value_type(hitSets_, &(*iter_));
141  }
142 
144  ++iter_;
145  return *this;
146  }
147 
149  const_iterator clone(*this);
150  operator++();
151  return clone;
152  }
153 
154  bool operator==(const const_iterator& other) const { return iter_ == other.iter_; }
155  bool operator!=(const const_iterator& other) const { return !operator==(other); }
156 
157  private:
161  };
162 
164  const LayerHitMapCache *cache,
165  const IntermediateHitTriplets *hitSets,
166  PLayerHitTripletsConstIterator tripletBegin,
167  PLayerHitTripletsConstIterator tripletEnd):
168  region_(region),
169  cache_(cache),
170  hitSets_(hitSets),
171  layerSetsBegin_(tripletBegin), layerSetsEnd_(tripletEnd)
172  {}
173 
174  const TrackingRegion& region() const { return *region_; }
175  const LayerHitMapCache& layerHitMapCache() const { return *cache_; }
176  size_t layerTripletsSize() const { return std::distance(layerSetsBegin_, layerSetsEnd_); }
177 
179  if(layerSetsBegin_ != layerSetsEnd_)
180  return const_iterator(hitSets_, this);
181  else
182  return end();
183  }
184  const_iterator cbegin() const { return begin(); }
185  const_iterator end() const { return const_iterator(hitSets_, this, const_iterator::end_tag()); }
186  const_iterator cend() const { return end(); }
187 
188  // used internally by the LayerHitTriplets helper class
189  PLayerHitTripletsConstIterator layerSetsBegin() const { return layerSetsBegin_; }
190  PLayerHitTripletsConstIterator layerSetsEnd() const { return layerSetsEnd_; }
191 
192  private:
193  const TrackingRegion *region_ = nullptr;
194  const LayerHitMapCache *cache_ = nullptr;
195  const IntermediateHitTriplets *hitSets_ = nullptr;
198  };
199 
201 
204 
206 
208  class RegionFiller {
209  public:
210  RegionFiller(): obj_(nullptr) {}
211  explicit RegionFiller(IntermediateHitTriplets *obj): obj_(obj) {}
212 
213  ~RegionFiller() = default;
214 
215  bool valid() const { return obj_ != nullptr; }
216 
217  LayerHitMapCache& layerHitMapCache() { return obj_->regions_.back().layerHitMapCache(); }
218 
219  void addTriplets(const LayerPair& layerPair,
220  const std::vector<SeedingLayerSetsHits::SeedingLayer>& thirdLayers,
221  const OrderedHitTriplets& triplets,
222  const std::vector<int>& thirdLayerIndex,
223  const std::vector<size_t>& permutations) {
224  assert(triplets.size() == thirdLayerIndex.size());
225  assert(triplets.size() == permutations.size());
226 
227  if(triplets.empty()) {
228  return;
229  }
230 
231  int prevLayer = -1;
232  for(size_t i=0, size=permutations.size(); i<size; ++i) {
233  // We go through the 'triplets' in the order defined by
234  // 'permutations', which is sorted such that we first go through
235  // triplets from (3rd) layer 0, then layer 1 and so on.
236  const size_t realIndex = permutations[i];
237 
238  const int layer = thirdLayerIndex[realIndex];
239  if(layer != prevLayer) {
240  prevLayer = layer;
241  obj_->layerTriplets_.emplace_back(LayerTriplet(std::get<0>(layerPair), std::get<1>(layerPair), thirdLayers[layer].index()), obj_->hitTriplets_.size());
242  }
243 
244  obj_->hitTriplets_.emplace_back(triplets[realIndex]);
245  obj_->layerTriplets_.back().setTripletsEnd(obj_->hitTriplets_.size());
246  }
247 
248  obj_->regions_.back().setLayerSetsEnd(obj_->layerTriplets_.size());
249  }
250  private:
252  };
253 
254  // allows declaring local variables with auto
255  static RegionFiller dummyFiller() { return RegionFiller(); }
256 
258 
261  IntermediateHitTriplets(const IntermediateHitTriplets& rh); // only to make ROOT dictionary generation happy
264  ~IntermediateHitTriplets() = default;
265 
266  void reserve(size_t nregions, size_t nlayersets, size_t ntriplets) {
267  regions_.reserve(nregions);
268  layerTriplets_.reserve(nregions*nlayersets);
269  hitTriplets_.reserve(ntriplets);
270  }
271 
272  void shrink_to_fit() {
273  regions_.shrink_to_fit();
274  layerTriplets_.shrink_to_fit();
275  hitTriplets_.shrink_to_fit();
276  }
277 
279  regions_.emplace_back(region, layerTriplets_.size());
280  return RegionFiller(this);
281  }
282 
284  bool empty() const { return regions_.empty(); }
285  size_t regionSize() const { return regions_.size(); }
286  size_t tripletsSize() const { return hitTriplets_.size(); }
287 
288  const_iterator begin() const { return const_iterator(this, regions_.begin()); }
289  const_iterator cbegin() const { return begin(); }
290  const_iterator end() const { return const_iterator(this, regions_.end()); }
291  const_iterator cend() const { return end(); }
292 
293  // used internally by all the helper classes
294  std::vector<RegionIndex>::const_iterator regionsBegin() const { return regions_.begin(); }
295  std::vector<RegionIndex>::const_iterator regionsEnd() const { return regions_.end(); }
296  std::vector<PLayerHitTriplets>::const_iterator layerSetsBegin() const { return layerTriplets_.begin(); }
297  std::vector<PLayerHitTriplets>::const_iterator layerSetsEnd() const { return layerTriplets_.end(); }
298  std::vector<OrderedHitTriplet>::const_iterator tripletsBegin() const { return hitTriplets_.begin(); }
299  std::vector<OrderedHitTriplet>::const_iterator tripletsEnd() const { return hitTriplets_.end(); }
300 
301 private:
303 
304  std::vector<RegionIndex> regions_;
305  std::vector<PLayerHitTriplets> layerTriplets_;
306  std::vector<OrderedHitTriplet> hitTriplets_;
307 };
308 
309 #endif
size
Write out results.
static RegionFiller dummyFiller()
const_iterator begin() const
LayerHitTriplets(const IntermediateHitTriplets *hitSets, const PLayerHitTriplets *layerTriplet)
SeedingLayerSetsHits::LayerIndex outerLayerIndex() const
const_iterator(const IntermediateHitTriplets *hitSets, const RegionLayerSets *regionLayerSets, end_tag)
std::tuple< SeedingLayerSetsHits::LayerIndex, SeedingLayerSetsHits::LayerIndex, SeedingLayerSetsHits::LayerIndex > LayerTriplet
std::vector< PLayerHitTriplets >::const_iterator layerSetsEnd() const
std::vector< RegionIndex >::const_iterator regionsEnd() const
#define nullptr
const_iterator cbegin() const
IntermediateHitTriplets(const SeedingLayerSetsHits *seedingLayers)
std::vector< PLayerHitTriplets >::const_iterator layerSetsBegin() const
std::vector< OrderedHitTriplet >::const_iterator const_iterator
std::vector< RegionIndex >::const_iterator regionsBegin() const
const_iterator end() const
std::vector< PLayerHitTriplets >::const_iterator PLayerHitTripletsConstIterator
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
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)
IntermediateHitTriplets & operator=(IntermediateHitTriplets &&)=default
const SeedingLayerSetsHits & seedingLayerHits() const
std::tuple< SeedingLayerSetsHits::LayerIndex, SeedingLayerSetsHits::LayerIndex > LayerPair
unsigned int size() const override
std::vector< RegionIndex > regions_
Pointer to SeedingLayerSetsHits (owned elsewhere)
const_iterator cend() const
PLayerHitTripletsConstIterator layerSetsEnd() const
void reserve(size_t nregions, size_t nlayersets, size_t ntriplets)
const PLayerHitTripletsConstIterator layerSetsBegin_
std::vector< OrderedHitTriplet >::const_iterator TripletConstIterator
SeedingLayerSetsHits::LayerIndex middleLayerIndex() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
RegionFiller beginRegion(const TrackingRegion *region)
PLayerHitTripletsConstIterator layerSetsBegin() const
const SeedingLayerSetsHits * seedingLayers_
SeedingLayerSetsHits::LayerIndex innerLayerIndex() const
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_.
ihd::const_iterator< RegionLayerSets, IntermediateHitTriplets > const_iterator
Iterator over regions.
std::vector< OrderedHitTriplet > hitTriplets_
Container of layer triplets, each element has indices pointing to hitTriplets_.
PLayerHitTriplets(const LayerTriplet &layerTriplet, unsigned int tripletsBegin)
const LayerHitMapCache & layerHitMapCache() const
std::vector< OrderedHitTriplet >::const_iterator tripletsBegin() const
~IntermediateHitTriplets()=default
std::vector< OrderedHitTriplet >::const_iterator tripletsEnd() const