CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
19 
21 
22 // C/C++ headers
23 #include <set>
24 #include <string>
25 #include <vector>
26 
28 
29 template <typename TILE>
31 public:
34  (HGCalClusteringAlgoBase::VerbosityLevel)ps.getUntrackedParameter<unsigned int>("verbosity", 3),
35  reco::CaloCluster::undefined,
36  iC),
37  thresholdW0_(ps.getParameter<std::vector<double>>("thresholdW0")),
38  positionDeltaRho2_(ps.getParameter<double>("positionDeltaRho2")),
39  vecDeltas_(ps.getParameter<std::vector<double>>("deltac")),
40  kappa_(ps.getParameter<double>("kappa")),
41  ecut_(ps.getParameter<double>("ecut")),
42  dependSensor_(ps.getParameter<bool>("dependSensor")),
43  dEdXweights_(ps.getParameter<std::vector<double>>("dEdXweights")),
44  thicknessCorrection_(ps.getParameter<std::vector<double>>("thicknessCorrection")),
45  sciThicknessCorrection_(ps.getParameter<double>("sciThicknessCorrection")),
46  deltasi_index_regemfac_(ps.getParameter<int>("deltasi_index_regemfac")),
47  maxNumberOfThickIndices_(ps.getParameter<unsigned>("maxNumberOfThickIndices")),
48  fcPerMip_(ps.getParameter<std::vector<double>>("fcPerMip")),
49  fcPerEle_(ps.getParameter<double>("fcPerEle")),
50  nonAgedNoises_(ps.getParameter<std::vector<double>>("noises")),
51  noiseMip_(ps.getParameter<edm::ParameterSet>("noiseMip").getParameter<double>("noise_MIP")),
52  use2x2_(ps.getParameter<bool>("use2x2")),
54 
55  ~HGCalCLUEAlgoT() override {}
56 
57  void getEventSetupPerAlgorithm(const edm::EventSetup& es) override;
58 
59  void populate(const HGCRecHitCollection& hits) override;
60 
61  // this is the method that will start the clusterisation (it is possible to invoke this method
62  // more than once - but make sure it is with different hit collections (or else use reset)
63 
64  void makeClusters() override;
65 
66  // this is the method to get the cluster collection out
67  std::vector<reco::BasicCluster> getClusters(bool) override;
68 
69  void reset() override {
70  clusters_v_.clear();
71  clusters_v_.shrink_to_fit();
72  for (auto& cl : numberOfClustersPerLayer_) {
73  cl = 0;
74  }
75 
76  for (auto& cells : cells_) {
77  cells.clear();
78  cells.shrink_to_fit();
79  }
80  density_.clear();
81  }
82 
83  Density getDensity() override;
84 
85  void computeThreshold();
86 
88  iDesc.add<std::vector<double>>("thresholdW0", {2.9, 2.9, 2.9});
89  iDesc.add<double>("positionDeltaRho2", 1.69);
90  iDesc.add<std::vector<double>>("deltac",
91  {
92  1.3,
93  1.3,
94  1.3,
95  0.0315, // for scintillator
96  });
97  iDesc.add<bool>("dependSensor", true);
98  iDesc.add<double>("ecut", 3.0);
99  iDesc.add<double>("kappa", 9.0);
100  iDesc.addUntracked<unsigned int>("verbosity", 3);
101  iDesc.add<std::vector<double>>("dEdXweights", {});
102  iDesc.add<std::vector<double>>("thicknessCorrection", {});
103  iDesc.add<double>("sciThicknessCorrection", 0.9);
104  iDesc.add<int>("deltasi_index_regemfac", 3);
105  iDesc.add<unsigned>("maxNumberOfThickIndices", 6);
106  iDesc.add<std::vector<double>>("fcPerMip", {});
107  iDesc.add<double>("fcPerEle", 0.0);
108  iDesc.add<std::vector<double>>("noises", {});
109  edm::ParameterSetDescription descNestedNoiseMIP;
110  descNestedNoiseMIP.add<bool>("scaleByDose", false);
111  descNestedNoiseMIP.add<unsigned int>("scaleByDoseAlgo", 0);
112  descNestedNoiseMIP.add<double>("scaleByDoseFactor", 1.);
113  descNestedNoiseMIP.add<std::string>("doseMap", "");
114  descNestedNoiseMIP.add<std::string>("sipmMap", "");
115  descNestedNoiseMIP.add<double>("referenceIdark", -1);
116  descNestedNoiseMIP.add<double>("referenceXtalk", -1);
117  descNestedNoiseMIP.add<double>("noise_MIP", 1. / 100.);
118  iDesc.add<edm::ParameterSetDescription>("noiseMip", descNestedNoiseMIP);
119  iDesc.add<bool>("use2x2", true); // use 2x2 or 3x3 scenario for scint density calculation
120  }
121 
124 
125 private:
126  // To compute the cluster position
127  std::vector<double> thresholdW0_;
128  const double positionDeltaRho2_;
129 
130  // The two parameters used to identify clusters
131  std::vector<double> vecDeltas_;
132  double kappa_;
133 
134  // The hit energy cutoff
135  double ecut_;
136 
137  // For keeping the density per hit
139 
140  // various parameters used for calculating the noise levels for a given sensor (and whether to use
141  // them)
143  std::vector<double> dEdXweights_;
144  std::vector<double> thicknessCorrection_;
148  std::vector<double> fcPerMip_;
149  double fcPerEle_;
150  std::vector<double> nonAgedNoises_;
151  double noiseMip_;
152  std::vector<std::vector<double>> thresholds_;
153  std::vector<std::vector<double>> v_sigmaNoise_;
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<bool> isSi;
165  std::vector<float> x;
166  std::vector<float> y;
167  std::vector<float> eta;
168  std::vector<float> phi;
169 
170  std::vector<float> weight;
171  std::vector<float> rho;
172 
173  std::vector<float> delta;
174  std::vector<int> nearestHigher;
175  std::vector<int> clusterIndex;
176  std::vector<float> sigmaNoise;
177  std::vector<std::vector<int>> followers;
178  std::vector<bool> isSeed;
179 
180  void clear() {
181  detid.clear();
182  isSi.clear();
183  x.clear();
184  y.clear();
185  eta.clear();
186  phi.clear();
187  weight.clear();
188  rho.clear();
189  delta.clear();
190  nearestHigher.clear();
191  clusterIndex.clear();
192  sigmaNoise.clear();
193  followers.clear();
194  isSeed.clear();
195  }
196 
197  void shrink_to_fit() {
198  detid.shrink_to_fit();
199  isSi.shrink_to_fit();
200  x.shrink_to_fit();
201  y.shrink_to_fit();
202  eta.shrink_to_fit();
203  phi.shrink_to_fit();
204  weight.shrink_to_fit();
205  rho.shrink_to_fit();
206  delta.shrink_to_fit();
207  nearestHigher.shrink_to_fit();
208  clusterIndex.shrink_to_fit();
209  sigmaNoise.shrink_to_fit();
210  followers.shrink_to_fit();
211  isSeed.shrink_to_fit();
212  }
213  };
214 
215  std::vector<CellsOnLayer> cells_;
216 
217  std::vector<int> numberOfClustersPerLayer_;
218 
219  inline float distance2(int cell1, int cell2, int layerId, bool isEtaPhi) const { // distance squared
220  if (isEtaPhi) {
221  const float dphi = reco::deltaPhi(cells_[layerId].phi[cell1], cells_[layerId].phi[cell2]);
222  const float deta = cells_[layerId].eta[cell1] - cells_[layerId].eta[cell2];
223  return (deta * deta + dphi * dphi);
224  } else {
225  const float dx = cells_[layerId].x[cell1] - cells_[layerId].x[cell2];
226  const float dy = cells_[layerId].y[cell1] - cells_[layerId].y[cell2];
227  return (dx * dx + dy * dy);
228  }
229  }
230 
231  inline float distance(int cell1, int cell2, int layerId, bool isEtaPhi) const { // 2-d distance on the layer (x-y)
232  return std::sqrt(distance2(cell1, cell2, layerId, isEtaPhi));
233  }
234 
235  void prepareDataStructures(const unsigned int layerId);
236  void calculateLocalDensity(const TILE& lt,
237  const unsigned int layerId,
238  float delta_c,
239  float delta_r); // return max density
240  void calculateDistanceToHigher(const TILE& lt, const unsigned int layerId, float delta_c, float delta_r);
241  int findAndAssignClusters(const unsigned int layerId, float delta_c, float delta_r);
242  math::XYZPoint calculatePosition(const std::vector<int>& v, const unsigned int layerId) const;
243  void setDensity(const unsigned int layerId);
244 };
245 
246 // explicit template instantiation
247 extern template class HGCalCLUEAlgoT<HGCalLayerTiles>;
248 extern template class HGCalCLUEAlgoT<HFNoseLayerTiles>;
249 
252 
253 #endif
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
const double positionDeltaRho2_
std::vector< double > thresholdW0_
unsigned maxNumberOfThickIndices_
int deltasi_index_regemfac_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
int findAndAssignClusters(const unsigned int layerId, float delta_c, float delta_r)
Density getDensity() override
std::vector< int > numberOfClustersPerLayer_
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
Definition: HGCalCLUEAlgo.h:87
void setDensity(const unsigned int layerId)
std::vector< std::vector< double > > thresholds_
std::vector< int > clusterIndex
float distance2(int cell1, int cell2, int layerId, bool isEtaPhi) const
void prepareDataStructures(const unsigned int layerId)
std::vector< reco::BasicCluster > clusters_v_
void populate(const HGCRecHitCollection &hits) override
std::vector< double > dEdXweights_
std::vector< float > rho
std::vector< float > sigmaNoise
std::vector< float > phi
std::vector< bool > isSeed
tuple cl
Definition: haddnano.py:49
std::map< DetId, float > Density
std::vector< float > x
void calculateDistanceToHigher(const TILE &lt, const unsigned int layerId, float delta_c, float delta_r)
math::XYZPoint calculatePosition(const std::vector< int > &v, const unsigned int layerId) const
void calculateLocalDensity(const TILE &lt, const unsigned int layerId, float delta_c, float delta_r)
std::vector< CellsOnLayer > cells_
T sqrt(T t)
Definition: SSEVec.h:19
HGCalCLUEAlgoT(const edm::ParameterSet &ps, edm::ConsumesCollector iC)
Definition: HGCalCLUEAlgo.h:32
void getEventSetupPerAlgorithm(const edm::EventSetup &es) override
double delta_r(const Fourvec &a, const Fourvec &b)
Find the distance between two four-vectors in the two-dimensional space .
Definition: fourvec.cc:238
std::vector< double > vecDeltas_
std::vector< double > fcPerMip_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
math::XYZPoint Point
point in the space
std::vector< float > delta
std::vector< DetId > detid
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ cells
std::vector< std::vector< int > > followers
std::vector< float > eta
std::vector< reco::BasicCluster > getClusters(bool) override
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< float > y
std::vector< std::vector< double > > v_sigmaNoise_
float outlierDeltaFactor_
std::vector< double > nonAgedNoises_
< trclass="colgroup">< tdclass="colgroup"colspan=5 > DT local reconstruction</td ></tr >< tr >< td >< ahref="classDTRecHit1DPair.html"> DTRecHit1DPair</a ></td >< td >< ahref="DataFormats_DTRecHit.html"> edm::RangeMap & lt
std::vector< bool > isSi
void reset() override
Definition: HGCalCLUEAlgo.h:69
std::vector< float > weight
std::vector< double > thicknessCorrection_
void computeThreshold()
double sciThicknessCorrection_
void makeClusters() override
hgcal_clustering::Density Density
~HGCalCLUEAlgoT() override
Definition: HGCalCLUEAlgo.h:55
std::vector< int > nearestHigher
float distance(int cell1, int cell2, int layerId, bool isEtaPhi) const