CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
PFMuonAlgo Class Reference

#include <PFMuonAlgo.h>

Classes

class  IndexPtComparator
 
class  TrackMETComparator
 
class  TrackPtErrorSorter
 

Public Member Functions

void addMissingMuons (edm::Handle< reco::MuonCollection >, reco::PFCandidateCollection *cands)
 
void changeTrack (reco::PFCandidate &, const MuonTrackTypePair &)
 
bool hasValidTrack (const reco::MuonRef &muonRef, bool loose=false)
 
 PFMuonAlgo (edm::ParameterSet const &)
 constructor More...
 
void postClean (reco::PFCandidateCollection *)
 
bool reconstructMuon (reco::PFCandidate &, const reco::MuonRef &, bool allowLoose=false)
 
void setInputsForCleaning (reco::VertexCollection const &)
 
std::unique_ptr< reco::PFCandidateCollectiontransferAddedMuonCandidates ()
 
std::unique_ptr< reco::PFCandidateCollectiontransferCleanedCosmicCandidates ()
 
std::unique_ptr< reco::PFCandidateCollectiontransferCleanedFakeCandidates ()
 
std::unique_ptr< reco::PFCandidateCollectiontransferCleanedTrackerAndGlobalCandidates ()
 
std::unique_ptr< reco::PFCandidateCollectiontransferPunchThroughCleanedHadronCandidates ()
 
std::unique_ptr< reco::PFCandidateCollectiontransferPunchThroughCleanedMuonCandidates ()
 

Static Public Member Functions

static bool isGlobalLooseMuon (const reco::PFBlockElement &elt)
 
static bool isGlobalLooseMuon (const reco::MuonRef &muonRef)
 
static bool isGlobalTightMuon (const reco::PFBlockElement &elt)
 
static bool isGlobalTightMuon (const reco::MuonRef &muonRef)
 
static bool isIsolatedMuon (const reco::PFBlockElement &elt)
 
static bool isIsolatedMuon (const reco::MuonRef &muonRef)
 
static bool isLooseMuon (const reco::PFBlockElement &elt)
 
static bool isLooseMuon (const reco::MuonRef &muonRef)
 
static bool isMuon (const reco::PFBlockElement &elt)
 
static bool isMuon (const reco::MuonRef &muonRef)
 
static bool isTightMuonPOG (const reco::MuonRef &muonRef)
 
static bool isTrackerLooseMuon (const reco::PFBlockElement &elt)
 
static bool isTrackerLooseMuon (const reco::MuonRef &muonRef)
 
static bool isTrackerTightMuon (const reco::PFBlockElement &elt)
 
static bool isTrackerTightMuon (const reco::MuonRef &muonRef)
 
static void printMuonProperties (const reco::MuonRef &muonRef)
 

Private Types

typedef reco::Muon::MuonTrackType MuonTrackType
 
typedef reco::Muon::MuonTrackTypePair MuonTrackTypePair
 

Private Member Functions

bool cleanMismeasured (reco::PFCandidate &, unsigned int)
 
bool cleanPunchThroughAndFakes (reco::PFCandidate &, reco::PFCandidateCollection *, unsigned int)
 
void estimateEventQuantities (const reco::PFCandidateCollection *)
 
std::pair< double, double > getMinMaxMET2 (const reco::PFCandidate &)
 
MuonTrackTypePair getTrackWithSmallestError (const std::vector< MuonTrackTypePair > &)
 
std::vector< reco::Muon::MuonTrackTypePairgoodMuonTracks (const reco::MuonRef &muon, bool includeSA=false)
 
std::vector< reco::Muon::MuonTrackTypePairmuonTracks (const reco::MuonRef &muon, bool includeSA=false, double dpt=1e+9)
 
void removeDeadCandidates (reco::PFCandidateCollection *, const std::vector< unsigned int > &)
 
std::vector< MuonTrackTypePairtracksPointingAtMET (const std::vector< MuonTrackTypePair > &)
 
std::vector< MuonTrackTypePairtracksWithBetterMET (const std::vector< MuonTrackTypePair > &, const reco::PFCandidate &)
 

Private Attributes

const double cosmicRejDistance_
 
const double dzPV_
 
const double errorCompScale_
 
const double eventFactorCosmics_
 
const double eventFractionCleaning_
 
const double eventFractionRejection_
 
std::vector< unsigned int > maskedIndices_
 
const double maxDPtOPt_
 
const double metFactorCleaning_
 
const double metFactorFake_
 
const double metFactorHighEta_
 
const double metFactorRejection_
 
const double metSigForCleaning_
 
const double metSigForRejection_
 
double METX_
 
double METY_
 
const int minPixelHits_
 
const double minPostCleaningPt_
 
const double minPunchThroughEnergy_
 
const double minPunchThroughMomentum_
 
const int minTrackerHits_
 
std::unique_ptr< reco::PFCandidateCollectionpfAddedMuonCandidates_
 the collection of added muon candidates More...
 
std::unique_ptr< reco::PFCandidateCollectionpfCleanedTrackerAndGlobalMuonCandidates_
 the collection of tracker/global cleaned muon candidates More...
 
std::unique_ptr< reco::PFCandidateCollectionpfCosmicsMuonCleanedCandidates_
 the collection of cosmics cleaned muon candidates More...
 
std::unique_ptr< reco::PFCandidateCollectionpfFakeMuonCleanedCandidates_
 the collection of fake cleaned muon candidates More...
 
std::unique_ptr< reco::PFCandidateCollectionpfPunchThroughHadronCleanedCandidates_
 the collection of punch-through cleaned neutral hadron candidates More...
 
std::unique_ptr< reco::PFCandidateCollectionpfPunchThroughMuonCleanedCandidates_
 the collection of punch-through cleaned muon candidates More...
 
const bool postCleaning_
 
const double ptFactorHighEta_
 
const double punchThroughFactor_
 
const double punchThroughMETFactor_
 
double sumet_
 
double sumetPU_
 
const reco::TrackBase::TrackQuality trackQuality_
 
const reco::VertexCollectionvertices_
 

Detailed Description

Definition at line 12 of file PFMuonAlgo.h.

Member Typedef Documentation

Definition at line 15 of file PFMuonAlgo.h.

Definition at line 14 of file PFMuonAlgo.h.

Constructor & Destructor Documentation

PFMuonAlgo::PFMuonAlgo ( edm::ParameterSet const &  )

constructor

Definition at line 26 of file PFMuonAlgo.cc.

28  : pfCosmicsMuonCleanedCandidates_(std::make_unique<reco::PFCandidateCollection>())
29  , pfCleanedTrackerAndGlobalMuonCandidates_(std::make_unique<reco::PFCandidateCollection>())
30  , pfFakeMuonCleanedCandidates_(std::make_unique<reco::PFCandidateCollection>())
31  , pfPunchThroughMuonCleanedCandidates_(std::make_unique<reco::PFCandidateCollection>())
32  , pfPunchThroughHadronCleanedCandidates_(std::make_unique<reco::PFCandidateCollection>())
33  , pfAddedMuonCandidates_(std::make_unique<reco::PFCandidateCollection>())
34 
35  , maxDPtOPt_(getParameter<double>(iConfig, "maxDPtOPt", 1.0))
36  , minTrackerHits_(getParameter<int>(iConfig, "minTrackerHits", 8))
37  , minPixelHits_(getParameter<int>(iConfig, "minPixelHits", 1))
38  , trackQuality_(reco::TrackBase::qualityByName(getParameter<std::string>(iConfig, "trackQuality", "highPurity")))
39  , errorCompScale_(getParameter<double>(iConfig, "ptErrorScale", 4.0))
40  , eventFractionCleaning_(getParameter<double>(iConfig, "eventFractionForCleaning", 0.75))
41  , dzPV_(getParameter<double>(iConfig, "dzPV", 0.2))
42  , postCleaning_(getParameter<bool>(iConfig, "postMuonCleaning", false)) // disable by default (for HLT)
43  , minPostCleaningPt_(getParameter<double>(iConfig, "minPtForPostCleaning", 20.))
44  , eventFactorCosmics_(getParameter<double>(iConfig, "eventFactorForCosmics", 10.))
45  , metSigForCleaning_(getParameter<double>(iConfig, "metSignificanceForCleaning", 3.))
46  , metSigForRejection_(getParameter<double>(iConfig, "metSignificanceForRejection", 4.))
47  , metFactorCleaning_(getParameter<double>(iConfig, "metFactorForCleaning", 4.))
48  , eventFractionRejection_(getParameter<double>(iConfig, "eventFractionForRejection", 0.75))
49  , metFactorRejection_(getParameter<double>(iConfig, "metFactorForRejection", 4.))
50  , metFactorHighEta_(getParameter<double>(iConfig, "metFactorForHighEta", 4.))
51  , ptFactorHighEta_(getParameter<double>(iConfig, "ptFactorForHighEta", 2.))
52  , metFactorFake_(getParameter<double>(iConfig, "metFactorForFakes", 4.))
53  , minPunchThroughMomentum_(getParameter<double>(iConfig, "minMomentumForPunchThrough", 100.))
54  , minPunchThroughEnergy_(getParameter<double>(iConfig, "minEnergyForPunchThrough", 100.))
55  , punchThroughFactor_(getParameter<double>(iConfig, "punchThroughFactor", 3.))
56  , punchThroughMETFactor_(getParameter<double>(iConfig, "punchThroughMETFactor", 4.))
57  , cosmicRejDistance_(getParameter<double>(iConfig, "cosmicRejectionDistance", 1.))
58 {}
std::unique_ptr< reco::PFCandidateCollection > pfPunchThroughMuonCleanedCandidates_
the collection of punch-through cleaned muon candidates
Definition: PFMuonAlgo.h:117
const double minPunchThroughEnergy_
Definition: PFMuonAlgo.h:151
const double metFactorRejection_
Definition: PFMuonAlgo.h:146
const bool postCleaning_
Definition: PFMuonAlgo.h:139
std::unique_ptr< reco::PFCandidateCollection > pfFakeMuonCleanedCandidates_
the collection of fake cleaned muon candidates
Definition: PFMuonAlgo.h:115
const double minPunchThroughMomentum_
Definition: PFMuonAlgo.h:150
const double punchThroughFactor_
Definition: PFMuonAlgo.h:152
std::unique_ptr< reco::PFCandidateCollection > pfCleanedTrackerAndGlobalMuonCandidates_
the collection of tracker/global cleaned muon candidates
Definition: PFMuonAlgo.h:113
const double maxDPtOPt_
Definition: PFMuonAlgo.h:132
const double metFactorCleaning_
Definition: PFMuonAlgo.h:144
const int minTrackerHits_
Definition: PFMuonAlgo.h:133
const double metFactorHighEta_
Definition: PFMuonAlgo.h:147
const double cosmicRejDistance_
Definition: PFMuonAlgo.h:154
const double minPostCleaningPt_
Definition: PFMuonAlgo.h:140
const double dzPV_
Definition: PFMuonAlgo.h:138
const double ptFactorHighEta_
Definition: PFMuonAlgo.h:148
const double eventFractionCleaning_
Definition: PFMuonAlgo.h:137
std::unique_ptr< reco::PFCandidateCollection > pfAddedMuonCandidates_
the collection of added muon candidates
Definition: PFMuonAlgo.h:121
const double metFactorFake_
Definition: PFMuonAlgo.h:149
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:134
const int minPixelHits_
Definition: PFMuonAlgo.h:134
const double eventFactorCosmics_
Definition: PFMuonAlgo.h:141
const double punchThroughMETFactor_
Definition: PFMuonAlgo.h:153
std::unique_ptr< reco::PFCandidateCollection > pfCosmicsMuonCleanedCandidates_
the collection of cosmics cleaned muon candidates
Definition: PFMuonAlgo.h:111
const double eventFractionRejection_
Definition: PFMuonAlgo.h:145
const double errorCompScale_
Definition: PFMuonAlgo.h:136
const double metSigForCleaning_
Definition: PFMuonAlgo.h:142
const reco::TrackBase::TrackQuality trackQuality_
Definition: PFMuonAlgo.h:135
const double metSigForRejection_
Definition: PFMuonAlgo.h:143
std::unique_ptr< reco::PFCandidateCollection > pfPunchThroughHadronCleanedCandidates_
the collection of punch-through cleaned neutral hadron candidates
Definition: PFMuonAlgo.h:119

Member Function Documentation

void PFMuonAlgo::addMissingMuons ( edm::Handle< reco::MuonCollection muons,
reco::PFCandidateCollection cands 
)

Definition at line 863 of file PFMuonAlgo.cc.

References changeTrack(), ALCARECOTkAlJpsiMuMu_cff::charge, cosmicRejDistance_, particleFlow_cfi::dEta, particleFlow_cfi::dPhi, PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi::dR, goodMuonTracks(), mps_fire::i, edm::Ref< C, T, F >::isNonnull(), METX_, METY_, reco::PFCandidate::mu, reco::PFCandidate::muonRef(), pfAddedMuonCandidates_, pfElectronTranslator_cfi::PFCandidate, postCleaning_, mathSSE::sqrt(), reco::PFCandidate::trackRef(), l1t::tracks, tracksPointingAtMET(), and vertices_.

Referenced by PFAlgo::reconstructParticles().

863  {
864  if(!postCleaning_)
865  return;
866 
867 
868  if( pfAddedMuonCandidates_.get() )
869  pfAddedMuonCandidates_->clear();
870  else
872 
873 
874 
875  for ( unsigned imu = 0; imu < muons->size(); ++imu ) {
876  reco::MuonRef muonRef( muons, imu );
877  bool used = false;
878  bool hadron = false;
879  for(unsigned i=0; i<cands->size(); i++) {
880  const PFCandidate& pfc = cands->at(i);
881  if ( !pfc.trackRef().isNonnull() ) continue;
882  if ( pfc.trackRef().isNonnull() && pfc.trackRef() == muonRef->track() )
883  hadron = true;
884  if ( !pfc.muonRef().isNonnull() ) continue;
885 
886  if ( pfc.muonRef()->innerTrack() == muonRef->innerTrack())
887  used = true;
888  else {
889  // Check if the stand-alone muon is not a spurious copy of an existing muon
890  // (Protection needed for HLT)
891  if ( pfc.muonRef()->isStandAloneMuon() && muonRef->isStandAloneMuon() ) {
892  double dEta = pfc.muonRef()->standAloneMuon()->eta() - muonRef->standAloneMuon()->eta();
893  double dPhi = pfc.muonRef()->standAloneMuon()->phi() - muonRef->standAloneMuon()->phi();
894  double dR = sqrt(dEta*dEta + dPhi*dPhi);
895  if ( dR < 0.005 ) {
896  used = true;
897  }
898  }
899  }
900 
901  if ( used ) break;
902  }
903 
904  if ( used ||hadron||(!muonRef.isNonnull()) ) continue;
905 
906 
907  TrackMETComparator comparator(METX_,METY_);
908  //Low pt dont need to be cleaned
909 
910  std::vector<reco::Muon::MuonTrackTypePair> tracks = goodMuonTracks(muonRef,true);
911  //If there is at least 1 track choice try to change the track
912  if(!tracks.empty()) {
913 
914  //Find tracks that change dramatically MET or Pt
915  std::vector<reco::Muon::MuonTrackTypePair> tracksThatChangeMET = tracksPointingAtMET(tracks);
916  //From those tracks get the one with smallest MET
917  if (!tracksThatChangeMET.empty()) {
918  reco::Muon::MuonTrackTypePair bestTrackType = *std::min_element(tracksThatChangeMET.begin(),tracksThatChangeMET.end(),comparator);
919 
920  //Make sure it is not cosmic
921  if((vertices_->empty()) ||bestTrackType.first->dz(vertices_->at(0).position())<cosmicRejDistance_){
922 
923  //make a pfcandidate
924  int charge = bestTrackType.first->charge()>0 ? 1 : -1;
925  math::XYZTLorentzVector momentum(bestTrackType.first->px(),
926  bestTrackType.first->py(),
927  bestTrackType.first->pz(),
928  sqrt(bestTrackType.first->p()*bestTrackType.first->p()+0.1057*0.1057));
929 
930  cands->push_back( PFCandidate( charge,
931  momentum,
933 
934  changeTrack(cands->back(),bestTrackType);
935 
936  if (muonRef->track().isNonnull() )
937  cands->back().setTrackRef( muonRef->track() );
938 
939  cands->back().setMuonRef(muonRef);
940 
941 
942  pfAddedMuonCandidates_->push_back(cands->back());
943 
944  }
945  }
946  }
947  }
948 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
const bool postCleaning_
Definition: PFMuonAlgo.h:139
std::vector< MuonTrackTypePair > tracksPointingAtMET(const std::vector< MuonTrackTypePair > &)
Definition: PFMuonAlgo.cc:1058
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:442
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
const double cosmicRejDistance_
Definition: PFMuonAlgo.h:154
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< reco::Muon::MuonTrackTypePair > goodMuonTracks(const reco::MuonRef &muon, bool includeSA=false)
Definition: PFMuonAlgo.cc:559
void changeTrack(reco::PFCandidate &, const MuonTrackTypePair &)
Definition: PFMuonAlgo.cc:702
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
std::unique_ptr< reco::PFCandidateCollection > pfAddedMuonCandidates_
the collection of added muon candidates
Definition: PFMuonAlgo.h:121
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
double METX_
Definition: PFMuonAlgo.h:158
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
const reco::VertexCollection * vertices_
Definition: PFMuonAlgo.h:127
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:40
double METY_
Definition: PFMuonAlgo.h:159
void PFMuonAlgo::changeTrack ( reco::PFCandidate candidate,
const MuonTrackTypePair track 
)

Definition at line 702 of file PFMuonAlgo.cc.

References reco::Muon::CombinedTrack, reco::Muon::DYT, reco::Muon::InnerTrack, reco::PFCandidate::mu, reco::Muon::Picky, reco::LeafCandidate::setCharge(), reco::PFCandidate::setMuonTrackType(), reco::LeafCandidate::setP4(), reco::PFCandidate::setParticleType(), reco::PFCandidate::setVertexSource(), mathSSE::sqrt(), reco::Muon::TPFMS, and tkIsoDeposits_cff::trackType.

Referenced by addMissingMuons(), cleanMismeasured(), and reconstructMuon().

702  {
703  using namespace reco;
704  reco::TrackRef bestTrack = track.first;
705  MuonTrackType trackType = track.second;
706  //OK Now redefine the canddiate with that track
707  double px = bestTrack->px();
708  double py = bestTrack->py();
709  double pz = bestTrack->pz();
710  double energy = sqrt(bestTrack->p()*bestTrack->p() + 0.1057*0.1057);
711 
712  candidate.setCharge(bestTrack->charge()>0 ? 1 : -1);
713  candidate.setP4(math::XYZTLorentzVector(px,py,pz,energy));
715  // candidate.setTrackRef( bestTrack );
716  candidate.setMuonTrackType(trackType);
717  if(trackType == reco::Muon::InnerTrack)
718  candidate.setVertexSource( PFCandidate::kTrkMuonVertex );
719  else if(trackType == reco::Muon::CombinedTrack)
720  candidate.setVertexSource( PFCandidate::kComMuonVertex );
721  else if(trackType == reco::Muon::TPFMS)
722  candidate.setVertexSource( PFCandidate::kTPFMSMuonVertex );
723  else if(trackType == reco::Muon::Picky)
724  candidate.setVertexSource( PFCandidate::kPickyMuonVertex );
725  else if(trackType == reco::Muon::DYT)
726  candidate.setVertexSource( PFCandidate::kDYTMuonVertex );
727  }
void setCharge(Charge q) final
set electric charge
Definition: LeafCandidate.h:93
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void setVertexSource(PFVertexType vt)
Definition: PFCandidate.h:407
void setMuonTrackType(const reco::Muon::MuonTrackType &type)
set the Best Muon Track Ref
Definition: PFCandidate.h:357
void setParticleType(ParticleType type)
set Particle Type
Definition: PFCandidate.cc:265
T sqrt(T t)
Definition: SSEVec.h:18
fixed size matrix
MuonTrackType
Definition: MuonTrackType.h:28
void setP4(const LorentzVector &p4) final
set 4-momentum
bool PFMuonAlgo::cleanMismeasured ( reco::PFCandidate pfc,
unsigned int  i 
)
private

Definition at line 971 of file PFMuonAlgo.cc.

References changeTrack(), eventFractionRejection_, goodMuonTracks(), maskedIndices_, metFactorRejection_, metSigForRejection_, METX_, METY_, minPostCleaningPt_, reco::PFCandidate::muonRef(), pfCleanedTrackerAndGlobalMuonCandidates_, pfFakeMuonCleanedCandidates_, reco::LeafCandidate::pt(), reco::LeafCandidate::px(), reco::LeafCandidate::py(), mathSSE::sqrt(), sumet_, sumetPU_, l1t::tracks, and tracksWithBetterMET().

Referenced by postClean(), and transferAddedMuonCandidates().

971  {
972  using namespace std;
973  using namespace reco;
974  bool cleaned=false;
975 
976  //First define the MET without this guy
977  double METNOX = METX_ - pfc.px();
978  double METNOY = METY_ - pfc.py();
979  double SUMETNO = sumet_ -pfc.pt();
980 
981  TrackMETComparator comparator(METNOX,METNOY);
982  //Low pt dont need to be cleaned
983  if (pfc.pt()<minPostCleaningPt_)
984  return false;
985  std::vector<reco::Muon::MuonTrackTypePair> tracks = goodMuonTracks(pfc.muonRef(),false);
986 
987 
988 
989  //If there is more than 1 track choice try to change the track
990  if(tracks.size()>1) {
991  //Find tracks that change dramatically MET or Pt
992  std::vector<reco::Muon::MuonTrackTypePair> tracksThatChangeMET = tracksWithBetterMET(tracks,pfc);
993  //From those tracks get the one with smallest MET
994  if (!tracksThatChangeMET.empty()) {
995  reco::Muon::MuonTrackTypePair bestTrackType = *std::min_element(tracksThatChangeMET.begin(),tracksThatChangeMET.end(),comparator);
996  changeTrack(pfc,bestTrackType);
997 
999  //update eventquantities
1000  METX_ = METNOX+pfc.px();
1001  METY_ = METNOY+pfc.py();
1002  sumet_=SUMETNO+pfc.pt();
1003 
1004  }
1005  }
1006 
1007  //Now attempt to kill it
1008  if (!(pfc.muonRef()->isGlobalMuon() && pfc.muonRef()->isTrackerMuon())) {
1009  //define MET significance and SUM ET
1010  double MET2 = METX_*METX_+METY_*METY_;
1011  double newMET2 = METNOX*METNOX+METNOY*METNOY;
1012  double METSig = sqrt(MET2)/sqrt(sumet_-sumetPU_);
1013  if( METSig>metSigForRejection_)
1014  if((newMET2 < MET2/metFactorRejection_) &&
1016  pfFakeMuonCleanedCandidates_->push_back(pfc);
1017  maskedIndices_.push_back(i);
1018  METX_ = METNOX;
1019  METY_ = METNOY;
1020  sumet_=SUMETNO;
1021  cleaned=true;
1022  }
1023 
1024  }
1025  return cleaned;
1026 
1027 }
double sumet_
Definition: PFMuonAlgo.h:157
const double metFactorRejection_
Definition: PFMuonAlgo.h:146
double px() const final
x coordinate of momentum vector
std::unique_ptr< reco::PFCandidateCollection > pfFakeMuonCleanedCandidates_
the collection of fake cleaned muon candidates
Definition: PFMuonAlgo.h:115
double pt() const final
transverse momentum
std::unique_ptr< reco::PFCandidateCollection > pfCleanedTrackerAndGlobalMuonCandidates_
the collection of tracker/global cleaned muon candidates
Definition: PFMuonAlgo.h:113
T sqrt(T t)
Definition: SSEVec.h:18
const double minPostCleaningPt_
Definition: PFMuonAlgo.h:140
std::vector< reco::Muon::MuonTrackTypePair > goodMuonTracks(const reco::MuonRef &muon, bool includeSA=false)
Definition: PFMuonAlgo.cc:559
void changeTrack(reco::PFCandidate &, const MuonTrackTypePair &)
Definition: PFMuonAlgo.cc:702
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
std::vector< unsigned int > maskedIndices_
Definition: PFMuonAlgo.h:123
double METX_
Definition: PFMuonAlgo.h:158
double py() const final
y coordinate of momentum vector
fixed size matrix
double sumetPU_
Definition: PFMuonAlgo.h:156
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:40
std::vector< MuonTrackTypePair > tracksWithBetterMET(const std::vector< MuonTrackTypePair > &, const reco::PFCandidate &)
Definition: PFMuonAlgo.cc:1030
const double eventFractionRejection_
Definition: PFMuonAlgo.h:145
const double metSigForRejection_
Definition: PFMuonAlgo.h:143
double METY_
Definition: PFMuonAlgo.h:159
bool PFMuonAlgo::cleanPunchThroughAndFakes ( reco::PFCandidate pfc,
reco::PFCandidateCollection cands,
unsigned int  imu 
)
private

Definition at line 1080 of file PFMuonAlgo.cc.

References reco::PFCandidate::elementsInBlocks(), reco::LeafCandidate::eta(), getMinMaxMET2(), reco::PFCandidate::h, reco::PFCandidate::h0, mps_fire::i, isIsolatedMuon(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::key(), maskedIndices_, SiStripPI::max, metFactorFake_, metFactorHighEta_, METX_, METY_, minPostCleaningPt_, minPunchThroughEnergy_, minPunchThroughMomentum_, reco::PFCandidate::muonRef(), reco::LeafCandidate::p(), reco::PFCandidate::particleId(), pfFakeMuonCleanedCandidates_, pfPunchThroughHadronCleanedCandidates_, pfPunchThroughMuonCleanedCandidates_, reco::LeafCandidate::pt(), ptFactorHighEta_, punchThroughFactor_, punchThroughMETFactor_, reco::PFCandidate::rawEcalEnergy(), reco::PFCandidate::rawHcalEnergy(), edm::second(), sumet_, and sumetPU_.

Referenced by postClean(), and transferAddedMuonCandidates().

1080  {
1081  using namespace reco;
1082 
1083  bool cleaned=false;
1084 
1085  if (pfc.pt()<minPostCleaningPt_)
1086  return false;
1087 
1088 
1089  double METXNO = METX_-pfc.pt();
1090  double METYNO = METY_-pfc.pt();
1091  double MET2NO = METXNO*METXNO+METYNO*METYNO;
1092  double MET2 = METX_*METX_+METY_*METY_;
1093  bool fake1=false;
1094 
1095  std::pair<double,double> met2 = getMinMaxMET2(pfc);
1096 
1097  //Check for Fakes at high pseudorapidity
1098  if(pfc.muonRef()->standAloneMuon().isNonnull())
1099  fake1 =fabs ( pfc.eta() ) > 2.15 &&
1100  met2.first<met2.second/2 &&
1101  MET2NO < MET2/metFactorHighEta_ &&
1102  pfc.muonRef()->standAloneMuon()->pt() < pfc.pt()/ptFactorHighEta_;
1103 
1104  double factor = std::max(2.,2000./(sumet_-pfc.pt()-sumetPU_));
1105  bool fake2 = ( pfc.pt()/(sumet_-sumetPU_) < 0.25 && MET2NO < MET2/metFactorFake_ && met2.first<met2.second/factor );
1106 
1107  bool punchthrough =pfc.p() > minPunchThroughMomentum_ &&
1109  pfc.rawEcalEnergy()+pfc.rawHcalEnergy() > pfc.p()/punchThroughFactor_ &&
1110  !isIsolatedMuon(pfc.muonRef()) && MET2NO < MET2/punchThroughMETFactor_;
1111 
1112 
1113  if(fake1 || fake2||punchthrough) {
1114  // Find the block of the muon
1115  const PFCandidate::ElementsInBlocks& eleInBlocks = pfc.elementsInBlocks();
1116  if ( !eleInBlocks.empty() ) {
1117  PFBlockRef blockRefMuon = eleInBlocks[0].first;
1118  unsigned indexMuon = eleInBlocks[0].second;
1119  if (eleInBlocks.size()>1)
1120  indexMuon = eleInBlocks[1].second;
1121 
1122  // Check if the muon gave rise to a neutral hadron
1123  double iHad = 1E9;
1124  bool hadron = false;
1125  for ( unsigned i = imu+1; i < cands->size(); ++i ) {
1126  const PFCandidate& pfcn = cands->at(i);
1127  const PFCandidate::ElementsInBlocks& ele = pfcn.elementsInBlocks();
1128  if ( ele.empty() ) {
1129  continue;
1130  }
1131  PFBlockRef blockRefHadron = ele[0].first;
1132  unsigned indexHadron = ele[0].second;
1133  // We are out of the block -> exit the loop
1134  if ( blockRefHadron.key() != blockRefMuon.key() ) break;
1135  // Check that this particle is a neutral hadron
1136  if ( indexHadron == indexMuon &&
1137  pfcn.particleId() == reco::PFCandidate::h0 ) {
1138  iHad = i;
1139  hadron = true;
1140  }
1141  if ( hadron ) break;
1142  }
1143 
1144  if ( hadron ) {
1145 
1146  double rescaleFactor = cands->at(iHad).p()/cands->at(imu).p();
1147  METX_ -= cands->at(imu).px() + cands->at(iHad).px();
1148  METY_ -= cands->at(imu).py() + cands->at(iHad).py();
1149  sumet_ -=cands->at(imu).pt();
1150  cands->at(imu).rescaleMomentum(rescaleFactor);
1151  maskedIndices_.push_back(iHad);
1152  pfPunchThroughHadronCleanedCandidates_->push_back(cands->at(iHad));
1153  cands->at(imu).setParticleType(reco::PFCandidate::h);
1154  pfPunchThroughMuonCleanedCandidates_->push_back(cands->at(imu));
1155  METX_ += cands->at(imu).px();
1156  METY_ += cands->at(imu).py();
1157  sumet_ += cands->at(imu).pt();
1158 
1159  } else if ( fake1 || fake2 ) {
1160  METX_ -= cands->at(imu).px();
1161  METY_ -= cands->at(imu).py();
1162  sumet_ -= cands->at(imu).pt();
1163  maskedIndices_.push_back(imu);
1164  pfFakeMuonCleanedCandidates_->push_back(cands->at(imu));
1165  cleaned=true;
1166  }
1167  }
1168  }
1169  return cleaned;
1170 }
static bool isIsolatedMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:137
double sumet_
Definition: PFMuonAlgo.h:157
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
std::unique_ptr< reco::PFCandidateCollection > pfPunchThroughMuonCleanedCandidates_
the collection of punch-through cleaned muon candidates
Definition: PFMuonAlgo.h:117
double eta() const final
momentum pseudorapidity
double rawEcalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:225
const double minPunchThroughEnergy_
Definition: PFMuonAlgo.h:151
std::unique_ptr< reco::PFCandidateCollection > pfFakeMuonCleanedCandidates_
the collection of fake cleaned muon candidates
Definition: PFMuonAlgo.h:115
const double minPunchThroughMomentum_
Definition: PFMuonAlgo.h:150
double pt() const final
transverse momentum
const double punchThroughFactor_
Definition: PFMuonAlgo.h:152
key_type key() const
Accessor for product key.
Definition: Ref.h:263
std::vector< ElementInBlock > ElementsInBlocks
Definition: PFCandidate.h:387
U second(std::pair< T, U > const &p)
const double metFactorHighEta_
Definition: PFMuonAlgo.h:147
const double minPostCleaningPt_
Definition: PFMuonAlgo.h:140
const double ptFactorHighEta_
Definition: PFMuonAlgo.h:148
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
const double metFactorFake_
Definition: PFMuonAlgo.h:149
double p() const final
magnitude of momentum vector
std::vector< unsigned int > maskedIndices_
Definition: PFMuonAlgo.h:123
double METX_
Definition: PFMuonAlgo.h:158
std::pair< double, double > getMinMaxMET2(const reco::PFCandidate &)
Definition: PFMuonAlgo.cc:951
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
double sumetPU_
Definition: PFMuonAlgo.h:156
const double punchThroughMETFactor_
Definition: PFMuonAlgo.h:153
virtual ParticleType particleId() const
Definition: PFCandidate.h:374
const ElementsInBlocks & elementsInBlocks() const
Definition: PFCandidate.cc:691
double rawHcalEnergy() const
return raw Hcal energy
Definition: PFCandidate.h:235
std::unique_ptr< reco::PFCandidateCollection > pfPunchThroughHadronCleanedCandidates_
the collection of punch-through cleaned neutral hadron candidates
Definition: PFMuonAlgo.h:119
double METY_
Definition: PFMuonAlgo.h:159
void PFMuonAlgo::estimateEventQuantities ( const reco::PFCandidateCollection pfc)
private

Definition at line 740 of file PFMuonAlgo.cc.

References mps_fire::i, METX_, METY_, sumet_, and sumetPU_.

Referenced by postClean(), and transferAddedMuonCandidates().

741 {
742  //SUM ET
743  sumetPU_ = 0.0;
744  METX_=0.;
745  METY_=0.;
746  sumet_=0.0;
747  for(reco::PFCandidateCollection::const_iterator i = pfc->begin();i!=pfc->end();++i) {
748  sumet_+=i->pt();
749  METX_+=i->px();
750  METY_+=i->py();
751  }
752 
753 }
double sumet_
Definition: PFMuonAlgo.h:157
double METX_
Definition: PFMuonAlgo.h:158
double sumetPU_
Definition: PFMuonAlgo.h:156
double METY_
Definition: PFMuonAlgo.h:159
std::pair< double, double > PFMuonAlgo::getMinMaxMET2 ( const reco::PFCandidate pfc)
private

Definition at line 951 of file PFMuonAlgo.cc.

References goodMuonTracks(), mps_fire::i, METX_, METY_, reco::PFCandidate::muonRef(), funct::pow(), reco::LeafCandidate::px(), reco::LeafCandidate::py(), and l1t::tracks.

Referenced by cleanPunchThroughAndFakes(), and transferAddedMuonCandidates().

951  {
952  std::vector<reco::Muon::MuonTrackTypePair> tracks = goodMuonTracks((pfc.muonRef()),true);
953 
954  double METXNO = METX_-pfc.px();
955  double METYNO = METY_-pfc.py();
956  std::vector<double> met2;
957  for (unsigned int i=0;i<tracks.size();++i) {
958  met2.push_back(pow(METXNO+tracks.at(i).first->px(),2)+pow(METYNO+tracks.at(i).first->py(),2));
959  }
960 
961  //PROTECT for cases of only one track. If there is only one track it will crash .
962  //Has never happened but could likely happen!
963 
964  if(tracks.size()>1)
965  return std::make_pair(*std::min_element(met2.begin(),met2.end()),*std::max_element(met2.begin(),met2.end()));
966  else
967  return std::make_pair(0,0);
968 }
double px() const final
x coordinate of momentum vector
std::vector< reco::Muon::MuonTrackTypePair > goodMuonTracks(const reco::MuonRef &muon, bool includeSA=false)
Definition: PFMuonAlgo.cc:559
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
double METX_
Definition: PFMuonAlgo.h:158
double py() const final
y coordinate of momentum vector
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double METY_
Definition: PFMuonAlgo.h:159
reco::Muon::MuonTrackTypePair PFMuonAlgo::getTrackWithSmallestError ( const std::vector< MuonTrackTypePair > &  tracks)
private

Definition at line 731 of file PFMuonAlgo.cc.

References MCScenario_CRAFT1_22X::sorter().

Referenced by reconstructMuon(), and transferAddedMuonCandidates().

731  {
732  TrackPtErrorSorter sorter;
733  return *std::min_element(tracks.begin(),tracks.end(),sorter);
734 }
std::vector< reco::Muon::MuonTrackTypePair > PFMuonAlgo::goodMuonTracks ( const reco::MuonRef muon,
bool  includeSA = false 
)
private

Definition at line 559 of file PFMuonAlgo.cc.

References maxDPtOPt_, and muonTracks().

Referenced by addMissingMuons(), cleanMismeasured(), getMinMaxMET2(), hasValidTrack(), reconstructMuon(), and transferAddedMuonCandidates().

559  {
560  return muonTracks(muon,includeSA,maxDPtOPt_);
561 }
const double maxDPtOPt_
Definition: PFMuonAlgo.h:132
std::vector< reco::Muon::MuonTrackTypePair > muonTracks(const reco::MuonRef &muon, bool includeSA=false, double dpt=1e+9)
Definition: PFMuonAlgo.cc:565
bool PFMuonAlgo::hasValidTrack ( const reco::MuonRef muonRef,
bool  loose = false 
)

Definition at line 412 of file PFMuonAlgo.cc.

References goodMuonTracks(), and muonTracks().

412  {
413  if(loose)
414  return !muonTracks(muonRef).empty();
415  else
416  return !goodMuonTracks(muonRef).empty();
417 
418 }
std::vector< reco::Muon::MuonTrackTypePair > goodMuonTracks(const reco::MuonRef &muon, bool includeSA=false)
Definition: PFMuonAlgo.cc:559
std::vector< reco::Muon::MuonTrackTypePair > muonTracks(const reco::MuonRef &muon, bool includeSA=false, double dpt=1e+9)
Definition: PFMuonAlgo.cc:565
bool PFMuonAlgo::isGlobalLooseMuon ( const reco::PFBlockElement elt)
static

Definition at line 111 of file PFMuonAlgo.cc.

References reco::PFBlockElementTrack::muonRef().

Referenced by isLooseMuon().

111  {
112 
113  const reco::PFBlockElementTrack* eltTrack
114  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
115 
116  assert ( eltTrack );
117  reco::MuonRef muonRef = eltTrack->muonRef();
118 
119  return isGlobalLooseMuon(muonRef);
120 
121 }
static bool isGlobalLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:111
const reco::MuonRef & muonRef() const override
bool PFMuonAlgo::isGlobalLooseMuon ( const reco::MuonRef muonRef)
static

Definition at line 254 of file PFMuonAlgo.cc.

References muon::isGoodMuon(), edm::Ref< C, T, F >::isNonnull(), min(), jets_cff::quality, mps_fire::result, and muon::TMLastStationAngTight.

254  {
255 
256  if ( !muonRef.isNonnull() ) return false;
257  if ( !muonRef->isGlobalMuon() ) return false;
258  if ( !muonRef->isStandAloneMuon() ) return false;
259 
260  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
261  reco::TrackRef combinedMu = muonRef->combinedMuon();
262  reco::TrackRef trackerMu = muonRef->track();
263 
264  unsigned nMuonHits =
265  standAloneMu->hitPattern().numberOfValidMuonDTHits() +
266  2*standAloneMu->hitPattern().numberOfValidMuonCSCHits();
267 
268  bool quality = false;
269 
270  if ( muonRef->isTrackerMuon() ){
271 
272  bool result = combinedMu->normalizedChi2() < 100.;
273 
274  bool laststation =
276 
277  int nMatches = muonRef->numberOfMatches();
278 
279  quality = laststation && nMuonHits > 12 && nMatches > 1;
280 
281  return result && quality;
282 
283  }
284  else{
285 
286  // Check the quality of the stand-alone muon :
287  // good chi**2 and large number of hits and good pt error
288  if ( nMuonHits <=15 ||
289  standAloneMu->normalizedChi2() > 10. ||
290  standAloneMu->ptError()/standAloneMu->pt() > 0.20 ) {
291  quality = false;
292  }
293  else {
294  // If the stand-alone muon is good, check the global muon
295  if ( combinedMu->normalizedChi2() > standAloneMu->normalizedChi2() ) {
296  // If the combined muon is worse than the stand-alone, it
297  // means that either the corresponding tracker track was not
298  // reconstructed, or that the sta muon comes from a late
299  // pion decay (hence with a momentum smaller than the track)
300  // Take the stand-alone muon only if its momentum is larger
301  // than that of the track
302 
303  // Note that here we even take the standAlone if it has a smaller pT, in contrast to GlobalTight
304  if(standAloneMu->pt() > trackerMu->pt() || combinedMu->normalizedChi2()<5.) quality = true;
305  }
306  else {
307  // If the combined muon is better (and good enough), take the
308  // global muon
309  if(combinedMu->ptError()/combinedMu->pt() < std::min(0.20,standAloneMu->ptError()/standAloneMu->pt()))
310  quality = true;
311 
312  }
313  }
314  }
315 
316 
317  return quality;
318 
319 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
T min(T a, T b)
Definition: MathUtil.h:58
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
bool PFMuonAlgo::isGlobalTightMuon ( const reco::PFBlockElement elt)
static

Definition at line 98 of file PFMuonAlgo.cc.

References reco::PFBlockElementTrack::muonRef().

Referenced by isMuon(), and PFAlgo::processBlock().

98  {
99 
100  const reco::PFBlockElementTrack* eltTrack
101  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
102 
103  assert ( eltTrack );
104  reco::MuonRef muonRef = eltTrack->muonRef();
105 
106  return isGlobalTightMuon(muonRef);
107 
108 }
static bool isGlobalTightMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:98
const reco::MuonRef & muonRef() const override
bool PFMuonAlgo::isGlobalTightMuon ( const reco::MuonRef muonRef)
static

Definition at line 163 of file PFMuonAlgo.cc.

References muon::GlobalMuonPromptTight, muon::isGoodMuon(), edm::Ref< C, T, F >::isNonnull(), min(), jets_cff::quality, mps_fire::result, and muon::TM2DCompatibilityTight.

163  {
164 
165  if ( !muonRef.isNonnull() ) return false;
166 
167  if ( !muonRef->isGlobalMuon() ) return false;
168  if ( !muonRef->isStandAloneMuon() ) return false;
169 
170 
171  if ( muonRef->isTrackerMuon() ) {
172 
174 
175  bool isTM2DCompatibilityTight = muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityTight);
176  int nMatches = muonRef->numberOfMatches();
177  bool quality = nMatches > 2 || isTM2DCompatibilityTight;
178 
179  return result && quality;
180 
181  } else {
182 
183  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
184 
185  // No tracker muon -> Request a perfect stand-alone muon, or an even better global muon
186  bool result = false;
187 
188  // Check the quality of the stand-alone muon :
189  // good chi**2 and large number of hits and good pt error
190  if ( ( standAloneMu->hitPattern().numberOfValidMuonDTHits() < 22 &&
191  standAloneMu->hitPattern().numberOfValidMuonCSCHits() < 15 ) ||
192  standAloneMu->normalizedChi2() > 10. ||
193  standAloneMu->ptError()/standAloneMu->pt() > 0.20 ) {
194  result = false;
195  } else {
196 
197  reco::TrackRef combinedMu = muonRef->combinedMuon();
198  reco::TrackRef trackerMu = muonRef->track();
199 
200  // If the stand-alone muon is good, check the global muon
201  if ( combinedMu->normalizedChi2() > standAloneMu->normalizedChi2() ) {
202  // If the combined muon is worse than the stand-alone, it
203  // means that either the corresponding tracker track was not
204  // reconstructed, or that the sta muon comes from a late
205  // pion decay (hence with a momentum smaller than the track)
206  // Take the stand-alone muon only if its momentum is larger
207  // than that of the track
208  result = standAloneMu->pt() > trackerMu->pt() ;
209  } else {
210  // If the combined muon is better (and good enough), take the
211  // global muon
212  result =
213  combinedMu->ptError()/combinedMu->pt() <
214  std::min(0.20,standAloneMu->ptError()/standAloneMu->pt());
215  }
216  }
217 
218  return result;
219  }
220 
221  return false;
222 
223 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
T min(T a, T b)
Definition: MathUtil.h:58
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
bool PFMuonAlgo::isIsolatedMuon ( const reco::PFBlockElement elt)
static

Definition at line 137 of file PFMuonAlgo.cc.

References reco::PFBlockElementTrack::muonRef().

Referenced by cleanPunchThroughAndFakes(), GreedyMuonPFCandidateFilter::filter(), isMuon(), and PFAlgo::processBlock().

137  {
138 
139  const reco::PFBlockElementTrack* eltTrack
140  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
141 
142  assert ( eltTrack );
143  reco::MuonRef muonRef = eltTrack->muonRef();
144 
145  return isIsolatedMuon(muonRef);
146 
147 }
static bool isIsolatedMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:137
const reco::MuonRef & muonRef() const override
bool PFMuonAlgo::isIsolatedMuon ( const reco::MuonRef muonRef)
static

Definition at line 345 of file PFMuonAlgo.cc.

References edm::Ref< C, T, F >::isNonnull(), and objects.autophobj::relIso.

345  {
346 
347 
348  if ( !muonRef.isNonnull() ) return false;
349  if ( !muonRef->isIsolationValid() ) return false;
350 
351  // Isolated Muons which are missed by standard cuts are nearly always global+tracker
352  if ( !muonRef->isGlobalMuon() ) return false;
353 
354  // If it's not a tracker muon, only take it if there are valid muon hits
355 
356  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
357 
358  if ( !muonRef->isTrackerMuon() ){
359  if(standAloneMu->hitPattern().numberOfValidMuonDTHits() == 0 &&
360  standAloneMu->hitPattern().numberOfValidMuonCSCHits() ==0) return false;
361  }
362 
363  // for isolation, take the smallest pt available to reject fakes
364 
365  reco::TrackRef combinedMu = muonRef->combinedMuon();
366  double smallestMuPt = combinedMu->pt();
367 
368  if(standAloneMu->pt()<smallestMuPt) smallestMuPt = standAloneMu->pt();
369 
370  if(muonRef->isTrackerMuon())
371  {
372  reco::TrackRef trackerMu = muonRef->track();
373  if(trackerMu->pt() < smallestMuPt) smallestMuPt= trackerMu->pt();
374  }
375 
376 
377  double sumPtR03 = muonRef->isolationR03().sumPt;
378 
379  double relIso = sumPtR03/smallestMuPt;
380 
381 
382 
383 
384  if(relIso<0.1) return true;
385  else return false;
386 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
bool PFMuonAlgo::isLooseMuon ( const reco::PFBlockElement elt)
static

Definition at line 78 of file PFMuonAlgo.cc.

References reco::PFBlockElementTrack::muonRef().

Referenced by GeneralTracksImporter::importToBlock(), GeneralTracksImporterWithVeto::importToBlock(), PFAlgo::processBlock(), and reconstructMuon().

78  {
79 
80 
81  const reco::PFBlockElementTrack* eltTrack
82  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
83 
84 
85 
86  assert ( eltTrack );
87 
88 
89  reco::MuonRef muonRef = eltTrack->muonRef();
90 
91 
92  return isLooseMuon(muonRef);
93 
94 }
static bool isLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:78
const reco::MuonRef & muonRef() const override
bool PFMuonAlgo::isLooseMuon ( const reco::MuonRef muonRef)
static

Definition at line 156 of file PFMuonAlgo.cc.

References isGlobalLooseMuon(), and isTrackerLooseMuon().

156  {
157 
158  return (isGlobalLooseMuon(muonRef) || isTrackerLooseMuon(muonRef));
159 
160 }
static bool isTrackerLooseMuon(const reco::PFBlockElement &elt)
static bool isGlobalLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:111
bool PFMuonAlgo::isMuon ( const reco::PFBlockElement elt)
static

Definition at line 66 of file PFMuonAlgo.cc.

Referenced by GeneralTracksImporter::importToBlock(), GeneralTracksImporterWithVeto::importToBlock(), PFEGammaAlgo::isMuon(), PFAlgo::processBlock(), reconstructMuon(), and PFElectronAlgo::SetLinks().

66  {
67 
68  const auto* eltTrack = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
69 
70  assert ( eltTrack );
71  reco::MuonRef muonRef = eltTrack->muonRef();
72 
73  return isMuon(muonRef);
74 
75 }
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:66
bool PFMuonAlgo::isMuon ( const reco::MuonRef muonRef)
static

Definition at line 150 of file PFMuonAlgo.cc.

References isGlobalTightMuon(), isIsolatedMuon(), and isTrackerTightMuon().

150  {
151 
152  return isGlobalTightMuon(muonRef) || isTrackerTightMuon(muonRef) || isIsolatedMuon(muonRef);
153 }
static bool isIsolatedMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:137
static bool isGlobalTightMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:98
static bool isTrackerTightMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:124
bool PFMuonAlgo::isTightMuonPOG ( const reco::MuonRef muonRef)
static

Definition at line 389 of file PFMuonAlgo.cc.

References muon::GlobalMuonPromptTight, and muon::isGoodMuon().

389  {
390 
391  if(!muon::isGoodMuon(*muonRef,muon::GlobalMuonPromptTight)) return false;
392 
393  if(!muonRef->isTrackerMuon()) return false;
394 
395  if(muonRef->numberOfMatches()<2) return false;
396 
397  //const reco::TrackRef& combinedMuon = muonRef->combinedMuon();
398  const reco::TrackRef& combinedMuon = muonRef->globalTrack();
399 
400  if(combinedMuon->hitPattern().numberOfValidTrackerHits()<11) return false;
401 
402  if(combinedMuon->hitPattern().numberOfValidPixelHits()==0) return false;
403 
404  if(combinedMuon->hitPattern().numberOfValidMuonHits()==0) return false;
405 
406  return true;
407 
408 }
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
static bool PFMuonAlgo::isTrackerLooseMuon ( const reco::PFBlockElement elt)
static

Referenced by isLooseMuon().

bool PFMuonAlgo::isTrackerLooseMuon ( const reco::MuonRef muonRef)
static

Definition at line 323 of file PFMuonAlgo.cc.

References muon::AllArbitrated, muon::isGoodMuon(), edm::Ref< C, T, F >::isNonnull(), jets_cff::quality, and muon::TMLastStationAngTight.

323  {
324 
325  if ( !muonRef.isNonnull() ) return false;
326  if(!muonRef->isTrackerMuon()) return false;
327 
328  reco::TrackRef trackerMu = muonRef->track();
329 
330  if(trackerMu->ptError()/trackerMu->pt() > 0.20) return false;
331 
332  // this doesn't seem to be necessary on the small samples looked at, but keep it around as insurance
333  if(trackerMu->pt()>20.) return false;
334 
335  bool isAllArbitrated = muon::isGoodMuon(*muonRef,muon::AllArbitrated);
336  bool isTMLastStationAngTight = muon::isGoodMuon(*muonRef,muon::TMLastStationAngTight);
337 
338  bool quality = isAllArbitrated && isTMLastStationAngTight;
339 
340  return quality;
341 
342 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
bool PFMuonAlgo::isTrackerTightMuon ( const reco::PFBlockElement elt)
static

Definition at line 124 of file PFMuonAlgo.cc.

References reco::PFBlockElementTrack::muonRef().

Referenced by isMuon(), and PFAlgo::processBlock().

124  {
125 
126  const reco::PFBlockElementTrack* eltTrack
127  = dynamic_cast<const reco::PFBlockElementTrack*>(&elt);
128 
129  assert ( eltTrack );
130  reco::MuonRef muonRef = eltTrack->muonRef();
131 
132  return isTrackerTightMuon(muonRef);
133 
134 }
const reco::MuonRef & muonRef() const override
static bool isTrackerTightMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:124
bool PFMuonAlgo::isTrackerTightMuon ( const reco::MuonRef muonRef)
static

Definition at line 226 of file PFMuonAlgo.cc.

References muon::AllArbitrated, reco::TrackBase::hitPattern(), muon::isGoodMuon(), edm::Ref< C, T, F >::isNonnull(), reco::HitPattern::numberOfValidTrackerHits(), muon::TM2DCompatibilityTight, and HiIsolationCommonParameters_cff::track.

226  {
227 
228  if ( !muonRef.isNonnull() ) return false;
229 
230  if(!muonRef->isTrackerMuon()) return false;
231 
232  reco::TrackRef trackerMu = muonRef->track();
233  const reco::Track& track = *trackerMu;
234 
235  unsigned nTrackerHits = track.hitPattern().numberOfValidTrackerHits();
236 
237  if(nTrackerHits<=12) return false;
238 
239  bool isAllArbitrated = muon::isGoodMuon(*muonRef,muon::AllArbitrated);
240 
241  bool isTM2DCompatibilityTight = muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityTight);
242 
243  if(!isAllArbitrated || !isTM2DCompatibilityTight) return false;
244 
245  if((trackerMu->ptError()/trackerMu->pt() > 0.10)){
246  //std::cout<<" PT ERROR > 10 % "<< trackerMu->pt() <<std::endl;
247  return false;
248  }
249  return true;
250 
251 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:479
int numberOfValidTrackerHits() const
Definition: HitPattern.h:901
std::vector< reco::Muon::MuonTrackTypePair > PFMuonAlgo::muonTracks ( const reco::MuonRef muon,
bool  includeSA = false,
double  dpt = 1e+9 
)
private

Definition at line 565 of file PFMuonAlgo.cc.

References reco::Muon::CombinedTrack, reco::Muon::DYT, reco::Muon::InnerTrack, edm::Ref< C, T, F >::isNonnull(), MillePedeFileConverter_cfg::out, reco::Muon::OuterTrack, reco::Muon::Picky, and reco::Muon::TPFMS.

Referenced by goodMuonTracks(), hasValidTrack(), reconstructMuon(), and transferAddedMuonCandidates().

565  {
566 
567 
568 
569  std::vector<reco::Muon::MuonTrackTypePair> out;
570 
571 
572  if(muon->globalTrack().isNonnull() && muon->globalTrack()->pt()>0)
573  if(muon->globalTrack()->ptError()/muon->globalTrack()->pt()<dpt)
574  out.emplace_back(muon->globalTrack(),reco::Muon::CombinedTrack);
575 
576  if(muon->innerTrack().isNonnull() && muon->innerTrack()->pt()>0)
577  if(muon->innerTrack()->ptError()/muon->innerTrack()->pt()<dpt)//Here Loose!@
578  out.emplace_back(muon->innerTrack(),reco::Muon::InnerTrack);
579 
580  bool pickyExists=false;
581  double pickyDpt=99999.;
582  if(muon->pickyTrack().isNonnull() && muon->pickyTrack()->pt()>0) {
583  pickyDpt = muon->pickyTrack()->ptError()/muon->pickyTrack()->pt();
584  if(pickyDpt<dpt)
585  out.emplace_back(muon->pickyTrack(),reco::Muon::Picky);
586  pickyExists=true;
587  }
588 
589  bool dytExists=false;
590  double dytDpt=99999.;
591  if(muon->dytTrack().isNonnull() && muon->dytTrack()->pt()>0) {
592  dytDpt = muon->dytTrack()->ptError()/muon->dytTrack()->pt();
593  if(dytDpt<dpt)
594  out.emplace_back(muon->dytTrack(),reco::Muon::DYT);
595  dytExists=true;
596  }
597 
598  //Magic: TPFMS is not a really good track especially under misalignment
599  //IT is kind of crap because if mu system is displaced it can make a change
600  //So allow TPFMS if there is no picky or the error of tpfms is better than picky
601  //AND if there is no DYT or the error of tpfms is better than DYT
602  if(muon->tpfmsTrack().isNonnull() && muon->tpfmsTrack()->pt()>0) {
603  double tpfmsDpt = muon->tpfmsTrack()->ptError()/muon->tpfmsTrack()->pt();
604  if( ( (pickyExists && tpfmsDpt<pickyDpt) || (!pickyExists) ) &&
605  ( (dytExists && tpfmsDpt<dytDpt) || (!dytExists) ) &&
606  tpfmsDpt<dpt )
607  out.emplace_back(muon->tpfmsTrack(),reco::Muon::TPFMS);
608  }
609 
610  if(includeSA && muon->outerTrack().isNonnull())
611  if(muon->outerTrack()->ptError()/muon->outerTrack()->pt()<dpt)
612  out.emplace_back(muon->outerTrack(),reco::Muon::OuterTrack);
613 
614  return out;
615 
616 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
void PFMuonAlgo::postClean ( reco::PFCandidateCollection cands)

Definition at line 759 of file PFMuonAlgo.cc.

References egammaForCoreTracking_cff::cands, cleanMismeasured(), cleanPunchThroughAndFakes(), cosmicRejDistance_, GlobalTrackerMuonAlignment_cfi::cosmics, estimateEventQuantities(), eventFactorCosmics_, mps_fire::i, maskedIndices_, METX_, METY_, reco::PFCandidate::mu, reco::PFCandidate::muonRef(), extraflags_cff::muons, reco::PFCandidate::particleId(), pfCleanedTrackerAndGlobalMuonCandidates_, pfCosmicsMuonCleanedCandidates_, pfFakeMuonCleanedCandidates_, pfPunchThroughHadronCleanedCandidates_, pfPunchThroughMuonCleanedCandidates_, postCleaning_, reco::LeafCandidate::pt(), reco::LeafCandidate::px(), reco::LeafCandidate::py(), removeDeadCandidates(), sumet_, sumetPU_, and vertices_.

Referenced by PFAlgo::reconstructParticles().

759  {
760  using namespace std;
761  using namespace reco;
762  if (!postCleaning_)
763  return;
764 
765  //Initialize vectors
766 
769  else
771 
774  else
776 
777  if( pfFakeMuonCleanedCandidates_.get() )
779  else
781 
782 
785  else
787 
790  else
792 
793 
794 
796 
797  maskedIndices_.clear();
798 
799  //Estimate MET and SumET
800 
802 
803 
804  std::vector<int> muons;
805  std::vector<int> cosmics;
806  //get the muons
807  for(unsigned int i=0;i<cands->size();++i) {
808  const reco::PFCandidate& cand = (*cands)[i];
809  if ( cand.particleId() == reco::PFCandidate::mu )
810  muons.push_back(i);
811 
812  }
813  //Then sort the muon indicess by decsending pt
814 
815  IndexPtComparator comparator(cands);
816  std::sort(muons.begin(),muons.end(),comparator);
817 
818 
819  //first kill cosmics
820  double METXCosmics=0;
821  double METYCosmics=0;
822  double SUMETCosmics=0.0;
823 
824  for(unsigned int i=0;i<muons.size();++i) {
825  const PFCandidate& pfc = cands->at(muons[i]);
826  double origin=0.0;
827  if(!vertices_->empty()&& vertices_->at(0).isValid() && ! vertices_->at(0).isFake())
828  origin = pfc.muonRef()->muonBestTrack()->dxy(vertices_->at(0).position());
829 
830  if( origin> cosmicRejDistance_) {
831  cosmics.push_back(muons[i]);
832  METXCosmics +=pfc.px();
833  METYCosmics +=pfc.py();
834  SUMETCosmics +=pfc.pt();
835  }
836  }
837  double MET2Cosmics = METXCosmics*METXCosmics+METYCosmics*METYCosmics;
838 
839  if ( SUMETCosmics > (sumet_-sumetPU_)/eventFactorCosmics_ && MET2Cosmics < METX_*METX_+ METY_*METY_)
840  for(unsigned int i=0;i<cosmics.size();++i) {
841  maskedIndices_.push_back(cosmics[i]);
842  pfCosmicsMuonCleanedCandidates_->push_back(cands->at(cosmics[i]));
843  }
844 
845  //Loop on the muons candidates and clean
846  for(unsigned int i=0;i<muons.size();++i) {
847  if( cleanMismeasured(cands->at(muons[i]),muons[i]))
848  continue;
849  cleanPunchThroughAndFakes(cands->at(muons[i]),cands,muons[i]);
850 
851  }
852 
853 
854 
855  //OK Now do the hard job ->remove the candidates that were cleaned
857 
858 
859 
860 
861 }
bool cleanMismeasured(reco::PFCandidate &, unsigned int)
Definition: PFMuonAlgo.cc:971
double sumet_
Definition: PFMuonAlgo.h:157
void removeDeadCandidates(reco::PFCandidateCollection *, const std::vector< unsigned int > &)
Definition: PFMuonAlgo.cc:1173
std::unique_ptr< reco::PFCandidateCollection > pfPunchThroughMuonCleanedCandidates_
the collection of punch-through cleaned muon candidates
Definition: PFMuonAlgo.h:117
const bool postCleaning_
Definition: PFMuonAlgo.h:139
double px() const final
x coordinate of momentum vector
std::unique_ptr< reco::PFCandidateCollection > pfFakeMuonCleanedCandidates_
the collection of fake cleaned muon candidates
Definition: PFMuonAlgo.h:115
bool cleanPunchThroughAndFakes(reco::PFCandidate &, reco::PFCandidateCollection *, unsigned int)
Definition: PFMuonAlgo.cc:1080
double pt() const final
transverse momentum
std::unique_ptr< reco::PFCandidateCollection > pfCleanedTrackerAndGlobalMuonCandidates_
the collection of tracker/global cleaned muon candidates
Definition: PFMuonAlgo.h:113
const double cosmicRejDistance_
Definition: PFMuonAlgo.h:154
void estimateEventQuantities(const reco::PFCandidateCollection *)
Definition: PFMuonAlgo.cc:740
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:459
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
std::vector< unsigned int > maskedIndices_
Definition: PFMuonAlgo.h:123
double METX_
Definition: PFMuonAlgo.h:158
double py() const final
y coordinate of momentum vector
const double eventFactorCosmics_
Definition: PFMuonAlgo.h:141
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
fixed size matrix
double sumetPU_
Definition: PFMuonAlgo.h:156
const reco::VertexCollection * vertices_
Definition: PFMuonAlgo.h:127
virtual ParticleType particleId() const
Definition: PFCandidate.h:374
std::unique_ptr< reco::PFCandidateCollection > pfCosmicsMuonCleanedCandidates_
the collection of cosmics cleaned muon candidates
Definition: PFMuonAlgo.h:111
std::unique_ptr< reco::PFCandidateCollection > pfPunchThroughHadronCleanedCandidates_
the collection of punch-through cleaned neutral hadron candidates
Definition: PFMuonAlgo.h:119
double METY_
Definition: PFMuonAlgo.h:159
void PFMuonAlgo::printMuonProperties ( const reco::MuonRef muonRef)
static

Definition at line 422 of file PFMuonAlgo.cc.

References gather_cfg::cout, delta, reco::TrackBase::hitPattern(), muon::isGoodMuon(), edm::Ref< C, T, F >::isNonnull(), SiStripPI::max, min(), reco::HitPattern::numberOfValidTrackerHits(), particleFlowDisplacedVertex_cfi::ratio, mathSSE::sqrt(), conversionPostprocessing_cfi::standAlone, muon::TM2DCompatibilityLoose, muon::TM2DCompatibilityTight, muon::TMLastStationAngLoose, muon::TMLastStationAngTight, muon::TMLastStationLoose, muon::TMLastStationOptimizedBarrelLowPtLoose, muon::TMLastStationOptimizedBarrelLowPtTight, muon::TMLastStationOptimizedLowPtLoose, muon::TMLastStationOptimizedLowPtTight, muon::TMLastStationTight, muon::TMOneStationLoose, muon::TMOneStationTight, HiIsolationCommonParameters_cff::track, and trackingTruthProducer_cfi::tracker.

422  {
423 
424  if ( !muonRef.isNonnull() ) return;
425 
426  bool isGL = muonRef->isGlobalMuon();
427  bool isTR = muonRef->isTrackerMuon();
428  bool isST = muonRef->isStandAloneMuon();
429 
430  std::cout<<" GL: "<<isGL<<" TR: "<<isTR<<" ST: "<<isST<<std::endl;
431  std::cout<<" nMatches "<<muonRef->numberOfMatches()<<std::endl;
432 
433  if ( muonRef->isGlobalMuon() ){
434  reco::TrackRef combinedMu = muonRef->combinedMuon();
435  std::cout<<" GL, pt: " << combinedMu->pt()
436  << " +/- " << combinedMu->ptError()/combinedMu->pt()
437  << " chi**2 GBL : " << combinedMu->normalizedChi2()<<std::endl;
438  std::cout<< " Total Muon Hits : " << combinedMu->hitPattern().numberOfValidMuonHits()
439  << "/" << combinedMu->hitPattern().numberOfLostMuonHits()
440  << " DT Hits : " << combinedMu->hitPattern().numberOfValidMuonDTHits()
441  << "/" << combinedMu->hitPattern().numberOfLostMuonDTHits()
442  << " CSC Hits : " << combinedMu->hitPattern().numberOfValidMuonCSCHits()
443  << "/" << combinedMu->hitPattern().numberOfLostMuonCSCHits()
444  << " RPC Hits : " << combinedMu->hitPattern().numberOfValidMuonRPCHits()
445  << "/" << combinedMu->hitPattern().numberOfLostMuonRPCHits()<<std::endl;
446 
447  std::cout<<" # of Valid Tracker Hits "<<combinedMu->hitPattern().numberOfValidTrackerHits()<<std::endl;
448  std::cout<<" # of Valid Pixel Hits "<<combinedMu->hitPattern().numberOfValidPixelHits()<<std::endl;
449  }
450  if ( muonRef->isStandAloneMuon() ){
451  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
452  std::cout<<" ST, pt: " << standAloneMu->pt()
453  << " +/- " << standAloneMu->ptError()/standAloneMu->pt()
454  << " eta : " << standAloneMu->eta()
455  << " DT Hits : " << standAloneMu->hitPattern().numberOfValidMuonDTHits()
456  << "/" << standAloneMu->hitPattern().numberOfLostMuonDTHits()
457  << " CSC Hits : " << standAloneMu->hitPattern().numberOfValidMuonCSCHits()
458  << "/" << standAloneMu->hitPattern().numberOfLostMuonCSCHits()
459  << " RPC Hits : " << standAloneMu->hitPattern().numberOfValidMuonRPCHits()
460  << "/" << standAloneMu->hitPattern().numberOfLostMuonRPCHits()
461  << " chi**2 STA : " << standAloneMu->normalizedChi2()<<std::endl;
462  }
463 
464 
465  if ( muonRef->isTrackerMuon() ){
466  reco::TrackRef trackerMu = muonRef->track();
467  const reco::Track& track = *trackerMu;
468  std::cout<<" TR, pt: " << trackerMu->pt()
469  << " +/- " << trackerMu->ptError()/trackerMu->pt()
470  << " chi**2 TR : " << trackerMu->normalizedChi2()<<std::endl;
471  std::cout<<" nTrackerHits "<<track.hitPattern().numberOfValidTrackerHits()<<std::endl;
472  std::cout<< "TMLastStationAngLoose "
473  << muon::isGoodMuon(*muonRef,muon::TMLastStationAngLoose) << std::endl
474  << "TMLastStationAngTight "
475  << muon::isGoodMuon(*muonRef,muon::TMLastStationAngTight) << std::endl
476  << "TMLastStationLoose "
477  << muon::isGoodMuon(*muonRef,muon::TMLastStationLoose) << std::endl
478  << "TMLastStationTight "
479  << muon::isGoodMuon(*muonRef,muon::TMLastStationTight) << std::endl
480  << "TMOneStationLoose "
481  << muon::isGoodMuon(*muonRef,muon::TMOneStationLoose) << std::endl
482  << "TMOneStationTight "
483  << muon::isGoodMuon(*muonRef,muon::TMOneStationTight) << std::endl
484  << "TMLastStationOptimizedLowPtLoose "
486  << "TMLastStationOptimizedLowPtTight "
488  << "TMLastStationOptimizedBarrelLowPtLoose "
490  << "TMLastStationOptimizedBarrelLowPtTight "
492  << std::endl;
493 
494  }
495 
496  std::cout<< "TM2DCompatibilityLoose "
497  << muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityLoose) << std::endl
498  << "TM2DCompatibilityTight "
499  << muon::isGoodMuon(*muonRef,muon::TM2DCompatibilityTight) << std::endl;
500 
501 
502 
503  if ( muonRef->isGlobalMuon() && muonRef->isTrackerMuon() && muonRef->isStandAloneMuon() ){
504  reco::TrackRef combinedMu = muonRef->combinedMuon();
505  reco::TrackRef trackerMu = muonRef->track();
506  reco::TrackRef standAloneMu = muonRef->standAloneMuon();
507 
508  double sigmaCombined = combinedMu->ptError()/(combinedMu->pt()*combinedMu->pt());
509  double sigmaTracker = trackerMu->ptError()/(trackerMu->pt()*trackerMu->pt());
510  double sigmaStandAlone = standAloneMu->ptError()/(standAloneMu->pt()*standAloneMu->pt());
511 
512  bool combined = combinedMu->ptError()/combinedMu->pt() < 0.20;
513  bool tracker = trackerMu->ptError()/trackerMu->pt() < 0.20;
514  bool standAlone = standAloneMu->ptError()/standAloneMu->pt() < 0.20;
515 
516  double delta1 = combined && tracker ?
517  fabs(1./combinedMu->pt() -1./trackerMu->pt())
518  /sqrt(sigmaCombined*sigmaCombined + sigmaTracker*sigmaTracker) : 100.;
519  double delta2 = combined && standAlone ?
520  fabs(1./combinedMu->pt() -1./standAloneMu->pt())
521  /sqrt(sigmaCombined*sigmaCombined + sigmaStandAlone*sigmaStandAlone) : 100.;
522  double delta3 = standAlone && tracker ?
523  fabs(1./standAloneMu->pt() -1./trackerMu->pt())
524  /sqrt(sigmaStandAlone*sigmaStandAlone + sigmaTracker*sigmaTracker) : 100.;
525 
526  double delta =
527  standAloneMu->hitPattern().numberOfValidMuonDTHits()+
528  standAloneMu->hitPattern().numberOfValidMuonCSCHits() > 0 ?
529  std::min(delta3,std::min(delta1,delta2)) : std::max(delta3,std::max(delta1,delta2));
530 
531  std::cout << "delta = " << delta << " delta1 "<<delta1<<" delta2 "<<delta2<<" delta3 "<<delta3<<std::endl;
532 
533  double ratio =
534  combinedMu->ptError()/combinedMu->pt()
535  / (trackerMu->ptError()/trackerMu->pt());
536  //if ( ratio > 2. && delta < 3. ) std::cout << "ALARM ! " << ratio << ", " << delta << std::endl;
537  std::cout<<" ratio "<<ratio<<" combined mu pt "<<combinedMu->pt()<<std::endl;
538  //bool quality3 = ( combinedMu->pt() < 50. || ratio < 2. ) && delta < 3.;
539 
540 
541  }
542 
543  double sumPtR03 = muonRef->isolationR03().sumPt;
544  double emEtR03 = muonRef->isolationR03().emEt;
545  double hadEtR03 = muonRef->isolationR03().hadEt;
546  double relIsoR03 = (sumPtR03 + emEtR03 + hadEtR03)/muonRef->pt();
547  double sumPtR05 = muonRef->isolationR05().sumPt;
548  double emEtR05 = muonRef->isolationR05().emEt;
549  double hadEtR05 = muonRef->isolationR05().hadEt;
550  double relIsoR05 = (sumPtR05 + emEtR05 + hadEtR05)/muonRef->pt();
551  std::cout<<" 0.3 Radion Rel Iso: "<<relIsoR03<<" sumPt "<<sumPtR03<<" emEt "<<emEtR03<<" hadEt "<<hadEtR03<<std::endl;
552  std::cout<<" 0.5 Radion Rel Iso: "<<relIsoR05<<" sumPt "<<sumPtR05<<" emEt "<<emEtR05<<" hadEt "<<hadEtR05<<std::endl;
553  return;
554 
555 }
dbl * delta
Definition: mlp_gen.cc:36
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
T sqrt(T t)
Definition: SSEVec.h:18
T min(T a, T b)
Definition: MathUtil.h:58
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:479
int numberOfValidTrackerHits() const
Definition: HitPattern.h:901
bool PFMuonAlgo::reconstructMuon ( reco::PFCandidate candidate,
const reco::MuonRef muon,
bool  allowLoose = false 
)

Definition at line 627 of file PFMuonAlgo.cc.

References changeTrack(), errorCompScale_, getTrackWithSmallestError(), goodMuonTracks(), reco::Muon::InnerTrack, isLooseMuon(), jets_cff::isMu, isMuon(), edm::Ref< C, T, F >::isNonnull(), muonTracks(), reco::PFCandidate::setMuonRef(), muon::tevOptimized(), trackQuality_, and tkIsoDeposits_cff::trackType.

Referenced by PFAlgo::reconstructTrack().

627  {
628  using namespace std;
629  using namespace reco;
630 
631  if (!muon.isNonnull())
632  return false;
633 
634 
635 
636 
637  bool isMu=false;
638 
639  if(allowLoose)
640  isMu = isMuon(muon) || isLooseMuon(muon);
641  else
642  isMu = isMuon(muon);
643 
644  if( !isMu)
645  return false;
646 
647 
648 
649 
650 
651  //get the valid tracks(without standalone except we allow loose muons)
652  //MIKE: Here we need to be careful. If we have a muon inside a dense
653  //jet environment often the track is badly measured. In this case
654  //we should not apply Dpt/Pt<1
655 
656  std::vector<reco::Muon::MuonTrackTypePair> validTracks = goodMuonTracks(muon);
657  if (!allowLoose)
658  validTracks = goodMuonTracks(muon);
659  else
660  validTracks = muonTracks(muon);
661 
662  if( validTracks.empty())
663  return false;
664 
665 
666 
667 
668  //check what is the track used.Rerun TuneP
669  reco::Muon::MuonTrackTypePair bestTrackPair = muon::tevOptimized(*muon);
670 
671  TrackRef bestTrack = bestTrackPair.first;
672  MuonTrackType trackType = bestTrackPair.second;
673 
674 
675 
676  MuonTrackTypePair trackPairWithSmallestError = getTrackWithSmallestError(validTracks);
677  TrackRef trackWithSmallestError = trackPairWithSmallestError.first;
678 
679  if( trackType == reco::Muon::InnerTrack &&
680  (!bestTrack->quality(trackQuality_) ||
681  bestTrack->ptError()/bestTrack->pt()> errorCompScale_*trackWithSmallestError->ptError()/trackWithSmallestError->pt() )) {
682  bestTrack = trackWithSmallestError;
683  trackType = trackPairWithSmallestError.second;
684  }
685  else if (trackType != reco::Muon::InnerTrack &&
686  bestTrack->ptError()/bestTrack->pt()> errorCompScale_*trackWithSmallestError->ptError()/trackWithSmallestError->pt()) {
687  bestTrack = trackWithSmallestError;
688  trackType = trackPairWithSmallestError.second;
689 
690  }
691 
692 
693  changeTrack(candidate,std::make_pair(bestTrack,trackType));
694  candidate.setMuonRef( muon );
695 
696  return true;
697 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:66
reco::Muon::MuonTrackTypePair MuonTrackTypePair
Definition: PFMuonAlgo.h:14
MuonTrackTypePair getTrackWithSmallestError(const std::vector< MuonTrackTypePair > &)
Definition: PFMuonAlgo.cc:731
reco::Muon::MuonTrackTypePair tevOptimized(const reco::TrackRef &combinedTrack, const reco::TrackRef &trackerTrack, const reco::TrackRef &tpfmsTrack, const reco::TrackRef &pickyTrack, const reco::TrackRef &dytTrack, const double ptThreshold=200., const double tune1=17., const double tune2=40., const double dptcut=0.25)
Definition: MuonCocktails.cc:9
std::vector< reco::Muon::MuonTrackTypePair > goodMuonTracks(const reco::MuonRef &muon, bool includeSA=false)
Definition: PFMuonAlgo.cc:559
void changeTrack(reco::PFCandidate &, const MuonTrackTypePair &)
Definition: PFMuonAlgo.cc:702
static bool isLooseMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:78
fixed size matrix
void setMuonRef(const reco::MuonRef &ref)
set muon reference
Definition: PFCandidate.cc:445
MuonTrackType
Definition: MuonTrackType.h:28
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:40
std::vector< reco::Muon::MuonTrackTypePair > muonTracks(const reco::MuonRef &muon, bool includeSA=false, double dpt=1e+9)
Definition: PFMuonAlgo.cc:565
const double errorCompScale_
Definition: PFMuonAlgo.h:136
const reco::TrackBase::TrackQuality trackQuality_
Definition: PFMuonAlgo.h:135
void PFMuonAlgo::removeDeadCandidates ( reco::PFCandidateCollection obj,
const std::vector< unsigned int > &  indices 
)
private

Definition at line 1173 of file PFMuonAlgo.cc.

References mps_fire::i, and N.

Referenced by postClean(), and transferAddedMuonCandidates().

1174 {
1175  size_t N = indices.size();
1176  size_t collSize = obj->size();
1177 
1178  for (size_t i = 0 ; i < N ; ++i)
1179  obj->at(indices.at(i)) = obj->at(collSize-i-1);
1180 
1181  obj->resize(collSize - indices.size());
1182 }
#define N
Definition: blowfish.cc:9
void PFMuonAlgo::setInputsForCleaning ( reco::VertexCollection const &  vertices)

Definition at line 1078 of file PFMuonAlgo.cc.

References electrons_cff::vertices, and vertices_.

Referenced by PFAlgo::setPFVertexParameters().

1078 { vertices_ = &vertices; }
const reco::VertexCollection * vertices_
Definition: PFMuonAlgo.h:127
std::vector< reco::Muon::MuonTrackTypePair > PFMuonAlgo::tracksPointingAtMET ( const std::vector< MuonTrackTypePair > &  tracks)
private

Definition at line 1058 of file PFMuonAlgo.cc.

References mps_fire::i, metFactorCleaning_, METX_, METY_, and funct::pow().

Referenced by addMissingMuons(), and transferAddedMuonCandidates().

1058  {
1059  std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
1060 
1061 
1062  double newMET2=0.0;
1063 
1064  for( unsigned int i=0;i<tracks.size();++i) {
1065  //calculate new SUM ET and MET2
1066  newMET2 = pow(METX_+tracks.at(i).first->px(),2)+pow(METY_+tracks.at(i).first->py(),2);
1067 
1068  if(newMET2<(METX_*METX_+METY_*METY_)/metFactorCleaning_)
1069  outputTracks.push_back(tracks.at(i));
1070  }
1071 
1072 
1073  return outputTracks;
1074 }
const double metFactorCleaning_
Definition: PFMuonAlgo.h:144
double METX_
Definition: PFMuonAlgo.h:158
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double METY_
Definition: PFMuonAlgo.h:159
std::vector< reco::Muon::MuonTrackTypePair > PFMuonAlgo::tracksWithBetterMET ( const std::vector< MuonTrackTypePair > &  tracks,
const reco::PFCandidate pfc 
)
private

Definition at line 1030 of file PFMuonAlgo.cc.

References eventFractionCleaning_, mps_fire::i, metFactorCleaning_, metSigForCleaning_, METX_, METY_, funct::pow(), reco::LeafCandidate::pt(), reco::LeafCandidate::px(), reco::LeafCandidate::py(), mathSSE::sqrt(), sumet_, and sumetPU_.

Referenced by cleanMismeasured(), and transferAddedMuonCandidates().

1030  {
1031  std::vector<reco::Muon::MuonTrackTypePair> outputTracks;
1032 
1033  double METNOX = METX_ - pfc.px();
1034  double METNOY = METY_ - pfc.py();
1035  double SUMETNO = sumet_ -pfc.pt();
1036  double MET2 = METX_*METX_+METY_*METY_;
1037  double newMET2=0.0;
1038  double newSUMET=0.0;
1039  double METSIG = sqrt(MET2)/sqrt(sumet_-sumetPU_);
1040 
1041 
1042  if(METSIG>metSigForCleaning_)
1043  for( unsigned int i=0;i<tracks.size();++i) {
1044  //calculate new SUM ET and MET2
1045  newSUMET = SUMETNO+tracks.at(i).first->pt()-sumetPU_;
1046  newMET2 = pow(METNOX+tracks.at(i).first->px(),2)+pow(METNOY+tracks.at(i).first->py(),2);
1047 
1048  if(newSUMET/(sumet_-sumetPU_)>eventFractionCleaning_ && newMET2<MET2/metFactorCleaning_)
1049  outputTracks.push_back(tracks.at(i));
1050  }
1051 
1052 
1053  return outputTracks;
1054 }
double sumet_
Definition: PFMuonAlgo.h:157
double px() const final
x coordinate of momentum vector
double pt() const final
transverse momentum
const double metFactorCleaning_
Definition: PFMuonAlgo.h:144
T sqrt(T t)
Definition: SSEVec.h:18
const double eventFractionCleaning_
Definition: PFMuonAlgo.h:137
double METX_
Definition: PFMuonAlgo.h:158
double py() const final
y coordinate of momentum vector
double sumetPU_
Definition: PFMuonAlgo.h:156
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
const double metSigForCleaning_
Definition: PFMuonAlgo.h:142
double METY_
Definition: PFMuonAlgo.h:159
std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::transferAddedMuonCandidates ( )
inline
std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::transferCleanedCosmicCandidates ( )
inline

Definition at line 59 of file PFMuonAlgo.h.

References eostools::move(), and pfCosmicsMuonCleanedCandidates_.

Referenced by PFProducer::produce().

59  {
61  }
std::unique_ptr< reco::PFCandidateCollection > pfCosmicsMuonCleanedCandidates_
the collection of cosmics cleaned muon candidates
Definition: PFMuonAlgo.h:111
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::transferCleanedFakeCandidates ( )
inline

Definition at line 67 of file PFMuonAlgo.h.

References eostools::move(), and pfFakeMuonCleanedCandidates_.

Referenced by PFProducer::produce().

67  {
69  }
std::unique_ptr< reco::PFCandidateCollection > pfFakeMuonCleanedCandidates_
the collection of fake cleaned muon candidates
Definition: PFMuonAlgo.h:115
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::transferCleanedTrackerAndGlobalCandidates ( )
inline

Definition at line 63 of file PFMuonAlgo.h.

References eostools::move(), and pfCleanedTrackerAndGlobalMuonCandidates_.

Referenced by PFProducer::produce().

63  {
65  }
std::unique_ptr< reco::PFCandidateCollection > pfCleanedTrackerAndGlobalMuonCandidates_
the collection of tracker/global cleaned muon candidates
Definition: PFMuonAlgo.h:113
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::transferPunchThroughCleanedHadronCandidates ( )
inline

Definition at line 75 of file PFMuonAlgo.h.

References eostools::move(), and pfPunchThroughHadronCleanedCandidates_.

Referenced by PFProducer::produce().

75  {
77  }
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< reco::PFCandidateCollection > pfPunchThroughHadronCleanedCandidates_
the collection of punch-through cleaned neutral hadron candidates
Definition: PFMuonAlgo.h:119
std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::transferPunchThroughCleanedMuonCandidates ( )
inline

Definition at line 71 of file PFMuonAlgo.h.

References eostools::move(), and pfPunchThroughMuonCleanedCandidates_.

Referenced by PFProducer::produce().

71  {
73  }
std::unique_ptr< reco::PFCandidateCollection > pfPunchThroughMuonCleanedCandidates_
the collection of punch-through cleaned muon candidates
Definition: PFMuonAlgo.h:117
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

const double PFMuonAlgo::cosmicRejDistance_
private

Definition at line 154 of file PFMuonAlgo.h.

Referenced by addMissingMuons(), and postClean().

const double PFMuonAlgo::dzPV_
private

Definition at line 138 of file PFMuonAlgo.h.

const double PFMuonAlgo::errorCompScale_
private

Definition at line 136 of file PFMuonAlgo.h.

Referenced by reconstructMuon().

const double PFMuonAlgo::eventFactorCosmics_
private

Definition at line 141 of file PFMuonAlgo.h.

Referenced by postClean().

const double PFMuonAlgo::eventFractionCleaning_
private

Definition at line 137 of file PFMuonAlgo.h.

Referenced by tracksWithBetterMET().

const double PFMuonAlgo::eventFractionRejection_
private

Definition at line 145 of file PFMuonAlgo.h.

Referenced by cleanMismeasured().

std::vector<unsigned int > PFMuonAlgo::maskedIndices_
private

Definition at line 123 of file PFMuonAlgo.h.

Referenced by cleanMismeasured(), cleanPunchThroughAndFakes(), and postClean().

const double PFMuonAlgo::maxDPtOPt_
private

Definition at line 132 of file PFMuonAlgo.h.

Referenced by goodMuonTracks().

const double PFMuonAlgo::metFactorCleaning_
private

Definition at line 144 of file PFMuonAlgo.h.

Referenced by tracksPointingAtMET(), and tracksWithBetterMET().

const double PFMuonAlgo::metFactorFake_
private

Definition at line 149 of file PFMuonAlgo.h.

Referenced by cleanPunchThroughAndFakes().

const double PFMuonAlgo::metFactorHighEta_
private

Definition at line 147 of file PFMuonAlgo.h.

Referenced by cleanPunchThroughAndFakes().

const double PFMuonAlgo::metFactorRejection_
private

Definition at line 146 of file PFMuonAlgo.h.

Referenced by cleanMismeasured().

const double PFMuonAlgo::metSigForCleaning_
private

Definition at line 142 of file PFMuonAlgo.h.

Referenced by tracksWithBetterMET().

const double PFMuonAlgo::metSigForRejection_
private

Definition at line 143 of file PFMuonAlgo.h.

Referenced by cleanMismeasured().

double PFMuonAlgo::METX_
private
double PFMuonAlgo::METY_
private
const int PFMuonAlgo::minPixelHits_
private

Definition at line 134 of file PFMuonAlgo.h.

const double PFMuonAlgo::minPostCleaningPt_
private

Definition at line 140 of file PFMuonAlgo.h.

Referenced by cleanMismeasured(), and cleanPunchThroughAndFakes().

const double PFMuonAlgo::minPunchThroughEnergy_
private

Definition at line 151 of file PFMuonAlgo.h.

Referenced by cleanPunchThroughAndFakes().

const double PFMuonAlgo::minPunchThroughMomentum_
private

Definition at line 150 of file PFMuonAlgo.h.

Referenced by cleanPunchThroughAndFakes().

const int PFMuonAlgo::minTrackerHits_
private

Definition at line 133 of file PFMuonAlgo.h.

std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::pfAddedMuonCandidates_
private

the collection of added muon candidates

Definition at line 121 of file PFMuonAlgo.h.

Referenced by addMissingMuons(), and transferAddedMuonCandidates().

std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::pfCleanedTrackerAndGlobalMuonCandidates_
private

the collection of tracker/global cleaned muon candidates

Definition at line 113 of file PFMuonAlgo.h.

Referenced by cleanMismeasured(), postClean(), and transferCleanedTrackerAndGlobalCandidates().

std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::pfCosmicsMuonCleanedCandidates_
private

the collection of cosmics cleaned muon candidates

Definition at line 111 of file PFMuonAlgo.h.

Referenced by postClean(), and transferCleanedCosmicCandidates().

std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::pfFakeMuonCleanedCandidates_
private

the collection of fake cleaned muon candidates

Definition at line 115 of file PFMuonAlgo.h.

Referenced by cleanMismeasured(), cleanPunchThroughAndFakes(), postClean(), and transferCleanedFakeCandidates().

std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::pfPunchThroughHadronCleanedCandidates_
private

the collection of punch-through cleaned neutral hadron candidates

Definition at line 119 of file PFMuonAlgo.h.

Referenced by cleanPunchThroughAndFakes(), postClean(), and transferPunchThroughCleanedHadronCandidates().

std::unique_ptr<reco::PFCandidateCollection> PFMuonAlgo::pfPunchThroughMuonCleanedCandidates_
private

the collection of punch-through cleaned muon candidates

Definition at line 117 of file PFMuonAlgo.h.

Referenced by cleanPunchThroughAndFakes(), postClean(), and transferPunchThroughCleanedMuonCandidates().

const bool PFMuonAlgo::postCleaning_
private

Definition at line 139 of file PFMuonAlgo.h.

Referenced by addMissingMuons(), and postClean().

const double PFMuonAlgo::ptFactorHighEta_
private

Definition at line 148 of file PFMuonAlgo.h.

Referenced by cleanPunchThroughAndFakes().

const double PFMuonAlgo::punchThroughFactor_
private

Definition at line 152 of file PFMuonAlgo.h.

Referenced by cleanPunchThroughAndFakes().

const double PFMuonAlgo::punchThroughMETFactor_
private

Definition at line 153 of file PFMuonAlgo.h.

Referenced by cleanPunchThroughAndFakes().

double PFMuonAlgo::sumet_
private
double PFMuonAlgo::sumetPU_
private
const reco::TrackBase::TrackQuality PFMuonAlgo::trackQuality_
private

Definition at line 135 of file PFMuonAlgo.h.

Referenced by reconstructMuon().

const reco::VertexCollection* PFMuonAlgo::vertices_
private

Definition at line 127 of file PFMuonAlgo.h.

Referenced by addMissingMuons(), postClean(), and setInputsForCleaning().