File indexing completed on 2024-04-06 12:23:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include "FWCore/Framework/interface/stream/EDProducer.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019
0020 #include "DataFormats/Common/interface/ValueMap.h"
0021 #include "DataFormats/Common/interface/View.h"
0022 #include "DataFormats/PatCandidates/interface/Vertexing.h"
0023 #include "PhysicsTools/PatAlgos/interface/VertexingHelper.h"
0024
0025 namespace pat {
0026
0027 class PATVertexAssociationProducer : public edm::stream::EDProducer<> {
0028 typedef edm::ValueMap<pat::VertexAssociation> VertexAssociationMap;
0029
0030 public:
0031 explicit PATVertexAssociationProducer(const edm::ParameterSet& iConfig);
0032 ~PATVertexAssociationProducer() override;
0033
0034 void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0035
0036 private:
0037 typedef std::vector<edm::InputTag> VInputTag;
0038
0039 std::vector<edm::InputTag> particles_;
0040 std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > > particlesTokens_;
0041 pat::helper::VertexingHelper vertexing_;
0042 };
0043
0044 }
0045
0046 using pat::PATVertexAssociationProducer;
0047
0048 PATVertexAssociationProducer::PATVertexAssociationProducer(const edm::ParameterSet& iConfig)
0049 : particles_(iConfig.existsAs<VInputTag>("candidates")
0050 ?
0051 iConfig.getParameter<VInputTag>("candidates")
0052 : VInputTag(1, iConfig.getParameter<edm::InputTag>("candidates"))),
0053 vertexing_(iConfig, consumesCollector()) {
0054 for (VInputTag::const_iterator it = particles_.begin(), end = particles_.end(); it != end; ++it) {
0055 particlesTokens_.push_back(consumes<edm::View<reco::Candidate> >(*it));
0056 }
0057 produces<VertexAssociationMap>();
0058 }
0059
0060 PATVertexAssociationProducer::~PATVertexAssociationProducer() {}
0061
0062 void PATVertexAssociationProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0063 using namespace edm;
0064 using namespace std;
0065
0066 vertexing_.newEvent(iEvent, iSetup);
0067
0068
0069 auto result = std::make_unique<VertexAssociationMap>();
0070 VertexAssociationMap::Filler filler(*result);
0071 vector<pat::VertexAssociation> assos;
0072
0073
0074 for (std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > >::const_iterator it = particlesTokens_.begin(),
0075 end = particlesTokens_.end();
0076 it != end;
0077 ++it) {
0078
0079 Handle<View<reco::Candidate> > cands;
0080 iEvent.getByToken(*it, cands);
0081 assos.clear();
0082 assos.reserve(cands->size());
0083
0084 for (size_t i = 0, n = cands->size(); i < n; ++i) {
0085 assos.push_back(vertexing_(cands->refAt(i)));
0086 }
0087
0088 filler.insert(cands, assos.begin(), assos.end());
0089 }
0090
0091
0092 filler.fill();
0093
0094
0095 iEvent.put(std::move(result));
0096 }
0097
0098 #include "FWCore/Framework/interface/MakerMacros.h"
0099
0100 DEFINE_FWK_MODULE(PATVertexAssociationProducer);