CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
reco::EcalClustersGraph Class Reference

#include <EcalClustersGraph.h>

Public Types

typedef std::shared_ptr< CalibratedPFClusterCalibratedClusterPtr
 
typedef std::vector< CalibratedClusterPtrCalibratedClusterPtrVector
 
typedef std::vector< std::pair< CalibratedClusterPtr, CalibratedClusterPtrVector > > EcalGraphOutput
 

Public Member Functions

 EcalClustersGraph (CalibratedClusterPtrVector clusters, int nSeeds, const CaloTopology *topology, const CaloSubdetectorGeometry *ebGeom, const CaloSubdetectorGeometry *eeGeom, const EcalRecHitCollection *recHitsEB, const EcalRecHitCollection *recHitsEE, const reco::SCProducerCache *cache)
 
void evaluateScores ()
 
void fillVariables ()
 
EcalGraphOutput getGraphOutput ()
 
void initWindows ()
 
double scoreThreshold (const CaloCluster *cluster)
 
void selectClusters ()
 
void setThresholds ()
 

Private Member Functions

std::array< int, 3 > clusterPosition (const CaloCluster *cluster) const
 
std::pair< double, double > computeCovariances (const CaloCluster *cluster)
 
std::vector< double > computeShowerShapes (const CaloCluster *cluster, bool full5x5)
 
DeepSCInputs::FeaturesMap computeVariables (const CaloCluster *seed, const CaloCluster *cluster) const
 
DeepSCInputs::FeaturesMap computeWindowVariables (const std::vector< DeepSCInputs::FeaturesMap > &clusters) const
 
double deltaEta (double seed_eta, double cluster_eta) const
 
std::array< double, 3 > dynamicWindow (double seedEta) const
 
std::vector< std::vector< float > > fillHits (const CaloCluster *cluster) const
 

Private Attributes

CalibratedClusterPtrVector clusters_
 
const CaloSubdetectorGeometryebGeom_
 
const CaloSubdetectorGeometryeeGeom_
 
reco::GraphMap graphMap_
 
reco::DeepSCInputs::Inputs inputs_
 
std::array< float, 3 > locCov_
 
uint nCls_
 
uint nSeeds_
 
const EcalRecHitCollectionrecHitsEB_
 
const EcalRecHitCollectionrecHitsEE_
 
const reco::SCProducerCachescProducerCache_
 
reco::GraphMap::CollectionStrategy strategy_
 
float threshold_
 
const CaloTopologytopology_
 
std::pair< double, double > widths_
 

Detailed Description

Definition at line 53 of file EcalClustersGraph.h.

Member Typedef Documentation

◆ CalibratedClusterPtr

Definition at line 55 of file EcalClustersGraph.h.

◆ CalibratedClusterPtrVector

Definition at line 56 of file EcalClustersGraph.h.

◆ EcalGraphOutput

Definition at line 57 of file EcalClustersGraph.h.

Constructor & Destructor Documentation

◆ EcalClustersGraph()

EcalClustersGraph::EcalClustersGraph ( CalibratedClusterPtrVector  clusters,
int  nSeeds,
const CaloTopology topology,
const CaloSubdetectorGeometry ebGeom,
const CaloSubdetectorGeometry eeGeom,
const EcalRecHitCollection recHitsEB,
const EcalRecHitCollection recHitsEE,
const reco::SCProducerCache cache 
)

Definition at line 11 of file EcalClustersGraph.cc.

References reco::GraphMap::addNode(), reco::DeepSCInputs::Inputs::clustersX, reco::DeepSCConfiguration::collectionStrategy, reco::SCProducerCache::config, graphMap_, reco::DeepSCInputs::Inputs::hitsX, mps_fire::i, inputs_, reco::DeepSCInputs::Inputs::isSeed, LogTrace, nCls_, nSeeds_, scProducerCache_, strategy_, and reco::DeepSCInputs::Inputs::windowX.

20  nSeeds_(nSeeds),
21  nCls_(clusters_.size()),
22  topology_(topology),
23  ebGeom_(ebGeom),
24  eeGeom_(eeGeom),
28  graphMap_(clusters.size()) {
29  // Prepare the batch size of the tensor inputs == number of windows
30  inputs_.clustersX.resize(nSeeds_);
31  inputs_.windowX.resize(nSeeds_);
32  inputs_.hitsX.resize(nSeeds_);
33  inputs_.isSeed.resize(nSeeds_);
34 
35  // Init the graph nodes
36  for (size_t i = 0; i < nCls_; i++) {
37  if (i < nSeeds_)
38  graphMap_.addNode(i, GraphMap::NodeCategory::kSeed);
39  else
40  graphMap_.addNode(i, GraphMap::NodeCategory::kNode);
41  }
42 
43  // Select the collection strategy from the config
44  if (scProducerCache_->config.collectionStrategy == "Cascade") {
45  strategy_ = GraphMap::CollectionStrategy::Cascade;
46  } else if (scProducerCache_->config.collectionStrategy == "CollectAndMerge") {
47  strategy_ = GraphMap::CollectionStrategy::CollectAndMerge;
48  } else if (scProducerCache_->config.collectionStrategy == "SeedsFirst") {
49  strategy_ = GraphMap::CollectionStrategy::SeedsFirst;
50  } else if (scProducerCache_->config.collectionStrategy == "CascadeHighest") {
51  strategy_ = GraphMap::CollectionStrategy::CascadeHighest;
52  } else {
53  edm::LogWarning("EcalClustersGraph") << "GraphMap::CollectionStrategy not recognized. Default to Cascade";
54  strategy_ = GraphMap::CollectionStrategy::Cascade;
55  }
56 
57  LogTrace("EcalClustersGraph") << "EcalClustersGraph created. nSeeds " << nSeeds_ << ", nClusters " << nCls_ << endl;
58 }
reco::DeepSCConfiguration config
std::vector< std::vector< float > > windowX
const CaloTopology * topology_
const EcalRecHitCollection * recHitsEB_
const EcalRecHitCollection * recHitsEE_
reco::DeepSCInputs::Inputs inputs_
const reco::SCProducerCache * scProducerCache_
const CaloSubdetectorGeometry * eeGeom_
reco::GraphMap::CollectionStrategy strategy_
void addNode(const uint index, const NodeCategory category)
Definition: GraphMap.cc:15
#define LogTrace(id)
const CaloSubdetectorGeometry * ebGeom_
std::vector< std::vector< std::vector< float > > > clustersX
CalibratedClusterPtrVector clusters_
def cache(function)
Definition: utilities.py:3
std::vector< std::vector< bool > > isSeed
Log< level::Warning, false > LogWarning
std::vector< std::vector< std::vector< std::vector< float > > > > hitsX

Member Function Documentation

◆ clusterPosition()

std::array< int, 3 > EcalClustersGraph::clusterPosition ( const CaloCluster cluster) const
private

Definition at line 60 of file EcalClustersGraph.cc.

References reco::CaloCluster::caloID(), ebGeom_, PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, eeGeom_, PFLayer::fromCaloID(), CaloSubdetectorGeometry::getClosestCell(), LEDCalibrationChannels::ieta, LEDCalibrationChannels::iphi, and reco::CaloCluster::position().

Referenced by computeVariables(), and initWindows().

60  {
61  std::array<int, 3> coordinates;
62  int ieta = -999;
63  int iphi = -999;
64  int iz = -99;
65 
66  const math::XYZPoint& caloPos = cluster->position();
67  if (PFLayer::fromCaloID(cluster->caloID()) == PFLayer::ECAL_BARREL) {
68  EBDetId eb_id(ebGeom_->getClosestCell(GlobalPoint(caloPos.x(), caloPos.y(), caloPos.z())));
69  ieta = eb_id.ieta();
70  iphi = eb_id.iphi();
71  iz = 0;
72  } else if (PFLayer::fromCaloID(cluster->caloID()) == PFLayer::ECAL_ENDCAP) {
73  EEDetId ee_id(eeGeom_->getClosestCell(GlobalPoint(caloPos.x(), caloPos.y(), caloPos.z())));
74  ieta = ee_id.ix();
75  iphi = ee_id.iy();
76  if (ee_id.zside() < 0)
77  iz = -1;
78  if (ee_id.zside() > 0)
79  iz = 1;
80  }
81 
82  coordinates[0] = ieta;
83  coordinates[1] = iphi;
84  coordinates[2] = iz;
85  return coordinates;
86 }
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
const CaloSubdetectorGeometry * eeGeom_
const CaloID & caloID() const
Definition: CaloCluster.h:201
const CaloSubdetectorGeometry * ebGeom_
virtual DetId getClosestCell(const GlobalPoint &r) const
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
static Layer fromCaloID(const reco::CaloID &id)
Definition: PFLayer.cc:38

◆ computeCovariances()

std::pair< double, double > EcalClustersGraph::computeCovariances ( const CaloCluster cluster)
private

Definition at line 254 of file EcalClustersGraph.cc.

References reco::CaloCluster::caloID(), reco::deltaPhi(), bTagMiniDQMDeepCSV::denominator, HLT_2022v14_cff::dEta, HLT_2022v14_cff::dPhi, ebGeom_, PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, eeGeom_, edm::SortedCollection< T, SORT >::end(), reco::CaloCluster::energy(), photons_cff::etaWidth, edm::SortedCollection< T, SORT >::find(), PFLayer::fromCaloID(), CaloSubdetectorGeometry::getGeometry(), reco::CaloCluster::hitsAndFractions(), photons_cff::phiWidth, reco::CaloCluster::position(), position, recHitsEB_, recHitsEE_, and mathSSE::sqrt().

Referenced by computeShowerShapes().

254  {
255  double numeratorEtaWidth = 0;
256  double numeratorPhiWidth = 0;
257  double denominator = cluster->energy();
258  double clEta = cluster->position().eta();
259  double clPhi = cluster->position().phi();
260  std::shared_ptr<const CaloCellGeometry> this_cell;
262 
263  const std::vector<std::pair<DetId, float>>& detId = cluster->hitsAndFractions();
264  // Loop over recHits associated with the given SuperCluster
265  for (const auto& hit : detId) {
266  if (PFLayer::fromCaloID(cluster->caloID()) == PFLayer::ECAL_BARREL) {
267  rHit = recHitsEB_->find(hit.first);
268  if (rHit == recHitsEB_->end()) {
269  continue;
270  }
271  this_cell = ebGeom_->getGeometry(rHit->id());
272  } else if (PFLayer::fromCaloID(cluster->caloID()) == PFLayer::ECAL_ENDCAP) {
273  rHit = recHitsEE_->find(hit.first);
274  if (rHit == recHitsEE_->end()) {
275  continue;
276  }
277  this_cell = eeGeom_->getGeometry(rHit->id());
278  } else {
279  continue;
280  }
281 
282  GlobalPoint position = this_cell->getPosition();
283  //take into account energy fractions
284  double energyHit = rHit->energy() * hit.second;
285  //form differences
286  double dPhi = deltaPhi(position.phi(), clPhi);
287  double dEta = position.eta() - clEta;
288  if (energyHit > 0) {
289  numeratorEtaWidth += energyHit * dEta * dEta;
290  numeratorPhiWidth += energyHit * dPhi * dPhi;
291  }
292  }
293  double etaWidth = sqrt(numeratorEtaWidth / denominator);
294  double phiWidth = sqrt(numeratorPhiWidth / denominator);
295 
296  return std::make_pair(etaWidth, phiWidth);
297 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
const EcalRecHitCollection * recHitsEB_
const EcalRecHitCollection * recHitsEE_
std::vector< EcalRecHit >::const_iterator const_iterator
const CaloSubdetectorGeometry * eeGeom_
const CaloID & caloID() const
Definition: CaloCluster.h:201
T sqrt(T t)
Definition: SSEVec.h:19
const CaloSubdetectorGeometry * ebGeom_
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const_iterator end() const
double energy() const
cluster energy
Definition: CaloCluster.h:149
iterator find(key_type k)
static int position[264][3]
Definition: ReadPGInfo.cc:289
static Layer fromCaloID(const reco::CaloID &id)
Definition: PFLayer.cc:38

◆ computeShowerShapes()

std::vector< double > EcalClustersGraph::computeShowerShapes ( const CaloCluster cluster,
bool  full5x5 = false 
)
private

Definition at line 299 of file EcalClustersGraph.cc.

References reco::CaloCluster::caloID(), computeCovariances(), StorageManager_cfg::e1, EcalClusterToolsT< noZS >::e3x3(), vertexPlots::e4, EcalClusterToolsT< noZS >::eBottom(), PFLayer::ECAL_BARREL, PFLayer::ECAL_ENDCAP, EcalClusterToolsT< noZS >::eLeft(), cosmicPhotonAnalyzer_cfi::eMax, EcalClusterToolsT< noZS >::eMax(), reco::CaloCluster::energy(), EcalClusterToolsT< noZS >::eRight(), EcalClusterToolsT< noZS >::eTop(), PFLayer::fromCaloID(), reco::CaloCluster::hitsAndFractions(), edm::isFinite(), EcalClusterToolsT< noZS >::localCovariances(), locCov_, electrons_cff::r9, recHitsEB_, recHitsEE_, mathSSE::sqrt(), topology_, and widths_.

299  {
300  std::vector<double> showerVars_;
301  showerVars_.resize(8);
302  widths_ = computeCovariances(cluster);
303  float e1 = 1.;
304  float e4 = 0.;
305  float r9 = 0.;
306 
307  if (full5x5) {
308  if (PFLayer::fromCaloID(cluster->caloID()) == PFLayer::ECAL_BARREL) {
315  r9 = noZS::EcalClusterTools::e3x3(*cluster, recHitsEB_, topology_) / cluster->energy(); //r9
316 
317  } else if (PFLayer::fromCaloID(cluster->caloID()) == PFLayer::ECAL_ENDCAP) {
324  r9 = noZS::EcalClusterTools::e3x3(*cluster, recHitsEE_, topology_) / cluster->energy(); //r9
325  }
326  } else {
327  if (PFLayer::fromCaloID(cluster->caloID()) == PFLayer::ECAL_BARREL) {
328  locCov_ = EcalClusterTools::localCovariances(*cluster, recHitsEB_, topology_);
329  e1 = EcalClusterTools::eMax(*cluster, recHitsEB_);
330  e4 = EcalClusterTools::eTop(*cluster, recHitsEB_, topology_) +
331  EcalClusterTools::eRight(*cluster, recHitsEB_, topology_) +
332  EcalClusterTools::eBottom(*cluster, recHitsEB_, topology_) +
333  EcalClusterTools::eLeft(*cluster, recHitsEB_, topology_);
334  r9 = EcalClusterTools::e3x3(*cluster, recHitsEB_, topology_) / cluster->energy(); //r9
335  } else if (PFLayer::fromCaloID(cluster->caloID()) == PFLayer::ECAL_ENDCAP) {
336  locCov_ = EcalClusterTools::localCovariances(*cluster, recHitsEE_, topology_);
337  e1 = EcalClusterTools::eMax(*cluster, recHitsEE_);
338  e4 = EcalClusterTools::eTop(*cluster, recHitsEE_, topology_) +
339  EcalClusterTools::eRight(*cluster, recHitsEE_, topology_) +
340  EcalClusterTools::eBottom(*cluster, recHitsEE_, topology_) +
341  EcalClusterTools::eLeft(*cluster, recHitsEE_, topology_);
342  r9 = EcalClusterTools::e3x3(*cluster, recHitsEE_, topology_) / cluster->energy();
343  }
344  }
345  showerVars_[0] = r9;
346  showerVars_[1] = sqrt(locCov_[0]); //sigmaietaieta
347  showerVars_[2] = locCov_[1]; //sigmaietaiphi
348  showerVars_[3] = (!edm::isFinite(locCov_[2])) ? 0. : sqrt(locCov_[2]); //sigmaiphiiphi
349  showerVars_[4] = (e1 != 0.) ? 1. - e4 / e1 : -999.; //swiss_cross
350  showerVars_[5] = cluster->hitsAndFractions().size(); //nXtals
351  showerVars_[6] = widths_.first; //etaWidth
352  showerVars_[7] = widths_.second; //phiWidth
353 
354  return showerVars_;
355 }
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
const CaloTopology * topology_
const EcalRecHitCollection * recHitsEB_
const EcalRecHitCollection * recHitsEE_
static float eMax(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits)
std::pair< double, double > widths_
constexpr bool isFinite(T x)
const CaloID & caloID() const
Definition: CaloCluster.h:201
std::array< float, 3 > locCov_
static std::array< float, 3 > localCovariances(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology, float w0=EgammaLocalCovParamDefaults::kRelEnCut, const EcalPFRecHitThresholds *thresholds=nullptr, float multEB=0.0, float multEE=0.0)
T sqrt(T t)
Definition: SSEVec.h:19
static float eBottom(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
double energy() const
cluster energy
Definition: CaloCluster.h:149
static float eTop(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static Layer fromCaloID(const reco::CaloID &id)
Definition: PFLayer.cc:38
static float eRight(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float e3x3(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float eLeft(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
std::pair< double, double > computeCovariances(const CaloCluster *cluster)

◆ computeVariables()

DeepSCInputs::FeaturesMap EcalClustersGraph::computeVariables ( const CaloCluster seed,
const CaloCluster cluster 
) const
private

Definition at line 205 of file EcalClustersGraph.cc.

References clusterPosition(), deltaEta(), reco::deltaPhi(), reco::CaloCluster::energy(), reco::CaloCluster::eta(), reco::CaloCluster::hitsAndFractions(), reco::CaloCluster::phi(), and fileCollector::seed.

Referenced by fillVariables().

206  {
207  DeepSCInputs::FeaturesMap clFeatures;
208  const auto& clusterLocal = clusterPosition(cluster);
209  double cl_energy = cluster->energy();
210  double cl_eta = cluster->eta();
211  double cl_phi = cluster->phi();
212  double seed_energy = seed->energy();
213  double seed_eta = seed->eta();
214  double seed_phi = seed->phi();
215  clFeatures["cl_energy"] = cl_energy; //cl_energy
216  clFeatures["cl_et"] = cl_energy / std::cosh(cl_eta); //cl_et
217  clFeatures["cl_eta"] = cl_eta; //cl_eta
218  clFeatures["cl_phi"] = cl_phi; //cl_phi
219  clFeatures["cl_ieta"] = clusterLocal[0]; //cl_ieta/ix
220  clFeatures["cl_iphi"] = clusterLocal[1]; //cl_iphi/iy
221  clFeatures["cl_iz"] = clusterLocal[2]; //cl_iz
222  clFeatures["cl_seed_dEta"] = deltaEta(seed_eta, cl_eta); //cl_dEta
223  clFeatures["cl_seed_dPhi"] = deltaPhi(seed_phi, cl_phi); //cl_dPhi
224  clFeatures["cl_seed_dEnergy"] = seed_energy - cl_energy; //cl_dEnergy
225  clFeatures["cl_seed_dEt"] = (seed_energy / std::cosh(seed_eta)) - (cl_energy / std::cosh(cl_eta)); //cl_dEt
226  clFeatures["cl_nxtals"] = cluster->hitsAndFractions().size(); // nxtals
227  return clFeatures;
228 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
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
double deltaEta(double seed_eta, double cluster_eta) const
std::map< std::string, double > FeaturesMap
std::array< int, 3 > clusterPosition(const CaloCluster *cluster) const
double energy() const
cluster energy
Definition: CaloCluster.h:149
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:181

◆ computeWindowVariables()

DeepSCInputs::FeaturesMap EcalClustersGraph::computeWindowVariables ( const std::vector< DeepSCInputs::FeaturesMap > &  clusters) const
private

Definition at line 230 of file EcalClustersGraph.cc.

References bsc_activity_cfg::clusters, crabWrapper::key, SiStripPI::max, SiStripPI::min, and heppy_batch::val.

Referenced by fillVariables().

231  {
232  size_t nCls = clusters.size();
233  std::map<std::string, float> min;
234  std::map<std::string, float> max;
235  std::map<std::string, float> avg;
236  for (const auto& clFeatures : clusters) {
237  for (auto const& [key, val] : clFeatures) {
238  avg[key] += (val / nCls);
239  if (val < min[key])
240  min[key] = val;
241  if (val > max[key])
242  max[key] = val;
243  }
244  }
245  DeepSCInputs::FeaturesMap windFeatures;
246  for (auto const& el : clusters.front()) {
247  windFeatures["max_" + el.first] = max[el.first];
248  windFeatures["min_" + el.first] = min[el.first];
249  windFeatures["avg_" + el.first] = avg[el.first];
250  }
251  return windFeatures;
252 }
std::map< std::string, double > FeaturesMap

◆ deltaEta()

double reco::EcalClustersGraph::deltaEta ( double  seed_eta,
double  cluster_eta 
) const
inlineprivate

Definition at line 83 of file EcalClustersGraph.h.

Referenced by computeVariables(), and initWindows().

83  {
84  return (1 - 2 * (seed_eta < 0)) * (cluster_eta - seed_eta);
85  }

◆ dynamicWindow()

std::array< double, 3 > EcalClustersGraph::dynamicWindow ( double  seedEta) const
private

Definition at line 88 of file EcalClustersGraph.cc.

References funct::abs(), PVValHelper::eta, and svgfig::window().

Referenced by initWindows().

88  {
89  // The dEta-dPhi detector window dimension is chosen to that the algorithm is always larger than
90  // the Mustache dimension
91  std::array<double, 3> window;
92 
93  double eta = std::abs(seedEta);
94  double deta_down = 0.;
95  double deta_up = 0.;
96  double dphi = 0.;
97 
98  //deta_down
99  constexpr float deta_down_bins[2] = {2.1, 2.5};
100  if (eta < deta_down_bins[0])
101  deta_down = -0.075;
102  else if (eta >= deta_down_bins[0] && eta < deta_down_bins[1])
103  deta_down = -0.1875 * eta + 0.31875;
104  else if (eta >= deta_down_bins[1])
105  deta_down = -0.15;
106 
107  //deta_up
108  constexpr float deta_up_bins[4] = {0.1, 1.3, 1.7, 1.9};
109  if (eta < deta_up_bins[0])
110  deta_up = 0.075;
111  else if (eta >= deta_up_bins[0] && eta < deta_up_bins[1])
112  deta_up = 0.0758929 - 0.0178571 * eta + 0.0892857 * (eta * eta);
113  else if (eta >= deta_up_bins[1] && eta < deta_up_bins[2])
114  deta_up = 0.2;
115  else if (eta >= deta_up_bins[2] && eta < deta_up_bins[3])
116  deta_up = 0.625 - 0.25 * eta;
117  else if (eta >= deta_up_bins[3])
118  deta_up = 0.15;
119 
120  //dphi
121  constexpr float dphi_bins[2] = {1.9, 2.7};
122  if (eta < dphi_bins[0])
123  dphi = 0.6;
124  else if (eta >= dphi_bins[0] && eta < dphi_bins[1])
125  dphi = 1.075 - 0.25 * eta;
126  else if (eta >= dphi_bins[1])
127  dphi = 0.4;
128 
129  window[0] = deta_down;
130  window[1] = deta_up;
131  window[2] = dphi;
132 
133  return window;
134 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:643

◆ evaluateScores()

void EcalClustersGraph::evaluateScores ( )

Definition at line 399 of file EcalClustersGraph.cc.

References reco::SCProducerCache::deepSCEvaluator, reco::GraphMap::getOutEdges(), graphMap_, mps_fire::i, inputs_, dqmiolumiharvest::j, dqmdumpme::k, LogTrace, nSeeds_, scProducerCache_, reco::GraphMap::setAdjMatrix(), and parallelization::uint.

399  {
400  // Evaluate model
401  const auto& scores = scProducerCache_->deepSCEvaluator->evaluate(inputs_);
402  for (uint i = 0; i < nSeeds_; ++i) {
403  uint k = 0;
404  LogTrace("EcalClustersGraph") << "Score) seed: " << i << ":";
405  for (auto const& j : graphMap_.getOutEdges(i)) {
406  // Fill the scores from seed --> node (i --> j)
407  // Not symmetrically, in order to save multiple values for seeds in other
408  // seeds windows.
409  graphMap_.setAdjMatrix(i, j, scores[i][k]);
410  LogTrace("EcalClustersGraph") << "\t" << i << "-->" << j << ": " << scores[i][k];
411  k++;
412  }
413  }
414 }
reco::DeepSCInputs::Inputs inputs_
const reco::SCProducerCache * scProducerCache_
#define LogTrace(id)
const std::vector< uint > & getOutEdges(const uint i) const
Definition: GraphMap.cc:41
void setAdjMatrix(const uint i, const uint j, const float score)
Definition: GraphMap.cc:34
std::unique_ptr< const DeepSCGraphEvaluation > deepSCEvaluator

◆ fillHits()

std::vector< std::vector< float > > EcalClustersGraph::fillHits ( const CaloCluster cluster) const
private

Definition at line 167 of file EcalClustersGraph.cc.

References reco::SCProducerCache::deepSCEvaluator, EcalBarrel, EcalEndcap, HCALHighEnergyHPDFilter_cfi::energy, edm::SortedCollection< T, SORT >::find(), first, reco::CaloCluster::hitsAndFractions(), mps_fire::i, EBDetId::ieta(), EBDetId::iphi(), EEDetId::ix(), EEDetId::iy(), MillePedeFileConverter_cfg::out, recHitsEB_, recHitsEE_, scProducerCache_, and EEDetId::zside().

Referenced by fillVariables().

167  {
168  const std::vector<std::pair<DetId, float>>& hitsAndFractions = cluster->hitsAndFractions();
169  std::vector<std::vector<float>> out(hitsAndFractions.size());
170  if (hitsAndFractions.empty()) {
171  edm::LogError("EcalClustersGraph") << "No hits in cluster!!";
172  }
173  // Map containing the available features for the rechits
174  DeepSCInputs::FeaturesMap rechitsFeatures;
175  for (unsigned int i = 0; i < hitsAndFractions.size(); i++) {
176  rechitsFeatures.clear();
177  if (hitsAndFractions[i].first.subdetId() == EcalBarrel) {
178  double energy = (*recHitsEB_->find(hitsAndFractions[i].first)).energy();
179  EBDetId eb_id(hitsAndFractions[i].first);
180  rechitsFeatures["ieta"] = eb_id.ieta(); //ieta
181  rechitsFeatures["iphi"] = eb_id.iphi(); //iphi
182  rechitsFeatures["iz"] = 0.; //iz
183  rechitsFeatures["en_withfrac"] = energy * hitsAndFractions[i].second; //energy * fraction
184  } else if (hitsAndFractions[i].first.subdetId() == EcalEndcap) {
185  double energy = (*recHitsEE_->find(hitsAndFractions[i].first)).energy();
186  EEDetId ee_id(hitsAndFractions[i].first);
187  rechitsFeatures["ieta"] = ee_id.ix(); //ix
188  rechitsFeatures["iphi"] = ee_id.iy(); //iy
189  if (ee_id.zside() < 0)
190  rechitsFeatures["iz"] = -1.; //iz
191  if (ee_id.zside() > 0)
192  rechitsFeatures["iz"] = +1.; //iz
193  rechitsFeatures["en_withfrac"] = energy * hitsAndFractions[i].second; //energy * fraction
194  } else {
195  edm::LogError("EcalClustersGraph") << "Rechit is not either EB or EE!!";
196  }
197  // Use the method in DeepSCGraphEvaluation to get only the requested variables and possible a rescaling
198  // (depends on configuration)
199  out[i] = scProducerCache_->deepSCEvaluator->getScaledInputs(rechitsFeatures,
200  scProducerCache_->deepSCEvaluator->inputFeaturesHits);
201  }
202  return out;
203 }
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
const EcalRecHitCollection * recHitsEB_
const EcalRecHitCollection * recHitsEE_
const reco::SCProducerCache * scProducerCache_
Log< level::Error, false > LogError
std::map< std::string, double > FeaturesMap
iterator find(key_type k)
std::unique_ptr< const DeepSCGraphEvaluation > deepSCEvaluator

◆ fillVariables()

void EcalClustersGraph::fillVariables ( )

Definition at line 357 of file EcalClustersGraph.cc.

References clusters_, reco::DeepSCInputs::Inputs::clustersX, computeVariables(), computeWindowVariables(), reco::SCProducerCache::deepSCEvaluator, fillHits(), reco::GraphMap::getOutEdges(), graphMap_, reco::DeepSCInputs::Inputs::hitsX, inputs_, reco::DeepSCInputs::Inputs::isSeed, crabWrapper::key, LogDebug, LogTrace, nSeeds_, scProducerCache_, parallelization::uint, heppy_batch::val, and reco::DeepSCInputs::Inputs::windowX.

357  {
358  LogDebug("EcalClustersGraph") << "Fill tensorflow input vector";
359  const auto& deepSCEval = scProducerCache_->deepSCEvaluator;
360  // Reserving the batch dimension
361  inputs_.clustersX.reserve(nSeeds_);
362  inputs_.hitsX.reserve(nSeeds_);
363  inputs_.windowX.reserve(nSeeds_);
364  inputs_.isSeed.reserve(nSeeds_);
365 
366  // Looping on all the seeds (window)
367  for (uint is = 0; is < nSeeds_; is++) {
368  const auto seedPointer = (*clusters_[is]).ptr().get();
369  std::vector<DeepSCInputs::FeaturesMap> unscaledClusterFeatures;
370  const auto& outEdges = graphMap_.getOutEdges(is);
371  size_t ncls = outEdges.size();
372  // Reserve the vector size
373  inputs_.clustersX[is].reserve(ncls);
374  inputs_.hitsX[is].reserve(ncls);
375  inputs_.isSeed[is].reserve(ncls);
376  unscaledClusterFeatures.reserve(ncls);
377  // Loop on all the clusters
378  for (const auto ic : outEdges) {
379  LogTrace("EcalClustersGraph") << "seed: " << is << ", out edge --> " << ic;
380  const auto clPointer = (*clusters_[ic]).ptr().get();
381  const auto& clusterFeatures = computeVariables(seedPointer, clPointer);
382  for (const auto& [key, val] : clusterFeatures) {
383  LogTrace("EcalCluster") << key << "=" << val;
384  }
385  unscaledClusterFeatures.push_back(clusterFeatures);
386  // Select and scale only the requested variables for the tensorflow model input
387  inputs_.clustersX[is].push_back(deepSCEval->getScaledInputs(clusterFeatures, deepSCEval->inputFeaturesClusters));
388  // The scaling and feature selection on hits is performed inside the function for each hit
389  inputs_.hitsX[is].push_back(fillHits(clPointer));
390  inputs_.isSeed[is].push_back(ic == is);
391  }
392  // For window we need the unscaled cluster features and then we select them
393  inputs_.windowX[is] =
394  deepSCEval->getScaledInputs(computeWindowVariables(unscaledClusterFeatures), deepSCEval->inputFeaturesWindows);
395  }
396  LogTrace("EcalClustersGraph") << "N. Windows: " << inputs_.clustersX.size();
397 }
std::vector< std::vector< float > > windowX
reco::DeepSCInputs::Inputs inputs_
DeepSCInputs::FeaturesMap computeWindowVariables(const std::vector< DeepSCInputs::FeaturesMap > &clusters) const
const reco::SCProducerCache * scProducerCache_
#define LogTrace(id)
const std::vector< uint > & getOutEdges(const uint i) const
Definition: GraphMap.cc:41
DeepSCInputs::FeaturesMap computeVariables(const CaloCluster *seed, const CaloCluster *cluster) const
std::vector< std::vector< std::vector< float > > > clustersX
std::vector< std::vector< float > > fillHits(const CaloCluster *cluster) const
CalibratedClusterPtrVector clusters_
std::vector< std::vector< bool > > isSeed
std::unique_ptr< const DeepSCGraphEvaluation > deepSCEvaluator
std::vector< std::vector< std::vector< std::vector< float > > > > hitsX
#define LogDebug(id)

◆ getGraphOutput()

EcalClustersGraph::EcalGraphOutput EcalClustersGraph::getGraphOutput ( )

Definition at line 426 of file EcalClustersGraph.cc.

References clusters_, reco::GraphMap::getGraphOutput(), graphMap_, and fileCollector::seed.

426  {
428  const auto& finalSuperClusters_ = graphMap_.getGraphOutput();
429  for (const auto& [is, cls] : finalSuperClusters_) {
431  CalibratedClusterPtrVector clusters_inWindow;
432  for (const auto& ic : cls) {
433  clusters_inWindow.push_back(clusters_[ic]);
434  }
435  finalWindows_.push_back({seed, clusters_inWindow});
436  }
437  return finalWindows_;
438 }
std::vector< CalibratedClusterPtr > CalibratedClusterPtrVector
const GraphOutput & getGraphOutput()
Definition: GraphMap.h:60
std::vector< std::pair< CalibratedClusterPtr, CalibratedClusterPtrVector > > EcalGraphOutput
CalibratedClusterPtrVector clusters_
std::shared_ptr< CalibratedPFCluster > CalibratedClusterPtr
\ Algorithm for box particle flow super clustering in the ECAL

◆ initWindows()

void EcalClustersGraph::initWindows ( )

Definition at line 136 of file EcalClustersGraph.cc.

References funct::abs(), reco::GraphMap::addEdge(), clusterPosition(), clusters_, deltaEta(), reco::deltaPhi(), dynamicWindow(), graphMap_, nCls_, nSeeds_, parallelization::uint, and ApeEstimator_cff::width.

136  {
137  for (uint is = 0; is < nSeeds_; is++) {
138  const auto& seedLocal = clusterPosition((*clusters_[is]).ptr().get());
139  double seed_eta = clusters_[is]->eta();
140  double seed_phi = clusters_[is]->phi();
141  const auto& width = dynamicWindow(seed_eta);
142  // Add a self loop on the seed node
143  graphMap_.addEdge(is, is);
144 
145  // The graph associated to each seed includes only other seeds if they have a smaller energy.
146  // This is imposed to be consistent with the current trained model, which has been training on "non-overalapping windows".
147  // The effect of connecting all the seeds, and not only the smaller energy ones has been already tested: the reconstruction
148  // differences are negligible (tested with Cascade collection algo).
149  // In the next version of the training this requirement will be relaxed to have a model that fully matches the reconstruction
150  // mechanism in terms of overlapping seeds.
151  for (uint icl = is + 1; icl < nCls_; icl++) {
152  if (is == icl)
153  continue;
154  const auto& clusterLocal = clusterPosition((*clusters_[icl]).ptr().get());
155  double cl_eta = clusters_[icl]->eta();
156  double cl_phi = clusters_[icl]->phi();
157  double dphi = deltaPhi(seed_phi, cl_phi);
158  double deta = deltaEta(seed_eta, cl_eta);
159 
160  if (seedLocal[2] == clusterLocal[2] && deta >= width[0] && deta <= width[1] && std::abs(dphi) <= width[2]) {
161  graphMap_.addEdge(is, icl);
162  }
163  }
164  }
165 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
std::array< double, 3 > dynamicWindow(double seedEta) const
double deltaEta(double seed_eta, double cluster_eta) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::array< int, 3 > clusterPosition(const CaloCluster *cluster) const
void addEdge(const uint i, const uint j)
Definition: GraphMap.cc:26
CalibratedClusterPtrVector clusters_

◆ scoreThreshold()

double reco::EcalClustersGraph::scoreThreshold ( const CaloCluster cluster)

◆ selectClusters()

void EcalClustersGraph::selectClusters ( )

Definition at line 421 of file EcalClustersGraph.cc.

References reco::GraphMap::collectNodes(), graphMap_, strategy_, and threshold_.

421  {
422  // Collect the final superClusters as subgraphs
424 }
reco::GraphMap::CollectionStrategy strategy_
void collectNodes(GraphMap::CollectionStrategy strategy, float threshold)
Definition: GraphMap.cc:97

◆ setThresholds()

void EcalClustersGraph::setThresholds ( )

Definition at line 416 of file EcalClustersGraph.cc.

References threshold_.

416  {
417  // Simple global threshold for the moment
418  threshold_ = 0.5;
419 }

Member Data Documentation

◆ clusters_

CalibratedClusterPtrVector reco::EcalClustersGraph::clusters_
private

Definition at line 98 of file EcalClustersGraph.h.

Referenced by fillVariables(), getGraphOutput(), and initWindows().

◆ ebGeom_

const CaloSubdetectorGeometry* reco::EcalClustersGraph::ebGeom_
private

Definition at line 107 of file EcalClustersGraph.h.

Referenced by clusterPosition(), and computeCovariances().

◆ eeGeom_

const CaloSubdetectorGeometry* reco::EcalClustersGraph::eeGeom_
private

Definition at line 108 of file EcalClustersGraph.h.

Referenced by clusterPosition(), and computeCovariances().

◆ graphMap_

reco::GraphMap reco::EcalClustersGraph::graphMap_
private

◆ inputs_

reco::DeepSCInputs::Inputs reco::EcalClustersGraph::inputs_
private

Definition at line 118 of file EcalClustersGraph.h.

Referenced by EcalClustersGraph(), evaluateScores(), and fillVariables().

◆ locCov_

std::array<float, 3> reco::EcalClustersGraph::locCov_
private

Definition at line 102 of file EcalClustersGraph.h.

Referenced by computeShowerShapes().

◆ nCls_

uint reco::EcalClustersGraph::nCls_
private

Definition at line 100 of file EcalClustersGraph.h.

Referenced by EcalClustersGraph(), and initWindows().

◆ nSeeds_

uint reco::EcalClustersGraph::nSeeds_
private

Definition at line 99 of file EcalClustersGraph.h.

Referenced by EcalClustersGraph(), evaluateScores(), fillVariables(), and initWindows().

◆ recHitsEB_

const EcalRecHitCollection* reco::EcalClustersGraph::recHitsEB_
private

Definition at line 109 of file EcalClustersGraph.h.

Referenced by computeCovariances(), computeShowerShapes(), and fillHits().

◆ recHitsEE_

const EcalRecHitCollection* reco::EcalClustersGraph::recHitsEE_
private

Definition at line 110 of file EcalClustersGraph.h.

Referenced by computeCovariances(), computeShowerShapes(), and fillHits().

◆ scProducerCache_

const reco::SCProducerCache* reco::EcalClustersGraph::scProducerCache_
private

Definition at line 111 of file EcalClustersGraph.h.

Referenced by EcalClustersGraph(), evaluateScores(), fillHits(), and fillVariables().

◆ strategy_

reco::GraphMap::CollectionStrategy reco::EcalClustersGraph::strategy_
private

Definition at line 115 of file EcalClustersGraph.h.

Referenced by EcalClustersGraph(), and selectClusters().

◆ threshold_

float reco::EcalClustersGraph::threshold_
private

Definition at line 119 of file EcalClustersGraph.h.

Referenced by selectClusters(), and setThresholds().

◆ topology_

const CaloTopology* reco::EcalClustersGraph::topology_
private

Definition at line 106 of file EcalClustersGraph.h.

Referenced by computeShowerShapes().

◆ widths_

std::pair<double, double> reco::EcalClustersGraph::widths_
private

Definition at line 103 of file EcalClustersGraph.h.

Referenced by computeShowerShapes().