CMS 3D CMS Logo

SeedingLayerSetsHits.h
Go to the documentation of this file.
1 #ifndef TrackingTools_TransientTrackingRecHit_SeedingLayerSetsHits
2 #define TrackingTools_TransientTrackingRecHit_SeedingLayerSetsHits
3 
6 
7 #include <vector>
8 #include <string>
9 #include <utility>
10 
11 class DetLayer;
12 
19 public:
21  using TkHitRef = BaseTrackerRecHit const &;
23  using OwnedHits = std::vector<HitPointer>;
24 
26  using Hits = std::vector<ConstRecHitPointer>;
27 
28  typedef unsigned short LayerSetIndex;
29  typedef unsigned short LayerIndex;
30  typedef unsigned int HitIndex;
31 
37  class SeedingLayer {
38  public:
41 
48  LayerIndex index() const { return index_; }
49  const std::string &name() const { return (*seedingLayerSets_->layerNames_)[index_]; }
50  const DetLayer *detLayer() const { return (*seedingLayerSets_->layerDets_)[index_]; }
51  Hits hits() const { return seedingLayerSets_->hits(index_); }
52 
53  private:
56  };
57 
66  public:
68  public:
69  typedef std::vector<LayerSetIndex>::const_iterator internal_iterator_type;
71  typedef internal_iterator_type::difference_type difference_type;
72 
75  : seedingLayerSets_(sls), iter_(iter) {}
76 
78 
80  ++iter_;
81  return *this;
82  }
84  const_iterator clone(*this);
85  ++clone;
86  return clone;
87  }
88 
89  bool operator==(const const_iterator &other) const { return iter_ == other.iter_; }
90  bool operator!=(const const_iterator &other) const { return !operator==(other); }
91 
92  private:
95  };
96 
99  std::vector<LayerSetIndex>::const_iterator begin,
100  std::vector<LayerSetIndex>::const_iterator end)
101  : seedingLayerSets_(sls), begin_(begin), end_(end) {}
102 
104  LayerSetIndex size() const { return end_ - begin_; }
105 
118  SeedingLayerSet slice(size_t begin, size_t end) const {
119  assert(begin < size());
120  assert(0 < end && end <= size());
121  assert(begin < end);
123  }
124 
127 
128  // iterators for range-for
130  const_iterator cbegin() const { return begin(); }
132  const_iterator cend() const { return end(); }
133 
134  private:
136  std::vector<LayerSetIndex>::const_iterator begin_; // Iterator to SeedingLayerSetsHits::layerSetIndices_, first layer
137  std::vector<LayerSetIndex>::const_iterator end_; // Iterator to SeedingLayerSetsHits::layerSetIndices_, last+1 layer
138  };
139 
141  public:
142  typedef std::vector<LayerSetIndex>::const_iterator internal_iterator_type;
144  typedef internal_iterator_type::difference_type difference_type;
145 
148  : seedingLayerSets_(sls), iter_(iter) {}
149 
152  }
153 
155  std::advance(iter_, seedingLayerSets_->nlayers_);
156  return *this;
157  }
159  const_iterator clone(*this);
160  ++(*this);
161  return clone;
162  }
163 
164  bool operator==(const const_iterator &other) const { return iter_ == other.iter_; }
165  bool operator!=(const const_iterator &other) const { return !operator==(other); }
166 
167  private:
170  };
171 
172  SeedingLayerSetsHits() = default;
173 
182  SeedingLayerSetsHits(unsigned short nlayers,
183  const std::vector<LayerSetIndex> *layerSetIndices,
184  const std::vector<std::string> *layerNames,
185  const std::vector<const DetLayer *> *layerDets);
186 
187  ~SeedingLayerSetsHits() = default;
188  SeedingLayerSetsHits(SeedingLayerSetsHits const &) = delete;
192 
193  void shrink_to_fit();
194  void addHits(LayerIndex layerIndex, OwnedHits &&hits);
195 
197  unsigned short numberOfLayersInSet() const { return nlayers_; }
199  unsigned short size() const { return nlayers_ > 0 ? layerSetIndices_->size() / nlayers_ : 0; }
200 
203  std::vector<LayerSetIndex>::const_iterator begin = layerSetIndices_->begin() + nlayers_ * index;
204  std::vector<LayerSetIndex>::const_iterator end = begin + nlayers_;
205  return SeedingLayerSet(this, begin, end);
206  }
207 
208  // iterators for range-for
209  const_iterator begin() const { return const_iterator(this, layerSetIndices_->begin()); }
210  const_iterator cbegin() const { return begin(); }
211  const_iterator end() const { return const_iterator(this, layerSetIndices_->end()); }
212  const_iterator cend() const { return end(); }
213 
214  // for more efficient edm::Event::put()
216  std::swap(nlayers_, other.nlayers_);
217  std::swap(layerSetIndices_, other.layerSetIndices_);
218  layerHitIndices_.swap(other.layerHitIndices_);
219  std::swap(layerNames_, other.layerNames_);
220  std::swap(layerDets_, other.layerDets_);
221  rechits_.swap(other.rechits_);
222  }
223 
224  void print() const;
225 
226 private:
227  Hits hits(LayerIndex layerIndex) const;
228 
230  unsigned short nlayers_ = 0;
231 
237  const std::vector<LayerSetIndex> *layerSetIndices_ = nullptr;
238 
239  // following are indexed by LayerIndex
240  std::vector<HitIndex> layerHitIndices_; // Indices to first hits in rechits_
241  const std::vector<std::string> *layerNames_ = nullptr; // Names of the layers
242  const std::vector<const DetLayer *> *layerDets_ = nullptr; // Pointers to corresponding DetLayer objects
243 
249 };
250 
251 #endif
const std::string & name() const
const_iterator begin() const
std::vector< LayerSetIndex >::const_iterator internal_iterator_type
void addHits(LayerIndex layerIndex, OwnedHits &&hits)
SeedingLayerSet slice(size_t begin, size_t end) const
const_iterator(const SeedingLayerSetsHits *sls, internal_iterator_type iter)
unsigned short LayerSetIndex
LayerSetIndex size() const
Number of layers in this set.
unsigned short size() const
Get the number of SeedingLayerSets.
void swap(SeedingLayerSetsHits &other)
SeedingLayer operator[](LayerSetIndex index) const
Get a given SeedingLayer (index is between 0 and size()-1)
bool operator!=(const const_iterator &other) const
assert(be >=bs)
~SeedingLayerSetsHits()=default
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
bool operator==(const const_iterator &other) const
BaseTrackerRecHit const & TkHitRef
bool operator==(const const_iterator &other) const
SeedingLayerSetsHits()=default
SeedingLayerSetsHits & operator=(SeedingLayerSetsHits const &)=delete
std::vector< LayerSetIndex >::const_iterator begin_
const_iterator cbegin() const
SeedingLayer(const SeedingLayerSetsHits *sls, LayerIndex index)
const_iterator cend() const
internal_iterator_type::difference_type difference_type
const std::vector< const DetLayer * > * layerDets_
const SeedingLayerSetsHits * seedingLayerSets_
const std::vector< LayerSetIndex > * layerSetIndices_
BaseTrackerRecHit const * ConstRecHitPointer
unsigned short numberOfLayersInSet() const
Get number of layers in each SeedingLayerSets.
std::vector< ConstRecHitPointer > Hits
std::vector< LayerSetIndex >::const_iterator internal_iterator_type
SeedingLayerSet(const SeedingLayerSetsHits *sls, std::vector< LayerSetIndex >::const_iterator begin, std::vector< LayerSetIndex >::const_iterator end)
const SeedingLayerSetsHits * seedingLayerSets_
internal_iterator_type::difference_type difference_type
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
const_iterator end() const
const_iterator(const SeedingLayerSetsHits *sls, internal_iterator_type iter)
std::vector< HitIndex > layerHitIndices_
Hits hits(LayerIndex layerIndex) const
unsigned short nlayers_
Number of layers in a SeedingLayerSet.
std::vector< HitPointer > OwnedHits
std::vector< LayerSetIndex >::const_iterator end_
const std::vector< std::string > * layerNames_
SeedingLayerSet operator[](LayerSetIndex index) const
Get the SeedingLayerSet at a given index.
const SeedingLayerSetsHits * seedingLayerSets_
bool operator!=(const const_iterator &other) const