File indexing completed on 2024-04-06 12:31:42
0001 #ifndef TrackingTools_TransientTrackingRecHit_SeedingLayerSetsHits
0002 #define TrackingTools_TransientTrackingRecHit_SeedingLayerSetsHits
0003
0004 #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h"
0005 #include "DataFormats/TrackingRecHit/interface/mayown_ptr.h"
0006
0007 #include <vector>
0008 #include <string>
0009 #include <utility>
0010
0011 class DetLayer;
0012
0013
0014
0015
0016
0017
0018 class SeedingLayerSetsHits {
0019 public:
0020 using TkHit = BaseTrackerRecHit;
0021 using TkHitRef = BaseTrackerRecHit const &;
0022 using HitPointer = mayown_ptr<BaseTrackerRecHit>;
0023 using OwnedHits = std::vector<HitPointer>;
0024
0025 using ConstRecHitPointer = BaseTrackerRecHit const *;
0026 using Hits = std::vector<ConstRecHitPointer>;
0027
0028 typedef unsigned short LayerSetIndex;
0029 typedef unsigned short LayerIndex;
0030 typedef unsigned int HitIndex;
0031
0032
0033
0034
0035
0036
0037 class SeedingLayer {
0038 public:
0039 SeedingLayer() : seedingLayerSets_(nullptr), index_(0) {}
0040 SeedingLayer(const SeedingLayerSetsHits *sls, LayerIndex index) : seedingLayerSets_(sls), index_(index) {}
0041
0042
0043
0044
0045
0046
0047
0048 LayerIndex index() const { return index_; }
0049 const std::string &name() const { return (*seedingLayerSets_->layerNames_)[index_]; }
0050 const DetLayer *detLayer() const { return (*seedingLayerSets_->layerDets_)[index_]; }
0051 Hits hits() const { return seedingLayerSets_->hits(index_); }
0052
0053 private:
0054 const SeedingLayerSetsHits *seedingLayerSets_;
0055 LayerIndex index_;
0056 };
0057
0058
0059
0060
0061
0062
0063
0064
0065 class SeedingLayerSet {
0066 public:
0067 class const_iterator {
0068 public:
0069 typedef std::vector<LayerSetIndex>::const_iterator internal_iterator_type;
0070 typedef SeedingLayer value_type;
0071 typedef internal_iterator_type::difference_type difference_type;
0072
0073 const_iterator() : seedingLayerSets_(nullptr) {}
0074 const_iterator(const SeedingLayerSetsHits *sls, internal_iterator_type iter)
0075 : seedingLayerSets_(sls), iter_(iter) {}
0076
0077 value_type operator*() const { return SeedingLayer(seedingLayerSets_, *iter_); }
0078
0079 const_iterator &operator++() {
0080 ++iter_;
0081 return *this;
0082 }
0083 const_iterator operator++(int) {
0084 const_iterator clone(*this);
0085 ++clone;
0086 return clone;
0087 }
0088
0089 bool operator==(const const_iterator &other) const { return iter_ == other.iter_; }
0090 bool operator!=(const const_iterator &other) const { return !operator==(other); }
0091
0092 private:
0093 const SeedingLayerSetsHits *seedingLayerSets_;
0094 internal_iterator_type iter_;
0095 };
0096
0097 SeedingLayerSet() : seedingLayerSets_(nullptr) {}
0098 SeedingLayerSet(const SeedingLayerSetsHits *sls,
0099 std::vector<LayerSetIndex>::const_iterator begin,
0100 std::vector<LayerSetIndex>::const_iterator end)
0101 : seedingLayerSets_(sls), begin_(begin), end_(end) {}
0102
0103
0104 LayerSetIndex size() const { return end_ - begin_; }
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 SeedingLayerSet slice(size_t begin, size_t end) const {
0119 assert(begin < size());
0120 assert(0 < end && end <= size());
0121 assert(begin < end);
0122 return SeedingLayerSet(seedingLayerSets_, begin_ + begin, begin_ + end);
0123 }
0124
0125
0126 SeedingLayer operator[](LayerSetIndex index) const { return SeedingLayer(seedingLayerSets_, *(begin_ + index)); }
0127
0128
0129 const_iterator begin() const { return const_iterator(seedingLayerSets_, begin_); }
0130 const_iterator cbegin() const { return begin(); }
0131 const_iterator end() const { return const_iterator(seedingLayerSets_, end_); }
0132 const_iterator cend() const { return end(); }
0133
0134 private:
0135 const SeedingLayerSetsHits *seedingLayerSets_;
0136 std::vector<LayerSetIndex>::const_iterator begin_;
0137 std::vector<LayerSetIndex>::const_iterator end_;
0138 };
0139
0140 class const_iterator {
0141 public:
0142 typedef std::vector<LayerSetIndex>::const_iterator internal_iterator_type;
0143 typedef SeedingLayerSet value_type;
0144 typedef internal_iterator_type::difference_type difference_type;
0145
0146 const_iterator() : seedingLayerSets_(nullptr) {}
0147 const_iterator(const SeedingLayerSetsHits *sls, internal_iterator_type iter)
0148 : seedingLayerSets_(sls), iter_(iter) {}
0149
0150 value_type operator*() const {
0151 return SeedingLayerSet(seedingLayerSets_, iter_, iter_ + seedingLayerSets_->nlayers_);
0152 }
0153
0154 const_iterator &operator++() {
0155 std::advance(iter_, seedingLayerSets_->nlayers_);
0156 return *this;
0157 }
0158 const_iterator operator++(int) {
0159 const_iterator clone(*this);
0160 ++(*this);
0161 return clone;
0162 }
0163
0164 bool operator==(const const_iterator &other) const { return iter_ == other.iter_; }
0165 bool operator!=(const const_iterator &other) const { return !operator==(other); }
0166
0167 private:
0168 const SeedingLayerSetsHits *seedingLayerSets_;
0169 internal_iterator_type iter_;
0170 };
0171
0172 SeedingLayerSetsHits() = default;
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182 SeedingLayerSetsHits(unsigned short nlayers,
0183 const std::vector<LayerSetIndex> *layerSetIndices,
0184 const std::vector<std::string> *layerNames,
0185 const std::vector<const DetLayer *> *layerDets);
0186
0187 ~SeedingLayerSetsHits() = default;
0188 SeedingLayerSetsHits(SeedingLayerSetsHits const &) = delete;
0189 SeedingLayerSetsHits &operator=(SeedingLayerSetsHits const &) = delete;
0190 SeedingLayerSetsHits(SeedingLayerSetsHits &&) = default;
0191 SeedingLayerSetsHits &operator=(SeedingLayerSetsHits &&) = default;
0192
0193 void shrink_to_fit();
0194 void addHits(LayerIndex layerIndex, OwnedHits &&hits);
0195
0196
0197 unsigned short numberOfLayersInSet() const { return nlayers_; }
0198
0199 unsigned short size() const { return nlayers_ > 0 ? layerSetIndices_->size() / nlayers_ : 0; }
0200
0201
0202 SeedingLayerSet operator[](LayerSetIndex index) const {
0203 std::vector<LayerSetIndex>::const_iterator begin = layerSetIndices_->begin() + nlayers_ * index;
0204 std::vector<LayerSetIndex>::const_iterator end = begin + nlayers_;
0205 return SeedingLayerSet(this, begin, end);
0206 }
0207
0208
0209 const_iterator begin() const { return const_iterator(this, layerSetIndices_->begin()); }
0210 const_iterator cbegin() const { return begin(); }
0211 const_iterator end() const { return const_iterator(this, layerSetIndices_->end()); }
0212 const_iterator cend() const { return end(); }
0213
0214
0215 void swap(SeedingLayerSetsHits &other) {
0216 std::swap(nlayers_, other.nlayers_);
0217 std::swap(layerSetIndices_, other.layerSetIndices_);
0218 layerHitIndices_.swap(other.layerHitIndices_);
0219 std::swap(layerNames_, other.layerNames_);
0220 std::swap(layerDets_, other.layerDets_);
0221 rechits_.swap(other.rechits_);
0222 }
0223
0224 void print() const;
0225
0226 private:
0227 Hits hits(LayerIndex layerIndex) const;
0228
0229
0230 unsigned short nlayers_ = 0;
0231
0232
0233
0234
0235
0236
0237 const std::vector<LayerSetIndex> *layerSetIndices_ = nullptr;
0238
0239
0240 std::vector<HitIndex> layerHitIndices_;
0241 const std::vector<std::string> *layerNames_ = nullptr;
0242 const std::vector<const DetLayer *> *layerDets_ = nullptr;
0243
0244
0245
0246
0247
0248 OwnedHits rechits_;
0249 };
0250
0251 #endif