CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
MuonPFCandidateCleaner Class Reference
Inheritance diagram for MuonPFCandidateCleaner:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 MuonPFCandidateCleaner (const edm::ParameterSet &)
 
 ~MuonPFCandidateCleaner ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void produce (edm::Event &, const edm::EventSetup &)
 

Private Attributes

double dRmatch_
 
int maxWarnings_tooFew_
 
int maxWarnings_tooMany_
 
int numWarnings_tooFew_
 
int numWarnings_tooMany_
 
bool removeDuplicates_
 
edm::InputTag srcPFCandidates_
 
edm::InputTag srcSelectedMuons_
 
int verbosity_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Produce collection of PFCandidates in Z –> mu+ mu- event from which the two muons are removed (later to be replaced by simulated tau decay products)

Authors
Tomasz Maciej Frueboes; Christian Veelken, LLR
Version
Revision:
1.1
Id:
MuonPFCandidateCleaner.cc,v 1.1 2013/02/05 19:59:05 veelken Exp

Definition at line 33 of file MuonPFCandidateCleaner.cc.

Constructor & Destructor Documentation

MuonPFCandidateCleaner::MuonPFCandidateCleaner ( const edm::ParameterSet cfg)
explicit

Definition at line 56 of file MuonPFCandidateCleaner.cc.

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), and verbosity_.

57  : srcSelectedMuons_(cfg.getParameter<edm::InputTag>("selectedMuons")),
59  dRmatch_(cfg.getParameter<double>("dRmatch")),
60  removeDuplicates_(cfg.getParameter<bool>("removeDuplicates")),
65 {
66  verbosity_ = ( cfg.exists("verbosity") ) ?
67  cfg.getParameter<int>("verbosity") : 0;
68 
69  produces<reco::PFCandidateCollection>();
70 }
T getParameter(std::string const &) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
MuonPFCandidateCleaner::~MuonPFCandidateCleaner ( )
inline

Definition at line 37 of file MuonPFCandidateCleaner.cc.

37 {}

Member Function Documentation

void MuonPFCandidateCleaner::produce ( edm::Event evt,
const edm::EventSetup es 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 118 of file MuonPFCandidateCleaner.cc.

References gather_cfg::cout, reco::deltaR(), PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi::dR, dRmatch_, reco::Candidate::eta(), edm::Event::getByLabel(), getSelMuons(), getTheMuMinus(), getTheMuPlus(), customizeTrackingMonitorSeedNumber::idx, reco::isMuon(), edm::RefToBase< T >::isNonnull(), maxWarnings_tooFew_, maxWarnings_tooMany_, numWarnings_tooFew_, numWarnings_tooMany_, reco::Candidate::p4(), reco::tau::pfCandidates(), reco::Candidate::phi(), reco::Candidate::pt(), edm::Event::put(), removeDuplicates_, python.multivaluedict::sort(), srcPFCandidates_, srcSelectedMuons_, and verbosity_.

119 {
120  if ( verbosity_ ) std::cout << "<MuonPFCandidateCleaner::produce>:" << std::endl;
121 
122  std::vector<reco::CandidateBaseRef> selMuons = getSelMuons(evt, srcSelectedMuons_);
123  const reco::CandidateBaseRef muPlus = getTheMuPlus(selMuons);
124  const reco::CandidateBaseRef muMinus = getTheMuMinus(selMuons);
125 
126  std::vector<reco::Particle::LorentzVector> selMuonP4s;
127  if ( muPlus.isNonnull() ) {
128  if ( verbosity_ ) std::cout << " muPlus: Pt = " << muPlus->pt() << ", eta = " << muPlus->eta() << ", phi = " << muPlus->phi() << std::endl;
129  selMuonP4s.push_back(muPlus->p4());
130  }
131  if ( muMinus.isNonnull() ) {
132  if ( verbosity_ ) std::cout << " muMinus: Pt = " << muMinus->pt() << ", eta = " << muMinus->eta() << ", phi = " << muMinus->phi() << std::endl;
133  selMuonP4s.push_back(muMinus->p4());
134  }
135 
136 //--- produce collection of PFCandidate excluding muons
138  evt.getByLabel(srcPFCandidates_, pfCandidates);
139 
140  std::auto_ptr<reco::PFCandidateCollection> pfCandidates_woMuons(new reco::PFCandidateCollection());
141 
142 //--- iterate over list of reconstructed PFCandidates,
143 // add PFCandidate to output collection in case it does not correspond to any selected muon
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 ) {
150  double dR = reco::deltaR(pfCandidate->p4(), *selMuonP4);
151  if ( dR < dRmatch_ ) tmpMatches.push_back(muonToPFCandMatchInfoType(*selMuonP4, &(*pfCandidate), dR));
152  }
153  // rank muon-to-pfCandidate matches by quality
154  std::sort(tmpMatches.begin(), tmpMatches.end(), SortMuonToPFCandMatchInfosDescendingMatchQuality());
155  if ( tmpMatches.size() > 0 ) selMuonToPFCandMatches.push_back(tmpMatches.front());
156  if ( removeDuplicates_ ) {
157  // CV: remove all high Pt charged PFCandidates very close to muon direction
158  // (duplicate tracks arise in case muon track in SiStrip + Pixel detector is reconstructed as 2 disjoint segments)
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);
162  }
163  }
164  }
165 
166  std::vector<const reco::PFCandidate*> removedPFCandidates;
167  for ( reco::PFCandidateCollection::const_iterator pfCandidate = pfCandidates->begin();
168  pfCandidate != pfCandidates->end(); ++pfCandidate ) {
169  bool isMuon = false;
170  for ( std::vector<muonToPFCandMatchInfoType>::const_iterator muonMatchInfo = selMuonToPFCandMatches.begin();
171  muonMatchInfo != selMuonToPFCandMatches.end(); ++muonMatchInfo ) {
172  if ( muonMatchInfo->pfCandidate_ == &(*pfCandidate) ) isMuon = true;
173  }
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;
176  }
177  if ( isMuon ) removedPFCandidates.push_back(&(*pfCandidate)); // pfCandidate belongs to a selected muon, do not copy
178  else pfCandidates_woMuons->push_back(*pfCandidate);
179  }
180  if ( (removedPFCandidates.size() > selMuons.size() && numWarnings_tooMany_ < maxWarnings_tooMany_) &&
181  (removedPFCandidates.size() < selMuons.size() && numWarnings_tooFew_ < maxWarnings_tooFew_ ) ) {
182  edm::LogWarning("MuonPFCandidateCleaner")
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;
187  int idx = 0;
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;
192  ++idx;
193  }
194  if ( removedPFCandidates.size() > selMuons.size() ) ++numWarnings_tooMany_;
195  if ( removedPFCandidates.size() < selMuons.size() ) ++numWarnings_tooFew_;
196  }
197 
198  evt.put(pfCandidates_woMuons);
199 }
reco::CandidateBaseRef getTheMuMinus(const std::vector< reco::CandidateBaseRef > &)
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:11
virtual float eta() const =0
momentum pseudorapidity
virtual float phi() const =0
momentum azimuthal angle
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.
Definition: Event.h:116
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
tuple cout
Definition: gather_cfg.py:121
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.
Definition: RefToBase.h:279
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector

Member Data Documentation

double MuonPFCandidateCleaner::dRmatch_
private

Definition at line 45 of file MuonPFCandidateCleaner.cc.

Referenced by produce().

int MuonPFCandidateCleaner::maxWarnings_tooFew_
private

Definition at line 50 of file MuonPFCandidateCleaner.cc.

Referenced by produce().

int MuonPFCandidateCleaner::maxWarnings_tooMany_
private

Definition at line 48 of file MuonPFCandidateCleaner.cc.

Referenced by produce().

int MuonPFCandidateCleaner::numWarnings_tooFew_
private

Definition at line 51 of file MuonPFCandidateCleaner.cc.

Referenced by produce().

int MuonPFCandidateCleaner::numWarnings_tooMany_
private

Definition at line 49 of file MuonPFCandidateCleaner.cc.

Referenced by produce().

bool MuonPFCandidateCleaner::removeDuplicates_
private

Definition at line 46 of file MuonPFCandidateCleaner.cc.

Referenced by produce().

edm::InputTag MuonPFCandidateCleaner::srcPFCandidates_
private

Definition at line 43 of file MuonPFCandidateCleaner.cc.

Referenced by produce().

edm::InputTag MuonPFCandidateCleaner::srcSelectedMuons_
private

Definition at line 42 of file MuonPFCandidateCleaner.cc.

Referenced by produce().

int MuonPFCandidateCleaner::verbosity_
private

Definition at line 53 of file MuonPFCandidateCleaner.cc.

Referenced by MuonPFCandidateCleaner(), and produce().