Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rivet consumes migration backport to 75X #10321

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,45 @@
#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 <vector>
#include <string>

namespace edm{
class ParameterSet;
class Event;
class EventSetup;
class InputTag;
}

class RivetAnalyzer : public edm::EDAnalyzer
{
public:
RivetAnalyzer(const edm::ParameterSet&);

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<edm::HepMCProduct> _hepmcCollection;
bool _useExternalWeight;
edm::InputTag _genEventInfoCollection;
edm::EDGetTokenT<GenEventInfoProduct> _genEventInfoCollection;
Rivet::AnalysisHandler _analysisHandler;
bool _isFirstEvent;
std::string _outFileName;
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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<reco::CandidateView> genParticlesToken_;
// edm::InputTag genRunInfoToken_;
edm::EDGetTokenT<GenEventInfoProduct> genEventInfoToken_;
edm::ESHandle<ParticleDataTable> pTable_;

private:
Expand All @@ -58,36 +58,36 @@ class GenParticles2HepMCConverter : public edm::EDProducer

GenParticles2HepMCConverter::GenParticles2HepMCConverter(const edm::ParameterSet& pset)
{
// lheEventLabel_ = pset.getParameter<edm::InputTag>("lheEvent");
genParticlesLabel_ = pset.getParameter<edm::InputTag>("genParticles");
//genRunInfoLabel_ = pset.getParameter<edm::InputTag>("genRunInfo");
genEventInfoLabel_ = pset.getParameter<edm::InputTag>("genEventInfo");
// lheEventToken_ = pset.getParameter<edm::InputTag>("lheEvent");
genParticlesToken_ = consumes<reco::CandidateView>(pset.getParameter<edm::InputTag>("genParticles"));
//genRunInfoToken_ = pset.getParameter<edm::InputTag>("genRunInfo");
genEventInfoToken_ = consumes<GenEventInfoProduct>(pset.getParameter<edm::InputTag>("genEventInfo"));

produces<edm::HepMCProduct>();
}

void GenParticles2HepMCConverter::beginRun(edm::Run& run, const edm::EventSetup& eventSetup)
{
//void GenParticles2HepMCConverter::beginRun(edm::Run& run, const edm::EventSetup& eventSetup)
//{
//edm::Handle<GenRunInfoProduct> 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<LHEEventProduct> lheEventHandle;
// event.getByLabel(lheEventLabel_, lheEventHandle);
// event.getByToken(lheEventToken_, lheEventHandle);

edm::Handle<reco::CandidateView> genParticlesHandle;
event.getByLabel(genParticlesLabel_, genParticlesHandle);
event.getByToken(genParticlesToken_, genParticlesHandle);

edm::Handle<GenEventInfoProduct> genEventInfoHandle;
event.getByLabel(genEventInfoLabel_, genEventInfoHandle);
event.getByToken(genEventInfoToken_, genEventInfoHandle);

eventSetup.getData(pTable_);

Expand Down
19 changes: 5 additions & 14 deletions GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace Rivet;
using namespace edm;

Expand All @@ -32,14 +23,14 @@ _produceDQM(pset.getParameter<bool>("ProduceDQMOutput"))
//retrive the analysis name from paarmeter set
std::vector<std::string> analysisNames = pset.getParameter<std::vector<std::string> >("AnalysisNames");

_hepmcCollection = pset.getParameter<edm::InputTag>("HepMCCollection");
_hepmcCollection = consumes<HepMCProduct>(pset.getParameter<edm::InputTag>("HepMCCollection"));

_useExternalWeight = pset.getParameter<bool>("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<edm::InputTag>("GenEventInfoCollection");
_genEventInfoCollection = consumes<GenEventInfoProduct>(pset.getParameter<edm::InputTag>("GenEventInfoCollection"));
}

//get the analyses
Expand Down Expand Up @@ -88,7 +79,7 @@ void RivetAnalyzer::analyze(const edm::Event& iEvent,const edm::EventSetup& iSet

//get the hepmc product from the event
edm::Handle<HepMCProduct> evt;
iEvent.getByLabel(_hepmcCollection, evt);
iEvent.getByToken(_hepmcCollection, evt);

// get HepMC GenEvent
const HepMC::GenEvent *myGenEvent = evt->GetEvent();
Expand All @@ -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> genEventInfoProduct;
iEvent.getByLabel(_genEventInfoCollection, genEventInfoProduct);
iEvent.getByToken(_genEventInfoCollection, genEventInfoProduct);
tmpGenEvtPtr->weights()[0] = genEventInfoProduct->weight();
myGenEvent = tmpGenEvtPtr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

generator = cms.EDProducer("GenParticles2HepMCConverter",
genParticles = cms.InputTag("genParticles"),
genEventInfo = cms.InputTag("generator"),
genEventInfo = cms.InputTag("generator", "", "SIM"),
)