-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.cc
More file actions
29 lines (22 loc) · 879 Bytes
/
generator.cc
File metadata and controls
29 lines (22 loc) · 879 Bytes
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
#include "generator.hh"
MyPrimaryGenerator::MyPrimaryGenerator()
{
fParticleGun = new G4ParticleGun(1); //1: one particle in a event
}
MyPrimaryGenerator::~MyPrimaryGenerator()
{
delete fParticleGun;
}
void MyPrimaryGenerator::GeneratePrimaries(G4Event *anEvent)
{
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
G4String particleName = "proton"; //name of particle
G4ParticleDefinition *particle = particleTable->FindParticle("proton");
G4ThreeVector pos(0.,0.,0.); //create particle at center of mother volume
G4ThreeVector mom(0.,0.,1.); //create particle in z direction
fParticleGun->SetParticlePosition(pos);
fParticleGun->SetParticleMomentumDirection(mom);
fParticleGun->SetParticleMomentum(100.*GeV);
fParticleGun->SetParticleDefinition(particle);
fParticleGun->GeneratePrimaryVertex(anEvent);
}