Skip to content

Commit

Permalink
Using GPS(General Particle Source)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejungwoo committed Apr 8, 2019
1 parent 33279eb commit c8a931d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
24 changes: 23 additions & 1 deletion myrun
@@ -1 +1,23 @@
/run/beamOn 1
/gps/position 0 0 0
/gps/direction 0 0 1
/gps/particle e-
/gps/energy 10 MeV
/run/beamOn 2

/gps/position 0 0 0
/gps/direction 0 0 1
/gps/particle neutron
/gps/energy 50 MeV
/run/beamOn 5

/gps/position 0 0 0
/gps/direction 0 0 1
/gps/particle proton
/gps/energy 20 MeV
/run/beamOn 10

/gps/position 0 0 0
/gps/direction 0 0 1
/gps/particle gamma
/gps/energy 1 MeV
/run/beamOn 2
14 changes: 2 additions & 12 deletions src/OTPrimaryGeneratorAction.cc
Expand Up @@ -4,7 +4,7 @@
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4RunManager.hh"
#include "G4ParticleGun.hh"
#include "G4GeneralParticleSource.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4SystemOfUnits.hh"
Expand All @@ -13,17 +13,7 @@
OTPrimaryGeneratorAction::OTPrimaryGeneratorAction()
: G4VUserPrimaryGeneratorAction()
{
G4int n_particle = 1;
fParticleGun = new G4ParticleGun(n_particle);

G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4String particleName;
G4ParticleDefinition* particle
= particleTable -> FindParticle(particleName = "proton");

fParticleGun -> SetParticleDefinition(particle);
fParticleGun -> SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
fParticleGun -> SetParticleEnergy(40.*MeV);
fParticleGun = new G4GeneralParticleSource();
}

OTPrimaryGeneratorAction::~OTPrimaryGeneratorAction()
Expand Down
9 changes: 3 additions & 6 deletions src/OTPrimaryGeneratorAction.hh
Expand Up @@ -2,7 +2,7 @@
#define OTPRIMARYGENERATORACTION_HH

#include "G4VUserPrimaryGeneratorAction.hh"
#include "G4ParticleGun.hh"
#include "G4GeneralParticleSource.hh"
#include "G4Event.hh"
#include "globals.hh"

Expand All @@ -14,12 +14,9 @@ class OTPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction

// method from the base class
virtual void GeneratePrimaries(G4Event*);

// method to access particle gun
const G4ParticleGun* GetParticleGun() const { return fParticleGun; }


private:
G4ParticleGun* fParticleGun; // pointer a to G4 gun class
G4GeneralParticleSource* fParticleGun;
};

#endif

0 comments on commit c8a931d

Please sign in to comment.