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