Skip to content

Commit

Permalink
Beam divergence vertex generator cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
forthommel authored and jan-kaspar committed Jan 31, 2019
1 parent cd8d74a commit 3565983
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class BeamDivergenceVtxGenerator : public edm::stream::EDProducer<>
{
public:
explicit BeamDivergenceVtxGenerator(const edm::ParameterSet&);
~BeamDivergenceVtxGenerator() = default;

~BeamDivergenceVtxGenerator() {}
static void fillDescriptions(edm::ConfigurationDescriptions&);

void produce(edm::Event&, const edm::EventSetup&) override;

Expand All @@ -40,3 +41,4 @@ class BeamDivergenceVtxGenerator : public edm::stream::EDProducer<>
};

#endif

This file was deleted.

41 changes: 25 additions & 16 deletions IOMC/EventVertexGenerators/src/BeamDivergenceVtxGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/RandomNumberGenerator.h"

Expand All @@ -19,27 +20,25 @@
//----------------------------------------------------------------------------------------------------

BeamDivergenceVtxGenerator::BeamDivergenceVtxGenerator(const edm::ParameterSet& iConfig) :
sourceToken_( consumes<edm::HepMCProduct>( iConfig.getParameter<edm::InputTag>( "src" ) ) ),

simulateVertex_ ( iConfig.getParameter<bool>( "simulateVertex" ) ),
simulateBeamDivergence_ ( iConfig.getParameter<bool>( "simulateBeamDivergence" ) )
sourceToken_(consumes<edm::HepMCProduct>( iConfig.getParameter<edm::InputTag>("src"))),
simulateVertex_ (iConfig.getParameter<bool>("simulateVertex")),
simulateBeamDivergence_(iConfig.getParameter<bool>("simulateBeamDivergence"))
{
edm::Service<edm::RandomNumberGenerator> rng;
if ( !rng.isAvailable() )
{
if (!rng.isAvailable())
throw cms::Exception("Configuration")
<< "The BeamDivergenceVtxGenerator requires the RandomNumberGeneratorService\n"
"which is not present in the configuration file. \n"
"which is not present in the configuration file. \n"
"You must add the service\n"
"in the configuration file or remove the modules that require it.";
}

produces<edm::HepMCProduct>();
}

//----------------------------------------------------------------------------------------------------

void BeamDivergenceVtxGenerator::produce(edm::Event& iEvent, const edm::EventSetup &iSetup)
void
BeamDivergenceVtxGenerator::produce(edm::Event& iEvent, const edm::EventSetup &iSetup)
{
// get random engine
edm::Service<edm::RandomNumberGenerator> rng;
Expand All @@ -58,8 +57,7 @@ void BeamDivergenceVtxGenerator::produce(edm::Event& iEvent, const edm::EventSet
std::unique_ptr<edm::HepMCProduct> pEvent(new edm::HepMCProduct(genevt));

// apply vertex smearing
if (simulateVertex_)
{
if (simulateVertex_) {
// NB: the separtion between effective offsets in LHC sectors 45 and 56 cannot be applied, thus the values for 45 are used
const double vtx_x = hBeamParameters->getVtxOffsetX45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevX();
const double vtx_y = hBeamParameters->getVtxOffsetY45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevY();
Expand All @@ -70,16 +68,14 @@ void BeamDivergenceVtxGenerator::produce(edm::Event& iEvent, const edm::EventSet
}

// apply beam divergence
if (simulateBeamDivergence_)
{
if (simulateBeamDivergence_) {
const double bd_x_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX45();
const double bd_x_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX56();

const double bd_y_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY45();
const double bd_y_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY56();

for (HepMC::GenEvent::particle_iterator part = genevt->particles_begin(); part != genevt->particles_end(); ++part)
{
for (HepMC::GenEvent::particle_iterator part = genevt->particles_begin(); part != genevt->particles_end(); ++part) {
const HepMC::FourVector mom = (*part)->momentum();

// TODO: this is an oversimplified implemetation
Expand Down Expand Up @@ -109,3 +105,16 @@ void BeamDivergenceVtxGenerator::produce(edm::Event& iEvent, const edm::EventSet
// save output
iEvent.put(std::move(pEvent));
}

void
BeamDivergenceVtxGenerator::fillDescriptions(edm::ConfigurationDescriptions& descriptions)
{
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("src", edm::InputTag("generator", "unsmeared"))
->setComment("input collection where to retrieve outgoing particles kinematics to be smeared");
desc.add<bool>("simulateBeamDivergence", true)->setComment("account for the beam angular divergence?");
desc.add<bool>("simulateVertex", true)->setComment("account for the vertex transverse smearing?");

descriptions.add("beamDivergenceVtxGenerator", desc);
}

0 comments on commit 3565983

Please sign in to comment.