14 #include "CLHEP/Random/RandFlat.h" 25 if (fProbParticle_.size() !=
fPartIDs.size())
26 throw cms::Exception(
"Configuration") <<
"Not all probabilities given for all particle types " 27 << fProbParticle_.size() <<
":" <<
fPartIDs.size() <<
" need them to match\n";
29 produces<HepMCProduct>(
"unsmeared");
30 produces<GenEventInfoProduct>();
35 << fBinsP_ <<
" bins within momentum range " << fMinP_ <<
":" <<
fMaxP_;
41 edm::LogVerbatim(
"IOMC") <<
" Bin[" <<
k <<
"] " << p <<
":" << p + fDeltaP_ <<
" --> " << fProbP_[
k];
44 for (
unsigned int k = 1;
k < fProbParticle_.size(); ++
k)
45 fProbParticle_[
k] += fProbParticle_[
k - 1];
46 for (
unsigned int k = 0;
k < fProbParticle_.size(); ++
k)
47 fProbParticle_[
k] /= fProbParticle_[fProbParticle_.size() - 1];
50 for (
unsigned int k = 0;
k < fProbParticle_.size(); ++
k)
54 fProbP_[
k] += fProbP_[
k - 1];
56 fProbP_[
k] /= fProbP_[fBinsP_ - 1];
61 edm::LogVerbatim(
"IOMC") <<
" Bin[" <<
k <<
"] " << p <<
":" << p + fDeltaP_ <<
" --> " << fProbP_[
k];
73 <<
"Begin New Event Generation";
87 HepMC::GenVertex* Vtx =
new HepMC::GenVertex(HepMC::FourVector(0., 0., 0.));
92 double r1 = CLHEP::RandFlat::shoot(engine, 0., 1.);
93 for (
unsigned int ip = 0; ip <
fPartIDs.size(); ip++) {
100 double r2 = CLHEP::RandFlat::shoot(engine, 0., 1.);
101 for (
int ip = 0; ip <
fBinsP_; ip++) {
110 edm::LogVerbatim(
"IOMC") <<
"Random " << r1 <<
" PartID " << PartID <<
" and for p " << r2 <<
" range " << minP
113 double mom = CLHEP::RandFlat::shoot(engine, minP, maxP);
117 double mass = PData->mass().value();
118 double energy =
sqrt(mom * mom + mass * mass);
119 double theta = 2. * atan(
exp(-eta));
120 double px = mom *
sin(theta) *
cos(phi);
121 double py = mom *
sin(theta) *
sin(phi);
122 double pz = mom *
cos(theta);
124 HepMC::FourVector
p(px, py, pz, energy);
127 Part->suggest_barcode(barcode);
128 Vtx->add_particle_out(Part);
131 HepMC::FourVector ap(-px, -py, -pz, energy);
132 int APartID = (PartID == 22 || PartID == 23) ? PartID : -PartID;
135 APart->suggest_barcode(barcode);
136 Vtx->add_particle_out(APart);
139 fEvt->add_vertex(Vtx);
141 fEvt->set_signal_process_id(20);
148 std::unique_ptr<HepMCProduct> BProduct(
new HepMCProduct());
149 BProduct->addHepMCData(
fEvt);
156 edm::LogVerbatim(
"IOMC") <<
" RandomMultiParticlePGunProducer : Event Generation Done ";
T getParameter(std::string const &) const
EventNumber_t event() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::vector< double > fProbParticle_
Sin< T >::type sin(const T &t)
Geom::Theta< T > theta() const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
RandomMultiParticlePGunProducer(const ParameterSet &pset)
void produce(Event &e, const EventSetup &es) override
ESHandle< HepPDT::ParticleDataTable > fPDGTable
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
std::vector< int > fPartIDs
HepPDT::ParticleData ParticleData
StreamID streamID() const
std::vector< double > fProbP_