CMS 3D CMS Logo

MuonCleanerBySegments.cc
Go to the documentation of this file.
1 
2 //
3 //
4 
27 
29 
34 
35 namespace modules {
36 
37  template <typename T>
39  public:
40  explicit MuonCleanerBySegmentsT(const edm::ParameterSet &iConfig);
42 
43  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
44 
45  bool isSameMuon(const T &mu1, const T &mu2) const {
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  }
50  bool isBetterMuon(const T &mu1, const T &mu2) const;
51 
52  private:
55 
60 
63 
67  typedef std::pair<const reco::Muon *, const reco::Muon *> MuonPointerPair;
69  };
70 
71  template <>
72  bool MuonCleanerBySegmentsT<pat::Muon>::isSameMuon(const pat::Muon &mu1, const pat::Muon &mu2) const;
73 } // namespace modules
74 
75 template <typename T>
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 }
88 
89 template <typename T>
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 }
134 
135 template <typename T>
136 bool modules::MuonCleanerBySegmentsT<T>::isBetterMuon(const T &mu1, const T &mu2) const {
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 }
157 
158 template <>
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 }
164 
165 namespace modules {
168 } // namespace modules
169 
171 using namespace modules;
mps_fire.i
i
Definition: mps_fire.py:428
modules::PATMuonCleanerBySegments
modules::MuonCleanerBySegmentsT< pat::Muon > PATMuonCleanerBySegments
Definition: MuonCleanerBySegments.cc:167
Muon.h
EDProducer.h
reco::Muon::SegmentArbitration
Definition: Muon.h:189
sistrip::View
View
Definition: ConstantsForView.h:26
modules::MuonCleanerBySegmentsT::isBetterMuon
bool isBetterMuon(const T &mu1, const T &mu2) const
Definition: MuonCleanerBySegments.cc:136
modules
Definition: ZHLTMatchFilter.cc:17
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
modules::MuonCleanerBySegmentsT
Removes duplicates from a muon collection using segment references.
Definition: MuonCleanerBySegments.cc:38
modules::MuonCleanerBySegments
modules::MuonCleanerBySegmentsT< reco::Muon > MuonCleanerBySegments
Definition: MuonCleanerBySegments.cc:166
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
modules::MuonCleanerBySegmentsT::MuonPointerPair
std::pair< const reco::Muon *, const reco::Muon * > MuonPointerPair
Cut on the pair of objects together.
Definition: MuonCleanerBySegments.cc:67
modules::MuonCleanerBySegmentsT::srcToken_
edm::EDGetTokenT< edm::View< T > > srcToken_
Tokens for input collections.
Definition: MuonCleanerBySegments.cc:54
modules::MuonCleanerBySegmentsT::passthrough_
StringCutObjectSelector< T > passthrough_
Always-accept cut.
Definition: MuonCleanerBySegments.cc:59
modules::MuonCleanerBySegmentsT::isSameMuon
bool isSameMuon(const T &mu1, const T &mu2) const
Definition: MuonCleanerBySegments.cc:45
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
edm::Handle
Definition: AssociativeIterator.h:50
modules::MuonCleanerBySegmentsT::MuonCleanerBySegmentsT
MuonCleanerBySegmentsT(const edm::ParameterSet &iConfig)
Definition: MuonCleanerBySegments.cc:76
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuonSelectors.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pat::PATObject::originalObjectRef
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:539
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
deltaR.h
modules::MuonCleanerBySegmentsT::defaultBestMuon_
bool defaultBestMuon_
Use default criteria to choose the best muon.
Definition: MuonCleanerBySegments.cc:65
modules::MuonCleanerBySegmentsT::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: MuonCleanerBySegments.cc:90
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
modules::MuonCleanerBySegmentsT::bestMuonSelector_
StringCutObjectSelector< MuonPointerPair, true > bestMuonSelector_
Definition: MuonCleanerBySegments.cc:68
InputTag.h
modules::MuonCleanerBySegmentsT::~MuonCleanerBySegmentsT
~MuonCleanerBySegmentsT() override
Definition: MuonCleanerBySegments.cc:41
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
muon::sharedSegments
int sharedSegments(const reco::Muon &muon1, const reco::Muon &muon2, unsigned int segmentArbitrationMask=reco::MuonSegmentMatch::BestInChamberByDR)
Definition: MuonSelectors.cc:978
StringCutObjectSelector.h
modules::MuonCleanerBySegmentsT::sharedFraction_
double sharedFraction_
Fraction of shared segments.
Definition: MuonCleanerBySegments.cc:62
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
T
long double T
Definition: Basic3DVectorLD.h:48
StringCutObjectSelector< T >
modules::MuonCleanerBySegmentsT::preselection_
StringCutObjectSelector< T > preselection_
Preselection cut.
Definition: MuonCleanerBySegments.cc:57
edm::EDProducer
Definition: EDProducer.h:35
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73