Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:30:51

0001 #ifndef RecoParticleFlow_PFProducer_PFMuonAlgo_h
0002 #define RecoParticleFlow_PFProducer_PFMuonAlgo_h
0003 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0004 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
0005 #include "DataFormats/VertexReco/interface/Vertex.h"
0006 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0009 #include "DataFormats/Common/interface/Handle.h"
0010 #include "DataFormats/MuonReco/interface/Muon.h"
0011 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0012 
0013 class PFMuonAlgo {
0014   typedef reco::Muon::MuonTrackTypePair MuonTrackTypePair;
0015   typedef reco::Muon::MuonTrackType MuonTrackType;
0016 
0017 public:
0018   /// constructor
0019   PFMuonAlgo(edm::ParameterSet const&, bool postMuonCleaning);
0020 
0021   static void fillPSetDescription(edm::ParameterSetDescription& iDesc);
0022 
0023   ////STATIC MUON ID METHODS
0024   static bool isMuon(const reco::PFBlockElement& elt);
0025   static bool isLooseMuon(const reco::PFBlockElement& elt);
0026   static bool isGlobalTightMuon(const reco::PFBlockElement& elt);
0027   static bool isGlobalLooseMuon(const reco::PFBlockElement& elt);
0028   static bool isTrackerTightMuon(const reco::PFBlockElement& elt);
0029   static bool isTrackerLooseMuon(const reco::PFBlockElement& elt);
0030   static bool isIsolatedMuon(const reco::PFBlockElement& elt);
0031   static bool isMuon(const reco::MuonRef& muonRef);
0032   static bool isLooseMuon(const reco::MuonRef& muonRef);
0033   static bool isGlobalTightMuon(const reco::MuonRef& muonRef);
0034   static bool isGlobalLooseMuon(const reco::MuonRef& muonRef);
0035 
0036   static bool isTrackerTightMuon(const reco::MuonRef& muonRef);
0037   static bool isTrackerLooseMuon(const reco::MuonRef& muonRef);
0038   static bool isIsolatedMuon(const reco::MuonRef& muonRef);
0039   static bool isTightMuonPOG(const reco::MuonRef& muonRef);
0040   static void printMuonProperties(const reco::MuonRef& muonRef);
0041 
0042   ////POST CLEANING AND MOMEMNTUM ASSIGNMENT
0043   static bool hasValidTrack(const reco::MuonRef& muonRef, bool loose, double maxDPtOPt);
0044 
0045   //Make a PF Muon : Basic method
0046   bool reconstructMuon(reco::PFCandidate&, const reco::MuonRef&, bool allowLoose = false);
0047 
0048   //Assign a different track to the muon
0049   void changeTrack(reco::PFCandidate&, const MuonTrackTypePair&);
0050   //PF Post cleaning algorithm
0051   void setInputsForCleaning(reco::VertexCollection const&);
0052   void postClean(reco::PFCandidateCollection*);
0053   void addMissingMuons(edm::Handle<reco::MuonCollection>, reco::PFCandidateCollection* cands);
0054   void setVetoes(const reco::PFCandidateCollection& vetoes) { vetoes_ = &vetoes; }
0055 
0056   std::unique_ptr<reco::PFCandidateCollection> transferCleanedCosmicCandidates() {
0057     return std::move(pfCosmicsMuonCleanedCandidates_);
0058   }
0059 
0060   std::unique_ptr<reco::PFCandidateCollection> transferCleanedTrackerAndGlobalCandidates() {
0061     return std::move(pfCleanedTrackerAndGlobalMuonCandidates_);
0062   }
0063 
0064   std::unique_ptr<reco::PFCandidateCollection> transferCleanedFakeCandidates() {
0065     return std::move(pfFakeMuonCleanedCandidates_);
0066   }
0067 
0068   std::unique_ptr<reco::PFCandidateCollection> transferPunchThroughCleanedMuonCandidates() {
0069     return std::move(pfPunchThroughMuonCleanedCandidates_);
0070   }
0071 
0072   std::unique_ptr<reco::PFCandidateCollection> transferPunchThroughCleanedHadronCandidates() {
0073     return std::move(pfPunchThroughHadronCleanedCandidates_);
0074   }
0075 
0076   std::unique_ptr<reco::PFCandidateCollection> transferAddedMuonCandidates() {
0077     return std::move(pfAddedMuonCandidates_);
0078   }
0079 
0080   static std::vector<reco::Muon::MuonTrackTypePair> muonTracks(const reco::MuonRef& muon,
0081                                                                double maxDPtOPt = 1e+9,
0082                                                                bool includeSA = false);
0083 
0084   static int muAssocToTrack(const reco::TrackRef& trackref, const reco::MuonCollection& muons);
0085 
0086 private:
0087   //Give the track with the smallest Dpt/Pt
0088   MuonTrackTypePair getTrackWithSmallestError(const std::vector<MuonTrackTypePair>&);
0089 
0090   //Estimate MET and SUmET for post cleaning
0091   void estimateEventQuantities(const reco::PFCandidateCollection*);
0092 
0093   //Post cleaning Sub-methods
0094   bool cleanMismeasured(reco::PFCandidate&, unsigned int);
0095   bool cleanPunchThroughAndFakes(reco::PFCandidate&, reco::PFCandidateCollection*, unsigned int);
0096 
0097   void removeDeadCandidates(reco::PFCandidateCollection*, const std::vector<unsigned int>&);
0098 
0099   //helpers
0100   std::pair<double, double> getMinMaxMET2(const reco::PFCandidate&);
0101   std::vector<MuonTrackTypePair> tracksWithBetterMET(const std::vector<MuonTrackTypePair>&, const reco::PFCandidate&);
0102   std::vector<MuonTrackTypePair> tracksPointingAtMET(const std::vector<MuonTrackTypePair>&);
0103 
0104   //Output collections for post cleaning
0105   /// the collection of  cosmics cleaned muon candidates
0106   std::unique_ptr<reco::PFCandidateCollection> pfCosmicsMuonCleanedCandidates_;
0107   /// the collection of  tracker/global cleaned muon candidates
0108   std::unique_ptr<reco::PFCandidateCollection> pfCleanedTrackerAndGlobalMuonCandidates_;
0109   /// the collection of  fake cleaned muon candidates
0110   std::unique_ptr<reco::PFCandidateCollection> pfFakeMuonCleanedCandidates_;
0111   /// the collection of  punch-through cleaned muon candidates
0112   std::unique_ptr<reco::PFCandidateCollection> pfPunchThroughMuonCleanedCandidates_;
0113   /// the collection of  punch-through cleaned neutral hadron candidates
0114   std::unique_ptr<reco::PFCandidateCollection> pfPunchThroughHadronCleanedCandidates_;
0115   /// the collection of  added muon candidates
0116   std::unique_ptr<reco::PFCandidateCollection> pfAddedMuonCandidates_;
0117 
0118   std::vector<unsigned int> maskedIndices_;
0119 
0120   const reco::PFCandidateCollection* vetoes_ = nullptr;
0121 
0122   //////////////////////////////////////////////////////////////////////////////////////
0123   const reco::VertexCollection* vertices_;
0124 
0125   //Configurables
0126   // for PFMuonAlgo::goodMuonTracks/muonTracks
0127   const double maxDPtOPt_;
0128   // for PFMuonAlgo::reconstructMuon
0129   const reco::TrackBase::TrackQuality trackQuality_;
0130   const double errorCompScale_;
0131   // for postCleaning (postClean/addMissingMuons)
0132   const bool postCleaning_;
0133   const double eventFractionCleaning_;
0134   const double minPostCleaningPt_;
0135   const double eventFactorCosmics_;
0136   const double metSigForCleaning_;
0137   const double metSigForRejection_;
0138   const double metFactorCleaning_;
0139   const double eventFractionRejection_;
0140   const double metFactorRejection_;
0141   const double metFactorHighEta_;
0142   const double ptFactorHighEta_;
0143   const double metFactorFake_;
0144   const double minPunchThroughMomentum_;
0145   const double minPunchThroughEnergy_;
0146   const double punchThroughFactor_;
0147   const double punchThroughMETFactor_;
0148   const double cosmicRejDistance_;
0149 
0150   double sumetPU_;
0151   double sumet_;
0152   double METX_;
0153   double METY_;
0154 
0155   ///////COMPARATORS
0156 
0157   class TrackMETComparator {
0158   public:
0159     TrackMETComparator(double METX, double METY) {
0160       metx_ = METX;
0161       mety_ = METY;
0162     }
0163     ~TrackMETComparator() {}
0164 
0165     bool operator()(const MuonTrackTypePair& mu1, const MuonTrackTypePair& mu2) {
0166       return pow(metx_ + mu1.first->px(), 2) + pow(mety_ + mu1.first->py(), 2) <
0167              pow(metx_ + mu2.first->px(), 2) + pow(mety_ + mu2.first->py(), 2);
0168     }
0169 
0170   private:
0171     double metx_;
0172     double mety_;
0173   };
0174 
0175   class IndexPtComparator {
0176   public:
0177     IndexPtComparator(const reco::PFCandidateCollection* coll) : coll_(coll) {}
0178     ~IndexPtComparator() {}
0179 
0180     bool operator()(int mu1, int mu2) { return coll_->at(mu1).pt() > coll_->at(mu2).pt(); }
0181 
0182   private:
0183     const reco::PFCandidateCollection* coll_;
0184   };
0185 
0186   class TrackPtErrorSorter {
0187   public:
0188     TrackPtErrorSorter() {}
0189     ~TrackPtErrorSorter() {}
0190 
0191     bool operator()(const MuonTrackTypePair& mu1, const MuonTrackTypePair& mu2) {
0192       return mu1.first->ptError() / mu1.first->pt() < mu2.first->ptError() / mu2.first->pt();
0193     }
0194   };
0195 };
0196 
0197 #endif