Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:29

0001 #include "PhysicsTools/Heppy/interface/CMGMuonCleanerBySegmentsAlgo.h"
0002 
0003 namespace heppy {
0004 
0005   CMGMuonCleanerBySegmentsAlgo::~CMGMuonCleanerBySegmentsAlgo() {}
0006 
0007   std::vector<bool> CMGMuonCleanerBySegmentsAlgo::clean(const std::vector<pat::Muon> &src) const {
0008     unsigned int nsrc = src.size();
0009     std::vector<bool> good(nsrc, true);
0010     for (unsigned int i = 0; i < nsrc; ++i) {
0011       const pat::Muon &mu1 = src[i];
0012       if (!preselection_(mu1))
0013         good[i] = false;
0014       if (!good[i])
0015         continue;
0016       int nSegments1 = mu1.numberOfMatches(reco::Muon::SegmentArbitration);
0017       for (unsigned int j = i + 1; j < nsrc; ++j) {
0018         const pat::Muon &mu2 = src[j];
0019         if (isSameMuon(mu1, mu2))
0020           continue;
0021         if (!good[j] || !preselection_(mu2))
0022           continue;
0023         int nSegments2 = mu2.numberOfMatches(reco::Muon::SegmentArbitration);
0024         if (nSegments2 == 0 || nSegments1 == 0)
0025           continue;
0026         double sf = muon::sharedSegments(mu1, mu2) / std::min<double>(nSegments1, nSegments2);
0027         if (sf > sharedFraction_) {
0028           if (isBetterMuon(mu1, mu1.isPFMuon(), mu2, mu2.isPFMuon())) {
0029             good[j] = false;
0030           } else {
0031             good[i] = false;
0032           }
0033         }
0034       }
0035     }
0036 
0037     for (unsigned int i = 0; i < nsrc; ++i) {
0038       const pat::Muon &mu1 = src[i];
0039       if (passthrough_(mu1))
0040         good[i] = true;
0041     }
0042 
0043     return good;
0044   }
0045 
0046   bool CMGMuonCleanerBySegmentsAlgo::isSameMuon(const pat::Muon &mu1, const pat::Muon &mu2) const {
0047     return (&mu1 == &mu2) || (mu1.originalObjectRef() == mu2.originalObjectRef()) ||
0048            (mu1.reco::Muon::innerTrack().isNonnull() ? mu1.reco::Muon::innerTrack() == mu2.reco::Muon::innerTrack()
0049                                                      : mu1.reco::Muon::outerTrack() == mu2.reco::Muon::outerTrack());
0050   }
0051 
0052   bool CMGMuonCleanerBySegmentsAlgo::isBetterMuon(const pat::Muon &mu1,
0053                                                   bool mu1PF,
0054                                                   const pat::Muon &mu2,
0055                                                   bool mu2PF) const {
0056     if (mu2.track().isNull())
0057       return true;
0058     if (mu1.track().isNull())
0059       return false;
0060     if (mu1PF != mu2PF)
0061       return mu1PF;
0062     if (mu1.isGlobalMuon() != mu2.isGlobalMuon())
0063       return mu1.isGlobalMuon();
0064     if (mu1.charge() == mu2.charge() && deltaR2(mu1, mu2) < 0.0009) {
0065       return mu1.track()->ptError() / mu1.track()->pt() < mu2.track()->ptError() / mu2.track()->pt();
0066     } else {
0067       int nm1 = mu1.numberOfMatches(reco::Muon::SegmentArbitration);
0068       int nm2 = mu2.numberOfMatches(reco::Muon::SegmentArbitration);
0069       return (nm1 != nm2 ? nm1 > nm2 : mu1.pt() > mu2.pt());
0070     }
0071   }
0072 }  // namespace heppy