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 Types | Private Attributes
modules::MuonCleanerBySegmentsT< T > Class Template Reference

Removes duplicates from a muon collection using segment references. More...

Inheritance diagram for modules::MuonCleanerBySegmentsT< T >:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

bool isBetterMuon (const T &mu1, const T &mu2) const
 
bool isSameMuon (const T &mu1, const T &mu2) const
 
template<>
bool isSameMuon (const pat::Muon &mu1, const pat::Muon &mu2) const
 
template<>
bool isSameMuon (const pat::Muon &mu1, const pat::Muon &mu2) const
 
 MuonCleanerBySegmentsT (const edm::ParameterSet &iConfig)
 
virtual void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
virtual ~MuonCleanerBySegmentsT ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 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
std::vector< ConsumesInfoconsumesInfo () const
 
 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
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Types

typedef std::pair< const
reco::Muon *, const reco::Muon * > 
MuonPointerPair
 Cut on the pair of objects together. More...
 

Private Attributes

StringCutObjectSelector
< MuonPointerPair, true > 
bestMuonSelector_
 
bool defaultBestMuon_
 Use default criteria to choose the best muon. More...
 
StringCutObjectSelector< Tpassthrough_
 Always-accept cut. More...
 
StringCutObjectSelector< Tpreselection_
 Preselection cut. More...
 
double sharedFraction_
 Fraction of shared segments. More...
 
edm::EDGetTokenT< edm::View< T > > srcToken_
 Tokens for input collections. More...
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- 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::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

template<typename T>
class modules::MuonCleanerBySegmentsT< T >

Removes duplicates from a muon collection using segment references.

      This module removes duplicates from a muon collection using segment references.

      All muons that don't pass the preselection are discarded first

      Then, for each pair of muons that share at least a given fraction of segments,
      the worse one is flagged as ghost.

      Finally, all muons that are not flagged as ghosts, or which pass a 'passthrough' selection,
      are saved in the output.
Author
Giovanni Petrucciani
Version
Id:
MuonCleanerBySegments.cc,v 1.1 2012/08/11 13:00:50 gpetrucc Exp

Definition at line 40 of file MuonCleanerBySegments.cc.

Member Typedef Documentation

template<typename T >
typedef std::pair<const reco::Muon *, const reco::Muon *> modules::MuonCleanerBySegmentsT< T >::MuonPointerPair
private

Cut on the pair of objects together.

Definition at line 69 of file MuonCleanerBySegments.cc.

Constructor & Destructor Documentation

template<typename T >
modules::MuonCleanerBySegmentsT< T >::MuonCleanerBySegmentsT ( const edm::ParameterSet iConfig)
explicit

Definition at line 79 of file MuonCleanerBySegments.cc.

79  :
81  preselection_(iConfig.existsAs<std::string>("preselection") ? iConfig.getParameter<std::string>("preselection") : ""),
82  passthrough_(iConfig.existsAs<std::string>("passthrough") ? iConfig.getParameter<std::string>("passthrough") : "0"),
83  sharedFraction_(iConfig.getParameter<double>("fractionOfSharedSegments")),
84  defaultBestMuon_(!iConfig.existsAs<std::string>("customArbitration")),
85  bestMuonSelector_(defaultBestMuon_ ? std::string("") : iConfig.getParameter<std::string>("customArbitration"))
86 {
87  // this is the basic output (edm::Association is not generic)
88  produces<std::vector<T> >();
89 }
T getParameter(std::string const &) const
double sharedFraction_
Fraction of shared segments.
StringCutObjectSelector< T > preselection_
Preselection cut.
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
StringCutObjectSelector< T > passthrough_
Always-accept cut.
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< edm::View< T > > srcToken_
Tokens for input collections.
StringCutObjectSelector< MuonPointerPair, true > bestMuonSelector_
bool defaultBestMuon_
Use default criteria to choose the best muon.
template<typename T >
virtual modules::MuonCleanerBySegmentsT< T >::~MuonCleanerBySegmentsT ( )
inlinevirtual

Definition at line 43 of file MuonCleanerBySegments.cc.

43 { }

Member Function Documentation

template<typename T >
bool modules::MuonCleanerBySegmentsT< T >::isBetterMuon ( const T mu1,
const T mu2 
) const

Definition at line 134 of file MuonCleanerBySegments.cc.

References reco::deltaR2(), and reco::Muon::SegmentArbitration.

134  {
135  if (!defaultBestMuon_) {
136  MuonPointerPair pair = { &mu1, &mu2 };
137  return bestMuonSelector_(pair);
138  }
139  if (mu2.track().isNull()) return true;
140  if (mu1.track().isNull()) return false;
141  if (mu1.isPFMuon() != mu2.isPFMuon()) return mu1.isPFMuon();
142  if (mu1.isGlobalMuon() != mu2.isGlobalMuon()) return mu1.isGlobalMuon();
143  if (mu1.charge() == mu2.charge() && deltaR2(mu1,mu2) < 0.0009) {
144  return mu1.track()->ptError()/mu1.track()->pt() < mu2.track()->ptError()/mu2.track()->pt();
145  } else {
146  int nm1 = mu1.numberOfMatches(reco::Muon::SegmentArbitration);
147  int nm2 = mu2.numberOfMatches(reco::Muon::SegmentArbitration);
148  return (nm1 != nm2 ? nm1 > nm2 : mu1.pt() > mu2.pt());
149  }
150 }
std::pair< const reco::Muon *, const reco::Muon * > MuonPointerPair
Cut on the pair of objects together.
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
StringCutObjectSelector< MuonPointerPair, true > bestMuonSelector_
bool defaultBestMuon_
Use default criteria to choose the best muon.
template<typename T >
bool modules::MuonCleanerBySegmentsT< T >::isSameMuon ( const T mu1,
const T mu2 
) const
inline

Definition at line 47 of file MuonCleanerBySegments.cc.

47  {
48  return (& mu1 == & mu2) ||
49  (mu1.reco::Muon::innerTrack().isNonnull() ?
50  mu1.reco::Muon::innerTrack() == mu2.reco::Muon::innerTrack() :
51  mu1.reco::Muon::outerTrack() == mu2.reco::Muon::outerTrack());
52  }
template<>
bool modules::MuonCleanerBySegmentsT< pat::Muon >::isSameMuon ( const pat::Muon mu1,
const pat::Muon mu2 
) const
template<>
bool modules::MuonCleanerBySegmentsT< pat::Muon >::isSameMuon ( const pat::Muon mu1,
const pat::Muon mu2 
) const

Definition at line 154 of file MuonCleanerBySegments.cc.

References pat::PATObject< ObjectType >::originalObjectRef().

154  {
155  return (& mu1 == & mu2) ||
156  (mu1.originalObjectRef() == mu2.originalObjectRef()) ||
157  (mu1.reco::Muon::innerTrack().isNonnull() ?
158  mu1.reco::Muon::innerTrack() == mu2.reco::Muon::innerTrack() :
159  mu1.reco::Muon::outerTrack() == mu2.reco::Muon::outerTrack());
160 }
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:498
template<typename T >
void modules::MuonCleanerBySegmentsT< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overridevirtual

Implements edm::EDProducer.

Definition at line 93 of file MuonCleanerBySegments.cc.

References edm::Event::getByToken(), i, j, dbtoconf::out, edm::Event::put(), reco::Muon::SegmentArbitration, muon::sharedSegments(), and alcazmumu_cfi::src.

93  {
94  using namespace edm;
95  using namespace std;
96 
98  auto_ptr<vector<T> > out(new vector<T>());
99 
100  iEvent.getByToken(srcToken_, src);
101  unsigned int nsrc = src->size();
102  out->reserve(nsrc);
103  std::vector<int> good(nsrc, true);
104  for (unsigned int i = 0; i < nsrc; ++i) {
105  const T &mu1 = (*src)[i];
106  if (!preselection_(mu1)) good[i] = false;
107  if (!good[i]) continue;
108  int nSegments1 = mu1.numberOfMatches(reco::Muon::SegmentArbitration);
109  for (unsigned int j = i+1; j < nsrc; ++j) {
110  const T &mu2 = (*src)[j];
111  if (isSameMuon(mu1,mu2)) continue;
112  if (!good[j] || !preselection_(mu2)) continue;
113  int nSegments2 = mu2.numberOfMatches(reco::Muon::SegmentArbitration);
114  if (nSegments2 == 0 || nSegments1 == 0) continue;
115  double sf = muon::sharedSegments(mu1,mu2)/std::min<double>(nSegments1,nSegments2);
116  if (sf > sharedFraction_) {
117  if (isBetterMuon(mu1,mu2)) {
118  good[j] = false;
119  } else {
120  good[i] = false;
121  }
122  }
123  }
124  }
125  for (unsigned int i = 0; i < nsrc; ++i) {
126  const T &mu1 = (*src)[i];
127  if (good[i] || passthrough_(mu1)) out->push_back(mu1);
128  }
129  iEvent.put(out);
130 }
int i
Definition: DBlmapReader.cc:9
double sharedFraction_
Fraction of shared segments.
StringCutObjectSelector< T > preselection_
Preselection cut.
StringCutObjectSelector< T > passthrough_
Always-accept cut.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
bool isSameMuon(const T &mu1, const T &mu2) const
int j
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< edm::View< T > > srcToken_
Tokens for input collections.
bool isBetterMuon(const T &mu1, const T &mu2) const
tuple out
Definition: dbtoconf.py:99
int sharedSegments(const reco::Muon &muon1, const reco::Muon &muon2, unsigned int segmentArbitrationMask=reco::MuonSegmentMatch::BestInChamberByDR)
long double T

Member Data Documentation

template<typename T >
StringCutObjectSelector<MuonPointerPair, true> modules::MuonCleanerBySegmentsT< T >::bestMuonSelector_
private

Definition at line 70 of file MuonCleanerBySegments.cc.

template<typename T >
bool modules::MuonCleanerBySegmentsT< T >::defaultBestMuon_
private

Use default criteria to choose the best muon.

Definition at line 67 of file MuonCleanerBySegments.cc.

template<typename T >
StringCutObjectSelector<T> modules::MuonCleanerBySegmentsT< T >::passthrough_
private

Always-accept cut.

Definition at line 61 of file MuonCleanerBySegments.cc.

template<typename T >
StringCutObjectSelector<T> modules::MuonCleanerBySegmentsT< T >::preselection_
private

Preselection cut.

Definition at line 59 of file MuonCleanerBySegments.cc.

template<typename T >
double modules::MuonCleanerBySegmentsT< T >::sharedFraction_
private

Fraction of shared segments.

Definition at line 64 of file MuonCleanerBySegments.cc.

template<typename T >
edm::EDGetTokenT<edm::View<T> > modules::MuonCleanerBySegmentsT< T >::srcToken_
private

Tokens for input collections.

Definition at line 56 of file MuonCleanerBySegments.cc.