Skip to content

Commit

Permalink
Merge pull request #14719 from mandrenguyen/consumesHiGenCommon81X
Browse files Browse the repository at this point in the history
Consumes migration and GenHIEventProducer forward port from 75X
  • Loading branch information
davidlange6 authored Jun 24, 2016
2 parents 804c01b + 247a1f4 commit dba7074
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"

#include "CLHEP/Random/RandGaussQ.h"
Expand Down Expand Up @@ -102,15 +104,15 @@ class BetaBoostEvtVtxGenerator : public edm::EDProducer{
TMatrixD *boost_;
double fTimeOffset;

edm::InputTag sourceLabel;
edm::EDGetTokenT<HepMCProduct> sourceLabel;

bool verbosity_;
};


BetaBoostEvtVtxGenerator::BetaBoostEvtVtxGenerator(const edm::ParameterSet & p ):
BetaBoostEvtVtxGenerator::BetaBoostEvtVtxGenerator(const edm::ParameterSet & p):
fVertex(0), boost_(0), fTimeOffset(0),
sourceLabel(p.getParameter<edm::InputTag>("src")),
sourceLabel(consumes<HepMCProduct>(p.getParameter<edm::InputTag>("src"))),
verbosity_(p.getUntrackedParameter<bool>("verbosity",false))
{
fX0 = p.getParameter<double>("X0")*cm;
Expand Down Expand Up @@ -261,8 +263,8 @@ void BetaBoostEvtVtxGenerator::produce( Event& evt, const EventSetup& )
CLHEP::HepRandomEngine* engine = &rng->getEngine(evt.streamID());

Handle<HepMCProduct> HepUnsmearedMCEvt;
evt.getByLabel(sourceLabel, HepUnsmearedMCEvt);
evt.getByToken(sourceLabel, HepUnsmearedMCEvt);

// Copy the HepMC::GenEvent
HepMC::GenEvent* genevt = new HepMC::GenEvent(*HepUnsmearedMCEvt->GetEvent());
std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(genevt));
Expand All @@ -275,6 +277,7 @@ void BetaBoostEvtVtxGenerator::produce( Event& evt, const EventSetup& )
HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
evt.put(std::move(HepMCEvt));

return ;
}

Expand Down
24 changes: 16 additions & 8 deletions GeneratorInterface/HiGenCommon/plugins/GenHIEventProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Description: <one line class summary>

#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
#include "SimDataFormats/HiGenData/interface/GenHIEvent.h"
#include "SimDataFormats/CrossingFrame/interface/MixCollection.h"

#include "HepMC/HeavyIon.h"
#include "FWCore/Framework/interface/ESHandle.h"
Expand All @@ -52,7 +53,7 @@ class GenHIEventProducer : public edm::EDProducer {

private:
virtual void produce(edm::Event&, const edm::EventSetup&) override;
std::vector<std::string> hepmcSrc_;
edm::EDGetTokenT<CrossingFrame<edm::HepMCProduct> > hepmcSrc_;
edm::ESHandle < ParticleDataTable > pdt;

double ptCut_;
Expand All @@ -74,10 +75,10 @@ class GenHIEventProducer : public edm::EDProducer {
GenHIEventProducer::GenHIEventProducer(const edm::ParameterSet& iConfig)
{
produces<edm::GenHIEvent>();
hepmcSrc_ = iConfig.getParameter<std::vector<std::string> >("generators");
hepmcSrc_ = consumes<CrossingFrame<edm::HepMCProduct> >(iConfig.getParameter<edm::InputTag>("src"));
doParticleInfo_ = iConfig.getUntrackedParameter<bool>("doParticleInfo",false);
if(doParticleInfo_){
ptCut_ = iConfig.getUntrackedParameter<double> ("ptCut",1.);
ptCut_ = iConfig.getParameter<double> ("ptCut");
}
}

Expand Down Expand Up @@ -120,11 +121,18 @@ GenHIEventProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
double EtMR = 0; // Normalized of total energy bym
double TotEnergy = 0; // Total energy bym

for(size_t ihep = 0; ihep < hepmcSrc_.size(); ++ihep){
Handle<edm::HepMCProduct> hepmc;
iEvent.getByLabel(hepmcSrc_[ihep],hepmc);
Handle<CrossingFrame<edm::HepMCProduct> > hepmc;
iEvent.getByToken(hepmcSrc_,hepmc);
MixCollection<HepMCProduct> mix(hepmc.product());

if(mix.size() < 1){
throw cms::Exception("MatchVtx")
<<"Mixing has "<<mix.size()<<" sub-events, should have been at least 1"
<<endl;
}

const HepMC::GenEvent* evt = hepmc->GetEvent();
const HepMCProduct& hievt = mix.getObject(mix.size()-1);
const HepMC::GenEvent* evt = hievt.GetEvent();
if(doParticleInfo_){
HepMC::GenEvent::particle_const_iterator begin = evt->particles_begin();
HepMC::GenEvent::particle_const_iterator end = evt->particles_end();
Expand Down Expand Up @@ -171,7 +179,7 @@ GenHIEventProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
ecc = hi->eccentricity();
}
}
}

// Get the normalized total energy bym
if(TotEnergy != 0){
EtMR = TotEnergy/2;
Expand Down
11 changes: 6 additions & 5 deletions GeneratorInterface/HiGenCommon/plugins/HiCentralityBiasFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"

Expand Down Expand Up @@ -57,7 +58,7 @@ class HiCentralityBiasFilter : public edm::EDFilter {
virtual bool filter(edm::Event&, const edm::EventSetup&) override;
virtual void endJob() override ;

edm::InputTag hepmcSrc_;
edm::EDGetTokenT<edm::HepMCProduct> hepmcSrc_;

edm::Service<edm::RandomNumberGenerator> rng_;

Expand All @@ -81,9 +82,9 @@ class HiCentralityBiasFilter : public edm::EDFilter {
HiCentralityBiasFilter::HiCentralityBiasFilter(const edm::ParameterSet& iConfig)
{
//now do what ever initialization is needed
hepmcSrc_ = iConfig.getUntrackedParameter<edm::InputTag>("src", edm::InputTag("generatorSmeared"));
func_ = iConfig.getParameter<string>("function");
par_ = iConfig.getParameter<vector<double> >("parameters");
hepmcSrc_ = consumes<edm::HepMCProduct>(iConfig.getParameter< edm::InputTag > ("generatorSmeared"));
func_ = iConfig.getParameter<string>("function");
par_ = iConfig.getParameter<vector<double> >("parameters");
}


Expand Down Expand Up @@ -111,7 +112,7 @@ HiCentralityBiasFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup
CLHEP::HepRandomEngine& engine = rng_->getEngine(iEvent.streamID());

Handle<HepMCProduct> mc;
iEvent.getByLabel(hepmcSrc_,mc);
iEvent.getByToken(hepmcSrc_,mc);
const HepMC::GenEvent* evt = mc->GetEvent();

const HepMC::HeavyIon* hi = evt->heavy_ion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class HighMultiplicityGenFilter : public edm::EDFilter {

// ----------member data ---------------------------
edm::ESHandle <ParticleDataTable> pdt;
edm::EDGetTokenT<edm::HepMCProduct> hepmcSrc;
double etaMax;
double ptMin;
int nMin;
Expand All @@ -64,9 +65,10 @@ class HighMultiplicityGenFilter : public edm::EDFilter {
// constructors and destructor
//
HighMultiplicityGenFilter::HighMultiplicityGenFilter(const edm::ParameterSet& iConfig) :
etaMax(iConfig.getUntrackedParameter<double>("etaMax")),
ptMin(iConfig.getUntrackedParameter<double>("ptMin")),
nMin(iConfig.getUntrackedParameter<int>("nMin"))
hepmcSrc(consumes<edm::HepMCProduct>(iConfig.getParameter< edm::InputTag > ("generatorSmeared"))),
etaMax(iConfig.getUntrackedParameter<double>("etaMax")),
ptMin(iConfig.getUntrackedParameter<double>("ptMin")),
nMin(iConfig.getUntrackedParameter<int>("nMin"))
{
//now do what ever initialization is needed
nAccepted = 0;
Expand All @@ -93,7 +95,7 @@ HighMultiplicityGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSe

bool accepted = false;
edm::Handle<edm::HepMCProduct> evt;
iEvent.getByLabel("generatorSmeared", evt);
iEvent.getByToken(hepmcSrc,evt);

iSetup.getData(pdt);

Expand Down
35 changes: 23 additions & 12 deletions GeneratorInterface/HiGenCommon/plugins/MixBoostEvtVtxGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ ________________________________________________________________________

#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
Expand Down Expand Up @@ -102,22 +104,21 @@ class MixBoostEvtVtxGenerator : public edm::EDProducer{
TMatrixD *boost_;
double fTimeOffset;

edm::InputTag sourceLabel;

CLHEP::RandGaussQ* fRandom ;

edm::InputTag signalLabel;
edm::InputTag hiLabel;
edm::EDGetTokenT<reco::VertexCollection> vtxLabel;
edm::EDGetTokenT<HepMCProduct> signalLabel;
edm::EDGetTokenT<CrossingFrame<HepMCProduct> > mixLabel;
bool useRecVertex;
std::vector<double> vtxOffset;

};


MixBoostEvtVtxGenerator::MixBoostEvtVtxGenerator(const edm::ParameterSet & pset ):
fVertex(0), boost_(0), fTimeOffset(0),
signalLabel(pset.getParameter<edm::InputTag>("signalLabel")),
hiLabel(pset.getParameter<edm::InputTag>("heavyIonLabel")),
vtxLabel(mayConsume<reco::VertexCollection>(pset.getParameter<edm::InputTag>("vtxLabel"))),
signalLabel(consumes<HepMCProduct>(pset.getParameter<edm::InputTag>("signalLabel"))),
mixLabel(consumes<CrossingFrame<HepMCProduct> >(pset.getParameter<edm::InputTag>("mixLabel"))),
useRecVertex(pset.exists("useRecVertex")?pset.getParameter<bool>("useRecVertex"):false)
{

Expand Down Expand Up @@ -249,10 +250,19 @@ TMatrixD* MixBoostEvtVtxGenerator::GetInvLorentzBoost() {

HepMC::FourVector* MixBoostEvtVtxGenerator::getVertex( Event& evt){

Handle<HepMCProduct> input;
evt.getByLabel(hiLabel,input);
const HepMC::GenEvent* inev = 0;

Handle<CrossingFrame<HepMCProduct> > cf;
evt.getByToken(mixLabel,cf);
MixCollection<HepMCProduct> mix(cf.product());

const HepMCProduct& bkg = mix.getObject(1);
if(!(bkg.isVtxGenApplied())){
throw cms::Exception("MatchVtx")<<"Input background does not have smeared vertex!"<<endl;
}else{
inev = bkg.GetEvent();
}

const HepMC::GenEvent* inev = input->GetEvent();
HepMC::GenVertex* genvtx = inev->signal_process_vertex();
if(!genvtx){
cout<<"No Signal Process Vertex!"<<endl;
Expand Down Expand Up @@ -282,8 +292,9 @@ HepMC::FourVector* MixBoostEvtVtxGenerator::getVertex( Event& evt){

HepMC::FourVector* MixBoostEvtVtxGenerator::getRecVertex( Event& evt){


Handle<reco::VertexCollection> input;
evt.getByLabel(hiLabel,input);
evt.getByToken(vtxLabel,input);

double aX,aY,aZ;

Expand All @@ -302,7 +313,7 @@ HepMC::FourVector* MixBoostEvtVtxGenerator::getRecVertex( Event& evt){
void MixBoostEvtVtxGenerator::produce( Event& evt, const EventSetup& )
{
Handle<HepMCProduct> HepUnsmearedMCEvt;
evt.getByLabel(signalLabel, HepUnsmearedMCEvt);
evt.getByToken(signalLabel, HepUnsmearedMCEvt);

// Copy the HepMC::GenEvent
HepMC::GenEvent* genevt = new HepMC::GenEvent(*HepUnsmearedMCEvt->GetEvent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
useCF = cms.untracked.bool(True),
signalLabel = cms.InputTag("generator","unsmeared"),
mixLabel = cms.InputTag("mix","generatorSmeared"),
vtxLabel = cms.InputTag("offlinePrimaryVertices"),
Beta=cms.double(0.434)
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
useCF = cms.untracked.bool(True),
signalLabel = cms.InputTag("generator","unsmeared"),
mixLabel = cms.InputTag("mix","generatorSmeared"),
vtxLabel = cms.InputTag("offlinePrimaryVertices"),
Beta=cms.double(-0.434)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
VtxSmeared = cms.EDProducer("MixEvtVtxGenerator",
useCF = cms.untracked.bool(True),
signalLabel = cms.InputTag("generator","unsmeared"),
mixLabel = cms.InputTag("mix","generatorSmeared")
mixLabel = cms.InputTag("mix","generatorSmeared"),
vtxLabel = cms.InputTag("offlinePrimaryVertices")
)

0 comments on commit dba7074

Please sign in to comment.