Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:39

0001 #include "RecoBTag/FeatureTools/interface/TrackInfoBuilder.h"
0002 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0003 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0004 #include "DataFormats/BTauReco/interface/JetTagInfo.h"
0005 #include "DataFormats/BTauReco/interface/IPTagInfo.h"
0006 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
0007 #include "TrackingTools/IPTools/interface/IPTools.h"
0008 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
0009 #include "RecoVertex/VertexTools/interface/VertexDistance3D.h"
0010 #include "TVector3.h"
0011 
0012 namespace btagbtvdeep {
0013 
0014   // adapted from DeepNtuples
0015   TrackInfoBuilder::TrackInfoBuilder(edm::ESHandle<TransientTrackBuilder> &build)
0016       : builder_(build),
0017         trackMomentum_(0),
0018         trackEta_(0),
0019         trackEtaRel_(0),
0020         trackPtRel_(0),
0021         trackPPar_(0),
0022         trackDeltaR_(0),
0023         trackPtRatio_(0),
0024         trackPParRatio_(0),
0025         trackSip2dVal_(0),
0026         trackSip2dSig_(0),
0027         trackSip3dVal_(0),
0028         trackSip3dSig_(0),
0029         trackJetDistVal_(0),
0030         trackJetDistSig_(0) {}
0031 
0032   void TrackInfoBuilder::buildTrackInfo(const reco::Candidate *candidate,
0033                                         const math::XYZVector &jetDir,
0034                                         GlobalVector refjetdirection,
0035                                         const reco::Vertex &pv) {
0036     TVector3 jetDir3(jetDir.x(), jetDir.y(), jetDir.z());
0037 
0038     // deal with PAT/AOD polymorphism to get track
0039     const reco::Track *track_ptr = nullptr;
0040     auto packed_candidate = dynamic_cast<const pat::PackedCandidate *>(candidate);
0041     auto pf_candidate = dynamic_cast<const reco::PFCandidate *>(candidate);
0042     if (pf_candidate) {
0043       track_ptr = pf_candidate->bestTrack();  // trackRef was sometimes null
0044     } else if (packed_candidate && packed_candidate->hasTrackDetails()) {
0045       // if PackedCandidate does not have TrackDetails this gives an Exception
0046       // because unpackCovariance might be called for pseudoTrack/bestTrack
0047       track_ptr = &(packed_candidate->pseudoTrack());
0048     }
0049 
0050     if (!track_ptr) {
0051       TVector3 trackMom3(candidate->momentum().x(), candidate->momentum().y(), candidate->momentum().z());
0052       trackMomentum_ = candidate->p();
0053       trackEta_ = candidate->eta();
0054       trackEtaRel_ = reco::btau::etaRel(jetDir, candidate->momentum());
0055       trackPtRel_ = trackMom3.Perp(jetDir3);
0056       trackPPar_ = jetDir.Dot(candidate->momentum());
0057       trackDeltaR_ = reco::deltaR(candidate->momentum(), jetDir);
0058       trackPtRatio_ = trackMom3.Perp(jetDir3) / candidate->p();
0059       trackPParRatio_ = jetDir.Dot(candidate->momentum()) / candidate->p();
0060       trackSip2dVal_ = 0.;
0061       trackSip2dSig_ = 0.;
0062       trackSip3dVal_ = 0.;
0063       trackSip3dSig_ = 0.;
0064       trackJetDistVal_ = 0.;
0065       trackJetDistSig_ = 0.;
0066       return;
0067     }
0068 
0069     math::XYZVector trackMom = track_ptr->momentum();
0070     double trackMag = std::sqrt(trackMom.Mag2());
0071     TVector3 trackMom3(trackMom.x(), trackMom.y(), trackMom.z());
0072 
0073     trackMomentum_ = std::sqrt(trackMom.Mag2());
0074     trackEta_ = trackMom.Eta();
0075     trackEtaRel_ = reco::btau::etaRel(jetDir, trackMom);
0076     trackPtRel_ = trackMom3.Perp(jetDir3);
0077     trackPPar_ = jetDir.Dot(trackMom);
0078     trackDeltaR_ = reco::deltaR(trackMom, jetDir);
0079     trackPtRatio_ = trackMom3.Perp(jetDir3) / trackMag;
0080     trackPParRatio_ = jetDir.Dot(trackMom) / trackMag;
0081 
0082     reco::TransientTrack transientTrack;
0083     transientTrack = builder_->build(*track_ptr);
0084     Measurement1D meas_ip2d = IPTools::signedTransverseImpactParameter(transientTrack, refjetdirection, pv).second;
0085     Measurement1D meas_ip3d = IPTools::signedImpactParameter3D(transientTrack, refjetdirection, pv).second;
0086     Measurement1D jetdist = IPTools::jetTrackDistance(transientTrack, refjetdirection, pv).second;
0087     trackSip2dVal_ = static_cast<float>(meas_ip2d.value());
0088     trackSip2dSig_ = static_cast<float>(meas_ip2d.significance());
0089     trackSip3dVal_ = static_cast<float>(meas_ip3d.value());
0090     trackSip3dSig_ = static_cast<float>(meas_ip3d.significance());
0091     trackJetDistVal_ = static_cast<float>(jetdist.value());
0092     trackJetDistSig_ = static_cast<float>(jetdist.significance());
0093   }
0094 
0095 }  // namespace btagbtvdeep