Skip to content

Commit

Permalink
Merge pull request #10320 from jhgoh/RivetConsumesMigration76
Browse files Browse the repository at this point in the history
RivetAnalyzer consumes migration 76X
  • Loading branch information
davidlange6 committed Oct 19, 2015
2 parents 3bbe62a + 80e0b20 commit cc1eca9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 36 deletions.
32 changes: 13 additions & 19 deletions GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,49 @@
#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 "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.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;
bool _useLHEweights;
int _LHEweightNumber;
edm::InputTag _LHECollection;
edm::InputTag _genEventInfoCollection;
edm::EDGetTokenT<LHEEventProduct> _LHECollection;
edm::EDGetTokenT<GenEventInfoProduct> _genEventInfoCollection;
Rivet::AnalysisHandler _analysisHandler;
bool _isFirstEvent;
std::string _outFileName;
Expand Down
23 changes: 7 additions & 16 deletions GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
#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 "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.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 @@ -33,15 +24,15 @@ _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");
_LHECollection = pset.getParameter<edm::InputTag>("LHECollection");
_genEventInfoCollection = consumes<GenEventInfoProduct>(pset.getParameter<edm::InputTag>("GenEventInfoCollection"));
_LHECollection = consumes<LHEEventProduct>(pset.getParameter<edm::InputTag>("LHECollection"));
_useLHEweights = pset.getParameter<bool>("useLHEweights");
_LHEweightNumber = pset.getParameter<int>("LHEweightNumber");

Expand Down Expand Up @@ -93,7 +84,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 @@ -111,11 +102,11 @@ void RivetAnalyzer::analyze(const edm::Event& iEvent,const edm::EventSetup& iSet

if(!_useLHEweights){
edm::Handle<GenEventInfoProduct> genEventInfoProduct;
iEvent.getByLabel(_genEventInfoCollection, genEventInfoProduct);
iEvent.getByToken(_genEventInfoCollection, genEventInfoProduct);
tmpGenEvtPtr->weights()[0] = genEventInfoProduct->weight();
}else{
edm::Handle<LHEEventProduct> lheEventHandle;
iEvent.getByLabel(_LHECollection,lheEventHandle);
iEvent.getByToken(_LHECollection,lheEventHandle);
const LHEEventProduct::WGT& wgt = lheEventHandle->weights().at(_LHEweightNumber);
tmpGenEvtPtr->weights()[0] = wgt.wgt;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FWCore.ParameterSet.Config as cms

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

0 comments on commit cc1eca9

Please sign in to comment.