CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
ticl::PatternRecognitionbyCLUE3D< TILES > Class Template Referencefinal

#include <PatternRecognitionbyCLUE3D.h>

Inheritance diagram for ticl::PatternRecognitionbyCLUE3D< TILES >:
ticl::PatternRecognitionAlgoBaseT< TILES >

Classes

struct  ClustersOnLayer
 

Public Member Functions

void energyRegressionAndID (const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result)
 
void makeTracksters (const typename PatternRecognitionAlgoBaseT< TILES >::Inputs &input, std::vector< Trackster > &result, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation) override
 
 PatternRecognitionbyCLUE3D (const edm::ParameterSet &conf, edm::ConsumesCollector)
 
 ~PatternRecognitionbyCLUE3D () override=default
 
- Public Member Functions inherited from ticl::PatternRecognitionAlgoBaseT< TILES >
virtual void makeTracksters (const Inputs &input, std::vector< Trackster > &result, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation)=0
 
 PatternRecognitionAlgoBaseT (const edm::ParameterSet &conf, edm::ConsumesCollector)
 
virtual ~PatternRecognitionAlgoBaseT ()
 

Static Public Member Functions

static void fillPSetDescription (edm::ParameterSetDescription &iDesc)
 

Private Member Functions

void calculateDistanceToHigher (const TILES &, const int layerId, const std::vector< std::pair< int, int >> &)
 
void calculateLocalDensity (const TILES &, const int layerId, const std::vector< std::pair< int, int >> &)
 
void dumpClusters (const TILES &tiles, const std::vector< std::pair< int, int >> &layerIdx2layerandSoa, const int) const
 
void dumpTiles (const TILES &) const
 
void dumpTracksters (const std::vector< std::pair< int, int >> &layerIdx2layerandSoa, const int, const std::vector< Trackster > &) const
 
int findAndAssignTracksters (const TILES &, const std::vector< std::pair< int, int >> &)
 
void reset ()
 

Private Attributes

edm::ESGetToken< CaloGeometry, CaloGeometryRecordcaloGeomToken_
 
std::vector< ClustersOnLayerclusters_
 
const double criticalDensity_
 
const double criticalEtaPhiDistance_
 
const double criticalSelfDensity_
 
const double criticalXYDistance_
 
const int criticalZDistanceLyr_
 
const double densityEtaPhiDistanceSqr_
 
const bool densityOnSameLayer_
 
const int densitySiblingLayers_
 
const double densityXYDistanceSqr_
 
const std::string eidInputName_
 
const float eidMinClusterEnergy_
 
const int eidNClusters_
 
const int eidNLayers_
 
const std::string eidOutputNameEnergy_
 
const std::string eidOutputNameId_
 
tensorflow::Session * eidSession_
 
const std::vector< int > filter_on_categories_
 
const double kernelDensityFactor_
 
std::vector< float > layersPosZ_
 
const int minNumLayerCluster_
 
const bool nearestHigherOnSameLayer_
 
const double outlierMultiplier_
 
const bool rescaleDensityByZ_
 
hgcal::RecHitTools rhtools_
 
const bool useAbsoluteProjectiveScale_
 
const bool useClusterDimensionXY_
 

Static Private Attributes

static const int eidNFeatures_ = 3
 

Additional Inherited Members

- Protected Attributes inherited from ticl::PatternRecognitionAlgoBaseT< TILES >
int algo_verbosity_
 

Detailed Description

template<typename TILES>
class ticl::PatternRecognitionbyCLUE3D< TILES >

Definition at line 12 of file PatternRecognitionbyCLUE3D.h.

Constructor & Destructor Documentation

◆ PatternRecognitionbyCLUE3D()

template<typename TILES >
PatternRecognitionbyCLUE3D::PatternRecognitionbyCLUE3D ( const edm::ParameterSet conf,
edm::ConsumesCollector  iC 
)

Definition at line 21 of file PatternRecognitionbyCLUE3D.cc.

24  criticalDensity_(conf.getParameter<double>("criticalDensity")),
25  criticalSelfDensity_(conf.getParameter<double>("criticalSelfDensity")),
26  densitySiblingLayers_(conf.getParameter<int>("densitySiblingLayers")),
27  densityEtaPhiDistanceSqr_(conf.getParameter<double>("densityEtaPhiDistanceSqr")),
28  densityXYDistanceSqr_(conf.getParameter<double>("densityXYDistanceSqr")),
29  kernelDensityFactor_(conf.getParameter<double>("kernelDensityFactor")),
30  densityOnSameLayer_(conf.getParameter<bool>("densityOnSameLayer")),
31  nearestHigherOnSameLayer_(conf.getParameter<bool>("nearestHigherOnSameLayer")),
32  useAbsoluteProjectiveScale_(conf.getParameter<bool>("useAbsoluteProjectiveScale")),
33  useClusterDimensionXY_(conf.getParameter<bool>("useClusterDimensionXY")),
34  rescaleDensityByZ_(conf.getParameter<bool>("rescaleDensityByZ")),
35  criticalEtaPhiDistance_(conf.getParameter<double>("criticalEtaPhiDistance")),
36  criticalXYDistance_(conf.getParameter<double>("criticalXYDistance")),
37  criticalZDistanceLyr_(conf.getParameter<int>("criticalZDistanceLyr")),
38  outlierMultiplier_(conf.getParameter<double>("outlierMultiplier")),
39  minNumLayerCluster_(conf.getParameter<int>("minNumLayerCluster")),
40  eidInputName_(conf.getParameter<std::string>("eid_input_name")),
41  eidOutputNameEnergy_(conf.getParameter<std::string>("eid_output_name_energy")),
42  eidOutputNameId_(conf.getParameter<std::string>("eid_output_name_id")),
43  eidMinClusterEnergy_(conf.getParameter<double>("eid_min_cluster_energy")),
44  eidNLayers_(conf.getParameter<int>("eid_n_layers")),
45  eidNClusters_(conf.getParameter<int>("eid_n_clusters")){};
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_

◆ ~PatternRecognitionbyCLUE3D()

template<typename TILES >
ticl::PatternRecognitionbyCLUE3D< TILES >::~PatternRecognitionbyCLUE3D ( )
overridedefault

Member Function Documentation

◆ calculateDistanceToHigher()

template<typename TILES >
void PatternRecognitionbyCLUE3D::calculateDistanceToHigher ( const TILES &  tiles,
const int  layerId,
const std::vector< std::pair< int, int >> &  layerIdx2layerandSoa 
)
private

Definition at line 648 of file PatternRecognitionbyCLUE3D.cc.

References funct::abs(), ticl::Advanced, HLT_2022v15_cff::delta_phi, reco::deltaPhi(), reco::deltaR2(), mps_fire::i, LEDCalibrationChannels::ieta, LEDCalibrationChannels::iphi, SiStripPI::max, allConversions_cfi::maxDelta, SiStripPI::min, HLT_2022v15_cff::minLayer, L1TMuonDQMOffline_cfi::nEtaBins, ecaldqm::binning::nPhiBins, hltrates_dqm_sourceclient-live_cfg::offset, trackingPOGFilters_cfi::phiWindow, and mathSSE::sqrt().

649  {
650  constexpr int nEtaBin = TILES::constants_type_t::nEtaBins;
651  constexpr int nPhiBin = TILES::constants_type_t::nPhiBins;
652  auto &clustersOnLayer = clusters_[layerId];
653  unsigned int numberOfClusters = clustersOnLayer.x.size();
654 
655  auto distanceSqr = [](float r0, float r1, float phi0, float phi1) -> float {
656  auto delta_phi = reco::deltaPhi(phi0, phi1);
657  return (r0 - r1) * (r0 - r1) + r1 * r1 * delta_phi * delta_phi;
658  };
659 
660  for (unsigned int i = 0; i < numberOfClusters; i++) {
662  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
663  << "Starting searching nearestHigher on " << layerId << " with rho: " << clustersOnLayer.rho[i]
664  << " at eta, phi: " << tiles[layerId].etaBin(clustersOnLayer.eta[i]) << ", "
665  << tiles[layerId].phiBin(clustersOnLayer.phi[i]);
666  }
667  // We need to partition the two sides of the HGCAL detector
668  auto lastLayerPerSide = static_cast<int>(rhtools_.lastLayer(false));
669  int minLayer = 0;
670  int maxLayer = 2 * lastLayerPerSide - 1;
671  if (layerId < lastLayerPerSide) {
673  maxLayer = std::min(layerId + densitySiblingLayers_, lastLayerPerSide - 1);
674  } else {
675  minLayer = std::max(layerId - densitySiblingLayers_, lastLayerPerSide + 1);
676  maxLayer = std::min(layerId + densitySiblingLayers_, maxLayer);
677  }
678  constexpr float maxDelta = std::numeric_limits<float>::max();
679  float i_delta = maxDelta;
680  std::pair<int, int> i_nearestHigher(-1, -1);
681  std::pair<float, int> nearest_distances(maxDelta, std::numeric_limits<int>::max());
682  for (int currentLayer = minLayer; currentLayer <= maxLayer; currentLayer++) {
683  if (!nearestHigherOnSameLayer_ && (layerId == currentLayer))
684  continue;
685  const auto &tileOnLayer = tiles[currentLayer];
686  int etaWindow = 1;
687  int phiWindow = 1;
688  int etaBinMin = std::max(tileOnLayer.etaBin(clustersOnLayer.eta[i]) - etaWindow, 0);
689  int etaBinMax = std::min(tileOnLayer.etaBin(clustersOnLayer.eta[i]) + etaWindow, nEtaBin);
690  int phiBinMin = tileOnLayer.phiBin(clustersOnLayer.phi[i]) - phiWindow;
691  int phiBinMax = tileOnLayer.phiBin(clustersOnLayer.phi[i]) + phiWindow;
692  for (int ieta = etaBinMin; ieta <= etaBinMax; ++ieta) {
693  auto offset = ieta * nPhiBin;
694  for (int iphi_it = phiBinMin; iphi_it <= phiBinMax; ++iphi_it) {
695  int iphi = ((iphi_it % nPhiBin + nPhiBin) % nPhiBin);
697  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
698  << "Searching nearestHigher on " << currentLayer << " eta, phi: " << ieta << ", " << iphi_it << " "
699  << iphi << " " << offset << " " << (offset + iphi);
700  }
701  for (auto otherClusterIdx : tileOnLayer[offset + iphi]) {
702  auto const &layerandSoa = layerIdx2layerandSoa[otherClusterIdx];
703  // Skip masked layer clusters
704  if ((layerandSoa.first == -1) && (layerandSoa.second == -1))
705  continue;
706  auto const &clustersOnOtherLayer = clusters_[layerandSoa.first];
707  auto dist = maxDelta;
708  auto dist_transverse = maxDelta;
709  int dist_layers = std::abs(layerandSoa.first - layerId);
711  dist_transverse = distanceSqr(clustersOnLayer.r_over_absz[i] * clustersOnLayer.z[i],
712  clustersOnOtherLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[i],
713  clustersOnLayer.phi[i],
714  clustersOnOtherLayer.phi[layerandSoa.second]);
715  // Add Z-scale to the final distance
716  dist = dist_transverse;
717  } else {
718  dist = reco::deltaR2(clustersOnLayer.eta[i],
719  clustersOnLayer.phi[i],
720  clustersOnOtherLayer.eta[layerandSoa.second],
721  clustersOnOtherLayer.phi[layerandSoa.second]);
722  dist_transverse = dist;
723  }
724  bool foundHigher = (clustersOnOtherLayer.rho[layerandSoa.second] > clustersOnLayer.rho[i]) ||
725  (clustersOnOtherLayer.rho[layerandSoa.second] == clustersOnLayer.rho[i] &&
726  clustersOnOtherLayer.layerClusterOriginalIdx[layerandSoa.second] >
727  clustersOnLayer.layerClusterOriginalIdx[i]);
729  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
730  << "Searching nearestHigher on " << currentLayer
731  << " with rho: " << clustersOnOtherLayer.rho[layerandSoa.second]
732  << " on layerIdxInSOA: " << layerandSoa.first << ", " << layerandSoa.second
733  << " with distance: " << sqrt(dist) << " foundHigher: " << foundHigher;
734  }
735  if (foundHigher && dist <= i_delta) {
736  // update i_delta
737  i_delta = dist;
738  nearest_distances = std::make_pair(sqrt(dist_transverse), dist_layers);
739  // update i_nearestHigher
740  i_nearestHigher = layerandSoa;
741  }
742  } // End of loop on clusters
743  } // End of loop on phi bins
744  } // End of loop on eta bins
745  } // End of loop on layers
746 
747  bool foundNearestInFiducialVolume = (i_delta != maxDelta);
749  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
750  << "i_delta: " << i_delta << " passed: " << foundNearestInFiducialVolume << " " << i_nearestHigher.first
751  << " " << i_nearestHigher.second << " distances: " << nearest_distances.first << ", "
752  << nearest_distances.second;
753  }
754  if (foundNearestInFiducialVolume) {
755  clustersOnLayer.delta[i] = nearest_distances;
756  clustersOnLayer.nearestHigher[i] = i_nearestHigher;
757  } else {
758  // otherwise delta is guaranteed to be larger outlierDeltaFactor_*delta_c
759  // we can safely maximize delta to be maxDelta
760  clustersOnLayer.delta[i] = std::make_pair(maxDelta, std::numeric_limits<int>::max());
761  clustersOnLayer.nearestHigher[i] = {-1, -1};
762  }
763  } // End of loop on clusters
764 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
Log< level::Info, true > LogVerbatim
std::vector< ClustersOnLayer > clusters_
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
unsigned int lastLayer(bool nose=false) const
Definition: RecHitTools.h:79

◆ calculateLocalDensity()

template<typename TILES >
void PatternRecognitionbyCLUE3D::calculateLocalDensity ( const TILES &  tiles,
const int  layerId,
const std::vector< std::pair< int, int >> &  layerIdx2layerandSoa 
)
private

Definition at line 493 of file PatternRecognitionbyCLUE3D.cc.

References funct::abs(), ticl::Advanced, HLT_2022v15_cff::delta_phi, reco::deltaPhi(), reco::deltaR2(), f, mps_fire::i, LEDCalibrationChannels::ieta, if(), LEDCalibrationChannels::iphi, SiStripPI::max, SiStripPI::min, HLT_2022v15_cff::minLayer, L1TMuonDQMOffline_cfi::nEtaBins, ecaldqm::binning::nPhiBins, hltrates_dqm_sourceclient-live_cfg::offset, trackingPOGFilters_cfi::phiWindow, mathSSE::sqrt(), testProducerWithPsetDescEmpty_cfi::y1, and testProducerWithPsetDescEmpty_cfi::y2.

494  {
495  constexpr int nEtaBin = TILES::constants_type_t::nEtaBins;
496  constexpr int nPhiBin = TILES::constants_type_t::nPhiBins;
497  auto &clustersOnLayer = clusters_[layerId];
498  unsigned int numberOfClusters = clustersOnLayer.x.size();
499 
500  auto isReachable = [](float r0, float r1, float phi0, float phi1, float delta_sqr) -> bool {
501  auto delta_phi = reco::deltaPhi(phi0, phi1);
502  return (r0 - r1) * (r0 - r1) + r1 * r1 * delta_phi * delta_phi < delta_sqr;
503  };
504  auto distance_debug = [&](float x1, float x2, float y1, float y2) -> float {
505  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
506  };
507 
508  for (unsigned int i = 0; i < numberOfClusters; i++) {
509  // We need to partition the two sides of the HGCAL detector
510  auto lastLayerPerSide = static_cast<int>(rhtools_.lastLayer(false));
511  int minLayer = 0;
512  int maxLayer = 2 * lastLayerPerSide - 1;
513  if (layerId < lastLayerPerSide) {
515  maxLayer = std::min(layerId + densitySiblingLayers_, lastLayerPerSide - 1);
516  } else {
517  minLayer = std::max(layerId - densitySiblingLayers_, lastLayerPerSide);
518  maxLayer = std::min(layerId + densitySiblingLayers_, maxLayer);
519  }
520  float deltaLayersZ = std::abs(layersPosZ_[maxLayer % lastLayerPerSide] - layersPosZ_[minLayer % lastLayerPerSide]);
521 
522  for (int currentLayer = minLayer; currentLayer <= maxLayer; currentLayer++) {
524  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "RefLayer: " << layerId << " SoaIDX: " << i;
525  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "NextLayer: " << currentLayer;
526  }
527  const auto &tileOnLayer = tiles[currentLayer];
528  bool onSameLayer = (currentLayer == layerId);
530  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "onSameLayer: " << onSameLayer;
531  }
532  const int etaWindow = 2;
533  const int phiWindow = 2;
534  int etaBinMin = std::max(tileOnLayer.etaBin(clustersOnLayer.eta[i]) - etaWindow, 0);
535  int etaBinMax = std::min(tileOnLayer.etaBin(clustersOnLayer.eta[i]) + etaWindow, nEtaBin);
536  int phiBinMin = tileOnLayer.phiBin(clustersOnLayer.phi[i]) - phiWindow;
537  int phiBinMax = tileOnLayer.phiBin(clustersOnLayer.phi[i]) + phiWindow;
539  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "eta: " << clustersOnLayer.eta[i];
540  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "phi: " << clustersOnLayer.phi[i];
541  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "etaBinMin: " << etaBinMin << ", etaBinMax: " << etaBinMax;
542  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "phiBinMin: " << phiBinMin << ", phiBinMax: " << phiBinMax;
543  }
544  for (int ieta = etaBinMin; ieta <= etaBinMax; ++ieta) {
545  auto offset = ieta * nPhiBin;
547  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "offset: " << offset;
548  }
549  for (int iphi_it = phiBinMin; iphi_it <= phiBinMax; ++iphi_it) {
550  int iphi = ((iphi_it % nPhiBin + nPhiBin) % nPhiBin);
552  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "iphi: " << iphi;
553  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
554  << "Entries in tileBin: " << tileOnLayer[offset + iphi].size();
555  }
556  for (auto otherClusterIdx : tileOnLayer[offset + iphi]) {
557  auto const &layerandSoa = layerIdx2layerandSoa[otherClusterIdx];
558  // Skip masked layer clusters
559  if ((layerandSoa.first == -1) && (layerandSoa.second == -1)) {
561  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Skipping masked layerIdx " << otherClusterIdx;
562  }
563  continue;
564  }
565  auto const &clustersLayer = clusters_[layerandSoa.first];
567  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
568  << "OtherLayer: " << layerandSoa.first << " SoaIDX: " << layerandSoa.second;
569  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "OtherEta: " << clustersLayer.eta[layerandSoa.second];
570  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "OtherPhi: " << clustersLayer.phi[layerandSoa.second];
571  }
572  bool reachable = false;
575  reachable = isReachable(clustersOnLayer.r_over_absz[i] * clustersOnLayer.z[i],
576  clustersLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[i],
577  clustersOnLayer.phi[i],
578  clustersLayer.phi[layerandSoa.second],
579  clustersOnLayer.radius[i] * clustersOnLayer.radius[i]);
580  } else {
581  // Still differentiate between silicon and Scintillator.
582  // Silicon has yet to be studied further.
583  if (clustersOnLayer.isSilicon[i]) {
584  reachable = isReachable(clustersOnLayer.r_over_absz[i] * clustersOnLayer.z[i],
585  clustersLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[i],
586  clustersOnLayer.phi[i],
587  clustersLayer.phi[layerandSoa.second],
589  } else {
590  reachable = isReachable(clustersOnLayer.r_over_absz[i] * clustersOnLayer.z[i],
591  clustersLayer.r_over_absz[layerandSoa.second] * clustersOnLayer.z[i],
592  clustersOnLayer.phi[i],
593  clustersLayer.phi[layerandSoa.second],
594  clustersOnLayer.radius[i] * clustersOnLayer.radius[i]);
595  }
596  }
597  } else {
598  reachable = (reco::deltaR2(clustersOnLayer.eta[i],
599  clustersOnLayer.phi[i],
600  clustersLayer.eta[layerandSoa.second],
601  clustersLayer.phi[layerandSoa.second]) < densityEtaPhiDistanceSqr_);
602  }
604  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Distance[eta,phi]: "
605  << reco::deltaR2(clustersOnLayer.eta[i],
606  clustersOnLayer.phi[i],
607  clustersLayer.eta[layerandSoa.second],
608  clustersLayer.phi[layerandSoa.second]);
609  auto dist = distance_debug(
610  clustersOnLayer.r_over_absz[i],
611  clustersLayer.r_over_absz[layerandSoa.second],
612  clustersOnLayer.r_over_absz[i] * std::abs(clustersOnLayer.phi[i]),
613  clustersLayer.r_over_absz[layerandSoa.second] * std::abs(clustersLayer.phi[layerandSoa.second]));
614  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Distance[cm]: " << (dist * clustersOnLayer.z[i]);
615  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
616  << "Energy Other: " << clustersLayer.energy[layerandSoa.second];
617  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Cluster radius: " << clustersOnLayer.radius[i];
618  }
619  if (reachable) {
620  float factor_same_layer_different_cluster = (onSameLayer && !densityOnSameLayer_) ? 0.f : 1.f;
621  auto energyToAdd = (clustersOnLayer.layerClusterOriginalIdx[i] == otherClusterIdx
622  ? 1.f
623  : kernelDensityFactor_ * factor_same_layer_different_cluster) *
624  clustersLayer.energy[layerandSoa.second];
625  clustersOnLayer.rho[i] += energyToAdd;
626  clustersOnLayer.z_extension[i] = deltaLayersZ;
628  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
629  << "Adding " << energyToAdd << " partial " << clustersOnLayer.rho[i];
630  }
631  }
632  } // end of loop on possible compatible clusters
633  } // end of loop over phi-bin region
634  } // end of loop over eta-bin region
635  } // end of loop on the sibling layers
636  if (rescaleDensityByZ_) {
638  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
639  << "Rescaling original density: " << clustersOnLayer.rho[i] << " by Z: " << deltaLayersZ
640  << " to final density/cm: " << clustersOnLayer.rho[i] / deltaLayersZ;
641  }
642  clustersOnLayer.rho[i] /= deltaLayersZ;
643  }
644  } // end of loop over clusters on this layer
645 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
Log< level::Info, true > LogVerbatim
std::vector< ClustersOnLayer > clusters_
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
unsigned int lastLayer(bool nose=false) const
Definition: RecHitTools.h:79

◆ dumpClusters()

template<typename TILES >
void PatternRecognitionbyCLUE3D::dumpClusters ( const TILES &  tiles,
const std::vector< std::pair< int, int >> &  layerIdx2layerandSoa,
const int  eventNumber 
) const
private

Definition at line 105 of file PatternRecognitionbyCLUE3D.cc.

References ticl::Advanced, alignBH_cfg::fixed, EgammaValidation_cff::num, and findQualityFiles::v.

107  {
109  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "[evt, lyr, Seed, x, y, z, r/|z|, eta, phi, "
110  "etab, phib, cells, enrgy, e/rho, rho, z_ext, "
111  " dlt_tr, dlt_lyr, "
112  " nestHL, nestHSoaIdx, radius, clIdx, lClOrigIdx, SOAidx";
113  }
114 
115  for (unsigned int layer = 0; layer < clusters_.size(); layer++) {
116  auto const &thisLayer = clusters_[layer];
117  int num = 0;
118  for (auto v : thisLayer.x) {
120  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
121  << std::setw(4) << eventNumber << ", " << std::setw(3) << layer << ", " << std::setw(4)
122  << thisLayer.isSeed[num] << ", " << std::setprecision(3) << std::fixed << v << ", " << thisLayer.y[num]
123  << ", " << thisLayer.z[num] << ", " << thisLayer.r_over_absz[num] << ", " << thisLayer.eta[num] << ", "
124  << thisLayer.phi[num] << ", " << std::setw(5) << tiles[layer].etaBin(thisLayer.eta[num]) << ", "
125  << std::setw(5) << tiles[layer].phiBin(thisLayer.phi[num]) << ", " << std::setw(4) << thisLayer.cells[num]
126  << ", " << std::setprecision(3) << thisLayer.energy[num] << ", "
127  << (thisLayer.energy[num] / thisLayer.rho[num]) << ", " << thisLayer.rho[num] << ", "
128  << thisLayer.z_extension[num] << ", " << std::scientific << thisLayer.delta[num].first << ", "
129  << std::setw(10) << thisLayer.delta[num].second << ", " << std::setw(5)
130  << thisLayer.nearestHigher[num].first << ", " << std::setw(10) << thisLayer.nearestHigher[num].second
131  << ", " << std::defaultfloat << std::setprecision(3) << thisLayer.radius[num] << ", " << std::setw(5)
132  << thisLayer.clusterIndex[num] << ", " << std::setw(4) << thisLayer.layerClusterOriginalIdx[num] << ", "
133  << std::setw(4) << num << ", ClusterInfo";
134  }
135  ++num;
136  }
137  }
138  for (unsigned int lcIdx = 0; lcIdx < layerIdx2layerandSoa.size(); lcIdx++) {
139  auto const &layerandSoa = layerIdx2layerandSoa[lcIdx];
140  // Skip masked layer clusters
141  if ((layerandSoa.first == -1) && (layerandSoa.second == -1))
142  continue;
144  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
145  << "lcIdx: " << lcIdx << " on Layer: " << layerandSoa.first << " SOA: " << layerandSoa.second;
146  }
147  }
148 }
Log< level::Info, true > LogVerbatim
std::vector< ClustersOnLayer > clusters_
constexpr std::array< uint8_t, layerIndexSize > layer

◆ dumpTiles()

template<typename TILES >
void PatternRecognitionbyCLUE3D::dumpTiles ( const TILES &  tiles) const
private

Definition at line 48 of file PatternRecognitionbyCLUE3D.cc.

References ticl::Advanced, relativeConstraints::empty, LEDCalibrationChannels::ieta, LEDCalibrationChannels::iphi, L1TMuonDQMOffline_cfi::nEtaBins, ecaldqm::binning::nPhiBins, and hltrates_dqm_sourceclient-live_cfg::offset.

48  {
49  constexpr int nEtaBin = TILES::constants_type_t::nEtaBins;
50  constexpr int nPhiBin = TILES::constants_type_t::nPhiBins;
51  auto lastLayerPerSide = static_cast<int>(rhtools_.lastLayer(false));
52  int maxLayer = 2 * lastLayerPerSide - 1;
53  for (int layer = 0; layer <= maxLayer; layer++) {
54  for (int ieta = 0; ieta < nEtaBin; ieta++) {
55  auto offset = ieta * nPhiBin;
56  for (int phi = 0; phi < nPhiBin; phi++) {
57  int iphi = ((phi % nPhiBin + nPhiBin) % nPhiBin);
58  if (!tiles[layer][offset + iphi].empty()) {
60  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Layer: " << layer << " ieta: " << ieta << " phi: " << phi
61  << " " << tiles[layer][offset + iphi].size();
62  }
63  }
64  }
65  }
66  }
67 }
Log< level::Info, true > LogVerbatim
constexpr std::array< uint8_t, layerIndexSize > layer
unsigned int lastLayer(bool nose=false) const
Definition: RecHitTools.h:79

◆ dumpTracksters()

template<typename TILES >
void PatternRecognitionbyCLUE3D::dumpTracksters ( const std::vector< std::pair< int, int >> &  layerIdx2layerandSoa,
const int  eventNumber,
const std::vector< Trackster > &  tracksters 
) const
private

Definition at line 70 of file PatternRecognitionbyCLUE3D.cc.

References ticl::Advanced, ticl::Trackster::charged_hadron, ticl::Trackster::electron, ticl::Trackster::neutral_hadron, EgammaValidation_cff::num, ticl::Trackster::photon, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, and findQualityFiles::v.

72  {
74  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
75  << "[evt, tracksterId, cells, prob_photon, prob_ele, prob_chad, prob_nhad, layer_i, x_i, y_i, eta_i, phi_i, "
76  "energy_i, radius_i, rho_i, z_extension, delta_tr, delta_lyr, isSeed_i";
77  }
78 
79  int num = 0;
80  const std::string sep(", ");
81  for (auto const &t : tracksters) {
82  for (auto v : t.vertices()) {
83  auto [lyrIdx, soaIdx] = layerIdx2layerandSoa[v];
84  auto const &thisLayer = clusters_[lyrIdx];
86  edm::LogVerbatim("PatternRecognitionbyCLUE3D_NTP")
87  << std::setw(4) << eventNumber << sep << std::setw(4) << num << sep << std::setw(4) << t.vertices().size()
88  << sep << std::setw(8) << t.id_probability(ticl::Trackster::ParticleType::photon) << sep << std::setw(8)
89  << t.id_probability(ticl::Trackster::ParticleType::electron) << sep << std::setw(8)
90  << t.id_probability(ticl::Trackster::ParticleType::charged_hadron) << sep << std::setw(8)
91  << t.id_probability(ticl::Trackster::ParticleType::neutral_hadron) << sep << std::setw(4) << lyrIdx << sep
92  << std::setw(10) << thisLayer.x[soaIdx] << sep << std::setw(10) << thisLayer.y[soaIdx] << sep
93  << std::setw(10) << thisLayer.eta[soaIdx] << sep << std::setw(10) << thisLayer.phi[soaIdx] << sep
94  << std::setw(10) << thisLayer.energy[soaIdx] << sep << std::setw(10) << thisLayer.radius[soaIdx] << sep
95  << std::setw(10) << thisLayer.rho[soaIdx] << sep << std::setw(10) << thisLayer.z_extension[soaIdx] << sep
96  << std::setw(10) << thisLayer.delta[soaIdx].first << sep << std::setw(10) << thisLayer.delta[soaIdx].second
97  << sep << std::setw(4) << thisLayer.isSeed[soaIdx];
98  }
99  }
100  num++;
101  }
102 }
Log< level::Info, true > LogVerbatim
std::vector< ClustersOnLayer > clusters_

◆ energyRegressionAndID()

template<typename TILES >
void PatternRecognitionbyCLUE3D::energyRegressionAndID ( const std::vector< reco::CaloCluster > &  layerClusters,
const tensorflow::Session *  eidSession,
std::vector< Trackster > &  result 
)

Definition at line 353 of file PatternRecognitionbyCLUE3D.cc.

References a, funct::abs(), b, data, HCALHighEnergyHPDFilter_cfi::energy, reco::CaloCluster::energy(), reco::CaloCluster::eta(), f, lowptgsfeleseed::features(), dqmMemoryStats::float, reco::CaloCluster::hitsAndFractions(), mps_fire::i, input, crabTemplate::inputList, createfilelist::int, dqmiolumiharvest::j, dqmdumpme::k, cmsLHEtoEOSManager::l, hltEgammaHGCALIDVarsL1Seeded_cfi::layerClusters, jetsAK4_CHS_cff::outputNames, PatBasicFWLiteJetAnalyzer_Selector_cfg::outputs, reco::CaloCluster::phi(), tensorflow::run(), jetsAK4_CHS_cff::sort, bphysicsOniaDQM_cfi::vertex, ticl::Trackster::vertex_multiplicity(), AlignmentTracksFromVertexSelector_cfi::vertices, and ticl::Trackster::vertices().

355  {
356  // Energy regression and particle identification strategy:
357  //
358  // 1. Set default values for regressed energy and particle id for each trackster.
359  // 2. Store indices of tracksters whose total sum of cluster energies is above the
360  // eidMinClusterEnergy_ (GeV) treshold. Inference is not applied for soft tracksters.
361  // 3. When no trackster passes the selection, return.
362  // 4. Create input and output tensors. The batch dimension is determined by the number of
363  // selected tracksters.
364  // 5. Fill input tensors with layer cluster features. Per layer, clusters are ordered descending
365  // by energy. Given that tensor data is contiguous in memory, we can use pointer arithmetic to
366  // fill values, even with batching.
367  // 6. Zero-fill features for empty clusters in each layer.
368  // 7. Batched inference.
369  // 8. Assign the regressed energy and id probabilities to each trackster.
370  //
371  // Indices used throughout this method:
372  // i -> batch element / trackster
373  // j -> layer
374  // k -> cluster
375  // l -> feature
376 
377  // set default values per trackster, determine if the cluster energy threshold is passed,
378  // and store indices of hard tracksters
379  std::vector<int> tracksterIndices;
380  for (int i = 0; i < static_cast<int>(tracksters.size()); i++) {
381  // calculate the cluster energy sum (2)
382  // note: after the loop, sumClusterEnergy might be just above the threshold which is enough to
383  // decide whether to run inference for the trackster or not
384  float sumClusterEnergy = 0.;
385  for (const unsigned int &vertex : tracksters[i].vertices()) {
386  sumClusterEnergy += static_cast<float>(layerClusters[vertex].energy());
387  // there might be many clusters, so try to stop early
388  if (sumClusterEnergy >= eidMinClusterEnergy_) {
389  // set default values (1)
390  tracksters[i].setRegressedEnergy(0.f);
391  tracksters[i].zeroProbabilities();
392  tracksterIndices.push_back(i);
393  break;
394  }
395  }
396  }
397 
398  // do nothing when no trackster passes the selection (3)
399  int batchSize = static_cast<int>(tracksterIndices.size());
400  if (batchSize == 0) {
401  return;
402  }
403 
404  // create input and output tensors (4)
405  tensorflow::TensorShape shape({batchSize, eidNLayers_, eidNClusters_, eidNFeatures_});
406  tensorflow::Tensor input(tensorflow::DT_FLOAT, shape);
408 
409  std::vector<tensorflow::Tensor> outputs;
410  std::vector<std::string> outputNames;
411  if (!eidOutputNameEnergy_.empty()) {
413  }
414  if (!eidOutputNameId_.empty()) {
415  outputNames.push_back(eidOutputNameId_);
416  }
417 
418  // fill input tensor (5)
419  for (int i = 0; i < batchSize; i++) {
420  const Trackster &trackster = tracksters[tracksterIndices[i]];
421 
422  // per layer, we only consider the first eidNClusters_ clusters in terms of energy, so in order
423  // to avoid creating large / nested structures to do the sorting for an unknown number of total
424  // clusters, create a sorted list of layer cluster indices to keep track of the filled clusters
425  std::vector<int> clusterIndices(trackster.vertices().size());
426  for (int k = 0; k < (int)trackster.vertices().size(); k++) {
427  clusterIndices[k] = k;
428  }
429  sort(clusterIndices.begin(), clusterIndices.end(), [&layerClusters, &trackster](const int &a, const int &b) {
430  return layerClusters[trackster.vertices(a)].energy() > layerClusters[trackster.vertices(b)].energy();
431  });
432 
433  // keep track of the number of seen clusters per layer
434  std::vector<int> seenClusters(eidNLayers_);
435 
436  // loop through clusters by descending energy
437  for (const int &k : clusterIndices) {
438  // get features per layer and cluster and store the values directly in the input tensor
439  const reco::CaloCluster &cluster = layerClusters[trackster.vertices(k)];
440  int j = rhtools_.getLayerWithOffset(cluster.hitsAndFractions()[0].first) - 1;
441  if (j < eidNLayers_ && seenClusters[j] < eidNClusters_) {
442  // get the pointer to the first feature value for the current batch, layer and cluster
443  float *features = &input.tensor<float, 4>()(i, j, seenClusters[j], 0);
444 
445  // fill features
446  *(features++) = float(cluster.energy() / float(trackster.vertex_multiplicity(k)));
447  *(features++) = float(std::abs(cluster.eta()));
448  *(features) = float(cluster.phi());
449 
450  // increment seen clusters
451  seenClusters[j]++;
452  }
453  }
454 
455  // zero-fill features of empty clusters in each layer (6)
456  for (int j = 0; j < eidNLayers_; j++) {
457  for (int k = seenClusters[j]; k < eidNClusters_; k++) {
458  float *features = &input.tensor<float, 4>()(i, j, k, 0);
459  for (int l = 0; l < eidNFeatures_; l++) {
460  *(features++) = 0.f;
461  }
462  }
463  }
464  }
465 
466  // run the inference (7)
467  tensorflow::run(const_cast<tensorflow::Session *>(eidSession), inputList, outputNames, &outputs);
468 
469  // store regressed energy per trackster (8)
470  if (!eidOutputNameEnergy_.empty()) {
471  // get the pointer to the energy tensor, dimension is batch x 1
472  float *energy = outputs[0].flat<float>().data();
473 
474  for (const int &i : tracksterIndices) {
475  tracksters[i].setRegressedEnergy(*(energy++));
476  }
477  }
478 
479  // store id probabilities per trackster (8)
480  if (!eidOutputNameId_.empty()) {
481  // get the pointer to the id probability tensor, dimension is batch x id_probabilities.size()
482  int probsIdx = eidOutputNameEnergy_.empty() ? 0 : 1;
483  float *probs = outputs[probsIdx].flat<float>().data();
484 
485  for (const int &i : tracksterIndices) {
486  tracksters[i].setProbabilities(probs);
487  probs += tracksters[i].id_probabilities().size();
488  }
489  }
490 }
std::vector< NamedTensor > NamedTensorList
Definition: TensorFlow.h:30
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:184
static std::string const input
Definition: EdmProvDump.cc:50
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:213
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
string inputList
Definition: crabTemplate.py:6
double energy() const
cluster energy
Definition: CaloCluster.h:149
std::vector< unsigned int > & vertices()
Definition: Trackster.h:57
std::vector< float > & vertex_multiplicity()
Definition: Trackster.h:58
double b
Definition: hdecay.h:118
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
double a
Definition: hdecay.h:119
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:181
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:365

◆ fillPSetDescription()

template<typename TILES >
void PatternRecognitionbyCLUE3D::fillPSetDescription ( edm::ParameterSetDescription iDesc)
static

Definition at line 837 of file PatternRecognitionbyCLUE3D.cc.

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

837  {
838  iDesc.add<int>("algo_verbosity", 0);
839  iDesc.add<double>("criticalDensity", 4)->setComment("in GeV");
840  iDesc.add<double>("criticalSelfDensity", 0.15 /* roughly 1/(densitySiblingLayers+1) */)
841  ->setComment("Minimum ratio of self_energy/local_density to become a seed.");
842  iDesc.add<int>("densitySiblingLayers", 3)
843  ->setComment(
844  "inclusive, layers to consider while computing local density and searching for nearestHigher higher");
845  iDesc.add<double>("densityEtaPhiDistanceSqr", 0.0008);
846  iDesc.add<double>("densityXYDistanceSqr", 3.24 /*6.76*/)
847  ->setComment("in cm, 2.6*2.6, distance on the transverse plane to consider for local density");
848  iDesc.add<double>("kernelDensityFactor", 0.2)
849  ->setComment("Kernel factor to be applied to other LC while computing the local density");
850  iDesc.add<bool>("densityOnSameLayer", false);
851  iDesc.add<bool>("nearestHigherOnSameLayer", false)
852  ->setComment("Allow the nearestHigher to be located on the same layer");
853  iDesc.add<bool>("useAbsoluteProjectiveScale", true)
854  ->setComment("Express all cuts in terms of r/z*z_0{,phi} projective variables");
855  iDesc.add<bool>("useClusterDimensionXY", false)
856  ->setComment(
857  "Boolean. If true use the estimated cluster radius to determine the cluster compatibility while computing "
858  "the local density");
859  iDesc.add<bool>("rescaleDensityByZ", false)
860  ->setComment(
861  "Rescale local density by the extension of the Z 'volume' explored. The transvere dimension is, at present, "
862  "fixed and factored out.");
863  iDesc.add<double>("criticalEtaPhiDistance", 0.025)
864  ->setComment("Minimal distance in eta,phi space from nearestHigher to become a seed");
865  iDesc.add<double>("criticalXYDistance", 1.8)
866  ->setComment("Minimal distance in cm on the XY plane from nearestHigher to become a seed");
867  iDesc.add<int>("criticalZDistanceLyr", 5)
868  ->setComment("Minimal distance in layers along the Z axis from nearestHigher to become a seed");
869  iDesc.add<double>("outlierMultiplier", 2);
870  iDesc.add<int>("minNumLayerCluster", 2)->setComment("Not Inclusive");
871  iDesc.add<std::string>("eid_input_name", "input");
872  iDesc.add<std::string>("eid_output_name_energy", "output/regressed_energy");
873  iDesc.add<std::string>("eid_output_name_id", "output/id_probabilities");
874  iDesc.add<double>("eid_min_cluster_energy", 1.);
875  iDesc.add<int>("eid_n_layers", 50);
876  iDesc.add<int>("eid_n_clusters", 10);
877 }
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)

◆ findAndAssignTracksters()

template<typename TILES >
int PatternRecognitionbyCLUE3D::findAndAssignTracksters ( const TILES &  tiles,
const std::vector< std::pair< int, int >> &  layerIdx2layerandSoa 
)
private

Definition at line 767 of file PatternRecognitionbyCLUE3D.cc.

References ticl::Advanced, and mps_fire::i.

768  {
769  unsigned int nTracksters = 0;
770 
771  std::vector<std::pair<int, int>> localStack;
772  auto critical_transverse_distance = useAbsoluteProjectiveScale_ ? criticalXYDistance_ : criticalEtaPhiDistance_;
773  // find cluster seeds and outlier
774  for (unsigned int layer = 0; layer < 2 * rhtools_.lastLayer(); layer++) {
775  auto &clustersOnLayer = clusters_[layer];
776  unsigned int numberOfClusters = clustersOnLayer.x.size();
777  for (unsigned int i = 0; i < numberOfClusters; i++) {
778  // initialize clusterIndex
779  clustersOnLayer.clusterIndex[i] = -1;
780  bool isSeed = (clustersOnLayer.delta[i].first > critical_transverse_distance ||
781  clustersOnLayer.delta[i].second > criticalZDistanceLyr_) &&
782  (clustersOnLayer.rho[i] >= criticalDensity_) &&
783  (clustersOnLayer.energy[i] / clustersOnLayer.rho[i] > criticalSelfDensity_);
784  if (!clustersOnLayer.isSilicon[i]) {
785  isSeed = (clustersOnLayer.delta[i].first > clustersOnLayer.radius[i] ||
786  clustersOnLayer.delta[i].second > criticalZDistanceLyr_) &&
787  (clustersOnLayer.rho[i] >= criticalDensity_) &&
788  (clustersOnLayer.energy[i] / clustersOnLayer.rho[i] > criticalSelfDensity_);
789  }
790  bool isOutlier = (clustersOnLayer.delta[i].first > outlierMultiplier_ * critical_transverse_distance) &&
791  (clustersOnLayer.rho[i] < criticalDensity_);
792  if (isSeed) {
794  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
795  << "Found seed on Layer " << layer << " SOAidx: " << i << " assigned ClusterIdx: " << nTracksters;
796  }
797  clustersOnLayer.clusterIndex[i] = nTracksters++;
798  clustersOnLayer.isSeed[i] = true;
799  localStack.emplace_back(layer, i);
800  } else if (!isOutlier) {
801  auto [lyrIdx, soaIdx] = clustersOnLayer.nearestHigher[i];
803  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
804  << "Found follower on Layer " << layer << " SOAidx: " << i << " attached to cluster on layer: " << lyrIdx
805  << " SOAidx: " << soaIdx;
806  }
807  if (lyrIdx >= 0)
808  clusters_[lyrIdx].followers[soaIdx].emplace_back(layer, i);
809  } else {
811  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
812  << "Found Outlier on Layer " << layer << " SOAidx: " << i << " with rho: " << clustersOnLayer.rho[i]
813  << " and delta: " << clustersOnLayer.delta[i].first << ", " << clustersOnLayer.delta[i].second;
814  }
815  }
816  }
817  }
818 
819  // Propagate cluster index
820  while (!localStack.empty()) {
821  auto [lyrIdx, soaIdx] = localStack.back();
822  auto &thisSeed = clusters_[lyrIdx].followers[soaIdx];
823  localStack.pop_back();
824 
825  // loop over followers
826  for (auto [follower_lyrIdx, follower_soaIdx] : thisSeed) {
827  // pass id to a follower
828  clusters_[follower_lyrIdx].clusterIndex[follower_soaIdx] = clusters_[lyrIdx].clusterIndex[soaIdx];
829  // push this follower to localStack
830  localStack.emplace_back(follower_lyrIdx, follower_soaIdx);
831  }
832  }
833  return nTracksters;
834 }
Log< level::Info, true > LogVerbatim
std::vector< ClustersOnLayer > clusters_
constexpr std::array< uint8_t, layerIndexSize > layer
unsigned int lastLayer(bool nose=false) const
Definition: RecHitTools.h:79

◆ makeTracksters()

template<typename TILES >
void PatternRecognitionbyCLUE3D::makeTracksters ( const typename PatternRecognitionAlgoBaseT< TILES >::Inputs input,
std::vector< Trackster > &  result,
std::unordered_map< int, std::vector< int >> &  seedToTracksterAssociation 
)
override

Definition at line 151 of file PatternRecognitionbyCLUE3D.cc.

References funct::abs(), ticl::Advanced, cms::cuda::assert(), ticl::assignPCAtoTracksters(), f, relativeConstraints::geom, edm::EventSetup::getData(), mps_fire::i, input, createfilelist::int, SiStripPI::max, point, reset(), mps_fire::result, mathSSE::sqrt(), makeMuonMisalignmentScenario::sum_x, makeMuonMisalignmentScenario::sum_y, submitPVValidationJobs::t, findQualityFiles::v, and x.

154  {
155  // Protect from events with no seeding regions
156  if (input.regions.empty())
157  return;
158 
159  const int eventNumber = input.ev.eventAuxiliary().event();
161  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "New Event";
162  }
163 
164  edm::EventSetup const &es = input.es;
167 
168  // Assume identical Z-positioning between positive and negative sides.
169  // Also, layers inside the HGCAL geometry start from 1.
170  for (unsigned int i = 0; i < rhtools_.lastLayer(); ++i) {
171  layersPosZ_.push_back(rhtools_.getPositionLayer(i + 1).z());
173  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Layer " << i << " located at Z: " << layersPosZ_.back();
174  }
175  }
176 
177  clusters_.clear();
178  clusters_.resize(2 * rhtools_.lastLayer(false));
179  std::vector<std::pair<int, int>> layerIdx2layerandSoa; //used everywhere also to propagate cluster masking
180 
181  layerIdx2layerandSoa.reserve(input.layerClusters.size());
182  unsigned int layerIdx = 0;
183  for (auto const &lc : input.layerClusters) {
184  if (input.mask[layerIdx] == 0.) {
186  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Skipping masked cluster: " << layerIdx;
187  }
188  layerIdx2layerandSoa.emplace_back(-1, -1);
189  layerIdx++;
190  continue;
191  }
192  const auto firstHitDetId = lc.hitsAndFractions()[0].first;
193  int layer = rhtools_.getLayerWithOffset(firstHitDetId) - 1 +
194  rhtools_.lastLayer(false) * ((rhtools_.zside(firstHitDetId) + 1) >> 1);
195  assert(layer >= 0);
196  auto detId = lc.hitsAndFractions()[0].first;
197 
198  layerIdx2layerandSoa.emplace_back(layer, clusters_[layer].x.size());
199  float sum_x = 0.;
200  float sum_y = 0.;
201  float sum_sqr_x = 0.;
202  float sum_sqr_y = 0.;
203  float ref_x = lc.x();
204  float ref_y = lc.y();
205  float invClsize = 1. / lc.hitsAndFractions().size();
206  for (auto const &hitsAndFractions : lc.hitsAndFractions()) {
207  auto const &point = rhtools_.getPosition(hitsAndFractions.first);
208  sum_x += point.x() - ref_x;
209  sum_sqr_x += (point.x() - ref_x) * (point.x() - ref_x);
210  sum_y += point.y() - ref_y;
211  sum_sqr_y += (point.y() - ref_y) * (point.y() - ref_y);
212  }
213  // The variance of X for X uniform in circle of radius R is R^2/4,
214  // therefore we multiply the sqrt(var) by 2 to have a rough estimate of the
215  // radius. On the other hand, while averaging the x and y radius, we would
216  // end up dividing by 2. Hence we omit the value here and in the average
217  // below, too.
218  float radius_x = sqrt((sum_sqr_x - (sum_x * sum_x) * invClsize) * invClsize);
219  float radius_y = sqrt((sum_sqr_y - (sum_y * sum_y) * invClsize) * invClsize);
221  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
222  << "cluster rx: " << std::setw(5) << radius_x << ", ry: " << std::setw(5) << radius_y
223  << ", r: " << std::setw(5) << (radius_x + radius_y) << ", cells: " << std::setw(4)
224  << lc.hitsAndFractions().size();
225  }
226 
227  // The case of single cell layer clusters has to be handled differently.
228 
229  if (invClsize == 1.) {
230  // Silicon case
231  if (rhtools_.isSilicon(detId)) {
232  radius_x = radius_y = rhtools_.getRadiusToSide(detId);
234  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Single cell cluster in silicon, rx: " << std::setw(5)
235  << radius_x << ", ry: " << std::setw(5) << radius_y;
236  }
237  } else {
238  auto const &point = rhtools_.getPosition(detId);
239  auto const &eta_phi_window = rhtools_.getScintDEtaDPhi(detId);
240  radius_x = radius_y = point.perp() * eta_phi_window.second;
242  edm::LogVerbatim("PatternRecognitionbyCLUE3D")
243  << "Single cell cluster in scintillator. rx: " << std::setw(5) << radius_x << ", ry: " << std::setw(5)
244  << radius_y << ", eta-span: " << std::setw(5) << eta_phi_window.first << ", phi-span: " << std::setw(5)
245  << eta_phi_window.second;
246  }
247  }
248  }
249  clusters_[layer].x.emplace_back(lc.x());
250  clusters_[layer].y.emplace_back(lc.y());
251  clusters_[layer].z.emplace_back(lc.z());
252  clusters_[layer].r_over_absz.emplace_back(sqrt(lc.x() * lc.x() + lc.y() * lc.y()) / std::abs(lc.z()));
253  clusters_[layer].radius.emplace_back(radius_x + radius_y);
254  clusters_[layer].eta.emplace_back(lc.eta());
255  clusters_[layer].phi.emplace_back(lc.phi());
256  clusters_[layer].cells.push_back(lc.hitsAndFractions().size());
257  clusters_[layer].isSilicon.push_back(rhtools_.isSilicon(detId));
258  clusters_[layer].energy.emplace_back(lc.energy());
259  clusters_[layer].isSeed.push_back(false);
260  clusters_[layer].clusterIndex.emplace_back(-1);
261  clusters_[layer].layerClusterOriginalIdx.emplace_back(layerIdx++);
262  clusters_[layer].nearestHigher.emplace_back(-1, -1);
263  clusters_[layer].rho.emplace_back(0.f);
264  clusters_[layer].z_extension.emplace_back(0.f);
265  clusters_[layer].delta.emplace_back(
267  }
268  for (unsigned int layer = 0; layer < clusters_.size(); layer++) {
269  clusters_[layer].followers.resize(clusters_[layer].x.size());
270  }
271 
272  auto lastLayerPerSide = static_cast<int>(rhtools_.lastLayer(false));
273  int maxLayer = 2 * lastLayerPerSide - 1;
274  std::vector<int> numberOfClustersPerLayer(maxLayer, 0);
275  for (int i = 0; i <= maxLayer; i++) {
276  calculateLocalDensity(input.tiles, i, layerIdx2layerandSoa);
277  }
278  for (int i = 0; i <= maxLayer; i++) {
279  calculateDistanceToHigher(input.tiles, i, layerIdx2layerandSoa);
280  }
281 
282  auto nTracksters = findAndAssignTracksters(input.tiles, layerIdx2layerandSoa);
284  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Reconstructed " << nTracksters << " tracksters" << std::endl;
285  dumpClusters(input.tiles, layerIdx2layerandSoa, eventNumber);
286  }
287 
288  // Build Trackster
289  result.resize(nTracksters);
290 
291  for (unsigned int layer = 0; layer < clusters_.size(); ++layer) {
292  const auto &thisLayer = clusters_[layer];
294  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Examining Layer: " << layer;
295  }
296  for (unsigned int lc = 0; lc < thisLayer.x.size(); ++lc) {
298  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Trackster " << thisLayer.clusterIndex[lc];
299  }
300  if (thisLayer.clusterIndex[lc] >= 0) {
302  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << " adding lcIdx: " << thisLayer.layerClusterOriginalIdx[lc];
303  }
304  result[thisLayer.clusterIndex[lc]].vertices().push_back(thisLayer.layerClusterOriginalIdx[lc]);
305  result[thisLayer.clusterIndex[lc]].vertex_multiplicity().push_back(1);
306  // loop over followers
307  for (auto [follower_lyrIdx, follower_soaIdx] : thisLayer.followers[lc]) {
308  std::array<unsigned int, 2> edge = {
309  {(unsigned int)thisLayer.layerClusterOriginalIdx[lc],
310  (unsigned int)clusters_[follower_lyrIdx].layerClusterOriginalIdx[follower_soaIdx]}};
311  result[thisLayer.clusterIndex[lc]].edges().push_back(edge);
312  }
313  }
314  }
315  }
316 
317  result.erase(
318  std::remove_if(std::begin(result),
319  std::end(result),
320  [&](auto const &v) { return static_cast<int>(v.vertices().size()) < minNumLayerCluster_; }),
321  result.end());
322  result.shrink_to_fit();
323 
325  input.layerClusters,
326  input.layerClustersTime,
327  rhtools_.getPositionLayer(rhtools_.lastLayerEE(false), false).z());
328 
329  // run energy regression and ID
330  energyRegressionAndID(input.layerClusters, input.tfSession, result);
332  for (auto const &t : result) {
333  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Barycenter: " << t.barycenter();
334  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "LCs: " << t.vertices().size();
335  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Energy: " << t.raw_energy();
336  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << "Regressed: " << t.regressed_energy();
337  }
338  }
339 
340  // Dump Tracksters information
342  dumpTracksters(layerIdx2layerandSoa, eventNumber, result);
343  }
344 
345  // Reset internal clusters_ structure of array for next event
346  reset();
348  edm::LogVerbatim("PatternRecognitionbyCLUE3D") << std::endl;
349  }
350 }
Log< level::Info, true > LogVerbatim
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
void energyRegressionAndID(const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result)
T z() const
Definition: PV3DBase.h:61
std::float_t getRadiusToSide(const DetId &) const
Definition: RecHitTools.cc:235
std::vector< ClustersOnLayer > clusters_
std::pair< float, float > getScintDEtaDPhi(const DetId &) const
Definition: RecHitTools.cc:225
assert(be >=bs)
int zside(const DetId &id) const
Definition: RecHitTools.cc:163
void calculateDistanceToHigher(const TILES &, const int layerId, const std::vector< std::pair< int, int >> &)
constexpr std::array< uint8_t, layerIndexSize > layer
static std::string const input
Definition: EdmProvDump.cc:50
void assignPCAtoTracksters(std::vector< Trackster > &, const std::vector< reco::CaloCluster > &, const edm::ValueMap< std::pair< float, float >> &, double, bool energyWeight=true)
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:129
T sqrt(T t)
Definition: SSEVec.h:19
bool isSilicon(const DetId &) const
Definition: RecHitTools.cc:428
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
int findAndAssignTracksters(const TILES &, const std::vector< std::pair< int, int >> &)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
void dumpClusters(const TILES &tiles, const std::vector< std::pair< int, int >> &layerIdx2layerandSoa, const int) const
GlobalPoint getPositionLayer(int layer, bool nose=false) const
Definition: RecHitTools.cc:141
void setGeometry(CaloGeometry const &)
Definition: RecHitTools.cc:68
void calculateLocalDensity(const TILES &, const int layerId, const std::vector< std::pair< int, int >> &)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
unsigned int lastLayerEE(bool nose=false) const
Definition: RecHitTools.h:75
void dumpTracksters(const std::vector< std::pair< int, int >> &layerIdx2layerandSoa, const int, const std::vector< Trackster > &) const
unsigned int lastLayer(bool nose=false) const
Definition: RecHitTools.h:79
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:365

◆ reset()

template<typename TILES >
void ticl::PatternRecognitionbyCLUE3D< TILES >::reset ( void  )
inlineprivate

Definition at line 93 of file PatternRecognitionbyCLUE3D.h.

References c, and ticl::PatternRecognitionbyCLUE3D< TILES >::clusters_.

93  {
94  for (auto& c : clusters_) {
95  c.clear();
96  c.shrink_to_fit();
97  }
98  }
std::vector< ClustersOnLayer > clusters_

Member Data Documentation

◆ caloGeomToken_

template<typename TILES >
edm::ESGetToken<CaloGeometry, CaloGeometryRecord> ticl::PatternRecognitionbyCLUE3D< TILES >::caloGeomToken_
private

Definition at line 113 of file PatternRecognitionbyCLUE3D.h.

◆ clusters_

template<typename TILES >
std::vector<ClustersOnLayer> ticl::PatternRecognitionbyCLUE3D< TILES >::clusters_
private

◆ criticalDensity_

template<typename TILES >
const double ticl::PatternRecognitionbyCLUE3D< TILES >::criticalDensity_
private

Definition at line 114 of file PatternRecognitionbyCLUE3D.h.

◆ criticalEtaPhiDistance_

template<typename TILES >
const double ticl::PatternRecognitionbyCLUE3D< TILES >::criticalEtaPhiDistance_
private

Definition at line 125 of file PatternRecognitionbyCLUE3D.h.

◆ criticalSelfDensity_

template<typename TILES >
const double ticl::PatternRecognitionbyCLUE3D< TILES >::criticalSelfDensity_
private

Definition at line 115 of file PatternRecognitionbyCLUE3D.h.

◆ criticalXYDistance_

template<typename TILES >
const double ticl::PatternRecognitionbyCLUE3D< TILES >::criticalXYDistance_
private

Definition at line 126 of file PatternRecognitionbyCLUE3D.h.

◆ criticalZDistanceLyr_

template<typename TILES >
const int ticl::PatternRecognitionbyCLUE3D< TILES >::criticalZDistanceLyr_
private

Definition at line 127 of file PatternRecognitionbyCLUE3D.h.

◆ densityEtaPhiDistanceSqr_

template<typename TILES >
const double ticl::PatternRecognitionbyCLUE3D< TILES >::densityEtaPhiDistanceSqr_
private

Definition at line 117 of file PatternRecognitionbyCLUE3D.h.

◆ densityOnSameLayer_

template<typename TILES >
const bool ticl::PatternRecognitionbyCLUE3D< TILES >::densityOnSameLayer_
private

Definition at line 120 of file PatternRecognitionbyCLUE3D.h.

◆ densitySiblingLayers_

template<typename TILES >
const int ticl::PatternRecognitionbyCLUE3D< TILES >::densitySiblingLayers_
private

Definition at line 116 of file PatternRecognitionbyCLUE3D.h.

◆ densityXYDistanceSqr_

template<typename TILES >
const double ticl::PatternRecognitionbyCLUE3D< TILES >::densityXYDistanceSqr_
private

Definition at line 118 of file PatternRecognitionbyCLUE3D.h.

◆ eidInputName_

template<typename TILES >
const std::string ticl::PatternRecognitionbyCLUE3D< TILES >::eidInputName_
private

Definition at line 131 of file PatternRecognitionbyCLUE3D.h.

◆ eidMinClusterEnergy_

template<typename TILES >
const float ticl::PatternRecognitionbyCLUE3D< TILES >::eidMinClusterEnergy_
private

Definition at line 134 of file PatternRecognitionbyCLUE3D.h.

◆ eidNClusters_

template<typename TILES >
const int ticl::PatternRecognitionbyCLUE3D< TILES >::eidNClusters_
private

Definition at line 136 of file PatternRecognitionbyCLUE3D.h.

◆ eidNFeatures_

template<typename TILES >
const int ticl::PatternRecognitionbyCLUE3D< TILES >::eidNFeatures_ = 3
staticprivate

Definition at line 141 of file PatternRecognitionbyCLUE3D.h.

◆ eidNLayers_

template<typename TILES >
const int ticl::PatternRecognitionbyCLUE3D< TILES >::eidNLayers_
private

Definition at line 135 of file PatternRecognitionbyCLUE3D.h.

◆ eidOutputNameEnergy_

template<typename TILES >
const std::string ticl::PatternRecognitionbyCLUE3D< TILES >::eidOutputNameEnergy_
private

Definition at line 132 of file PatternRecognitionbyCLUE3D.h.

◆ eidOutputNameId_

template<typename TILES >
const std::string ticl::PatternRecognitionbyCLUE3D< TILES >::eidOutputNameId_
private

Definition at line 133 of file PatternRecognitionbyCLUE3D.h.

◆ eidSession_

template<typename TILES >
tensorflow::Session* ticl::PatternRecognitionbyCLUE3D< TILES >::eidSession_
private

Definition at line 139 of file PatternRecognitionbyCLUE3D.h.

◆ filter_on_categories_

template<typename TILES >
const std::vector<int> ticl::PatternRecognitionbyCLUE3D< TILES >::filter_on_categories_
private

Definition at line 130 of file PatternRecognitionbyCLUE3D.h.

◆ kernelDensityFactor_

template<typename TILES >
const double ticl::PatternRecognitionbyCLUE3D< TILES >::kernelDensityFactor_
private

Definition at line 119 of file PatternRecognitionbyCLUE3D.h.

◆ layersPosZ_

template<typename TILES >
std::vector<float> ticl::PatternRecognitionbyCLUE3D< TILES >::layersPosZ_
private

Definition at line 111 of file PatternRecognitionbyCLUE3D.h.

◆ minNumLayerCluster_

template<typename TILES >
const int ticl::PatternRecognitionbyCLUE3D< TILES >::minNumLayerCluster_
private

Definition at line 129 of file PatternRecognitionbyCLUE3D.h.

◆ nearestHigherOnSameLayer_

template<typename TILES >
const bool ticl::PatternRecognitionbyCLUE3D< TILES >::nearestHigherOnSameLayer_
private

Definition at line 121 of file PatternRecognitionbyCLUE3D.h.

◆ outlierMultiplier_

template<typename TILES >
const double ticl::PatternRecognitionbyCLUE3D< TILES >::outlierMultiplier_
private

Definition at line 128 of file PatternRecognitionbyCLUE3D.h.

◆ rescaleDensityByZ_

template<typename TILES >
const bool ticl::PatternRecognitionbyCLUE3D< TILES >::rescaleDensityByZ_
private

Definition at line 124 of file PatternRecognitionbyCLUE3D.h.

◆ rhtools_

template<typename TILES >
hgcal::RecHitTools ticl::PatternRecognitionbyCLUE3D< TILES >::rhtools_
private

Definition at line 138 of file PatternRecognitionbyCLUE3D.h.

◆ useAbsoluteProjectiveScale_

template<typename TILES >
const bool ticl::PatternRecognitionbyCLUE3D< TILES >::useAbsoluteProjectiveScale_
private

Definition at line 122 of file PatternRecognitionbyCLUE3D.h.

◆ useClusterDimensionXY_

template<typename TILES >
const bool ticl::PatternRecognitionbyCLUE3D< TILES >::useClusterDimensionXY_
private

Definition at line 123 of file PatternRecognitionbyCLUE3D.h.