LDMX Software
CLUE.h
Go to the documentation of this file.
1
7#ifndef ECAL_CLUE_H_
8#define ECAL_CLUE_H_
9
10#include <math.h>
11
12#include <algorithm>
13#include <iomanip>
14#include <iostream>
15#include <limits>
16#include <map>
17#include <memory>
18#include <set>
19#include <stack>
20
21#include "Ecal/Event/EcalHit.h"
22#include "Ecal/IntermediateCluster.h"
23#include "Framework/Logger.h"
24
25namespace ecal {
26
27class CLUE {
28 enableLogging("CLUE");
29
30 public:
31 struct Density {
32 double x_;
33 double y_;
34 double z_;
35 double total_energy_;
36 int index_;
37
38 // index of density this density is follower of
39 // set to index of spatially closest density with higher energy; -1 if seed
40 int follower_of_;
41 // 2D separation distance to density that this is follower of
42 double delta_;
43 // separation in z to density that this is follower of
44 double z_delta_;
45 // 2D cluster ID
46 int cluster_id_;
47 // layer of density
48 int layer_;
49 // hits in this density
50 std::vector<const ldmx::EcalHit*> hits_;
51
52 Density() {}
53
54 Density(float xx, float yy) : x_(xx), y_(yy) {
55 total_energy_ = 0.;
56 index_ = -1;
57 follower_of_ = -1;
58 delta_ = std::numeric_limits<float>::max();
59 z_delta_ = std::numeric_limits<float>::max();
60 cluster_id_ = -1;
61 layer_ = -1;
62 z_ = 0.;
63 hits_ = {};
64 }
65 };
66
71 template <typename T>
72 T dist(T x1, T y1, T x2, T y2);
73 // 3D version
74 template <typename T>
75 T dist(T x1, T y1, T z1, T x2, T y2, T z2);
76 std::vector<std::vector<const ldmx::EcalHit*>> createLayers(
77 const std::vector<const ldmx::EcalHit*>& hits);
78 float roundToDecimal(float x, int num_decimal_precision_digits);
79 std::vector<std::shared_ptr<Density>> setup(
80 const std::vector<const ldmx::EcalHit*>& hits);
81
82 // connectingLayers marks if we're currently doing 3D clustering (i.e.
83 // connecting seeds between layers) otherwise, layerTag tells us which layer
84 // number we're working on
85 std::vector<std::vector<const ldmx::EcalHit*>> clustering(
86 std::vector<std::shared_ptr<Density>>& densities, bool connectingLayers,
87 int layerTag = 0);
88
89 std::vector<std::shared_ptr<Density>> setupForClue3D();
90
91 void convertToIntermediateClusters(
92 std::vector<std::vector<const ldmx::EcalHit*>>& clusters);
93
94 void cluster(const std::vector<ldmx::EcalHit>& hits, double dc, double rc,
95 double deltac, double deltao, int nbrOfLayers,
96 bool reclustering);
97
98 std::vector<double> getCentroidDistances() const {
99 return centroid_distances_;
100 }
101
102 int getNLoops() const { return clustering_loops_; }
103
104 int getInitialClusterNbr() const { return initial_cluster_nbr_; }
105
106 std::vector<IntermediateCluster> getClusters() const {
107 return final_clusters_;
108 }
109
110 // First layer centroids are available for potential future combination with
111 // TS
112 std::vector<IntermediateCluster> getFirstLayerCentroids() const {
113 return first_layer_centroids_;
114 }
115
116 private:
117 int clustering_loops_;
118
119 bool reclustering_;
120
121 double dc_;
122 double rhoc_;
123 double deltac_;
124 double deltao_;
125 double dm_;
126
127 // layers in Ecal
128 int max_layers_{32};
129 int nbr_of_layers_;
130
131 std::vector<double> layer_rho_c_;
132 std::vector<double> layer_delta_c_;
133 // containment radius for the different layers of the ECal
134 std::vector<double> radius_{
135 5.723387467629167, 5.190678018534044, 5.927290663506518,
136 6.182560329200212, 7.907549398117859, 8.606100542857211,
137 10.93381822596916, 12.043201938160239, 14.784548371508041,
138 16.102403056546482, 18.986402399412817, 20.224453740305716,
139 23.048820910305643, 24.11202594672678, 26.765135236851666,
140 27.78700483852502, 30.291794353801293, 31.409870873194464,
141 33.91006482486666, 35.173073672355926, 38.172422630271,
142 40.880288341493205, 44.696485719120005, 49.23802839743545,
143 53.789910813378675, 60.87843355562641, 66.32931132415688,
144 75.78117972604727, 86.04697356716805, 96.90360704034346};
145
146 std::vector<double> centroid_distances_;
147 IntermediateCluster event_centroid_;
148
149 std::vector<IntermediateCluster> first_layer_centroids_;
150
151 int seed_index_{0};
152 std::vector<std::vector<std::shared_ptr<Density>>> seeds_;
153
154 int initial_cluster_nbr_{-1};
155 std::vector<IntermediateCluster> final_clusters_;
156 std::vector<std::pair<double, double>> layer_centroid_separations_;
157};
158} // namespace ecal
159
160#endif
T dist(T x1, T y1, T x2, T y2)
Euclidean distance between two points.
Definition CLUE.cxx:15