Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "PrimaryGeneratorAction.h"
#include "G4Event.hh"
#include "G4ParticleTable.hh"
#include "G4IonTable.hh"
#include "G4ParticleDefinition.hh"
PrimaryGeneratorAction::PrimaryGeneratorAction() {
}
PrimaryGeneratorAction::~PrimaryGeneratorAction() {
}
void
PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) {
// Generate Vertex (G4PrimaryVertex) and Particle (G4PrimaryParticle).
// Following is an example:
double x = 0.0;
double y = 0.0;
double z = 0.0;
double t = 0.0;
G4PrimaryVertex* g4vtx = new G4PrimaryVertex(x, y, z, t);
G4int pdgcode = 22;
// check the pdgid
G4ParticleTable* particletbl = G4ParticleTable::GetParticleTable();
G4ParticleDefinition* particle_def = particletbl->FindParticle(pdgcode);
double px = 0.0;
double py = 0.0;
double pz = 0.0;
G4PrimaryParticle* g4prim=new G4PrimaryParticle(particle_def, px, py, pz);
g4vtx->SetPrimary(g4prim);
anEvent->AddPrimaryVertex(g4vtx);
}