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::stream::EDProducer<>

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::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

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::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

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 38 of file MuonCleanerBySegments.cc.

Member Typedef Documentation

◆ MuonPointerPair

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 67 of file MuonCleanerBySegments.cc.

Constructor & Destructor Documentation

◆ MuonCleanerBySegmentsT()

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

Definition at line 76 of file MuonCleanerBySegments.cc.

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

◆ ~MuonCleanerBySegmentsT()

template<typename T >
modules::MuonCleanerBySegmentsT< T >::~MuonCleanerBySegmentsT ( )
inlineoverride

Definition at line 41 of file MuonCleanerBySegments.cc.

41 {}

Member Function Documentation

◆ isBetterMuon()

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

Definition at line 136 of file MuonCleanerBySegments.cc.

References HLTMuonOfflineAnalyzer_cfi::deltaR2, and reco::Muon::SegmentArbitration.

136  {
137  if (!defaultBestMuon_) {
138  MuonPointerPair pair = {&mu1, &mu2};
139  return bestMuonSelector_(pair);
140  }
141  if (mu2.track().isNull())
142  return true;
143  if (mu1.track().isNull())
144  return false;
145  if (mu1.isPFMuon() != mu2.isPFMuon())
146  return mu1.isPFMuon();
147  if (mu1.isGlobalMuon() != mu2.isGlobalMuon())
148  return mu1.isGlobalMuon();
149  if (mu1.charge() == mu2.charge() && deltaR2(mu1, mu2) < 0.0009) {
150  return mu1.track()->ptError() / mu1.track()->pt() < mu2.track()->ptError() / mu2.track()->pt();
151  } else {
152  int nm1 = mu1.numberOfMatches(reco::Muon::SegmentArbitration);
153  int nm2 = mu2.numberOfMatches(reco::Muon::SegmentArbitration);
154  return (nm1 != nm2 ? nm1 > nm2 : mu1.pt() > mu2.pt());
155  }
156 }
std::pair< const reco::Muon *, const reco::Muon * > MuonPointerPair
Cut on the pair of objects together.
StringCutObjectSelector< MuonPointerPair, true > bestMuonSelector_
bool defaultBestMuon_
Use default criteria to choose the best muon.

◆ isSameMuon() [1/3]

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

Definition at line 45 of file MuonCleanerBySegments.cc.

45  {
46  return (&mu1 == &mu2) ||
47  (mu1.reco::Muon::innerTrack().isNonnull() ? mu1.reco::Muon::innerTrack() == mu2.reco::Muon::innerTrack()
48  : mu1.reco::Muon::outerTrack() == mu2.reco::Muon::outerTrack());
49  }

◆ isSameMuon() [2/3]

template<>
bool modules::MuonCleanerBySegmentsT< pat::Muon >::isSameMuon ( const pat::Muon mu1,
const pat::Muon mu2 
) const

◆ isSameMuon() [3/3]

template<>
bool modules::MuonCleanerBySegmentsT< pat::Muon >::isSameMuon ( const pat::Muon mu1,
const pat::Muon mu2 
) const

Definition at line 159 of file MuonCleanerBySegments.cc.

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

159  {
160  return (&mu1 == &mu2) || (mu1.originalObjectRef() == mu2.originalObjectRef()) ||
161  (mu1.reco::Muon::innerTrack().isNonnull() ? mu1.reco::Muon::innerTrack() == mu2.reco::Muon::innerTrack()
162  : mu1.reco::Muon::outerTrack() == mu2.reco::Muon::outerTrack());
163 }
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:537

◆ produce()

template<typename T >
void modules::MuonCleanerBySegmentsT< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 90 of file MuonCleanerBySegments.cc.

References caHitNtupletGeneratorKernels::good, mps_fire::i, iEvent, dqmiolumiharvest::j, eostools::move(), MillePedeFileConverter_cfg::out, reco::Muon::SegmentArbitration, muon::sharedSegments(), and TrackRefitter_38T_cff::src.

90  {
91  using namespace edm;
92  using namespace std;
93 
95  unique_ptr<vector<T> > out(new vector<T>());
96 
97  iEvent.getByToken(srcToken_, src);
98  unsigned int nsrc = src->size();
99  out->reserve(nsrc);
100  std::vector<int> good(nsrc, true);
101  for (unsigned int i = 0; i < nsrc; ++i) {
102  const T &mu1 = (*src)[i];
103  if (!preselection_(mu1))
104  good[i] = false;
105  if (!good[i])
106  continue;
107  int nSegments1 = mu1.numberOfMatches(reco::Muon::SegmentArbitration);
108  for (unsigned int j = i + 1; j < nsrc; ++j) {
109  const T &mu2 = (*src)[j];
110  if (isSameMuon(mu1, mu2))
111  continue;
112  if (!good[j] || !preselection_(mu2))
113  continue;
114  int nSegments2 = mu2.numberOfMatches(reco::Muon::SegmentArbitration);
115  if (nSegments2 == 0 || nSegments1 == 0)
116  continue;
117  double sf = muon::sharedSegments(mu1, mu2) / std::min<double>(nSegments1, nSegments2);
118  if (sf > sharedFraction_) {
119  if (isBetterMuon(mu1, mu2)) {
120  good[j] = false;
121  } else {
122  good[i] = false;
123  }
124  }
125  }
126  }
127  for (unsigned int i = 0; i < nsrc; ++i) {
128  const T &mu1 = (*src)[i];
129  if (good[i] || passthrough_(mu1))
130  out->push_back(mu1);
131  }
132  iEvent.put(std::move(out));
133 }
double sharedFraction_
Fraction of shared segments.
StringCutObjectSelector< T > preselection_
Preselection cut.
StringCutObjectSelector< T > passthrough_
Always-accept cut.
bool isBetterMuon(const T &mu1, const T &mu2) const
int iEvent
Definition: GenABIO.cc:224
bool isSameMuon(const T &mu1, const T &mu2) const
edm::EDGetTokenT< edm::View< T > > srcToken_
Tokens for input collections.
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

◆ bestMuonSelector_

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

Definition at line 68 of file MuonCleanerBySegments.cc.

◆ defaultBestMuon_

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

Use default criteria to choose the best muon.

Definition at line 65 of file MuonCleanerBySegments.cc.

◆ passthrough_

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

Always-accept cut.

Definition at line 59 of file MuonCleanerBySegments.cc.

◆ preselection_

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

Preselection cut.

Definition at line 57 of file MuonCleanerBySegments.cc.

◆ sharedFraction_

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

Fraction of shared segments.

Definition at line 62 of file MuonCleanerBySegments.cc.

◆ srcToken_

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

Tokens for input collections.

Definition at line 54 of file MuonCleanerBySegments.cc.