Go to the documentation of this file.00001 #include <ostream>
00002
00003 #include "IOMC/ParticleGuns/interface/FlatRandomPtThetaGunProducer.h"
00004
00005 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00006 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
00007
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011
00012 using namespace edm;
00013
00014 FlatRandomPtThetaGunProducer::FlatRandomPtThetaGunProducer(const edm::ParameterSet& pset) :
00015 FlatBaseThetaGunProducer(pset)
00016 {
00017 edm::ParameterSet defpset ;
00018 edm::ParameterSet pgun_params =
00019 pset.getParameter<edm::ParameterSet>("PGunParameters") ;
00020
00021 fMinPt = pgun_params.getParameter<double>("MinPt");
00022 fMaxPt = pgun_params.getParameter<double>("MaxPt");
00023
00024 produces<HepMCProduct>();
00025 produces<GenEventInfoProduct>();
00026
00027
00028
00029 }
00030
00031 FlatRandomPtThetaGunProducer::~FlatRandomPtThetaGunProducer() {}
00032
00033 void FlatRandomPtThetaGunProducer::produce(edm::Event &e, const EventSetup& es) {
00034
00035 if ( fVerbosity > 0 ) {
00036 LogDebug("FlatThetaGun") << "FlatRandomPtThetaGunProducer : Begin New Event Generation";
00037 }
00038
00039
00040
00041
00042
00043
00044
00045
00046 fEvt = new HepMC::GenEvent() ;
00047
00048
00049
00050
00051
00052 HepMC::GenVertex* Vtx = new HepMC::GenVertex(HepMC::FourVector(0.,0.,0.));
00053
00054
00055
00056 int barcode = 1 ;
00057 for (unsigned int ip=0; ip<fPartIDs.size(); ++ip) {
00058
00059 double pt = fRandomGenerator->fire(fMinPt, fMaxPt) ;
00060 double theta = fRandomGenerator->fire(fMinTheta, fMaxTheta) ;
00061 double phi = fRandomGenerator->fire(fMinPhi, fMaxPhi) ;
00062 int PartID = fPartIDs[ip] ;
00063 const HepPDT::ParticleData*
00064 PData = fPDGTable->particle(HepPDT::ParticleID(abs(PartID))) ;
00065 double mass = PData->mass().value() ;
00066 double mom = pt/sin(theta) ;
00067 double px = pt*cos(phi) ;
00068 double py = pt*sin(phi) ;
00069 double pz = mom*cos(theta) ;
00070 double energy2= mom*mom + mass*mass ;
00071 double energy = sqrt(energy2) ;
00072 HepMC::FourVector p(px,py,pz,energy) ;
00073 HepMC::GenParticle* Part = new HepMC::GenParticle(p,PartID,1);
00074 Part->suggest_barcode( barcode ) ;
00075 barcode++ ;
00076 Vtx->add_particle_out(Part);
00077
00078 if ( fAddAntiParticle ) {
00079 HepMC::FourVector ap(-px,-py,-pz,energy) ;
00080 int APartID = -PartID ;
00081 if ( PartID == 22 || PartID == 23 ) {
00082 APartID = PartID ;
00083 }
00084 HepMC::GenParticle* APart = new HepMC::GenParticle(ap,APartID,1);
00085 APart->suggest_barcode( barcode ) ;
00086 barcode++ ;
00087 Vtx->add_particle_out(APart) ;
00088 }
00089 }
00090
00091 fEvt->add_vertex(Vtx) ;
00092 fEvt->set_event_number(e.id().event()) ;
00093 fEvt->set_signal_process_id(20) ;
00094
00095 if ( fVerbosity > 0 ) {
00096 fEvt->print() ;
00097 }
00098
00099 std::auto_ptr<HepMCProduct> BProduct(new HepMCProduct()) ;
00100 BProduct->addHepMCData( fEvt );
00101 e.put(BProduct);
00102
00103 std::auto_ptr<GenEventInfoProduct> genEventInfo(new GenEventInfoProduct(fEvt));
00104 e.put(genEventInfo);
00105
00106 if ( fVerbosity > 0 ) {
00107 LogDebug("FlatThetaGun") << "FlatRandomPtThetaGunProducer : Event Generation Done ";
00108 }
00109 }