Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-26 04:08:59

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