LDMX Software
TemplatedClusterFinder.h
1
2#ifndef HCAL_TEMPLATEDCLUSTERFINDER_H_
3#define HCAL_TEMPLATEDCLUSTERFINDER_H_
4
5#include <math.h>
6
7#include <map>
8
9#include "Hcal/WorkingCluster.h"
10#include "TH2F.h"
11
12namespace hcal {
13
14template <class WeightClass>
15
17 public:
18 void add(const ldmx::HcalHit* eh, const ldmx::HcalGeometry& hex) {
19 clusters_.push_back(WorkingCluster(eh, hex));
20 }
21
22 static bool compClusters(const WorkingCluster& a, const WorkingCluster& b) {
23 return a.centroid().E() > b.centroid().E();
24 }
25
26 void cluster(double seed_threshold, double cutoff, double deltaTime) {
27 int ncluster = clusters_.size();
28 double minwgt = cutoff;
29 std::sort(clusters_.begin(), clusters_.end(), compClusters);
30 do {
31 bool any = false;
32 unsigned int mi(0), mj(0);
33
34 int nseeds = 0;
35 // loop over all clusters:
36 for (unsigned int i = 0; i < clusters_.size(); i++) {
37 // skip if empty
38 if (clusters_[i].empty()) continue;
39 // check if cluster might be a seed minimum seed:
40 bool iseed = (clusters_[i].centroid().E() >= seed_threshold);
41 if (iseed) {
42 nseeds++;
43
44 } else {
45 // Since we sorted initially if we find a hit below seed threshold
46 // it is guaranteed that there will be no seeds after.
47 break;
48 }
49 // loop over the rest of the clusters:
50 for (unsigned int j = i + 1; j < clusters_.size(); j++) {
51 if (clusters_[j].empty() or
52 (!iseed and clusters_[j].centroid().E() < seed_threshold))
53 continue;
54 // calculate weights between the two clusters:
55 double wgt = wgt_(clusters_[i], clusters_[j]); // TODO
56 if (!any or
57 wgt < minwgt) { // minwgt begins at cut-off, this probably wants
58 // to tell us if these can physically be part of
59 // same shower (deltaT, and R cuts)
60 any = true;
61 minwgt = wgt;
62 mi = i;
63 mj = j;
64 }
65 }
66 }
67
68 // if(abs(clusters_[mi].GetTime() - clusters_[mj].GetTime()) > deltaTime)
69 // continue;
70
71 nseeds_ = nseeds;
72 transitionWeights_.insert(std::pair<int, double>(ncluster, minwgt));
73 if (any and 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
85 } while (minwgt < cutoff and ncluster > 1);
86 finalwgt_ = minwgt;
87 }
88
89 double getYMax() const { return finalwgt_; }
90
91 int getNSeeds() const { return nseeds_; }
92
93 std::map<int, double> getWeights() const { return transitionWeights_; }
94
95 std::vector<WorkingCluster> getClusters() const { return clusters_; }
96
97 private:
98 WeightClass wgt_;
99 double finalwgt_;
100 int nseeds_;
101 std::map<int, double> transitionWeights_;
102 std::vector<WorkingCluster> clusters_;
103};
104} // namespace hcal
105
106#endif
Implementation of HCal strip readout.
Stores reconstructed hit information from the HCAL.
Definition HcalHit.h:23