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