Geant4-11
test.py
Go to the documentation of this file.
1#!/usr/bin/python3
2# ==================================================================
3# python script for Geant4Py test
4#
5# gtest09
6# - test for checking use of G4PhysListFactory
7# ==================================================================
8
9from Geant4 import *
10
11# ==================================================================
12# user actions in python
13# ==================================================================
15 "My Detector Construction"
16
17 def __init__(self):
18 G4VUserDetectorConstruction.__init__(self)
19
20 # -----------------------------------------------------------------
21 def Construct(self):
22 # Python has automatic garbage collection system.
23 # Geometry objects must be defined as GLOBAL not to be deleted.
24 air= gNistManager.FindOrBuildMaterial("G4_AIR")
25
26 # world volume
27 global sld_world, lv_world, pv_world
28 sld_world= G4Box("world", 1.*m, 1.*m, 1.*m)
29 lv_world= G4LogicalVolume(sld_world, air, "world")
30 pv_world= G4PVPlacement(G4Transform3D(), lv_world, "world",
31 None, False, 0)
32
33 return pv_world
34
36 "My Primary Generator Action"
37
38 def __init__(self):
39 G4VUserPrimaryGeneratorAction.__init__(self)
41
42 def GeneratePrimaries(self, event):
43 dx=0.
44 self.particleGun.SetParticleMomentumDirection(G4ThreeVector(dx, 0., 1.))
45 self.particleGun.GeneratePrimaryVertex(event)
46
47# ==================================================================
48# main
49# ==================================================================
50# set geometry
52gRunManager.SetUserInitialization(myDC)
53
54# Create physics list
56myPhysList = factory.GetReferencePhysList("FTFP_BERT")
57
58if myPhysList is None:
59 raise RuntimeError("No physics list named FTFP_BERT found")
60
61gRunManager.SetUserInitialization(myPhysList)
62
63# Event generator
65myGenAction.particleGun.SetParticleByName("e-")
66myGenAction.particleGun.SetParticleEnergy(200.*MeV)
67myGenAction.particleGun.SetParticlePosition(G4ThreeVector(0.,0.,-14.9)*cm)
68
69gRunManager.SetUserAction(myGenAction)
70
71# Init, run terminate
72gRunManager.Initialize()
73gRunManager.BeamOn(10)
Definition: G4Box.hh:56
virtual G4VPhysicalVolume * Construct()=0
def GeneratePrimaries(self, event)
Definition: test.py:19
def gTerminate()
Definition: __init__.py:214