-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathHGCalCLUEAlgo.h
250 lines (209 loc) · 9.23 KB
/
HGCalCLUEAlgo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#ifndef RecoLocalCalo_HGCalRecProducers_HGCalCLUEAlgo_h
#define RecoLocalCalo_HGCalRecProducers_HGCalCLUEAlgo_h
#include "RecoLocalCalo/HGCalRecProducers/interface/HGCalClusteringAlgoBase.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
#include "Geometry/CaloTopology/interface/HGCalTopology.h"
#include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "DataFormats/EgammaReco/interface/BasicCluster.h"
#include "DataFormats/Math/interface/Point3D.h"
#include "DataFormats/Math/interface/deltaPhi.h"
#include "RecoLocalCalo/HGCalRecProducers/interface/HGCalLayerTiles.h"
#include "RecoLocalCalo/HGCalRecProducers/interface/HGCalCLUEStrategy.h"
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
// C/C++ headers
#include <string>
#include <vector>
#include <limits>
#define DEBUG_CLUSTERS_ALPAKA 0
#if DEBUG_CLUSTERS_ALPAKA
#include "RecoLocalCalo/HGCalRecProducers/interface/DumpClustersDetails.h"
#endif
template <typename TILE, typename STRATEGY>
class HGCalCLUEAlgoT : public HGCalClusteringAlgoBase {
public:
HGCalCLUEAlgoT(const edm::ParameterSet& ps)
: HGCalClusteringAlgoBase(
(HGCalClusteringAlgoBase::VerbosityLevel)ps.getUntrackedParameter<unsigned int>("verbosity", 3),
reco::CaloCluster::undefined),
vecDeltas_(ps.getParameter<std::vector<double>>("deltac")),
kappa_(ps.getParameter<double>("kappa")),
ecut_(ps.getParameter<double>("ecut")),
dependSensor_(ps.getParameter<bool>("dependSensor")),
dEdXweights_(ps.getParameter<std::vector<double>>("dEdXweights")),
thicknessCorrection_(ps.getParameter<std::vector<double>>("thicknessCorrection")),
sciThicknessCorrection_(ps.getParameter<double>("sciThicknessCorrection")),
deltasi_index_regemfac_(ps.getParameter<int>("deltasi_index_regemfac")),
maxNumberOfThickIndices_(ps.getParameter<unsigned>("maxNumberOfThickIndices")),
fcPerMip_(ps.getParameter<std::vector<double>>("fcPerMip")),
fcPerEle_(ps.getParameter<double>("fcPerEle")),
nonAgedNoises_(ps.getParameter<std::vector<double>>("noises")),
noiseMip_(ps.getParameter<edm::ParameterSet>("noiseMip").getParameter<double>("noise_MIP")),
thresholdW0_(ps.getParameter<std::vector<double>>("thresholdW0")),
positionDeltaRho2_(ps.getParameter<double>("positionDeltaRho2")),
use2x2_(ps.getParameter<bool>("use2x2")),
initialized_(false) {
#if DEBUG_CLUSTERS_ALPAKA
moduleType_ = ps.getParameter<std::string>("type");
#endif
}
~HGCalCLUEAlgoT() override {}
void getEventSetupPerAlgorithm(const edm::EventSetup& es) override;
void populate(const HGCRecHitCollection& hits) override;
// this is the method that will start the clusterisation (it is possible to invoke this method
// more than once - but make sure it is with different hit collections (or else use reset)
void makeClusters() override;
// this is the method to get the cluster collection out
std::vector<reco::BasicCluster> getClusters(bool) override;
void reset() override {
clusters_v_.clear();
clusters_v_.shrink_to_fit();
for (auto& cl : numberOfClustersPerLayer_) {
cl = 0;
}
for (auto& cells : cells_) {
cells.clear();
cells.shrink_to_fit();
}
}
void computeThreshold();
static void fillPSetDescription(edm::ParameterSetDescription& iDesc) {
iDesc.add<std::vector<double>>("thresholdW0", {2.9, 2.9, 2.9});
iDesc.add<double>("positionDeltaRho2", 1.69);
iDesc.add<std::vector<double>>("deltac",
{
1.3,
1.3,
1.3,
0.0315, // for scintillator
});
iDesc.add<bool>("dependSensor", true);
iDesc.add<double>("ecut", 3.0);
iDesc.add<double>("kappa", 9.0);
iDesc.addUntracked<unsigned int>("verbosity", 3);
iDesc.add<std::vector<double>>("dEdXweights", {});
iDesc.add<std::vector<double>>("thicknessCorrection", {});
iDesc.add<double>("sciThicknessCorrection", 0.9);
iDesc.add<int>("deltasi_index_regemfac", 3);
iDesc.add<unsigned>("maxNumberOfThickIndices", 6);
iDesc.add<std::vector<double>>("fcPerMip", {});
iDesc.add<double>("fcPerEle", 0.0);
iDesc.add<std::vector<double>>("noises", {});
edm::ParameterSetDescription descNestedNoiseMIP;
descNestedNoiseMIP.add<bool>("scaleByDose", false);
descNestedNoiseMIP.add<unsigned int>("scaleByDoseAlgo", 0);
descNestedNoiseMIP.add<double>("scaleByDoseFactor", 1.);
descNestedNoiseMIP.add<std::string>("doseMap", "");
descNestedNoiseMIP.add<std::string>("sipmMap", "");
descNestedNoiseMIP.add<double>("referenceIdark", -1);
descNestedNoiseMIP.add<double>("referenceXtalk", -1);
descNestedNoiseMIP.add<double>("noise_MIP", 1. / 100.);
iDesc.add<edm::ParameterSetDescription>("noiseMip", descNestedNoiseMIP);
iDesc.add<bool>("use2x2", true); // use 2x2 or 3x3 scenario for scint density calculation
}
/// point in the space
typedef math::XYZPoint Point;
private:
// The two parameters used to identify clusters
std::vector<double> vecDeltas_;
double kappa_;
// The hit energy cutoff
double ecut_;
// various parameters used for calculating the noise levels for a given sensor (and whether to use
// them)
bool dependSensor_;
std::vector<double> dEdXweights_;
std::vector<double> thicknessCorrection_;
double sciThicknessCorrection_;
int deltasi_index_regemfac_;
unsigned maxNumberOfThickIndices_;
std::vector<double> fcPerMip_;
double fcPerEle_;
std::vector<double> nonAgedNoises_;
double noiseMip_;
std::vector<std::vector<double>> thresholds_;
std::vector<std::vector<double>> v_sigmaNoise_;
std::vector<double> thresholdW0_;
double positionDeltaRho2_;
bool use2x2_;
// initialization bool
bool initialized_;
float outlierDeltaFactor_ = 2.f;
struct CellsOnLayer {
std::vector<DetId> detid;
std::vector<float> dim1;
std::vector<float> dim2;
std::vector<float> weight;
std::vector<float> rho;
std::vector<float> delta;
std::vector<int> nearestHigher;
std::vector<int> clusterIndex;
std::vector<float> sigmaNoise;
std::vector<std::vector<int>> followers;
std::vector<bool> isSeed;
float layerDim3 = std::numeric_limits<float>::infinity();
void clear() {
detid.clear();
dim1.clear();
dim2.clear();
weight.clear();
rho.clear();
delta.clear();
nearestHigher.clear();
clusterIndex.clear();
sigmaNoise.clear();
followers.clear();
isSeed.clear();
}
void shrink_to_fit() {
detid.shrink_to_fit();
dim1.shrink_to_fit();
dim2.shrink_to_fit();
weight.shrink_to_fit();
rho.shrink_to_fit();
delta.shrink_to_fit();
nearestHigher.shrink_to_fit();
clusterIndex.shrink_to_fit();
sigmaNoise.shrink_to_fit();
followers.shrink_to_fit();
isSeed.shrink_to_fit();
}
};
std::vector<CellsOnLayer> cells_;
std::vector<int> numberOfClustersPerLayer_;
#if DEBUG_CLUSTERS_ALPAKA
std::string moduleType_;
#endif
inline float distance2(const TILE& lt, int cell1, int cell2, int layerId) const { // 2-d distance on the layer (x-y)
return (lt.distance2(cells_[layerId].dim1[cell1],
cells_[layerId].dim2[cell1],
cells_[layerId].dim1[cell2],
cells_[layerId].dim2[cell2]));
}
inline float distance(const TILE& lt, int cell1, int cell2, int layerId) const { // 2-d distance on the layer (x-y)
return std::sqrt(lt.distance2(cells_[layerId].dim1[cell1],
cells_[layerId].dim2[cell1],
cells_[layerId].dim1[cell2],
cells_[layerId].dim2[cell2]));
}
void prepareDataStructures(const unsigned int layerId);
void calculateLocalDensity(const TILE& lt, const unsigned int layerId,
float delta); // return max density
void calculateLocalDensity(const TILE& lt, const unsigned int layerId, float delta, HGCalSiliconStrategy strategy);
void calculateLocalDensity(const TILE& lt,
const unsigned int layerId,
float delta,
HGCalScintillatorStrategy strategy);
void calculateDistanceToHigher(const TILE& lt, const unsigned int layerId, float delta);
int findAndAssignClusters(const unsigned int layerId, float delta);
};
// explicit template instantiation
extern template class HGCalCLUEAlgoT<HGCalSiliconLayerTiles, HGCalSiliconStrategy>;
extern template class HGCalCLUEAlgoT<HGCalScintillatorLayerTiles, HGCalScintillatorStrategy>;
extern template class HGCalCLUEAlgoT<HFNoseLayerTiles, HGCalSiliconStrategy>;
using HGCalSiCLUEAlgo = HGCalCLUEAlgoT<HGCalSiliconLayerTiles, HGCalSiliconStrategy>;
using HGCalSciCLUEAlgo = HGCalCLUEAlgoT<HGCalScintillatorLayerTiles, HGCalScintillatorStrategy>;
using HFNoseCLUEAlgo = HGCalCLUEAlgoT<HFNoseLayerTiles, HGCalSiliconStrategy>;
#endif