File indexing completed on 2021-02-14 14:21:09
0001 #include <ostream>
0002
0003 #include "IOMC/ParticleGuns/interface/FlatRandomEThetaGunProducer.h"
0004
0005 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0006 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
0007
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ServiceRegistry/interface/Service.h"
0012 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
0013
0014 #include "CLHEP/Random/RandFlat.h"
0015
0016 namespace CLHEP {
0017 class HepRandomEngine;
0018 }
0019
0020 using namespace edm;
0021
0022 FlatRandomEThetaGunProducer::FlatRandomEThetaGunProducer(const edm::ParameterSet& pset)
0023 : FlatBaseThetaGunProducer(pset) {
0024 edm::ParameterSet defpset;
0025 edm::ParameterSet pgun_params = pset.getParameter<edm::ParameterSet>("PGunParameters");
0026
0027
0028
0029 fMinE = pgun_params.getParameter<double>("MinE");
0030 fMaxE = pgun_params.getParameter<double>("MaxE");
0031
0032 produces<HepMCProduct>("unsmeared");
0033 produces<GenEventInfoProduct>();
0034
0035
0036
0037
0038 }
0039
0040 FlatRandomEThetaGunProducer::~FlatRandomEThetaGunProducer() {}
0041
0042 void FlatRandomEThetaGunProducer::produce(edm::Event& e, const edm::EventSetup& es) {
0043 if (fVerbosity > 0) {
0044 LogDebug("FlatThetaGun") << "FlatRandomEThetaGunProducer : Begin New Event Generation";
0045 }
0046
0047 edm::Service<edm::RandomNumberGenerator> rng;
0048 CLHEP::HepRandomEngine* engine = &rng->getEngine(e.streamID());
0049
0050
0051
0052
0053
0054
0055
0056 fEvt = new HepMC::GenEvent();
0057
0058
0059
0060
0061
0062
0063 HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(0., 0., 0.));
0064
0065
0066
0067 int barcode = 1;
0068 for (unsigned int ip = 0; ip < fPartIDs.size(); ip++) {
0069 double energy = CLHEP::RandFlat::shoot(engine, fMinE, fMaxE);
0070 double theta = CLHEP::RandFlat::shoot(engine, fMinTheta, fMaxTheta);
0071 double phi = CLHEP::RandFlat::shoot(engine, fMinPhi, fMaxPhi);
0072 int PartID = fPartIDs[ip];
0073 const HepPDT::ParticleData* PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID)));
0074 double mass = PData->mass().value();
0075 double mom2 = energy * energy - mass * mass;
0076 double mom = (mom2 > 0. ? std::sqrt(mom2) : 0.);
0077 double px = mom * sin(theta) * cos(phi);
0078 double py = mom * sin(theta) * sin(phi);
0079 double pz = mom * cos(theta);
0080
0081 HepMC::FourVector p(px, py, pz, energy);
0082 HepMC::GenParticle* Part = new HepMC::GenParticle(p, PartID, 1);
0083 Part->suggest_barcode(barcode);
0084 barcode++;
0085 Vtx->add_particle_out(Part);
0086
0087 if (fAddAntiParticle) {
0088 HepMC::FourVector ap(-px, -py, -pz, energy);
0089 int APartID = -PartID;
0090 if (PartID == 22 || PartID == 23) {
0091 APartID = PartID;
0092 }
0093 HepMC::GenParticle* APart = new HepMC::GenParticle(ap, APartID, 1);
0094 APart->suggest_barcode(barcode);
0095 barcode++;
0096 Vtx->add_particle_out(APart);
0097 }
0098 }
0099 fEvt->add_vertex(Vtx);
0100 fEvt->set_event_number(e.id().event());
0101 fEvt->set_signal_process_id(20);
0102
0103 if (fVerbosity > 0) {
0104 fEvt->print();
0105 }
0106
0107 std::unique_ptr<HepMCProduct> BProduct(new HepMCProduct());
0108 BProduct->addHepMCData(fEvt);
0109 e.put(std::move(BProduct), "unsmeared");
0110
0111 std::unique_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
0112 e.put(std::move(genEventInfo));
0113
0114 if (fVerbosity > 0) {
0115 LogDebug("FlatThetaGun") << "FlatRandomEThetaGunProducer : Event Generation Done";
0116 }
0117 }