source: trunk/environments/g4py/examples/demos/water_phantom/test.py @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

  • Property svn:executable set to *
File size: 2.5 KB
Line 
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# ==================================================================
12class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
13  "My Primary Generator Action"
14
15  def __init__(self):
16    G4VUserPrimaryGeneratorAction.__init__(self)
17    self.particleGun= G4ParticleGun(1)
18
19  def GeneratePrimaries(self, event):
20    self.particleGun.GeneratePrimaryVertex(event)
21
22# ------------------------------------------------------------------
23class MyRunAction(G4UserRunAction):
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# ------------------------------------------------------------------
32class MyEventAction(G4UserEventAction):
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= demo_wp.MyPhysicsList()
61gRunManager.SetUserInitialization(myPL)
62
63# set user actions...
64myPGA= MyPrimaryGeneratorAction()
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
Note: See TracBrowser for help on using the repository browser.