File indexing completed on 2024-04-06 12:09:12
0001 #include <memory>
0002 #include <vector>
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "DataFormats/Common/interface/View.h"
0005 #include "DataFormats/TrackReco/interface/Track.h"
0006 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
0007 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0008 #include "FWCore/Framework/interface/global/EDProducer.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012
0013 class V0VertexTrackProducer : public edm::global::EDProducer<> {
0014 public:
0015 explicit V0VertexTrackProducer(const edm::ParameterSet&);
0016 ~V0VertexTrackProducer() override = default;
0017 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0018
0019 void produce(edm::StreamID streamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const override;
0020
0021 private:
0022 const edm::EDGetTokenT<reco::VertexCompositeCandidateCollection> vccToken_;
0023 };
0024
0025 V0VertexTrackProducer::V0VertexTrackProducer(const edm::ParameterSet& iConfig)
0026 : vccToken_{consumes<reco::VertexCompositeCandidateCollection>(
0027 iConfig.getParameter<edm::InputTag>("vertexCompositeCandidates"))} {
0028 produces<std::vector<reco::Track>>();
0029 }
0030
0031 void V0VertexTrackProducer::produce(edm::StreamID streamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const {
0032 edm::Handle<reco::VertexCompositeCandidateCollection> vccHandle;
0033 iEvent.getByToken(vccToken_, vccHandle);
0034
0035 std::unique_ptr<std::vector<reco::Track>> outputTracks(new std::vector<reco::Track>());
0036
0037 if (vccHandle.isValid()) {
0038
0039 for (const auto& vcc : *vccHandle) {
0040 for (size_t i = 0; i < vcc.numberOfDaughters(); ++i) {
0041 const reco::Candidate* daughter = vcc.daughter(i);
0042 const reco::RecoChargedCandidate* chargedDaughter = dynamic_cast<const reco::RecoChargedCandidate*>(daughter);
0043 if (chargedDaughter) {
0044 const reco::TrackRef trackRef = chargedDaughter->track();
0045 if (trackRef.isNonnull()) {
0046 outputTracks->push_back(*trackRef);
0047 }
0048 }
0049 }
0050 }
0051 } else {
0052 edm::LogError("V0VertexTrackProducer") << "Error >> Failed to get VertexCompositeCandidateCollection";
0053 }
0054 iEvent.put(std::move(outputTracks));
0055 }
0056
0057 void V0VertexTrackProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0058 edm::ParameterSetDescription desc;
0059 desc.add<edm::InputTag>("vertexCompositeCandidates", edm::InputTag("generalV0Candidates:Kshort"));
0060 descriptions.addWithDefaultLabel(desc);
0061 }
0062
0063 DEFINE_FWK_MODULE(V0VertexTrackProducer);