source: trunk/environments/g4py/tests/gtest01/test.py @ 1358

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

tag geant4.9.4 beta 1 + modifs locales

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