LDMX Software
ecal::TemplatedClusterFinder< WeightClass > Class Template Reference

Public Member Functions

void add (const ldmx::EcalHit &eh)
 
void cluster (double seed_threshold, double cutoff)
 
double getYMax () const
 
int getNSeeds () const
 
int getNLoops () const
 
std::map< int, double > getWeights () const
 
std::vector< IntermediateClustergetClusters () const
 

Static Public Member Functions

static bool compClusters (const IntermediateCluster &a, const IntermediateCluster &b)
 

Private Attributes

WeightClass wgt_
 
double finalwgt_
 
int nseeds_
 
int loops_
 
std::map< int, double > transition_weights_
 
std::vector< IntermediateClusterclusters_
 
std::vector< IntermediateClusterfinal_clusters_
 

Detailed Description

template<class WeightClass>
class ecal::TemplatedClusterFinder< WeightClass >

Definition at line 20 of file TemplatedClusterFinder.h.

Member Function Documentation

◆ add()

template<class WeightClass >
void ecal::TemplatedClusterFinder< WeightClass >::add ( const ldmx::EcalHit & eh)
inline

Definition at line 22 of file TemplatedClusterFinder.h.

22 {
23 clusters_.push_back(IntermediateCluster(eh));
24 }

◆ cluster()

template<class WeightClass >
void ecal::TemplatedClusterFinder< WeightClass >::cluster ( double seed_threshold,
double cutoff )
inline

Definition at line 31 of file TemplatedClusterFinder.h.

31 {
32 int ncluster = clusters_.size();
33 double minwgt = cutoff;
34 // Sort after highest energy
35 std::sort(clusters_.begin(), clusters_.end(), compClusters);
36 loops_ = 0;
37 do {
38 bool any = false;
39 size_t mi(0), mj(0);
40
41 int nseeds = 0;
42
43 for (size_t i = 0; i < clusters_.size(); i++) {
44 if (clusters_[i].empty()) continue;
45
46 bool iseed = (clusters_[i].centroid().E() >= seed_threshold);
47 if (iseed) {
48 nseeds++;
49 } else {
50 // Since we sorted initially if we find a hit below seed threshold
51 // it is guaranteed that there will be no seeds after.
52 break;
53 }
54
55 for (size_t j = i + 1; j < clusters_.size(); j++) {
56 if (clusters_[j].empty() ||
57 (!iseed && clusters_[j].centroid().E() <
58 seed_threshold)) // this never happens
59 continue;
60 double wgt = wgt_(clusters_[i], clusters_[j]);
61 if (!any || wgt < minwgt) {
62 any = true;
63 minwgt = wgt;
64 mi = i;
65 mj = j;
66 }
67 }
68 }
69
70 nseeds_ = nseeds;
71 transition_weights_.insert(std::pair<int, double>(ncluster, minwgt));
72
73 if (any && minwgt < cutoff) {
74 // put the bigger one in mi
75 if (clusters_[mi].centroid().E() < clusters_[mj].centroid().E()) {
76 std::swap(mi, mj);
77 }
78 // now we have the smallest, merge
79 clusters_[mi].add(clusters_[mj]);
80 clusters_[mj].clear();
81 // decrement cluster count
82 ncluster--;
83 }
84 loops_++;
85 } while (minwgt < cutoff && ncluster > 1);
86 finalwgt_ = minwgt;
87 for (const auto& cl : clusters_) {
88 if (!cl.empty() && cl.centroid().E() >= seed_threshold)
89 final_clusters_.push_back(cl);
90 else if (cl.centroid().E() < seed_threshold)
91 break; // clusters are sorted, so should be safe to break
92 }
93 }

◆ compClusters()

template<class WeightClass >
static bool ecal::TemplatedClusterFinder< WeightClass >::compClusters ( const IntermediateCluster & a,
const IntermediateCluster & b )
inlinestatic

Definition at line 26 of file TemplatedClusterFinder.h.

27 {
28 return a.centroid().E() > b.centroid().E();
29 }

◆ getClusters()

template<class WeightClass >
std::vector< IntermediateCluster > ecal::TemplatedClusterFinder< WeightClass >::getClusters ( ) const
inline

Definition at line 103 of file TemplatedClusterFinder.h.

103 {
104 return final_clusters_;
105 }

◆ getNLoops()

template<class WeightClass >
int ecal::TemplatedClusterFinder< WeightClass >::getNLoops ( ) const
inline

Definition at line 99 of file TemplatedClusterFinder.h.

99{ return loops_; }

◆ getNSeeds()

template<class WeightClass >
int ecal::TemplatedClusterFinder< WeightClass >::getNSeeds ( ) const
inline

Definition at line 97 of file TemplatedClusterFinder.h.

97{ return nseeds_; }

◆ getWeights()

template<class WeightClass >
std::map< int, double > ecal::TemplatedClusterFinder< WeightClass >::getWeights ( ) const
inline

Definition at line 101 of file TemplatedClusterFinder.h.

101{ return transition_weights_; }

◆ getYMax()

template<class WeightClass >
double ecal::TemplatedClusterFinder< WeightClass >::getYMax ( ) const
inline

Definition at line 95 of file TemplatedClusterFinder.h.

95{ return finalwgt_; }

Member Data Documentation

◆ clusters_

template<class WeightClass >
std::vector<IntermediateCluster> ecal::TemplatedClusterFinder< WeightClass >::clusters_
private

Definition at line 113 of file TemplatedClusterFinder.h.

◆ final_clusters_

template<class WeightClass >
std::vector<IntermediateCluster> ecal::TemplatedClusterFinder< WeightClass >::final_clusters_
private

Definition at line 114 of file TemplatedClusterFinder.h.

◆ finalwgt_

template<class WeightClass >
double ecal::TemplatedClusterFinder< WeightClass >::finalwgt_
private

Definition at line 109 of file TemplatedClusterFinder.h.

◆ loops_

template<class WeightClass >
int ecal::TemplatedClusterFinder< WeightClass >::loops_
private

Definition at line 111 of file TemplatedClusterFinder.h.

◆ nseeds_

template<class WeightClass >
int ecal::TemplatedClusterFinder< WeightClass >::nseeds_
private

Definition at line 110 of file TemplatedClusterFinder.h.

◆ transition_weights_

template<class WeightClass >
std::map<int, double> ecal::TemplatedClusterFinder< WeightClass >::transition_weights_
private

Definition at line 112 of file TemplatedClusterFinder.h.

◆ wgt_

template<class WeightClass >
WeightClass ecal::TemplatedClusterFinder< WeightClass >::wgt_
private

Definition at line 108 of file TemplatedClusterFinder.h.


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