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  descNestedNoiseMIP.add<double>("scaleByDoseFactor", 1.);
111  iDesc.add<edm::ParameterSetDescription>("scaleByDose", descNestedNoiseMIP);
112  descNestedNoiseMIP.add<std::string>("doseMap", "");
113  iDesc.add<edm::ParameterSetDescription>("doseMap", descNestedNoiseMIP);
114  descNestedNoiseMIP.add<double>("noise_MIP", 1. / 100.);
115  iDesc.add<edm::ParameterSetDescription>("noiseMip", descNestedNoiseMIP);
116  }
117 
120 
121 private:
122  // To compute the cluster position
123  std::vector<double> thresholdW0_;
124  std::vector<double> positionDeltaRho_c_;
125 
126  // The two parameters used to identify clusters
127  std::vector<double> vecDeltas_;
128  double kappa_;
129 
130  // The hit energy cutoff
131  double ecut_;
132 
133  // for energy sharing
134  double sigma2_; // transverse shower size
135 
136  // The vector of clusters
137  std::vector<reco::BasicCluster> clusters_v_;
138 
139  // For keeping the density per hit
141 
142  // various parameters used for calculating the noise levels for a given sensor (and whether to use them)
144  std::vector<double> dEdXweights_;
145  std::vector<double> thicknessCorrection_;
146  std::vector<double> fcPerMip_;
147  double fcPerEle_;
148  std::vector<double> nonAgedNoises_;
149  double noiseMip_;
150  std::vector<std::vector<double>> thresholds_;
151  std::vector<std::vector<double>> sigmaNoise_;
152 
153  // initialization bool
155 
156  struct Hexel {
157  double x;
158  double y;
159  double z;
161  double weight;
162  double fraction;
164  double rho;
165  double delta;
167  bool isBorder;
168  bool isHalo;
170  float sigmaNoise;
171  float thickness;
173 
175  DetId id_in,
176  bool isHalf,
177  float sigmaNoise_in,
178  float thickness_in,
179  const hgcal::RecHitTools *tools_in)
180  : isHalfCell(isHalf),
181  weight(0.),
182  fraction(1.0),
183  detid(id_in),
184  rho(0.),
185  delta(0.),
186  nearestHigher(-1),
187  isBorder(false),
188  isHalo(false),
189  clusterIndex(-1),
190  sigmaNoise(sigmaNoise_in),
191  thickness(thickness_in),
192  tools(tools_in) {
193  const GlobalPoint position(tools->getPosition(detid));
194  weight = hit.energy();
195  x = position.x();
196  y = position.y();
197  z = position.z();
198  }
200  : x(0.),
201  y(0.),
202  z(0.),
203  isHalfCell(false),
204  weight(0.),
205  fraction(1.0),
206  detid(),
207  rho(0.),
208  delta(0.),
209  nearestHigher(-1),
210  isBorder(false),
211  isHalo(false),
212  clusterIndex(-1),
213  sigmaNoise(0.),
214  thickness(0.),
215  tools(nullptr) {}
216  bool operator>(const Hexel &rhs) const { return (rho > rhs.rho); }
217  };
218 
221 
222  std::vector<std::vector<std::vector<KDNode>>> layerClustersPerLayer_;
223 
224  std::vector<size_t> sort_by_delta(const std::vector<KDNode> &v) const {
225  std::vector<size_t> idx(v.size());
226  std::iota(std::begin(idx), std::end(idx), 0);
227  sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1].data.delta > v[i2].data.delta; });
228  return idx;
229  }
230 
231  std::vector<std::vector<KDNode>> points_; //a vector of vectors of hexels, one for each layer
232  //@@EM todo: the number of layers should be obtained programmatically - the range is 1-n instead of 0-n-1...
233 
234  std::vector<std::array<float, 2>> minpos_;
235  std::vector<std::array<float, 2>> maxpos_;
236 
237  //these functions should be in a helper class.
238  inline double distance2(const Hexel &pt1, const Hexel &pt2) const { //distance squared
239  const double dx = pt1.x - pt2.x;
240  const double dy = pt1.y - pt2.y;
241  return (dx * dx + dy * dy);
242  } //distance squaredq
243  inline double distance(const Hexel &pt1, const Hexel &pt2) const { //2-d distance on the layer (x-y)
244  return std::sqrt(distance2(pt1, pt2));
245  }
246  double calculateLocalDensity(std::vector<KDNode> &, KDTree &, const unsigned int) const; //return max density
247  double calculateDistanceToHigher(std::vector<KDNode> &) const;
248  int findAndAssignClusters(std::vector<KDNode> &,
249  KDTree &,
250  double,
251  KDTreeBox<2> &,
252  const unsigned int,
253  std::vector<std::vector<KDNode>> &) const;
254  math::XYZPoint calculatePosition(std::vector<KDNode> &) const;
255 
256  //For keeping the density information
257  void setDensity(const std::vector<KDNode> &nd);
258 
259  // attempt to find subclusters within a given set of hexels
260  std::vector<unsigned> findLocalMaximaInCluster(const std::vector<KDNode> &);
261  math::XYZPoint calculatePositionWithFraction(const std::vector<KDNode> &, const std::vector<double> &);
262  double calculateEnergyWithFraction(const std::vector<KDNode> &, const std::vector<double> &);
263  // outputs
264  void shareEnergy(const std::vector<KDNode> &, const std::vector<unsigned> &, std::vector<std::vector<double>> &);
265 };
266 
267 #endif
ConfigurationDescriptions.h
KDTreeLinkerAlgo.h
HGCalImagingAlgo::thresholds_
std::vector< std::vector< double > > thresholds_
Definition: HGCalImagingAlgo.h:150
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:160
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:169
HGCalImagingAlgo::fcPerMip_
std::vector< double > fcPerMip_
Definition: HGCalImagingAlgo.h:146
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:174
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:234
HGCalImagingAlgo::Hexel::z
double z
Definition: HGCalImagingAlgo.h:159
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:156
HGCalImagingAlgo::kappa_
double kappa_
Definition: HGCalImagingAlgo.h:128
HGCalImagingAlgo::Hexel::fraction
double fraction
Definition: HGCalImagingAlgo.h:162
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HGCalImagingAlgo::Point
math::XYZPoint Point
point in the space
Definition: HGCalImagingAlgo.h:119
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:143
HGCalImagingAlgo::Hexel::nearestHigher
int nearestHigher
Definition: HGCalImagingAlgo.h:166
HGCalImagingAlgo::getClusters
std::vector< reco::BasicCluster > getClusters(bool) override
Definition: HGCalImagingAlgo.cc:119
HGCalImagingAlgo::thicknessCorrection_
std::vector< double > thicknessCorrection_
Definition: HGCalImagingAlgo.h:145
HGCalImagingAlgo::positionDeltaRho_c_
std::vector< double > positionDeltaRho_c_
Definition: HGCalImagingAlgo.h:124
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
DetId
Definition: DetId.h:17
HGCalImagingAlgo::Hexel::rho
double rho
Definition: HGCalImagingAlgo.h:164
HGCalImagingAlgo
Definition: HGCalImagingAlgo.h:31
HGCalImagingAlgo::noiseMip_
double noiseMip_
Definition: HGCalImagingAlgo.h:149
HGCalTopology.h
HGCalImagingAlgo::clusters_v_
std::vector< reco::BasicCluster > clusters_v_
Definition: HGCalImagingAlgo.h:137
DDAxes::undefined
HGCalImagingAlgo::distance2
double distance2(const Hexel &pt1, const Hexel &pt2) const
Definition: HGCalImagingAlgo.h:238
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:220
mps_fire.end
end
Definition: mps_fire.py:242
HGCalImagingAlgo::sigmaNoise_
std::vector< std::vector< double > > sigmaNoise_
Definition: HGCalImagingAlgo.h:151
HGCalImagingAlgo::maxpos_
std::vector< std::array< float, 2 > > maxpos_
Definition: HGCalImagingAlgo.h:235
HGCalImagingAlgo::ecut_
double ecut_
Definition: HGCalImagingAlgo.h:131
KDTreeBox
Definition: KDTreeLinkerAlgo.h:14
HGCalImagingAlgo::thresholdW0_
std::vector< double > thresholdW0_
Definition: HGCalImagingAlgo.h:123
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:243
HLT_FULL_cff.pt1
pt1
Definition: HLT_FULL_cff.py:9870
Point3DBase< float, GlobalTag >
HGCalImagingAlgo::density_
Density density_
Definition: HGCalImagingAlgo.h:140
HGCalImagingAlgo::Hexel::operator>
bool operator>(const Hexel &rhs) const
Definition: HGCalImagingAlgo.h:216
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:224
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:231
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:158
HGCalImagingAlgo::vecDeltas_
std::vector< double > vecDeltas_
Definition: HGCalImagingAlgo.h:127
HGCalImagingAlgo::dEdXweights_
std::vector< double > dEdXweights_
Definition: HGCalImagingAlgo.h:144
ParameterSet
Definition: Functions.h:16
HGCalImagingAlgo::Hexel::delta
double delta
Definition: HGCalImagingAlgo.h:165
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:171
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
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:9872
KDTreeNodeInfo
Definition: KDTreeLinkerAlgo.h:34
HGCalImagingAlgo::Hexel::weight
double weight
Definition: HGCalImagingAlgo.h:161
HGCalImagingAlgo::Hexel::x
double x
Definition: HGCalImagingAlgo.h:157
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:222
CaloCellGeometry.h
std
Definition: JetResolutionObject.h:76
HGCalImagingAlgo::sigma2_
double sigma2_
Definition: HGCalImagingAlgo.h:134
DetId.h
HGCalImagingAlgo::Hexel::sigmaNoise
float sigmaNoise
Definition: HGCalImagingAlgo.h:170
HGCalImagingAlgo::Hexel::tools
const hgcal::RecHitTools * tools
Definition: HGCalImagingAlgo.h:172
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:148
HGCalImagingAlgo::initialized_
bool initialized_
Definition: HGCalImagingAlgo.h:154
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:163
HGCalImagingAlgo::Hexel::isHalo
bool isHalo
Definition: HGCalImagingAlgo.h:168
HGCalImagingAlgo::Hexel::Hexel
Hexel()
Definition: HGCalImagingAlgo.h:199
HGCalImagingAlgo::fcPerEle_
double fcPerEle_
Definition: HGCalImagingAlgo.h:147
HGCalImagingAlgo::Hexel::isBorder
bool isBorder
Definition: HGCalImagingAlgo.h:167
HGCalClusteringAlgoBase::VerbosityLevel
VerbosityLevel
Definition: HGCalClusteringAlgoBase.h:49
HGCalClusteringAlgoBase
Definition: HGCalClusteringAlgoBase.h:47
PVValHelper::dx
Definition: PVValidationHelpers.h:49
HGCalImagingAlgo::KDTree
KDTreeLinkerAlgo< Hexel > KDTree
Definition: HGCalImagingAlgo.h:219
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