CMS 3D CMS Logo

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