Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-16 23:01:11

0001 #include "RecoBTag/FeatureTools/interface/ChargedCandidateConverter.h"
0002 
0003 namespace btagbtvdeep {
0004 
0005   void packedCandidateToFeatures(const pat::PackedCandidate* c_pf,
0006                                  const pat::Jet& jet,
0007                                  const TrackInfoBuilder& track_info,
0008                                  const bool isWeightedJet,
0009                                  const float drminpfcandsv,
0010                                  const float jetR,
0011                                  const float puppiw,
0012                                  ChargedCandidateFeatures& c_pf_features,
0013                                  const bool flip,
0014                                  const float distminpfcandsv) {
0015     commonCandidateToFeatures(
0016         c_pf, jet, track_info, isWeightedJet, drminpfcandsv, jetR, puppiw, c_pf_features, flip, distminpfcandsv);
0017 
0018     c_pf_features.vtx_ass = c_pf->pvAssociationQuality();
0019 
0020     c_pf_features.puppiw = puppiw;
0021     c_pf_features.charge = c_pf->charge();
0022 
0023     c_pf_features.CaloFrac = c_pf->caloFraction();
0024     c_pf_features.HadFrac = c_pf->hcalFraction();
0025     c_pf_features.lostInnerHits = catch_infs(c_pf->lostInnerHits(), 2);
0026     c_pf_features.numberOfPixelHits = catch_infs(c_pf->numberOfPixelHits(), -1);
0027     c_pf_features.numberOfStripHits = catch_infs(c_pf->stripLayersWithMeasurement(), -1);
0028 
0029     // if PackedCandidate does not have TrackDetails this gives an Exception
0030     // because unpackCovariance might be called for pseudoTrack/bestTrack
0031     if (c_pf->hasTrackDetails()) {
0032       const auto& pseudo_track = c_pf->pseudoTrack();
0033       c_pf_features.chi2 = catch_infs_and_bound(pseudo_track.normalizedChi2(), 300, -1, 300);
0034       // this returns the quality enum not a mask.
0035       c_pf_features.quality = pseudo_track.qualityMask();
0036     } else {
0037       // default negative chi2 and loose track if notTrackDetails
0038       c_pf_features.chi2 = catch_infs_and_bound(-1, 300, -1, 300);
0039       c_pf_features.quality = (1 << reco::TrackBase::loose);
0040     }
0041 
0042     c_pf_features.dxy = catch_infs(c_pf->dxy());
0043     c_pf_features.dz = catch_infs(c_pf->dz());
0044     c_pf_features.dxysig = c_pf->bestTrack() ? catch_infs(c_pf->dxy() / c_pf->dxyError()) : 0;
0045     c_pf_features.dzsig = c_pf->bestTrack() ? catch_infs(c_pf->dz() / c_pf->dzError()) : 0;
0046 
0047     float pdgid_;
0048     if (abs(c_pf->pdgId()) == 11 and c_pf->charge() != 0) {
0049       pdgid_ = 0.0;
0050     } else if (abs(c_pf->pdgId()) == 13 and c_pf->charge() != 0) {
0051       pdgid_ = 1.0;
0052     } else if (abs(c_pf->pdgId()) == 22 and c_pf->charge() == 0) {
0053       pdgid_ = 2.0;
0054     } else if (abs(c_pf->pdgId()) != 22 and c_pf->charge() == 0 and abs(c_pf->pdgId()) != 1 and
0055                abs(c_pf->pdgId()) != 2) {
0056       pdgid_ = 3.0;
0057     } else if (abs(c_pf->pdgId()) != 11 and abs(c_pf->pdgId()) != 13 and c_pf->charge() != 0) {
0058       pdgid_ = 4.0;
0059     } else if (c_pf->charge() == 0 and abs(c_pf->pdgId()) == 1) {
0060       pdgid_ = 5.0;
0061     } else if (c_pf->charge() == 0 and abs(c_pf->pdgId()) == 2) {
0062       pdgid_ = 6.0;
0063     } else {
0064       pdgid_ = 7.0;
0065     }
0066     c_pf_features.pdgID = pdgid_;
0067   }
0068 
0069   void recoCandidateToFeatures(const reco::PFCandidate* c_pf,
0070                                const reco::Jet& jet,
0071                                const TrackInfoBuilder& track_info,
0072                                const bool isWeightedJet,
0073                                const float drminpfcandsv,
0074                                const float jetR,
0075                                const float puppiw,
0076                                const int pv_ass_quality,
0077                                const reco::VertexRef& pv,
0078                                ChargedCandidateFeatures& c_pf_features,
0079                                const bool flip,
0080                                const float distminpfcandsv) {
0081     commonCandidateToFeatures(
0082         c_pf, jet, track_info, isWeightedJet, drminpfcandsv, jetR, puppiw, c_pf_features, flip, distminpfcandsv);
0083 
0084     c_pf_features.vtx_ass = vtx_ass_from_pfcand(*c_pf, pv_ass_quality, pv);
0085     c_pf_features.puppiw = puppiw;
0086 
0087     const auto& pseudo_track = (c_pf->bestTrack()) ? *c_pf->bestTrack() : reco::Track();
0088     c_pf_features.chi2 = catch_infs_and_bound(std::floor(pseudo_track.normalizedChi2()), 300, -1, 300);
0089     c_pf_features.quality = quality_from_pfcand(*c_pf);
0090 
0091     // To be implemented if FatJet tag becomes RECO compatible
0092     // const auto *trk =
0093     // float dz =
0094     // float dxy =
0095 
0096     // c_pf_features.dxy =
0097     // c_pf_features.dz =
0098     // c_pf_features.dxysig =
0099     // c_pf_features.dzsig =
0100   }
0101 
0102 }  // namespace btagbtvdeep