File indexing completed on 2024-04-06 12:31:05
0001
0002
0003 #include <memory>
0004
0005
0006 #include "DataFormats/BTauReco/interface/SecondaryVertexTagInfo.h"
0007 #include "DataFormats/Common/interface/AssociationMap.h"
0008 #include "DataFormats/VertexReco/interface/Vertex.h"
0009 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0010
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/Frameworkfwd.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/Framework/interface/global/EDProducer.h"
0015
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017
0018
0019
0020
0021
0022 class SecondaryVertexTagInfoProxy : public edm::global::EDProducer<> {
0023 public:
0024 explicit SecondaryVertexTagInfoProxy(const edm::ParameterSet &);
0025
0026 private:
0027 void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0028
0029 edm::EDGetTokenT<reco::SecondaryVertexTagInfoCollection> svTagInfoCollection_;
0030 };
0031
0032 SecondaryVertexTagInfoProxy::SecondaryVertexTagInfoProxy(const edm::ParameterSet &config) {
0033
0034 svTagInfoCollection_ = consumes<reco::SecondaryVertexTagInfoCollection>(
0035 config.getUntrackedParameter<edm::InputTag>("svTagInfoProducer"));
0036
0037
0038 produces<reco::VertexCollection>();
0039 produces<edm::AssociationMap<edm::OneToMany<reco::SecondaryVertexTagInfoCollection, reco::VertexCollection>>>();
0040 }
0041
0042 void SecondaryVertexTagInfoProxy::produce(edm::StreamID, edm::Event &event, const edm::EventSetup &setup) const {
0043
0044 edm::Handle<reco::SecondaryVertexTagInfoCollection> svTagInfoCollection;
0045 event.getByToken(svTagInfoCollection_, svTagInfoCollection);
0046
0047
0048 std::unique_ptr<reco::VertexCollection> proxy(new reco::VertexCollection);
0049 std::unique_ptr<edm::AssociationMap<edm::OneToMany<reco::SecondaryVertexTagInfoCollection, reco::VertexCollection>>>
0050 assoc(new edm::AssociationMap<edm::OneToMany<reco::SecondaryVertexTagInfoCollection, reco::VertexCollection>>);
0051
0052
0053 reco::VertexRefProd vertexRefProd = event.getRefBeforePut<reco::VertexCollection>();
0054
0055
0056 std::size_t index = 0;
0057
0058
0059 for (std::size_t svIndex = 0; svIndex < svTagInfoCollection->size(); ++svIndex) {
0060
0061 reco::SecondaryVertexTagInfoRef svTagInfo(svTagInfoCollection, svIndex);
0062
0063
0064 for (unsigned int vIndex = 0; vIndex < svTagInfo->nVertices(); ++vIndex) {
0065 proxy->push_back(svTagInfo->secondaryVertex(vIndex));
0066 assoc->insert(svTagInfo, reco::VertexRef(vertexRefProd, index));
0067 ++index;
0068 }
0069 }
0070
0071
0072 event.put(std::move(proxy));
0073 event.put(std::move(assoc));
0074 }
0075
0076
0077 DEFINE_FWK_MODULE(SecondaryVertexTagInfoProxy);