CMS 3D CMS Logo

ChargedCandidateConverter.h
Go to the documentation of this file.
1 #ifndef RecoBTag_FeatureTools_ChargedCandidateConverter_h
2 #define RecoBTag_FeatureTools_ChargedCandidateConverter_h
3 
7 
11 
12 namespace btagbtvdeep {
13 
14  template <typename CandidateType>
15  void commonCandidateToFeatures(const CandidateType * c_pf,
16  const reco::Jet & jet,
17  const TrackInfoBuilder & track_info,
18  const float & drminpfcandsv, const float & jetR,
19  ChargedCandidateFeatures & c_pf_features,
20  const bool flip = false) {
21 
22 
23  float trackSip2dVal = track_info.getTrackSip2dVal();
24  float trackSip2dSig = track_info.getTrackSip2dSig();
25  float trackSip3dVal = track_info.getTrackSip3dVal();
26  float trackSip3dSig = track_info.getTrackSip3dSig();
27  if(flip == true){
28  trackSip2dVal = -trackSip2dVal;
29  trackSip2dSig = -trackSip2dSig;
30  trackSip3dSig = -trackSip3dSig;
31  trackSip3dVal = -trackSip3dVal;
32  }
33 
34  c_pf_features.deltaR = reco::deltaR(*c_pf, jet);
35  c_pf_features.ptrel = catch_infs_and_bound(c_pf->pt() / jet.pt(), 0, -1, 0, -1);
36  c_pf_features.ptrel_noclip = c_pf->pt() / jet.pt();
37  c_pf_features.erel = c_pf->energy() / jet.energy();
38  const float etasign = jet.eta() > 0 ? 1 : -1;
39  c_pf_features.etarel = etasign * (c_pf->eta() - jet.eta());
40 
41  c_pf_features.btagPf_trackEtaRel = catch_infs_and_bound(track_info.getTrackEtaRel(), 0, -5, 15);
42  c_pf_features.btagPf_trackPtRel = catch_infs_and_bound(track_info.getTrackPtRel(), 0, -1, 4);
43  c_pf_features.btagPf_trackPPar = catch_infs_and_bound(track_info.getTrackPPar(), 0, -1e5, 1e5);
44  c_pf_features.btagPf_trackDeltaR = catch_infs_and_bound(track_info.getTrackDeltaR(), 0, -5, 5);
45  c_pf_features.btagPf_trackPtRatio = catch_infs_and_bound(track_info.getTrackPtRatio(), 0, -1, 10);
46  c_pf_features.btagPf_trackPParRatio = catch_infs_and_bound(track_info.getTrackPParRatio(), 0, -10, 100);
47  c_pf_features.btagPf_trackSip3dVal = catch_infs_and_bound(trackSip3dVal, 0, -1, 1e5);
48  c_pf_features.btagPf_trackSip3dSig = catch_infs_and_bound(trackSip3dSig, 0, -1, 4e4);
49  c_pf_features.btagPf_trackSip2dVal = catch_infs_and_bound(trackSip2dVal, 0, -1, 70);
50  c_pf_features.btagPf_trackSip2dSig = catch_infs_and_bound(trackSip2dSig, 0, -1, 4e4);
51  c_pf_features.btagPf_trackJetDistVal = catch_infs_and_bound(track_info.getTrackJetDistVal(), 0, -20, 1);
52 
53  c_pf_features.drminsv = catch_infs_and_bound(drminpfcandsv, 0, -1. * jetR, 0, -1. * jetR);
54 
55  // subjet related
56  const auto* patJet = dynamic_cast<const pat::Jet*>(&jet);
57  if (!patJet) {
58  throw edm::Exception(edm::errors::InvalidReference) << "Input is not a pat::Jet.";
59  }
60 
61  if (patJet->nSubjetCollections() > 0) {
62  auto subjets = patJet->subjets();
63  // sort by pt
64  std::sort(subjets.begin(), subjets.end(), [](const edm::Ptr<pat::Jet>& p1, const edm::Ptr<pat::Jet>& p2) {
65  return p1->pt() > p2->pt();
66  });
67  c_pf_features.drsubjet1 = !subjets.empty() ? reco::deltaR(*c_pf, *subjets.at(0)) : -1;
68  c_pf_features.drsubjet2 = subjets.size() > 1 ? reco::deltaR(*c_pf, *subjets.at(1)) : -1;
69  } else {
70  // AK4 jets don't have subjets
71  c_pf_features.drsubjet1 = -1;
72  c_pf_features.drsubjet2 = -1;
73  }
74  }
75 
77  const pat::Jet & jet,
78  const TrackInfoBuilder & track_info,
79  const float drminpfcandsv, const float jetR,
80  ChargedCandidateFeatures & c_pf_features,
81  const bool flip = false) ;
82 
83 
85  const reco::Jet & jet,
86  const TrackInfoBuilder & track_info,
87  const float drminpfcandsv, const float jetR, const float puppiw,
88  const int pv_ass_quality,
89  const reco::VertexRef & pv,
90  ChargedCandidateFeatures & c_pf_features,
91  const bool flip = false) ;
92 
93 
94 }
95 
96 #endif //RecoBTag_FeatureTools_ChargedCandidateConverter_h
double eta() const final
momentum pseudorapidity
Base class for all types of Jets.
Definition: Jet.h:20
double pt() const final
transverse momentum
const float getTrackEtaRel() const
const float getTrackDeltaR() const
const float getTrackPParRatio() const
const float getTrackSip2dSig() const
const float catch_infs_and_bound(const float in, const float replace_value, const float lowerbound, const float upperbound, const float offset=0., const bool use_offsets=true)
Definition: deep_helpers.cc:34
const float getTrackPPar() const
double energy() const final
energy
def pv(vc)
Definition: MetAnalyzer.py:7
const float getTrackPtRatio() const
double p2[4]
Definition: TauolaWrapper.h:90
const float getTrackSip3dVal() const
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
void packedCandidateToFeatures(const pat::PackedCandidate *c_pf, const pat::Jet &jet, const TrackInfoBuilder &track_info, const float drminpfcandsv, const float jetR, ChargedCandidateFeatures &c_pf_features, const bool flip=false)
const float getTrackJetDistVal() const
void recoCandidateToFeatures(const reco::PFCandidate *c_pf, const reco::Jet &jet, const TrackInfoBuilder &track_info, const float drminpfcandsv, const float jetR, const float puppiw, const int pv_ass_quality, const reco::VertexRef &pv, ChargedCandidateFeatures &c_pf_features, const bool flip=false)
Analysis-level calorimeter jet class.
Definition: Jet.h:80
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
double p1[4]
Definition: TauolaWrapper.h:89
const float getTrackPtRel() const
const float getTrackSip2dVal() const
void commonCandidateToFeatures(const CandidateType *c_pf, const reco::Jet &jet, const TrackInfoBuilder &track_info, const float &drminpfcandsv, const float &jetR, ChargedCandidateFeatures &c_pf_features, const bool flip=false)
const float getTrackSip3dSig() const