14 #include "CLHEP/Random/RandFlat.h"
18 const unsigned int np = 6;
29 produces<HepMCProduct>(
"unsmeared");
30 produces<GenEventInfoProduct>();
31 edm::LogVerbatim(
"ParticleGun") <<
"FileRandomMultiParticlePGun is initialzed with i/p file " << file
32 <<
" and use momentum range " << fMinP_ <<
":" <<
fMaxP_;
40 throw cms::Exception(
"Configuration") <<
"Cannot find the file " << file <<
"\n";
47 for (
int ip = 0; ip <
fPBin_; ++ip) {
48 for (
int ie = 0; ie <
fEtaBin_; ++ie) {
50 std::vector<double> prob(
np, 0);
52 is >> xl >> xh >> je >> prob[0] >> prob[1] >> prob[2] >> prob[3] >> prob[4] >> prob[5];
55 for (
unsigned int k = 0;
k <
np; ++
k) {
58 prob[
k] += prob[
k - 1];
60 for (
unsigned int k = 0;
k <
np; ++
k)
62 int indx = (ip + 1) *
kfactor + ie;
66 <<
"FileRandomMultiParticlePGun [" << ip <<
"," << ie <<
", " << indx <<
"] Probability " << prob[0]
67 <<
", " << prob[1] <<
", " << prob[2] <<
", " << prob[3] <<
", " << prob[4] <<
", " << prob[5];
81 edm::LogVerbatim(
"ParticleGun") <<
"FileRandomMultiParticlePGunProducer: Begin New Event Generation";
94 HepMC::GenVertex* Vtx =
new HepMC::GenVertex(HepMC::FourVector(0., 0., 0.));
97 double mom = CLHEP::RandFlat::shoot(engine,
fMinP_,
fMaxP_);
102 if (ipp ==
fP_.end())
104 int ip =
static_cast<int>(ipp -
fP_.begin());
105 int indx = ip *
kfactor + ieta;
107 edm::LogVerbatim(
"ParticleGun") <<
"FileRandomMultiParticlePGunProducer: p " << mom <<
" Eta " << eta <<
" Phi "
108 << phi <<
" Index " << indx;
112 int barcode(0), partID(
fPartIDs[0]);
113 double r1 = CLHEP::RandFlat::shoot(engine, 0., 1.);
114 for (
unsigned int ip = 0; ip <
fPartIDs.size(); ip++) {
122 double mass = PData->mass().value();
123 double energy =
sqrt(mom * mom + mass * mass);
124 double theta = 2. * atan(
exp(-eta));
125 double px = mom *
sin(theta) *
cos(phi);
126 double py = mom *
sin(theta) *
sin(phi);
127 double pz = mom *
cos(theta);
129 HepMC::FourVector
p(px, py, pz, energy);
132 Part->suggest_barcode(barcode);
133 Vtx->add_particle_out(Part);
135 fEvt->add_vertex(Vtx);
137 fEvt->set_signal_process_id(20);
142 std::unique_ptr<HepMCProduct> BProduct(
new HepMCProduct());
143 BProduct->addHepMCData(
fEvt);
149 edm::LogVerbatim(
"ParticleGun") <<
"FileRandomMultiParticlePGunProducer : Event Generation Done";
Log< level::Info, true > LogVerbatim
EventNumber_t event() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Sin< T >::type sin(const T &t)
Geom::Theta< T > theta() const
Exp< T >::type exp(const T &t)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void produce(Event &e, const EventSetup &es) override
ESHandle< HepPDT::ParticleDataTable > fPDGTable
Cos< T >::type cos(const T &t)
std::vector< int > fPartIDs
HepPDT::ParticleData ParticleData
std::vector< double > fP_
~FileRandomMultiParticlePGunProducer() override
T getParameter(std::string const &) const
FileRandomMultiParticlePGunProducer(const ParameterSet &pset)
std::map< int, std::vector< double > > fProbParticle_
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
StreamID streamID() const
const unsigned int kfactor