CMS 3D CMS Logo

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;
ConfigurationDescriptions.h
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
pat::PackedCandidateMuonSelectorProducer::lostTrackToken_
const edm::EDGetTokenT< pat::PackedCandidateCollection > lostTrackToken_
Definition: PackedCandidateMuonSelectorProducer.cc:45
mps_fire.i
i
Definition: mps_fire.py:428
pat::PackedCandidateMuonSelectorProducer::muonToken_
const edm::EDGetTokenT< reco::MuonCollection > muonToken_
Definition: PackedCandidateMuonSelectorProducer.cc:43
StringCutObjectSelector.h
muon
Definition: MuonCocktails.h:17
edm::EDGetTokenT< reco::MuonCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
pat::PackedCandidateMuonSelectorProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PackedCandidateMuonSelectorProducer.cc:55
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
pat::PackedCandidateMuonSelectorProducer::~PackedCandidateMuonSelectorProducer
~PackedCandidateMuonSelectorProducer() override=default
pat::PackedCandidateMuonSelectorProducer::muonSelectors_
const std::vector< std::string > muonSelectors_
Definition: PackedCandidateMuonSelectorProducer.cc:48
edm::RefVector
Definition: EDProductfwd.h:27
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
muon::isGoodMuon
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
Definition: MuonSelectors.cc:649
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
muon::selectionTypeFromString
SelectionType selectionTypeFromString(const std::string &label)
Definition: MuonSelectors.cc:9
MuonSelectors.h
pat::PackedCandidateMuonSelectorProducer::muonIDMap_
std::map< std::string, std::unique_ptr< StringCutObjectSelector< reco::Muon > > > muonIDMap_
Definition: PackedCandidateMuonSelectorProducer.cc:50
pat::MuonCollection
std::vector< Muon > MuonCollection
Definition: Muon.h:35
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pat::PackedCandidateMuonSelectorProducer::PackedCandidateMuonSelectorProducer
PackedCandidateMuonSelectorProducer(const edm::ParameterSet &iConfig)
Definition: PackedCandidateMuonSelectorProducer.cc:17
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
PackedCandidate.h
cand
Definition: decayParser.h:32
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::stream::EDProducer
Definition: EDProducer.h:38
pat::PackedCandidateMuonSelectorProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: PackedCandidateMuonSelectorProducer.cc:120
pat::PackedCandidateMuonSelectorProducer::candidate2PFToken_
const edm::EDGetTokenT< edm::Association< reco::PFCandidateCollection > > candidate2PFToken_
Definition: PackedCandidateMuonSelectorProducer.cc:46
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
pat::PackedCandidateMuonSelectorProducer::candidateToken_
const edm::EDGetTokenT< pat::PackedCandidateCollection > candidateToken_
Definition: PackedCandidateMuonSelectorProducer.cc:44
pat::PackedCandidateMuonSelectorProducer::muonIDs_
const std::vector< std::string > muonIDs_
Definition: PackedCandidateMuonSelectorProducer.cc:49
l1t::PFCandidateCollection
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
InputTag.h
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1130
reco::TrackBase::qualityByName
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
pat::PackedCandidateMuonSelectorProducer
Definition: PackedCandidateMuonSelectorProducer.cc:15
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
pat::PackedCandidateMuonSelectorProducer::track2LostTrackToken_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > track2LostTrackToken_
Definition: PackedCandidateMuonSelectorProducer.cc:47
HLT_FULL_cff.candidates
candidates
Definition: HLT_FULL_cff.py:54985
ParameterSet.h
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
pat::PackedCandidateRef
edm::Ref< pat::PackedCandidateCollection > PackedCandidateRef
Definition: PackedCandidate.h:1131