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 
StringCutObjectSelector< pat::PackedCandidate, false > pfCandidateCut_
reco::CandidatePtr pfCandidate_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
edm::Ptr< pat::PackedCandidate > PackedCandidatePtr
Definition: HeavyIon.h:7
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > pfCandToken_
int iEvent
Definition: GenABIO.cc:224
~PATMuonMerger() override
edm::EDGetTokenT< std::vector< pat::Muon > > muonToken_
T sqrt(T t)
Definition: SSEVec.h:23
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::InputTag pfCandidate_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
HLT enums.
edm::InputTag lostTrack_
StringCutObjectSelector< pat::Muon, false > muonsCut_
StringCutObjectSelector< pat::PackedCandidate, false > lostTrackCut_
PATMuonMerger(const edm::ParameterSet &iConfig)
Analysis-level muon class.
Definition: Muon.h:51
edm::EDGetTokenT< std::vector< pat::PackedCandidate > > lostTrackToken_
def move(src, dest)
Definition: eostools.py:511
edm::InputTag muons_