CMS 3D CMS Logo

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)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~MuonCleanerBySegmentsT () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

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
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
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)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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:161
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 >
modules::MuonCleanerBySegmentsT< T >::~MuonCleanerBySegmentsT ( )
inlineoverride

Definition at line 43 of file MuonCleanerBySegments.cc.

References iEvent, and modules::MuonCleanerBySegmentsT< T >::produce().

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 modules::MuonCleanerBySegmentsT< T >::bestMuonSelector_, modules::MuonCleanerBySegmentsT< T >::defaultBestMuon_, reco::deltaR2(), and reco::Muon::SegmentArbitration.

Referenced by modules::MuonCleanerBySegmentsT< T >::isSameMuon(), and modules::MuonCleanerBySegmentsT< T >::produce().

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.
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
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.

References modules::MuonCleanerBySegmentsT< T >::isBetterMuon().

Referenced by modules::MuonCleanerBySegmentsT< T >::produce().

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:500
template<typename T >
void modules::MuonCleanerBySegmentsT< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 93 of file MuonCleanerBySegments.cc.

References edm::Event::getByToken(), mps_fire::i, modules::MuonCleanerBySegmentsT< T >::isBetterMuon(), modules::MuonCleanerBySegmentsT< T >::isSameMuon(), eostools::move(), MillePedeFileConverter_cfg::out, modules::MuonCleanerBySegmentsT< T >::passthrough_, modules::MuonCleanerBySegmentsT< T >::preselection_, edm::Event::put(), reco::Muon::SegmentArbitration, modules::MuonCleanerBySegmentsT< T >::sharedFraction_, muon::sharedSegments(), TrackRefitter_38T_cff::src, and modules::MuonCleanerBySegmentsT< T >::srcToken_.

Referenced by modules::MuonCleanerBySegmentsT< T >::~MuonCleanerBySegmentsT().

93  {
94  using namespace edm;
95  using namespace std;
96 
98  unique_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(std::move(out));
130 }
double sharedFraction_
Fraction of shared segments.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
StringCutObjectSelector< T > preselection_
Preselection cut.
StringCutObjectSelector< T > passthrough_
Always-accept cut.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
bool isSameMuon(const T &mu1, const T &mu2) const
edm::EDGetTokenT< edm::View< T > > srcToken_
Tokens for input collections.
bool isBetterMuon(const T &mu1, const T &mu2) const
int sharedSegments(const reco::Muon &muon1, const reco::Muon &muon2, unsigned int segmentArbitrationMask=reco::MuonSegmentMatch::BestInChamberByDR)
HLT enums.
long double T
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

template<typename T >
StringCutObjectSelector<MuonPointerPair, true> modules::MuonCleanerBySegmentsT< T >::bestMuonSelector_
private
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.

Referenced by modules::MuonCleanerBySegmentsT< T >::isBetterMuon().

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

Always-accept cut.

Definition at line 61 of file MuonCleanerBySegments.cc.

Referenced by modules::MuonCleanerBySegmentsT< T >::produce().

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

Preselection cut.

Definition at line 59 of file MuonCleanerBySegments.cc.

Referenced by modules::MuonCleanerBySegmentsT< T >::produce().

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

Fraction of shared segments.

Definition at line 64 of file MuonCleanerBySegments.cc.

Referenced by modules::MuonCleanerBySegmentsT< T >::produce().

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.

Referenced by modules::MuonCleanerBySegmentsT< T >::produce().