57 : srcSelectedMuons_(cfg.getParameter<edm::InputTag>(
"selectedMuons")),
58 srcPFCandidates_(cfg.getParameter<edm::InputTag>(
"pfCands")),
59 dRmatch_(cfg.getParameter<double>(
"dRmatch")),
60 removeDuplicates_(cfg.getParameter<bool>(
"removeDuplicates")),
61 maxWarnings_tooMany_(100),
62 numWarnings_tooMany_(0),
63 maxWarnings_tooFew_(3),
64 numWarnings_tooFew_(0)
69 produces<reco::PFCandidateCollection>();
74 struct muonToPFCandMatchInfoType
77 : muonPt_(muonP4.
pt()),
78 pfCandidatePt_(pfCandidate->
pt()),
79 pfCandidateCharge_(pfCandidate->
charge()),
83 ~muonToPFCandMatchInfoType() {}
85 double pfCandidatePt_;
86 int pfCandidateCharge_;
91 struct SortMuonToPFCandMatchInfosDescendingMatchQuality
93 bool operator() (
const muonToPFCandMatchInfoType& m1,
const muonToPFCandMatchInfoType& m2)
96 if ( m1.pfCandidatePt_ > (0.5*m1.muonPt_) && m2.pfCandidatePt_ < (0.5*m2.muonPt_) )
return true;
97 if ( m1.pfCandidatePt_ < (0.5*m1.muonPt_) && m2.pfCandidatePt_ > (0.5*m2.muonPt_) )
return false;
99 if ( m1.pfCandidateCharge_ != 0 && m2.pfCandidateCharge_ == 0 )
return true;
100 if ( m1.pfCandidateCharge_ == 0 && m2.pfCandidateCharge_ != 0 )
return false;
103 return (m1.dR_ < m2.dR_);
112 std::ostringstream retVal;
113 retVal <<
"Run = " << run_number <<
", LS = " << ls_number <<
", Event = " << event_number;
126 std::vector<reco::Particle::LorentzVector> selMuonP4s;
128 if (
verbosity_ )
std::cout <<
" muPlus: Pt = " << muPlus->
pt() <<
", eta = " << muPlus->
eta() <<
", phi = " << muPlus->
phi() << std::endl;
129 selMuonP4s.push_back(muPlus->
p4());
132 if (
verbosity_ )
std::cout <<
" muMinus: Pt = " << muMinus->
pt() <<
", eta = " << muMinus->
eta() <<
", phi = " << muMinus->
phi() << std::endl;
133 selMuonP4s.push_back(muMinus->
p4());
144 std::vector<muonToPFCandMatchInfoType> selMuonToPFCandMatches;
145 for ( std::vector<reco::Particle::LorentzVector>::const_iterator selMuonP4 = selMuonP4s.begin();
146 selMuonP4 != selMuonP4s.end(); ++selMuonP4 ) {
147 std::vector<muonToPFCandMatchInfoType> tmpMatches;
148 for ( reco::PFCandidateCollection::const_iterator pfCandidate = pfCandidates->begin();
149 pfCandidate != pfCandidates->end(); ++pfCandidate ) {
151 if ( dR <
dRmatch_ ) tmpMatches.push_back(muonToPFCandMatchInfoType(*selMuonP4, &(*pfCandidate), dR));
154 std::sort(tmpMatches.begin(), tmpMatches.end(), SortMuonToPFCandMatchInfosDescendingMatchQuality());
155 if ( tmpMatches.size() > 0 ) selMuonToPFCandMatches.push_back(tmpMatches.front());
159 for ( std::vector<muonToPFCandMatchInfoType>::const_iterator tmpMatch = tmpMatches.begin();
160 tmpMatch != tmpMatches.end(); ++tmpMatch ) {
161 if ( tmpMatch->dR_ < 1.e-3 && fabs(tmpMatch->pfCandidateCharge_) > 0.5 && tmpMatch->pfCandidatePt_ > (0.33*tmpMatch->muonPt_) ) selMuonToPFCandMatches.push_back(*tmpMatch);
166 std::vector<const reco::PFCandidate*> removedPFCandidates;
167 for ( reco::PFCandidateCollection::const_iterator pfCandidate = pfCandidates->begin();
168 pfCandidate != pfCandidates->end(); ++pfCandidate ) {
170 for ( std::vector<muonToPFCandMatchInfoType>::const_iterator muonMatchInfo = selMuonToPFCandMatches.begin();
171 muonMatchInfo != selMuonToPFCandMatches.end(); ++muonMatchInfo ) {
172 if ( muonMatchInfo->pfCandidate_ == &(*pfCandidate) ) isMuon =
true;
174 if (
verbosity_ && pfCandidate->pt() > 10. && fabs(pfCandidate->charge()) > 0.5 ) {
175 std::cout <<
"pfCandidate: Pt = " << pfCandidate->pt() <<
", eta = " << pfCandidate->eta() <<
", phi = " << pfCandidate->phi() <<
", isMuon = " << isMuon << std::endl;
177 if ( isMuon ) removedPFCandidates.push_back(&(*pfCandidate));
178 else pfCandidates_woMuons->push_back(*pfCandidate);
183 <<
" (" << runLumiEventNumbers_to_string(evt) <<
")" << std::endl
184 <<
" Removed " << removedPFCandidates.size() <<
" PF-candidates from event containing " << selMuons.size() <<
" muons !!" << std::endl;
185 if ( muPlus.
isNonnull() )
std::cout <<
" muPlus: Pt = " << muPlus->
pt() <<
", eta = " << muPlus->
eta() <<
", phi = " << muPlus->
phi() << std::endl;
186 if ( muMinus.
isNonnull() )
std::cout <<
" muMinus: Pt = " << muMinus->
pt() <<
", eta = " << muMinus->
eta() <<
", phi = " << muMinus->
phi() << std::endl;
188 for ( std::vector<const reco::PFCandidate*>::const_iterator removedPFCandidate = removedPFCandidates.begin();
189 removedPFCandidate != removedPFCandidates.end(); ++removedPFCandidate ) {
190 std::cout <<
"PF-candidate #" << idx <<
" (charge = " << (*removedPFCandidate)->charge() <<
"):"
191 <<
" Pt = " << (*removedPFCandidate)->pt() <<
", eta = " << (*removedPFCandidate)->eta() <<
", phi = " << (*removedPFCandidate)->phi() << std::endl;
198 evt.
put(pfCandidates_woMuons);
T getParameter(std::string const &) const
EventNumber_t event() const
reco::CandidateBaseRef getTheMuMinus(const std::vector< reco::CandidateBaseRef > &)
bool isMuon(const Candidate &part)
unsigned int EventNumber_t
virtual float eta() const =0
momentum pseudorapidity
#define DEFINE_FWK_MODULE(type)
reco::PFCandidatePtr pfCandidate_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
edm::LuminosityBlockNumber_t luminosityBlock() const
virtual float phi() const =0
momentum azimuthal angle
double deltaR(const T1 &t1, const T2 &t2)
unsigned int LuminosityBlockNumber_t
~MuonPFCandidateCleaner()
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
virtual float pt() const =0
transverse momentum
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
virtual void produce(edm::Event &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
edm::InputTag srcSelectedMuons_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
edm::InputTag srcPFCandidates_
Particle reconstructed by the particle flow algorithm.
std::vector< reco::CandidateBaseRef > getSelMuons(const edm::Event &, const edm::InputTag &)
reco::CandidateBaseRef getTheMuPlus(const std::vector< reco::CandidateBaseRef > &)
bool isNonnull() const
Checks for non-null.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
MuonPFCandidateCleaner(const edm::ParameterSet &)
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector