CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
HGCalCLUEAlgo Class Reference

#include <HGCalCLUEAlgo.h>

Inheritance diagram for HGCalCLUEAlgo:
HGCalClusteringAlgoBase

Classes

struct  CellsOnLayer
 

Public Types

typedef math::XYZPoint Point
 point in the space More...
 
- Public Types inherited from HGCalClusteringAlgoBase
enum  VerbosityLevel { pDEBUG = 0, pWARNING = 1, pINFO = 2, pERROR = 3 }
 

Public Member Functions

void computeThreshold ()
 
std::vector< reco::BasicClustergetClusters (bool) override
 
Density getDensity () override
 
void getEventSetupPerAlgorithm (const edm::EventSetup &es) override
 
 HGCalCLUEAlgo (const edm::ParameterSet &ps)
 
void makeClusters () override
 
void populate (const HGCRecHitCollection &hits) override
 
void reset () override
 
 ~HGCalCLUEAlgo () override
 
- Public Member Functions inherited from HGCalClusteringAlgoBase
void getEventSetup (const edm::EventSetup &es)
 
 HGCalClusteringAlgoBase (VerbosityLevel v, reco::CaloCluster::AlgoId algo)
 
void setAlgoId (reco::CaloCluster::AlgoId algo)
 
void setVerbosity (VerbosityLevel the_verbosity)
 
virtual ~HGCalClusteringAlgoBase ()
 

Static Public Member Functions

static void fillPSetDescription (edm::ParameterSetDescription &iDesc)
 

Private Member Functions

void calculateDistanceToHigher (const HGCalLayerTiles &lt, const unsigned int layerId, float delta_c, float delta_r)
 
void calculateLocalDensity (const HGCalLayerTiles &lt, const unsigned int layerId, float delta_c, float delta_r)
 
math::XYZPoint calculatePosition (const std::vector< int > &v, const unsigned int layerId) const
 
float distance (int cell1, int cell2, int layerId, bool isEtaPhi) const
 
float distance2 (int cell1, int cell2, int layerId, bool isEtaPhi) const
 
int findAndAssignClusters (const unsigned int layerId, float delta_c, float delta_r)
 
void prepareDataStructures (const unsigned int layerId)
 
void setDensity (const unsigned int layerId)
 

Private Attributes

std::vector< CellsOnLayercells_
 
std::vector< double > dEdXweights_
 
Density density_
 
bool dependSensor_
 
double ecut_
 
double fcPerEle_
 
std::vector< double > fcPerMip_
 
bool initialized_
 
double kappa_
 
double noiseMip_
 
std::vector< double > nonAgedNoises_
 
std::vector< int > numberOfClustersPerLayer_
 
float outlierDeltaFactor_ = 2.f
 
std::vector< double > thicknessCorrection_
 
std::vector< std::vector< double > > thresholds_
 
std::vector< double > thresholdW0_
 
bool use2x2_
 
std::vector< std::vector< double > > v_sigmaNoise_
 
std::vector< double > vecDeltas_
 

Additional Inherited Members

- Public Attributes inherited from HGCalClusteringAlgoBase
unsigned int firstLayerBH_
 
unsigned int lastLayerEE_
 
unsigned int lastLayerFH_
 
unsigned int maxlayer_
 
int scintMaxIphi_
 
- Protected Attributes inherited from HGCalClusteringAlgoBase
reco::CaloCluster::AlgoId algoId_
 
std::vector< reco::BasicClusterclusters_v_
 
hgcal::RecHitTools rhtools_
 
VerbosityLevel verbosity_
 

Detailed Description

Definition at line 29 of file HGCalCLUEAlgo.h.

Member Typedef Documentation

point in the space

Definition at line 107 of file HGCalCLUEAlgo.h.

Constructor & Destructor Documentation

HGCalCLUEAlgo::HGCalCLUEAlgo ( const edm::ParameterSet ps)
inline

Definition at line 31 of file HGCalCLUEAlgo.h.

33  (HGCalClusteringAlgoBase::VerbosityLevel)ps.getUntrackedParameter<unsigned int>("verbosity", 3),
35  thresholdW0_(ps.getParameter<std::vector<double>>("thresholdW0")),
36  vecDeltas_(ps.getParameter<std::vector<double>>("deltac")),
37  kappa_(ps.getParameter<double>("kappa")),
38  ecut_(ps.getParameter<double>("ecut")),
39  dependSensor_(ps.getParameter<bool>("dependSensor")),
40  dEdXweights_(ps.getParameter<std::vector<double>>("dEdXweights")),
41  thicknessCorrection_(ps.getParameter<std::vector<double>>("thicknessCorrection")),
42  fcPerMip_(ps.getParameter<std::vector<double>>("fcPerMip")),
43  fcPerEle_(ps.getParameter<double>("fcPerEle")),
44  nonAgedNoises_(ps.getParameter<edm::ParameterSet>("noises").getParameter<std::vector<double>>("values")),
45  noiseMip_(ps.getParameter<edm::ParameterSet>("noiseMip").getParameter<double>("noise_MIP")),
46  use2x2_(ps.getParameter<bool>("use2x2")),
47  initialized_(false) {}
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > nonAgedNoises_
std::vector< double > thicknessCorrection_
std::vector< double > thresholdW0_
std::vector< double > fcPerMip_
HGCalClusteringAlgoBase(VerbosityLevel v, reco::CaloCluster::AlgoId algo)
std::vector< double > dEdXweights_
std::vector< double > vecDeltas_
HGCalCLUEAlgo::~HGCalCLUEAlgo ( )
inlineoverride

Member Function Documentation

void HGCalCLUEAlgo::calculateDistanceToHigher ( const HGCalLayerTiles lt,
const unsigned int  layerId,
float  delta_c,
float  delta_r 
)
private

Definition at line 334 of file HGCalCLUEAlgo.cc.

References dumpMFGeometry_cfg::delta, hitfit::delta_r(), HLT_2018_cff::distance, HGCalLayerTiles::getGlobalBinByBin(), HGCalLayerTiles::getGlobalBinByBinEtaPhi(), mps_fire::i, dqmiolumiharvest::j, LogDebug, SiStripPI::max, allConversions_cfi::maxDelta, FastTimerService_cff::range, HGCalLayerTiles::searchBox(), HGCalLayerTiles::searchBoxEtaPhi(), photonAnalyzer_cfi::xBin, and photonAnalyzer_cfi::yBin.

Referenced by distance().

337  {
338  auto& cellsOnLayer = cells_[layerId];
339  unsigned int numberOfCells = cellsOnLayer.detid.size();
340  bool isOnlySi(false);
341  if (rhtools_.isOnlySilicon(layerId))
342  isOnlySi = true;
343 
344  for (unsigned int i = 0; i < numberOfCells; i++) {
345  bool isSi = isOnlySi || cellsOnLayer.isSi[i];
346  // initialize delta and nearest higher for i
348  float i_delta = maxDelta;
349  int i_nearestHigher = -1;
350  if (isSi) {
351  float delta = delta_c;
352  // get search box for ith hit
353  // guarantee to cover a range "outlierDeltaFactor_*delta_c"
355  std::array<int, 4> search_box = lt.searchBox(
356  cellsOnLayer.x[i] - range, cellsOnLayer.x[i] + range, cellsOnLayer.y[i] - range, cellsOnLayer.y[i] + range);
357  // loop over all bins in the search box
358  for (int xBin = search_box[0]; xBin < search_box[1] + 1; ++xBin) {
359  for (int yBin = search_box[2]; yBin < search_box[3] + 1; ++yBin) {
360  // get the id of this bin
361  size_t binId = lt.getGlobalBinByBin(xBin, yBin);
362  // get the size of this bin
363  size_t binSize = lt[binId].size();
364 
365  // loop over all hits in this bin
366  for (unsigned int j = 0; j < binSize; j++) {
367  unsigned int otherId = lt[binId][j];
368  bool otherSi = isOnlySi || cellsOnLayer.isSi[otherId];
369  if (otherSi) { //silicon cells cannot talk to scintillator cells
370  float dist = distance(i, otherId, layerId, false);
371  bool foundHigher = (cellsOnLayer.rho[otherId] > cellsOnLayer.rho[i]) ||
372  (cellsOnLayer.rho[otherId] == cellsOnLayer.rho[i] &&
373  cellsOnLayer.detid[otherId] > cellsOnLayer.detid[i]);
374  // if dist == i_delta, then last comer being the nearest higher
375  if (foundHigher && dist <= i_delta) {
376  // update i_delta
377  i_delta = dist;
378  // update i_nearestHigher
379  i_nearestHigher = otherId;
380  }
381  }
382  }
383  }
384  }
385 
386  bool foundNearestHigherInSearchBox = (i_delta != maxDelta);
387  if (foundNearestHigherInSearchBox) {
388  cellsOnLayer.delta[i] = i_delta;
389  cellsOnLayer.nearestHigher[i] = i_nearestHigher;
390  } else {
391  // otherwise delta is guaranteed to be larger outlierDeltaFactor_*delta_c
392  // we can safely maximize delta to be maxDelta
393  cellsOnLayer.delta[i] = maxDelta;
394  cellsOnLayer.nearestHigher[i] = -1;
395  }
396  } else {
397  //similar to silicon
398  float delta = delta_r;
400  std::array<int, 4> search_box = lt.searchBoxEtaPhi(cellsOnLayer.eta[i] - range,
401  cellsOnLayer.eta[i] + range,
402  cellsOnLayer.phi[i] - range,
403  cellsOnLayer.phi[i] + range);
404  // loop over all bins in the search box
405  for (int xBin = search_box[0]; xBin < search_box[1] + 1; ++xBin) {
406  for (int yBin = search_box[2]; yBin < search_box[3] + 1; ++yBin) {
407  // get the id of this bin
408  size_t binId = lt.getGlobalBinByBinEtaPhi(xBin, yBin);
409  // get the size of this bin
410  size_t binSize = lt[binId].size();
411 
412  // loop over all hits in this bin
413  for (unsigned int j = 0; j < binSize; j++) {
414  unsigned int otherId = lt[binId][j];
415  if (!cellsOnLayer.isSi[otherId]) { //scintillator cells cannot talk to silicon cells
416  float dist = distance(i, otherId, layerId, true);
417  bool foundHigher = (cellsOnLayer.rho[otherId] > cellsOnLayer.rho[i]) ||
418  (cellsOnLayer.rho[otherId] == cellsOnLayer.rho[i] &&
419  cellsOnLayer.detid[otherId] > cellsOnLayer.detid[i]);
420  // if dist == i_delta, then last comer being the nearest higher
421  if (foundHigher && dist <= i_delta) {
422  // update i_delta
423  i_delta = dist;
424  // update i_nearestHigher
425  i_nearestHigher = otherId;
426  }
427  }
428  }
429  }
430  }
431 
432  bool foundNearestHigherInSearchBox = (i_delta != maxDelta);
433  if (foundNearestHigherInSearchBox) {
434  cellsOnLayer.delta[i] = i_delta;
435  cellsOnLayer.nearestHigher[i] = i_nearestHigher;
436  } else {
437  // otherwise delta is guaranteed to be larger outlierDeltaFactor_*delta_c
438  // we can safely maximize delta to be maxDelta
439  cellsOnLayer.delta[i] = maxDelta;
440  cellsOnLayer.nearestHigher[i] = -1;
441  }
442  }
443  LogDebug("HGCalCLUEAlgo") << "Debugging calculateDistanceToHigher: \n"
444  << " cell: " << i << " isSilicon: " << cellsOnLayer.isSi[i]
445  << " eta: " << cellsOnLayer.eta[i] << " phi: " << cellsOnLayer.phi[i]
446  << " energy: " << cellsOnLayer.weight[i] << " density: " << cellsOnLayer.rho[i]
447  << " nearest higher: " << cellsOnLayer.nearestHigher[i]
448  << " distance: " << cellsOnLayer.delta[i] << "\n";
449  }
450 }
#define LogDebug(id)
bool isOnlySilicon(const unsigned int layer) const
Definition: RecHitTools.cc:424
float outlierDeltaFactor_
int getGlobalBinByBinEtaPhi(int etaBin, int phiBin) const
std::array< int, 4 > searchBox(float xMin, float xMax, float yMin, float yMax) const
int getGlobalBinByBin(int xBin, int yBin) const
std::vector< CellsOnLayer > cells_
double delta_r(const Fourvec &a, const Fourvec &b)
Find the distance between two four-vectors in the two-dimensional space .
Definition: fourvec.cc:238
std::array< int, 4 > searchBoxEtaPhi(float etaMin, float etaMax, float phiMin, float phiMax) const
float distance(int cell1, int cell2, int layerId, bool isEtaPhi) const
void HGCalCLUEAlgo::calculateLocalDensity ( const HGCalLayerTiles lt,
const unsigned int  layerId,
float  delta_c,
float  delta_r 
)
private

Definition at line 233 of file HGCalCLUEAlgo.cc.

References funct::abs(), Vispa.Plugins.EdmBrowser.EdmDataAccessor::all(), dumpMFGeometry_cfg::delta, hitfit::delta_r(), HLT_2018_cff::distance, muonRecoAnalyzer_cfi::etaBin, HGCalLayerTiles::getGlobalBinByBin(), HGCalLayerTiles::getGlobalBinByBinEtaPhi(), mps_fire::i, HGCScintillatorDetId::ieta(), HGCScintillatorDetId::iphi(), dqmiolumiharvest::j, LogDebug, SiStripPI::max, BeamMonitor_cff::phiBin, HGCalLayerTiles::searchBox(), HGCalLayerTiles::searchBoxEtaPhi(), photonAnalyzer_cfi::xBin, and photonAnalyzer_cfi::yBin.

Referenced by distance().

236  {
237  auto& cellsOnLayer = cells_[layerId];
238  unsigned int numberOfCells = cellsOnLayer.detid.size();
239  bool isOnlySi(false);
240  if (rhtools_.isOnlySilicon(layerId))
241  isOnlySi = true;
242 
243  for (unsigned int i = 0; i < numberOfCells; i++) {
244  bool isSi = isOnlySi || cellsOnLayer.isSi[i];
245  if (isSi) {
246  float delta = delta_c;
247  std::array<int, 4> search_box = lt.searchBox(
248  cellsOnLayer.x[i] - delta, cellsOnLayer.x[i] + delta, cellsOnLayer.y[i] - delta, cellsOnLayer.y[i] + delta);
249 
250  for (int xBin = search_box[0]; xBin < search_box[1] + 1; ++xBin) {
251  for (int yBin = search_box[2]; yBin < search_box[3] + 1; ++yBin) {
252  int binId = lt.getGlobalBinByBin(xBin, yBin);
253  size_t binSize = lt[binId].size();
254 
255  for (unsigned int j = 0; j < binSize; j++) {
256  unsigned int otherId = lt[binId][j];
257  bool otherSi = isOnlySi || cellsOnLayer.isSi[otherId];
258  if (otherSi) { //silicon cells cannot talk to scintillator cells
259  if (distance(i, otherId, layerId, false) < delta) {
260  cellsOnLayer.rho[i] += (i == otherId ? 1.f : 0.5f) * cellsOnLayer.weight[otherId];
261  }
262  }
263  }
264  }
265  }
266  } else {
267  float delta = delta_r;
268  std::array<int, 4> search_box = lt.searchBoxEtaPhi(cellsOnLayer.eta[i] - delta,
269  cellsOnLayer.eta[i] + delta,
270  cellsOnLayer.phi[i] - delta,
271  cellsOnLayer.phi[i] + delta);
272  cellsOnLayer.rho[i] += cellsOnLayer.weight[i];
273  float northeast(0), northwest(0), southeast(0), southwest(0), all(0);
274 
275  for (int etaBin = search_box[0]; etaBin < search_box[1] + 1; ++etaBin) {
276  for (int phiBin = search_box[2]; phiBin < search_box[3] + 1; ++phiBin) {
277  int binId = lt.getGlobalBinByBinEtaPhi(etaBin, phiBin);
278  size_t binSize = lt[binId].size();
279 
280  for (unsigned int j = 0; j < binSize; j++) {
281  unsigned int otherId = lt[binId][j];
282  if (!cellsOnLayer.isSi[otherId]) { //scintillator cells cannot talk to silicon cells
283  if (distance(i, otherId, layerId, true) < delta) {
284  int iPhi = HGCScintillatorDetId(cellsOnLayer.detid[i]).iphi();
285  int otherIPhi = HGCScintillatorDetId(cellsOnLayer.detid[otherId]).iphi();
286  int iEta = HGCScintillatorDetId(cellsOnLayer.detid[i]).ieta();
287  int otherIEta = HGCScintillatorDetId(cellsOnLayer.detid[otherId]).ieta();
288  int dIPhi = otherIPhi - iPhi;
289  dIPhi += abs(dIPhi) < 2
290  ? 0
291  : dIPhi < 0 ? scintMaxIphi_
292  : -scintMaxIphi_; // cells with iPhi=288 and iPhi=1 should be neiboring cells
293  int dIEta = otherIEta - iEta;
294  LogDebug("HGCalCLUEAlgo") << " Debugging calculateLocalDensity for Scintillator: \n"
295  << " cell: " << otherId << " energy: " << cellsOnLayer.weight[otherId]
296  << " otherIPhi: " << otherIPhi << " iPhi: " << iPhi
297  << " otherIEta: " << otherIEta << " iEta: " << iEta << "\n";
298 
299  if (otherId != i) {
300  auto neighborCellContribution = 0.5f * cellsOnLayer.weight[otherId];
301  all += neighborCellContribution;
302  if (dIPhi >= 0 && dIEta >= 0)
303  northeast += neighborCellContribution;
304  if (dIPhi <= 0 && dIEta >= 0)
305  southeast += neighborCellContribution;
306  if (dIPhi >= 0 && dIEta <= 0)
307  northwest += neighborCellContribution;
308  if (dIPhi <= 0 && dIEta <= 0)
309  southwest += neighborCellContribution;
310  }
311  LogDebug("HGCalCLUEAlgo") << " Debugging calculateLocalDensity for Scintillator: \n"
312  << " northeast: " << northeast << " southeast: " << southeast
313  << " northwest: " << northwest << " southwest: " << southwest << "\n";
314  }
315  }
316  }
317  }
318  }
319  float neighborsval = (std::max(northeast, northwest) > std::max(southeast, southwest))
320  ? std::max(northeast, northwest)
321  : std::max(southeast, southwest);
322  if (use2x2_)
323  cellsOnLayer.rho[i] += neighborsval;
324  else
325  cellsOnLayer.rho[i] += all;
326  }
327  LogDebug("HGCalCLUEAlgo") << "Debugging calculateLocalDensity: \n"
328  << " cell: " << i << " isSilicon: " << cellsOnLayer.isSi[i]
329  << " eta: " << cellsOnLayer.eta[i] << " phi: " << cellsOnLayer.phi[i]
330  << " energy: " << cellsOnLayer.weight[i] << " density: " << cellsOnLayer.rho[i] << "\n";
331  }
332 }
#define LogDebug(id)
bool isOnlySilicon(const unsigned int layer) const
Definition: RecHitTools.cc:424
int getGlobalBinByBinEtaPhi(int etaBin, int phiBin) const
std::array< int, 4 > searchBox(float xMin, float xMax, float yMin, float yMax) const
int getGlobalBinByBin(int xBin, int yBin) const
std::vector< CellsOnLayer > cells_
double delta_r(const Fourvec &a, const Fourvec &b)
Find the distance between two four-vectors in the two-dimensional space .
Definition: fourvec.cc:238
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int iphi() const
get the phi index
std::array< int, 4 > searchBoxEtaPhi(float etaMin, float etaMax, float phiMin, float phiMax) const
float distance(int cell1, int cell2, int layerId, bool isEtaPhi) const
math::XYZPoint HGCalCLUEAlgo::calculatePosition ( const std::vector< int > &  v,
const unsigned int  layerId 
) const
private

Definition at line 177 of file HGCalCLUEAlgo.cc.

References f, mps_fire::i, dqm-mbProfile::log, and SiStripPI::max.

Referenced by distance().

177  {
178  float total_weight = 0.f;
179  float x = 0.f;
180  float y = 0.f;
181 
182  unsigned int maxEnergyIndex = 0;
183  float maxEnergyValue = 0.f;
184 
185  auto& cellsOnLayer = cells_[layerId];
186 
187  // loop over hits in cluster candidate
188  // determining the maximum energy hit
189  for (auto i : v) {
190  total_weight += cellsOnLayer.weight[i];
191  if (cellsOnLayer.weight[i] > maxEnergyValue) {
192  maxEnergyValue = cellsOnLayer.weight[i];
193  maxEnergyIndex = i;
194  }
195  }
196 
197  // Si cell or Scintillator. Used to set approach and parameters
198  auto thick = rhtools_.getSiThickIndex(cellsOnLayer.detid[maxEnergyIndex]);
199  bool isSiliconCell = (thick != -1);
200 
201  // TODO: this is recomputing everything twice and overwriting the position with log weighting position
202  if (isSiliconCell) {
203  float total_weight_log = 0.f;
204  float x_log = 0.f;
205  float y_log = 0.f;
206  for (auto i : v) {
207  float rhEnergy = cellsOnLayer.weight[i];
208  float Wi = std::max(thresholdW0_[thick] + std::log(rhEnergy / total_weight), 0.);
209  x_log += cellsOnLayer.x[i] * Wi;
210  y_log += cellsOnLayer.y[i] * Wi;
211  total_weight_log += Wi;
212  }
213 
214  total_weight = total_weight_log;
215  x = x_log;
216  y = y_log;
217  } else {
218  for (auto i : v) {
219  float rhEnergy = cellsOnLayer.weight[i];
220 
221  x += cellsOnLayer.x[i] * rhEnergy;
222  y += cellsOnLayer.y[i] * rhEnergy;
223  }
224  }
225  if (total_weight != 0.) {
226  float inv_tot_weight = 1.f / total_weight;
227  return math::XYZPoint(
228  x * inv_tot_weight, y * inv_tot_weight, rhtools_.getPosition(cellsOnLayer.detid[maxEnergyIndex]).z());
229  } else
230  return math::XYZPoint(0.f, 0.f, 0.f);
231 }
std::vector< double > thresholdW0_
std::vector< CellsOnLayer > cells_
T z() const
Definition: PV3DBase.h:61
double f[11][100]
int getSiThickIndex(const DetId &) const
Definition: RecHitTools.cc:205
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:129
void HGCalCLUEAlgo::computeThreshold ( )

Definition at line 499 of file HGCalCLUEAlgo.cc.

References LogDebug.

Referenced by reset().

499  {
500  // To support the TDR geometry and also the post-TDR one (v9 onwards), we
501  // need to change the logic of the vectors containing signal to noise and
502  // thresholds. The first 3 indices will keep on addressing the different
503  // thicknesses of the Silicon detectors, while the last one, number 3 (the
504  // fourth) will address the Scintillators. This change will support both
505  // geometries at the same time.
506 
507  if (initialized_)
508  return; // only need to calculate thresholds once
509 
510  initialized_ = true;
511 
512  std::vector<double> dummy;
513  const unsigned maxNumberOfThickIndices = 3;
514  dummy.resize(maxNumberOfThickIndices + 1, 0); // +1 to accomodate for the Scintillators
515  thresholds_.resize(maxlayer_, dummy);
516  v_sigmaNoise_.resize(maxlayer_, dummy);
517 
518  for (unsigned ilayer = 1; ilayer <= maxlayer_; ++ilayer) {
519  for (unsigned ithick = 0; ithick < maxNumberOfThickIndices; ++ithick) {
520  float sigmaNoise = 0.001f * fcPerEle_ * nonAgedNoises_[ithick] * dEdXweights_[ilayer] /
521  (fcPerMip_[ithick] * thicknessCorrection_[ithick]);
522  thresholds_[ilayer - 1][ithick] = sigmaNoise * ecut_;
523  v_sigmaNoise_[ilayer - 1][ithick] = sigmaNoise;
524  LogDebug("HGCalCLUEAlgo") << "ilayer: " << ilayer << " nonAgedNoises: " << nonAgedNoises_[ithick]
525  << " fcPerEle: " << fcPerEle_ << " fcPerMip: " << fcPerMip_[ithick]
526  << " noiseMip: " << fcPerEle_ * nonAgedNoises_[ithick] / fcPerMip_[ithick]
527  << " sigmaNoise: " << sigmaNoise << "\n";
528  }
529  float scintillators_sigmaNoise = 0.001f * noiseMip_ * dEdXweights_[ilayer];
530  thresholds_[ilayer - 1][maxNumberOfThickIndices] = ecut_ * scintillators_sigmaNoise;
531  v_sigmaNoise_[ilayer - 1][maxNumberOfThickIndices] = scintillators_sigmaNoise;
532  LogDebug("HGCalCLUEAlgo") << "ilayer: " << ilayer << " noiseMip: " << noiseMip_
533  << " scintillators_sigmaNoise: " << scintillators_sigmaNoise << "\n";
534  }
535 }
#define LogDebug(id)
std::vector< std::vector< double > > v_sigmaNoise_
std::vector< double > nonAgedNoises_
std::vector< double > thicknessCorrection_
std::vector< double > fcPerMip_
std::vector< double > dEdXweights_
std::vector< std::vector< double > > thresholds_
float HGCalCLUEAlgo::distance ( int  cell1,
int  cell2,
int  layerId,
bool  isEtaPhi 
) const
inlineprivate

Definition at line 194 of file HGCalCLUEAlgo.h.

References calculateDistanceToHigher(), calculateLocalDensity(), calculatePosition(), hitfit::delta_r(), distance2(), findAndAssignClusters(), prepareDataStructures(), setDensity(), mathSSE::sqrt(), and findQualityFiles::v.

194  { // 2-d distance on the layer (x-y)
195  return std::sqrt(distance2(cell1, cell2, layerId, isEtaPhi));
196  }
T sqrt(T t)
Definition: SSEVec.h:19
float distance2(int cell1, int cell2, int layerId, bool isEtaPhi) const
float HGCalCLUEAlgo::distance2 ( int  cell1,
int  cell2,
int  layerId,
bool  isEtaPhi 
) const
inlineprivate

Definition at line 182 of file HGCalCLUEAlgo.h.

References hgcalTopologyTester_cfi::cell1, hgcalTopologyTester_cfi::cell2, reco::deltaPhi(), PVValHelper::dx, PVValHelper::dy, and HGCalCLUEAlgo::CellsOnLayer::phi.

Referenced by distance().

182  { // distance squared
183  if (isEtaPhi) {
184  const float dphi = reco::deltaPhi(cells_[layerId].phi[cell1], cells_[layerId].phi[cell2]);
185  const float deta = cells_[layerId].eta[cell1] - cells_[layerId].eta[cell2];
186  return (deta * deta + dphi * dphi);
187  } else {
188  const float dx = cells_[layerId].x[cell1] - cells_[layerId].x[cell2];
189  const float dy = cells_[layerId].y[cell1] - cells_[layerId].y[cell2];
190  return (dx * dx + dy * dy);
191  }
192  }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
std::vector< CellsOnLayer > cells_
static void HGCalCLUEAlgo::fillPSetDescription ( edm::ParameterSetDescription iDesc)
inlinestatic

Definition at line 77 of file HGCalCLUEAlgo.h.

References edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addUntracked(), and AlCaHLTBitMon_QueryRunRegistry::string.

77  {
78  iDesc.add<std::vector<double>>("thresholdW0", {2.9, 2.9, 2.9});
79  iDesc.add<std::vector<double>>("deltac",
80  {
81  1.3,
82  1.3,
83  5.0,
84  0.0315, // for scintillator
85  });
86  iDesc.add<bool>("dependSensor", true);
87  iDesc.add<double>("ecut", 3.0);
88  iDesc.add<double>("kappa", 9.0);
89  iDesc.addUntracked<unsigned int>("verbosity", 3);
90  iDesc.add<std::vector<double>>("dEdXweights", {});
91  iDesc.add<std::vector<double>>("thicknessCorrection", {});
92  iDesc.add<std::vector<double>>("fcPerMip", {});
93  iDesc.add<double>("fcPerEle", 0.0);
94  edm::ParameterSetDescription descNestedNoises;
95  descNestedNoises.add<std::vector<double>>("values", {});
96  iDesc.add<edm::ParameterSetDescription>("noises", descNestedNoises);
97  edm::ParameterSetDescription descNestedNoiseMIP;
98  descNestedNoiseMIP.add<bool>("scaleByDose", false);
99  descNestedNoiseMIP.add<unsigned int>("scaleByDoseAlgo", 0);
100  descNestedNoiseMIP.add<std::string>("doseMap", "");
101  descNestedNoiseMIP.add<double>("noise_MIP", 1. / 100.);
102  iDesc.add<edm::ParameterSetDescription>("noiseMip", descNestedNoiseMIP);
103  iDesc.add<bool>("use2x2", true); // use 2x2 or 3x3 scenario for scint density calculation
104  }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
int HGCalCLUEAlgo::findAndAssignClusters ( const unsigned int  layerId,
float  delta_c,
float  delta_r 
)
private

Definition at line 452 of file HGCalCLUEAlgo.cc.

References dumpMFGeometry_cfg::delta, hitfit::delta_r(), mps_fire::i, and dqmiolumiharvest::j.

Referenced by distance().

452  {
453  // this is called once per layer and endcap...
454  // so when filling the cluster temporary vector of Hexels we resize each time
455  // by the number of clusters found. This is always equal to the number of
456  // cluster centers...
457  unsigned int nClustersOnLayer = 0;
458  auto& cellsOnLayer = cells_[layerId];
459  unsigned int numberOfCells = cellsOnLayer.detid.size();
460  std::vector<int> localStack;
461  // find cluster seeds and outlier
462  for (unsigned int i = 0; i < numberOfCells; i++) {
463  float rho_c = kappa_ * cellsOnLayer.sigmaNoise[i];
464  bool isSi = rhtools_.isOnlySilicon(layerId) || cellsOnLayer.isSi[i];
465  float delta = isSi ? delta_c : delta_r;
466 
467  // initialize clusterIndex
468  cellsOnLayer.clusterIndex[i] = -1;
469  bool isSeed = (cellsOnLayer.delta[i] > delta) && (cellsOnLayer.rho[i] >= rho_c);
470  bool isOutlier = (cellsOnLayer.delta[i] > outlierDeltaFactor_ * delta) && (cellsOnLayer.rho[i] < rho_c);
471  if (isSeed) {
472  cellsOnLayer.clusterIndex[i] = nClustersOnLayer;
473  cellsOnLayer.isSeed[i] = true;
474  nClustersOnLayer++;
475  localStack.push_back(i);
476 
477  } else if (!isOutlier) {
478  cellsOnLayer.followers[cellsOnLayer.nearestHigher[i]].push_back(i);
479  }
480  }
481 
482  // need to pass clusterIndex to their followers
483  while (!localStack.empty()) {
484  int endStack = localStack.back();
485  auto& thisSeed = cellsOnLayer.followers[endStack];
486  localStack.pop_back();
487 
488  // loop over followers
489  for (int j : thisSeed) {
490  // pass id to a follower
491  cellsOnLayer.clusterIndex[j] = cellsOnLayer.clusterIndex[endStack];
492  // push this follower to localStack
493  localStack.push_back(j);
494  }
495  }
496  return nClustersOnLayer;
497 }
bool isOnlySilicon(const unsigned int layer) const
Definition: RecHitTools.cc:424
float outlierDeltaFactor_
std::vector< CellsOnLayer > cells_
double delta_r(const Fourvec &a, const Fourvec &b)
Find the distance between two four-vectors in the two-dimensional space .
Definition: fourvec.cc:238
std::vector< reco::BasicCluster > HGCalCLUEAlgo::getClusters ( bool  )
overridevirtual

Implements HGCalClusteringAlgoBase.

Definition at line 122 of file HGCalCLUEAlgo.cc.

References AlignmentPI::calculatePosition(), GetRecoTauVFromDQM_MC_cff::cl, reco::CaloID::DET_HGCAL_ENDCAP, HCALHighEnergyHPDFilter_cfi::energy, mps_fire::i, SiStripPI::max, unpackBuffers-CaloStage1::offsets, and position.

Referenced by ~HGCalCLUEAlgo().

122  {
123  std::vector<int> offsets(numberOfClustersPerLayer_.size(), 0);
124 
125  int maxClustersOnLayer = numberOfClustersPerLayer_[0];
126 
127  for (unsigned layerId = 1; layerId < offsets.size(); ++layerId) {
128  offsets[layerId] = offsets[layerId - 1] + numberOfClustersPerLayer_[layerId - 1];
129 
130  maxClustersOnLayer = std::max(maxClustersOnLayer, numberOfClustersPerLayer_[layerId]);
131  }
132 
133  auto totalNumberOfClusters = offsets.back() + numberOfClustersPerLayer_.back();
134  clusters_v_.resize(totalNumberOfClusters);
135  std::vector<std::vector<int>> cellsIdInCluster;
136  cellsIdInCluster.reserve(maxClustersOnLayer);
137 
138  for (unsigned int layerId = 0; layerId < 2 * maxlayer_ + 2; ++layerId) {
139  cellsIdInCluster.resize(numberOfClustersPerLayer_[layerId]);
140  auto& cellsOnLayer = cells_[layerId];
141  unsigned int numberOfCells = cellsOnLayer.detid.size();
142  auto firstClusterIdx = offsets[layerId];
143 
144  for (unsigned int i = 0; i < numberOfCells; ++i) {
145  auto clusterIndex = cellsOnLayer.clusterIndex[i];
146  if (clusterIndex != -1)
147  cellsIdInCluster[clusterIndex].push_back(i);
148  }
149 
150  std::vector<std::pair<DetId, float>> thisCluster;
151 
152  for (auto& cl : cellsIdInCluster) {
153  auto position = calculatePosition(cl, layerId);
154  float energy = 0.f;
155  int seedDetId = -1;
156 
157  for (auto cellIdx : cl) {
158  energy += cellsOnLayer.weight[cellIdx];
159  thisCluster.emplace_back(cellsOnLayer.detid[cellIdx], 1.f);
160  if (cellsOnLayer.isSeed[cellIdx]) {
161  seedDetId = cellsOnLayer.detid[cellIdx];
162  }
163  }
164  auto globalClusterIndex = cellsOnLayer.clusterIndex[cl[0]] + firstClusterIdx;
165 
166  clusters_v_[globalClusterIndex] =
168  clusters_v_[globalClusterIndex].setSeed(seedDetId);
169  thisCluster.clear();
170  }
171 
172  cellsIdInCluster.clear();
173  }
174  return clusters_v_;
175 }
CaloCluster BasicCluster
Definition: BasicCluster.h:21
std::vector< reco::BasicCluster > clusters_v_
std::vector< CellsOnLayer > cells_
math::XYZPoint calculatePosition(const std::vector< int > &v, const unsigned int layerId) const
std::vector< int > numberOfClustersPerLayer_
reco::CaloCluster::AlgoId algoId_
static int position[264][3]
Definition: ReadPGInfo.cc:289
Density HGCalCLUEAlgo::getDensity ( )
overridevirtual

Implements HGCalClusteringAlgoBase.

Definition at line 544 of file HGCalCLUEAlgo.cc.

Referenced by reset().

544 { return density_; }
Density density_
void HGCalCLUEAlgo::getEventSetupPerAlgorithm ( const edm::EventSetup es)
overridevirtual

Reimplemented from HGCalClusteringAlgoBase.

Definition at line 18 of file HGCalCLUEAlgo.cc.

Referenced by ~HGCalCLUEAlgo().

18  {
19  cells_.clear();
21  cells_.resize(2 * (maxlayer_ + 1));
22  numberOfClustersPerLayer_.resize(2 * (maxlayer_ + 1), 0);
23 }
std::vector< CellsOnLayer > cells_
std::vector< int > numberOfClustersPerLayer_
void HGCalCLUEAlgo::makeClusters ( )
overridevirtual

Implements HGCalClusteringAlgoBase.

Definition at line 91 of file HGCalCLUEAlgo.cc.

References HGCalLayerTiles::clear(), hitfit::delta_r(), PVValHelper::eta, HGCalLayerTiles::fill(), mps_fire::i, and LogDebug.

Referenced by ~HGCalCLUEAlgo().

91  {
92  // assign all hits in each layer to a cluster core
93  tbb::this_task_arena::isolate([&] {
94  tbb::parallel_for(size_t(0), size_t(2 * maxlayer_ + 2), [&](size_t i) {
96  HGCalLayerTiles lt;
97  lt.clear();
98  lt.fill(cells_[i].x, cells_[i].y, cells_[i].eta, cells_[i].phi, cells_[i].isSi);
99  float delta_c; // maximum search distance (critical distance) for local
100  // density calculation
101  if (i % maxlayer_ < lastLayerEE_)
102  delta_c = vecDeltas_[0];
103  else if (i % maxlayer_ < (firstLayerBH_ - 1))
104  delta_c = vecDeltas_[1];
105  else
106  delta_c = vecDeltas_[2];
107  float delta_r = vecDeltas_[3];
108  LogDebug("HGCalCLUEAlgo") << "maxlayer: " << maxlayer_ << " lastLayerEE: " << lastLayerEE_
109  << " firstLayerBH: " << firstLayerBH_ << "\n";
110 
111  calculateLocalDensity(lt, i, delta_c, delta_r);
112  calculateDistanceToHigher(lt, i, delta_c, delta_r);
113  numberOfClustersPerLayer_[i] = findAndAssignClusters(i, delta_c, delta_r);
114  });
115  });
116  //Now that we have the density per point we can store it
117  for (unsigned int i = 0; i < 2 * maxlayer_ + 2; ++i) {
118  setDensity(i);
119  }
120 }
#define LogDebug(id)
void prepareDataStructures(const unsigned int layerId)
void setDensity(const unsigned int layerId)
void fill(const std::vector< float > &x, const std::vector< float > &y, const std::vector< float > &eta, const std::vector< float > &phi, const std::vector< bool > &isSi)
std::vector< CellsOnLayer > cells_
void calculateDistanceToHigher(const HGCalLayerTiles &lt, const unsigned int layerId, float delta_c, float delta_r)
std::vector< int > numberOfClustersPerLayer_
double delta_r(const Fourvec &a, const Fourvec &b)
Find the distance between two four-vectors in the two-dimensional space .
Definition: fourvec.cc:238
std::vector< double > vecDeltas_
int findAndAssignClusters(const unsigned int layerId, float delta_c, float delta_r)
void calculateLocalDensity(const HGCalLayerTiles &lt, const unsigned int layerId, float delta_c, float delta_r)
void HGCalCLUEAlgo::populate ( const HGCRecHitCollection hits)
overridevirtual

Implements HGCalClusteringAlgoBase.

Definition at line 25 of file HGCalCLUEAlgo.cc.

References CaloRecHit::detid(), CaloRecHit::energy(), mps_fire::i, hltrates_dqm_sourceclient-live_cfg::offset, position, and edm::SortedCollection< T, SORT >::size().

Referenced by ~HGCalCLUEAlgo().

25  {
26  // loop over all hits and create the Hexel structure, skip energies below ecut
27 
28  if (dependSensor_) {
29  // for each layer and wafer calculate the thresholds (sigmaNoise and energy)
30  // once
32  }
33 
34  for (unsigned int i = 0; i < hits.size(); ++i) {
35  const HGCRecHit& hgrh = hits[i];
36  DetId detid = hgrh.detid();
37  unsigned int layerOnSide = (rhtools_.getLayerWithOffset(detid) - 1);
38 
39  // set sigmaNoise default value 1 to use kappa value directly in case of
40  // sensor-independent thresholds
41  float sigmaNoise = 1.f;
42  if (dependSensor_) {
43  int thickness_index = rhtools_.getSiThickIndex(detid);
44  if (thickness_index == -1)
45  thickness_index = 3;
46  double storedThreshold = thresholds_[layerOnSide][thickness_index];
47  sigmaNoise = v_sigmaNoise_[layerOnSide][thickness_index];
48 
49  if (hgrh.energy() < storedThreshold)
50  continue; // this sets the ZS threshold at ecut times the sigma noise
51  // for the sensor
52  }
53  if (!dependSensor_ && hgrh.energy() < ecut_)
54  continue;
56  int offset = ((rhtools_.zside(detid) + 1) >> 1) * maxlayer_;
57  int layer = layerOnSide + offset;
58 
59  cells_[layer].detid.emplace_back(detid);
60  cells_[layer].x.emplace_back(position.x());
61  cells_[layer].y.emplace_back(position.y());
62  if (!rhtools_.isOnlySilicon(layer)) {
63  cells_[layer].isSi.emplace_back(rhtools_.isSilicon(detid));
64  cells_[layer].eta.emplace_back(position.eta());
65  cells_[layer].phi.emplace_back(position.phi());
66  } // else, isSilicon == true and eta phi values will not be used
67  cells_[layer].weight.emplace_back(hgrh.energy());
68  cells_[layer].sigmaNoise.emplace_back(sigmaNoise);
69  }
70 }
constexpr float energy() const
Definition: CaloRecHit.h:29
bool isOnlySilicon(const unsigned int layer) const
Definition: RecHitTools.cc:424
int zside(const DetId &id) const
Definition: RecHitTools.cc:163
std::vector< std::vector< double > > v_sigmaNoise_
constexpr const DetId & detid() const
Definition: CaloRecHit.h:33
std::vector< CellsOnLayer > cells_
void computeThreshold()
bool isSilicon(const DetId &) const
Definition: RecHitTools.cc:417
Definition: DetId.h:17
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:355
int getSiThickIndex(const DetId &) const
Definition: RecHitTools.cc:205
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:129
size_type size() const
static int position[264][3]
Definition: ReadPGInfo.cc:289
std::vector< std::vector< double > > thresholds_
void HGCalCLUEAlgo::prepareDataStructures ( const unsigned int  layerId)
private

Definition at line 72 of file HGCalCLUEAlgo.cc.

References f, and cmsLHEtoEOSManager::l.

Referenced by distance().

72  {
73  auto cellsSize = cells_[l].detid.size();
74  cells_[l].rho.resize(cellsSize, 0.f);
75  cells_[l].delta.resize(cellsSize, 9999999);
76  cells_[l].nearestHigher.resize(cellsSize, -1);
77  cells_[l].clusterIndex.resize(cellsSize, -1);
78  cells_[l].followers.resize(cellsSize);
79  cells_[l].isSeed.resize(cellsSize, false);
80  if (rhtools_.isOnlySilicon(l)) {
81  cells_[l].isSi.resize(cellsSize, true);
82  cells_[l].eta.resize(cellsSize, 0.f);
83  cells_[l].phi.resize(cellsSize, 0.f);
84  }
85 }
bool isOnlySilicon(const unsigned int layer) const
Definition: RecHitTools.cc:424
std::vector< CellsOnLayer > cells_
double f[11][100]
void HGCalCLUEAlgo::reset ( void  )
inlineoverridevirtual

Implements HGCalClusteringAlgoBase.

Definition at line 63 of file HGCalCLUEAlgo.h.

References postprocess-scan-build::cells, cells_, GetRecoTauVFromDQM_MC_cff::cl, HGCalClusteringAlgoBase::clusters_v_, computeThreshold(), getDensity(), and numberOfClustersPerLayer_.

63  {
64  clusters_v_.clear();
65  for (auto& cl : numberOfClustersPerLayer_) {
66  cl = 0;
67  }
68 
69  for (auto& cells : cells_)
70  cells.clear();
71  }
std::vector< reco::BasicCluster > clusters_v_
std::vector< CellsOnLayer > cells_
std::vector< int > numberOfClustersPerLayer_
void HGCalCLUEAlgo::setDensity ( const unsigned int  layerId)
private

Definition at line 537 of file HGCalCLUEAlgo.cc.

References mps_fire::i.

Referenced by distance().

537  {
538  auto& cellsOnLayer = cells_[layerId];
539  unsigned int numberOfCells = cellsOnLayer.detid.size();
540  for (unsigned int i = 0; i < numberOfCells; ++i)
541  density_[cellsOnLayer.detid[i]] = cellsOnLayer.rho[i];
542 }
std::vector< CellsOnLayer > cells_
Density density_

Member Data Documentation

std::vector<CellsOnLayer> HGCalCLUEAlgo::cells_
private

Definition at line 178 of file HGCalCLUEAlgo.h.

Referenced by reset().

std::vector<double> HGCalCLUEAlgo::dEdXweights_
private

Definition at line 126 of file HGCalCLUEAlgo.h.

Density HGCalCLUEAlgo::density_
private

Definition at line 121 of file HGCalCLUEAlgo.h.

bool HGCalCLUEAlgo::dependSensor_
private

Definition at line 125 of file HGCalCLUEAlgo.h.

double HGCalCLUEAlgo::ecut_
private

Definition at line 118 of file HGCalCLUEAlgo.h.

double HGCalCLUEAlgo::fcPerEle_
private

Definition at line 129 of file HGCalCLUEAlgo.h.

std::vector<double> HGCalCLUEAlgo::fcPerMip_
private

Definition at line 128 of file HGCalCLUEAlgo.h.

bool HGCalCLUEAlgo::initialized_
private

Definition at line 138 of file HGCalCLUEAlgo.h.

double HGCalCLUEAlgo::kappa_
private

Definition at line 115 of file HGCalCLUEAlgo.h.

double HGCalCLUEAlgo::noiseMip_
private

Definition at line 131 of file HGCalCLUEAlgo.h.

std::vector<double> HGCalCLUEAlgo::nonAgedNoises_
private

Definition at line 130 of file HGCalCLUEAlgo.h.

std::vector<int> HGCalCLUEAlgo::numberOfClustersPerLayer_
private

Definition at line 180 of file HGCalCLUEAlgo.h.

Referenced by reset().

float HGCalCLUEAlgo::outlierDeltaFactor_ = 2.f
private

Definition at line 140 of file HGCalCLUEAlgo.h.

std::vector<double> HGCalCLUEAlgo::thicknessCorrection_
private

Definition at line 127 of file HGCalCLUEAlgo.h.

std::vector<std::vector<double> > HGCalCLUEAlgo::thresholds_
private

Definition at line 132 of file HGCalCLUEAlgo.h.

std::vector<double> HGCalCLUEAlgo::thresholdW0_
private

Definition at line 111 of file HGCalCLUEAlgo.h.

bool HGCalCLUEAlgo::use2x2_
private

Definition at line 135 of file HGCalCLUEAlgo.h.

std::vector<std::vector<double> > HGCalCLUEAlgo::v_sigmaNoise_
private

Definition at line 133 of file HGCalCLUEAlgo.h.

std::vector<double> HGCalCLUEAlgo::vecDeltas_
private

Definition at line 114 of file HGCalCLUEAlgo.h.