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 public:
35  (HGCalClusteringAlgoBase::VerbosityLevel)ps.getUntrackedParameter<unsigned int>("verbosity", 3),
36  reco::CaloCluster::undefined),
37  thresholdW0_(ps.getParameter<std::vector<double>>("thresholdW0")),
38  positionDeltaRho_c_(ps.getParameter<std::vector<double>>("positionDeltaRho_c")),
39  vecDeltas_(ps.getParameter<std::vector<double>>("deltac")),
40  kappa_(ps.getParameter<double>("kappa")),
41  ecut_(ps.getParameter<double>("ecut")),
42  sigma2_(1.0),
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>("noise_MIP")),
51 
52  ~HGCalImagingAlgo() override {}
53 
54  void getEventSetupPerAlgorithm(const edm::EventSetup &es) override;
55 
56  void populate(const HGCRecHitCollection &hits) override;
57  // 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
58  // different hit collections (or else use reset)
59 
60  void makeClusters() override;
61 
62  // this is the method to get the cluster collection out
63  std::vector<reco::BasicCluster> getClusters(bool) override;
64 
65  // use this if you want to reuse the same cluster object but don't want to accumulate clusters (hardly useful?)
66  void reset() override {
67  clusters_v_.clear();
68  clusters_v_.shrink_to_fit();
69  layerClustersPerLayer_.clear();
70  layerClustersPerLayer_.shrink_to_fit();
71  for (auto &it : points_) {
72  it.clear();
73  it.shrink_to_fit();
74  std::vector<KDNode>().swap(it);
75  }
76  for (unsigned int i = 0; i < minpos_.size(); i++) {
77  minpos_[i][0] = 0.;
78  minpos_[i][1] = 0.;
79  maxpos_[i][0] = 0.;
80  maxpos_[i][1] = 0.;
81  }
82  }
83  void computeThreshold();
84 
85  //getDensity
86  Density getDensity() override;
87 
89  iDesc.add<std::vector<double>>("thresholdW0", {2.9, 2.9, 2.9});
90  iDesc.add<std::vector<double>>("positionDeltaRho_c", {1.3, 1.3, 1.3});
91  iDesc.add<std::vector<double>>("deltac",
92  {
93  2.0,
94  2.0,
95  5.0,
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<std::vector<double>>("fcPerMip", {});
104  iDesc.add<double>("fcPerEle", 0.0);
105  edm::ParameterSetDescription descNestedNoises;
106  descNestedNoises.add<std::vector<double>>("values", {});
107  iDesc.add<edm::ParameterSetDescription>("noises", descNestedNoises);
108  edm::ParameterSetDescription descNestedNoiseMIP;
109  descNestedNoiseMIP.add<bool>("scaleByDose", false);
110  iDesc.add<edm::ParameterSetDescription>("scaleByDose", descNestedNoiseMIP);
111  descNestedNoiseMIP.add<std::string>("doseMap", "");
112  iDesc.add<edm::ParameterSetDescription>("doseMap", descNestedNoiseMIP);
113  descNestedNoiseMIP.add<double>("noise_MIP", 1. / 100.);
114  iDesc.add<edm::ParameterSetDescription>("noiseMip", descNestedNoiseMIP);
115  }
116 
119 
120 private:
121  // To compute the cluster position
122  std::vector<double> thresholdW0_;
123  std::vector<double> positionDeltaRho_c_;
124 
125  // The two parameters used to identify clusters
126  std::vector<double> vecDeltas_;
127  double kappa_;
128 
129  // The hit energy cutoff
130  double ecut_;
131 
132  // for energy sharing
133  double sigma2_; // transverse shower size
134 
135  // The vector of clusters
136  std::vector<reco::BasicCluster> clusters_v_;
137 
138  // For keeping the density per hit
140 
141  // various parameters used for calculating the noise levels for a given sensor (and whether to use them)
143  std::vector<double> dEdXweights_;
144  std::vector<double> thicknessCorrection_;
145  std::vector<double> fcPerMip_;
146  double fcPerEle_;
147  std::vector<double> nonAgedNoises_;
148  double noiseMip_;
149  std::vector<std::vector<double>> thresholds_;
150  std::vector<std::vector<double>> sigmaNoise_;
151 
152  // initialization bool
154 
155  struct Hexel {
156  double x;
157  double y;
158  double z;
160  double weight;
161  double fraction;
163  double rho;
164  double delta;
166  bool isBorder;
167  bool isHalo;
169  float sigmaNoise;
170  float thickness;
172 
174  DetId id_in,
175  bool isHalf,
176  float sigmaNoise_in,
177  float thickness_in,
178  const hgcal::RecHitTools *tools_in)
179  : isHalfCell(isHalf),
180  weight(0.),
181  fraction(1.0),
182  detid(id_in),
183  rho(0.),
184  delta(0.),
185  nearestHigher(-1),
186  isBorder(false),
187  isHalo(false),
188  clusterIndex(-1),
189  sigmaNoise(sigmaNoise_in),
190  thickness(thickness_in),
191  tools(tools_in) {
192  const GlobalPoint position(tools->getPosition(detid));
193  weight = hit.energy();
194  x = position.x();
195  y = position.y();
196  z = position.z();
197  }
199  : x(0.),
200  y(0.),
201  z(0.),
202  isHalfCell(false),
203  weight(0.),
204  fraction(1.0),
205  detid(),
206  rho(0.),
207  delta(0.),
208  nearestHigher(-1),
209  isBorder(false),
210  isHalo(false),
211  clusterIndex(-1),
212  sigmaNoise(0.),
213  thickness(0.),
214  tools(nullptr) {}
215  bool operator>(const Hexel &rhs) const { return (rho > rhs.rho); }
216  };
217 
220 
221  std::vector<std::vector<std::vector<KDNode>>> layerClustersPerLayer_;
222 
223  std::vector<size_t> sort_by_delta(const std::vector<KDNode> &v) const {
224  std::vector<size_t> idx(v.size());
225  std::iota(std::begin(idx), std::end(idx), 0);
226  sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1].data.delta > v[i2].data.delta; });
227  return idx;
228  }
229 
230  std::vector<std::vector<KDNode>> points_; //a vector of vectors of hexels, one for each layer
231  //@@EM todo: the number of layers should be obtained programmatically - the range is 1-n instead of 0-n-1...
232 
233  std::vector<std::array<float, 2>> minpos_;
234  std::vector<std::array<float, 2>> maxpos_;
235 
236  //these functions should be in a helper class.
237  inline double distance2(const Hexel &pt1, const Hexel &pt2) const { //distance squared
238  const double dx = pt1.x - pt2.x;
239  const double dy = pt1.y - pt2.y;
240  return (dx * dx + dy * dy);
241  } //distance squaredq
242  inline double distance(const Hexel &pt1, const Hexel &pt2) const { //2-d distance on the layer (x-y)
243  return std::sqrt(distance2(pt1, pt2));
244  }
245  double calculateLocalDensity(std::vector<KDNode> &, KDTree &, const unsigned int) const; //return max density
246  double calculateDistanceToHigher(std::vector<KDNode> &) const;
247  int findAndAssignClusters(std::vector<KDNode> &,
248  KDTree &,
249  double,
250  KDTreeBox<2> &,
251  const unsigned int,
252  std::vector<std::vector<KDNode>> &) const;
253  math::XYZPoint calculatePosition(std::vector<KDNode> &) const;
254 
255  //For keeping the density information
256  void setDensity(const std::vector<KDNode> &nd);
257 
258  // attempt to find subclusters within a given set of hexels
259  std::vector<unsigned> findLocalMaximaInCluster(const std::vector<KDNode> &);
260  math::XYZPoint calculatePositionWithFraction(const std::vector<KDNode> &, const std::vector<double> &);
261  double calculateEnergyWithFraction(const std::vector<KDNode> &, const std::vector<double> &);
262  // outputs
263  void shareEnergy(const std::vector<KDNode> &, const std::vector<unsigned> &, std::vector<std::vector<double>> &);
264 };
265 
266 #endif
ConfigurationDescriptions.h
KDTreeLinkerAlgo.h
HGCalImagingAlgo::thresholds_
std::vector< std::vector< double > > thresholds_
Definition: HGCalImagingAlgo.h:149
HGCalImagingAlgo::calculateEnergyWithFraction
double calculateEnergyWithFraction(const std::vector< KDNode > &, const std::vector< double > &)
Definition: HGCalImagingAlgo.cc:522
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
HGCalImagingAlgo::Hexel::isHalfCell
bool isHalfCell
Definition: HGCalImagingAlgo.h:159
hgcal::RecHitTools
Definition: RecHitTools.h:23
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
HLT_2018_cff.pt2
pt2
Definition: HLT_2018_cff.py:8552
HGCalImagingAlgo::Hexel::clusterIndex
int clusterIndex
Definition: HGCalImagingAlgo.h:168
HGCalImagingAlgo::fcPerMip_
std::vector< double > fcPerMip_
Definition: HGCalImagingAlgo.h:145
funct::false
false
Definition: Factorize.h:34
HGCalImagingAlgo::Hexel::Hexel
Hexel(const HGCRecHit &hit, DetId id_in, bool isHalf, float sigmaNoise_in, float thickness_in, const hgcal::RecHitTools *tools_in)
Definition: HGCalImagingAlgo.h:173
HGCalClusteringAlgoBase.h
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
BasicCluster.h
edm
HLT enums.
Definition: AlignableModifier.h:19
HGCalImagingAlgo::minpos_
std::vector< std::array< float, 2 > > minpos_
Definition: HGCalImagingAlgo.h:233
HGCalImagingAlgo::Hexel::z
double z
Definition: HGCalImagingAlgo.h:158
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HLT_2018_cff.pt1
pt1
Definition: HLT_2018_cff.py:8550
edm::SortedCollection
Definition: SortedCollection.h:49
HGCalImagingAlgo::Hexel
Definition: HGCalImagingAlgo.h:155
HGCalImagingAlgo::kappa_
double kappa_
Definition: HGCalImagingAlgo.h:127
HGCalImagingAlgo::Hexel::fraction
double fraction
Definition: HGCalImagingAlgo.h:161
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HGCalImagingAlgo::Point
math::XYZPoint Point
point in the space
Definition: HGCalImagingAlgo.h:118
findQualityFiles.v
v
Definition: findQualityFiles.py:179
HGCalImagingAlgo::findLocalMaximaInCluster
std::vector< unsigned > findLocalMaximaInCluster(const std::vector< KDNode > &)
Definition: HGCalImagingAlgo.cc:479
HGCalImagingAlgo::dependSensor_
bool dependSensor_
Definition: HGCalImagingAlgo.h:142
training_settings.idx
idx
Definition: training_settings.py:16
HGCalImagingAlgo::Hexel::nearestHigher
int nearestHigher
Definition: HGCalImagingAlgo.h:165
end
#define end
Definition: vmac.h:39
HGCalImagingAlgo::getClusters
std::vector< reco::BasicCluster > getClusters(bool) override
Definition: HGCalImagingAlgo.cc:119
HGCalImagingAlgo::thicknessCorrection_
std::vector< double > thicknessCorrection_
Definition: HGCalImagingAlgo.h:144
HGCalImagingAlgo::positionDeltaRho_c_
std::vector< double > positionDeltaRho_c_
Definition: HGCalImagingAlgo.h:123
DetId
Definition: DetId.h:17
HGCalImagingAlgo::Hexel::rho
double rho
Definition: HGCalImagingAlgo.h:163
HGCalImagingAlgo
Definition: HGCalImagingAlgo.h:31
HGCalImagingAlgo::noiseMip_
double noiseMip_
Definition: HGCalImagingAlgo.h:148
HGCalTopology.h
HGCalImagingAlgo::clusters_v_
std::vector< reco::BasicCluster > clusters_v_
Definition: HGCalImagingAlgo.h:136
DDAxes::undefined
HGCalImagingAlgo::distance2
double distance2(const Hexel &pt1, const Hexel &pt2) const
Definition: HGCalImagingAlgo.h:237
HGCalImagingAlgo::getEventSetupPerAlgorithm
void getEventSetupPerAlgorithm(const edm::EventSetup &es) override
Definition: HGCalImagingAlgo.cc:17
HGCalImagingAlgo::calculatePositionWithFraction
math::XYZPoint calculatePositionWithFraction(const std::vector< KDNode > &, const std::vector< double > &)
Definition: HGCalImagingAlgo.cc:507
hgcal_clustering::Density
std::map< DetId, float > Density
Definition: HGCalClusteringAlgoBase.h:43
TruncatedPyramid.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HGCalImagingAlgo::KDNode
KDTreeNodeInfo< Hexel > KDNode
Definition: HGCalImagingAlgo.h:219
HGCalImagingAlgo::sigmaNoise_
std::vector< std::vector< double > > sigmaNoise_
Definition: HGCalImagingAlgo.h:150
HGCalImagingAlgo::maxpos_
std::vector< std::array< float, 2 > > maxpos_
Definition: HGCalImagingAlgo.h:234
HGCalImagingAlgo::ecut_
double ecut_
Definition: HGCalImagingAlgo.h:130
KDTreeBox
Definition: KDTreeLinkerAlgo.h:14
HGCalImagingAlgo::thresholdW0_
std::vector< double > thresholdW0_
Definition: HGCalImagingAlgo.h:122
KDTreeLinkerAlgo
Definition: KDTreeLinkerAlgo.h:102
HGCalImagingAlgo::makeClusters
void makeClusters() override
Definition: HGCalImagingAlgo.cc:93
HGCalImagingAlgo::distance
double distance(const Hexel &pt1, const Hexel &pt2) const
Definition: HGCalImagingAlgo.h:242
Point3DBase< float, GlobalTag >
HGCalImagingAlgo::density_
Density density_
Definition: HGCalImagingAlgo.h:139
HGCalImagingAlgo::Hexel::operator>
bool operator>(const Hexel &rhs) const
Definition: HGCalImagingAlgo.h:215
CaloGeometryRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HGCRecHit
Definition: HGCRecHit.h:14
HGCalImagingAlgo::sort_by_delta
std::vector< size_t > sort_by_delta(const std::vector< KDNode > &v) const
Definition: HGCalImagingAlgo.h:223
HGCalImagingAlgo::findAndAssignClusters
int findAndAssignClusters(std::vector< KDNode > &, KDTree &, double, KDTreeBox< 2 > &, const unsigned int, std::vector< std::vector< KDNode >> &) const
Definition: HGCalImagingAlgo.cc:344
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
HGCalImagingAlgo::points_
std::vector< std::vector< KDNode > > points_
Definition: HGCalImagingAlgo.h:230
CaloSubdetectorGeometry.h
HGCRecHitCollections.h
HGCalGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:36
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
HGCalImagingAlgo::Hexel::y
double y
Definition: HGCalImagingAlgo.h:157
HGCalImagingAlgo::vecDeltas_
std::vector< double > vecDeltas_
Definition: HGCalImagingAlgo.h:126
HGCalImagingAlgo::dEdXweights_
std::vector< double > dEdXweights_
Definition: HGCalImagingAlgo.h:143
ParameterSet
Definition: Functions.h:16
HGCalImagingAlgo::Hexel::delta
double delta
Definition: HGCalImagingAlgo.h:164
HGCalImagingAlgo::calculateDistanceToHigher
double calculateDistanceToHigher(std::vector< KDNode > &) const
Definition: HGCalImagingAlgo.cc:291
HGCalImagingAlgo::getDensity
Density getDensity() override
Definition: HGCalImagingAlgo.cc:668
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
HGCalImagingAlgo::Hexel::thickness
float thickness
Definition: HGCalImagingAlgo.h:170
HGCalImagingAlgo::setDensity
void setDensity(const std::vector< KDNode > &nd)
Definition: HGCalImagingAlgo.cc:660
createfilelist.int
int
Definition: createfilelist.py:10
HGCalImagingAlgo::~HGCalImagingAlgo
~HGCalImagingAlgo() override
Definition: HGCalImagingAlgo.h:52
PVValHelper::dy
Definition: PVValidationHelpers.h:49
edm::EventSetup
Definition: EventSetup.h:57
tools
Definition: tools.py:1
KDTreeNodeInfo
Definition: KDTreeLinkerAlgo.h:34
HGCalImagingAlgo::Hexel::weight
double weight
Definition: HGCalImagingAlgo.h:160
HGCalImagingAlgo::Hexel::x
double x
Definition: HGCalImagingAlgo.h:156
HGCalImagingAlgo::computeThreshold
void computeThreshold()
Definition: HGCalImagingAlgo.cc:628
HGCalImagingAlgo::calculateLocalDensity
double calculateLocalDensity(std::vector< KDNode > &, KDTree &, const unsigned int) const
Definition: HGCalImagingAlgo.cc:262
HGCalImagingAlgo::layerClustersPerLayer_
std::vector< std::vector< std::vector< KDNode > > > layerClustersPerLayer_
Definition: HGCalImagingAlgo.h:221
CaloCellGeometry.h
std
Definition: JetResolutionObject.h:76
HGCalImagingAlgo::sigma2_
double sigma2_
Definition: HGCalImagingAlgo.h:133
DetId.h
HGCalImagingAlgo::Hexel::sigmaNoise
float sigmaNoise
Definition: HGCalImagingAlgo.h:169
HGCalImagingAlgo::Hexel::tools
const hgcal::RecHitTools * tools
Definition: HGCalImagingAlgo.h:171
CaloGeometry.h
HGCalImagingAlgo::fillPSetDescription
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
Definition: HGCalImagingAlgo.h:88
HGCalImagingAlgo::shareEnergy
void shareEnergy(const std::vector< KDNode > &, const std::vector< unsigned > &, std::vector< std::vector< double >> &)
Definition: HGCalImagingAlgo.cc:531
Point3D.h
HGCalImagingAlgo::reset
void reset() override
Definition: HGCalImagingAlgo.h:66
HGCalImagingAlgo::nonAgedNoises_
std::vector< double > nonAgedNoises_
Definition: HGCalImagingAlgo.h:147
HGCalImagingAlgo::initialized_
bool initialized_
Definition: HGCalImagingAlgo.h:153
HGCalImagingAlgo::calculatePosition
math::XYZPoint calculatePosition(std::vector< KDNode > &) const
Definition: HGCalImagingAlgo.cc:196
HGCalImagingAlgo::HGCalImagingAlgo
HGCalImagingAlgo(const edm::ParameterSet &ps)
Definition: HGCalImagingAlgo.h:33
HGCalImagingAlgo::Hexel::detid
DetId detid
Definition: HGCalImagingAlgo.h:162
HGCalImagingAlgo::Hexel::isHalo
bool isHalo
Definition: HGCalImagingAlgo.h:167
HGCalImagingAlgo::Hexel::Hexel
Hexel()
Definition: HGCalImagingAlgo.h:198
HGCalImagingAlgo::fcPerEle_
double fcPerEle_
Definition: HGCalImagingAlgo.h:146
HGCalImagingAlgo::Hexel::isBorder
bool isBorder
Definition: HGCalImagingAlgo.h:166
HGCalClusteringAlgoBase::VerbosityLevel
VerbosityLevel
Definition: HGCalClusteringAlgoBase.h:49
HGCalClusteringAlgoBase
Definition: HGCalClusteringAlgoBase.h:47
begin
#define begin
Definition: vmac.h:32
PVValHelper::dx
Definition: PVValidationHelpers.h:48
HGCalImagingAlgo::KDTree
KDTreeLinkerAlgo< Hexel > KDTree
Definition: HGCalImagingAlgo.h:218
weight
Definition: weight.py:1
RecHitTools.h
hit
Definition: SiStripHitEffFromCalibTree.cc:88
Density
hgcal_clustering::Density Density
Definition: HGCalImagingAlgo.h:29
HGCalImagingAlgo::populate
void populate(const HGCRecHitCollection &hits) override
Definition: HGCalImagingAlgo.cc:26