From 030333036910623006124425fc2aea8a2d79ccf7 Mon Sep 17 00:00:00 2001 From: Junghwan John Goh Date: Wed, 22 Jul 2015 23:55:30 +0200 Subject: [PATCH 1/3] migrate to getByToken, stream module --- .../plugins/GenParticles2HepMCConverter.cc | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/GeneratorInterface/RivetInterface/plugins/GenParticles2HepMCConverter.cc b/GeneratorInterface/RivetInterface/plugins/GenParticles2HepMCConverter.cc index 581f7369db7a6..71909e17f65d0 100644 --- a/GeneratorInterface/RivetInterface/plugins/GenParticles2HepMCConverter.cc +++ b/GeneratorInterface/RivetInterface/plugins/GenParticles2HepMCConverter.cc @@ -1,5 +1,5 @@ #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/EventSetup.h" @@ -25,20 +25,20 @@ using namespace std; -class GenParticles2HepMCConverter : public edm::EDProducer +class GenParticles2HepMCConverter : public edm::stream::EDProducer<> { public: explicit GenParticles2HepMCConverter(const edm::ParameterSet& pset); ~GenParticles2HepMCConverter() {}; - void beginRun(edm::Run& run, const edm::EventSetup& eventSetup); - void produce(edm::Event& event, const edm::EventSetup& eventSetup); + //void beginRun(const edm::Run& run, const edm::EventSetup& eventSetup) override; + void produce(edm::Event& event, const edm::EventSetup& eventSetup) override; private: -// edm::InputTag lheEventLabel_; - edm::InputTag genParticlesLabel_; -// edm::InputTag genRunInfoLabel_; - edm::InputTag genEventInfoLabel_; +// edm::InputTag lheEventToken_; + edm::EDGetTokenT genParticlesToken_; +// edm::InputTag genRunInfoToken_; + edm::EDGetTokenT genEventInfoToken_; edm::ESHandle pTable_; private: @@ -58,36 +58,36 @@ class GenParticles2HepMCConverter : public edm::EDProducer GenParticles2HepMCConverter::GenParticles2HepMCConverter(const edm::ParameterSet& pset) { -// lheEventLabel_ = pset.getParameter("lheEvent"); - genParticlesLabel_ = pset.getParameter("genParticles"); - //genRunInfoLabel_ = pset.getParameter("genRunInfo"); - genEventInfoLabel_ = pset.getParameter("genEventInfo"); +// lheEventToken_ = pset.getParameter("lheEvent"); + genParticlesToken_ = consumes(pset.getParameter("genParticles")); + //genRunInfoToken_ = pset.getParameter("genRunInfo"); + genEventInfoToken_ = consumes(pset.getParameter("genEventInfo")); produces(); } -void GenParticles2HepMCConverter::beginRun(edm::Run& run, const edm::EventSetup& eventSetup) -{ +//void GenParticles2HepMCConverter::beginRun(edm::Run& run, const edm::EventSetup& eventSetup) +//{ //edm::Handle genRunInfoHandle; - //event.getByLabel(genRunInfoLabel_, genRunInfoHandle); + //event.getByToken(genRunInfoToken_, genRunInfoHandle); // const double xsecIn = genRunInfoHandle->internalXSec().value(); // const double xsecInErr = genRunInfoHandle->internalXSec().error(); // const double xsecLO = genRunInfoHandle->externalXSecLO().value(); // const double xsecLOErr = genRunInfoHandle->externalXSecLO().error(); // const double xsecNLO = genRunInfoHandle->externalXSecNLO().value(); // const double xsecNLOErr = genRunInfoHandle->externalXSecNLO().error(); -} +//} void GenParticles2HepMCConverter::produce(edm::Event& event, const edm::EventSetup& eventSetup) { // edm::Handle lheEventHandle; -// event.getByLabel(lheEventLabel_, lheEventHandle); +// event.getByToken(lheEventToken_, lheEventHandle); edm::Handle genParticlesHandle; - event.getByLabel(genParticlesLabel_, genParticlesHandle); + event.getByToken(genParticlesToken_, genParticlesHandle); edm::Handle genEventInfoHandle; - event.getByLabel(genEventInfoLabel_, genEventInfoHandle); + event.getByToken(genEventInfoToken_, genEventInfoHandle); eventSetup.getData(pTable_); From 18cfbd5c85d10ba3e9936ed81cf0c19d733edf02 Mon Sep 17 00:00:00 2001 From: Junghwan John Goh Date: Thu, 23 Jul 2015 02:40:23 +0200 Subject: [PATCH 2/3] consumes migration + cleanup of RivetAnalyzer --- .../RivetInterface/interface/RivetAnalyzer.h | 29 +++++++------------ .../RivetInterface/plugins/RivetAnalyzer.cc | 19 ++++-------- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h b/GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h index 037ba5c6aa68c..7e752257b9618 100644 --- a/GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h +++ b/GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h @@ -2,28 +2,21 @@ #define GeneratorInterface_RivetInterface_RivetAnalyzer #include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Utilities/interface/InputTag.h" #include "Rivet/AnalysisHandler.hh" //DQM services #include "DQMServices/Core/interface/DQMStore.h" -#include "FWCore/ServiceRegistry/interface/Service.h" #include "DQMServices/Core/interface/MonitorElement.h" -#include "Rivet/Tools/RivetYODA.hh" -#include "YODA/ROOTCnv.h" +#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" +#include "Rivet/Tools/RivetYODA.hh" +//#include "YODA/ROOTCnv.h" #include #include -namespace edm{ - class ParameterSet; - class Event; - class EventSetup; - class InputTag; -} - class RivetAnalyzer : public edm::EDAnalyzer { public: @@ -31,23 +24,23 @@ class RivetAnalyzer : public edm::EDAnalyzer virtual ~RivetAnalyzer(); - virtual void beginJob(); + virtual void beginJob() override; - virtual void endJob(); + virtual void endJob() override; - virtual void analyze(const edm::Event&, const edm::EventSetup&); + virtual void analyze(const edm::Event&, const edm::EventSetup&) override; - virtual void beginRun(const edm::Run&, const edm::EventSetup&); + virtual void beginRun(const edm::Run&, const edm::EventSetup&) override; - virtual void endRun(const edm::Run&, const edm::EventSetup&); + virtual void endRun(const edm::Run&, const edm::EventSetup&) override; private: void normalizeTree(); - edm::InputTag _hepmcCollection; + edm::EDGetTokenT _hepmcCollection; bool _useExternalWeight; - edm::InputTag _genEventInfoCollection; + edm::EDGetTokenT _genEventInfoCollection; Rivet::AnalysisHandler _analysisHandler; bool _isFirstEvent; std::string _outFileName; diff --git a/GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc b/GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc index b02c7175d3211..40d57b2ce5399 100644 --- a/GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc +++ b/GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc @@ -1,22 +1,13 @@ #include "GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h" #include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/MakerMacros.h" -#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" -#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" -#include "DataFormats/Common/interface/Handle.h" +#include "FWCore/ServiceRegistry/interface/Service.h" #include "Rivet/AnalysisHandler.hh" #include "Rivet/Analysis.hh" -#include -#include -#include -#include -#include - using namespace Rivet; using namespace edm; @@ -32,14 +23,14 @@ _produceDQM(pset.getParameter("ProduceDQMOutput")) //retrive the analysis name from paarmeter set std::vector analysisNames = pset.getParameter >("AnalysisNames"); - _hepmcCollection = pset.getParameter("HepMCCollection"); + _hepmcCollection = consumes(pset.getParameter("HepMCCollection")); _useExternalWeight = pset.getParameter("UseExternalWeight"); if (_useExternalWeight) { if (!pset.exists("GenEventInfoCollection")){ throw cms::Exception("RivetAnalyzer") << "when using an external event weight you have to specify the GenEventInfoProduct collection from which the weight has to be taken " ; } - _genEventInfoCollection = pset.getParameter("GenEventInfoCollection"); + _genEventInfoCollection = consumes(pset.getParameter("GenEventInfoCollection")); } //get the analyses @@ -88,7 +79,7 @@ void RivetAnalyzer::analyze(const edm::Event& iEvent,const edm::EventSetup& iSet //get the hepmc product from the event edm::Handle evt; - iEvent.getByLabel(_hepmcCollection, evt); + iEvent.getByToken(_hepmcCollection, evt); // get HepMC GenEvent const HepMC::GenEvent *myGenEvent = evt->GetEvent(); @@ -102,7 +93,7 @@ void RivetAnalyzer::analyze(const edm::Event& iEvent,const edm::EventSetup& iSet edm::LogWarning("RivetAnalyzer") << "Original event weight size is " << tmpGenEvtPtr->weights().size() << ". Will change only the first one "; } edm::Handle genEventInfoProduct; - iEvent.getByLabel(_genEventInfoCollection, genEventInfoProduct); + iEvent.getByToken(_genEventInfoCollection, genEventInfoProduct); tmpGenEvtPtr->weights()[0] = genEventInfoProduct->weight(); myGenEvent = tmpGenEvtPtr; } From 8182a24c703b4c4a5ec406aa6fcb826a7c9127da Mon Sep 17 00:00:00 2001 From: Junghwan John Goh Date: Thu, 23 Jul 2015 02:41:39 +0200 Subject: [PATCH 3/3] read geninfo from generator::SIM to avoid framework error --- .../RivetInterface/python/genParticles2HepMC_cfi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GeneratorInterface/RivetInterface/python/genParticles2HepMC_cfi.py b/GeneratorInterface/RivetInterface/python/genParticles2HepMC_cfi.py index 7a355acb73bc5..464f1fb01f64f 100644 --- a/GeneratorInterface/RivetInterface/python/genParticles2HepMC_cfi.py +++ b/GeneratorInterface/RivetInterface/python/genParticles2HepMC_cfi.py @@ -2,5 +2,5 @@ generator = cms.EDProducer("GenParticles2HepMCConverter", genParticles = cms.InputTag("genParticles"), - genEventInfo = cms.InputTag("generator"), + genEventInfo = cms.InputTag("generator", "", "SIM"), )