CMS 3D CMS Logo

TrackstersMergeProducer.cc
Go to the documentation of this file.
1 #include <memory> // unique_ptr
13 
24 
26 
30 
34 
37 
41 
44 
48 
49 #include "TrackstersPCA.h"
50 
51 using namespace ticl;
52 
54 public:
55  explicit TrackstersMergeProducer(const edm::ParameterSet &ps);
57  void produce(edm::Event &, const edm::EventSetup &) override;
58  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
59 
60  // static methods for handling the global cache
61  static std::unique_ptr<TrackstersCache> initializeGlobalCache(const edm::ParameterSet &);
62  static void globalEndJob(TrackstersCache *);
63 
64  void beginJob();
65  void endJob();
66 
67  void beginRun(edm::Run const &iEvent, edm::EventSetup const &es) override;
68 
69 private:
72 
73  void fillTile(TICLTracksterTiles &, const std::vector<Trackster> &, TracksterIterIndex);
74 
75  void energyRegressionAndID(const std::vector<reco::CaloCluster> &layerClusters,
76  const tensorflow::Session *,
77  std::vector<Trackster> &result) const;
78  void printTrackstersDebug(const std::vector<Trackster> &, const char *label) const;
79  void assignTimeToCandidates(std::vector<TICLCandidate> &resultCandidates) const;
80  void dumpTrackster(const Trackster &) const;
81 
82  std::unique_ptr<LinkingAlgoBase> linkingAlgo_;
83 
94  const tensorflow::Session *tfSession_;
95 
99 
103  const int eta_bin_window_;
104  const int phi_bin_window_;
105  const double pt_sigma_high_;
106  const double pt_sigma_low_;
107  const double halo_max_distance2_;
108  const double track_min_pt_;
109  const double track_min_eta_;
110  const double track_max_eta_;
112  const double cosangle_align_;
113  const double e_over_h_threshold_;
114  const double pt_neutral_threshold_;
116  const double resol_calo_scale_had_;
117  const double resol_calo_offset_em_;
118  const double resol_calo_scale_em_;
122  const float eidMinClusterEnergy_;
123  const int eidNLayers_;
124  const int eidNClusters_;
125  std::once_flag initializeGeometry_;
126 
128 
129  std::unique_ptr<GeomDet> firstDisk_[2];
130 
131  tensorflow::Session *eidSession_;
133 
134  static constexpr int eidNFeatures_ = 3;
135 
137 };
138 
140  : tracksters_clue3d_token_(consumes<std::vector<Trackster>>(ps.getParameter<edm::InputTag>("trackstersclue3d"))),
141  clusters_token_(consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_clusters"))),
142  clustersTime_token_(
143  consumes<edm::ValueMap<std::pair<float, float>>>(ps.getParameter<edm::InputTag>("layer_clustersTime"))),
144  tracks_token_(consumes<std::vector<reco::Track>>(ps.getParameter<edm::InputTag>("tracks"))),
145  tracks_time_token_(consumes<edm::ValueMap<float>>(ps.getParameter<edm::InputTag>("tracksTime"))),
146  tracks_time_quality_token_(consumes<edm::ValueMap<float>>(ps.getParameter<edm::InputTag>("tracksTimeQual"))),
147  tracks_time_err_token_(consumes<edm::ValueMap<float>>(ps.getParameter<edm::InputTag>("tracksTimeErr"))),
148  muons_token_(consumes<std::vector<reco::Muon>>(ps.getParameter<edm::InputTag>("muons"))),
149  tfDnnLabel_(ps.getParameter<std::string>("tfDnnLabel")),
150  tfDnnToken_(esConsumes(edm::ESInputTag("", tfDnnLabel_))),
151  tfSession_(nullptr),
152  geometry_token_(esConsumes<CaloGeometry, CaloGeometryRecord, edm::Transition::BeginRun>()),
153  detector_(ps.getParameter<std::string>("detector")),
154  propName_(ps.getParameter<std::string>("propagator")),
155  bfield_token_(esConsumes<MagneticField, IdealMagneticFieldRecord, edm::Transition::BeginRun>()),
156  propagator_token_(
158  optimiseAcrossTracksters_(ps.getParameter<bool>("optimiseAcrossTracksters")),
159  eta_bin_window_(ps.getParameter<int>("eta_bin_window")),
160  phi_bin_window_(ps.getParameter<int>("phi_bin_window")),
161  pt_sigma_high_(ps.getParameter<double>("pt_sigma_high")),
162  pt_sigma_low_(ps.getParameter<double>("pt_sigma_low")),
163  halo_max_distance2_(ps.getParameter<double>("halo_max_distance2")),
164  track_min_pt_(ps.getParameter<double>("track_min_pt")),
165  track_min_eta_(ps.getParameter<double>("track_min_eta")),
166  track_max_eta_(ps.getParameter<double>("track_max_eta")),
167  track_max_missing_outerhits_(ps.getParameter<int>("track_max_missing_outerhits")),
168  cosangle_align_(ps.getParameter<double>("cosangle_align")),
169  e_over_h_threshold_(ps.getParameter<double>("e_over_h_threshold")),
170  pt_neutral_threshold_(ps.getParameter<double>("pt_neutral_threshold")),
171  resol_calo_offset_had_(ps.getParameter<double>("resol_calo_offset_had")),
172  resol_calo_scale_had_(ps.getParameter<double>("resol_calo_scale_had")),
173  resol_calo_offset_em_(ps.getParameter<double>("resol_calo_offset_em")),
174  resol_calo_scale_em_(ps.getParameter<double>("resol_calo_scale_em")),
175  eidInputName_(ps.getParameter<std::string>("eid_input_name")),
176  eidOutputNameEnergy_(ps.getParameter<std::string>("eid_output_name_energy")),
177  eidOutputNameId_(ps.getParameter<std::string>("eid_output_name_id")),
178  eidMinClusterEnergy_(ps.getParameter<double>("eid_min_cluster_energy")),
179  eidNLayers_(ps.getParameter<int>("eid_n_layers")),
180  eidNClusters_(ps.getParameter<int>("eid_n_clusters")),
181  eidSession_(nullptr) {
182  produces<std::vector<Trackster>>();
183  produces<std::vector<TICLCandidate>>();
184 
185  std::string detectorName_ = (detector_ == "HFNose") ? "HGCalHFNoseSensitive" : "HGCalEESensitive";
186  hdc_token_ =
187  esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag("", detectorName_));
188 
189  auto linkingPSet = ps.getParameter<edm::ParameterSet>("linkingPSet");
190  auto algoType = linkingPSet.getParameter<std::string>("type");
191  linkingAlgo_ = LinkingAlgoFactory::get()->create(algoType, linkingPSet);
192 }
193 
195 
197 
200  hgcons_ = hdc.product();
201 
204 
207 
208  linkingAlgo_->initialize(hgcons_, rhtools_, bfield, propagator);
209 };
210 
212  const std::vector<Trackster> &tracksters,
213  TracksterIterIndex tracksterIteration) {
214  int tracksterId = 0;
215  for (auto const &t : tracksters) {
216  tracksterTile.fill(tracksterIteration, t.barycenter().eta(), t.barycenter().phi(), tracksterId);
217  LogDebug("TrackstersMergeProducer") << "Adding tracksterId: " << tracksterId << " into bin [eta,phi]: [ "
218  << tracksterTile[tracksterIteration].etaBin(t.barycenter().eta()) << ", "
219  << tracksterTile[tracksterIteration].phiBin(t.barycenter().phi())
220  << "] for iteration: " << tracksterIteration << std::endl;
221 
222  tracksterId++;
223  }
224 }
225 
227  auto e_over_h = (t.raw_em_pt() / ((t.raw_pt() - t.raw_em_pt()) != 0. ? (t.raw_pt() - t.raw_em_pt()) : 1.));
228  LogDebug("TrackstersMergeProducer")
229  << "\nTrackster raw_pt: " << t.raw_pt() << " raw_em_pt: " << t.raw_em_pt() << " eoh: " << e_over_h
230  << " barycenter: " << t.barycenter() << " eta,phi (baricenter): " << t.barycenter().eta() << ", "
231  << t.barycenter().phi() << " eta,phi (eigen): " << t.eigenvectors(0).eta() << ", " << t.eigenvectors(0).phi()
232  << " pt(eigen): " << std::sqrt(t.eigenvectors(0).Unit().perp2()) * t.raw_energy() << " seedID: " << t.seedID()
233  << " seedIndex: " << t.seedIndex() << " size: " << t.vertices().size() << " average usage: "
234  << (std::accumulate(std::begin(t.vertex_multiplicity()), std::end(t.vertex_multiplicity()), 0.) /
235  (float)t.vertex_multiplicity().size())
236  << " raw_energy: " << t.raw_energy() << " regressed energy: " << t.regressed_energy()
237  << " probs(ga/e/mu/np/cp/nh/am/unk): ";
238  for (auto const &p : t.id_probabilities()) {
239  LogDebug("TrackstersMergeProducer") << std::fixed << p << " ";
240  }
241  LogDebug("TrackstersMergeProducer") << " sigmas: ";
242  for (auto const &s : t.sigmas()) {
243  LogDebug("TrackstersMergeProducer") << s << " ";
244  }
245  LogDebug("TrackstersMergeProducer") << std::endl;
246 }
247 
249  auto resultTrackstersMerged = std::make_unique<std::vector<Trackster>>();
250  auto resultCandidates = std::make_unique<std::vector<TICLCandidate>>();
251  auto resultFromTracks = std::make_unique<std::vector<TICLCandidate>>();
252  tfSession_ = es.getData(tfDnnToken_).getSession();
253 
254  edm::Handle<std::vector<Trackster>> trackstersclue3d_h;
255  evt.getByToken(tracksters_clue3d_token_, trackstersclue3d_h);
256 
258  evt.getByToken(tracks_token_, track_h);
259  const auto &tracks = *track_h;
260 
261  const auto &layerClusters = evt.get(clusters_token_);
262  const auto &layerClustersTimes = evt.get(clustersTime_token_);
263  const auto &muons = evt.get(muons_token_);
264  const auto &trackTime = evt.get(tracks_time_token_);
265  const auto &trackTimeErr = evt.get(tracks_time_err_token_);
266  const auto &trackTimeQual = evt.get(tracks_time_quality_token_);
267 
268  // Linking
269  linkingAlgo_->linkTracksters(
270  track_h, trackTime, trackTimeErr, trackTimeQual, muons, trackstersclue3d_h, *resultCandidates, *resultFromTracks);
271 
272  // Print debug info
273  LogDebug("TrackstersMergeProducer") << "Results from the linking step : " << std::endl
274  << "No. of Tracks : " << tracks.size()
275  << " No. of Tracksters : " << (*trackstersclue3d_h).size() << std::endl
276  << "(neutral candidates have track id -1)" << std::endl;
277 
278  std::vector<TICLCandidate> &candidates = *resultCandidates;
279  for (const auto &cand : candidates) {
280  auto track_ptr = cand.trackPtr();
281  auto trackster_ptrs = cand.tracksters();
282 
283 #ifdef EDM_ML_DEBUG
284  auto track_idx = track_ptr.get() - (edm::Ptr<reco::Track>(track_h, 0)).get();
285  track_idx = (track_ptr.isNull()) ? -1 : track_idx;
286  LogDebug("TrackstersMergeProducer") << "PDG ID " << cand.pdgId() << " charge " << cand.charge() << " p " << cand.p()
287  << std::endl;
288  LogDebug("TrackstersMergeProducer") << "track id (p) : " << track_idx << " ("
289  << (track_ptr.isNull() ? -1 : track_ptr->p()) << ") "
290  << " trackster ids (E) : ";
291 #endif
292 
293  // Merge included tracksters
294  ticl::Trackster outTrackster;
295  auto updated_size = 0;
296  for (const auto &ts_ptr : trackster_ptrs) {
297 #ifdef EDM_ML_DEBUG
298  auto ts_idx = ts_ptr.get() - (edm::Ptr<ticl::Trackster>(trackstersclue3d_h, 0)).get();
299  LogDebug("TrackstersMergeProducer") << ts_idx << " (" << ts_ptr->raw_energy() << ") ";
300 #endif
301 
302  auto &thisTrackster = *ts_ptr;
303  updated_size += thisTrackster.vertices().size();
304  outTrackster.vertices().reserve(updated_size);
305  outTrackster.vertex_multiplicity().reserve(updated_size);
306  std::copy(std::begin(thisTrackster.vertices()),
307  std::end(thisTrackster.vertices()),
308  std::back_inserter(outTrackster.vertices()));
309  std::copy(std::begin(thisTrackster.vertex_multiplicity()),
310  std::end(thisTrackster.vertex_multiplicity()),
311  std::back_inserter(outTrackster.vertex_multiplicity()));
312  }
313 
314  LogDebug("TrackstersMergeProducer") << std::endl;
315 
316  // Find duplicate LCs
317  auto &orig_vtx = outTrackster.vertices();
318  auto vtx_sorted{orig_vtx};
319  std::sort(std::begin(vtx_sorted), std::end(vtx_sorted));
320  for (unsigned int iLC = 1; iLC < vtx_sorted.size(); ++iLC) {
321  if (vtx_sorted[iLC] == vtx_sorted[iLC - 1]) {
322  // Clean up duplicate LCs
323  const auto lcIdx = vtx_sorted[iLC];
324  const auto firstEl = std::find(orig_vtx.begin(), orig_vtx.end(), lcIdx);
325  const auto firstPos = std::distance(std::begin(orig_vtx), firstEl);
326  auto iDup = std::find(std::next(firstEl), orig_vtx.end(), lcIdx);
327  while (iDup != orig_vtx.end()) {
328  orig_vtx.erase(iDup);
329  outTrackster.vertex_multiplicity().erase(outTrackster.vertex_multiplicity().begin() +
330  std::distance(std::begin(orig_vtx), iDup));
331  outTrackster.vertex_multiplicity()[firstPos] -= 1;
332  iDup = std::find(std::next(firstEl), orig_vtx.end(), lcIdx);
333  };
334  }
335  }
336 
337  outTrackster.zeroProbabilities();
338  if (!track_ptr.isNull())
339  outTrackster.setSeed(track_h.id(), track_ptr.get() - (edm::Ptr<reco::Track>(track_h, 0)).get());
340  if (!outTrackster.vertices().empty()) {
341  resultTrackstersMerged->push_back(outTrackster);
342  }
343  }
344 
345  assignPCAtoTracksters(*resultTrackstersMerged,
347  layerClustersTimes,
349  energyRegressionAndID(layerClusters, tfSession_, *resultTrackstersMerged);
350 
351  //filling the TICLCandidates information
352  assert(resultTrackstersMerged->size() == resultCandidates->size());
353 
354  auto isHad = [](const Trackster &tracksterMerge) {
355  return tracksterMerge.id_probability(Trackster::ParticleType::photon) +
356  tracksterMerge.id_probability(Trackster::ParticleType::electron) <
357  0.5;
358  };
359  for (size_t i = 0; i < resultTrackstersMerged->size(); i++) {
360  auto const &tm = (*resultTrackstersMerged)[i];
361  auto &cand = (*resultCandidates)[i];
362  //common properties
363  cand.setIdProbabilities(tm.id_probabilities());
364  //charged candidates
365  if (!cand.trackPtr().isNull()) {
366  auto pdgId = isHad(tm) ? 211 : 11;
367  auto const &tk = cand.trackPtr().get();
368  cand.setPdgId(pdgId * tk->charge());
369  cand.setCharge(tk->charge());
370  cand.setRawEnergy(tm.raw_energy());
371  auto const &regrE = tm.regressed_energy();
372  math::XYZTLorentzVector p4(regrE * tk->momentum().unit().x(),
373  regrE * tk->momentum().unit().y(),
374  regrE * tk->momentum().unit().z(),
375  regrE);
376  cand.setP4(p4);
377  } else { // neutral candidates
378  auto pdgId = isHad(tm) ? 130 : 22;
379  cand.setPdgId(pdgId);
380  cand.setCharge(0);
381  cand.setRawEnergy(tm.raw_energy());
382  const float &regrE = tm.regressed_energy();
383  math::XYZTLorentzVector p4(regrE * tm.barycenter().unit().x(),
384  regrE * tm.barycenter().unit().y(),
385  regrE * tm.barycenter().unit().z(),
386  regrE);
387  cand.setP4(p4);
388  }
389  }
390  for (auto &cand : *resultFromTracks) { //Tracks with no linked tracksters are promoted to charged hadron candidates
391  auto const &tk = cand.trackPtr().get();
392  cand.setPdgId(211 * tk->charge());
393  cand.setCharge(tk->charge());
394  const float energy = std::sqrt(tk->p() * tk->p() + ticl::mpion2);
395  cand.setRawEnergy(energy);
396  math::PtEtaPhiMLorentzVector p4Polar(tk->pt(), tk->eta(), tk->phi(), ticl::mpion);
397  cand.setP4(p4Polar);
398  }
399  // Compute timing
400  resultCandidates->insert(resultCandidates->end(), resultFromTracks->begin(), resultFromTracks->end());
401  assignTimeToCandidates(*resultCandidates);
402 
403  evt.put(std::move(resultTrackstersMerged));
404  evt.put(std::move(resultCandidates));
405 }
406 
407 void TrackstersMergeProducer::energyRegressionAndID(const std::vector<reco::CaloCluster> &layerClusters,
408  const tensorflow::Session *eidSession,
409  std::vector<Trackster> &tracksters) const {
410  // Energy regression and particle identification strategy:
411  //
412  // 1. Set default values for regressed energy and particle id for each trackster.
413  // 2. Store indices of tracksters whose total sum of cluster energies is above the
414  // eidMinClusterEnergy_ (GeV) threshold. Inference is not applied for soft tracksters.
415  // 3. When no trackster passes the selection, return.
416  // 4. Create input and output tensors. The batch dimension is determined by the number of
417  // selected tracksters.
418  // 5. Fill input tensors with layer cluster features. Per layer, clusters are ordered descending
419  // by energy. Given that tensor data is contiguous in memory, we can use pointer arithmetic to
420  // fill values, even with batching.
421  // 6. Zero-fill features for empty clusters in each layer.
422  // 7. Batched inference.
423  // 8. Assign the regressed energy and id probabilities to each trackster.
424  //
425  // Indices used throughout this method:
426  // i -> batch element / trackster
427  // j -> layer
428  // k -> cluster
429  // l -> feature
430 
431  // do nothing when no trackster passes the selection (3)
432  int batchSize = (int)tracksters.size();
433  if (batchSize == 0) {
434  return;
435  }
436 
437  for (auto &t : tracksters) {
438  t.setRegressedEnergy(0.f);
439  t.zeroProbabilities();
440  }
441 
442  // create input and output tensors (4)
443  tensorflow::TensorShape shape({batchSize, eidNLayers_, eidNClusters_, eidNFeatures_});
444  tensorflow::Tensor input(tensorflow::DT_FLOAT, shape);
446  static constexpr int inputDimension = 4;
447 
448  std::vector<tensorflow::Tensor> outputs;
449  std::vector<std::string> outputNames;
450  if (!eidOutputNameEnergy_.empty()) {
452  }
453  if (!eidOutputNameId_.empty()) {
454  outputNames.push_back(eidOutputNameId_);
455  }
456 
457  // fill input tensor (5)
458  for (int i = 0; i < batchSize; i++) {
459  const Trackster &trackster = tracksters[i];
460 
461  // per layer, we only consider the first eidNClusters_ clusters in terms of
462  // energy, so in order to avoid creating large / nested structures to do
463  // the sorting for an unknown number of total clusters, create a sorted
464  // list of layer cluster indices to keep track of the filled clusters
465  std::vector<int> clusterIndices(trackster.vertices().size());
466  for (int k = 0; k < (int)trackster.vertices().size(); k++) {
467  clusterIndices[k] = k;
468  }
469  sort(clusterIndices.begin(), clusterIndices.end(), [&layerClusters, &trackster](const int &a, const int &b) {
470  return layerClusters[trackster.vertices(a)].energy() > layerClusters[trackster.vertices(b)].energy();
471  });
472 
473  // keep track of the number of seen clusters per layer
474  std::vector<int> seenClusters(eidNLayers_);
475 
476  // loop through clusters by descending energy
477  for (const int &k : clusterIndices) {
478  // get features per layer and cluster and store the values directly in the input tensor
479  const reco::CaloCluster &cluster = layerClusters[trackster.vertices(k)];
480  int j = rhtools_.getLayerWithOffset(cluster.hitsAndFractions()[0].first) - 1;
481  if (j < eidNLayers_ && seenClusters[j] < eidNClusters_) {
482  // get the pointer to the first feature value for the current batch, layer and cluster
483  float *features = &input.tensor<float, inputDimension>()(i, j, seenClusters[j], 0);
484 
485  // fill features
486  *(features++) = float(cluster.energy() / float(trackster.vertex_multiplicity(k)));
487  *(features++) = float(std::abs(cluster.eta()));
488  *(features) = float(cluster.phi());
489 
490  // increment seen clusters
491  seenClusters[j]++;
492  }
493  }
494 
495  // zero-fill features of empty clusters in each layer (6)
496  for (int j = 0; j < eidNLayers_; j++) {
497  for (int k = seenClusters[j]; k < eidNClusters_; k++) {
498  float *features = &input.tensor<float, inputDimension>()(i, j, k, 0);
499  for (int l = 0; l < eidNFeatures_; l++) {
500  *(features++) = 0.f;
501  }
502  }
503  }
504  }
505 
506  // run the inference (7)
508 
509  // store regressed energy per trackster (8)
510  if (!eidOutputNameEnergy_.empty()) {
511  // get the pointer to the energy tensor, dimension is batch x 1
512  float *energy = outputs[0].flat<float>().data();
513 
514  for (int i = 0; i < batchSize; ++i) {
515  float regressedEnergy =
516  tracksters[i].raw_energy() > eidMinClusterEnergy_ ? energy[i] : tracksters[i].raw_energy();
517  tracksters[i].setRegressedEnergy(regressedEnergy);
518  }
519  }
520 
521  // store id probabilities per trackster (8)
522  if (!eidOutputNameId_.empty()) {
523  // get the pointer to the id probability tensor, dimension is batch x id_probabilities.size()
524  int probsIdx = !eidOutputNameEnergy_.empty();
525  float *probs = outputs[probsIdx].flat<float>().data();
526  int probsNumber = tracksters[0].id_probabilities().size();
527  for (int i = 0; i < batchSize; ++i) {
528  tracksters[i].setProbabilities(&probs[i * probsNumber]);
529  }
530  }
531 }
532 
533 void TrackstersMergeProducer::assignTimeToCandidates(std::vector<TICLCandidate> &resultCandidates) const {
534  for (auto &cand : resultCandidates) {
535  if (cand.tracksters().size() > 1) { // For single-trackster candidates the timing is already set
536  float time = 0.f;
537  float timeErr = 0.f;
538  for (const auto &tr : cand.tracksters()) {
539  if (tr->timeError() > 0) {
540  auto invTimeESq = pow(tr->timeError(), -2);
541  time += tr->time() * invTimeESq;
542  timeErr += invTimeESq;
543  }
544  }
545  if (timeErr > 0) {
546  timeErr = 1. / timeErr;
547 
548  cand.setTime(time * timeErr);
549  cand.setTimeError(sqrt(timeErr));
550  }
551  }
552  }
553 }
554 
555 void TrackstersMergeProducer::printTrackstersDebug(const std::vector<Trackster> &tracksters, const char *label) const {
556 #ifdef EDM_ML_DEBUG
557  int counter = 0;
558  for (auto const &t : tracksters) {
559  LogDebug("TrackstersMergeProducer")
560  << counter++ << " TrackstersMergeProducer (" << label << ") obj barycenter: " << t.barycenter()
561  << " eta,phi (baricenter): " << t.barycenter().eta() << ", " << t.barycenter().phi()
562  << " eta,phi (eigen): " << t.eigenvectors(0).eta() << ", " << t.eigenvectors(0).phi()
563  << " pt(eigen): " << std::sqrt(t.eigenvectors(0).Unit().perp2()) * t.raw_energy() << " seedID: " << t.seedID()
564  << " seedIndex: " << t.seedIndex() << " size: " << t.vertices().size() << " average usage: "
565  << (std::accumulate(std::begin(t.vertex_multiplicity()), std::end(t.vertex_multiplicity()), 0.) /
566  (float)t.vertex_multiplicity().size())
567  << " raw_energy: " << t.raw_energy() << " regressed energy: " << t.regressed_energy()
568  << " probs(ga/e/mu/np/cp/nh/am/unk): ";
569  for (auto const &p : t.id_probabilities()) {
570  LogDebug("TrackstersMergeProducer") << std::fixed << p << " ";
571  }
572  LogDebug("TrackstersMergeProducer") << " sigmas: ";
573  for (auto const &s : t.sigmas()) {
574  LogDebug("TrackstersMergeProducer") << s << " ";
575  }
576  LogDebug("TrackstersMergeProducer") << std::endl;
577  }
578 #endif
579 }
580 
583 
584  edm::ParameterSetDescription linkingDesc;
585  linkingDesc.addNode(edm::PluginDescription<LinkingAlgoFactory>("type", "LinkingAlgoByDirectionGeometric", true));
586  desc.add<edm::ParameterSetDescription>("linkingPSet", linkingDesc);
587 
588  desc.add<edm::InputTag>("trackstersclue3d", edm::InputTag("ticlTrackstersCLUE3DHigh"));
589  desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalLayerClusters"));
590  desc.add<edm::InputTag>("layer_clustersTime", edm::InputTag("hgcalLayerClusters", "timeLayerCluster"));
591  desc.add<edm::InputTag>("tracks", edm::InputTag("generalTracks"));
592  desc.add<edm::InputTag>("tracksTime", edm::InputTag("tofPID:t0"));
593  desc.add<edm::InputTag>("tracksTimeQual", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA"));
594  desc.add<edm::InputTag>("tracksTimeErr", edm::InputTag("tofPID:sigmat0"));
595  desc.add<edm::InputTag>("muons", edm::InputTag("muons1stStep"));
596  desc.add<std::string>("detector", "HGCAL");
597  desc.add<std::string>("propagator", "PropagatorWithMaterial");
598  desc.add<bool>("optimiseAcrossTracksters", true);
599  desc.add<int>("eta_bin_window", 1);
600  desc.add<int>("phi_bin_window", 1);
601  desc.add<double>("pt_sigma_high", 2.);
602  desc.add<double>("pt_sigma_low", 2.);
603  desc.add<double>("halo_max_distance2", 4.);
604  desc.add<double>("track_min_pt", 1.);
605  desc.add<double>("track_min_eta", 1.48);
606  desc.add<double>("track_max_eta", 3.);
607  desc.add<int>("track_max_missing_outerhits", 5);
608  desc.add<double>("cosangle_align", 0.9945);
609  desc.add<double>("e_over_h_threshold", 1.);
610  desc.add<double>("pt_neutral_threshold", 2.);
611  desc.add<double>("resol_calo_offset_had", 1.5);
612  desc.add<double>("resol_calo_scale_had", 0.15);
613  desc.add<double>("resol_calo_offset_em", 1.5);
614  desc.add<double>("resol_calo_scale_em", 0.15);
615  desc.add<std::string>("tfDnnLabel", "tracksterSelectionTf");
616  desc.add<std::string>("eid_input_name", "input");
617  desc.add<std::string>("eid_output_name_energy", "output/regressed_energy");
618  desc.add<std::string>("eid_output_name_id", "output/id_probabilities");
619  desc.add<double>("eid_min_cluster_energy", 2.5);
620  desc.add<int>("eid_n_layers", 50);
621  desc.add<int>("eid_n_clusters", 10);
622  descriptions.add("trackstersMergeProducer", desc);
623 }
624 
ticl::Trackster::IterationIndex TracksterIterIndex
constexpr double mpion
Definition: commons.h:11
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< NamedTensor > NamedTensorList
Definition: TensorFlow.h:31
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void fillTile(TICLTracksterTiles &, const std::vector< Trackster > &, TracksterIterIndex)
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:347
const edm::EDGetTokenT< std::vector< Trackster > > tracksters_clue3d_token_
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
void assignTimeToCandidates(std::vector< TICLCandidate > &resultCandidates) const
tensorflow::Session * eidSession_
const tensorflow::Session * tfSession_
void produce(edm::Event &, const edm::EventSetup &) override
void printTrackstersDebug(const std::vector< Trackster > &, const char *label) const
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:540
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometry_token_
assert(be >=bs)
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:184
const edm::EDGetTokenT< edm::ValueMap< float > > tracks_time_quality_token_
void beginJob()
Definition: Breakpoints.cc:14
static std::string const input
Definition: EdmProvDump.cc:50
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
void assignPCAtoTracksters(std::vector< Trackster > &, const std::vector< reco::CaloCluster > &, const edm::ValueMap< std::pair< float, float >> &, double, bool energyWeight=true)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
char const * label
static constexpr int eidNFeatures_
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
const edm::EDGetTokenT< edm::ValueMap< float > > tracks_time_err_token_
Definition: Muon.py:1
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
T sqrt(T t)
Definition: SSEVec.h:19
void beginRun(edm::Run const &iEvent, edm::EventSetup const &es) override
void energyRegressionAndID(const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result) const
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:286
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
const edm::EDGetTokenT< std::vector< reco::Muon > > muons_token_
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void dumpTrackster(const Trackster &) const
string inputList
Definition: crabTemplate.py:6
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
double energy() const
cluster energy
Definition: CaloCluster.h:149
const edm::EDGetTokenT< std::vector< reco::Track > > tracks_token_
std::vector< unsigned int > & vertices()
Definition: Trackster.h:57
const std::string eidOutputNameEnergy_
std::unique_ptr< LinkingAlgoBase > linkingAlgo_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > bfield_token_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
TrackstersMergeProducer(const edm::ParameterSet &ps)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > hdc_token_
std::vector< float > & vertex_multiplicity()
Definition: Trackster.h:58
double b
Definition: hdecay.h:118
void add(std::string const &label, ParameterSetDescription const &psetDescription)
GlobalPoint getPositionLayer(int layer, bool nose=false) const
Definition: RecHitTools.cc:141
const HGCalDDDConstants * hgcons_
void setGeometry(CaloGeometry const &)
Definition: RecHitTools.cc:68
fixed size matrix
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
constexpr float mpion2
Definition: commons.h:12
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagator_token_
double a
Definition: hdecay.h:119
Definition: Common.h:8
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void fill(int index, double eta, double phi, unsigned int objectId)
Definition: TICLLayerTile.h:99
const edm::EDGetTokenT< edm::ValueMap< float > > tracks_time_token_
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:181
#define get
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511
unsigned int lastLayerEE(bool nose=false) const
Definition: RecHitTools.h:75
const edm::ESGetToken< TfGraphDefWrapper, TfGraphRecord > tfDnnToken_
Definition: Run.h:45
#define LogDebug(id)
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:365