[1337] | 1 | #!/usr/bin/python |
---|
| 2 | # ================================================================== |
---|
| 3 | # python script for Geant4Py test |
---|
| 4 | # |
---|
| 5 | # ================================================================== |
---|
| 6 | from Geant4 import * |
---|
| 7 | import demo_wp |
---|
| 8 | |
---|
| 9 | # ================================================================== |
---|
| 10 | # user actions in python |
---|
| 11 | # ================================================================== |
---|
| 12 | class 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 | # ------------------------------------------------------------------ |
---|
| 23 | class 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 | # ------------------------------------------------------------------ |
---|
| 32 | class MyEventAction(G4UserEventAction): |
---|
| 33 | "My Event Action" |
---|
| 34 | |
---|
| 35 | def EndOfEventAction(self, event): |
---|
| 36 | pass |
---|
| 37 | |
---|
| 38 | # ------------------------------------------------------------------ |
---|
| 39 | class 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 | # ================================================================== |
---|
| 54 | myMaterials= demo_wp.MyMaterials() |
---|
| 55 | myMaterials.Construct() |
---|
| 56 | |
---|
| 57 | myDC= demo_wp.MyDetectorConstruction() |
---|
| 58 | gRunManager.SetUserInitialization(myDC) |
---|
| 59 | |
---|
| 60 | myPL= demo_wp.MyPhysicsList() |
---|
| 61 | gRunManager.SetUserInitialization(myPL) |
---|
| 62 | |
---|
| 63 | # set user actions... |
---|
| 64 | myPGA= MyPrimaryGeneratorAction() |
---|
| 65 | gRunManager.SetUserAction(myPGA) |
---|
| 66 | |
---|
| 67 | myRA= MyRunAction() |
---|
| 68 | gRunManager.SetUserAction(myRA) |
---|
| 69 | |
---|
| 70 | myEA= MyEventAction() |
---|
| 71 | gRunManager.SetUserAction(myEA) |
---|
| 72 | |
---|
| 73 | mySA= MySteppingAction() |
---|
| 74 | gRunManager.SetUserAction(mySA) |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | # set particle gun |
---|
| 78 | pg= myPGA.particleGun |
---|
| 79 | pg.SetParticleByName("proton") |
---|
| 80 | pg.SetParticleEnergy(230.*MeV) |
---|
| 81 | pg.SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.)) |
---|
| 82 | pg.SetParticlePosition(G4ThreeVector(0.,0.,-20.)*cm) |
---|
| 83 | |
---|
| 84 | gRunManager.Initialize() |
---|
| 85 | |
---|
| 86 | # visualization |
---|
| 87 | gApplyUICommand("/control/execute vis.mac") |
---|
| 88 | |
---|
| 89 | # beamOn |
---|
| 90 | #gRunManager.BeamOn(3) |
---|
| 91 | |
---|
| 92 | |
---|