LDMX Software
recon::WorkingCluster< HitType > Class Template Reference

An in-memory representation of a cluster being built during reconstruction. More...

#include <WorkingCluster.h>

Public Member Functions

 WorkingCluster ()=default
 Default constructor.
 
 WorkingCluster (const HitType *hit)
 Construct a cluster from a single hit.
 
 WorkingCluster (const HitType &hit)
 Construct a cluster from a single hit (reference version).
 
 ~WorkingCluster ()=default
 Default destructor.
 
void add (const HitType *hit)
 Add a hit to the cluster using its stored position.
 
void add (const HitType &hit)
 Add a hit to the cluster using its stored position (reference version).
 
void add (const HitType *hit, double x, double y, double z)
 Add a hit to the cluster with explicit position.
 
void add (const WorkingCluster< HitType > &other)
 Merge another cluster into this one.
 
double centroidX () const
 Get the centroid X position (energy-weighted).
 
double centroidY () const
 Get the centroid Y position (energy-weighted).
 
double centroidZ () const
 Get the centroid Z position (energy-weighted).
 
double energy () const
 Get the total energy of the cluster.
 
double time () const
 Get the time of the cluster (latest hit time).
 
const std::vector< const HitType * > & hits () const
 Get the list of hits in this cluster.
 
bool empty () const
 Check if the cluster is empty.
 
void clear ()
 Clear all hits from the cluster.
 
void setCentroid (double x, double y, double z, double e)
 Set the centroid position and energy explicitly.
 
void setTime (double t)
 Set the time explicitly.
 
int layer () const
 Get the layer of the cluster.
 
void setLayer (int layer)
 Set the layer of the cluster.
 

Private Attributes

std::vector< const HitType * > hits_
 The hits in this cluster.
 
double centroid_x_ {0}
 Centroid X position (energy-weighted)
 
double centroid_y_ {0}
 Centroid Y position (energy-weighted)
 
double centroid_z_ {0}
 Centroid Z position (energy-weighted)
 
double centroid_e_ {0}
 Total energy.
 
double time_ {0}
 Time (latest hit time)
 
int layer_ {-1}
 Layer number.
 

Detailed Description

template<class HitType>
class recon::WorkingCluster< HitType >

An in-memory representation of a cluster being built during reconstruction.

This class is a general-purpose tool for building clusters from calorimeter hits. It is templated on the hit type, which must inherit from CalorimeterHit. The cluster stores an energy-weighted centroid in (x,y,z,E) space.

Template Parameters
HitTypeThe type of hit to cluster (must inherit from CalorimeterHit)

Definition at line 28 of file WorkingCluster.h.

Constructor & Destructor Documentation

◆ WorkingCluster() [1/2]

template<class HitType >
recon::WorkingCluster< HitType >::WorkingCluster ( const HitType * hit)
inline

Construct a cluster from a single hit.

Parameters
hitPointer to the hit to initialize the cluster with

Definition at line 40 of file WorkingCluster.h.

40 {
41 if (hit) {
42 add(hit);
43 }
44 }
void add(const HitType *hit)
Add a hit to the cluster using its stored position.

References recon::WorkingCluster< HitType >::add().

◆ WorkingCluster() [2/2]

template<class HitType >
recon::WorkingCluster< HitType >::WorkingCluster ( const HitType & hit)
inline

Construct a cluster from a single hit (reference version).

Parameters
hitReference to the hit to initialize the cluster with

Definition at line 51 of file WorkingCluster.h.

51{ add(hit); }

References recon::WorkingCluster< HitType >::add().

Member Function Documentation

◆ add() [1/4]

template<class HitType >
void recon::WorkingCluster< HitType >::add ( const HitType & hit)
inline

Add a hit to the cluster using its stored position (reference version).

Parameters
hitReference to the hit to add

Definition at line 95 of file WorkingCluster.h.

95{ add(&hit); }

References recon::WorkingCluster< HitType >::add().

Referenced by recon::WorkingCluster< HitType >::add().

◆ add() [2/4]

template<class HitType >
void recon::WorkingCluster< HitType >::add ( const HitType * hit)
inline

Add a hit to the cluster using its stored position.

The centroid is updated using energy-weighted averaging.

Parameters
hitPointer to the hit to add

Definition at line 65 of file WorkingCluster.h.

65 {
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 }
double centroid_e_
Total energy.
double centroid_x_
Centroid X position (energy-weighted)
double time_
Time (latest hit time)
double centroid_y_
Centroid Y position (energy-weighted)
std::vector< const HitType * > hits_
The hits in this cluster.
double centroid_z_
Centroid Z position (energy-weighted)

References recon::WorkingCluster< HitType >::centroid_e_, recon::WorkingCluster< HitType >::centroid_x_, recon::WorkingCluster< HitType >::centroid_y_, recon::WorkingCluster< HitType >::centroid_z_, recon::WorkingCluster< HitType >::hits_, and recon::WorkingCluster< HitType >::time_.

Referenced by recon::TemplatedClusterFinder< HitType, WeightClass >::add(), recon::WorkingCluster< HitType >::WorkingCluster(), and recon::WorkingCluster< HitType >::WorkingCluster().

◆ add() [3/4]

template<class HitType >
void recon::WorkingCluster< HitType >::add ( const HitType * hit,
double x,
double y,
double z )
inline

Add a hit to the cluster with explicit position.

This version allows providing the position externally (e.g., from geometry).

Parameters
hitPointer to the hit to add
xX position of the hit
yY position of the hit
zZ position of the hit

Definition at line 108 of file WorkingCluster.h.

108 {
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 }

References recon::WorkingCluster< HitType >::centroid_e_, recon::WorkingCluster< HitType >::centroid_x_, recon::WorkingCluster< HitType >::centroid_y_, recon::WorkingCluster< HitType >::centroid_z_, recon::WorkingCluster< HitType >::hits_, and recon::WorkingCluster< HitType >::time_.

◆ add() [4/4]

template<class HitType >
void recon::WorkingCluster< HitType >::add ( const WorkingCluster< HitType > & other)
inline

Merge another cluster into this one.

Parameters
otherThe cluster to merge into this one

Definition at line 134 of file WorkingCluster.h.

134 {
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 }

References recon::WorkingCluster< HitType >::centroid_e_, recon::WorkingCluster< HitType >::centroid_x_, recon::WorkingCluster< HitType >::centroid_y_, recon::WorkingCluster< HitType >::centroid_z_, recon::WorkingCluster< HitType >::hits_, and recon::WorkingCluster< HitType >::time_.

◆ centroidX()

template<class HitType >
double recon::WorkingCluster< HitType >::centroidX ( ) const
inline

Get the centroid X position (energy-weighted).

Definition at line 161 of file WorkingCluster.h.

161{ return centroid_x_; }

References recon::WorkingCluster< HitType >::centroid_x_.

Referenced by ecal::MyClusterWeight::operator()(), and hcal::MyClusterWeight::operator()().

◆ centroidY()

template<class HitType >
double recon::WorkingCluster< HitType >::centroidY ( ) const
inline

Get the centroid Y position (energy-weighted).

Definition at line 166 of file WorkingCluster.h.

166{ return centroid_y_; }

References recon::WorkingCluster< HitType >::centroid_y_.

Referenced by ecal::MyClusterWeight::operator()(), and hcal::MyClusterWeight::operator()().

◆ centroidZ()

template<class HitType >
double recon::WorkingCluster< HitType >::centroidZ ( ) const
inline

Get the centroid Z position (energy-weighted).

Definition at line 171 of file WorkingCluster.h.

171{ return centroid_z_; }

References recon::WorkingCluster< HitType >::centroid_z_.

Referenced by ecal::MyClusterWeight::operator()(), and hcal::MyClusterWeight::operator()().

◆ clear()

◆ empty()

template<class HitType >
bool recon::WorkingCluster< HitType >::empty ( ) const
inline

Check if the cluster is empty.

Definition at line 191 of file WorkingCluster.h.

191{ return hits_.empty(); }

References recon::WorkingCluster< HitType >::hits_.

◆ energy()

template<class HitType >
double recon::WorkingCluster< HitType >::energy ( ) const
inline

◆ hits()

template<class HitType >
const std::vector< const HitType * > & recon::WorkingCluster< HitType >::hits ( ) const
inline

Get the list of hits in this cluster.

Definition at line 186 of file WorkingCluster.h.

186{ return hits_; }

References recon::WorkingCluster< HitType >::hits_.

◆ layer()

template<class HitType >
int recon::WorkingCluster< HitType >::layer ( ) const
inline

Get the layer of the cluster.

Definition at line 223 of file WorkingCluster.h.

223{ return layer_; }
int layer_
Layer number.

References recon::WorkingCluster< HitType >::layer_.

Referenced by recon::WorkingCluster< HitType >::setLayer().

◆ setCentroid()

template<class HitType >
void recon::WorkingCluster< HitType >::setCentroid ( double x,
double y,
double z,
double e )
inline

◆ setLayer()

template<class HitType >
void recon::WorkingCluster< HitType >::setLayer ( int layer)
inline

Set the layer of the cluster.

Definition at line 228 of file WorkingCluster.h.

228{ layer_ = layer; }
int layer() const
Get the layer of the cluster.

References recon::WorkingCluster< HitType >::layer(), and recon::WorkingCluster< HitType >::layer_.

◆ setTime()

template<class HitType >
void recon::WorkingCluster< HitType >::setTime ( double t)
inline

Set the time explicitly.

Definition at line 218 of file WorkingCluster.h.

218{ time_ = t; }

References recon::WorkingCluster< HitType >::time_.

◆ time()

template<class HitType >
double recon::WorkingCluster< HitType >::time ( ) const
inline

Get the time of the cluster (latest hit time).

Definition at line 181 of file WorkingCluster.h.

181{ return time_; }

References recon::WorkingCluster< HitType >::time_.

Member Data Documentation

◆ centroid_e_

◆ centroid_x_

◆ centroid_y_

◆ centroid_z_

◆ hits_

◆ layer_

template<class HitType >
int recon::WorkingCluster< HitType >::layer_ {-1}
private

Layer number.

Definition at line 250 of file WorkingCluster.h.

250{-1};

Referenced by recon::WorkingCluster< HitType >::layer(), and recon::WorkingCluster< HitType >::setLayer().

◆ time_


The documentation for this class was generated from the following file: