File indexing completed on 2024-04-06 12:23:42
0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Utilities/interface/InputTag.h"
0005 #include "DataFormats/Common/interface/View.h"
0006
0007 #include "DataFormats/PatCandidates/interface/UserData.h"
0008 #include "PhysicsTools/PatAlgos/interface/PATUserDataMerger.h"
0009 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0010
0011 #include "DataFormats/VertexReco/interface/Vertex.h"
0012 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0013
0014 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0015 #include "DataFormats/TrackReco/interface/Track.h"
0016 #include "DataFormats/Math/interface/deltaR.h"
0017 #include "DataFormats/MuonReco/interface/MuonSimInfo.h"
0018 #include "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h"
0019
0020 class pfTracksProducer : public edm::stream::EDProducer<> {
0021 public:
0022 explicit pfTracksProducer(const edm::ParameterSet& iConfig)
0023 : PFCands_(consumes<std::vector<pat::PackedCandidate>>(iConfig.getParameter<edm::InputTag>("PFCands"))),
0024 LostTracks_(consumes<std::vector<pat::PackedCandidate>>(iConfig.getParameter<edm::InputTag>("lostTracks"))),
0025 trkSelection_(iConfig.getParameter<std::string>("trkSelection")),
0026 HighPurity_(iConfig.getParameter<bool>("TrkHPurity")) {
0027 produces<reco::TrackCollection>();
0028 }
0029 ~pfTracksProducer() override {}
0030
0031 private:
0032 void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0033
0034 edm::EDGetToken PFCands_;
0035 edm::EDGetToken LostTracks_;
0036 const StringCutObjectSelector<pat::PackedCandidate> trkSelection_;
0037 const bool HighPurity_;
0038 };
0039
0040 void pfTracksProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0041 edm::Handle<std::vector<pat::PackedCandidate>> pfcands;
0042 iEvent.getByToken(PFCands_, pfcands);
0043
0044 edm::Handle<std::vector<pat::PackedCandidate>> lostTracks;
0045 iEvent.getByToken(LostTracks_, lostTracks);
0046
0047 std::unique_ptr<std::vector<reco::Track>> tracks(new std::vector<reco::Track>());
0048 tracks->reserve(pfcands->size() + lostTracks->size());
0049
0050 for (const auto& container : {pfcands, lostTracks}) {
0051 for (const pat::PackedCandidate& trk : *container) {
0052 if (!trk.hasTrackDetails())
0053 continue;
0054 if (!trkSelection_(trk))
0055 continue;
0056 if (HighPurity_ && !trk.trackHighPurity())
0057 continue;
0058 tracks->emplace_back(*trk.bestTrack());
0059 }
0060 }
0061
0062 iEvent.put(std::move(tracks));
0063 }
0064
0065 #include "FWCore/Framework/interface/MakerMacros.h"
0066 DEFINE_FWK_MODULE(pfTracksProducer);