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 
17 
20 
23 
24 // C/C++ headers
25 #include <set>
26 #include <string>
27 #include <vector>
28 
30 
32  public:
33 
36  (HGCalClusteringAlgoBase::VerbosityLevel)ps.getUntrackedParameter<unsigned int>("verbosity",3),
37  reco::CaloCluster::undefined),
38  thresholdW0_(ps.getParameter<std::vector<double> >("thresholdW0")),
39  positionDeltaRho_c_(ps.getParameter<std::vector<double> >("positionDeltaRho_c")),
40  vecDeltas_(ps.getParameter<std::vector<double> >("deltac")),
41  kappa_(ps.getParameter<double>("kappa")),
42  ecut_(ps.getParameter<double>("ecut")),
43  dependSensor_(ps.getParameter<bool>("dependSensor")),
44  dEdXweights_(ps.getParameter<std::vector<double> >("dEdXweights")),
45  thicknessCorrection_(ps.getParameter<std::vector<double> >("thicknessCorrection")),
46  fcPerMip_(ps.getParameter<std::vector<double> >("fcPerMip")),
47  fcPerEle_(ps.getParameter<double>("fcPerEle")),
48  nonAgedNoises_(ps.getParameter<edm::ParameterSet>("noises").getParameter<std::vector<double> >("values")),
49  noiseMip_(ps.getParameter<edm::ParameterSet>("noiseMip").getParameter<double>("value")),
51  points_(2*(maxlayer+1)),
52  minpos_(2*(maxlayer+1),{ {0.0f,0.0f} }),
53  maxpos_(2*(maxlayer+1),{ {0.0f,0.0f} }) {}
54 
55  ~HGCalCLUEAlgo() override {}
56 
57  void populate(const HGCRecHitCollection &hits) override;
58  // this is the method that will start the clusterisation (it is possible to invoke this method
59  // more than once - but make sure it is with different hit collections (or else use reset)
60 
61  void makeClusters() override;
62 
63  // this is the method to get the cluster collection out
64  std::vector<reco::BasicCluster> getClusters(bool) override;
65 
66  // use this if you want to reuse the same cluster object but don't want to accumulate clusters
67  // (hardly useful?)
68  void reset() override {
69  clusters_v_.clear();
70  layerClustersPerLayer_.clear();
71  for (auto &it : points_) {
72  it.clear();
73  std::vector<KDNode>().swap(it);
74  }
75  for (unsigned int i = 0; i < minpos_.size(); i++) {
76  minpos_[i][0] = 0.;
77  minpos_[i][1] = 0.;
78  maxpos_[i][0] = 0.;
79  maxpos_[i][1] = 0.;
80  }
81  }
82 
83  Density getDensity() override;
84 
85  void computeThreshold();
86 
88  iDesc.add<std::vector<double>>("thresholdW0", {
89  2.9,
90  2.9,
91  2.9
92  });
93  iDesc.add<std::vector<double>>("positionDeltaRho_c", {
94  1.3,
95  1.3,
96  1.3
97  });
98  iDesc.add<std::vector<double>>("deltac", {
99  1.3,
100  1.3,
101  5.0,
102  });
103  iDesc.add<bool>("dependSensor", true);
104  iDesc.add<double>("ecut", 3.0);
105  iDesc.add<double>("kappa", 9.0);
106  iDesc.addUntracked<unsigned int>("verbosity", 3);
107  iDesc.add<std::vector<double>>("dEdXweights",{});
108  iDesc.add<std::vector<double>>("thicknessCorrection",{});
109  iDesc.add<std::vector<double>>("fcPerMip",{});
110  iDesc.add<double>("fcPerEle",0.0);
111  edm::ParameterSetDescription descNestedNoises;
112  descNestedNoises.add<std::vector<double> >("values", {});
113  iDesc.add<edm::ParameterSetDescription>("noises", descNestedNoises);
114  edm::ParameterSetDescription descNestedNoiseMIP;
115  descNestedNoiseMIP.add<double>("value", 0 );
116  iDesc.add<edm::ParameterSetDescription>("noiseMip", descNestedNoiseMIP);
117  }
118 
121 
122  private:
123  // To compute the cluster position
124  std::vector<double> thresholdW0_;
125  std::vector<double> positionDeltaRho_c_;
126 
127  // The two parameters used to identify clusters
128  std::vector<double> vecDeltas_;
129  double kappa_;
130 
131  // The hit energy cutoff
132  double ecut_;
133 
134  // For keeping the density per hit
136 
137  // various parameters used for calculating the noise levels for a given sensor (and whether to use
138  // them)
140  std::vector<double> dEdXweights_;
141  std::vector<double> thicknessCorrection_;
142  std::vector<double> fcPerMip_;
143  double fcPerEle_;
144  std::vector<double> nonAgedNoises_;
145  double noiseMip_;
146  std::vector<std::vector<double> > thresholds_;
147  std::vector<std::vector<double> > v_sigmaNoise_;
148 
149  // initialization bool
151 
152  struct Hexel {
153  double x;
154  double y;
155  double z;
157  double weight;
158  double fraction;
160  double rho;
161  double delta;
164  float sigmaNoise;
165  float thickness;
167 
168  Hexel(const HGCRecHit &hit, DetId id_in, bool isHalf, float sigmaNoise_in, float thickness_in,
169  const hgcal::RecHitTools *tools_in)
170  : isHalfCell(isHalf),
171  weight(0.),
172  fraction(1.0),
173  detid(id_in),
174  rho(0.),
175  delta(0.),
176  nearestHigher(-1),
177  clusterIndex(-1),
178  sigmaNoise(sigmaNoise_in),
179  thickness(thickness_in),
180  tools(tools_in) {
181  const GlobalPoint position(tools->getPosition(detid));
182  weight = hit.energy();
183  x = position.x();
184  y = position.y();
185  z = position.z();
186  }
188  : x(0.),
189  y(0.),
190  z(0.),
191  isHalfCell(false),
192  weight(0.),
193  fraction(1.0),
194  detid(),
195  rho(0.),
196  delta(0.),
197  nearestHigher(-1),
198  clusterIndex(-1),
199  sigmaNoise(0.),
200  thickness(0.),
201  tools(nullptr) {}
202  bool operator>(const Hexel &rhs) const { return (rho > rhs.rho); }
203  };
204 
207 
208  std::vector<std::vector<std::vector<KDNode> > > layerClustersPerLayer_;
209 
210  std::vector<size_t> sort_by_delta(const std::vector<KDNode> &v) const {
211  std::vector<size_t> idx(v.size());
212  std::iota(std::begin(idx), std::end(idx), 0);
213  sort(idx.begin(), idx.end(),
214  [&v](size_t i1, size_t i2) { return v[i1].data.delta > v[i2].data.delta; });
215  return idx;
216  }
217 
218  std::vector<std::vector<KDNode> > points_; // a vector of vectors of hexels, one for each layer
219  //@@EM todo: the number of layers should be obtained programmatically - the range is 1-n instead
220  //of 0-n-1...
221 
222  std::vector<std::array<float, 2> > minpos_;
223  std::vector<std::array<float, 2> > maxpos_;
224 
225  // these functions should be in a helper class.
226  inline double distance2(const Hexel &pt1, const Hexel &pt2) const { // distance squared
227  const double dx = pt1.x - pt2.x;
228  const double dy = pt1.y - pt2.y;
229  return (dx * dx + dy * dy);
230  } // distance squaredq
231  inline double distance(const Hexel &pt1,
232  const Hexel &pt2) const { // 2-d distance on the layer (x-y)
233  return std::sqrt(distance2(pt1, pt2));
234  }
235  double calculateLocalDensity(std::vector<KDNode> &, KDTree &,
236  const unsigned int) const; // return max density
237  double calculateDistanceToHigher(std::vector<KDNode> &) const;
238  int findAndAssignClusters(std::vector<KDNode> &, KDTree &, double, KDTreeBox &,
239  const unsigned int, std::vector<std::vector<KDNode> > &) const;
240  math::XYZPoint calculatePosition(const std::vector<KDNode> &) const;
241  void setDensity(const std::vector<KDNode> &nd);
242 };
243 
244 #endif
constexpr float energy() const
Definition: CaloRecHit.h:31
std::vector< std::vector< std::vector< KDNode > > > layerClustersPerLayer_
std::vector< std::array< float, 2 > > minpos_
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
int findAndAssignClusters(std::vector< KDNode > &, KDTree &, double, KDTreeBox &, const unsigned int, std::vector< std::vector< KDNode > > &) const
std::vector< std::vector< double > > v_sigmaNoise_
std::map< DetId, float > Density
std::vector< double > nonAgedNoises_
#define nullptr
std::vector< double > thicknessCorrection_
void makeClusters() override
HGCalCLUEAlgo(const edm::ParameterSet &ps)
Definition: HGCalCLUEAlgo.h:34
std::vector< reco::BasicCluster > clusters_v_
const hgcal::RecHitTools * tools
double calculateDistanceToHigher(std::vector< KDNode > &) const
std::vector< reco::BasicCluster > getClusters(bool) override
std::vector< double > thresholdW0_
std::vector< double > fcPerMip_
Density getDensity() override
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
Hexel(const HGCRecHit &hit, DetId id_in, bool isHalf, float sigmaNoise_in, float thickness_in, const hgcal::RecHitTools *tools_in)
hgcal_clustering::Density Density
Definition: HGCalCLUEAlgo.h:29
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
Definition: HGCalCLUEAlgo.h:87
void computeThreshold()
bool operator>(const Hexel &rhs) const
T sqrt(T t)
Definition: SSEVec.h:18
~HGCalCLUEAlgo() override
Definition: HGCalCLUEAlgo.h:55
#define end
Definition: vmac.h:39
std::vector< double > dEdXweights_
std::vector< std::vector< KDNode > > points_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< size_t > sort_by_delta(const std::vector< KDNode > &v) const
void populate(const HGCRecHitCollection &hits) override
double calculateLocalDensity(std::vector< KDNode > &, KDTree &, const unsigned int) const
Definition: DetId.h:18
std::vector< double > vecDeltas_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Density density_
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:112
double distance(const Hexel &pt1, const Hexel &pt2) const
static const unsigned int maxlayer
double distance2(const Hexel &pt1, const Hexel &pt2) const
std::vector< std::array< float, 2 > > maxpos_
fixed size matrix
#define begin
Definition: vmac.h:32
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:509
std::vector< double > positionDeltaRho_c_
KDTreeLinkerAlgo< Hexel, 2 > KDTree
math::XYZPoint calculatePosition(const std::vector< KDNode > &) const
math::XYZPoint Point
point in the space
void reset() override
Definition: HGCalCLUEAlgo.h:68
std::vector< std::vector< double > > thresholds_
KDTreeNodeInfoT< Hexel, 2 > KDNode
void setDensity(const std::vector< KDNode > &nd)