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
10namespace recon {
11
25template <class HitType>
27 public:
31 WorkingCluster() = default;
32
38 WorkingCluster(const HitType* hit) {
39 if (hit) {
40 add(hit);
41 }
42 }
43
49 WorkingCluster(const HitType& hit) { add(hit); }
50
54 ~WorkingCluster() = default;
55
63 void add(const HitType* hit) {
64 if (!hit) return;
65
66 double hit_e = hit->getEnergy();
67 double hit_x = hit->getXPos();
68 double hit_y = hit->getYPos();
69 double hit_z = hit->getZPos();
70 double hit_t = hit->getTime();
71
72 double new_e = hit_e + centroid_e_;
73 if (new_e > 0) {
74 centroid_x_ = (centroid_x_ * centroid_e_ + hit_e * hit_x) / new_e;
75 centroid_y_ = (centroid_y_ * centroid_e_ + hit_e * hit_y) / new_e;
76 centroid_z_ = (centroid_z_ * centroid_e_ + hit_e * hit_z) / new_e;
77 }
78 centroid_e_ = new_e;
79
80 // Track the latest time
81 if (hit_t > time_) {
82 time_ = hit_t;
83 }
84
85 hits_.push_back(hit);
86 }
87
93 void add(const HitType& hit) { add(&hit); }
94
106 void add(const HitType* hit, double x, double y, double z) {
107 if (!hit) return;
108
109 double hit_e = hit->getEnergy();
110 double hit_t = hit->getTime();
111
112 double new_e = hit_e + centroid_e_;
113 if (new_e > 0) {
114 centroid_x_ = (centroid_x_ * centroid_e_ + hit_e * x) / new_e;
115 centroid_y_ = (centroid_y_ * centroid_e_ + hit_e * y) / new_e;
116 centroid_z_ = (centroid_z_ * centroid_e_ + hit_e * z) / new_e;
117 }
118 centroid_e_ = new_e;
119
120 if (hit_t > time_) {
121 time_ = hit_t;
122 }
123
124 hits_.push_back(hit);
125 }
126
132 void add(const WorkingCluster<HitType>& other) {
133 double new_e = other.centroid_e_ + centroid_e_;
134 if (new_e > 0) {
136 (centroid_x_ * centroid_e_ + other.centroid_x_ * other.centroid_e_) /
137 new_e;
139 (centroid_y_ * centroid_e_ + other.centroid_y_ * other.centroid_e_) /
140 new_e;
142 (centroid_z_ * centroid_e_ + other.centroid_z_ * other.centroid_e_) /
143 new_e;
144 }
145 centroid_e_ = new_e;
146
147 if (other.time_ > time_) {
148 time_ = other.time_;
149 }
150
151 for (const auto* hit : other.hits_) {
152 hits_.push_back(hit);
153 }
154 }
155
159 double centroidX() const { return centroid_x_; }
160
164 double centroidY() const { return centroid_y_; }
165
169 double centroidZ() const { return centroid_z_; }
170
174 double energy() const { return centroid_e_; }
175
179 double time() const { return time_; }
180
184 const std::vector<const HitType*>& hits() const { return hits_; }
185
189 bool empty() const { return hits_.empty(); }
190
194 void clear() {
195 hits_.clear();
196 centroid_x_ = 0;
197 centroid_y_ = 0;
198 centroid_z_ = 0;
199 centroid_e_ = 0;
200 time_ = 0;
201 }
202
206 void setCentroid(double x, double y, double z, double e) {
207 centroid_x_ = x;
208 centroid_y_ = y;
209 centroid_z_ = z;
210 centroid_e_ = e;
211 }
212
216 void setTime(double t) { time_ = t; }
217
221 int layer() const { return layer_; }
222
226 void setLayer(int layer) { layer_ = layer; }
227
228 private:
230 std::vector<const HitType*> hits_;
231
233 double centroid_x_{0};
234
236 double centroid_y_{0};
237
239 double centroid_z_{0};
240
242 double centroid_e_{0};
243
245 double time_{0};
246
248 int layer_{-1};
249};
250
251} // namespace recon
252
253#endif // RECON_WORKINGCLUSTER_H_
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.