CMS 3D CMS Logo

ChargedCandidateConverter.h
Go to the documentation of this file.
1 #ifndef RecoSV_DeepFlavour_ChargedCandidateConverter_h
2 #define RecoSV_DeepFlavour_ChargedCandidateConverter_h
3 
4 #include "deep_helpers.h"
5 #include "TrackInfoBuilder.h"
7 
10 
11 namespace btagbtvdeep {
12 
13 
15 
16  public:
17 
18  // conversion map from quality flags used in PV association and miniAOD one
19  constexpr static int qualityMap[8] = {1,0,1,1,4,4,5,6};
20 
26  };
27 
28  template <typename CandidateType>
29  static void CommonCandidateToFeatures(const CandidateType * c_pf,
30  const reco::Jet & jet,
31  const TrackInfoBuilder & track_info,
32  const float & drminpfcandsv,
33  ChargedCandidateFeatures & c_pf_features) {
34 
35  c_pf_features.ptrel = catch_infs_and_bound(c_pf->pt()/jet.pt(),
36  0,-1,0,-1);
37  // track_info has to be built before passing as parameter
38  c_pf_features.btagPf_trackEtaRel =catch_infs_and_bound(track_info.getTrackEtaRel(), 0,-5,15);
39  c_pf_features.btagPf_trackPtRel =catch_infs_and_bound(track_info.getTrackPtRel(), 0,-1,4);
40  c_pf_features.btagPf_trackPPar =catch_infs_and_bound(track_info.getTrackPPar(), 0,-1e5,1e5 );
41  c_pf_features.btagPf_trackDeltaR =catch_infs_and_bound(track_info.getTrackDeltaR(), 0,-5,5 );
42  c_pf_features.btagPf_trackPParRatio =catch_infs_and_bound(track_info.getTrackPParRatio(),0,-10,100);
43  c_pf_features.btagPf_trackSip3dVal =catch_infs_and_bound(track_info.getTrackSip3dVal(), 0, -1,1e5 );
44  c_pf_features.btagPf_trackSip3dSig =catch_infs_and_bound(track_info.getTrackSip3dSig(), 0, -1,4e4 );
45  c_pf_features.btagPf_trackSip2dVal =catch_infs_and_bound(track_info.getTrackSip2dVal(), 0, -1,70 );
46  c_pf_features.btagPf_trackSip2dSig =catch_infs_and_bound(track_info.getTrackSip2dSig(), 0, -1,4e4 );
47  c_pf_features.btagPf_trackJetDistVal =catch_infs_and_bound(track_info.getTrackJetDistVal(),0,-20,1 );
48 
49 
50  c_pf_features.drminsv = catch_infs_and_bound(drminpfcandsv,0,-0.4,0,-0.4);
51 
52  }
53 
54 
56  const pat::Jet & jet,
57  const TrackInfoBuilder & track_info,
58  const float drminpfcandsv,
59  ChargedCandidateFeatures & c_pf_features) {
60 
61  CommonCandidateToFeatures(c_pf, jet, track_info, drminpfcandsv, c_pf_features);
62 
63  c_pf_features.vtx_ass = c_pf->pvAssociationQuality();
64 
65  c_pf_features.puppiw = c_pf->puppiWeight();
66 
67  // if PackedCandidate does not have TrackDetails this gives an Exception
68  // because unpackCovariance might be called for pseudoTrack/bestTrack
69  if (c_pf->hasTrackDetails()) {
70  const auto & pseudo_track = c_pf->pseudoTrack();
71  c_pf_features.chi2 = catch_infs_and_bound(pseudo_track.normalizedChi2(),300,-1,300);
72  // this returns the quality enum not a mask.
73  c_pf_features.quality = pseudo_track.qualityMask();
74  } else {
75  // default negative chi2 and loose track if notTrackDetails
76  c_pf_features.chi2 = catch_infs_and_bound(-1,300,-1,300);
77  c_pf_features.quality =(1 << reco::TrackBase::loose);
78  }
79 
80  }
81 
82  static void RecoCandidateToFeatures(const reco::PFCandidate * c_pf,
83  const reco::Jet & jet,
84  const TrackInfoBuilder & track_info,
85  const float drminpfcandsv, const float puppiw,
86  const int pv_ass_quality,
87  const reco::VertexRef & pv,
88  ChargedCandidateFeatures & c_pf_features) {
89 
90  CommonCandidateToFeatures(c_pf, jet, track_info, drminpfcandsv, c_pf_features);
91 
92  c_pf_features.vtx_ass = (float) pat::PackedCandidate::PVAssociationQuality(qualityMap[pv_ass_quality]);
93  if (c_pf->trackRef().isNonnull() &&
94  pv->trackWeight(c_pf->trackRef()) > 0.5 &&
95  pv_ass_quality == 7) {
97  }
98 
99  c_pf_features.puppiw = puppiw;
100 
101  const auto & pseudo_track = (c_pf->bestTrack()) ? *c_pf->bestTrack() : reco::Track();
102  c_pf_features.chi2 = catch_infs_and_bound(std::floor(pseudo_track.normalizedChi2()),300,-1,300);
103 
104  // conditions from PackedCandidate producer
105  bool highPurity = c_pf->trackRef().isNonnull() && pseudo_track.quality(reco::Track::highPurity);
106  // do same bit operations than in PackedCandidate
107  uint16_t qualityFlags = 0;
108  qualityFlags = (qualityFlags & ~trackHighPurityMask) | ((highPurity << trackHighPurityShift) & trackHighPurityMask);
109  bool isHighPurity = (qualityFlags & trackHighPurityMask)>>trackHighPurityShift;
110  // to do as in TrackBase
111  uint8_t quality = (1 << reco::TrackBase::loose);
112  if (isHighPurity) {
113  quality |= (1 << reco::TrackBase::highPurity);
114  }
115  c_pf_features.quality = quality;
116 
117  }
118 
119  };
120 
121  // static data member (avoid undefined ref)
123 
124 
125 }
126 
127 #endif //RecoSV_DeepFlavour_ChargedCandidateConverter_h
float puppiWeight() const
Set both weights at once (with option for only full PUPPI)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
static void CommonCandidateToFeatures(const CandidateType *c_pf, const reco::Jet &jet, const TrackInfoBuilder &track_info, const float &drminpfcandsv, ChargedCandidateFeatures &c_pf_features)
Base class for all types of Jets.
Definition: Jet.h:20
double pt() const final
transverse momentum
const float getTrackEtaRel() const
#define constexpr
const float getTrackDeltaR() const
const float getTrackPParRatio() const
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
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.h:26
const float getTrackPPar() const
const PVAssociationQuality pvAssociationQuality() const
def pv(vc)
Definition: MetAnalyzer.py:6
virtual const reco::Track & pseudoTrack() const
Return reference to a pseudo track made with candidate kinematics, parameterized error for eta...
const float getTrackSip3dVal() const
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
const float getTrackJetDistVal() const
static void PackedCandidateToFeatures(const pat::PackedCandidate *c_pf, const pat::Jet &jet, const TrackInfoBuilder &track_info, const float drminpfcandsv, ChargedCandidateFeatures &c_pf_features)
Analysis-level calorimeter jet class.
Definition: Jet.h:80
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
const float getTrackPtRel() const
static void RecoCandidateToFeatures(const reco::PFCandidate *c_pf, const reco::Jet &jet, const TrackInfoBuilder &track_info, const float drminpfcandsv, const float puppiw, const int pv_ass_quality, const reco::VertexRef &pv, ChargedCandidateFeatures &c_pf_features)
const float getTrackSip2dVal() const
const reco::Track * bestTrack() const override
Definition: PFCandidate.h:162
const float getTrackSip3dSig() const