CMS 3D CMS Logo

PHGCSimAccumulator.h
Go to the documentation of this file.
1 #ifndef DataFormats_HGCDigi_PHGCSimAccumulator_h
2 #define DataFormats_HGCDigi_PHGCSimAccumulator_h
3 
5 #include <iostream>
6 #include <vector>
7 
9 public:
10  class DetIdSize {
11  public:
12  DetIdSize() {}
13  DetIdSize(unsigned int detId) : detId_(detId) {}
14  void increaseSize() { ++size_; }
15  unsigned int detId() const { return detId_; }
16  unsigned int size() const { return size_; }
17 
18  private:
19  unsigned int detId_ = 0;
20  unsigned char size_ = 0;
21  };
22 
24  public:
25  constexpr static unsigned energyOffset = 15;
26  constexpr static unsigned energyMask = 0x1;
27  constexpr static unsigned sampleOffset = 11;
28  constexpr static unsigned sampleMask = 0xf;
29  constexpr static unsigned dataOffset = 0;
30  constexpr static unsigned dataMask = 0x7ff;
31 
33  SimHitCollection(unsigned int nhits) : nhits_(nhits) {}
34  SimHitCollection(const unsigned short si,
35  const std::vector<unsigned short>& accCharge,
36  const std::vector<unsigned short>& time)
37  : nhits_(accCharge.size()) {
38  chargeArray_.reserve(nhits_);
39  timeArray_.reserve(nhits_);
40  for (size_t i = 0; i < nhits_; ++i) {
41  unsigned short ei = 0;
42  unsigned short d = accCharge[i];
43  unsigned short data = ((ei << energyOffset) | (si << sampleOffset) | d);
44  chargeArray_.emplace_back(data);
45  }
46  for (size_t i = 0; i < nhits_; ++i) {
47  unsigned short ei = 1;
48  unsigned short d = time[i];
49  unsigned short data = ((ei << energyOffset) | (si << sampleOffset) | d);
50  timeArray_.emplace_back(data);
51  }
52  }
53  SimHitCollection(const SimHitCollection& simhitcollection) = default;
54  unsigned int nhits() const { return nhits_; }
55  unsigned int sampleIndex() const { return (chargeArray_[0] >> sampleOffset) & sampleMask; }
56  const std::vector<unsigned short>& chargeArray() const { return chargeArray_; }
57  const std::vector<unsigned short>& timeArray() const { return timeArray_; }
58 
59  private:
60  unsigned int nhits_;
61  std::vector<unsigned short> chargeArray_;
62  std::vector<unsigned short> timeArray_;
63  };
64 
65  PHGCSimAccumulator() = default;
66  ~PHGCSimAccumulator() = default;
67 
68  void reserve(size_t size) {
69  detIdSize_.reserve(size);
70  simhitCollection_.reserve(size);
71  }
72  void shrink_to_fit() {
73  detIdSize_.shrink_to_fit();
74  simhitCollection_.shrink_to_fit();
75  }
76 
77  void emplace_back(unsigned int detId,
78  unsigned short sampleIndex,
79  const std::vector<unsigned short>& accCharge,
80  const std::vector<unsigned short>& timing) {
81  if (detIdSize_.empty() || detIdSize_.back().detId() != detId) {
82  detIdSize_.emplace_back(detId);
83  }
84  simhitCollection_.emplace_back(sampleIndex, accCharge, timing);
85  detIdSize_.back().increaseSize();
86  }
87 
88  class TmpElem {
89  public:
90  TmpElem(const unsigned int detId, const SimHitCollection& simhitCollection)
91  : detId_(detId), simhitcollection_(simhitCollection) {}
92 
93  unsigned int detId() const { return detId_; }
94  unsigned short sampleIndex() const { return simhitcollection_.sampleIndex(); }
95  unsigned int nhits() const { return simhitcollection_.nhits(); }
96  const std::vector<unsigned short> chargeArray() const { return simhitcollection_.chargeArray(); }
97  const std::vector<unsigned short> timeArray() const { return simhitcollection_.timeArray(); }
98 
99  private:
100  unsigned int detId_;
102  };
103 
105  public:
106  // begin
108  : ncc_(ncc), iDet_(0), iData_(0), endData_(ncc->detIdSize_.empty() ? 0 : ncc->detIdSize_.front().size()) {}
109  // end
110  const_iterator(const PHGCSimAccumulator* ncc, unsigned int detSize, unsigned int dataSize)
111  : ncc_(ncc), iDet_(detSize), iData_(dataSize), endData_(0) {}
112 
113  bool operator==(const const_iterator& other) const { return iDet_ == other.iDet_ && iData_ == other.iData_; }
114  bool operator!=(const const_iterator& other) const { return !operator==(other); }
116  ++iData_;
117  if (iData_ == endData_) {
118  ++iDet_;
119  endData_ += (iDet_ == ncc_->detIdSize_.size()) ? 0 : ncc_->detIdSize_[iDet_].size();
120  }
121  return *this;
122  }
124  auto tmp = *this;
125  ++(*this);
126  return tmp;
127  }
128 
130 
131  private:
133  unsigned int iDet_;
134  unsigned int iData_;
135  unsigned int endData_;
136  };
137 
138  TmpElem back() const { return TmpElem(detIdSize_.back().detId(), simhitCollection_.back()); }
139 
140  const_iterator cbegin() const { return const_iterator(this); }
141  const_iterator begin() const { return cbegin(); }
142  const_iterator cend() const { return const_iterator(this, detIdSize_.size(), simhitCollection_.size()); }
143  const_iterator end() const { return cend(); }
144 
145 private:
146  std::vector<DetIdSize> detIdSize_;
147  std::vector<SimHitCollection> simhitCollection_;
148 };
149 
150 #endif
PHGCSimAccumulator::SimHitCollection::chargeArray_
std::vector< unsigned short > chargeArray_
Definition: PHGCSimAccumulator.h:61
PHGCSimAccumulator
Definition: PHGCSimAccumulator.h:8
PHGCSimAccumulator::DetIdSize::DetIdSize
DetIdSize()
Definition: PHGCSimAccumulator.h:12
mps_fire.i
i
Definition: mps_fire.py:428
PHGCSimAccumulator::SimHitCollection::SimHitCollection
SimHitCollection(unsigned int nhits)
Definition: PHGCSimAccumulator.h:33
PHGCSimAccumulator::TmpElem
Definition: PHGCSimAccumulator.h:88
PHGCSimAccumulator::SimHitCollection::SimHitCollection
SimHitCollection()
Definition: PHGCSimAccumulator.h:32
PHGCSimAccumulator::shrink_to_fit
void shrink_to_fit()
Definition: PHGCSimAccumulator.h:72
PHGCSimAccumulator::DetIdSize::size_
unsigned char size_
Definition: PHGCSimAccumulator.h:20
PHGCSimAccumulator::TmpElem::timeArray
const std::vector< unsigned short > timeArray() const
Definition: PHGCSimAccumulator.h:97
PHGCSimAccumulator::SimHitCollection::timeArray_
std::vector< unsigned short > timeArray_
Definition: PHGCSimAccumulator.h:62
PHGCSimAccumulator::SimHitCollection::sampleOffset
constexpr static unsigned sampleOffset
Definition: PHGCSimAccumulator.h:27
PHGCSimAccumulator::SimHitCollection::dataMask
constexpr static unsigned dataMask
Definition: PHGCSimAccumulator.h:30
protons_cff.time
time
Definition: protons_cff.py:39
PHGCSimAccumulator::SimHitCollection::energyOffset
constexpr static unsigned energyOffset
Definition: PHGCSimAccumulator.h:25
PHGCSimAccumulator::SimHitCollection::energyMask
constexpr static unsigned energyMask
Definition: PHGCSimAccumulator.h:26
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
PHGCSimAccumulator::SimHitCollection::sampleMask
constexpr static unsigned sampleMask
Definition: PHGCSimAccumulator.h:28
PHGCSimAccumulator::detIdSize_
std::vector< DetIdSize > detIdSize_
Definition: PHGCSimAccumulator.h:146
PHGCSimAccumulator::SimHitCollection
Definition: PHGCSimAccumulator.h:23
PHGCSimAccumulator::TmpElem::nhits
unsigned int nhits() const
Definition: PHGCSimAccumulator.h:95
PHGCSimAccumulator::TmpElem::chargeArray
const std::vector< unsigned short > chargeArray() const
Definition: PHGCSimAccumulator.h:96
PHGCSimAccumulator::TmpElem::simhitcollection_
SimHitCollection simhitcollection_
Definition: PHGCSimAccumulator.h:101
PHGCSimAccumulator::reserve
void reserve(size_t size)
Definition: PHGCSimAccumulator.h:68
PHGCSimAccumulator::TmpElem::TmpElem
TmpElem(const unsigned int detId, const SimHitCollection &simhitCollection)
Definition: PHGCSimAccumulator.h:90
trackingPlots.other
other
Definition: trackingPlots.py:1460
PHGCSimAccumulator::SimHitCollection::timeArray
const std::vector< unsigned short > & timeArray() const
Definition: PHGCSimAccumulator.h:57
PHGCSimAccumulator::const_iterator::const_iterator
const_iterator(const PHGCSimAccumulator *ncc, unsigned int detSize, unsigned int dataSize)
Definition: PHGCSimAccumulator.h:110
PHGCSimAccumulator::TmpElem::detId_
unsigned int detId_
Definition: PHGCSimAccumulator.h:100
PHGCSimAccumulator::back
TmpElem back() const
Definition: PHGCSimAccumulator.h:138
PHGCSimAccumulator::begin
const_iterator begin() const
Definition: PHGCSimAccumulator.h:141
PHGCSimAccumulator::const_iterator
Definition: PHGCSimAccumulator.h:104
PHGCSimAccumulator::DetIdSize::DetIdSize
DetIdSize(unsigned int detId)
Definition: PHGCSimAccumulator.h:13
PHGCSimAccumulator::cbegin
const_iterator cbegin() const
Definition: PHGCSimAccumulator.h:140
PHGCSimAccumulator::SimHitCollection::nhits
unsigned int nhits() const
Definition: PHGCSimAccumulator.h:54
PHGCSimAccumulator::simhitCollection_
std::vector< SimHitCollection > simhitCollection_
Definition: PHGCSimAccumulator.h:147
PHGCSimAccumulator::const_iterator::operator!=
bool operator!=(const const_iterator &other) const
Definition: PHGCSimAccumulator.h:114
PHGCSimAccumulator::const_iterator::operator==
bool operator==(const const_iterator &other) const
Definition: PHGCSimAccumulator.h:113
PHGCSimAccumulator::SimHitCollection::nhits_
unsigned int nhits_
Definition: PHGCSimAccumulator.h:60
PHGCSimAccumulator::const_iterator::ncc_
const PHGCSimAccumulator * ncc_
Definition: PHGCSimAccumulator.h:132
PHGCSimAccumulator::DetIdSize::size
unsigned int size() const
Definition: PHGCSimAccumulator.h:16
PHGCSimAccumulator::const_iterator::operator++
const_iterator & operator++()
Definition: PHGCSimAccumulator.h:115
PHGCSimAccumulator::const_iterator::iData_
unsigned int iData_
Definition: PHGCSimAccumulator.h:134
PHGCSimAccumulator::TmpElem::sampleIndex
unsigned short sampleIndex() const
Definition: PHGCSimAccumulator.h:94
PHGCSimAccumulator::const_iterator::operator*
TmpElem operator*()
Definition: PHGCSimAccumulator.h:129
PHGCSimAccumulator::const_iterator::endData_
unsigned int endData_
Definition: PHGCSimAccumulator.h:135
PHGCSimAccumulator::cend
const_iterator cend() const
Definition: PHGCSimAccumulator.h:142
PHGCSimAccumulator::emplace_back
void emplace_back(unsigned int detId, unsigned short sampleIndex, const std::vector< unsigned short > &accCharge, const std::vector< unsigned short > &timing)
Definition: PHGCSimAccumulator.h:77
ecalMatacq_cfi.timing
timing
Definition: ecalMatacq_cfi.py:26
DetId.h
PHGCSimAccumulator::end
const_iterator end() const
Definition: PHGCSimAccumulator.h:143
PHGCSimAccumulator::SimHitCollection::chargeArray
const std::vector< unsigned short > & chargeArray() const
Definition: PHGCSimAccumulator.h:56
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
PHGCSimAccumulator::const_iterator::operator++
const_iterator operator++(int)
Definition: PHGCSimAccumulator.h:123
PHGCSimAccumulator::SimHitCollection::sampleIndex
unsigned int sampleIndex() const
Definition: PHGCSimAccumulator.h:55
PHGCSimAccumulator::const_iterator::iDet_
unsigned int iDet_
Definition: PHGCSimAccumulator.h:133
PHGCSimAccumulator::DetIdSize::detId_
unsigned int detId_
Definition: PHGCSimAccumulator.h:19
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ztail.d
d
Definition: ztail.py:151
PHGCSimAccumulator::~PHGCSimAccumulator
~PHGCSimAccumulator()=default
PHGCSimAccumulator::PHGCSimAccumulator
PHGCSimAccumulator()=default
PHGCSimAccumulator::TmpElem::detId
unsigned int detId() const
Definition: PHGCSimAccumulator.h:93
PHGCSimAccumulator::DetIdSize
Definition: PHGCSimAccumulator.h:10
PHGCSimAccumulator::SimHitCollection::SimHitCollection
SimHitCollection(const unsigned short si, const std::vector< unsigned short > &accCharge, const std::vector< unsigned short > &time)
Definition: PHGCSimAccumulator.h:34
PHGCSimAccumulator::SimHitCollection::dataOffset
constexpr static unsigned dataOffset
Definition: PHGCSimAccumulator.h:29
PHGCSimAccumulator::DetIdSize::increaseSize
void increaseSize()
Definition: PHGCSimAccumulator.h:14
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
PHGCSimAccumulator::DetIdSize::detId
unsigned int detId() const
Definition: PHGCSimAccumulator.h:15
PHGCSimAccumulator::const_iterator::const_iterator
const_iterator(const PHGCSimAccumulator *ncc)
Definition: PHGCSimAccumulator.h:107