CMS 3D CMS Logo

SeedingLayerSetsHits.h
Go to the documentation of this file.
1 #ifndef TrackingTools_TransientTrackingRecHit_SeedingLayerSetsHits
2 #define TrackingTools_TransientTrackingRecHit_SeedingLayerSetsHits
3 
4 
7 
8 #include <vector>
9 #include <string>
10 #include <utility>
11 
12 class DetLayer;
13 
20 public:
22  using TkHitRef = BaseTrackerRecHit const &;
24  using OwnedHits=std::vector<HitPointer>;
25 
27  using Hits = std::vector<ConstRecHitPointer>;
28 
29  typedef unsigned short LayerSetIndex;
30  typedef unsigned short LayerIndex;
31  typedef unsigned int HitIndex;
32 
38  class SeedingLayer {
39  public:
41  SeedingLayer(const SeedingLayerSetsHits *sls, LayerIndex index):
42  seedingLayerSets_(sls), index_(index) {}
43 
50  LayerIndex index() const { return index_; }
51  const std::string& name() const { return (*seedingLayerSets_->layerNames_)[index_]; }
52  const DetLayer *detLayer() const { return (*seedingLayerSets_->layerDets_)[index_]; }
53  Hits hits() const { return seedingLayerSets_->hits(index_); }
54 
55  private:
57  LayerIndex index_;
58  };
59 
68  public:
70  public:
71  typedef std::vector<LayerSetIndex>::const_iterator internal_iterator_type;
73  typedef internal_iterator_type::difference_type difference_type;
74 
76  const_iterator(const SeedingLayerSetsHits *sls, internal_iterator_type iter): seedingLayerSets_(sls), iter_(iter) {}
77 
78  value_type operator*() const { return SeedingLayer(seedingLayerSets_, *iter_); }
79 
80  const_iterator& operator++() { ++iter_; return *this; }
82  const_iterator clone(*this);
83  ++clone;
84  return clone;
85  }
86 
87  bool operator==(const const_iterator& other) const { return iter_ == other.iter_; }
88  bool operator!=(const const_iterator& other) const { return !operator==(other); }
89 
90  private:
92  internal_iterator_type iter_;
93  };
94 
96  SeedingLayerSet(const SeedingLayerSetsHits *sls, std::vector<LayerSetIndex>::const_iterator begin, std::vector<LayerSetIndex>::const_iterator end):
97  seedingLayerSets_(sls), begin_(begin), end_(end) {}
98 
100  LayerSetIndex size() const { return end_-begin_; }
101 
114  SeedingLayerSet slice(size_t begin, size_t end) const {
115  assert(begin < size());
116  assert(0 < end && end <= size());
117  assert(begin < end);
118  return SeedingLayerSet(seedingLayerSets_, begin_+begin, begin_+end);
119  }
120 
122  SeedingLayer operator[](LayerSetIndex index) const {
123  return SeedingLayer(seedingLayerSets_, *(begin_+index));
124  }
125 
126  // iterators for range-for
128  const_iterator cbegin() const { return begin(); }
130  const_iterator cend() const { return end(); }
131 
132  private:
134  std::vector<LayerSetIndex>::const_iterator begin_; // Iterator to SeedingLayerSetsHits::layerSetIndices_, first layer
135  std::vector<LayerSetIndex>::const_iterator end_; // Iterator to SeedingLayerSetsHits::layerSetIndices_, last+1 layer
136  };
137 
139  public:
140  typedef std::vector<LayerSetIndex>::const_iterator internal_iterator_type;
142  typedef internal_iterator_type::difference_type difference_type;
143 
145  const_iterator(const SeedingLayerSetsHits *sls, internal_iterator_type iter): seedingLayerSets_(sls), iter_(iter) {}
146 
147  value_type operator*() const { return SeedingLayerSet(seedingLayerSets_, iter_, iter_+seedingLayerSets_->nlayers_); }
148 
149  const_iterator& operator++() { std::advance(iter_, seedingLayerSets_->nlayers_); return *this; }
151  const_iterator clone(*this);
152  ++(*this);
153  return clone;
154  }
155 
156  bool operator==(const const_iterator& other) const { return iter_ == other.iter_; }
157  bool operator!=(const const_iterator& other) const { return !operator==(other); }
158 
159  private:
161  internal_iterator_type iter_;
162  };
163 
164 
165  SeedingLayerSetsHits() = default;
166 
175  SeedingLayerSetsHits(unsigned short nlayers,
176  const std::vector<LayerSetIndex> *layerSetIndices,
177  const std::vector<std::string> *layerNames,
178  const std::vector<const DetLayer *> *layerDets);
179 
180  ~SeedingLayerSetsHits() = default;
185 
186 
187  void shrink_to_fit();
188  void addHits(LayerIndex layerIndex, OwnedHits&& hits);
189 
190 
192  unsigned short numberOfLayersInSet() const { return nlayers_; }
194  unsigned short size() const { return nlayers_ > 0 ? layerSetIndices_->size() / nlayers_ : 0; }
195 
197  SeedingLayerSet operator[](LayerSetIndex index) const {
198  std::vector<LayerSetIndex>::const_iterator begin = layerSetIndices_->begin()+nlayers_*index;
199  std::vector<LayerSetIndex>::const_iterator end = begin+nlayers_;
200  return SeedingLayerSet(this, begin, end);
201  }
202 
203  // iterators for range-for
204  const_iterator begin() const { return const_iterator(this, layerSetIndices_->begin()); }
205  const_iterator cbegin() const { return begin(); }
206  const_iterator end() const { return const_iterator(this, layerSetIndices_->end()); }
207  const_iterator cend() const { return end(); }
208 
209  // for more efficient edm::Event::put()
211  std::swap(nlayers_, other.nlayers_);
216  rechits_.swap(other.rechits_);
217  }
218 
219  void print() const;
220 
221 private:
222  Hits hits(LayerIndex layerIndex) const;
223 
225  unsigned short nlayers_ = 0;
226 
232  const std::vector<LayerSetIndex> *layerSetIndices_ = nullptr;
233 
234  // following are indexed by LayerIndex
235  std::vector<HitIndex> layerHitIndices_; // Indices to first hits in rechits_
236  const std::vector<std::string> *layerNames_ = nullptr; // Names of the layers
237  const std::vector<const DetLayer *> *layerDets_ = nullptr; // Pointers to corresponding DetLayer objects
238 
244 };
245 
246 #endif
const_iterator end() const
LayerSetIndex size() const
Number of layers in this set.
unsigned short numberOfLayersInSet() const
Get number of layers in each SeedingLayerSets.
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)
SeedingLayer operator[](LayerSetIndex index) const
Get a given SeedingLayer (index is between 0 and size()-1)
unsigned short LayerSetIndex
const_iterator begin() const
const_iterator cend() const
void swap(SeedingLayerSetsHits &other)
BaseTrackerRecHit const * ConstRecHitPointer
#define nullptr
bool operator!=(const const_iterator &other) const
~SeedingLayerSetsHits()=default
BaseTrackerRecHit const & TkHitRef
SeedingLayerSetsHits()=default
SeedingLayerSetsHits & operator=(SeedingLayerSetsHits const &)=delete
Hits hits(LayerIndex layerIndex) const
std::vector< LayerSetIndex >::const_iterator begin_
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
SeedingLayerSet operator[](LayerSetIndex index) const
Get the SeedingLayerSet at a given index.
bool operator!=(const const_iterator &other) const
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
SeedingLayer(const SeedingLayerSetsHits *sls, LayerIndex index)
internal_iterator_type::difference_type difference_type
const std::vector< const DetLayer * > * layerDets_
const SeedingLayerSetsHits * seedingLayerSets_
const std::vector< LayerSetIndex > * layerSetIndices_
const std::string & name() const
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_
const_iterator cbegin() const
internal_iterator_type::difference_type difference_type
bool operator==(const const_iterator &other) const
const DetLayer * detLayer() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
const_iterator(const SeedingLayerSetsHits *sls, internal_iterator_type iter)
std::vector< HitIndex > layerHitIndices_
unsigned short nlayers_
Number of layers in a SeedingLayerSet.
std::vector< HitPointer > OwnedHits
bool operator==(const const_iterator &other) const
std::vector< LayerSetIndex >::const_iterator end_
const std::vector< std::string > * layerNames_
const SeedingLayerSetsHits * seedingLayerSets_
unsigned short size() const
Get the number of SeedingLayerSets.