CMS 3D CMS Logo

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