File indexing completed on 2024-04-06 12:23:47
0001
0002
0003
0004
0005
0006
0007
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/stream/EDProducer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "DataFormats/Common/interface/Association.h"
0013 #include "DataFormats/Common/interface/RefToPtr.h"
0014
0015 #include "DataFormats/JetReco/interface/Jet.h"
0016 #include "DataFormats/JetReco/interface/JetCollection.h"
0017 #include "DataFormats/JetMatching/interface/JetFlavourInfo.h"
0018 #include "DataFormats/JetMatching/interface/JetFlavourInfoMatching.h"
0019
0020 #include "DataFormats/JetReco/interface/GenJet.h"
0021 #include "DataFormats/JetReco/interface/GenJetCollection.h"
0022
0023 namespace pat {
0024
0025 class GenJetFlavourInfoPreserver : public edm::stream::EDProducer<> {
0026 public:
0027 explicit GenJetFlavourInfoPreserver(const edm::ParameterSet& iConfig);
0028 ~GenJetFlavourInfoPreserver() override {}
0029
0030 void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0031
0032 private:
0033 const edm::EDGetTokenT<edm::View<reco::GenJet> > genJetsToken_;
0034 const edm::EDGetTokenT<edm::View<reco::Jet> > slimmedGenJetsToken_;
0035
0036 const edm::EDGetTokenT<reco::JetFlavourInfoMatchingCollection> genJetFlavourInfosToken_;
0037 const edm::EDGetTokenT<edm::Association<std::vector<reco::GenJet> > > slimmedGenJetAssociationToken_;
0038 };
0039
0040 }
0041
0042 pat::GenJetFlavourInfoPreserver::GenJetFlavourInfoPreserver(const edm::ParameterSet& iConfig)
0043 : genJetsToken_(consumes<edm::View<reco::GenJet> >(iConfig.getParameter<edm::InputTag>("genJets"))),
0044 slimmedGenJetsToken_(consumes<edm::View<reco::Jet> >(iConfig.getParameter<edm::InputTag>("slimmedGenJets"))),
0045 genJetFlavourInfosToken_(
0046 consumes<reco::JetFlavourInfoMatchingCollection>(iConfig.getParameter<edm::InputTag>("genJetFlavourInfos"))),
0047 slimmedGenJetAssociationToken_(consumes<edm::Association<std::vector<reco::GenJet> > >(
0048 iConfig.getParameter<edm::InputTag>("slimmedGenJetAssociation"))) {
0049 produces<reco::JetFlavourInfoMatchingCollection>();
0050 }
0051
0052 void pat::GenJetFlavourInfoPreserver::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0053 using namespace edm;
0054 using namespace std;
0055
0056 Handle<View<reco::GenJet> > genJets;
0057 iEvent.getByToken(genJetsToken_, genJets);
0058
0059 Handle<View<reco::Jet> > slimmedGenJets;
0060 iEvent.getByToken(slimmedGenJetsToken_, slimmedGenJets);
0061
0062 Handle<reco::JetFlavourInfoMatchingCollection> genJetFlavourInfos;
0063 iEvent.getByToken(genJetFlavourInfosToken_, genJetFlavourInfos);
0064
0065 Handle<edm::Association<std::vector<reco::GenJet> > > slimmedGenJetAssociation;
0066 iEvent.getByToken(slimmedGenJetAssociationToken_, slimmedGenJetAssociation);
0067
0068 auto jetFlavourInfos = std::make_unique<reco::JetFlavourInfoMatchingCollection>(reco::JetRefBaseProd(slimmedGenJets));
0069 assert(genJets->size() == genJetFlavourInfos->size());
0070
0071 edm::Ref<std::vector<reco::GenJet> > slimmedGenJetRef;
0072
0073 for (unsigned int i = 0; i < genJets->size(); ++i) {
0074 slimmedGenJetRef = (*slimmedGenJetAssociation)[genJets->refAt(i)];
0075 if (!slimmedGenJetRef)
0076 continue;
0077 (*jetFlavourInfos)[reco::JetBaseRef(slimmedGenJetRef)] = (*genJetFlavourInfos)[i].second;
0078 }
0079
0080 iEvent.put(std::move(jetFlavourInfos));
0081 }
0082
0083 #include "FWCore/Framework/interface/MakerMacros.h"
0084 using namespace pat;
0085 DEFINE_FWK_MODULE(GenJetFlavourInfoPreserver);