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
0009 class TrackExtraRekeyer : public edm::global::EDProducer<> {
0010 public:
0011 explicit TrackExtraRekeyer(const edm::ParameterSet &);
0012 ~TrackExtraRekeyer() override = default;
0013
0014 static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0015
0016 private:
0017 void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0018
0019
0020 const edm::EDGetTokenT<reco::TrackCollection> inputTrack_;
0021 const edm::EDGetTokenT<edm::Association<reco::TrackExtraCollection>> inputAssoc_;
0022 const edm::EDPutTokenT<reco::TrackCollection> outputTrack_;
0023 };
0024
0025 TrackExtraRekeyer::TrackExtraRekeyer(const edm::ParameterSet &iConfig)
0026 : inputTrack_(consumes(iConfig.getParameter<edm::InputTag>("src"))),
0027 inputAssoc_(consumes(iConfig.getParameter<edm::InputTag>("association"))),
0028 outputTrack_(produces<reco::TrackCollection>()) {}
0029
0030
0031 void TrackExtraRekeyer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0032 using namespace edm;
0033
0034 auto const &tracks = iEvent.get(inputTrack_);
0035 auto const &assoc = iEvent.get(inputAssoc_);
0036
0037 reco::TrackCollection tracksOut;
0038
0039 for (auto const &track : tracks) {
0040 if (!assoc.contains(track.extra().id())) {
0041 continue;
0042 }
0043 const reco::TrackExtraRef &trackextraref = assoc[track.extra()];
0044 if (trackextraref.isNonnull()) {
0045 auto &trackout = tracksOut.emplace_back(track);
0046 trackout.setExtra(trackextraref);
0047 }
0048 }
0049 iEvent.emplace(outputTrack_, std::move(tracksOut));
0050 }
0051
0052 void TrackExtraRekeyer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0053 edm::ParameterSetDescription desc;
0054 desc.setComment("Simple prooducer to re-key muon tracks for refit");
0055 desc.add<edm::InputTag>("src", edm::InputTag("generalTracks"))->setComment("input track collections");
0056 desc.add<edm::InputTag>("association", edm::InputTag("muonReducedTrackExtras"))
0057 ->setComment("input track association collection");
0058 descriptions.addWithDefaultLabel(desc);
0059 }
0060
0061 DEFINE_FWK_MODULE(TrackExtraRekeyer);