CMS 3D CMS Logo

PATMuonMerger.cc
Go to the documentation of this file.
5 
9 
13 
16 
17 namespace pat {
19 }
20 
22 public:
23  explicit PATMuonMerger(const edm::ParameterSet& iConfig);
24  ~PATMuonMerger() override {}
25 
26  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
27  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
28 
29 private:
36 
40 };
41 
43  : muons_(iConfig.getParameter<edm::InputTag>("muons")),
44  muonsCut_(iConfig.getParameter<std::string>("muonCut")),
45  pfCandidate_(iConfig.getParameter<edm::InputTag>("pfCandidates")),
46  pfCandidateCut_(iConfig.getParameter<std::string>("pfCandidatesCut")),
47  lostTrack_(iConfig.getParameter<edm::InputTag>("otherTracks")),
48  lostTrackCut_(iConfig.getParameter<std::string>("lostTrackCut")) {
49  muonToken_ = consumes<std::vector<pat::Muon>>(muons_);
50  pfCandToken_ = consumes<std::vector<pat::PackedCandidate>>(pfCandidate_);
51  lostTrackToken_ = consumes<std::vector<pat::PackedCandidate>>(lostTrack_);
52  produces<std::vector<pat::Muon>>();
53 }
54 
56  // mergedMuons
58  desc.add<std::string>("muonCut", "");
59  desc.add<edm::InputTag>("otherTracks", edm::InputTag("lostTracks"));
60  desc.add<edm::InputTag>("pfCandidates", edm::InputTag("packedPFCandidates"));
61  desc.add<std::string>("pfCandidatesCut", "");
62  desc.add<edm::InputTag>("muons", edm::InputTag("slimmedMuons"));
63  desc.add<std::string>("lostTrackCut", "");
64  descriptions.add("mergedMuonsNoCuts", desc);
65 }
66 
71 
72  iEvent.getByToken(muonToken_, muons);
73  iEvent.getByToken(pfCandToken_, pfCands);
74  iEvent.getByToken(lostTrackToken_, lostTracks);
75 
76  auto out = std::make_unique<std::vector<pat::Muon>>();
77  out->reserve(muons->size() + pfCands->size() + lostTracks->size());
78 
79  // copy all muons
80  for (auto& muon : *muons) {
81  if (!muonsCut_(muon))
82  continue;
83  out->push_back(muon);
84  }
85 
86  // add other pfCandidates, removing duplicates
87  for (unsigned int pf = 0; pf < pfCands->size(); ++pf) {
88  auto pfCand = pfCands->at(pf);
89  if (!pfCandidateCut_(pfCand))
90  continue;
91  reco::CandidatePtr pfCandPtr(pfCands, pf);
92  bool isPFMuon = false;
93  for (auto& muon : *muons) {
94  for (unsigned int i = 0, n = muon.numberOfSourceCandidatePtrs(); i < n; ++i) {
95  reco::CandidatePtr ptr = muon.sourceCandidatePtr(i);
96  if (ptr.isNonnull() && ptr == pfCandPtr) {
97  isPFMuon = true;
98  break;
99  }
100  }
101  if (isPFMuon)
102  break;
103  }
104  if (isPFMuon) {
105  continue;
106  }
107 
108  // now make a reco::Muon and recast to pat::Muon
109  double energy = sqrt(pfCand.p() * pfCand.p() + 0.011163691);
110  math::XYZTLorentzVector p4(pfCand.px(), pfCand.py(), pfCand.pz(), energy);
111  reco::Muon mu(pfCand.charge(), p4, pfCand.vertex());
112  pat::Muon aMu(mu);
113  out->push_back(aMu);
114  }
115 
116  // adding now lost tracks, removing duplicates
117  for (auto& lostTrack : *lostTracks) {
118  if (!lostTrackCut_(lostTrack))
119  continue;
120  if (std::abs(lostTrack.pdgId()) == 13)
121  continue;
122 
123  // now make a reco::Muon and recast to pat::Muon
124  double energy = sqrt(lostTrack.p() * lostTrack.p() + 0.011163691);
125  math::XYZTLorentzVector p4(lostTrack.px(), lostTrack.py(), lostTrack.pz(), energy);
126  reco::Muon mu(lostTrack.charge(), p4, lostTrack.vertex());
127  pat::Muon aMu(mu);
128  out->push_back(aMu);
129  }
130  iEvent.put(std::move(out));
131 }
132 
ConfigurationDescriptions.h
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
pat::PackedCandidatePtr
edm::Ptr< pat::PackedCandidate > PackedCandidatePtr
Definition: PATMuonMerger.cc:18
mps_fire.i
i
Definition: mps_fire.py:428
isotracks_cff.lostTracks
lostTracks
Definition: isotracks_cff.py:23
Muon.h
PATMuonMerger::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATMuonMerger.cc:67
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
muon
Definition: MuonCocktails.h:17
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
PATMuonMerger::~PATMuonMerger
~PATMuonMerger() override
Definition: PATMuonMerger.cc:24
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
getRef.h
EDProducer.h
PATMuonMerger::PATMuonMerger
PATMuonMerger(const edm::ParameterSet &iConfig)
Definition: PATMuonMerger.cc:42
PATMuonMerger::pfCandidate_
edm::InputTag pfCandidate_
Definition: PATMuonMerger.cc:32
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
edm::Handle
Definition: AssociativeIterator.h:50
reco::Muon
Definition: Muon.h:27
PATMuonMerger::lostTrack_
edm::InputTag lostTrack_
Definition: PATMuonMerger.cc:34
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
pfCandidate_
reco::CandidatePtr pfCandidate_
Definition: PFRecoTauChargedHadronFromGenericTrackPlugin.cc:197
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PATMuonMerger::muonsCut_
StringCutObjectSelector< pat::Muon, false > muonsCut_
Definition: PATMuonMerger.cc:31
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
PATMuonMerger::muonToken_
edm::EDGetTokenT< std::vector< pat::Muon > > muonToken_
Definition: PATMuonMerger.cc:37
PackedCandidate.h
iEvent
int iEvent
Definition: GenABIO.cc:224
RefToPtr.h
p4
double p4[4]
Definition: TauolaWrapper.h:92
PATMuonMerger::lostTrackToken_
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > lostTrackToken_
Definition: PATMuonMerger.cc:39
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
PATMuonMerger::pfCandToken_
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > pfCandToken_
Definition: PATMuonMerger.cc:38
PATMuonMerger::muons_
edm::InputTag muons_
Definition: PATMuonMerger.cc:30
InputTag.h
edm::Ptr
Definition: AssociationVector.h:31
PATMuonMerger::pfCandidateCut_
StringCutObjectSelector< pat::PackedCandidate, false > pfCandidateCut_
Definition: PATMuonMerger.cc:33
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
StringCutObjectSelector.h
PATMuonMerger::lostTrackCut_
StringCutObjectSelector< pat::PackedCandidate, false > lostTrackCut_
Definition: PATMuonMerger.cc:35
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
StringCutObjectSelector< pat::Muon, false >
edm::Ptr::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
PATMuonMerger
Definition: PATMuonMerger.cc:21
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
PATMuonMerger::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PATMuonMerger.cc:55
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15