Geant4-11
test.py
Go to the documentation of this file.
1#!/usr/bin/python3
2# ==================================================================
3# python script for Geant4Py test
4#
5# gtest01
6# - check basic control flow
7# ==================================================================
8from Geant4 import *
9import gtest01
10import random
11
12# ==================================================================
13# user actions in python
14# ==================================================================
15class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
16 "My Primary Generator Action"
17
18 def __init__(self):
19 G4VUserPrimaryGeneratorAction.__init__(self)
21
22 def GeneratePrimaries(self, event):
23 #dx= random.gauss(0., 0.1)
24 dx=0.
25 self.particleGun.SetParticleMomentumDirection(G4ThreeVector(dx, 0., 1.))
26 self.particleGun.GeneratePrimaryVertex(event)
27
28# ------------------------------------------------------------------
30 "My Run Action"
31
32 def BeginOfRunAction(self, run):
33 print("*** #event to be processed (BRA)=",
34 run.GetNumberOfEventToBeProcessed())
35
36 def EndOfRunAction(self, run):
37 print("*** run end run(ERA)=", run.GetRunID())
38
39# ------------------------------------------------------------------
41 "My Event Action"
42
43 #def BeginOfEventAction(self, event):
44 #print("*** current event (BEA)=", event.GetEventID())
45 # pass
46
47 #def EndOfEventAction(self, event):
48 #print("*** current event (EEA)=", event.GetEventID())
49
50# ------------------------------------------------------------------
51class MySteppingAction(G4UserSteppingAction):
52 "My Stepping Action"
53
54 def UserSteppingAction(self, step):
55 #print("*** dE/dx in current step=", step.GetTotalEnergyDeposit())
56 track= step.GetTrack()
57 touchable= track.GetTouchable()
58 pv= touchable.GetVolume()
59 #print(pv.GetCopyNo())
60 #print(touchable.GetReplicaNumber(0))
61
62# ------------------------------------------------------------------
64 "My Magnetic Field"
65
66 def GetFieldValue(self, pos, time):
67 bfield= G4ThreeVector()
68 bfield.x= 0.
69 bfield.y= 5.*tesla
70 bfield.z= 0.
71 return bfield
72
73# ==================================================================
74# main
75# ==================================================================
76qMaterials= gtest01.QMaterials()
77qMaterials.Construct()
78
79qDC= gtest01.QDetectorConstruction()
80gRunManager.SetUserInitialization(qDC)
81
82qPL= gtest01.QPhysicsList()
83gRunManager.SetUserInitialization(qPL)
84
85# set user actions...
86#qPGA= gtest01.QPrimaryGeneratorAction()
88gRunManager.SetUserAction(myPGA)
89
90#myRA= MyRunAction()
91#gRunManager.SetUserAction(myRA)
92
93myEA= MyEventAction()
94gRunManager.SetUserAction(myEA)
95
96mySA= MySteppingAction()
97gRunManager.SetUserAction(mySA)
98
99# set particle gun
100#ApplyUICommand("/control/execute gun.mac")
101#pg= qPGA.GetParticleGun()
102pg= myPGA.particleGun
103pg.SetParticleByName("e-")
104pg.SetParticleEnergy(200.*MeV)
105pg.SetParticlePosition(G4ThreeVector(0.,0.,-14.9)*cm)
106
107# magnetic field
108fieldMgr= gTransportationManager.GetFieldManager()
109myField= G4UniformMagField(G4ThreeVector(0.,10.*tesla,0.))
110#myField= MyField()
111fieldMgr.SetDetectorField(myField)
112fieldMgr.CreateChordFinder(myField)
113
114gRunManager.Initialize()
115
116# beamOn
117gRunManager.BeamOn(10)
void print(G4double elem)
def GetFieldValue(self, pos, time)
Definition: test.py:66
def GeneratePrimaries(self, event)
Definition: test.py:19
def EndOfRunAction(self, run)
Definition: test.py:26
def BeginOfRunAction(self, run)
Definition: test.py:32
def UserSteppingAction(self, step)
Definition: test.py:42
def gTerminate()
Definition: __init__.py:214