LDMX Software
WorkingCluster.h
Go to the documentation of this file.
1
5#ifndef RECON_WORKINGCLUSTER_H_
6#define RECON_WORKINGCLUSTER_H_
7
8#include <vector>
9
11
12namespace recon {
13
27template <class HitType>
29 public:
33 WorkingCluster() = default;
34
40 WorkingCluster(const HitType* hit) {
41 if (hit) {
42 add(hit);
43 }
44 }
45
51 WorkingCluster(const HitType& hit) { add(hit); }
52
56 ~WorkingCluster() = default;
57
65 void add(const HitType* hit) {
66 if (!hit) return;
67
68 double hit_e = hit->getEnergy();
69 double hit_x = hit->getXPos();
70 double hit_y = hit->getYPos();
71 double hit_z = hit->getZPos();
72 double hit_t = hit->getTime();
73
74 double new_e = hit_e + centroid_e_;
75 if (new_e > 0) {
76 centroid_x_ = (centroid_x_ * centroid_e_ + hit_e * hit_x) / new_e;
77 centroid_y_ = (centroid_y_ * centroid_e_ + hit_e * hit_y) / new_e;
78 centroid_z_ = (centroid_z_ * centroid_e_ + hit_e * hit_z) / new_e;
79 }
80 centroid_e_ = new_e;
81
82 // Track the latest time
83 if (hit_t > time_) {
84 time_ = hit_t;
85 }
86
87 hits_.push_back(hit);
88 }
89
95 void add(const HitType& hit) { add(&hit); }
96
108 void add(const HitType* hit, double x, double y, double z) {
109 if (!hit) return;
110
111 double hit_e = hit->getEnergy();
112 double hit_t = hit->getTime();
113
114 double new_e = hit_e + centroid_e_;
115 if (new_e > 0) {
116 centroid_x_ = (centroid_x_ * centroid_e_ + hit_e * x) / new_e;
117 centroid_y_ = (centroid_y_ * centroid_e_ + hit_e * y) / new_e;
118 centroid_z_ = (centroid_z_ * centroid_e_ + hit_e * z) / new_e;
119 }
120 centroid_e_ = new_e;
121
122 if (hit_t > time_) {
123 time_ = hit_t;
124 }
125
126 hits_.push_back(hit);
127 }
128
134 void add(const WorkingCluster<HitType>& other) {
135 double new_e = other.centroid_e_ + centroid_e_;
136 if (new_e > 0) {
138 (centroid_x_ * centroid_e_ + other.centroid_x_ * other.centroid_e_) /
139 new_e;
141 (centroid_y_ * centroid_e_ + other.centroid_y_ * other.centroid_e_) /
142 new_e;
144 (centroid_z_ * centroid_e_ + other.centroid_z_ * other.centroid_e_) /
145 new_e;
146 }
147 centroid_e_ = new_e;
148
149 if (other.time_ > time_) {
150 time_ = other.time_;
151 }
152
153 for (const auto* hit : other.hits_) {
154 hits_.push_back(hit);
155 }
156 }
157
161 double centroidX() const { return centroid_x_; }
162
166 double centroidY() const { return centroid_y_; }
167
171 double centroidZ() const { return centroid_z_; }
172
176 double energy() const { return centroid_e_; }
177
181 double time() const { return time_; }
182
186 const std::vector<const HitType*>& hits() const { return hits_; }
187
191 bool empty() const { return hits_.empty(); }
192
196 void clear() {
197 hits_.clear();
198 centroid_x_ = 0;
199 centroid_y_ = 0;
200 centroid_z_ = 0;
201 centroid_e_ = 0;
202 time_ = 0;
203 }
204
208 void setCentroid(double x, double y, double z, double e) {
209 centroid_x_ = x;
210 centroid_y_ = y;
211 centroid_z_ = z;
212 centroid_e_ = e;
213 }
214
218 void setTime(double t) { time_ = t; }
219
223 int layer() const { return layer_; }
224
228 void setLayer(int layer) { layer_ = layer; }
229
230 private:
232 std::vector<const HitType*> hits_;
233
235 double centroid_x_{0};
236
238 double centroid_y_{0};
239
241 double centroid_z_{0};
242
244 double centroid_e_{0};
245
247 double time_{0};
248
250 int layer_{-1};
251};
252
253} // namespace recon
254
255#endif // RECON_WORKINGCLUSTER_H_
Class that represents a reconstructed hit in a calorimeter cell within the detector.
An in-memory representation of a cluster being built during reconstruction.
double centroid_e_
Total energy.
double time() const
Get the time of the cluster (latest hit time).
double centroid_x_
Centroid X position (energy-weighted)
const std::vector< const HitType * > & hits() const
Get the list of hits in this cluster.
bool empty() const
Check if the cluster is empty.
double centroidY() const
Get the centroid Y position (energy-weighted).
double centroidX() const
Get the centroid X position (energy-weighted).
void setLayer(int layer)
Set the layer of the cluster.
double time_
Time (latest hit time)
double centroid_y_
Centroid Y position (energy-weighted)
void add(const HitType *hit, double x, double y, double z)
Add a hit to the cluster with explicit position.
std::vector< const HitType * > hits_
The hits in this cluster.
~WorkingCluster()=default
Default destructor.
int layer_
Layer number.
double centroidZ() const
Get the centroid Z position (energy-weighted).
void clear()
Clear all hits from the cluster.
WorkingCluster(const HitType &hit)
Construct a cluster from a single hit (reference version).
void setCentroid(double x, double y, double z, double e)
Set the centroid position and energy explicitly.
void add(const WorkingCluster< HitType > &other)
Merge another cluster into this one.
void setTime(double t)
Set the time explicitly.
double energy() const
Get the total energy of the cluster.
double centroid_z_
Centroid Z position (energy-weighted)
int layer() const
Get the layer of the cluster.
WorkingCluster(const HitType *hit)
Construct a cluster from a single hit.
void add(const HitType &hit)
Add a hit to the cluster using its stored position (reference version).
WorkingCluster()=default
Default constructor.
void add(const HitType *hit)
Add a hit to the cluster using its stored position.