Geant4-11
test.py
Go to the documentation of this file.
1#!/usr/bin/python
2# ==================================================================
3# python script for Geant4Py test
4#
5# ==================================================================
6from Geant4 import *
7import demo_wp
8
9# ==================================================================
10# user actions in python
11# ==================================================================
13 "My Primary Generator Action"
14
15 def __init__(self):
16 G4VUserPrimaryGeneratorAction.__init__(self)
18
19 def GeneratePrimaries(self, event):
20 self.particleGun.GeneratePrimaryVertex(event)
21
22# ------------------------------------------------------------------
24 "My Run Action"
25
26 def EndOfRunAction(self, run):
27 print "*** End of Run"
28 print "- Run sammary : (id= %d, #events= %d)" \
29 % (run.GetRunID(), run.GetNumberOfEventToBeProcessed())
30
31# ------------------------------------------------------------------
33 "My Event Action"
34
35 def EndOfEventAction(self, event):
36 pass
37
38# ------------------------------------------------------------------
39class MySteppingAction(G4UserSteppingAction):
40 "My Stepping Action"
41
42 def UserSteppingAction(self, step):
43 pass
44 #print "*** dE/dx in current step=", step.GetTotalEnergyDeposit()
45 preStepPoint= step.GetPreStepPoint()
46 track= step.GetTrack()
47 touchable= track.GetTouchable()
48 #print "*** vid= ", touchable.GetReplicaNumber()
49
50
51# ==================================================================
52# main
53# ==================================================================
54myMaterials= demo_wp.MyMaterials()
55myMaterials.Construct()
56
57myDC= demo_wp.MyDetectorConstruction()
58gRunManager.SetUserInitialization(myDC)
59
60myPL= FTFP_BERT()
61gRunManager.SetUserInitialization(myPL)
62
63# set user actions...
65gRunManager.SetUserAction(myPGA)
66
67myRA= MyRunAction()
68gRunManager.SetUserAction(myRA)
69
70myEA= MyEventAction()
71gRunManager.SetUserAction(myEA)
72
73mySA= MySteppingAction()
74gRunManager.SetUserAction(mySA)
75
76
77# set particle gun
78pg= myPGA.particleGun
79pg.SetParticleByName("proton")
80pg.SetParticleEnergy(230.*MeV)
81pg.SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.))
82pg.SetParticlePosition(G4ThreeVector(0.,0.,-20.)*cm)
83
84gRunManager.Initialize()
85
86# visualization
87gApplyUICommand("/control/execute vis.mac")
88
89# beamOn
90#gRunManager.BeamOn(3)
91
92
def EndOfEventAction(self, event)
Definition: test.py:35
def GeneratePrimaries(self, event)
Definition: test.py:19
def EndOfRunAction(self, run)
Definition: test.py:26
def UserSteppingAction(self, step)
Definition: test.py:42
gApplyUICommand
Definition: __init__.py:158