#include "AAPrimaryGeneratorAction.hh" #include "G4Event.hh" #include "G4ParticleGun.hh" #include "G4ParticleTable.hh" #include "G4ParticleDefinition.hh" #include "Sim.hh" #include using namespace std; using namespace CLHEP; AAPrimaryGeneratorAction::AAPrimaryGeneratorAction() { particleGun = new G4ParticleGun( 1 ); } AAPrimaryGeneratorAction::~AAPrimaryGeneratorAction() { delete particleGun; } #include "G4ParticleDefinition.hh" void AAPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) { foreach( trk , input_tracks ) { g_sim->current_track = &trk; G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); int code = trk.type; // print ("code translation " , trk.type ,"->", code ); G4ParticleDefinition* def = particleTable->FindParticle( code ); if (!def ) { dbg("failed to find particle with code", code); continue; // skip the weirdo } const double mass = def -> GetPDGMass () / GeV; if ( mass > trk.E ) { cout << " AAPrimaryGeneratorAction::GeneratePrimaries : particle has less energy than mass \n" << trk << " mass="<SetParticleDefinition( def ); particleGun->SetParticleEnergy( (trk.E - mass) * GeV ); // == kinetic energy particleGun->SetParticlePosition( G4ThreeVector( trk.pos.x * m , trk.pos.y* m, trk.pos.z*m )); G4ThreeVector v( trk.dir.x, trk.dir.y, trk.dir.z); particleGun->SetParticleMomentumDirection(v); particleGun->GeneratePrimaryVertex(anEvent); } }