Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:59

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/global/EDProducer.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 
0005 #include "DataFormats/TrackReco/interface/Track.h"
0006 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0007 #include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
0008 #include "DataFormats/PatCandidates/interface/Muon.h"
0009 
0010 class TrackProducerFromPatMuons : public edm::global::EDProducer<> {
0011 public:
0012   explicit TrackProducerFromPatMuons(const edm::ParameterSet &);
0013   ~TrackProducerFromPatMuons() override = default;
0014 
0015   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0016 
0017 private:
0018   void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0019 
0020   const edm::EDGetTokenT<std::vector<pat::Muon>> inputMuons_;
0021   const edm::EDPutTokenT<reco::TrackCollection> outputTrack_;
0022   const bool innerTrackOnly_;
0023 };
0024 
0025 TrackProducerFromPatMuons::TrackProducerFromPatMuons(const edm::ParameterSet &iConfig)
0026     : inputMuons_(consumes<std::vector<pat::Muon>>(iConfig.getParameter<edm::InputTag>("src"))),
0027       outputTrack_(produces<reco::TrackCollection>()),
0028       innerTrackOnly_(iConfig.getParameter<bool>("innerTrackOnly")) {}
0029 
0030 // ------------ method called for each event  ------------
0031 void TrackProducerFromPatMuons::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0032   using namespace edm;
0033 
0034   auto const &muons = iEvent.get(inputMuons_);
0035 
0036   reco::TrackCollection tracksOut;
0037 
0038   for (auto const &muon : muons) {
0039     const reco::TrackRef trackRef = innerTrackOnly_ ? muon.innerTrack() : muon.muonBestTrack();
0040     if (trackRef.isNonnull() && trackRef->extra().isAvailable()) {
0041       tracksOut.emplace_back(*trackRef);
0042     }
0043   }
0044   iEvent.emplace(outputTrack_, std::move(tracksOut));
0045 }
0046 
0047 void TrackProducerFromPatMuons::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0048   edm::ParameterSetDescription desc;
0049   desc.setComment("Simple prooducer to generate track from pat::muons ");
0050   desc.add<edm::InputTag>("src", edm::InputTag("slimmedMuons"))->setComment("input track collections");
0051   desc.add<bool>("innerTrackOnly", true)->setComment("use only inner track");
0052   descriptions.addWithDefaultLabel(desc);
0053 }
0054 
0055 DEFINE_FWK_MODULE(TrackProducerFromPatMuons);