Skip to content

Commit

Permalink
Modernize pythia6 related modules
Browse files Browse the repository at this point in the history
- moved away from legacy module
- added consumes and esConsumes
  • Loading branch information
Dr15Jones committed Oct 13, 2021
1 parent b4ee2fd commit 063acb1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
4 changes: 3 additions & 1 deletion GeneratorInterface/Pythia6Interface/plugins/Pythia6Gun.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//#include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Concurrency/interface/SharedResourceNames.h"

#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
Expand Down Expand Up @@ -45,6 +45,7 @@ Pythia6Gun::Pythia6Gun(const ParameterSet& pset)
throw edm::Exception(edm::errors::Configuration, "PythiaError") << " pythia did not accept MSTU(12)=12345";
}

usesResource(edm::SharedResourceNames::kPythia6);
produces<HepMCProduct>("unsmeared");
}

Expand Down Expand Up @@ -83,6 +84,7 @@ void Pythia6Gun::beginLuminosityBlock(LuminosityBlock const& lumi, EventSetup co
call_pyinit("NONE", "", "", 0.0);
}

void Pythia6Gun::endLuminosityBlock(LuminosityBlock const& lumi, EventSetup const&) {}
void Pythia6Gun::endRun(Run const&, EventSetup const& es) {
// here put in GenRunInfoProduct

Expand Down
6 changes: 4 additions & 2 deletions GeneratorInterface/Pythia6Interface/plugins/Pythia6Gun.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "HepMC/GenEvent.h"

// #include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/one/EDProducer.h"

#include "GeneratorInterface/Pythia6Interface/interface/Pythia6Service.h"
#include "GeneratorInterface/Pythia6Interface/interface/Pythia6Declarations.h"
Expand All @@ -37,12 +37,14 @@ namespace gen {

// class Pythia6Service;

class Pythia6Gun : public edm::EDProducer {
class Pythia6Gun
: public edm::one::EDProducer<edm::one::WatchLuminosityBlocks, edm::one::WatchRuns, edm::one::SharedResources> {
public:
Pythia6Gun(const edm::ParameterSet&);
~Pythia6Gun() override;
void beginJob() override;
void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) final;
void beginRun(edm::Run const&, edm::EventSetup const&) override;
void endRun(edm::Run const&, edm::EventSetup const&) override;
void produce(edm::Event&, const edm::EventSetup&) override;
Expand Down
10 changes: 7 additions & 3 deletions GeneratorInterface/Pythia6Interface/test/BasicGenTester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "TH1.h"

#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
#include "HepPDT/ParticleDataTable.hh"

class BasicGenTester : public edm::EDAnalyzer {
class BasicGenTester : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
public:
//
explicit BasicGenTester(const edm::ParameterSet&);
Expand All @@ -45,6 +45,7 @@ class BasicGenTester : public edm::EDAnalyzer {
double fPtMin;
double fPtMax;
edm::ESHandle<HepPDT::ParticleDataTable> fPDGTable;
edm::ESGetToken<HepPDT::ParticleDataTable, edm::DefaultRecord> fPDGTableToken;
};

using namespace edm;
Expand All @@ -59,6 +60,9 @@ BasicGenTester::BasicGenTester(const ParameterSet& pset)
fNPart = pset.getUntrackedParameter<int>("NPartForHisto", 500);
fPtMin = pset.getUntrackedParameter<double>("PtMinForHisto", 0.);
fPtMax = pset.getUntrackedParameter<double>("PtMaxForHisto", 25.);
usesResource(TFileService::kSharedResource);
fPDGTableToken = esConsumes<edm::Transition::BeginRun>();
consumes<HepMCProduct>(edm::InputTag("VtxSmeared"));
}

void BasicGenTester::beginJob() {
Expand All @@ -82,7 +86,7 @@ void BasicGenTester::beginJob() {
}

void BasicGenTester::beginRun(const edm::Run& r, const edm::EventSetup& es) {
es.getData(fPDGTable);
fPDGTable = es.getHandle(fPDGTableToken);

return;
}
Expand Down
23 changes: 14 additions & 9 deletions GeneratorInterface/Pythia6Interface/test/TauPhotonTester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "TH1.h"

#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
#include "HepPDT/ParticleDataTable.hh"

class TauPhotonTester : public edm::EDAnalyzer {
class TauPhotonTester : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
public:
//
explicit TauPhotonTester(const edm::ParameterSet&);
virtual ~TauPhotonTester() {} // no need to delete ROOT stuff
// as it'll be deleted upon closing TFile
~TauPhotonTester() override {} // no need to delete ROOT stuff
// as it'll be deleted upon closing TFile

virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
virtual void beginJob() override;
virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
virtual void endJob() override;
void analyze(const edm::Event&, const edm::EventSetup&) override;
void beginJob() override;
void beginRun(const edm::Run&, const edm::EventSetup&) override;
void endRun(const edm::Run&, const edm::EventSetup&) override {}
void endJob() override;

private:
int fTauPhotonCounter;
Expand All @@ -39,6 +40,7 @@ class TauPhotonTester : public edm::EDAnalyzer {
TH1D* fPhotonEnergyGt10MeV;
TH1D* fPhotonPtGt10MeV;
edm::ESHandle<HepPDT::ParticleDataTable> fPDGTable;
edm::ESGetToken<HepPDT::ParticleDataTable, edm::DefaultRecord> fPDGTableToken;
int fVerbosity;
};

Expand All @@ -48,6 +50,9 @@ using namespace std;
TauPhotonTester::TauPhotonTester(const ParameterSet& pset)
: fTauPhotonCounter(0), fTauDecPhotonCounter(0), fTauPhotonVtxCounter(0), fVerbosity(0) {
fVerbosity = pset.getUntrackedParameter<int>("Verbosity", 0);
fPDGTableToken = esConsumes<edm::Transition::BeginRun>();
consumes<HepMCProduct>(edm::InputTag("VtxSmeared"));
usesResource(TFileService::kSharedResource);
}

void TauPhotonTester::beginJob() {
Expand All @@ -62,7 +67,7 @@ void TauPhotonTester::beginJob() {
}

void TauPhotonTester::beginRun(const edm::Run& r, const edm::EventSetup& es) {
es.getData(fPDGTable);
fPDGTable = es.getHandle(fPDGTableToken);

return;
}
Expand Down

0 comments on commit 063acb1

Please sign in to comment.