File indexing completed on 2024-04-06 12:27:01
0001 #ifndef MuonIdentification_MuonSelectionTypeValueMapProducer_h
0002 #define MuonIdentification_MuonSelectionTypeValueMapProducer_h
0003
0004 #include <string>
0005 #include <vector>
0006
0007 #include "DataFormats/Common/interface/ValueMap.h"
0008 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0009 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0010
0011 #include "FWCore/Framework/interface/stream/EDProducer.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017
0018 class MuonSelectionTypeValueMapProducer : public edm::stream::EDProducer<> {
0019 public:
0020 explicit MuonSelectionTypeValueMapProducer(const edm::ParameterSet& iConfig)
0021 : inputMuonCollection_(iConfig.getParameter<edm::InputTag>("inputMuonCollection")),
0022 selectionTypeLabel_(iConfig.getParameter<std::string>("selectionType")) {
0023 selectionType_ = muon::selectionTypeFromString(selectionTypeLabel_);
0024 produces<edm::ValueMap<bool>>().setBranchAlias("muid" + selectionTypeLabel_);
0025 muonToken_ = consumes<reco::MuonCollection>(inputMuonCollection_);
0026 }
0027 ~MuonSelectionTypeValueMapProducer() override {}
0028
0029 private:
0030 void produce(edm::Event&, const edm::EventSetup&) override;
0031
0032 edm::InputTag inputMuonCollection_;
0033 edm::EDGetTokenT<reco::MuonCollection> muonToken_;
0034
0035 std::string selectionTypeLabel_;
0036 muon::SelectionType selectionType_;
0037 };
0038
0039 inline void MuonSelectionTypeValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0040
0041 edm::Handle<reco::MuonCollection> muonsH;
0042 iEvent.getByToken(muonToken_, muonsH);
0043
0044
0045 std::vector<bool> values;
0046 values.reserve(muonsH->size());
0047
0048
0049 for (reco::MuonCollection::const_iterator it = muonsH->begin(); it != muonsH->end(); ++it)
0050 values.push_back(muon::isGoodMuon(*it, selectionType_));
0051
0052
0053 auto out = std::make_unique<edm::ValueMap<bool>>();
0054 edm::ValueMap<bool>::Filler filler(*out);
0055 filler.insert(muonsH, values.begin(), values.end());
0056 filler.fill();
0057
0058
0059 iEvent.put(std::move(out));
0060 }
0061
0062 #endif