CMS 3D CMS Logo

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

#include <PatternRecognitionbyCA.h>

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

Public Member Functions

void emptyTrackstersFromSeedsTRK (std::vector< Trackster > &tracksters, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation, const edm::ProductID &collectionID) const
 
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
 
 PatternRecognitionbyCA (const edm::ParameterSet &conf, edm::ConsumesCollector iC)
 
 ~PatternRecognitionbyCA () override
 
- 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 mergeTrackstersTRK (const std::vector< Trackster > &, const std::vector< reco::CaloCluster > &, std::vector< Trackster > &, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation) const
 

Private Attributes

edm::ESGetToken< CaloGeometry, CaloGeometryRecordcaloGeomToken_
 
bool check_missing_layers_ = false
 
const bool computeLocalTime_
 
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 double energy_em_over_total_threshold_
 
const float etaLimitIncreaseWindow_
 
const std::vector< int > filter_on_categories_
 
const float max_delta_time_
 
const double max_longitudinal_sigmaPCA_
 
const int max_missing_layers_in_trackster_
 
const unsigned int max_out_in_hops_
 
const int min_clusters_per_ntuplet_
 
const float min_cos_pointing_
 
const float min_cos_theta_
 
const unsigned int min_layers_per_trackster_
 
const bool oneTracksterPerTrackSeed_
 
const bool out_in_dfs_
 
const double pid_threshold_
 
const bool promoteEmptyRegionToTrackster_
 
hgcal::RecHitTools rhtools_
 
const float root_doublet_max_distance_from_seed_squared_
 
const unsigned int shower_start_max_layer_
 
const std::vector< double > siblings_maxRSquared_
 
const int skip_layers_
 
const std::unique_ptr< HGCGraphT< TILES > > theGraph_
 

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::PatternRecognitionbyCA< TILES >

Definition at line 14 of file PatternRecognitionbyCA.h.

Constructor & Destructor Documentation

◆ PatternRecognitionbyCA()

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

Definition at line 19 of file PatternRecognitionbyCA.cc.

22  theGraph_(std::make_unique<HGCGraphT<TILES>>()),
23  oneTracksterPerTrackSeed_(conf.getParameter<bool>("oneTracksterPerTrackSeed")),
24  promoteEmptyRegionToTrackster_(conf.getParameter<bool>("promoteEmptyRegionToTrackster")),
25  out_in_dfs_(conf.getParameter<bool>("out_in_dfs")),
26  max_out_in_hops_(conf.getParameter<int>("max_out_in_hops")),
27  min_cos_theta_(conf.getParameter<double>("min_cos_theta")),
28  min_cos_pointing_(conf.getParameter<double>("min_cos_pointing")),
30  conf.getParameter<double>("root_doublet_max_distance_from_seed_squared")),
31  etaLimitIncreaseWindow_(conf.getParameter<double>("etaLimitIncreaseWindow")),
32  skip_layers_(conf.getParameter<int>("skip_layers")),
33  max_missing_layers_in_trackster_(conf.getParameter<int>("max_missing_layers_in_trackster")),
35  shower_start_max_layer_(conf.getParameter<int>("shower_start_max_layer")),
36  min_layers_per_trackster_(conf.getParameter<int>("min_layers_per_trackster")),
37  filter_on_categories_(conf.getParameter<std::vector<int>>("filter_on_categories")),
38  pid_threshold_(conf.getParameter<double>("pid_threshold")),
39  energy_em_over_total_threshold_(conf.getParameter<double>("energy_em_over_total_threshold")),
40  max_longitudinal_sigmaPCA_(conf.getParameter<double>("max_longitudinal_sigmaPCA")),
42  max_delta_time_(conf.getParameter<double>("max_delta_time")),
43  eidInputName_(conf.getParameter<std::string>("eid_input_name")),
44  eidOutputNameEnergy_(conf.getParameter<std::string>("eid_output_name_energy")),
45  eidOutputNameId_(conf.getParameter<std::string>("eid_output_name_id")),
46  eidMinClusterEnergy_(conf.getParameter<double>("eid_min_cluster_energy")),
47  eidNLayers_(conf.getParameter<int>("eid_n_layers")),
48  eidNClusters_(conf.getParameter<int>("eid_n_clusters")),
49  computeLocalTime_(conf.getParameter<bool>("computeLocalTime")),
50  siblings_maxRSquared_(conf.getParameter<std::vector<double>>("siblings_maxRSquared")){};
const std::unique_ptr< HGCGraphT< TILES > > theGraph_
const std::vector< double > siblings_maxRSquared_
const std::vector< int > filter_on_categories_
const unsigned int min_layers_per_trackster_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
const unsigned int shower_start_max_layer_
const float root_doublet_max_distance_from_seed_squared_

◆ ~PatternRecognitionbyCA()

template<typename TILES >
PatternRecognitionbyCA::~PatternRecognitionbyCA ( )
override

Definition at line 53 of file PatternRecognitionbyCA.cc.

53 {};

Member Function Documentation

◆ emptyTrackstersFromSeedsTRK()

template<typename TILES >
void PatternRecognitionbyCA::emptyTrackstersFromSeedsTRK ( std::vector< Trackster > &  tracksters,
std::unordered_map< int, std::vector< int >> &  seedToTracksterAssociation,
const edm::ProductID collectionID 
) const

Definition at line 331 of file PatternRecognitionbyCA.cc.

References ticl::Trackster::charged_hadron, f, and submitPVValidationJobs::t.

334  {
335  for (auto &thisSeed : seedToTracksterAssociation) {
336  if (thisSeed.second.empty()) {
337  Trackster t;
338  t.setRegressedEnergy(0.f);
339  t.zeroProbabilities();
341  t.setSeed(collectionID, thisSeed.first);
342  tracksters.emplace_back(t);
343  thisSeed.second.emplace_back(tracksters.size() - 1);
344  }
345  }
346 }
double f[11][100]

◆ energyRegressionAndID()

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

Definition at line 349 of file PatternRecognitionbyCA.cc.

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

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

◆ fillPSetDescription()

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

Definition at line 489 of file PatternRecognitionbyCA.cc.

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

489  {
490  iDesc.add<int>("algo_verbosity", 0);
491  iDesc.add<bool>("oneTracksterPerTrackSeed", false);
492  iDesc.add<bool>("promoteEmptyRegionToTrackster", false);
493  iDesc.add<bool>("out_in_dfs", true);
494  iDesc.add<int>("max_out_in_hops", 10);
495  iDesc.add<double>("min_cos_theta", 0.915);
496  iDesc.add<double>("min_cos_pointing", -1.);
497  iDesc.add<double>("root_doublet_max_distance_from_seed_squared", 9999);
498  iDesc.add<double>("etaLimitIncreaseWindow", 2.1);
499  iDesc.add<int>("skip_layers", 0);
500  iDesc.add<int>("max_missing_layers_in_trackster", 9999);
501  iDesc.add<int>("shower_start_max_layer", 9999)->setComment("make default such that no filtering is applied");
502  iDesc.add<int>("min_layers_per_trackster", 10);
503  iDesc.add<std::vector<int>>("filter_on_categories", {0});
504  iDesc.add<double>("pid_threshold", 0.)->setComment("make default such that no filtering is applied");
505  iDesc.add<double>("energy_em_over_total_threshold", -1.)
506  ->setComment("make default such that no filtering is applied");
507  iDesc.add<double>("max_longitudinal_sigmaPCA", 9999);
508  iDesc.add<double>("max_delta_time", 3.)->setComment("nsigma");
509  iDesc.add<std::string>("eid_input_name", "input");
510  iDesc.add<std::string>("eid_output_name_energy", "output/regressed_energy");
511  iDesc.add<std::string>("eid_output_name_id", "output/id_probabilities");
512  iDesc.add<double>("eid_min_cluster_energy", 1.);
513  iDesc.add<int>("eid_n_layers", 50);
514  iDesc.add<int>("eid_n_clusters", 10);
515  iDesc.add<bool>("computeLocalTime", false);
516  iDesc.add<std::vector<double>>("siblings_maxRSquared", {6e-4, 6e-4, 6e-4});
517 }
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)

◆ makeTracksters()

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

Definition at line 56 of file PatternRecognitionbyCA.cc.

References ticl::Advanced, cms::cuda::assert(), ticl::assignPCAtoTracksters(), ticl::Basic, ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), filterCSVwithJSON::copy, HLT_2024v13_cff::doublets, dqmdumpme::first, caHitNtupletGeneratorKernels::foundNtuplets, relativeConstraints::geom, edm::EventSetup::getData(), mps_fire::i, input, createfilelist::int, dqmiolumiharvest::j, LogDebug, SiStripPI::min, L1TMuonDQMOffline_cfi::nEtaBins, None, ecaldqm::binning::nPhiBins, pixelTracksMonitoring_cff::ntuplet, AlCaHLTBitMon_ParallelJobs::p, mps_fire::result, jetUpdater_cfi::sort, submitPVValidationJobs::t, createJobs::tmp, tier0::unique(), and relativeConstraints::value.

59  {
60  // Protect from events with no seeding regions
61  if (input.regions.empty())
62  return;
63 
64  edm::EventSetup const &es = input.es;
67 
69  theGraph_->clear();
71  LogDebug("HGCPatternRecoByCA") << "Making Tracksters with CA" << std::endl;
72  }
73 
77 
78  bool isRegionalIter = (input.regions[0].index != -1);
79  std::vector<HGCDoublet::HGCntuplet> foundNtuplets;
80  std::vector<int> seedIndices;
81  std::vector<uint8_t> layer_cluster_usage(input.layerClusters.size(), 0);
82  theGraph_->makeAndConnectDoublets(input.tiles,
83  input.regions,
84  nEtaBin,
85  nPhiBin,
86  input.layerClusters,
87  input.mask,
88  input.layerClustersTime,
89  1,
90  1,
96  rhtools_.lastLayer(isHFnose),
98  rhtools_.lastLayerEE(isHFnose),
101 
103  //#ifdef FP_DEBUG
104  const auto &doublets = theGraph_->getAllDoublets();
105  int tracksterId = -1;
106 
107  // container for holding tracksters before selection
108  std::vector<Trackster> tmpTracksters;
109  tmpTracksters.reserve(foundNtuplets.size());
110 
111  for (auto const &ntuplet : foundNtuplets) {
112  tracksterId++;
113 
114  std::set<unsigned int> effective_cluster_idx;
115 
116  for (auto const &doublet : ntuplet) {
117  auto innerCluster = doublets[doublet].innerClusterId();
118  auto outerCluster = doublets[doublet].outerClusterId();
119 
120  effective_cluster_idx.insert(innerCluster);
121  effective_cluster_idx.insert(outerCluster);
122 
124  LogDebug("HGCPatternRecoByCA") << " New doublet " << doublet << " for trackster: " << result.size()
125  << " InnerCl " << innerCluster << " " << input.layerClusters[innerCluster].x()
126  << " " << input.layerClusters[innerCluster].y() << " "
127  << input.layerClusters[innerCluster].z() << " OuterCl " << outerCluster << " "
128  << input.layerClusters[outerCluster].x() << " "
129  << input.layerClusters[outerCluster].y() << " "
130  << input.layerClusters[outerCluster].z() << " " << tracksterId << std::endl;
131  }
132  }
133  unsigned showerMinLayerId = 99999;
134  std::vector<unsigned int> uniqueLayerIds;
135  uniqueLayerIds.reserve(effective_cluster_idx.size());
136  std::vector<std::pair<unsigned int, unsigned int>> lcIdAndLayer;
137  lcIdAndLayer.reserve(effective_cluster_idx.size());
138  for (auto const i : effective_cluster_idx) {
139  auto const &haf = input.layerClusters[i].hitsAndFractions();
140  auto layerId = rhtools_.getLayerWithOffset(haf[0].first);
141  showerMinLayerId = std::min(layerId, showerMinLayerId);
142  uniqueLayerIds.push_back(layerId);
143  lcIdAndLayer.emplace_back(i, layerId);
144  }
145  std::sort(uniqueLayerIds.begin(), uniqueLayerIds.end());
146  uniqueLayerIds.erase(std::unique(uniqueLayerIds.begin(), uniqueLayerIds.end()), uniqueLayerIds.end());
147  unsigned int numberOfLayersInTrackster = uniqueLayerIds.size();
148  if (check_missing_layers_) {
149  int numberOfMissingLayers = 0;
150  unsigned int j = showerMinLayerId;
151  unsigned int indexInVec = 0;
152  for (const auto &layer : uniqueLayerIds) {
153  if (layer != j) {
154  numberOfMissingLayers++;
155  j++;
156  if (numberOfMissingLayers > max_missing_layers_in_trackster_) {
157  numberOfLayersInTrackster = indexInVec;
158  for (auto &llpair : lcIdAndLayer) {
159  if (llpair.second >= layer) {
160  effective_cluster_idx.erase(llpair.first);
161  }
162  }
163  break;
164  }
165  }
166  indexInVec++;
167  j++;
168  }
169  }
170  if ((numberOfLayersInTrackster >= min_layers_per_trackster_) and (showerMinLayerId <= shower_start_max_layer_)) {
171  // Put back indices, in the form of a Trackster, into the results vector
172  Trackster tmp;
173  tmp.vertices().reserve(effective_cluster_idx.size());
174  tmp.vertex_multiplicity().resize(effective_cluster_idx.size(), 1);
175  //regions and seedIndices can have different size
176  //if a seeding region does not lead to any trackster
177  tmp.setSeed(input.regions[0].collectionID, seedIndices[tracksterId]);
178 
179  std::copy(std::begin(effective_cluster_idx), std::end(effective_cluster_idx), std::back_inserter(tmp.vertices()));
180  tmpTracksters.push_back(tmp);
181  }
182  }
183  ticl::assignPCAtoTracksters(tmpTracksters,
184  input.layerClusters,
185  input.layerClustersTime,
186  rhtools_.getPositionLayer(rhtools_.lastLayerEE(isHFnose), isHFnose).z(),
188 
189  // run energy regression and ID
190  energyRegressionAndID(input.layerClusters, input.tfSession, tmpTracksters);
191  // Filter results based on PID criteria or EM/Total energy ratio.
192  // We want to **keep** tracksters whose cumulative
193  // probability summed up over the selected categories
194  // is greater than the chosen threshold. Therefore
195  // the filtering function should **discard** all
196  // tracksters **below** the threshold.
197  auto filter_on_pids = [&](Trackster &t) -> bool {
198  auto cumulative_prob = 0.;
199  for (auto index : filter_on_categories_) {
200  cumulative_prob += t.id_probabilities(index);
201  }
202  return (cumulative_prob <= pid_threshold_) &&
203  (t.raw_em_energy() < energy_em_over_total_threshold_ * t.raw_energy());
204  };
205 
206  std::vector<unsigned int> selectedTrackstersIds;
207  for (unsigned i = 0; i < tmpTracksters.size(); ++i) {
208  if (!filter_on_pids(tmpTracksters[i]) and tmpTracksters[i].sigmasPCA()[0] < max_longitudinal_sigmaPCA_) {
209  selectedTrackstersIds.push_back(i);
210  }
211  }
212 
213  result.reserve(selectedTrackstersIds.size());
214 
215  for (unsigned i = 0; i < selectedTrackstersIds.size(); ++i) {
216  const auto &t = tmpTracksters[selectedTrackstersIds[i]];
217  for (auto const lcId : t.vertices()) {
218  layer_cluster_usage[lcId]++;
220  LogDebug("HGCPatternRecoByCA") << "LayerID: " << lcId << " count: " << (int)layer_cluster_usage[lcId]
221  << std::endl;
222  }
223  if (isRegionalIter) {
224  seedToTracksterAssociation[t.seedIndex()].push_back(i);
225  }
226  result.push_back(t);
227  }
228 
229  for (auto &trackster : result) {
230  assert(trackster.vertices().size() <= trackster.vertex_multiplicity().size());
231  for (size_t i = 0; i < trackster.vertices().size(); ++i) {
232  trackster.vertex_multiplicity()[i] = layer_cluster_usage[trackster.vertices(i)];
234  LogDebug("HGCPatternRecoByCA") << "LayerID: " << trackster.vertices(i)
235  << " count: " << (int)trackster.vertex_multiplicity(i) << std::endl;
236  }
237  }
238  // Now decide if the tracksters from the track-based iterations have to be merged
240  std::vector<Trackster> tmp;
241  mergeTrackstersTRK(result, input.layerClusters, tmp, seedToTracksterAssociation);
242  tmp.swap(result);
243  }
244 
246  input.layerClusters,
247  input.layerClustersTime,
248  rhtools_.getPositionLayer(rhtools_.lastLayerEE(isHFnose), isHFnose).z(),
250 
251  // run energy regression and ID
252  energyRegressionAndID(input.layerClusters, input.tfSession, result);
253 
254  // now adding dummy tracksters from seeds not connected to any shower in the result collection
255  // these are marked as charged hadrons with probability 1.
257  emptyTrackstersFromSeedsTRK(result, seedToTracksterAssociation, input.regions[0].collectionID);
258  }
259 
261  for (auto &trackster : result) {
262  LogDebug("HGCPatternRecoByCA") << "Trackster characteristics: " << std::endl;
263  LogDebug("HGCPatternRecoByCA") << "Size: " << trackster.vertices().size() << std::endl;
264  auto counter = 0;
265  for (auto const &p : trackster.id_probabilities()) {
266  LogDebug("HGCPatternRecoByCA") << counter++ << ": " << p << std::endl;
267  }
268  }
269  }
270  theGraph_->clear();
271 }
const std::unique_ptr< HGCGraphT< TILES > > theGraph_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void mergeTrackstersTRK(const std::vector< Trackster > &, const std::vector< reco::CaloCluster > &, std::vector< Trackster > &, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation) const
void emptyTrackstersFromSeedsTRK(std::vector< Trackster > &tracksters, std::unordered_map< int, std::vector< int >> &seedToTracksterAssociation, const edm::ProductID &collectionID) const
const std::vector< double > siblings_maxRSquared_
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50
const std::vector< int > filter_on_categories_
unsigned int lastLayerFH() const
Definition: RecHitTools.h:77
const unsigned int min_layers_per_trackster_
def unique(seq, keepstr=True)
Definition: tier0.py:24
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
void energyRegressionAndID(const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result)
GlobalPoint getPositionLayer(int layer, bool nose=false) const
Definition: RecHitTools.cc:152
void setGeometry(CaloGeometry const &)
Definition: RecHitTools.cc:79
static constexpr int nPhiBins
const unsigned int shower_start_max_layer_
void assignPCAtoTracksters(std::vector< Trackster > &, const std::vector< reco::CaloCluster > &, const edm::ValueMap< std::pair< float, float >> &, double, bool computeLocalTime=false, bool energyWeight=true)
const float root_doublet_max_distance_from_seed_squared_
tmp
align.sh
Definition: createJobs.py:716
unsigned int lastLayerEE(bool nose=false) const
Definition: RecHitTools.h:76
#define LogDebug(id)
unsigned int lastLayer(bool nose=false) const
Definition: RecHitTools.h:80
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:381

◆ mergeTrackstersTRK()

template<typename TILES >
void PatternRecognitionbyCA::mergeTrackstersTRK ( const std::vector< Trackster > &  input,
const std::vector< reco::CaloCluster > &  layerClusters,
std::vector< Trackster > &  output,
std::unordered_map< int, std::vector< int >> &  seedToTracksterAssociation 
) const
private

Definition at line 274 of file PatternRecognitionbyCA.cc.

References ticl::Basic, filterCSVwithJSON::copy, HLT_2024v13_cff::distance, spr::find(), input, dqmiolumiharvest::j, LogDebug, GetRecoTauVFromDQM_MC_cff::next, and jetUpdater_cfi::sort.

278  {
279  output.reserve(input.size());
280  for (auto &thisSeed : seedToTracksterAssociation) {
281  auto &tracksters = thisSeed.second;
282  if (!tracksters.empty()) {
283  auto numberOfTrackstersInSeed = tracksters.size();
284  output.emplace_back(input[tracksters[0]]);
285  auto &outTrackster = output.back();
286  tracksters[0] = output.size() - 1;
287  auto updated_size = outTrackster.vertices().size();
288  for (unsigned int j = 1; j < numberOfTrackstersInSeed; ++j) {
289  auto &thisTrackster = input[tracksters[j]];
290  updated_size += thisTrackster.vertices().size();
292  LogDebug("HGCPatternRecoByCA") << "Updated size: " << updated_size << std::endl;
293  }
294  outTrackster.vertices().reserve(updated_size);
295  outTrackster.vertex_multiplicity().reserve(updated_size);
296  std::copy(std::begin(thisTrackster.vertices()),
297  std::end(thisTrackster.vertices()),
298  std::back_inserter(outTrackster.vertices()));
299  std::copy(std::begin(thisTrackster.vertex_multiplicity()),
300  std::end(thisTrackster.vertex_multiplicity()),
301  std::back_inserter(outTrackster.vertex_multiplicity()));
302  }
303  tracksters.resize(1);
304 
305  // Find duplicate LCs
306  auto &orig_vtx = outTrackster.vertices();
307  auto vtx_sorted{orig_vtx};
308  std::sort(std::begin(vtx_sorted), std::end(vtx_sorted));
309  for (unsigned int iLC = 1; iLC < vtx_sorted.size(); ++iLC) {
310  if (vtx_sorted[iLC] == vtx_sorted[iLC - 1]) {
311  // Clean up duplicate LCs
312  const auto lcIdx = vtx_sorted[iLC];
313  const auto firstEl = std::find(orig_vtx.begin(), orig_vtx.end(), lcIdx);
314  const auto firstPos = std::distance(std::begin(orig_vtx), firstEl);
315  auto iDup = std::find(std::next(firstEl), orig_vtx.end(), lcIdx);
316  while (iDup != orig_vtx.end()) {
317  orig_vtx.erase(iDup);
318  outTrackster.vertex_multiplicity().erase(outTrackster.vertex_multiplicity().begin() +
319  std::distance(std::begin(orig_vtx), iDup));
320  outTrackster.vertex_multiplicity()[firstPos] -= 1;
321  iDup = std::find(std::next(firstEl), orig_vtx.end(), lcIdx);
322  };
323  }
324  }
325  }
326  }
327  output.shrink_to_fit();
328 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
static std::string const input
Definition: EdmProvDump.cc:50
Definition: output.py:1
#define LogDebug(id)

Member Data Documentation

◆ caloGeomToken_

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

Definition at line 37 of file PatternRecognitionbyCA.h.

◆ check_missing_layers_

template<typename TILES >
bool ticl::PatternRecognitionbyCA< TILES >::check_missing_layers_ = false
private

Definition at line 49 of file PatternRecognitionbyCA.h.

◆ computeLocalTime_

template<typename TILES >
const bool ticl::PatternRecognitionbyCA< TILES >::computeLocalTime_
private

Definition at line 64 of file PatternRecognitionbyCA.h.

◆ eidInputName_

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

Definition at line 58 of file PatternRecognitionbyCA.h.

◆ eidMinClusterEnergy_

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

Definition at line 61 of file PatternRecognitionbyCA.h.

◆ eidNClusters_

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

Definition at line 63 of file PatternRecognitionbyCA.h.

◆ eidNFeatures_

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

Definition at line 70 of file PatternRecognitionbyCA.h.

◆ eidNLayers_

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

Definition at line 62 of file PatternRecognitionbyCA.h.

◆ eidOutputNameEnergy_

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

Definition at line 59 of file PatternRecognitionbyCA.h.

◆ eidOutputNameId_

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

Definition at line 60 of file PatternRecognitionbyCA.h.

◆ eidSession_

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

Definition at line 67 of file PatternRecognitionbyCA.h.

◆ energy_em_over_total_threshold_

template<typename TILES >
const double ticl::PatternRecognitionbyCA< TILES >::energy_em_over_total_threshold_
private

Definition at line 54 of file PatternRecognitionbyCA.h.

◆ etaLimitIncreaseWindow_

template<typename TILES >
const float ticl::PatternRecognitionbyCA< TILES >::etaLimitIncreaseWindow_
private

Definition at line 46 of file PatternRecognitionbyCA.h.

◆ filter_on_categories_

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

Definition at line 52 of file PatternRecognitionbyCA.h.

◆ max_delta_time_

template<typename TILES >
const float ticl::PatternRecognitionbyCA< TILES >::max_delta_time_
private

Definition at line 57 of file PatternRecognitionbyCA.h.

◆ max_longitudinal_sigmaPCA_

template<typename TILES >
const double ticl::PatternRecognitionbyCA< TILES >::max_longitudinal_sigmaPCA_
private

Definition at line 55 of file PatternRecognitionbyCA.h.

◆ max_missing_layers_in_trackster_

template<typename TILES >
const int ticl::PatternRecognitionbyCA< TILES >::max_missing_layers_in_trackster_
private

Definition at line 48 of file PatternRecognitionbyCA.h.

◆ max_out_in_hops_

template<typename TILES >
const unsigned int ticl::PatternRecognitionbyCA< TILES >::max_out_in_hops_
private

Definition at line 42 of file PatternRecognitionbyCA.h.

◆ min_clusters_per_ntuplet_

template<typename TILES >
const int ticl::PatternRecognitionbyCA< TILES >::min_clusters_per_ntuplet_
private

Definition at line 56 of file PatternRecognitionbyCA.h.

◆ min_cos_pointing_

template<typename TILES >
const float ticl::PatternRecognitionbyCA< TILES >::min_cos_pointing_
private

Definition at line 44 of file PatternRecognitionbyCA.h.

◆ min_cos_theta_

template<typename TILES >
const float ticl::PatternRecognitionbyCA< TILES >::min_cos_theta_
private

Definition at line 43 of file PatternRecognitionbyCA.h.

◆ min_layers_per_trackster_

template<typename TILES >
const unsigned int ticl::PatternRecognitionbyCA< TILES >::min_layers_per_trackster_
private

Definition at line 51 of file PatternRecognitionbyCA.h.

◆ oneTracksterPerTrackSeed_

template<typename TILES >
const bool ticl::PatternRecognitionbyCA< TILES >::oneTracksterPerTrackSeed_
private

Definition at line 39 of file PatternRecognitionbyCA.h.

◆ out_in_dfs_

template<typename TILES >
const bool ticl::PatternRecognitionbyCA< TILES >::out_in_dfs_
private

Definition at line 41 of file PatternRecognitionbyCA.h.

◆ pid_threshold_

template<typename TILES >
const double ticl::PatternRecognitionbyCA< TILES >::pid_threshold_
private

Definition at line 53 of file PatternRecognitionbyCA.h.

◆ promoteEmptyRegionToTrackster_

template<typename TILES >
const bool ticl::PatternRecognitionbyCA< TILES >::promoteEmptyRegionToTrackster_
private

Definition at line 40 of file PatternRecognitionbyCA.h.

◆ rhtools_

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

Definition at line 66 of file PatternRecognitionbyCA.h.

◆ root_doublet_max_distance_from_seed_squared_

template<typename TILES >
const float ticl::PatternRecognitionbyCA< TILES >::root_doublet_max_distance_from_seed_squared_
private

Definition at line 45 of file PatternRecognitionbyCA.h.

◆ shower_start_max_layer_

template<typename TILES >
const unsigned int ticl::PatternRecognitionbyCA< TILES >::shower_start_max_layer_
private

Definition at line 50 of file PatternRecognitionbyCA.h.

◆ siblings_maxRSquared_

template<typename TILES >
const std::vector<double> ticl::PatternRecognitionbyCA< TILES >::siblings_maxRSquared_
private

Definition at line 68 of file PatternRecognitionbyCA.h.

◆ skip_layers_

template<typename TILES >
const int ticl::PatternRecognitionbyCA< TILES >::skip_layers_
private

Definition at line 47 of file PatternRecognitionbyCA.h.

◆ theGraph_

template<typename TILES >
const std::unique_ptr<HGCGraphT<TILES> > ticl::PatternRecognitionbyCA< TILES >::theGraph_
private

Definition at line 38 of file PatternRecognitionbyCA.h.