CMS 3D CMS Logo

MtdSimCluster.h
Go to the documentation of this file.
1 // Author: Aurora Perego, Fabio Cossutti - aurora.perego@cern.ch, fabio.cossutti@ts.infn.it
2 // Date: 05/2023
3 
4 #ifndef SimDataFormats_CaloAnalysis_MtdSimCluster_h
5 #define SimDataFormats_CaloAnalysis_MtdSimCluster_h
6 
10 #include <vector>
11 
12 class MtdSimCluster : public SimCluster {
13  friend std::ostream &operator<<(std::ostream &s, MtdSimCluster const &tp);
14 
15 public:
16  MtdSimCluster();
17  MtdSimCluster(const SimTrack &simtrk);
18  MtdSimCluster(EncodedEventId eventID, uint32_t particleID); // for PU
19 
20  // destructor
22 
24  void addHitTime(float time) {
25  times_.emplace_back(time);
26  ++nsimhits_;
27  }
28 
31  mtdHits_.emplace_back(hit);
32  fractions_.emplace_back(fraction);
33  }
34 
36  void addHitPosition(LocalPoint pos) { positions_.emplace_back(pos); }
37 
39  std::vector<std::pair<uint64_t, float>> hits_and_fractions() const {
40  assert(mtdHits_.size() == fractions_.size());
41  std::vector<std::pair<uint64_t, float>> result;
42  result.reserve(mtdHits_.size());
43  for (size_t i = 0; i < mtdHits_.size(); ++i) {
44  result.emplace_back(mtdHits_[i], fractions_[i]);
45  }
46  return result;
47  }
48 
50  std::vector<std::pair<uint64_t, float>> hits_and_energies() const {
51  assert(mtdHits_.size() == energies_.size());
52  std::vector<std::pair<uint64_t, float>> result;
53  result.reserve(mtdHits_.size());
54  for (size_t i = 0; i < mtdHits_.size(); ++i) {
55  result.emplace_back(mtdHits_[i], energies_[i]);
56  }
57  return result;
58  }
59 
62  std::vector<uint64_t>().swap(mtdHits_);
63  std::vector<float>().swap(fractions_);
64  }
65 
67  std::vector<std::pair<uint64_t, float>> hits_and_times() const {
68  assert(mtdHits_.size() == times_.size());
69  std::vector<std::pair<uint64_t, float>> result;
70  result.reserve(mtdHits_.size());
71  for (size_t i = 0; i < mtdHits_.size(); ++i) {
72  result.emplace_back(mtdHits_[i], times_[i]);
73  }
74  return result;
75  }
76 
78  std::vector<std::pair<uint64_t, LocalPoint>> hits_and_positions() const {
79  assert(mtdHits_.size() == times_.size());
80  std::vector<std::pair<uint64_t, LocalPoint>> result;
81  result.reserve(mtdHits_.size());
82  for (size_t i = 0; i < mtdHits_.size(); ++i) {
83  result.emplace_back(mtdHits_[i], positions_[i]);
84  }
85  return result;
86  }
87 
89  std::vector<std::pair<uint32_t, std::pair<uint8_t, uint8_t>>> detIds_and_rows() const {
90  std::vector<std::pair<uint32_t, std::pair<uint8_t, uint8_t>>> result;
91  result.reserve(mtdHits_.size());
92  for (size_t i = 0; i < mtdHits_.size(); ++i) {
93  result.emplace_back(
94  mtdHits_[i] >> 32,
95  std::pair<uint8_t, uint8_t>(static_cast<uint8_t>(mtdHits_[i] >> 16), static_cast<uint8_t>(mtdHits_[i])));
96  }
97  return result;
98  }
99 
101  void clearHitsTime() { std::vector<float>().swap(times_); }
102 
104  void clearHitsPosition() { std::vector<LocalPoint>().swap(positions_); }
105 
106  void clear() {
108  clearHitsEnergy();
109  clearHitsTime();
111  }
112 
114  void addSimHit(const PSimHit &hit) {
115  simhit_energy_ += hit.energyLoss();
116  ++nsimhits_;
117  }
118 
119  void setTrackIdOffset(unsigned int offset) { idOffset_ = offset; }
120 
121  unsigned int trackIdOffset() const { return idOffset_; }
122 
123 protected:
124  std::vector<uint64_t> mtdHits_;
125  std::vector<float> times_;
126  std::vector<LocalPoint> positions_;
127  unsigned int idOffset_{0};
128 };
129 
130 #endif
float simhit_energy_
Definition: SimCluster.h:254
std::vector< LocalPoint > positions_
assert(be >=bs)
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
uint64_t nsimhits_
Definition: SimCluster.h:250
void clearHitsEnergy()
clear the energies list
Definition: SimCluster.h:238
void clearHitsAndFractions()
clear the hits and fractions list
Definition: MtdSimCluster.h:61
void addHitPosition(LocalPoint pos)
add hit position
Definition: MtdSimCluster.h:36
std::vector< std::pair< uint64_t, LocalPoint > > hits_and_positions() const
Returns list of hit IDs and times for this SimCluster.
Definition: MtdSimCluster.h:78
Monte Carlo truth information used for tracking validation.
Definition: SimCluster.h:33
void addSimHit(const PSimHit &hit)
add simhit&#39;s energy to cluster
void setTrackIdOffset(unsigned int offset)
std::vector< float > times_
std::vector< float > fractions_
Definition: SimCluster.h:256
std::vector< std::pair< uint64_t, float > > hits_and_energies() const
Returns list of hit IDs and energies for this SimCluster.
Definition: MtdSimCluster.h:50
std::vector< std::pair< uint64_t, float > > hits_and_times() const
Returns list of hit IDs and times for this SimCluster.
Definition: MtdSimCluster.h:67
unsigned long long uint64_t
Definition: Time.h:13
std::vector< std::pair< uint64_t, float > > hits_and_fractions() const
Returns list of hit IDs and fractions for this SimCluster.
Definition: MtdSimCluster.h:39
std::vector< uint64_t > mtdHits_
void clearHitsPosition()
clear the positions list
void addHitAndFraction(uint64_t hit, float fraction)
add hit with fraction
Definition: MtdSimCluster.h:30
friend std::ostream & operator<<(std::ostream &s, MtdSimCluster const &tp)
void addHitTime(float time)
add hit time
Definition: MtdSimCluster.h:24
unsigned int trackIdOffset() const
void clearHitsTime()
clear the times list
unsigned int idOffset_
std::vector< float > energies_
Definition: SimCluster.h:257
std::vector< std::pair< uint32_t, std::pair< uint8_t, uint8_t > > > detIds_and_rows() const
Returns list of detIds, rows and columns for this SimCluster.
Definition: MtdSimCluster.h:89