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 
27 public:
29  using TkHitRef = BaseTrackerRecHit const &;
31  using OwnedHits=std::vector<HitPointer>;
32 
34  using Hits = std::vector<ConstRecHitPointer>;
35 
36  typedef unsigned short LayerSetIndex;
37  typedef unsigned short LayerIndex;
38  typedef unsigned int HitIndex;
39 
45  class SeedingLayer {
46  public:
48  SeedingLayer(const SeedingLayerSetsHits *sls, LayerIndex index):
49  seedingLayerSets_(sls), index_(index) {}
50 
57  LayerIndex index() const { return index_; }
58  const std::string& name() const { return (*seedingLayerSets_->layerNames_)[index_]; }
59  const DetLayer *detLayer() const { return seedingLayerSets_->layerDets_[index_]; }
60  Hits hits() const { return seedingLayerSets_->hits(index_); }
61 
62  private:
64  LayerIndex index_;
65  };
66 
75  public:
77  public:
78  typedef std::vector<LayerSetIndex>::const_iterator internal_iterator_type;
80  typedef internal_iterator_type::difference_type difference_type;
81 
83  const_iterator(const SeedingLayerSetsHits *sls, internal_iterator_type iter): seedingLayerSets_(sls), iter_(iter) {}
84 
85  value_type operator*() const { return SeedingLayer(seedingLayerSets_, *iter_); }
86 
87  const_iterator& operator++() { ++iter_; return *this; }
89  const_iterator clone(*this);
90  ++clone;
91  return clone;
92  }
93 
94  bool operator==(const const_iterator& other) const { return iter_ == other.iter_; }
95  bool operator!=(const const_iterator& other) const { return !operator==(other); }
96 
97  private:
99  internal_iterator_type iter_;
100  };
101 
103  SeedingLayerSet(const SeedingLayerSetsHits *sls, std::vector<LayerSetIndex>::const_iterator begin, std::vector<LayerSetIndex>::const_iterator end):
104  seedingLayerSets_(sls), begin_(begin), end_(end) {}
105 
107  LayerSetIndex size() const { return end_-begin_; }
108 
121  SeedingLayerSet slice(size_t begin, size_t end) const {
122  assert(begin < size());
123  assert(0 < end && end <= size());
124  assert(begin < end);
125  return SeedingLayerSet(seedingLayerSets_, begin_+begin, begin_+end);
126  }
127 
129  SeedingLayer operator[](LayerSetIndex index) const {
130  return SeedingLayer(seedingLayerSets_, *(begin_+index));
131  }
132 
133  // iterators for range-for
135  const_iterator cbegin() const { return begin(); }
137  const_iterator cend() const { return end(); }
138 
139  private:
141  std::vector<LayerSetIndex>::const_iterator begin_; // Iterator to SeedingLayerSetsHits::layerSetIndices_, first layer
142  std::vector<LayerSetIndex>::const_iterator end_; // Iterator to SeedingLayerSetsHits::layerSetIndices_, last+1 layer
143  };
144 
146  public:
147  typedef std::vector<LayerSetIndex>::const_iterator internal_iterator_type;
149  typedef internal_iterator_type::difference_type difference_type;
150 
152  const_iterator(const SeedingLayerSetsHits *sls, internal_iterator_type iter): seedingLayerSets_(sls), iter_(iter) {}
153 
154  value_type operator*() const { return SeedingLayerSet(seedingLayerSets_, iter_, iter_+seedingLayerSets_->nlayers_); }
155 
156  const_iterator& operator++() { std::advance(iter_, seedingLayerSets_->nlayers_); return *this; }
158  const_iterator clone(*this);
159  ++(*this);
160  return clone;
161  }
162 
163  bool operator==(const const_iterator& other) const { return iter_ == other.iter_; }
164  bool operator!=(const const_iterator& other) const { return !operator==(other); }
165 
166  private:
168  internal_iterator_type iter_;
169  };
170 
171 
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 
192 
193 
194  void swapHits(std::vector<HitIndex>& layerHitIndices, OwnedHits& hits);
195 
196 
198  unsigned short numberOfLayersInSet() const { return nlayers_; }
200  unsigned short size() const { return nlayers_ > 0 ? layerSetIndices_->size() / nlayers_ : 0; }
201 
203  SeedingLayerSet operator[](LayerSetIndex index) const {
204  std::vector<LayerSetIndex>::const_iterator begin = layerSetIndices_->begin()+nlayers_*index;
205  std::vector<LayerSetIndex>::const_iterator end = begin+nlayers_;
206  return SeedingLayerSet(this, begin, end);
207  }
208 
209  // iterators for range-for
210  const_iterator begin() const { return const_iterator(this, layerSetIndices_->begin()); }
211  const_iterator cbegin() const { return begin(); }
212  const_iterator end() const { return const_iterator(this, layerSetIndices_->end()); }
213  const_iterator cend() const { return end(); }
214 
215  // for more efficient edm::Event::put()
217  std::swap(nlayers_, other.nlayers_);
221  layerDets_.swap(other.layerDets_);
222  rechits_.swap(other.rechits_);
223  }
224 
225  void print() const;
226 
227 private:
228  Hits hits(LayerIndex layerIndex) const;
229 
231  unsigned short nlayers_;
232 
238  const std::vector<LayerSetIndex> *layerSetIndices_;
239 
240  // following are indexed by LayerIndex
241  std::vector<HitIndex> layerHitIndices_; // Indices to first hits in rechits_
242  const std::vector<std::string> *layerNames_; // Names of the layers
243  std::vector<const DetLayer *> layerDets_; // Pointers to corresponding DetLayer objects
244 
250 };
251 
252 #endif
void swapHits(std::vector< HitIndex > &layerHitIndices, OwnedHits &hits)
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
std::vector< l1t::Jet >::iterator end_
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
bool operator!=(const const_iterator &other) const
BaseTrackerRecHit const & TkHitRef
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 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_
std::vector< const DetLayer * > layerDets_
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.