CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PackedCandidateMuonSelectorProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 
12 
13 namespace pat {
14 
16  public:
18  : muonToken_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
19  candidateToken_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("candidates"))),
20  candidate2PFToken_(consumes<edm::Association<reco::PFCandidateCollection>>(
21  iConfig.getParameter<edm::InputTag>("candidates"))),
22  track2LostTrackToken_(consumes<edm::Association<pat::PackedCandidateCollection>>(
23  iConfig.getParameter<edm::InputTag>("lostTracks"))),
24  muonSelectors_(iConfig.getParameter<std::vector<std::string>>("muonSelectors")),
25  muonIDs_(iConfig.getParameter<std::vector<std::string>>("muonIDs")) {
26  for (const auto& sel : muonSelectors_) {
27  produces<pat::PackedCandidateRefVector>("lostTracks" + sel);
28  produces<pat::PackedCandidateRefVector>("pfCandidates" + sel);
29  }
30  for (const auto& sel : muonIDs_) {
31  muonIDMap_[sel] = std::make_unique<StringCutObjectSelector<reco::Muon>>("passed('" + sel + "')");
32  produces<pat::PackedCandidateRefVector>("lostTracks" + sel);
33  produces<pat::PackedCandidateRefVector>("pfCandidates" + sel);
34  }
35  }
36  ~PackedCandidateMuonSelectorProducer() override = default;
37 
38  void produce(edm::Event&, const edm::EventSetup&) override;
39 
41 
42  private:
48  const std::vector<std::string> muonSelectors_;
49  const std::vector<std::string> muonIDs_;
50  std::map<std::string, std::unique_ptr<StringCutObjectSelector<reco::Muon>>> muonIDMap_;
51  };
52 
53 } // namespace pat
54 
56  const auto& muons = iEvent.get(muonToken_);
57  const auto& candidates = iEvent.getHandle(candidateToken_);
58  const auto& candidate2PF = iEvent.get(candidate2PFToken_);
59  const auto& track2LostTrack = iEvent.get(track2LostTrackToken_);
60 
61  std::map<std::string, std::unique_ptr<pat::PackedCandidateRefVector>> lostTrackMap, candMap;
62  for (const auto& sel : muonSelectors_) {
63  lostTrackMap.emplace(sel, new pat::PackedCandidateRefVector());
64  candMap.emplace(sel, new pat::PackedCandidateRefVector());
65  }
66  for (const auto& sel : muonIDs_) {
67  lostTrackMap.emplace(sel, new pat::PackedCandidateRefVector());
68  candMap.emplace(sel, new pat::PackedCandidateRefVector());
69  }
70 
71  // loop over muons
72  for (const auto& muon : muons) {
73  const auto& muonTrack = muon.innerTrack();
74  // ignore muons without high purity inner track
75  if (muonTrack.isNull() || !muonTrack->quality(reco::TrackBase::qualityByName("highPurity")))
76  continue;
77 
78  // find lost track associated to muon
79  const auto& lostTrack = track2LostTrack[muonTrack];
80  if (lostTrack.isNonnull()) {
81  for (const auto& sel : muonSelectors_) {
83  lostTrackMap[sel]->push_back(lostTrack);
84  }
85  for (const auto& sel : muonIDs_) {
86  if ((*muonIDMap_.at(sel))(muon))
87  lostTrackMap[sel]->push_back(lostTrack);
88  }
89  continue;
90  }
91 
92  // find PF candidate associated to muon
93  for (size_t i = 0; i < candidates->size(); i++) {
94  const auto& cand = pat::PackedCandidateRef(candidates, i);
95  const auto& candTrack = candidate2PF[cand]->trackRef();
96  // check if candidate and muon are compatible
97  if (candTrack.isNonnull() && muonTrack == candTrack) {
98  for (const auto& sel : muonSelectors_) {
100  candMap[sel]->push_back(cand);
101  }
102  for (const auto& sel : muonIDs_) {
103  if ((*muonIDMap_.at(sel))(muon))
104  candMap[sel]->push_back(cand);
105  }
106  break;
107  }
108  }
109  }
110 
111  for (auto& s : lostTrackMap) {
112  iEvent.put(std::move(s.second), "lostTracks" + s.first);
113  }
114  for (auto& s : candMap) {
115  iEvent.put(std::move(s.second), "pfCandidates" + s.first);
116  }
117 }
118 
119 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
122  desc.add<edm::InputTag>("muons", edm::InputTag("muons"))->setComment("muon input collection");
123  desc.add<edm::InputTag>("candidates", edm::InputTag("packedPFCandidates"))
124  ->setComment("packed PF candidate input collection");
125  desc.add<edm::InputTag>("lostTracks", edm::InputTag("lostTracks"))->setComment("lost track input collection");
126  desc.add<std::vector<std::string>>("muonSelectors", {"AllTrackerMuons", "TMOneStationTight"})
127  ->setComment("muon selectors");
128  desc.add<std::vector<std::string>>("muonIDs", {})->setComment("muon IDs");
129  descriptions.add("packedCandidateMuonID", desc);
130 }
131 
133 using namespace pat;
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
static void fillDescriptions(edm::ConfigurationDescriptions &)
~PackedCandidateMuonSelectorProducer() override=default
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< edm::Association< reco::PFCandidateCollection > > candidate2PFToken_
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
std::vector< pat::PackedCandidate > PackedCandidateCollection
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > track2LostTrackToken_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
int iEvent
Definition: GenABIO.cc:224
std::map< std::string, std::unique_ptr< StringCutObjectSelector< reco::Muon > > > muonIDMap_
def move
Definition: eostools.py:511
edm::Ref< pat::PackedCandidateCollection > PackedCandidateRef
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
void produce(edm::Event &, const edm::EventSetup &) override
PackedCandidateMuonSelectorProducer(const edm::ParameterSet &iConfig)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const edm::EDGetTokenT< reco::MuonCollection > muonToken_
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
SelectionType selectionTypeFromString(const std::string &label)
Definition: MuonSelectors.cc:9
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< Muon > MuonCollection
Definition: Muon.h:35
deadvectors[0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
tuple muons
Definition: patZpeak.py:41
const edm::EDGetTokenT< pat::PackedCandidateCollection > candidateToken_
const edm::EDGetTokenT< pat::PackedCandidateCollection > lostTrackToken_