source: trunk/environments/g4py/tests/gtest01/root_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: 4.0 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 ROOT
11
12# ==================================================================
13#                          ROOT PART                               #
14# ==================================================================
15
16# ------------------------------------------------------------------
17def init_root():
18# ------------------------------------------------------------------ 
19  ROOT.gROOT.Reset()
20
21  # plot style
22  ROOT.gStyle.SetTextFont(82)
23  ROOT.gStyle.SetTitleFont(82, "X")
24  ROOT.gStyle.SetLabelFont(82, "X")
25  ROOT.gStyle.SetTitleFont(82, "Y")
26  ROOT.gStyle.SetLabelFont(82, "Y")
27
28  #ROOT.gStyle.SetOptTitle(0)
29  ROOT.gStyle.SetErrorX(0)
30
31  canvas= ROOT.TCanvas("g4py_plots",
32                       "Geant4Py Sample Plots",
33                       620, 30, 600, 400)
34
35  #canvas.Divide(2,2);
36  #canvas.SetFillColor(29)
37
38  canvas.SetGrid()
39
40  return canvas
41
42# ------------------------------------------------------------------
43def hini():
44# ------------------------------------------------------------------ 
45  global hist1
46  hist1= ROOT.TH1D("dE/dx/step", "dE/dx", 100, 0., 2000.)
47  hist1.SetXTitle("(keV)")
48
49
50# ------------------------------------------------------------------
51def hshow():
52# ------------------------------------------------------------------ 
53  hist1.Draw()
54 
55# ==================================================================
56#                         Geant4 PART                              #
57# ==================================================================
58
59# ==================================================================
60#   user actions in python
61# ==================================================================
62class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
63  "My Primary Generator Action"
64
65  def __init__(self):
66    G4VUserPrimaryGeneratorAction.__init__(self)
67    self.particleGun= G4ParticleGun(1)
68
69  def GeneratePrimaries(self, event):
70    self.particleGun.GeneratePrimaryVertex(event)
71
72# ------------------------------------------------------------------
73class MyRunAction(G4UserRunAction):
74  "My Run Action"
75
76  def BeginOfRunAction(self, run):
77    print "*** #event to be processed (BRA)=",
78    run.numberOfEventToBeProcessed
79
80  def EndOfRunAction(self, run):
81    print "*** run end run(ERA)=", run.runID
82
83# ------------------------------------------------------------------
84class MyEventAction(G4UserEventAction):
85  "My Event Action"
86
87  def BeginOfEventAction(self, event):
88    print "*** current event (BEA)=", event.eventID
89
90  def EndOfEventAction(self, event):
91    print "*** current event (EEA)=", event.eventID
92
93# ------------------------------------------------------------------
94class MySteppingAction(G4UserSteppingAction):
95  "My Stepping Action"
96
97  def UserSteppingAction(self, step):
98    #print "*** dE/dx in current step=", step.GetTotalEnergyDeposit()
99    dedx= step.GetTotalEnergyDeposit()
100    if(dedx>0):
101      hist1.Fill(dedx/HEPUnit.keV)
102
103# ==================================================================
104#   main
105# ==================================================================
106g4pyCanvas= init_root()
107hini()
108
109app= gtest01.MyApplication()
110app.Configure()
111
112# set user actions...
113myPGA= MyPrimaryGeneratorAction()
114gRunManager.SetUserAction(myPGA)
115
116myRA= MyRunAction()
117gRunManager.SetUserAction(myRA)
118 
119#myEA= MyEventAction()
120#gRunManager.SetUserAction(myEA)
121
122mySA= MySteppingAction()
123gRunManager.SetUserAction(mySA)
124
125 
126# set particle gun
127#ApplyUICommand("/control/execute gun.mac")
128pg= myPGA.particleGun
129pg.SetParticleByName("e-")
130pg.SetParticleEnergy(200.*HEPUnit.MeV)
131pg.SetParticleMomentumDirection(G4ThreeVector(0.2, 0., 1.))
132pg.SetParticlePosition(G4ThreeVector(0.,0.,-14.9)*HEPUnit.cm)
133 
134# visualization
135ApplyUICommand("/control/execute vis.mac")
136 
137# beamOn
138gRunManager.BeamOn(1000)
139
140#
141hshow()
142
143
Note: See TracBrowser for help on using the repository browser.