25 #include <CLHEP/Random/RandGauss.h>
63 simulateVertex_(iConfig.getParameter<bool>(
"simulateVertex")),
64 simulateBeamDivergence_(iConfig.getParameter<bool>(
"simulateBeamDivergence")) {
66 if (!tagSrcHepMC.
label().empty())
69 for (
const auto &it : iConfig.
getParameter<std::vector<edm::InputTag>>(
"srcGenParticle"))
75 <<
"The BeamDivergenceVtxGenerator requires the RandomNumberGeneratorService\n"
76 "which is not present in the configuration file. \n"
77 "You must add the service\n"
78 "in the configuration file or remove the modules that require it.";
80 produces<edm::HepMCProduct>();
89 ->setComment(
"input collection in HepMC format");
91 desc.
add<std::vector<edm::InputTag>>(
"srcGenParticle", std::vector<edm::InputTag>())
92 ->
setComment(
"input collections in GenParticle format");
94 desc.
add<
bool>(
"simulateBeamDivergence",
true)->setComment(
"account for the beam angular divergence?");
95 desc.
add<
bool>(
"simulateVertex",
true)->setComment(
"account for the vertex transverse smearing?");
97 descriptions.
add(
"beamDivergenceVtxGenerator", desc);
129 sp.
vtx_x = hBeamParameters->getVtxOffsetX45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevX();
130 sp.
vtx_y = hBeamParameters->getVtxOffsetY45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevY();
131 sp.
vtx_z = hBeamParameters->getVtxOffsetZ45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevZ();
132 sp.
vtx_t = hBeamParameters->getVtxOffsetT45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevT();
136 sp.
bd_x_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX45();
137 sp.
bd_x_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX56();
138 sp.
bd_y_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY45();
139 sp.
bd_y_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY56();
149 for (
const auto &
gp : *hGPCollection)
159 template <
typename T>
164 double th_x = mom.x() / mom.z();
165 double th_y = mom.y() / mom.z();
176 const double sign = (mom.z() > 0.) ? 1. : -1.;
177 const double p =
sqrt(mom.x() * mom.x() + mom.y() * mom.y() + mom.z() * mom.z());
178 const double p_z = sign * p /
sqrt(1. + th_x * th_x + th_y * th_y);
180 return HepMC::FourVector(p_z * th_x, p_z * th_y, p_z, mom.e());
188 const auto &pos = (*vit)->position();
189 (*vit)->set_position(HepMC::FourVector(pos.x() + sp.
vtx_x * 1E1,
190 pos.y() + sp.
vtx_y * 1E1,
191 pos.z() + sp.
vtx_z * 1E1,
192 pos.t() + sp.
vtx_t * 1E1));
197 for (HepMC::GenEvent::particle_iterator
part = genEvt->particles_begin();
part != genEvt->particles_end(); ++
part)
198 (*part)->set_momentum(
smearMomentum((*part)->momentum(), sp));
208 HepMC::GenVertex *vtx =
new HepMC::GenVertex(HepMC::FourVector(
212 ( +sp.
vtx_t) * 1E1));
213 genEvt->add_vertex(vtx);
217 vtx->add_particle_out(particle);
void setComment(std::string const &value)
std::vector< edm::EDGetTokenT< reco::GenParticleCollection > > genParticleTokens_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
static void fillDescriptions(edm::ConfigurationDescriptions &)
double vz() const override
z coordinate of vertex position
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
static HepMC::FourVector smearMomentum(const T &mom, const SmearingParameters &sp)
constexpr bool isUninitialized() const noexcept
double vy() const override
y coordinate of vertex position
int status() const final
status word
edm::ESGetToken< CTPPSBeamParameters, CTPPSBeamParametersRcd > beamParametersToken_
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
const LorentzVector & p4() const final
four-momentum Lorentz vector
int pdgId() const final
PDG identifier.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< edm::HepMCProduct > sourceToken_
double vx() const override
x coordinate of vertex position
void applySmearingHepMC(const SmearingParameters &sp, HepMC::GenEvent *genEvt)
void addSmearedGenParticle(const reco::GenParticle &gp, const SmearingParameters &sp, HepMC::GenEvent *genEvt)
BeamDivergenceVtxGenerator(const edm::ParameterSet &)
T getParameter(std::string const &) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~BeamDivergenceVtxGenerator() override=default
StreamID streamID() const
bool simulateBeamDivergence_
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
void produce(edm::Event &, const edm::EventSetup &) override