An example of GEANT4 in IPython

Version 0.1, released 18/11/2014, alpha

This is a rough example of what can be done within IPython notebook with the GEANT4 python environment. Currently this "linac head" is made of just a vacuum and two scattering foils. The beam distribution currently is just a purely mono-energetic 6 MeV beam projecting out from a point. This is very much a non-physical simulation. It is designed for example purposes only.

As a starting place I recommend fiddling with the geometry class.

If you want to see an advanced example of Geant4 with its python bindings Christopher Poole's linac is great.

Importing GEANT4

Importing the GEANT4 module is as simple as writing:

from Geant4 import *

The rest of what is written here you might get an idea about from this lecture


In [1]:
%pylab inline

from Geant4 import *

from IPython.display import Image


Populating the interactive namespace from numpy and matplotlib

*************************************************************
 Geant4 version Name: geant4-09-06-patch-03    (14-March-2014)
                      Copyright : Geant4 Collaboration
                      Reference : NIM A 506 (2003), 250-303
                            WWW : http://cern.ch/geant4
*************************************************************

Visualization Manager instantiating with verbosity "warnings (3)"...

Setting the requirements for a simulation

Now, before we start up our simulation we need to define a few classes. Geant4 absolutely requires the following three classes:

  • A detector geometry, this is where stuff is and what it is made of
  • A physics list, which is what particles to use and how to simulate them
  • and a primary generator, which is how do you generate your particles, what energy do they have, direction, position, type etc.

This small example only includes those three classes, however things such as outputting where energy was deposited requires further elements to the simulation such as scoring

A good overview of the base GEANT4 simulation requirements is found in the Geant4 documentation

Creating the geometry class

Everything written in the next cell defines what exists in your world. To get an idea of what is going on here is the palce to start. A list of Geant4 materials will be useful to know what you can quickly make your world out of. My recommendation would be to have a fiddle around and see what happens. That's the way I tend to learn best. Once you desire to extend yourself you might want to have a look at some of the Geant4 documentation:


In [2]:
class MyDetectorConstruction(G4VUserDetectorConstruction):
    "My Detector Construction"

    def __init__(self):

        G4VUserDetectorConstruction.__init__(self)
        
        
        self.solid = {}
        self.logical = {}
        self.physical = {}
       

        self.create_world(side = 4000,
                          material = "G4_AIR")
        
        self.create_cylinder(name = "vacuum", 
                             radius = 200,
                             length = 320,
                             translation = [0,0,900],
                             material = "G4_Galactic",
                             colour = [1.,1.,1.,0.1],
                             mother = 'world')
        
        self.create_cylinder(name = "upper_scatter", 
                             radius = 10,
                             length = 0.01,
                             translation = [0,0,60],
                             material = "G4_Ta",
                             colour = [1.,1.,1.,0.7],
                             mother = 'vacuum')
        
        self.create_cylinder(name = "lower_scatter", 
                             radius = 30,
                             length = 0.01,
                             translation = [0,0,20],
                             material = "G4_Al",
                             colour = [1.,1.,1.,0.7],
                             mother = 'vacuum')
        
        self.create_applicator_aperture(name = "apature_1",
                                        inner_side = 142,
                                        outer_side = 182,
                                        thickness = 6,
                                        translation = [0,0,449],
                                        material = "G4_Fe",
                                        colour = [1,1,1,0.7],
                                        mother = 'world')
        
        self.create_applicator_aperture(name = "apature_2",
                                        inner_side = 130,
                                        outer_side = 220,
                                        thickness = 12,
                                        translation = [0,0,269],
                                        material = "G4_Fe",
                                        colour = [1,1,1,0.7],
                                        mother = 'world')
        
        self.create_applicator_aperture(name = "apature_3",
                                        inner_side = 110,
                                        outer_side = 180,
                                        thickness = 12,
                                        translation = [0,0,140],
                                        material = "G4_Fe",
                                        colour = [1,1,1,0.7],
                                        mother = 'world')
        
        self.create_applicator_aperture(name = "apature_4",
                                        inner_side = 100,
                                        outer_side = 140,
                                        thickness = 12,
                                        translation = [0,0,59],
                                        material = "G4_Fe",
                                        colour = [1,1,1,0.7],
                                        mother = 'world')
        
        self.create_applicator_aperture(name = "cutout",
                                        inner_side = 100,
                                        outer_side = 120,
                                        thickness = 6,
                                        translation = [0,0,50],
                                        material = "G4_Fe",
                                        colour = [1,1,1,0.7],
                                        mother = 'world')
        
        self.create_cube(name = "phantom",
                         side = 500,
                         translation = [0,0,-250],
                         material = "G4_WATER",
                         colour = [0,0,1,0.4],
                         mother = 'world')
    
 
    
    def create_world(self, **kwargs):
        
        material = gNistManager.FindOrBuildMaterial(kwargs['material'])
        side = kwargs['side']
        
        self.solid['world'] = G4Box("world", side/2., side/2., side/2.)
        
        self.logical['world'] = G4LogicalVolume(self.solid['world'], 
                                                material, 
                                                "world")
        
        self.physical['world'] = G4PVPlacement(G4Transform3D(), 
                                               self.logical['world'], 
                                               "world", None, False, 0)

        visual = G4VisAttributes()
        visual.SetVisibility(False)
        
        self.logical['world'].SetVisAttributes(visual)
        
    
    
    def create_cylinder(self, **kwargs):
        
        name = kwargs['name']
        radius = kwargs['radius']
        length = kwargs['length']
        translation = G4ThreeVector(*kwargs['translation'])
        material = gNistManager.FindOrBuildMaterial(kwargs['material'])
        visual = G4VisAttributes(G4Color(*kwargs['colour']))
        mother = self.physical[kwargs['mother']]
        
        
        self.solid[name] = G4Tubs(name, 0., radius, length/2., 0., 2*pi)
        
        self.logical[name] = G4LogicalVolume(self.solid[name], 
                                             material,
                                             name)
        
        self.physical[name] = G4PVPlacement(None, translation, 
                                            name, 
                                            self.logical[name],
                                            mother, False, 0)

        self.logical[name].SetVisAttributes(visual)
    
    
    def create_cube(self, **kwargs):
        
        name = kwargs['name']
        side = kwargs['side']
        translation = G4ThreeVector(*kwargs['translation'])
        material = gNistManager.FindOrBuildMaterial(kwargs['material'])
        visual = G4VisAttributes(G4Color(*kwargs['colour']))
        mother = self.physical[kwargs['mother']]
        
        self.solid[name] = G4Box(name, side/2., side/2., side/2.)
        
        self.logical[name] = G4LogicalVolume(self.solid[name], 
                                             material,
                                             name)
        
        self.physical[name] = G4PVPlacement(None, translation, 
                                            name, 
                                            self.logical[name],
                                            mother, False, 0)

        self.logical[name].SetVisAttributes(visual)
    
    
    def create_applicator_aperture(self, **kwargs):
        
        name = kwargs['name']
        inner_side = kwargs['inner_side']
        outer_side = kwargs['outer_side']
        thickness = kwargs['thickness']
        translation = G4ThreeVector(*kwargs['translation'])
        material = gNistManager.FindOrBuildMaterial(kwargs['material'])
        visual = G4VisAttributes(G4Color(*kwargs['colour']))
        mother = self.physical[kwargs['mother']]
        
        
        inner_box = G4Box("inner", inner_side/2., inner_side/2., thickness/2. + 1)
        outer_box = G4Box("outer", outer_side/2., outer_side/2., thickness/2.)

        
        self.solid[name] = G4SubtractionSolid(name, 
                                              outer_box, 
                                              inner_box)
        
        self.logical[name] = G4LogicalVolume(self.solid[name], 
                                             material,
                                             name)
        
        self.physical[name] = G4PVPlacement(None, 
                                            translation,
                                            name, 
                                            self.logical[name],
                                            mother, False, 0)

        self.logical[name].SetVisAttributes(visual)
        
        

    # -----------------------------------------------------------------
    def Construct(self): # return the world volume
        
        return self.physical['world']

Now that you have made your geometry class, time to load it up


In [3]:
# set geometry
detector = MyDetectorConstruction()
gRunManager.SetUserInitialization(detector)

The physics list

There are a range of physics options available, generally one would define their own physics class. Just for ease at the moment I have used a standard one (and because I am still learning myself). If someone really wanted to use this for realistic results you would need to customise this yourself, especially a complicated concept called cuts. I have found in one case that the default option gave awkward PDDs.


In [4]:
# set physics list
physics_list = FTFP_BERT()
gRunManager.SetUserInitialization(physics_list)


<<< Geant4 Physics List simulation engine: FTFP_BERT 2.0

Generating the beam

Given here is a very simplistic beam. I have made it so that mono-energetic electrons are shot all in the same direction, all from a single point. This of course is not realistic.


In [5]:
class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
    "My Primary Generator Action"

    def __init__(self):
        
        G4VUserPrimaryGeneratorAction.__init__(self)
        
        particle_table = G4ParticleTable.GetParticleTable()

        electron = particle_table.FindParticle(G4String("e-"))
        positron = particle_table.FindParticle(G4String("e+"))
        gamma = particle_table.FindParticle(G4String("gamma"))
        
        beam = G4ParticleGun()
        beam.SetParticleEnergy(6*MeV)
        beam.SetParticleMomentumDirection(G4ThreeVector(0,0,-1))
        beam.SetParticleDefinition(electron)
        beam.SetParticlePosition(G4ThreeVector(0,0,1005))
        
        self.particleGun = beam

        
    def GeneratePrimaries(self, event):
        
        self.particleGun.GeneratePrimaryVertex(event)

And this is now loading up the generator we have just made


In [6]:
primary_generator_action = MyPrimaryGeneratorAction()
gRunManager.SetUserAction(primary_generator_action)

Initialise the simulation

Now that we have set all of the requirements for our simulation we can initialise it


In [7]:
# Initialise
gRunManager.Initialize()


### Adding tracking cuts for neutron  TimeCut(ns)= 10000  KinEnergyCut(MeV)= 0

Seeing the geometry

To see the beautiful geometry we have made we can use a raytracer macro. This first cell creates the macro file. The second cell runs the file and then displays the created png image.


In [8]:
%%file macros/raytrace.mac

/vis/open RayTracer
/vis/rayTracer/headAngle 340.
/vis/rayTracer/eyePosition 200 200 250  cm
/vis/rayTracer/trace images/world.jpg


Overwriting macros/raytrace.mac

In [9]:
gUImanager.ExecuteMacroFile('macros/raytrace.mac')

# Show image
Image(filename="images/world.jpg")


Out[9]:

Seeing the particle tracks

We can use a dawn macro in order to print out the particle tracks that a given number of generated particles porduced.


In [10]:
%%file macros/dawn.mac

/vis/open DAWNFILE

/vis/scene/create
/vis/scene/add/volume

/vis/scene/add/trajectories smooth
/vis/modeling/trajectories/create/drawByCharge
/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 2

/vis/scene/endOfEventAction accumulate 1000

/vis/scene/add/hits

/vis/sceneHandler/attach
#/vis/scene/add/axes 0. 0. 0. 10. cm

/vis/viewer/set/targetPoint 0.0 0.0 300.0 mm
/vis/viewer/set/viewpointThetaPhi 90 0

/vis/viewer/zoom 1


Overwriting macros/dawn.mac

In [11]:
gUImanager.ExecuteMacroFile('macros/dawn.mac')


/tracking/storeTrajectory 2

Once we have defined how we want to see the tracks we can beam on our pretend linac with 50 electrons.


In [12]:
gRunManager.BeamOn(50)

!mv g4_00.prim images/world.prim


phot:   for  gamma    SubType= 12
      LambdaPrime table from 200 keV to 10 TeV in 54 bins 
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
       PhotoElectric :  Emin=        0 eV    Emax=       10 TeV   AngularGenSauterGavrila  FluoActive

compt:   for  gamma    SubType= 13
      Lambda table from 100 eV  to 1 MeV in 28 bins, spline: 1
      LambdaPrime table from 1 MeV to 10 TeV in 49 bins 
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
       Klein-Nishina :  Emin=        0 eV    Emax=       10 TeV

conv:   for  gamma    SubType= 14
      Lambda table from 1.022 MeV to 10 TeV in 49 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        BetheHeitler :  Emin=        0 eV    Emax=       80 GeV
     BetheHeitlerLPM :  Emin=       80 GeV   Emax=       10 TeV

msc:   for e-    SubType= 10
      RangeFactor= 0.04, stepLimitType: 1, latDisplacement: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
          UrbanMsc95 :  Emin=        0 eV    Emax=      100 MeV  Table with 42 bins Emin=    100 eV    Emax=    100 MeV
        WentzelVIUni :  Emin=      100 MeV   Emax=       10 TeV  Table with 35 bins Emin=    100 MeV   Emax=     10 TeV

eIoni:   for  e-    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        MollerBhabha :  Emin=        0 eV    Emax=       10 TeV

eBrem:   for  e-    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      LPM flag: 1 for E > 1 GeV
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
             eBremSB :  Emin=        0 eV    Emax=        1 GeV   DipBustGen
            eBremLPM :  Emin=        1 GeV   Emax=       10 TeV   DipBustGen

CoulombScat:   for  e-    SubType= 1
      Lambda table from 100 MeV to 10 TeV in 35 bins, spline: 1
      180 < Theta(degree) < 180; pLimit(GeV^1)= 0.139531
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
  eCoulombScattering :  Emin=      100 MeV   Emax=       10 TeV

msc:   for e+    SubType= 10
      RangeFactor= 0.04, stepLimitType: 1, latDisplacement: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
          UrbanMsc95 :  Emin=        0 eV    Emax=      100 MeV  Table with 42 bins Emin=    100 eV    Emax=    100 MeV
        WentzelVIUni :  Emin=      100 MeV   Emax=       10 TeV  Table with 35 bins Emin=    100 MeV   Emax=     10 TeV

eIoni:   for  e+    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        MollerBhabha :  Emin=        0 eV    Emax=       10 TeV

eBrem:   for  e+    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      LPM flag: 1 for E > 1 GeV
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
             eBremSB :  Emin=        0 eV    Emax=        1 GeV   DipBustGen
            eBremLPM :  Emin=        1 GeV   Emax=       10 TeV   DipBustGen

annihil:   for  e+    SubType= 5
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
            eplus2gg :  Emin=        0 eV    Emax=       10 TeV

CoulombScat:   for  e+    SubType= 1
      Lambda table from 100 MeV to 10 TeV in 35 bins, spline: 1
      180 < Theta(degree) < 180; pLimit(GeV^1)= 0.139531
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
  eCoulombScattering :  Emin=      100 MeV   Emax=       10 TeV

msc:   for proton    SubType= 10
      RangeFactor= 0.2, step limit type: 0, lateralDisplacement: 1, polarAngleLimit(deg)= 180
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        WentzelVIUni :  Emin=        0 eV    Emax=       10 TeV  Table with 77 bins Emin=    100 eV    Emax=     10 TeV

hIoni:   for  proton    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 0.1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               Bragg :  Emin=        0 eV    Emax=        2 MeV
          BetheBloch :  Emin=        2 MeV   Emax=       10 TeV

hBrems:   for  proton    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               hBrem :  Emin=        0 eV    Emax=       10 TeV

hPairProd:   for  proton    SubType= 4
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
           hPairProd :  Emin=        0 eV    Emax=       10 TeV

msc:   for GenericIon    SubType= 10
      RangeFactor= 0.2, stepLimitType: 0, latDisplacement: 0
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
          UrbanMsc95 :  Emin=        0 eV    Emax=       10 TeV

ionIoni:   for  GenericIon    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 0.01, dRoverRange= 0.1, integral: 1, fluct: 1, linLossLimit= 0.02
      Stopping Power data for 17 ion/material pairs 
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
            BraggIon :  Emin=        0 eV    Emax=        2 MeV
          BetheBloch :  Emin=        2 MeV   Emax=       10 TeV

msc:   for alpha    SubType= 10
      RangeFactor= 0.2, stepLimitType: 0, latDisplacement: 0
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
          UrbanMsc95 :  Emin=        0 eV    Emax=       10 TeV  Table with 77 bins Emin=    100 eV    Emax=     10 TeV

ionIoni:   for  alpha    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 0.01, dRoverRange= 0.1, integral: 1, fluct: 1, linLossLimit= 0.02
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
            BraggIon :  Emin=        0 eV    Emax=   7.9452 MeV
          BetheBloch :  Emin=   7.9452 MeV   Emax=       10 TeV

msc:   for anti_proton    SubType= 10
      RangeFactor= 0.2, step limit type: 0, lateralDisplacement: 1, polarAngleLimit(deg)= 180
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        WentzelVIUni :  Emin=        0 eV    Emax=       10 TeV  Table with 77 bins Emin=    100 eV    Emax=     10 TeV

hIoni:   for  anti_proton    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 0.1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
            ICRU73QO :  Emin=        0 eV    Emax=        2 MeV
          BetheBloch :  Emin=        2 MeV   Emax=       10 TeV

hBrems:   for  anti_proton    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               hBrem :  Emin=        0 eV    Emax=       10 TeV

hPairProd:   for  anti_proton    SubType= 4
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
           hPairProd :  Emin=        0 eV    Emax=       10 TeV

msc:   for kaon+    SubType= 10
      RangeFactor= 0.2, step limit type: 0, lateralDisplacement: 1, polarAngleLimit(deg)= 180
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        WentzelVIUni :  Emin=        0 eV    Emax=       10 TeV  Table with 77 bins Emin=    100 eV    Emax=     10 TeV

hIoni:   for  kaon+    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 0.1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               Bragg :  Emin=        0 eV    Emax=  1.05231 MeV
          BetheBloch :  Emin=  1.05231 MeV   Emax=       10 TeV

hBrems:   for  kaon+    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               hBrem :  Emin=        0 eV    Emax=       10 TeV

hPairProd:   for  kaon+    SubType= 4
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
           hPairProd :  Emin=        0 eV    Emax=       10 TeV

msc:   for kaon-    SubType= 10
      RangeFactor= 0.2, step limit type: 0, lateralDisplacement: 1, polarAngleLimit(deg)= 180
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        WentzelVIUni :  Emin=        0 eV    Emax=       10 TeV  Table with 77 bins Emin=    100 eV    Emax=     10 TeV

hIoni:   for  kaon-    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 0.1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
            ICRU73QO :  Emin=        0 eV    Emax=  1.05231 MeV
          BetheBloch :  Emin=  1.05231 MeV   Emax=       10 TeV

hBrems:   for  kaon-    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               hBrem :  Emin=        0 eV    Emax=       10 TeV

hPairProd:   for  kaon-    SubType= 4
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
           hPairProd :  Emin=        0 eV    Emax=       10 TeV

msc:   for mu+    SubType= 10
      RangeFactor= 0.2, step limit type: 0, lateralDisplacement: 1, polarAngleLimit(deg)= 180
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        WentzelVIUni :  Emin=        0 eV    Emax=       10 TeV  Table with 77 bins Emin=    100 eV    Emax=     10 TeV

muIoni:   for  mu+    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               Bragg :  Emin=        0 eV    Emax=      200 keV
          BetheBloch :  Emin=      200 keV   Emax=        1 GeV
        MuBetheBloch :  Emin=        1 GeV   Emax=       10 TeV

muBrems:   for  mu+    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
              MuBrem :  Emin=        0 eV    Emax=       10 TeV

muPairProd:   for  mu+    SubType= 4
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
          muPairProd :  Emin=        0 eV    Emax=       10 TeV

CoulombScat:   for  mu+    SubType= 1
      Lambda table from 100 eV  to 10 TeV in 43 bins, spline: 1
      180 < Theta(degree) < 180; pLimit(GeV^1)= 0.139531
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
  eCoulombScattering :  Emin=        0 eV    Emax=       10 TeV

msc:   for mu-    SubType= 10
      RangeFactor= 0.2, step limit type: 0, lateralDisplacement: 1, polarAngleLimit(deg)= 180
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        WentzelVIUni :  Emin=        0 eV    Emax=       10 TeV  Table with 77 bins Emin=    100 eV    Emax=     10 TeV

muIoni:   for  mu-    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
            ICRU73QO :  Emin=        0 eV    Emax=      200 keV
          BetheBloch :  Emin=      200 keV   Emax=        1 GeV
        MuBetheBloch :  Emin=        1 GeV   Emax=       10 TeV

muBrems:   for  mu-    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
              MuBrem :  Emin=        0 eV    Emax=       10 TeV

muPairProd:   for  mu-    SubType= 4
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
          muPairProd :  Emin=        0 eV    Emax=       10 TeV

CoulombScat:   for  mu-    SubType= 1
      Lambda table from 100 eV  to 10 TeV in 43 bins, spline: 1
      180 < Theta(degree) < 180; pLimit(GeV^1)= 0.139531
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
  eCoulombScattering :  Emin=        0 eV    Emax=       10 TeV

msc:   for pi+    SubType= 10
      RangeFactor= 0.2, step limit type: 0, lateralDisplacement: 1, polarAngleLimit(deg)= 180
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        WentzelVIUni :  Emin=        0 eV    Emax=       10 TeV  Table with 77 bins Emin=    100 eV    Emax=     10 TeV

hIoni:   for  pi+    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 0.1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               Bragg :  Emin=        0 eV    Emax=  297.505 keV
          BetheBloch :  Emin=  297.505 keV   Emax=       10 TeV

hBrems:   for  pi+    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               hBrem :  Emin=        0 eV    Emax=       10 TeV

hPairProd:   for  pi+    SubType= 4
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
           hPairProd :  Emin=        0 eV    Emax=       10 TeV

msc:   for pi-    SubType= 10
      RangeFactor= 0.2, step limit type: 0, lateralDisplacement: 1, polarAngleLimit(deg)= 180
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
        WentzelVIUni :  Emin=        0 eV    Emax=       10 TeV  Table with 77 bins Emin=    100 eV    Emax=     10 TeV

hIoni:   for  pi-    SubType= 2
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      finalRange(mm)= 0.1, dRoverRange= 0.2, integral: 1, fluct: 1, linLossLimit= 0.01
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
            ICRU73QO :  Emin=        0 eV    Emax=  297.505 keV
          BetheBloch :  Emin=  297.505 keV   Emax=       10 TeV

hBrems:   for  pi-    SubType= 3
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
               hBrem :  Emin=        0 eV    Emax=       10 TeV

hPairProd:   for  pi-    SubType= 4
      dE/dx and range tables from 100 eV  to 10 TeV in 77 bins
      Lambda tables from threshold to 10 TeV in 77 bins, spline: 1
      ===== EM models for the G4Region  DefaultRegionForTheWorld ======
           hPairProd :  Emin=        0 eV    Emax=       10 TeV
============================================================================================
             HADRONIC PROCESSES SUMMARY (verbose level 1)

                                  Hadronic Processes for <GenericIon>
                                  -----------------------------------
        ionInelastic  Models:     Binary Light Ion Cascade: Emin(GeV)=    0  Emax(GeV)= 4
                                                      FTFP: Emin(GeV)=    2  Emax(GeV)= 100000

        ionInelastic  Crs sctns: Glauber-Gribov nucleus nucleus: Emin(GeV)=    0  Emax(GeV)= 100000
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000


                                  Hadronic Processes for <anti_neutron>
                                  -----------------------------------
          hadElastic  Models:                 hElasticLHEP: Emin(GeV)=    0  Emax(GeV)= 100000

          hadElastic  Crs sctns:            GheishaElastic: Emin(GeV)=    0  Emax(GeV)= 100000

AntiNeutronInelastic  Models:                         FTFP: Emin(GeV)=    0  Emax(GeV)= 100000

AntiNeutronInelastic  Crs sctns:              AntiAGlauber: Emin(GeV)=    0  Emax(GeV)= 1.79769e+305
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000


                                  Hadronic Processes for <anti_proton>
                                  -----------------------------------
          hadElastic  Models:                 hElasticLHEP: Emin(GeV)=    0  Emax(GeV)= 0.1
                                              AntiAElastic: Emin(GeV)=  0.1  Emax(GeV)= 100000

          hadElastic  Crs sctns:              AntiAGlauber: Emin(GeV)=    0  Emax(GeV)= 1.79769e+305
                                            GheishaElastic: Emin(GeV)=    0  Emax(GeV)= 100000

 AntiProtonInelastic  Models:                         FTFP: Emin(GeV)=    0  Emax(GeV)= 100000

 AntiProtonInelastic  Crs sctns:              AntiAGlauber: Emin(GeV)=    0  Emax(GeV)= 1.79769e+305
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000

          hFritiofCaptureAtRest

                                  Hadronic Processes for <e+>
                                  -----------------------------------
     PositronNuclear  Models:      G4ElectroVDNuclearModel: Emin(GeV)=    0  Emax(GeV)= 1e+06

     PositronNuclear  Crs sctns:          ElectroNuclearXS: Emin(GeV)=    0  Emax(GeV)= 100000
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000


                                  Hadronic Processes for <e->
                                  -----------------------------------
      ElectroNuclear  Models:      G4ElectroVDNuclearModel: Emin(GeV)=    0  Emax(GeV)= 1e+06

      ElectroNuclear  Crs sctns:          ElectroNuclearXS: Emin(GeV)=    0  Emax(GeV)= 100000
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000


                                  Hadronic Processes for <gamma>
                                  -----------------------------------
     PhotonInelastic  Models:               BertiniCascade: Emin(GeV)=    0  Emax(GeV)= 3.5
                                           TheoFSGenerator: Emin(GeV)=    3  Emax(GeV)= 100000

     PhotonInelastic  Crs sctns:            PhotoNuclearXS: Emin(GeV)=    0  Emax(GeV)= 100000
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000


                                  Hadronic Processes for <kaon+>
                                  -----------------------------------
          hadElastic  Models:                 hElasticLHEP: Emin(GeV)=    0  Emax(GeV)= 100000

          hadElastic  Crs sctns:            GheishaElastic: Emin(GeV)=    0  Emax(GeV)= 100000

   KaonPlusInelastic  Models:                         FTFP: Emin(GeV)=    4  Emax(GeV)= 100000
                                            BertiniCascade: Emin(GeV)=    0  Emax(GeV)= 5

   KaonPlusInelastic  Crs sctns:  ChipsKaonPlusInelasticXS: Emin(GeV)=    0  Emax(GeV)= 100000
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000


                                  Hadronic Processes for <kaon->
                                  -----------------------------------
          hadElastic  Models:                 hElasticLHEP: Emin(GeV)=    0  Emax(GeV)= 100000

          hadElastic  Crs sctns:            GheishaElastic: Emin(GeV)=    0  Emax(GeV)= 100000

  KaonMinusInelastic  Models:                         FTFP: Emin(GeV)=    4  Emax(GeV)= 100000
                                            BertiniCascade: Emin(GeV)=    0  Emax(GeV)= 5

  KaonMinusInelastic  Crs sctns: ChipsKaonMinusInelasticXS: Emin(GeV)=    0  Emax(GeV)= 100000
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000

          hBertiniCaptureAtRest

                                  Hadronic Processes for <lambda>
                                  -----------------------------------
          hadElastic  Models:                 hElasticLHEP: Emin(GeV)=    0  Emax(GeV)= 100000

          hadElastic  Crs sctns:            GheishaElastic: Emin(GeV)=    0  Emax(GeV)= 100000

     LambdaInelastic  Models:               BertiniCascade: Emin(GeV)=    0  Emax(GeV)= 6
                                                      FTFP: Emin(GeV)=    2  Emax(GeV)= 100000

     LambdaInelastic  Crs sctns:   ChipsHyperonInelasticXS: Emin(GeV)=    0  Emax(GeV)= 100000
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000


                     Hadronic Processes for <mu->
          muMinusCaptureAtRest

                                  Hadronic Processes for <neutron>
                                  -----------------------------------
          hadElastic  Models:                hElasticCHIPS: Emin(GeV)=    0  Emax(GeV)= 100000

          hadElastic  Crs sctns:     ChipsNeutronElasticXS: Emin(GeV)=    0  Emax(GeV)= 100000
                                            GheishaElastic: Emin(GeV)=    0  Emax(GeV)= 100000

    NeutronInelastic  Models:                         FTFP: Emin(GeV)=    4  Emax(GeV)= 100000
                                            BertiniCascade: Emin(GeV)=    0  Emax(GeV)= 5

    NeutronInelastic  Crs sctns:       Barashenkov-Glauber: Emin(GeV)=    0  Emax(GeV)= 100000
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000

            nCapture  Models:                   G4LCapture: Emin(GeV)=    0  Emax(GeV)= 20000

            nCapture  Crs sctns:          GheishaCaptureXS: Emin(GeV)=    0  Emax(GeV)= 100000

            nFission  Models:                   G4LFission: Emin(GeV)=    0  Emax(GeV)= 20000

            nFission  Crs sctns:          GheishaFissionXS: Emin(GeV)=    0  Emax(GeV)= 100000


                                  Hadronic Processes for <pi+>
                                  -----------------------------------
          hadElastic  Models:                 hElasticLHEP: Emin(GeV)=    0  Emax(GeV)= 1
                                           hElasticGlauber: Emin(GeV)=    1  Emax(GeV)= 100000

          hadElastic  Crs sctns:       Barashenkov-Glauber: Emin(GeV)=    0  Emax(GeV)= 100000
                                            GheishaElastic: Emin(GeV)=    0  Emax(GeV)= 100000

   PionPlusInelastic  Models:                         FTFP: Emin(GeV)=    4  Emax(GeV)= 100000
                                            BertiniCascade: Emin(GeV)=    0  Emax(GeV)= 5

   PionPlusInelastic  Crs sctns:      G4CrossSectionPairGG: Emin(GeV)=    0  Emax(GeV)= 100000
                         G4CrossSectionPairGG: G4PiNuclearCrossSection cross sections 
                           below 91 GeV, Glauber-Gribov above 
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000


                                  Hadronic Processes for <pi->
                                  -----------------------------------
          hadElastic  Models:                 hElasticLHEP: Emin(GeV)=    0  Emax(GeV)= 1
                                           hElasticGlauber: Emin(GeV)=    1  Emax(GeV)= 100000

          hadElastic  Crs sctns:       Barashenkov-Glauber: Emin(GeV)=    0  Emax(GeV)= 100000
                                            GheishaElastic: Emin(GeV)=    0  Emax(GeV)= 100000

  PionMinusInelastic  Models:                         FTFP: Emin(GeV)=    4  Emax(GeV)= 100000
                                            BertiniCascade: Emin(GeV)=    0  Emax(GeV)= 5

  PionMinusInelastic  Crs sctns:      G4CrossSectionPairGG: Emin(GeV)=    0  Emax(GeV)= 100000
                         G4CrossSectionPairGG: G4PiNuclearCrossSection cross sections 
                           below 91 GeV, Glauber-Gribov above 
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000

          hBertiniCaptureAtRest

                                  Hadronic Processes for <proton>
                                  -----------------------------------
          hadElastic  Models:                hElasticCHIPS: Emin(GeV)=    0  Emax(GeV)= 100000

          hadElastic  Crs sctns:      ChipsProtonElasticXS: Emin(GeV)=    0  Emax(GeV)= 100000
                                            GheishaElastic: Emin(GeV)=    0  Emax(GeV)= 100000

     ProtonInelastic  Models:                         FTFP: Emin(GeV)=    4  Emax(GeV)= 100000
                                            BertiniCascade: Emin(GeV)=    0  Emax(GeV)= 5

     ProtonInelastic  Crs sctns:       Barashenkov-Glauber: Emin(GeV)=    0  Emax(GeV)= 100000
                                          GheishaInelastic: Emin(GeV)=    0  Emax(GeV)= 100000

============================================================================================
===========================================    
Output file: g4_00.prim
Destination directory (current dir if NULL): 
Maximal number of files in the destination directory: 100
Note:                                                
  * The maximal number is customizable as:           
       % setenv  G4DAWNFILE_MAX_FILE_NUM  number 
  * The destination directory is customizable as:
       % setenv  G4DAWNFILE_DEST_DIR  dir_name/  
     ** Do not forget "/" at the end of the    
        dir_name, e.g. "./tmp/".  
===========================================      

File  g4_00.prim  is generated.
dawn g4_00.prim

The beam on created a prim file which needs to be converted to png for viewing.


In [13]:
!dawn -d images/world.prim
!convert images/world.eps images/world.png


***************************************
          Fukui  Renderer         
              DAWN                
 (Drawer for Academic WritiNgs)   
 ver 3.90b (Dev. indep. Mode)
          September 01, 2010
***************************************


***** g4.prim viewer mode (default)
***** ("dawn -h" for help)

***** PostScript file "images/world.eps" is created.
***** The showpage command is added.
sh: 1: gv: not found

And here is our wonderful simulation


In [14]:
Image("images/world.png")


Out[14]:

In [15]:
!G4VRML_DEST_DIR=.
!G4VRMLFILE_MAX_FILE_NUM=1
!G4VRMLFILE_VIEWER=echo

gApplyUICommand("/vis/open VRML2FILE")
gRunManager.BeamOn(1)

!mv g4_00.wrl images/world.wrl

Versions


In [16]:
%load_ext version_information

%version_information matplotlib, numpy


Out[16]:
SoftwareVersion
Python3.4.0 64bit [GCC 4.8.2]
IPython3.0.0-dev
OSLinux 3.16.0 24 generic x86_64 with Ubuntu 14.04 trusty
matplotlib1.3.1
numpy1.8.2
Tue Nov 18 11:48:03 2014 UTC