Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:45:25

0001 #ifndef CommonTools_PFCandProducer_PrimaryVertexAssignment_
0002 #define CommonTools_PFCandProducer_PrimaryVertexAssignment_
0003 
0004 #include "DataFormats/RecoCandidate/interface/RecoChargedRefCandidate.h"
0005 
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 
0009 #include "DataFormats/Candidate/interface/Candidate.h"
0010 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0011 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0012 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0013 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0014 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
0015 
0016 class PrimaryVertexAssignment {
0017 public:
0018   enum Quality {
0019     UsedInFit = 7,
0020     PrimaryDz = 6,
0021     PrimaryV0 = 5,
0022     BTrack = 4,
0023     Unused = 3,
0024     OtherDz = 2,
0025     NotReconstructedPrimary = 1,
0026     Unassigned = 0
0027   };
0028 
0029   PrimaryVertexAssignment(const edm::ParameterSet& iConfig)
0030       : maxDzSigForPrimaryAssignment_(iConfig.getParameter<double>("maxDzSigForPrimaryAssignment")),
0031         maxDzForPrimaryAssignment_(iConfig.getParameter<double>("maxDzForPrimaryAssignment")),
0032         maxDzErrorForPrimaryAssignment_(iConfig.getParameter<double>("maxDzErrorForPrimaryAssignment")),
0033         maxDtSigForPrimaryAssignment_(iConfig.getParameter<double>("maxDtSigForPrimaryAssignment")),
0034         maxJetDeltaR_(iConfig.getParameter<double>("maxJetDeltaR")),
0035         minJetPt_(iConfig.getParameter<double>("minJetPt")),
0036         maxDistanceToJetAxis_(iConfig.getParameter<double>("maxDistanceToJetAxis")),
0037         maxDzForJetAxisAssigment_(iConfig.getParameter<double>("maxDzForJetAxisAssigment")),
0038         maxDxyForJetAxisAssigment_(iConfig.getParameter<double>("maxDxyForJetAxisAssigment")),
0039         maxDxySigForNotReconstructedPrimary_(iConfig.getParameter<double>("maxDxySigForNotReconstructedPrimary")),
0040         maxDxyForNotReconstructedPrimary_(iConfig.getParameter<double>("maxDxyForNotReconstructedPrimary")),
0041         useTiming_(iConfig.getParameter<bool>("useTiming")),
0042         useVertexFit_(iConfig.getParameter<bool>("useVertexFit")),
0043         preferHighRanked_(iConfig.getParameter<bool>("preferHighRanked")),
0044         fNumOfPUVtxsForCharged_(iConfig.getParameter<unsigned int>("NumOfPUVtxsForCharged")),
0045         fDzCutForChargedFromPUVtxs_(iConfig.getParameter<double>("DzCutForChargedFromPUVtxs")),
0046         fPtMaxCharged_(iConfig.getParameter<double>("PtMaxCharged")),
0047         fEtaMinUseDz_(iConfig.getParameter<double>("EtaMinUseDz")),
0048         fOnlyUseFirstDz_(iConfig.getParameter<bool>("OnlyUseFirstDz")) {}
0049 
0050   ~PrimaryVertexAssignment() {}
0051 
0052   std::pair<int, PrimaryVertexAssignment::Quality> chargedHadronVertex(
0053       const reco::VertexCollection& vertices,
0054       const reco::TrackRef& trackRef,
0055       const reco::Track* track,
0056       float trackTime,
0057       float trackTimeResolution,  // <0 if timing not available for this object
0058       const edm::View<reco::Candidate>& jets,
0059       const TransientTrackBuilder& builder) const;
0060 
0061   std::pair<int, PrimaryVertexAssignment::Quality> chargedHadronVertex(
0062       const reco::VertexCollection& vertices,
0063       int iVertex,
0064       const reco::Track* track,
0065       float trackTime,
0066       float trackTimeResolution,  // <0 if timing not available for this object
0067       const edm::View<reco::Candidate>& jets,
0068       const TransientTrackBuilder& builder) const;
0069 
0070   std::pair<int, PrimaryVertexAssignment::Quality> chargedHadronVertex(
0071       const reco::VertexCollection& vertices,
0072       const reco::TrackRef& trackRef,
0073       float trackTime,
0074       float trackTimeResolution,  // <0 if timing not available for this object
0075       const edm::View<reco::Candidate>& jets,
0076       const TransientTrackBuilder& builder) const {
0077     return chargedHadronVertex(vertices, trackRef, &(*trackRef), trackTime, trackTimeResolution, jets, builder);
0078   }
0079 
0080   std::pair<int, PrimaryVertexAssignment::Quality> chargedHadronVertex(const reco::VertexCollection& vertices,
0081                                                                        const reco::PFCandidate& pfcand,
0082                                                                        const edm::View<reco::Candidate>& jets,
0083                                                                        const TransientTrackBuilder& builder) const {
0084     float time = 0, timeResolution = -1;
0085     if (useTiming_ && pfcand.isTimeValid()) {
0086       time = pfcand.time();
0087       timeResolution = pfcand.timeError();
0088     }
0089     if (pfcand.gsfTrackRef().isNull()) {
0090       if (pfcand.trackRef().isNull())
0091         return {-1, PrimaryVertexAssignment::Unassigned};
0092       else
0093         return chargedHadronVertex(vertices, pfcand.trackRef(), time, timeResolution, jets, builder);
0094     }
0095     return chargedHadronVertex(
0096         vertices, reco::TrackRef(), &(*pfcand.gsfTrackRef()), time, timeResolution, jets, builder);
0097   }
0098 
0099   std::pair<int, PrimaryVertexAssignment::Quality> chargedHadronVertex(const reco::VertexCollection& vertices,
0100                                                                        const pat::PackedCandidate& pfcand,
0101                                                                        const edm::View<reco::Candidate>& jets,
0102                                                                        const TransientTrackBuilder& builder) const {
0103     float time = 0, timeResolution = -1;
0104     if (useTiming_ && pfcand.timeError() > 0) {
0105       time = pfcand.time();
0106       timeResolution = pfcand.timeError();
0107     }
0108     if (!pfcand.hasTrackDetails())
0109       return {-1, PrimaryVertexAssignment::Unassigned};
0110     else
0111       return chargedHadronVertex(
0112           vertices,
0113           (useVertexFit_ && (pfcand.pvAssociationQuality() >= pat::PackedCandidate::UsedInFitLoose))
0114               ? pfcand.vertexRef().key()
0115               : -1,
0116           &pfcand.pseudoTrack(),
0117           time,
0118           timeResolution,
0119           jets,
0120           builder);
0121   }
0122 
0123   std::pair<int, PrimaryVertexAssignment::Quality> chargedHadronVertex(const reco::VertexCollection& vertices,
0124                                                                        const reco::RecoChargedRefCandidate& chcand,
0125                                                                        const edm::ValueMap<float>* trackTimeTag,
0126                                                                        const edm::ValueMap<float>* trackTimeResoTag,
0127                                                                        const edm::View<reco::Candidate>& jets,
0128                                                                        const TransientTrackBuilder& builder) const {
0129     float time = 0, timeResolution = -1;
0130     if (useTiming_) {
0131       time = (*trackTimeTag)[chcand.track()];
0132       timeResolution = (*trackTimeResoTag)[chcand.track()];
0133     }
0134     if (chcand.track().isNull())
0135       return {-1, PrimaryVertexAssignment::Unassigned};
0136     return chargedHadronVertex(vertices, chcand.track(), time, timeResolution, jets, builder);
0137   }
0138 
0139 private:
0140   double maxDzSigForPrimaryAssignment_;
0141   double maxDzForPrimaryAssignment_;
0142   double maxDzErrorForPrimaryAssignment_;
0143   double maxDtSigForPrimaryAssignment_;
0144   double maxJetDeltaR_;
0145   double minJetPt_;
0146   double maxDistanceToJetAxis_;
0147   double maxDzForJetAxisAssigment_;
0148   double maxDxyForJetAxisAssigment_;
0149   double maxDxySigForNotReconstructedPrimary_;
0150   double maxDxyForNotReconstructedPrimary_;
0151   bool useTiming_;
0152   bool useVertexFit_;
0153   bool preferHighRanked_;
0154   unsigned int fNumOfPUVtxsForCharged_;
0155   double fDzCutForChargedFromPUVtxs_;
0156   double fPtMaxCharged_;
0157   double fEtaMinUseDz_;
0158   bool fOnlyUseFirstDz_;
0159 };
0160 
0161 #endif