CMS 3D CMS Logo

TracksterLinkingbySuperClusteringMustache.cc
Go to the documentation of this file.
1 #include <string>
2 #include <memory>
3 #include <algorithm>
4 
9 
14 
15 using namespace ticl;
16 
18  const edm::ParameterSet& ps, edm::ConsumesCollector iC, cms::Ort::ONNXRuntime const* onnxRuntime)
19  : TracksterLinkingAlgoBase(ps, iC, onnxRuntime),
20  ecalMustacheSCParametersToken_(iC.esConsumes<EcalMustacheSCParameters, EcalMustacheSCParametersRcd>()),
21  ecalSCDynamicDPhiParametersToken_(iC.esConsumes<EcalSCDynamicDPhiParameters, EcalSCDynamicDPhiParametersRcd>()),
22  seedThresholdPt_(ps.getParameter<double>("seedThresholdPt")),
23  candidateEnergyThreshold_(ps.getParameter<double>("candidateEnergyThreshold")),
24  filterByTracksterPID_(ps.getParameter<bool>("filterByTracksterPID")),
25  tracksterPIDCategoriesToFilter_(ps.getParameter<std::vector<int>>("tracksterPIDCategoriesToFilter")),
26  PIDThreshold_(ps.getParameter<double>("PIDThreshold")) {}
27 
29  const hgcal::RecHitTools rhtools,
30  const edm::ESHandle<MagneticField> bfieldH,
31  const edm::ESHandle<Propagator> propH) {}
32 
36 }
37 
40  float probTotal = 0.0f;
42  probTotal += tst.id_probabilities(cat);
43  }
44  return probTotal >= PIDThreshold_;
45  } else
46  return true;
47 }
48 
56  const Inputs& input,
57  std::vector<Trackster>& resultTracksters,
58  std::vector<std::vector<unsigned int>>& outputSuperclusters,
59  std::vector<std::vector<unsigned int>>& linkedTracksterIdToInputTracksterId) {
60  // For now we use all input tracksters for superclustering. At some point there might be a filter here for EM tracksters (electromagnetic identification with DNN ?)
61  auto const& inputTracksters = input.tracksters;
62  const unsigned int tracksterCount = inputTracksters.size();
63 
64  /* Sorting tracksters by decreasing order of pT (out-of-place sort).
65  inputTracksters[trackstersIndicesPt[0]], ..., inputTracksters[trackstersIndicesPt[N]] makes a list of tracksters sorted by decreasing pT
66  Indices into this pT sorted collection will have the suffix _pt. Thus inputTracksters[index] and inputTracksters[trackstersIndicesPt[index_pt]] are correct
67  */
68  std::vector<unsigned int> trackstersIndicesPt(inputTracksters.size());
69  std::iota(trackstersIndicesPt.begin(), trackstersIndicesPt.end(), 0);
70  std::stable_sort(
71  trackstersIndicesPt.begin(), trackstersIndicesPt.end(), [&inputTracksters](unsigned int i1, unsigned int i2) {
72  return inputTracksters[i1].raw_pt() > inputTracksters[i2].raw_pt();
73  });
74 
75  std::vector<bool> tracksterMask_pt(tracksterCount, false); // Mask for already superclustered tracksters
76  // We also mask tracksters that don't pass the PID cut
77  for (unsigned int ts_idx_pt = 0; ts_idx_pt < tracksterCount; ts_idx_pt++) {
78  tracksterMask_pt[ts_idx_pt] = !trackstersPassesPIDCut(inputTracksters[trackstersIndicesPt[ts_idx_pt]]);
79  }
80 
81  for (unsigned int ts_seed_idx_pt = 0; ts_seed_idx_pt < tracksterCount; ts_seed_idx_pt++) {
82  Trackster const& ts_seed = inputTracksters[trackstersIndicesPt[ts_seed_idx_pt]];
83  if (ts_seed.raw_pt() <= seedThresholdPt_)
84  break; // Look only at seed tracksters passing threshold, take advantage of pt sorting for fast exit
85  if (tracksterMask_pt[ts_seed_idx_pt])
86  continue; // Trackster does not pass PID cut
87 
88  outputSuperclusters.emplace_back(std::initializer_list<unsigned int>{trackstersIndicesPt[ts_seed_idx_pt]});
89  resultTracksters.emplace_back(inputTracksters[trackstersIndicesPt[ts_seed_idx_pt]]);
90  linkedTracksterIdToInputTracksterId.emplace_back(
91  std::initializer_list<unsigned int>{trackstersIndicesPt[ts_seed_idx_pt]});
92 
93  for (unsigned int ts_cand_idx_pt = ts_seed_idx_pt + 1; ts_cand_idx_pt < tracksterCount; ts_cand_idx_pt++) {
94  if (tracksterMask_pt[ts_cand_idx_pt])
95  continue; // Trackster is either already superclustered or did not pass PID cut
96 
97  Trackster const& ts_cand = inputTracksters[trackstersIndicesPt[ts_cand_idx_pt]];
98 
99  if (ts_cand.raw_energy() <= candidateEnergyThreshold_)
100  continue;
101 
103  ts_seed.barycenter().eta(),
104  ts_seed.barycenter().phi(),
105  ts_cand.raw_energy(),
106  ts_cand.barycenter().eta(),
107  ts_cand.barycenter().phi());
108 
110  ts_seed.barycenter().eta(),
111  ts_seed.barycenter().phi(),
112  ts_cand.raw_energy(),
113  ts_cand.barycenter().eta(),
114  ts_cand.barycenter().phi())) {
115  outputSuperclusters.back().push_back(trackstersIndicesPt[ts_cand_idx_pt]);
116  resultTracksters.back().mergeTracksters(ts_cand);
117  linkedTracksterIdToInputTracksterId.back().push_back(trackstersIndicesPt[ts_cand_idx_pt]);
118  tracksterMask_pt[ts_cand_idx_pt] = true;
119  }
120  }
121  }
122 }
123 
125  TracksterLinkingAlgoBase::fillPSetDescription(desc); // adds algo_verbosity
126  desc.add<double>("seedThresholdPt", 1.)
127  ->setComment("Minimum transverse energy of trackster to be considered as seed of a supercluster");
128  desc.add<double>("candidateEnergyThreshold", 0.15)
129  ->setComment("Minimum energy of trackster to be considered as candidate for superclustering");
130  desc.add<bool>("filterByTracksterPID", true)->setComment("Filter tracksters before superclustering by PID score");
131  desc.add<std::vector<int>>(
132  "tracksterPIDCategoriesToFilter",
133  {static_cast<int>(Trackster::ParticleType::photon), static_cast<int>(Trackster::ParticleType::electron)})
134  ->setComment("List of PID particle types (ticl::Trackster::ParticleType enum) to consider for PID filtering");
135  desc.add<double>("PIDThreshold", 0.8)->setComment("PID score threshold");
136 }
edm::ESGetToken< EcalSCDynamicDPhiParameters, EcalSCDynamicDPhiParametersRcd > ecalSCDynamicDPhiParametersToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const float raw_pt() const
Definition: Trackster.h:156
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const Vector & barycenter() const
Definition: Trackster.h:159
bool inMustache(const EcalMustacheSCParameters *params, const float maxEta, const float maxPhi, const float ClustE, const float ClusEta, const float ClusPhi)
Definition: Mustache.cc:8
void linkTracksters(const Inputs &input, std::vector< Trackster > &resultTracksters, std::vector< std::vector< unsigned int >> &linkedResultTracksters, std::vector< std::vector< unsigned int >> &linkedTracksterIdToInputTracksterId) override
static std::string const input
Definition: EdmProvDump.cc:50
edm::ESGetToken< EcalMustacheSCParameters, EcalMustacheSCParametersRcd > ecalMustacheSCParametersToken_
void initialize(const HGCalDDDConstants *hgcons, const hgcal::RecHitTools rhtools, const edm::ESHandle< MagneticField > bfieldH, const edm::ESHandle< Propagator > propH) override
TracksterLinkingbySuperClusteringMustache(const edm::ParameterSet &ps, edm::ConsumesCollector iC, cms::Ort::ONNXRuntime const *onnxRuntime=nullptr)
int iEvent
Definition: GenABIO.cc:224
def cat(path)
Definition: eostools.py:401
const float raw_energy() const
Definition: Trackster.h:154
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
static void fillPSetDescription(edm::ParameterSetDescription &desc)
bool inDynamicDPhiWindow(const EcalSCDynamicDPhiParameters *params, const float seedEta, const float seedPhi, const float ClustE, const float ClusEta, const float clusPhi)
Definition: Mustache.cc:64
Definition: Common.h:10
virtual void setEvent(edm::Event &iEvent, edm::EventSetup const &iEventSetup) override
const std::array< float, 8 > & id_probabilities() const
Definition: Trackster.h:165