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 26 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 38 of file WorkingCluster.h.

38 {
39 if (hit) {
40 add(hit);
41 }
42 }
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 49 of file WorkingCluster.h.

49{ 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 93 of file WorkingCluster.h.

93{ 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 63 of file WorkingCluster.h.

63 {
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 }
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 106 of file WorkingCluster.h.

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

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 132 of file WorkingCluster.h.

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

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 159 of file WorkingCluster.h.

159{ 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 164 of file WorkingCluster.h.

164{ 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 169 of file WorkingCluster.h.

169{ 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 189 of file WorkingCluster.h.

189{ 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 184 of file WorkingCluster.h.

184{ 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 221 of file WorkingCluster.h.

221{ 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 226 of file WorkingCluster.h.

226{ 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 216 of file WorkingCluster.h.

216{ 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 179 of file WorkingCluster.h.

179{ 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 248 of file WorkingCluster.h.

248{-1};

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

◆ time_


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