CMS 3D CMS Logo

ParticleNetFeatureEvaluator.cc
Go to the documentation of this file.
1 #include <TVector3.h>
2 #include <TTree.h>
3 
5 
14 
22 
27 
31 
32 using namespace btagbtvdeep;
33 
35 public:
36  explicit ParticleNetFeatureEvaluator(const edm::ParameterSet &);
37  ~ParticleNetFeatureEvaluator() override;
38 
39  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
40 
41 private:
42  void beginStream(edm::StreamID) override {}
43  void produce(edm::Event &, const edm::EventSetup &) override;
44  void endStream() override {}
45  void fillParticleFeatures(DeepBoostedJetFeatures &fts,
46  const reco::Jet &jet,
47  const std::vector<math::XYZTLorentzVector> &tau_pfcandidates,
51  void fillSVFeatures(DeepBoostedJetFeatures &fts, const reco::Jet &jet);
52  void fillLostTrackFeatures(DeepBoostedJetFeatures &fts, const reco::Jet &jet);
53  bool useTrackProperties(const pat::PackedCandidate *cand);
54 
55  const double jet_radius_;
56  const double min_jet_pt_;
57  const double max_jet_eta_;
58  const double min_jet_eta_;
61  const double min_pt_for_losttrack_;
62  const double max_dr_for_losttrack_;
63  const double min_pt_for_taus_;
64  const double max_eta_for_taus_;
65  const bool include_neutrals_;
66 
77 
83 
84  const static std::vector<std::string> particle_features_;
85  const static std::vector<std::string> sv_features_;
86  const static std::vector<std::string> losttrack_features_;
87  const reco::Vertex *pv_ = nullptr;
88 
89  TTree *tree;
90  unsigned int event;
91  float jet_pt;
92  float jet_pt_raw;
93  float jet_eta;
94  float jet_phi;
95  float jet_mass;
96  unsigned int ijet;
97  std::vector<float> jet_pfcand_pt_log;
98  std::vector<float> jet_pfcand_energy_log;
99  std::vector<float> jet_pfcand_deta;
100  std::vector<float> jet_pfcand_dphi;
101  std::vector<float> jet_pfcand_eta;
102  std::vector<float> jet_pfcand_charge;
103  std::vector<float> jet_pfcand_frompv;
104  std::vector<float> jet_pfcand_nlostinnerhits;
105  std::vector<float> jet_pfcand_track_chi2;
106  std::vector<float> jet_pfcand_track_qual;
107  std::vector<float> jet_pfcand_dz;
108  std::vector<float> jet_pfcand_dzsig;
109  std::vector<float> jet_pfcand_dxy;
110  std::vector<float> jet_pfcand_dxysig;
111  std::vector<float> jet_pfcand_etarel;
112  std::vector<float> jet_pfcand_pperp_ratio;
113  std::vector<float> jet_pfcand_ppara_ratio;
114  std::vector<float> jet_pfcand_trackjet_d3d;
115  std::vector<float> jet_pfcand_trackjet_d3dsig;
116  std::vector<float> jet_pfcand_trackjet_dist;
117  std::vector<float> jet_pfcand_npixhits;
118  std::vector<float> jet_pfcand_nstriphits;
119  std::vector<float> jet_pfcand_trackjet_decayL;
120  std::vector<float> jet_pfcand_id;
121  std::vector<float> jet_pfcand_calofraction;
122  std::vector<float> jet_pfcand_hcalfraction;
123  std::vector<float> jet_pfcand_puppiw;
124  std::vector<float> jet_pfcand_muon_id;
125  std::vector<float> jet_pfcand_muon_isglobal;
126  std::vector<float> jet_pfcand_muon_chi2;
127  std::vector<float> jet_pfcand_muon_segcomp;
128  std::vector<float> jet_pfcand_muon_nvalidhit;
129  std::vector<float> jet_pfcand_muon_nstation;
130  std::vector<float> jet_pfcand_electron_detaIn;
131  std::vector<float> jet_pfcand_electron_dphiIn;
134  std::vector<float> jet_pfcand_electron_r9;
135  std::vector<float> jet_pfcand_electron_convProb;
136  std::vector<float> jet_pfcand_photon_sigIetaIeta;
137  std::vector<float> jet_pfcand_photon_r9;
138  std::vector<float> jet_pfcand_photon_eVeto;
139  std::vector<float> jet_pfcand_tau_signal;
140  std::vector<float> jet_sv_pt_log;
141  std::vector<float> jet_sv_mass;
142  std::vector<float> jet_sv_deta;
143  std::vector<float> jet_sv_dphi;
144  std::vector<float> jet_sv_eta;
145  std::vector<float> jet_sv_ntrack;
146  std::vector<float> jet_sv_chi2;
147  std::vector<float> jet_sv_dxy;
148  std::vector<float> jet_sv_dxysig;
149  std::vector<float> jet_sv_d3d;
150  std::vector<float> jet_sv_d3dsig;
151  std::vector<float> jet_losttrack_pt_log;
152  std::vector<float> jet_losttrack_eta;
153  std::vector<float> jet_losttrack_deta;
154  std::vector<float> jet_losttrack_dphi;
155  std::vector<float> jet_losttrack_charge;
156  std::vector<float> jet_losttrack_frompv;
157  std::vector<float> jet_losttrack_track_chi2;
158  std::vector<float> jet_losttrack_track_qual;
159  std::vector<float> jet_losttrack_dz;
160  std::vector<float> jet_losttrack_dxy;
161  std::vector<float> jet_losttrack_dzsig;
162  std::vector<float> jet_losttrack_dxysig;
163  std::vector<float> jet_losttrack_etarel;
164  std::vector<float> jet_losttrack_trackjet_d3d;
165  std::vector<float> jet_losttrack_trackjet_d3dsig;
166  std::vector<float> jet_losttrack_trackjet_dist;
167  std::vector<float> jet_losttrack_trackjet_decayL;
168  std::vector<float> jet_losttrack_npixhits;
169  std::vector<float> jet_losttrack_nstriphits;
170 };
171 
172 const std::vector<std::string> ParticleNetFeatureEvaluator::particle_features_{"jet_pfcand_pt_log",
173  "jet_pfcand_energy_log",
174  "jet_pfcand_deta",
175  "jet_pfcand_dphi",
176  "jet_pfcand_eta",
177  "jet_pfcand_charge",
178  "jet_pfcand_frompv",
179  "jet_pfcand_nlostinnerhits",
180  "jet_pfcand_track_chi2",
181  "jet_pfcand_track_qual",
182  "jet_pfcand_dz",
183  "jet_pfcand_dzsig",
184  "jet_pfcand_dxy",
185  "jet_pfcand_dxysig",
186  "jet_pfcand_etarel",
187  "jet_pfcand_pperp_ratio",
188  "jet_pfcand_ppara_ratio",
189  "jet_pfcand_trackjet_d3d",
190  "jet_pfcand_trackjet_d3dsig",
191  "jet_pfcand_trackjet_dist",
192  "jet_pfcand_nhits",
193  "jet_pfcand_npixhits",
194  "jet_pfcand_nstriphits",
195  "jet_pfcand_trackjet_decayL",
196  "jet_pfcand_id",
197  "jet_pfcand_calofraction",
198  "jet_pfcand_hcalfraction",
199  "jet_pfcand_puppiw",
200  "jet_pfcand_muon_id",
201  "jet_pfcand_muon_isglobal",
202  "jet_pfcand_muon_segcomp",
203  "jet_pfcand_muon_chi2",
204  "jet_pfcand_muon_nvalidhit",
205  "jet_pfcand_muon_nstation",
206  "jet_pfcand_electron_detaIn",
207  "jet_pfcand_electron_dphiIn",
208  "jet_pfcand_electron_sigIetaIeta",
209  "jet_pfcand_electron_sigIphiIphi",
210  "jet_pfcand_electron_r9",
211  "jet_pfcand_electron_convProb",
212  "jet_pfcand_photon_sigIetaIeta",
213  "jet_pfcand_photon_r9",
214  "jet_pfcand_photon_eVeto",
215  "jet_pfcand_tau_signal",
216  "pfcand_mask"};
217 
218 const std::vector<std::string> ParticleNetFeatureEvaluator::sv_features_{"jet_sv_pt_log",
219  "jet_sv_mass",
220  "jet_sv_deta",
221  "jet_sv_dphi",
222  "jet_sv_eta",
223  "jet_sv_ntrack",
224  "jet_sv_chi2",
225  "jet_sv_dxy",
226  "jet_sv_dxysig",
227  "jet_sv_d3d",
228  "jet_sv_d3dsig",
229  "sv_mask"};
230 
231 const std::vector<std::string> ParticleNetFeatureEvaluator::losttrack_features_{"jet_losttrack_pt_log",
232  "jet_losttrack_eta",
233  "jet_losttrack_deta",
234  "jet_losttrack_dphi",
235  "jet_losttrack_charge",
236  "jet_losttrack_frompv",
237  "jet_losttrack_track_chi2",
238  "jet_losttrack_track_qual",
239  "jet_losttrack_dz",
240  "jet_losttrack_dxy",
241  "jet_losttrack_dzsig",
242  "jet_losttrack_dxysig",
243  "jet_losttrack_etarel",
244  "jet_losttrack_trackjet_d3d",
245  "jet_losttrack_trackjet_d3dsig",
246  "jet_losttrack_trackjet_dist",
247  "jet_losttrack_trackjet_decayL",
248  "jet_losttrack_npixhits",
249  "jet_losttrack_nstriphits",
250  "lt_mask"};
251 
253  : jet_radius_(iConfig.getParameter<double>("jet_radius")),
254  min_jet_pt_(iConfig.getParameter<double>("min_jet_pt")),
255  max_jet_eta_(iConfig.getParameter<double>("max_jet_eta")),
256  min_jet_eta_(iConfig.getParameter<double>("min_jet_eta")),
257  min_pt_for_track_properties_(iConfig.getParameter<double>("min_pt_for_track_properties")),
258  min_pt_for_pfcandidates_(iConfig.getParameter<double>("min_pt_for_pfcandidates")),
259  min_pt_for_losttrack_(iConfig.getParameter<double>("min_pt_for_losttrack")),
260  max_dr_for_losttrack_(iConfig.getParameter<double>("max_dr_for_losttrack")),
261  min_pt_for_taus_(iConfig.getParameter<double>("min_pt_for_taus")),
262  max_eta_for_taus_(iConfig.getParameter<double>("max_eta_for_taus")),
263  include_neutrals_(iConfig.getParameter<bool>("include_neutrals")),
264  muon_token_(consumes<pat::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
265  electron_token_(consumes<pat::ElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"))),
266  photon_token_(consumes<pat::PhotonCollection>(iConfig.getParameter<edm::InputTag>("photons"))),
267  tau_token_(consumes<pat::TauCollection>(iConfig.getParameter<edm::InputTag>("taus"))),
268  jet_token_(consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("jets"))),
269  losttrack_token_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("losttracks"))),
270  vtx_token_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
271  sv_token_(consumes<reco::VertexCompositePtrCandidateCollection>(
272  iConfig.getParameter<edm::InputTag>("secondary_vertices"))),
273  pfcand_token_(consumes<edm::View<reco::Candidate>>(iConfig.getParameter<edm::InputTag>("pf_candidates"))),
274  track_builder_token_(
275  esConsumes<TransientTrackBuilder, TransientTrackRecord>(edm::ESInputTag("", "TransientTrackBuilder"))) {
276  produces<std::vector<reco::DeepBoostedJetTagInfo>>();
277 }
278 
280 
282  // pfDeepBoostedJetTagInfos
284  desc.add<double>("jet_radius", 0.8);
285  desc.add<double>("min_jet_pt", 150);
286  desc.add<double>("max_jet_eta", 99);
287  desc.add<double>("min_jet_eta", 0.0);
288  desc.add<double>("min_pt_for_track_properties", -1);
289  desc.add<double>("min_pt_for_pfcandidates", -1);
290  desc.add<double>("min_pt_for_losttrack", 1);
291  desc.add<double>("max_dr_for_losttrack", 0.4);
292  desc.add<double>("min_pt_for_taus", 20.);
293  desc.add<double>("max_eta_for_taus", 2.5);
294  desc.add<bool>("include_neutrals", true);
295  desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"));
296  desc.add<edm::InputTag>("secondary_vertices", edm::InputTag("slimmedSecondaryVertices"));
297  desc.add<edm::InputTag>("pf_candidates", edm::InputTag("packedPFCandidates"));
298  desc.add<edm::InputTag>("losttracks", edm::InputTag("lostTracks"));
299  desc.add<edm::InputTag>("jets", edm::InputTag("slimmedJetsAK8"));
300  desc.add<edm::InputTag>("muons", edm::InputTag("slimmedMuons"));
301  desc.add<edm::InputTag>("taus", edm::InputTag("slimmedTaus"));
302  desc.add<edm::InputTag>("electrons", edm::InputTag("slimmedElectrons"));
303  desc.add<edm::InputTag>("photons", edm::InputTag("slimmedPhotons"));
304  descriptions.add("ParticleNetFeatureEvaluator", desc);
305 }
306 
308  // output collection
309  auto output_tag_infos = std::make_unique<std::vector<reco::DeepBoostedJetTagInfo>>();
310  // Input jets
311  auto jets = iEvent.getHandle(jet_token_);
312  // Input muons
313  auto muons = iEvent.getHandle(muon_token_);
314  // Input taus
315  auto taus = iEvent.getHandle(tau_token_);
316  // Input electrons
317  auto electrons = iEvent.getHandle(electron_token_);
318  // Input photons
319  auto photons = iEvent.getHandle(photon_token_);
320  // Input lost tracks
321  iEvent.getByToken(losttrack_token_, losttracks_);
322  // Primary vertexes
323  iEvent.getByToken(vtx_token_, vtxs_);
324  if (vtxs_->empty()) {
325  // produce empty TagInfos in case no primary vertex
326  iEvent.put(std::move(output_tag_infos));
327  return; // exit event
328  }
329  // Leading vertex
330  pv_ = &vtxs_->at(0);
331  // Secondary vertexs
332  iEvent.getByToken(sv_token_, svs_);
333  // PF candidates
334  iEvent.getByToken(pfcand_token_, pfcands_);
335  // Track builder
336  track_builder_ = iSetup.getHandle(track_builder_token_);
337 
338  // tau signal candidates
339  std::vector<math::XYZTLorentzVector> tau_pfcandidates;
340  for (size_t itau = 0; itau < taus->size(); itau++) {
341  if (taus->at(itau).pt() < min_pt_for_taus_)
342  continue;
343  if (fabs(taus->at(itau).eta()) > max_eta_for_taus_)
344  continue;
345  for (unsigned ipart = 0; ipart < taus->at(itau).signalCands().size(); ipart++) {
347  dynamic_cast<const pat::PackedCandidate *>(taus->at(itau).signalCands()[ipart].get());
348  tau_pfcandidates.push_back(pfcand->p4());
349  }
350  }
351 
352  // Loop over jet
353  for (std::size_t jet_n = 0; jet_n < jets->size(); jet_n++) {
354  const auto &jet = (*jets)[jet_n];
355  edm::RefToBase<reco::Jet> jet_ref(jets, jet_n);
356 
357  // create jet features
359  for (const auto &name : particle_features_)
360  features.add(name);
361  for (const auto &name : sv_features_)
362  features.add(name);
363 
364  // fill values only if above pt threshold and has daughters, otherwise left
365  bool fill_vars = true;
366  if ((jet.pt() < min_jet_pt_ and
367  dynamic_cast<const pat::Jet *>(&jet)->correctedJet("Uncorrected").pt() < min_jet_pt_) or
368  std::abs(jet.eta()) >= max_jet_eta_ or std::abs(jet.eta()) < min_jet_eta_)
369  fill_vars = false;
370  if (jet.numberOfDaughters() == 0)
371  fill_vars = false;
372 
373  // fill features
374  if (fill_vars) {
375  fillParticleFeatures(features, jet, tau_pfcandidates, *muons, *electrons, *photons);
376  fillSVFeatures(features, jet);
377  fillLostTrackFeatures(features, jet);
378  features.check_consistency(particle_features_);
379  features.check_consistency(sv_features_);
380  features.check_consistency(losttrack_features_);
381  }
382 
383  // this should always be done even if features are not filled
384  output_tag_infos->emplace_back(features, jet_ref);
385  }
386  // move output collection
387  iEvent.put(std::move(output_tag_infos));
388 }
389 
391  const auto *track = cand->bestTrack();
392  return track != nullptr and track->pt() > min_pt_for_track_properties_;
393 };
394 
396  const reco::Jet &jet,
397  const std::vector<math::XYZTLorentzVector> &tau_pfcandidates,
398  const pat::MuonCollection &muons,
401  // some jet properties
402  math::XYZVector jet_dir = jet.momentum().Unit();
403  TVector3 jet_direction(jet.momentum().Unit().x(), jet.momentum().Unit().y(), jet.momentum().Unit().z());
404  GlobalVector jet_ref_track_dir(jet.px(), jet.py(), jet.pz());
405  // vertexes
406  reco::VertexRefProd PVRefProd(vtxs_);
407  // track builder
408  TrackInfoBuilder trackinfo(track_builder_);
409 
410  // make list of pf-candidates to be considered
411  std::vector<const pat::PackedCandidate *> daughters;
412  for (const auto &dau : jet.daughterPtrVector()) {
413  // remove particles w/ extremely low puppi weights
414  const pat::PackedCandidate *cand = dynamic_cast<const pat::PackedCandidate *>(&(*dau));
415  if (not cand)
416  throw edm::Exception(edm::errors::InvalidReference) << "Cannot convert to either pat::PackedCandidate";
417  // base requirements on PF candidates
418  if (cand->pt() < min_pt_for_pfcandidates_)
419  continue;
420  // charged candidate selection (for Higgs Interaction Net)
421  if (!include_neutrals_ and (cand->charge() == 0 or cand->pt() < min_pt_for_track_properties_))
422  continue;
423  // filling daughters
424  daughters.push_back(cand);
425  }
426 
427  // sort by original pt (not Puppi-weighted)
428  std::sort(daughters.begin(), daughters.end(), [](const auto &a, const auto &b) { return a->pt() > b->pt(); });
429 
430  // reserve space
431  for (const auto &name : particle_features_)
432  fts.reserve(name, daughters.size());
433 
434  // Build observables
435  for (const auto &cand : daughters) {
436  if (!include_neutrals_ and !useTrackProperties(cand))
437  continue;
438 
439  // input particle is a packed PF candidate
440  auto candP4 = cand->p4();
441  auto candP3 = cand->momentum();
442 
443  // candidate track
444  const reco::Track *track = nullptr;
445  if (useTrackProperties(cand))
446  track = cand->bestTrack();
447 
448  // reco-vertex association
449  reco::VertexRef pv_ass = reco::VertexRef(vtxs_, 0);
450  math::XYZPoint pv_ass_pos = pv_ass->position();
451 
452  TVector3 cand_direction(candP3.x(), candP3.y(), candP3.z());
453 
454  fts.fill("jet_pfcand_pt_log", std::isnan(std::log(candP4.pt())) ? 0 : std::log(candP4.pt()));
455  fts.fill("jet_pfcand_energy_log", std::isnan(std::log(candP4.energy())) ? 0 : std::log(candP4.energy()));
456  fts.fill("jet_pfcand_eta", candP4.eta());
457  fts.fill("jet_pfcand_deta", jet_direction.Eta() - cand_direction.Eta());
458  fts.fill("jet_pfcand_dphi", jet_direction.DeltaPhi(cand_direction));
459  fts.fill("jet_pfcand_charge", cand->charge());
460  fts.fill("jet_pfcand_etarel",
461  std::isnan(reco::btau::etaRel(jet_dir, candP3)) ? 0 : reco::btau::etaRel(jet_dir, candP3));
462  fts.fill("jet_pfcand_pperp_ratio",
463  std::isnan(jet_direction.Perp(cand_direction) / cand_direction.Mag())
464  ? 0
465  : jet_direction.Perp(cand_direction) / cand_direction.Mag());
466  fts.fill("jet_pfcand_ppara_ratio",
467  std::isnan(jet_direction.Dot(cand_direction) / cand_direction.Mag())
468  ? 0
469  : jet_direction.Dot(cand_direction) / cand_direction.Mag());
470  fts.fill("jet_pfcand_frompv", cand->fromPV());
471  fts.fill("jet_pfcand_dz", std::isnan(cand->dz(pv_ass_pos)) ? 0 : cand->dz(pv_ass_pos));
472  fts.fill("jet_pfcand_dxy", std::isnan(cand->dxy(pv_ass_pos)) ? 0 : cand->dxy(pv_ass_pos));
473  fts.fill("jet_pfcand_puppiw", cand->puppiWeight());
474  fts.fill("jet_pfcand_nlostinnerhits", cand->lostInnerHits());
475  fts.fill("jet_pfcand_nhits", cand->numberOfHits());
476  fts.fill("jet_pfcand_npixhits", cand->numberOfPixelHits());
477  fts.fill("jet_pfcand_nstriphits", cand->stripLayersWithMeasurement());
478 
479  if (abs(cand->pdgId()) == 11 and cand->charge() != 0)
480  fts.fill("jet_pfcand_id", 0);
481  else if (abs(cand->pdgId()) == 13 and cand->charge() != 0)
482  fts.fill("jet_pfcand_id", 1);
483  else if (abs(cand->pdgId()) == 22 and cand->charge() == 0)
484  fts.fill("jet_pfcand_id", 2);
485  else if (abs(cand->pdgId()) != 22 and cand->charge() == 0 and abs(cand->pdgId()) != 1 and abs(cand->pdgId()) != 2)
486  fts.fill("jet_pfcand_id", 3);
487  else if (abs(cand->pdgId()) != 11 and abs(cand->pdgId()) != 13 and cand->charge() != 0)
488  fts.fill("jet_pfcand_id", 4);
489  else if (cand->charge() == 0 and abs(cand->pdgId()) == 1)
490  fts.fill("jet_pfcand_id", 5);
491  else if (cand->charge() == 0 and abs(cand->pdgId()) == 2)
492  fts.fill("jet_pfcand_id", 6);
493  else
494  fts.fill("jet_pfcand_id", -1);
495 
496  fts.fill("jet_pfcand_hcalfraction", std::isnan(cand->hcalFraction()) ? 0 : cand->hcalFraction());
497  fts.fill("jet_pfcand_calofraction", std::isnan(cand->caloFraction()) ? 0 : cand->caloFraction());
498  fts.fill("pfcand_mask", 1);
499 
500  if (track) {
501  fts.fill(
502  "jet_pfcand_dzsig",
503  std::isnan(fabs(cand->dz(pv_ass_pos)) / cand->dzError()) ? 0 : fabs(cand->dz(pv_ass_pos)) / cand->dzError());
504  fts.fill("jet_pfcand_dxysig",
505  std::isnan(fabs(cand->dxy(pv_ass_pos)) / cand->dxyError())
506  ? 0
507  : fabs(cand->dxy(pv_ass_pos)) / cand->dxyError());
508  fts.fill("jet_pfcand_track_chi2", track->normalizedChi2());
509  fts.fill("jet_pfcand_track_qual", track->qualityMask());
510 
511  reco::TransientTrack transientTrack = track_builder_->build(*track);
512  Measurement1D meas_ip2d =
513  IPTools::signedTransverseImpactParameter(transientTrack, jet_ref_track_dir, *pv_).second;
514  Measurement1D meas_ip3d = IPTools::signedImpactParameter3D(transientTrack, jet_ref_track_dir, *pv_).second;
515  Measurement1D meas_jetdist = IPTools::jetTrackDistance(transientTrack, jet_ref_track_dir, *pv_).second;
516  Measurement1D meas_decayl = IPTools::signedDecayLength3D(transientTrack, jet_ref_track_dir, *pv_).second;
517 
518  fts.fill("jet_pfcand_trackjet_d3d", std::isnan(meas_ip3d.value()) ? 0 : meas_ip3d.value());
519  fts.fill("jet_pfcand_trackjet_d3dsig",
520  std::isnan(fabs(meas_ip3d.significance())) ? 0 : fabs(meas_ip3d.significance()));
521  fts.fill("jet_pfcand_trackjet_dist", std::isnan(-meas_jetdist.value()) ? 0 : -meas_jetdist.value());
522  fts.fill("jet_pfcand_trackjet_decayL", std::isnan(meas_decayl.value()) ? 0 : meas_decayl.value());
523  } else {
524  fts.fill("jet_pfcand_dzsig", 0);
525  fts.fill("jet_pfcand_dxysig", 0);
526  fts.fill("jet_pfcand_track_chi2", 0);
527  fts.fill("jet_pfcand_track_qual", 0);
528  fts.fill("jet_pfcand_trackjet_d3d", 0);
529  fts.fill("jet_pfcand_trackjet_d3dsig", 0);
530  fts.fill("jet_pfcand_trackjet_dist", 0);
531  fts.fill("jet_pfcand_trackjet_decayL", 0);
532  }
533 
534  // muons specific
535  if (abs(cand->pdgId()) == 13) {
536  std::vector<unsigned int> muonsToSkip;
537  int ipos = -1;
538  float minDR = 1000;
539  for (size_t i = 0; i < muons.size(); i++) {
540  if (not muons[i].isPFMuon())
541  continue;
542  if (std::find(muonsToSkip.begin(), muonsToSkip.end(), i) != muonsToSkip.end())
543  continue;
544  float dR = reco::deltaR(muons[i].p4(), candP4);
545  if (dR < jet_radius_ and dR < minDR) {
546  minDR = dR;
547  ipos = i;
548  muonsToSkip.push_back(i);
549  }
550  }
551  if (ipos >= 0) {
552  int muonId = 0;
554  muonId++;
556  muonId++;
558  muonId++;
560  muonId++;
562  muonId++;
563  fts.fill("jet_pfcand_muon_id", muonId);
564  fts.fill("jet_pfcand_muon_isglobal", muons[ipos].isGlobalMuon());
565  fts.fill("jet_pfcand_muon_chi2",
566  (muons[ipos].isGlobalMuon()) ? muons[ipos].globalTrack()->normalizedChi2() : 0);
567  fts.fill("jet_pfcand_muon_nvalidhit",
568  (muons[ipos].isGlobalMuon()) ? muons[ipos].globalTrack()->hitPattern().numberOfValidMuonHits() : 0);
569  fts.fill("jet_pfcand_muon_nstation", muons[ipos].numberOfMatchedStations());
570  fts.fill("jet_pfcand_muon_segcomp", muon::segmentCompatibility(muons[ipos]));
571  } else {
572  fts.fill("jet_pfcand_muon_id", 0);
573  fts.fill("jet_pfcand_muon_isglobal", 0);
574  fts.fill("jet_pfcand_muon_chi2", 0);
575  fts.fill("jet_pfcand_muon_nvalidhit", 0);
576  fts.fill("jet_pfcand_muon_nstation", 0);
577  fts.fill("jet_pfcand_muon_segcomp", 0);
578  }
579  } else {
580  fts.fill("jet_pfcand_muon_id", 0);
581  fts.fill("jet_pfcand_muon_isglobal", 0);
582  fts.fill("jet_pfcand_muon_chi2", 0);
583  fts.fill("jet_pfcand_muon_nvalidhit", 0);
584  fts.fill("jet_pfcand_muon_nstation", 0);
585  fts.fill("jet_pfcand_muon_segcomp", 0);
586  }
587 
588  // electrons specific
589  if (abs(cand->pdgId()) == 11) {
590  int ipos = -1;
591  for (size_t i = 0; i < electrons.size(); i++) {
592  if (electrons[i].isPF()) {
593  for (const auto &element : electrons[i].associatedPackedPFCandidates()) {
594  if (abs(element->pdgId()) == 11 and element->p4() == candP4)
595  ipos = i;
596  }
597  }
598  }
599  if (ipos >= 0) {
600  fts.fill("jet_pfcand_electron_detaIn",
601  std::isnan(electrons[ipos].deltaEtaSuperClusterTrackAtVtx())
602  ? 0
603  : electrons[ipos].deltaEtaSuperClusterTrackAtVtx());
604  fts.fill("jet_pfcand_electron_dphiIn",
605  std::isnan(electrons[ipos].deltaPhiSuperClusterTrackAtVtx())
606  ? 0
607  : electrons[ipos].deltaPhiSuperClusterTrackAtVtx());
608  fts.fill("jet_pfcand_electron_sigIetaIeta",
610  fts.fill("jet_pfcand_electron_sigIphiIphi",
611  std::isnan(electrons[ipos].full5x5_sigmaIphiIphi()) ? 0 : electrons[ipos].full5x5_sigmaIphiIphi());
612  fts.fill("jet_pfcand_electron_r9", std::isnan(electrons[ipos].full5x5_r9()) ? 0 : electrons[ipos].full5x5_r9());
613  fts.fill("jet_pfcand_electron_convProb",
615  } else {
616  fts.fill("jet_pfcand_electron_detaIn", 0);
617  fts.fill("jet_pfcand_electron_dphiIn", 0);
618  fts.fill("jet_pfcand_electron_sigIetaIeta", 0);
619  fts.fill("jet_pfcand_electron_sigIphiIphi", 0);
620  fts.fill("jet_pfcand_electron_r9", 0);
621  fts.fill("jet_pfcand_electron_convProb", 0);
622  }
623  } else {
624  fts.fill("jet_pfcand_electron_detaIn", 0);
625  fts.fill("jet_pfcand_electron_dphiIn", 0);
626  fts.fill("jet_pfcand_electron_sigIetaIeta", 0);
627  fts.fill("jet_pfcand_electron_sigIphiIphi", 0);
628  fts.fill("jet_pfcand_electron_r9", 0);
629  fts.fill("jet_pfcand_electron_convProb", 0);
630  }
631 
632  // photons specific
633  if (abs(cand->pdgId()) == 22) {
634  int ipos = -1;
635  for (size_t i = 0; i < photons.size(); i++) {
636  for (const auto &element : photons[i].associatedPackedPFCandidates()) {
637  if (abs(element->pdgId()) == 22 and element->p4() == candP4)
638  ipos = i;
639  }
640  }
641  if (ipos >= 0) {
642  fts.fill("jet_pfcand_photon_sigIetaIeta",
644  fts.fill("jet_pfcand_photon_r9", std::isnan(photons[ipos].full5x5_r9()) ? 0 : photons[ipos].full5x5_r9());
645  fts.fill("jet_pfcand_photon_eVeto", photons[ipos].passElectronVeto());
646  } else {
647  fts.fill("jet_pfcand_photon_sigIetaIeta", 0);
648  fts.fill("jet_pfcand_photon_r9", 0);
649  fts.fill("jet_pfcand_photon_eVeto", 0);
650  }
651  } else {
652  fts.fill("jet_pfcand_photon_sigIetaIeta", 0);
653  fts.fill("jet_pfcand_photon_r9", 0);
654  fts.fill("jet_pfcand_photon_eVeto", 0);
655  }
656 
657  // tau specific prior to any puppi weight application
658  if (std::find(tau_pfcandidates.begin(), tau_pfcandidates.end(), cand->p4()) != tau_pfcandidates.end())
659  fts.fill("jet_pfcand_tau_signal", 1);
660  else
661  fts.fill("jet_pfcand_tau_signal", 0);
662  }
663 }
664 
666  // secondary vertexes matching jet
667  std::vector<const reco::VertexCompositePtrCandidate *> jetSVs;
668  for (const auto &sv : *svs_) {
669  if (reco::deltaR2(sv, jet) < jet_radius_ * jet_radius_) {
670  jetSVs.push_back(&sv);
671  }
672  }
673 
674  // sort by dxy significance
675  std::sort(jetSVs.begin(),
676  jetSVs.end(),
678  return sv_vertex_comparator(*sva, *svb, *pv_);
679  });
680 
681  // reserve space
682  for (const auto &name : sv_features_)
683  fts.reserve(name, jetSVs.size());
684 
685  GlobalVector jet_global_vec(jet.px(), jet.py(), jet.pz());
686 
687  for (const auto *sv : jetSVs) {
688  fts.fill("sv_mask", 1);
689  fts.fill("jet_sv_pt_log", std::isnan(std::log(sv->pt())) ? 0 : std::log(sv->pt()));
690  fts.fill("jet_sv_eta", sv->eta());
691  fts.fill("jet_sv_mass", sv->mass());
692  fts.fill("jet_sv_deta", sv->eta() - jet.eta());
693  fts.fill("jet_sv_dphi", sv->phi() - jet.phi());
694  fts.fill("jet_sv_ntrack", sv->numberOfDaughters());
695  fts.fill("jet_sv_chi2", sv->vertexNormalizedChi2());
696 
698  sv->fillVertexCovariance(csv);
699  reco::Vertex svtx(sv->vertex(), csv);
700 
702  auto valxy = dxy.signedDistance(svtx, *pv_, jet_global_vec);
703  fts.fill("jet_sv_dxy", std::isnan(valxy.value()) ? 0 : valxy.value());
704  fts.fill("jet_sv_dxysig", std::isnan(fabs(valxy.significance())) ? 0 : fabs(valxy.significance()));
705 
706  VertexDistance3D d3d;
707  auto val3d = d3d.signedDistance(svtx, *pv_, jet_global_vec);
708  fts.fill("jet_sv_d3d", std::isnan(val3d.value()) ? 0 : val3d.value());
709  fts.fill("jet_sv_d3dsig", std::isnan(fabs(val3d.significance())) ? 0 : fabs(val3d.significance()));
710  }
711 }
712 
714  // some jet properties
715  TVector3 jet_direction(jet.momentum().Unit().x(), jet.momentum().Unit().y(), jet.momentum().Unit().z());
716  GlobalVector jet_ref_track_dir(jet.px(), jet.py(), jet.pz());
717  math::XYZVector jet_dir = jet.momentum().Unit();
718 
719  std::vector<pat::PackedCandidate> jet_lost_tracks;
720  for (size_t itrk = 0; itrk < losttracks_->size(); itrk++) {
721  if (reco::deltaR(losttracks_->at(itrk).p4(), jet.p4()) < max_dr_for_losttrack_ and
722  losttracks_->at(itrk).pt() > min_pt_for_losttrack_) {
723  jet_lost_tracks.push_back(losttracks_->at(itrk));
724  }
725  }
726  std::sort(
727  jet_lost_tracks.begin(), jet_lost_tracks.end(), [](const auto &a, const auto &b) { return a.pt() > b.pt(); });
728 
729  // reserve space
730  for (const auto &name : losttrack_features_)
731  fts.reserve(name, jet_lost_tracks.size());
732 
733  reco::VertexRef pv_ass = reco::VertexRef(vtxs_, 0);
734  math::XYZPoint pv_ass_pos = pv_ass->position();
735 
736  for (auto const &ltrack : jet_lost_tracks) {
737  fts.fill("jet_losttrack_pt_log", std::isnan(std::log(ltrack.pt())) ? 0 : std::log(ltrack.pt()));
738  fts.fill("jet_losttrack_eta", ltrack.eta());
739  fts.fill("jet_losttrack_charge", ltrack.charge());
740  fts.fill("jet_losttrack_frompv", ltrack.fromPV());
741  fts.fill("jet_losttrack_dz", std::isnan(ltrack.dz(pv_ass_pos)) ? 0 : ltrack.dz(pv_ass_pos));
742  fts.fill("jet_losttrack_dxy", std::isnan(ltrack.dxy(pv_ass_pos)) ? 0 : ltrack.dxy(pv_ass_pos));
743  fts.fill("jet_losttrack_npixhits", ltrack.numberOfPixelHits());
744  fts.fill("jet_losttrack_nstriphits", ltrack.stripLayersWithMeasurement());
745 
746  TVector3 ltrack_momentum(ltrack.momentum().x(), ltrack.momentum().y(), ltrack.momentum().z());
747  fts.fill("jet_losttrack_deta", jet_direction.Eta() - ltrack_momentum.Eta());
748  fts.fill("jet_losttrack_dphi", jet_direction.DeltaPhi(ltrack_momentum));
749  fts.fill("jet_losttrack_etarel",
750  std::isnan(reco::btau::etaRel(jet_dir, ltrack.momentum()))
751  ? 0
752  : reco::btau::etaRel(jet_dir, ltrack.momentum()));
753 
754  const reco::Track *track = ltrack.bestTrack();
755  if (track) {
756  fts.fill("jet_losttrack_track_chi2", track->normalizedChi2());
757  fts.fill("jet_losttrack_track_qual", track->qualityMask());
758  fts.fill("jet_losttrack_dxysig",
759  std::isnan(fabs(ltrack.dxy(pv_ass_pos)) / ltrack.dxyError())
760  ? 0
761  : fabs(ltrack.dxy(pv_ass_pos)) / ltrack.dxyError());
762  fts.fill("jet_losttrack_dzsig",
763  std::isnan(fabs(ltrack.dz(pv_ass_pos)) / ltrack.dzError())
764  ? 0
765  : fabs(ltrack.dz(pv_ass_pos)) / ltrack.dzError());
766 
767  reco::TransientTrack transientTrack = track_builder_->build(*track);
768  Measurement1D meas_ip3d = IPTools::signedImpactParameter3D(transientTrack, jet_ref_track_dir, *pv_).second;
769  Measurement1D meas_jetdist = IPTools::jetTrackDistance(transientTrack, jet_ref_track_dir, *pv_).second;
770  Measurement1D meas_decayl = IPTools::signedDecayLength3D(transientTrack, jet_ref_track_dir, *pv_).second;
771 
772  fts.fill("jet_losttrack_trackjet_d3d", std::isnan(meas_ip3d.value()) ? 0 : meas_ip3d.value());
773  fts.fill("jet_losttrack_trackjet_d3dsig",
774  std::isnan(fabs(meas_ip3d.significance())) ? 0 : fabs(meas_ip3d.significance()));
775  fts.fill("jet_losttrack_trackjet_dist", std::isnan(-meas_jetdist.value()) ? 0 : -meas_jetdist.value());
776  fts.fill("jet_losttrack_trackjet_decayL", std::isnan(meas_decayl.value()) ? 0 : meas_decayl.value());
777  } else {
778  fts.fill("jet_losttrack_track_chi2", 0);
779  fts.fill("jet_losttrack_track_qual", 0);
780  fts.fill("jet_losttrack_dxysig", 0);
781  fts.fill("jet_losttrack_dzsig", 0);
782  fts.fill("jet_losttrack_trackjet_d3d", 0);
783  fts.fill("jet_losttrack_trackjet_d3dsig", 0);
784  fts.fill("jet_losttrack_trackjet_dist", 0);
785  fts.fill("jet_losttrack_trackjet_decayL", 0);
786  }
787 
788  fts.fill("lt_mask", 1);
789  }
790 }
791 
792 // define this as a plug-in
793 DEFINE_FWK_MODULE(ParticleNetFeatureEvaluator);
edm::Handle< reco::VertexCompositePtrCandidateCollection > svs_
def isnan(num)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< float > jet_losttrack_trackjet_dist
double pt() const final
transverse momentum
edm::Handle< reco::VertexCollection > vtxs_
Base class for all types of Jets.
Definition: Jet.h:20
double etaRel(const math::XYZVector &dir, const math::XYZVector &track)
void beginStream(edm::StreamID) override
edm::EDGetTokenT< pat::ElectronCollection > electron_token_
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:57
std::vector< float > jet_pfcand_electron_sigIetaIeta
std::vector< pat::PackedCandidate > PackedCandidateCollection
std::pair< bool, Measurement1D > signedDecayLength3D(const TrajectoryStateOnSurface &state, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:105
edm::Handle< edm::View< reco::Candidate > > pfcands_
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:81
std::vector< Tau > TauCollection
Definition: Tau.h:35
std::vector< float > jet_losttrack_trackjet_d3dsig
edm::ESHandle< TransientTrackBuilder > track_builder_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
edm::EDGetTokenT< pat::TauCollection > tau_token_
math::Error< dimension >::type CovarianceMatrix
covariance error matrix (3x3)
Definition: Vertex.h:47
std::vector< VertexCompositePtrCandidate > VertexCompositePtrCandidateCollection
collection of Candidate objects
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::pair< double, Measurement1D > jetTrackDistance(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:206
Definition: HeavyIon.h:7
edm::EDGetTokenT< pat::MuonCollection > muon_token_
static const std::vector< std::string > particle_features_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< pat::PackedCandidateCollection > losttrack_token_
std::vector< Electron > ElectronCollection
Definition: Electron.h:36
void reserve(const std::string &name, unsigned capacity)
edm::Handle< pat::PackedCandidateCollection > losttracks_
Definition: Jet.py:1
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
std::vector< float > jet_losttrack_trackjet_decayL
std::vector< float > jet_pfcand_photon_sigIetaIeta
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
edm::EDGetTokenT< edm::View< reco::Jet > > jet_token_
static const std::vector< std::string > losttrack_features_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< float > jet_pfcand_electron_sigIphiIphi
void produce(edm::Event &, const edm::EventSetup &) override
ParticleNetFeatureEvaluator(const edm::ParameterSet &)
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
void fillLostTrackFeatures(DeepBoostedJetFeatures &fts, const reco::Jet &jet)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Measurement1D signedDistance(const reco::Vertex &primVtx, const reco::Vertex &secVtx, const GlobalVector &momentum) const override
void fillParticleFeatures(DeepBoostedJetFeatures &fts, const reco::Jet &jet, const std::vector< math::XYZTLorentzVector > &tau_pfcandidates, const pat::MuonCollection &muons, const pat::ElectronCollection &electrons, const pat::PhotonCollection &photons)
edm::EDGetTokenT< reco::VertexCompositePtrCandidateCollection > sv_token_
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > track_builder_token_
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
Definition: VertexFwd.h:13
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
std::vector< float > jet_pfcand_electron_convProb
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
edm::EDGetTokenT< pat::PhotonCollection > photon_token_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool sv_vertex_comparator(const SVType &sva, const SVType &svb, const PVType &pv)
Definition: deep_helpers.h:54
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
double b
Definition: hdecay.h:120
Analysis-level calorimeter jet class.
Definition: Jet.h:77
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool useTrackProperties(const pat::PackedCandidate *cand)
void fill(const std::string &name, float value)
double value() const
Definition: Measurement1D.h:25
std::vector< Muon > MuonCollection
Definition: Muon.h:35
double significance() const
Definition: Measurement1D.h:29
fixed size matrix
HLT enums.
double a
Definition: hdecay.h:121
static const std::vector< std::string > sv_features_
edm::EDGetTokenT< reco::VertexCollection > vtx_token_
std::vector< Photon > PhotonCollection
Definition: Photon.h:31
def move(src, dest)
Definition: eostools.py:511
void fillSVFeatures(DeepBoostedJetFeatures &fts, const reco::Jet &jet)
edm::EDGetTokenT< edm::View< reco::Candidate > > pfcand_token_