Import Geant4 8.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 14:44:26 +02:00
parent 8a51e0bc40
commit 216a75eeb1
8717 changed files with 360418 additions and 141343 deletions
+32
View File
@@ -0,0 +1,32 @@
$Id: History,v 1.2 2006/06/13 15:53:08 kmura Exp $
-------------------------------------------------------------------
=========================================================
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
=========================================================
Category History file
---------------------
A set of examples for Geant4Py.
----------------------------------------------------------
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
14 June 2006 K.Murakami
- Summary
[demos/water_phantom]
an example of dose calculation in water phantom with
on-line histogramming with ROOT
[education/lesson1, lesson2]
educational examples with TKinter GUI
[emplot]
examples of plotting photon cross section and stopping power
24 June 2005 K.Murakami
- just created.
+258
View File
@@ -0,0 +1,258 @@
\documentclass{article}
\title{How to EZsim using the site-modules of Geant4Py?}
\author{ H. Yoshida \and K. Murakami}
\begin{document}
\maketitle
\section{g4py/site-modules}
Currently site-modules have the following wrapper modules:
\begin{itemize}
\item EZsim
\begin{itemize}
\item EZgeom : main topic of this document
\begin{itemize}
\item ezgeom
\end{itemize}
\end{itemize}
\item geometries : examples of wrapping
\begin{itemize}
\item ExN01geom
\item ExN03geom
\end{itemize}
\item materials : pre-defined materials
\begin{itemize}
\item NISTmaterials
\end{itemize}
\item physics\_lists : examples of wrapping
\begin{itemize}
\item EMSTDpl
\item ExN01pl
\item ExN03pl
\item (GenericPhysicsList)
\end{itemize}
\item primaries : pre-defined particle guns
\begin{itemize}
\item MedicalBeam
\item ParticleGun
\end{itemize}
\end{itemize}
\section{The levels of Python wrapping}
The application of these site modules are stored in
\begin{itemize}
\item tests : many test examples
\item examples/demos/water\_phantom : voxelized water phantom and scoring
\item examples/education
\begin{itemize}
\item lesson1 : measurement of the mass attenuation coefficients
\item lesson2 : exampleN03
\end{itemize}
\end{itemize}
In general, Python wrapping can be applied in various levels.
This can be seen, for example, in the above examples which demonstrate how the
geometries are constructed. We cite two examples how site modules can be used,
and how existing C++ classes can be wrapped to co-work within the framework of
Geant4Py.
\subsection{Full Python case}
The script examples/education/lesson1/Lesson1.py uses the Phtyon modules of
EZgeom. It defines a simple absorber box, using EZgeom module. Its material,
dimensions, colors etc. are modifiable by using Python methods.
\subsection{Wrapping an existing C++ geometry}
The script examples/education/lesson2/ExN03.py uses the geometry of
exampleN03 as it is (ExN03DetectorConstruction).
The modules in site-modules/geometries/ExN03geom wrap these C++ classes and
their methods like exposes its methods like "SetAbsorberMaterial",
"SetAbsorberThickness", "GeometryUpdated" etc..
It also used wrapped "ExN03PhysicsList".
So, ExN03.py script do nothing for the geometry and physics list. It simply
initialized them.
\section{Closer look: Full Python case}
Exposed modules by the EZgeom module are following:
\begin{itemize}
\item Construct() :
\item SetWorldMaterial(material)
\item SetWorldVisibility(bool)
\item ResizeWorld(dx, dy, dz)
\item ResetWorld(dx, dy, dz)
\end{itemize}
Also exposed are modules in the G4EzVolume class.
\begin{itemize}
\item CreateBoxVolume, Tube/Cone/Sphere/Orb
\item Set(Get)Sold
\item Set(Get)Material
\item Set(Get)Color
\item Set(Get)Visibility
\item
\item Placeit()
\item ReplicateIt()
\item VoxelizeIt()
\item
\item SetSensitiveDetector
\end{itemize}
In addition, you can use global names like gMaterialTable etc. which are
defined in the g4py/source and exposed in the widest name space under
Boost-python. You can easily get the list of all g* modules from ipython
shell, once you import Geant4 modules.
Let us explain how to use the above modules, taking the script in
examples/education/lesson1/Leson1.py as an example.
It starts by lines to import modules:
\begin{verbatim}
1: from Geant4 import *
2: import NISTmaterials
3: from EZsim import EZgeom
4: from EZsim.EZgeom import G4EzVolume
5: import EMSTDpl
6: import ParticleGun
7: from time import *
8: import sys
\end{verbatim}
In line 1 you import all exposed modules of Geant4.
From the line 2 to 6, you import relevant site-modules. Lines 7 and 8 is to
import generic Python modules.
Then you define a Python class "Configure" for initialization.
\begin{verbatim}
def Configure():
NISTmaterials.Construct() # NIST materials predefined in g4py
EZgeom.Construct() # initialize
EMSTDpl.Construct() # initialize the physics list
ParticleGun.Construct() # initialize the particle gun
gControlExecute("gun.mac") # this is one of the globals
\end{verbatim}
Now you define the concrete geometry.
\begin{verbatim}
def ConstructGeom():
print "* Constructing geometry..."
# materils
galactic = G4Material.GetMaterial("G4_Galactic", 1)
water = G4Material.GetMaterial("G4_WATER", 1)
# world
EZgeom.SetWorldMaterial(galactic)
EZgeom.ResizeWorld(120.*cm, 120.*cm, 100.*cm)
# water phantom ; logical and physical volumes
global water_phantom, water_phantom_pv
water_phantom= G4EzVolume("WaterPhantom")
water_phantom.CreateBoxVolume(water, 110.*cm, 110.*cm, 10.*cm)
#Place the water phantom in the vacuum!!
water_phantom_pv = water_phantom.PlaceIt(G4ThreeVector(0.,0.,0.*cm))
\end{verbatim}
Here water\_phantom is the logical volume, while water\_phantom\_pv is the
physical volume. These variables are defined as global for later use.
If you want to change the material of the water\_phantom with the lead, for
example, you define lead by makinging its instance from the pre-defined list
and SetMaterial().
\begin{verbatim}
lead = G4Material.GetMaterial("G4_Pb", 1)
water_phantom.SetMaterial(lead)
\end{verbatim}
To print out the name of the materialof the logical volume,
\begin{verbatim}
print water_phantom.Getmaterial().GetName()
\end{verbatim}
If you want to change the dimensions of the water\_phantom, you have to get
its instance of the solid, and then SetZHalfLength().
\begin{verbatim}
solid = EZgeom.G4EzVolume.GetSold(water_phantom)
solid.SetZHalfLength(thickness * mm/2.0)
\end{verbatim}
If you want to relocate the water phantom, i.e., water\_phantom\_pv,
\begin{verbatim}
water_phantom_pv.SetTransformation(G4TreeVector(, ,))
\end{verbatim}
You can use any Geant4 commands with gApplyUICommand() method.
You simply provide it with strings, as seen in the next code fragment.
\begin{verbatim}
eventNum = self.eventVar.get()
for i in range(eventNum):
gunYZpos = str(i-eventNum/2) + ". -20. cm"
gApplyUICommand("/gun/position 0. " + gunYZpos)
gRunManager.BeamOn(1)
sleep(0.01)
\end{verbatim}
With the above code fragment, you use "eventVar" which is supplied by the
"Scale" widget. You repeat gRunManager.BeamOn(1), after a sleep of every
o.o1 second. You use gApplyUICommand() to change the gun's YZ position before
every shoot.
\section{Closer study: wrapped C++ classes case}
The script file in g4py/examples/education/lesson2/ExN03.py is an example.
The C++ classes of geometry and physics list of exampleN03 are exposed with
mo modifications. To expose them, wrapper classes, pyExN03geom.cc and
pyExN03pl.cc are created and stored in ExN03geom/ and ExN03pl/ respectively.
They are pre-compiled and shared libraries; ExN03geom.so, and ExN03pl.so are
stored in the g4py/lib/site-modules library repository.
ExN03geom exposes all the methods defined in ExN03DetectorConstruction.
ExN03.py in lesson2 initializes the geometry and physics list by simply using
the exposed classes;
\begin{verbatim}
from Geant4 import *
import NISTmaterials
import ExN03geom
import ExN03pl
exN03geom = ExN03geom.ExN03DetectorConstruction()
gRunManager.SetUserInitialization(exN03geom)
exN03PL = ExN03pl.ExN03PhysicsList()
gRunManager.SetUserInitialization(exN03PL)
\end{verbatim}
ExN03.py provides the widgets to choose a material with the Checkbutton,
to set the thickness with the Scale widget etc. It provides a "Run" button
to do /run/beamOn equivalent.
Just before "beamOn", the geometry is modified like;
\begin{verbatim}
def cmd_beamOn(self):
exN03geom.SetAbsorberMaterial(self.materialVar.get())
exN03geom.SetAbsorberThickness(self.thickVar.get() * mm/2.0)
exN03geom.UpdateGeometry()
exN03PL.SetDefaultCutValue(self.cutVar.get() * mm)
exN03PL.SetCutsWithDefault()
exN03geom.SetMagField(self.magVar.get() * tesla)
\end{verbatim}
Here, self.xxxVar.get() are the values (String or Double) supplied by the
Checkbutton or Scale widgets.
The on/off of each process is done using the global name gProcessTable.
\begin{verbatim}
def cmd_setProcess(self):
for i in self.processList:
if self.processVar[i].get() == 0:
gProcessTable.SetProcessActivation(i, 0)
print "Process " + i + " inactivated"
else:
gProcessTable.SetProcessActivation(i, 1)
print "Process " + i + " activated"
\end{verbatim}
Here "processList" is a list of the names of processes like below and
"processVar" contains the on/off values of the Checkbuttons for respective
processes.
\begin{verbatim}
self.processList = ["phot", "compt", "conv", "msc", "eIoni", "eBrem", "annih
il","muIoni", "muBrems"]
\end{verbatim}
\end{document}
+31
View File
@@ -0,0 +1,31 @@
$Id: README,v 1.2 2006/06/13 16:07:20 kmura Exp $
-------------------------------------------------------------------
This directory contains a set of examples for Geant4Py.
[demos/water_phantom]
An example of "water phantom dosimetry"
This demo program shows that a Geant4 application well coworks with ROOT
on Python front end. VisManager, PrimaryGeneratorAction, UserAction-s,
histogramming with ROOT are implemented in Python;
+ dose calculation in a water phantom
+ Python overloading of user actions
+ on-line histogramming with ROOT
+ visualization
[education]
Educational examples with Graphical User Interface using TKinter
* lesson1
The first version of the courseware of the mass attenuation coefficient.
* lesson2
GUI interface of ExN03, which can control geometry configuration,
intial particle condition, physics processes, cut value,
magnetic field and visualization outputs.
[emplot]
Examples of plotting photon cross sections and stopping powers with ROOT
+216
View File
@@ -0,0 +1,216 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# gtest01
# - check basic control flow
# ==================================================================
from Geant4 import *
import demo_wp
import MedicalBeam
import ROOT
# ==================================================================
# ROOT PART #
# ==================================================================
# ------------------------------------------------------------------
def init_root():
# ------------------------------------------------------------------
ROOT.gROOT.Reset()
# plot style
ROOT.gStyle.SetTextFont(42)
ROOT.gStyle.SetTitleFont(42, "X")
ROOT.gStyle.SetLabelFont(42, "X")
ROOT.gStyle.SetTitleFont(42, "Y")
ROOT.gStyle.SetLabelFont(42, "Y")
global gCanvas
gCanvas= ROOT.TCanvas("water_phantom_plots",
"Water Phantom Demo Plots",
620, 30, 800, 800)
# ------------------------------------------------------------------
def hini():
# ------------------------------------------------------------------
global gPad1
gPad1= ROOT.TPad("2D", "2D", 0.02, 0.5, 0.98, 1.)
gPad1.Draw()
gPad1.cd()
ROOT.gStyle.SetPalette(1);
global hist_dose2d
hist_dose2d= ROOT.TH2D("2D Dose", "Dose Distribution",
200, 0., 400.,
81, -81., 81.)
hist_dose2d.SetXTitle("Z (mm)")
hist_dose2d.SetYTitle("X (mm)")
hist_dose2d.SetStats(0)
hist_dose2d.Draw("colz")
gCanvas.cd()
global gPad2
gPad2= ROOT.TPad("Z", "Z", 0.02, 0., 0.98, 0.5)
gPad2.Draw()
gPad2.cd()
global hist_dosez
hist_dosez= ROOT.TH1D("Z Dose", "Depth Dose", 200, 0., 400.)
hist_dosez.SetXTitle("(mm)")
hist_dosez.SetYTitle("Accumulated Dose (MeV)")
hist_dosez.Draw()
# ------------------------------------------------------------------
def hshow():
# ------------------------------------------------------------------
gPad1.cd()
hist_dose2d.Draw("colz")
gPad2.cd()
hist_dosez.Draw()
# ==================================================================
# Geant4 PART #
# ==================================================================
# ==================================================================
# user actions in python
# ==================================================================
class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
"My Primary Generator Action"
def __init__(self):
G4VUserPrimaryGeneratorAction.__init__(self)
self.particleGun= G4ParticleGun(1)
def GeneratePrimaries(self, event):
self.particleGun.GeneratePrimaryVertex(event)
# ------------------------------------------------------------------
class MyRunAction(G4UserRunAction):
"My Run Action"
def EndOfRunAction(self, run):
print "*** End of Run"
print "- Run sammary : (id= %d, #events= %d)" \
% (run.GetRunID(), run.GetNumberOfEventToBeProcessed())
# ------------------------------------------------------------------
class MyEventAction(G4UserEventAction):
"My Event Action"
def EndOfEventAction(self, event):
gPad1.Modified()
gPad1.Update()
gPad2.Modified()
gPad2.Update()
ROOT.gSystem.ProcessEvents()
# ------------------------------------------------------------------
class MySteppingAction(G4UserSteppingAction):
"My Stepping Action"
def UserSteppingAction(self, step):
pass
# ------------------------------------------------------------------
class ScoreSD(G4VSensitiveDetector):
"SD for score voxels"
def __init__(self):
G4VSensitiveDetector.__init__(self, "ScoreVoxel")
def ProcessHits(self, step, rohist):
preStepPoint= step.GetPreStepPoint()
if(preStepPoint.GetCharge() == 0):
return
track= step.GetTrack()
touchable= track.GetTouchable()
voxel_id= touchable.GetReplicaNumber()
dedx= step.GetTotalEnergyDeposit()
xz= posXZ(voxel_id)
hist_dose2d.Fill(xz[1], xz[0], dedx/MeV)
if( abs(xz[0]) <= 100 ):
hist_dosez.Fill(xz[1], dedx/MeV)
# ------------------------------------------------------------------
def posXZ(copyN):
dd= 2.*mm
nx= 81
iz= copyN/nx
ix= copyN-iz*nx-nx/2
x0= ix*dd
z0= (iz+0.5)*dd
return (x0,z0)
# ==================================================================
# main
# ==================================================================
# init ROOT...
init_root()
hini()
# configure application
#app= demo_wp.MyApplication()
#app.Configure()
myMaterials= demo_wp.MyMaterials()
myMaterials.Construct()
myDC= demo_wp.MyDetectorConstruction()
gRunManager.SetUserInitialization(myDC)
myPL= demo_wp.MyPhysicsList()
gRunManager.SetUserInitialization(myPL)
# set user actions...
myPGA= MyPrimaryGeneratorAction()
gRunManager.SetUserAction(myPGA)
myRA= MyRunAction()
gRunManager.SetUserAction(myRA)
myEA= MyEventAction()
gRunManager.SetUserAction(myEA)
#mySA= MySteppingAction()
#gRunManager.SetUserAction(mySA)
# set particle gun
#pg= myPGA.particleGun
#pg.SetParticleByName("proton")
#pg.SetParticleEnergy(230.*MeV)
#pg.SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.))
#pg.SetParticlePosition(G4ThreeVector(0.,0.,-50.)*cm)
# medical beam
beam= MedicalBeam.Construct()
beam.particle= "proton"
beam.kineticE= 230.*MeV
#beam.particle= "gamma"
#beam.kineticE= 1.77*MeV
beam.sourcePosition= G4ThreeVector(0.,0.,-100.*cm)
beam.SSD= 100.*cm
beam.fieldXY= [5.*cm, 5.*cm]
# initialize
gRunManager.Initialize()
# set SD (A SD should be set after geometry construction)
scoreSD= ScoreSD()
myDC.SetSDtoScoreVoxel(scoreSD)
# visualization
gApplyUICommand("/control/execute vis.mac")
# beamOn
gRunManager.BeamOn(100)
#ROOT.gSystem.Run()
@@ -0,0 +1,14 @@
# $Id: GNUmakefile,v 1.1 2006/05/11 04:35:32 kmura Exp $
# $Name: geant4-08-01 $
# ===========================================================
# Makefile for building Geant4Py modules
# ===========================================================
include ../../../../config/config.gmk
# python module name
MODULE := ../demo_wp#
include $(G4PY_INSTALL)/config/g4py.gmk
include $(G4PY_INSTALL)/config/module.gmk
@@ -0,0 +1,137 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: MyDetectorConstruction.cc,v 1.3 2006/06/29 15:28:11 gunter Exp $
// $Name: geant4-08-01 $
// ====================================================================
// MyDetectorConstruction.cc
//
// 2005 Q
// ====================================================================
#include "MyDetectorConstruction.hh"
#include "G4Material.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4VisAttributes.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////////////////////////
MyDetectorConstruction::MyDetectorConstruction()
: scoreVoxel(0)
////////////////////////////////////////////////
{
}
/////////////////////////////////////////////////
MyDetectorConstruction::~MyDetectorConstruction()
/////////////////////////////////////////////////
{
}
//////////////////////////////////////////////////////
G4VPhysicalVolume* MyDetectorConstruction::Construct()
//////////////////////////////////////////////////////
{
G4Material* mate;
G4VisAttributes* va;
// ==============================================================
// world volume
// ==============================================================
G4Box* areaSolid= new G4Box("area", 25.*cm, 25.*cm, 1.1*m);
G4Material* vacuum= G4Material::GetMaterial("Vacuum");
G4LogicalVolume* areaLV= new G4LogicalVolume(areaSolid, vacuum, "area");
G4PVPlacement* area= new G4PVPlacement(0, G4ThreeVector(), "area",
areaLV, 0, false, 0);
// vis. attributes
va= new G4VisAttributes(G4Color(1.,1.,1.));
va-> SetVisibility(false);
areaLV-> SetVisAttributes(va);
// ==============================================================
// phantom
// ==============================================================
// water phantom
const double dxyphantom= 40.*cm;
const double dzphantom= 50.*cm;
G4Box* sphantom= new G4Box("phantom",
dxyphantom/2., dxyphantom/2., dzphantom/2.);
G4Material* water= G4Material::GetMaterial("Water");
G4LogicalVolume* lphantom= new G4LogicalVolume(sphantom,
water, "phantom");
G4PVPlacement* phantom= new G4PVPlacement(0,
G4ThreeVector(0.,0., dzphantom/2.),
lphantom, "phantom",
areaLV, false, 0);
va= new G4VisAttributes(G4Color(0.,0.1,0.8));
lphantom-> SetVisAttributes(va);
// score voxels
const G4double dvoxel= 2.*mm;
const G4double dvoxel_y= 20.*mm;
G4Box* svoxel= new G4Box("voxel", dvoxel/2., dvoxel_y/2., dvoxel/2.);
scoreVoxel= new G4LogicalVolume(svoxel, water, "voxel");
va= new G4VisAttributes(G4Color(0.,0.8,0.8));
va-> SetVisibility(false);
scoreVoxel-> SetVisAttributes(va);
G4int ix, iz;
G4int index=0;
for (iz=0; iz<200; iz++) {
for (ix=-40; ix<=40; ix++) {
G4double x0= ix*dvoxel;
G4double z0= -dzphantom/2.+(iz+0.5)*dvoxel;
G4PVPlacement* pvoxel= new
G4PVPlacement(0, G4ThreeVector(x0, 0., z0),
scoreVoxel, "voxel", lphantom,
false, index);
index++;
}
}
return area;
}
/////////////////////////////////////////////////////////////////////////
void MyDetectorConstruction::SetSDtoScoreVoxel(G4VSensitiveDetector* asd)
/////////////////////////////////////////////////////////////////////////
{
if(scoreVoxel) {
scoreVoxel-> SetSensitiveDetector(asd);
}
}
@@ -0,0 +1,60 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: MyDetectorConstruction.hh,v 1.3 2006/06/29 15:28:13 gunter Exp $
// $Name: geant4-08-01 $
// ====================================================================
// MyDetectorConstruction.hh
//
// 2005 Q
// ====================================================================
#ifndef MY_DETECTOR_CONSTRUCTION_H
#define MY_DETECTOR_CONSTRUCTION_H
#include "G4VUserDetectorConstruction.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class G4LogicalVolume;
class G4VSensitiveDetector;
class MyDetectorConstruction : public G4VUserDetectorConstruction {
private:
G4LogicalVolume* scoreVoxel;
public:
MyDetectorConstruction();
~MyDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
void SetSDtoScoreVoxel(G4VSensitiveDetector* asd);
};
#endif
@@ -0,0 +1,121 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: MyMaterials.cc,v 1.3 2006/06/29 15:28:16 gunter Exp $
// $Name: geant4-08-01 $
// ====================================================================
// MyMaterials.cc
//
// 2005 Q
// ====================================================================
#include "MyMaterials.hh"
#include "G4Material.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////
MyMaterials::MyMaterials()
//////////////////////////
{
}
///////////////////////////
MyMaterials::~MyMaterials()
///////////////////////////
{
}
/////////////////////////////
void MyMaterials::Construct()
/////////////////////////////
{
G4double A, Z;
// ------------------------------------------------------------------------
// Elements
// ------------------------------------------------------------------------
G4Element* elH = new G4Element("Hydrogen","H", Z=1., A=1.00794*g/mole);
G4Element* elC = new G4Element("Carbon", "C", Z=6., A= 12.011 *g/mole);
G4Element* elN = new G4Element("Nitrogen","N", Z=7., A= 14.00674*g/mole);
G4Element* elO = new G4Element("Oxygen", "O", Z=8., A= 15.9994*g/mole);
// ------------------------------------------------------------------------
// Materials
// ------------------------------------------------------------------------
G4double density, massfraction;
G4int natoms, nel;
// temperature of experimental hall is controlled at 20 degree.
const G4double expTemp= STP_Temperature+20.*kelvin;
// vacuum
density= universe_mean_density;
G4Material* Vacuum= new G4Material("Vacuum", density, nel=2);
Vacuum-> AddElement(elN, .7);
Vacuum-> AddElement(elO, .3);
// air
density= 1.2929e-03 *g/cm3; // at 20 degree
G4Material* Air= new G4Material("Air", density, nel=2,
kStateGas, expTemp);
G4double ttt= 75.47+23.20;
Air-> AddElement(elN, massfraction= 75.47/ttt);
Air-> AddElement(elO, massfraction= 23.20/ttt);
// water
density= 1.000*g/cm3;
G4Material* H2O= new G4Material("Water", density, nel=2);
H2O-> AddElement(elH, natoms=2);
H2O-> AddElement(elO, natoms=1);
// alminium
A= 26.98 *g/mole;
density= 2.70 *g/cm3;
G4Material* Al= new G4Material("Al", Z=13., A, density);
// iron
A= 55.847 *g/mole;
density= 7.87 *g/cm3;
G4Material* Fe= new G4Material("Iron", Z=26., A, density);
// lead
A= 207.2 *g/mole;
density= 11.35 *g/cm3;
G4Material* Pb= new G4Material("Lead", Z=82., A, density);
// scintillator (Polystyene(C6H5CH=CH2))
density= 1.032 *g/cm3;
G4Material* Scinti= new G4Material("Scinti", density, nel=2);
Scinti-> AddElement(elC, natoms=8);
Scinti-> AddElement(elH, natoms=8);
}
@@ -0,0 +1,52 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: MyMaterials.hh,v 1.3 2006/06/29 15:28:19 gunter Exp $
// $Name: geant4-08-01 $
// ====================================================================
// MyMaterials.hh
//
// 2005 Q
// ====================================================================
#ifndef MY_MATERIALS_H
#define MY_MATERIALS_H
#include "globals.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class MyMaterials {
public:
MyMaterials();
~MyMaterials();
void Construct();
};
#endif
@@ -0,0 +1,69 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: MyPhysicsList.cc,v 1.3 2006/06/29 15:28:21 gunter Exp $
// $Name: geant4-08-01 $
// ====================================================================
// MyPhysicsList.cc
//
// 2005 Q
// ====================================================================
#include "MyPhysicsList.hh"
#include "Particles.hh"
#include "PhysicsListEMstd.hh"
#include "PhysicsListLHad.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////
MyPhysicsList::MyPhysicsList()
: G4VModularPhysicsList()
//////////////////////////////
{
defaultCutValue = 1.*mm;
SetVerboseLevel(1);
RegisterPhysics(new Particles);
RegisterPhysics(new PhysicsListEMstd);
RegisterPhysics(new PhysicsListLHad);
}
///////////////////////////////
MyPhysicsList::~MyPhysicsList()
///////////////////////////////
{
}
/////////////////////////////
void MyPhysicsList::SetCuts()
/////////////////////////////
{
SetCutsWithDefault();
}
@@ -0,0 +1,53 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: MyPhysicsList.hh,v 1.3 2006/06/29 15:28:23 gunter Exp $
// $Name: geant4-08-01 $
// ====================================================================
// MyPhysicsList.hh
//
// 2005 Q
// ====================================================================
#ifndef MY_PHYSICS_LIST_H
#define MY_PHYSICS_LIST_H
#include "G4VModularPhysicsList.hh"
#include "globals.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class MyPhysicsList: public G4VModularPhysicsList {
public:
MyPhysicsList();
~MyPhysicsList();
virtual void SetCuts();
};
#endif
@@ -0,0 +1,82 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: Particles.cc,v 1.3 2006/06/29 15:28:25 gunter Exp $
// $Name: geant4-08-01 $
// ====================================================================
// Particles.cc
//
// Physics list for defining particles
//
// ====================================================================
#include "Particles.hh"
#include "G4LeptonConstructor.hh"
#include "G4BosonConstructor.hh"
#include "G4MesonConstructor.hh"
#include "G4BaryonConstructor.hh"
#include "G4ShortLivedConstructor.hh"
#include "G4IonConstructor.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////////
Particles::Particles()
: G4VPhysicsConstructor("Particles")
//////////////////////////////////////
{
}
///////////////////////
Particles::~Particles()
///////////////////////
{
}
///////////////////////////////////
void Particles::ConstructParticle()
///////////////////////////////////
{
G4LeptonConstructor::ConstructParticle();
G4BosonConstructor::ConstructParticle();
G4MesonConstructor::ConstructParticle();
G4BaryonConstructor::ConstructParticle();
G4ShortLivedConstructor::ConstructParticle();
G4IonConstructor::ConstructParticle();
}
//////////////////////////////////
void Particles::ConstructProcess()
//////////////////////////////////
{
}
@@ -0,0 +1,54 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: Particles.hh,v 1.3 2006/06/29 15:28:27 gunter Exp $
// ====================================================================
// Particles.hh
//
// 2004 Q
// ====================================================================
#ifndef PARTICLES_H
#define PARTICLES_H
#include "G4VPhysicsConstructor.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class Particles : public G4VPhysicsConstructor {
public:
Particles();
~Particles();
virtual void ConstructParticle();
virtual void ConstructProcess();
};
#endif
@@ -0,0 +1,123 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: PhysicsListEMstd.cc,v 1.3 2006/06/29 15:28:29 gunter Exp $
// $Name: geant4-08-01 $
// ====================================================================
// PhysicsListEMstd.cc
//
// Physics list for electron/positron/gamma
// EM-standard package w/ default parameters
//
// ====================================================================
#include "PhysicsListEMstd.hh"
#include "G4ProcessManager.hh"
#include "G4ParticleDefinition.hh"
#include "G4Gamma.hh"
#include "G4Electron.hh"
#include "G4Positron.hh"
#include "G4NeutrinoE.hh"
#include "G4AntiNeutrinoE.hh"
#include "G4ComptonScattering.hh"
#include "G4GammaConversion.hh"
#include "G4PhotoElectricEffect.hh"
#include "G4MultipleScattering.hh"
#include "G4eIonisation.hh"
#include "G4eBremsstrahlung.hh"
#include "G4eplusAnnihilation.hh"
// ====================================================================
//
// class description
//
// ====================================================================
////////////////////////////////////
PhysicsListEMstd::PhysicsListEMstd()
: G4VPhysicsConstructor("EM-std")
////////////////////////////////////
{
}
/////////////////////////////////////
PhysicsListEMstd::~PhysicsListEMstd()
/////////////////////////////////////
{
}
//////////////////////////////////////////
void PhysicsListEMstd::ConstructParticle()
//////////////////////////////////////////
{
}
/////////////////////////////////////////
void PhysicsListEMstd::ConstructProcess()
/////////////////////////////////////////
{
G4ProcessManager* pm;
// ----------------------------------------------------------
// gamma physics
// ----------------------------------------------------------
pm= G4Gamma::Gamma()-> GetProcessManager();
pm-> AddDiscreteProcess(new G4PhotoElectricEffect);
pm-> AddDiscreteProcess(new G4ComptonScattering);
pm-> AddDiscreteProcess(new G4GammaConversion);
// ----------------------------------------------------------
// electron physics
// ----------------------------------------------------------
G4MultipleScattering* msc= new G4MultipleScattering;
G4eIonisation* eion= new G4eIonisation;
G4eBremsstrahlung* ebrems= new G4eBremsstrahlung;
pm= G4Electron::Electron()->GetProcessManager();
pm-> AddProcess(msc, ordInActive, 1, 1);
pm-> AddProcess(eion, ordInActive, 2, 2);
pm-> AddProcess(ebrems, ordInActive, ordInActive, 3);
// ----------------------------------------------------------
// positron physics
// ----------------------------------------------------------
msc= new G4MultipleScattering;
eion= new G4eIonisation;
ebrems= new G4eBremsstrahlung;
G4eplusAnnihilation* annihilation= new G4eplusAnnihilation;
pm= G4Positron::Positron()-> GetProcessManager();
pm-> AddProcess(msc, ordInActive, 1, 1);
pm-> AddProcess(eion, ordInActive, 2, 2);
pm-> AddProcess(ebrems, ordInActive, ordInActive, 3);
pm-> AddProcess(annihilation, 0, ordInActive, 4);
}
@@ -0,0 +1,54 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: PhysicsListEMstd.hh,v 1.3 2006/06/29 15:28:32 gunter Exp $
// ====================================================================
// PhysicsListEMstd.hh
//
// 2004 Q
// ====================================================================
#ifndef PHYSICS_LIST_EM_STD_H
#define PHYSICS_LIST_EM_STD_H
#include "G4VPhysicsConstructor.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class PhysicsListEMstd : public G4VPhysicsConstructor {
public:
PhysicsListEMstd();
~PhysicsListEMstd();
virtual void ConstructParticle();
virtual void ConstructProcess();
};
#endif
@@ -0,0 +1,396 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: PhysicsListLHad.cc,v 1.3 2006/06/29 15:28:35 gunter Exp $
// ====================================================================
// PhysicsListLHad.cc
//
// Light package of hadron physics
// ====================================================================
#include "PhysicsListLHad.hh"
#include "G4ProcessManager.hh"
#include "G4ParticleDefinition.hh"
#include "G4MultipleScattering.hh"
#include "G4hIonisation.hh"
// Hadronic Processes
#include "G4HadronElasticProcess.hh"
#include "G4HadronFissionProcess.hh"
#include "G4HadronCaptureProcess.hh"
#include "G4ProtonInelasticProcess.hh"
#include "G4AntiProtonInelasticProcess.hh"
#include "G4NeutronInelasticProcess.hh"
#include "G4AntiNeutronInelasticProcess.hh"
#include "G4PionPlusInelasticProcess.hh"
#include "G4PionMinusInelasticProcess.hh"
#include "G4KaonPlusInelasticProcess.hh"
#include "G4KaonZeroSInelasticProcess.hh"
#include "G4KaonZeroLInelasticProcess.hh"
#include "G4KaonMinusInelasticProcess.hh"
// Low energy models
#include "G4LElastic.hh"
#include "G4LFission.hh"
#include "G4LCapture.hh"
#include "G4LEProtonInelastic.hh"
#include "G4LEAntiProtonInelastic.hh"
#include "G4LENeutronInelastic.hh"
#include "G4LEAntiNeutronInelastic.hh"
#include "G4LEPionPlusInelastic.hh"
#include "G4LEPionMinusInelastic.hh"
#include "G4LEKaonPlusInelastic.hh"
#include "G4LEKaonZeroSInelastic.hh"
#include "G4LEKaonZeroLInelastic.hh"
#include "G4LEKaonMinusInelastic.hh"
// High-energy Models
#include "G4HEProtonInelastic.hh"
#include "G4HEAntiProtonInelastic.hh"
#include "G4HEPionPlusInelastic.hh"
#include "G4HEPionMinusInelastic.hh"
#include "G4HEKaonPlusInelastic.hh"
#include "G4HEKaonZeroInelastic.hh"
#include "G4HEKaonZeroInelastic.hh"
#include "G4HEKaonMinusInelastic.hh"
// Stopping processes
#include "G4AntiProtonAnnihilationAtRest.hh"
// Binary Cascade
#include "G4BinaryCascade.hh"
#include "G4ProtonInelasticCrossSection.hh"
// ====================================================================
//
// class description
//
// ====================================================================
//////////////////////////////////
PhysicsListLHad::PhysicsListLHad()
: G4VPhysicsConstructor("LHad")
//////////////////////////////////
{
}
///////////////////////////////////
PhysicsListLHad::~PhysicsListLHad()
///////////////////////////////////
{
}
/////////////////////////////////////////
void PhysicsListLHad::ConstructParticle()
/////////////////////////////////////////
{
}
////////////////////////////////////////
void PhysicsListLHad::ConstructProcess()
////////////////////////////////////////
{
G4ProcessManager* pManager;
// ---------------------------------------------------------------
// proton
// ---------------------------------------------------------------
pManager= G4Proton::Proton()-> GetProcessManager();
// elastic
G4HadronElasticProcess* thepElasticProcess = new G4HadronElasticProcess();
G4LElastic* thepElasticModel = new G4LElastic();
thepElasticProcess->RegisterMe(thepElasticModel);
pManager-> AddDiscreteProcess(thepElasticProcess);
// inelastic
G4ProtonInelasticProcess* theProtonInelasticProcess
= new G4ProtonInelasticProcess();
G4HEProtonInelastic* theProtonHEPModel = new G4HEProtonInelastic();
G4LEProtonInelastic* theProtonLEPModel = new G4LEProtonInelastic();
theProtonLEPModel->SetMinEnergy(2.8*GeV);
G4BinaryCascade* theProtonBICModel = new G4BinaryCascade();
theProtonBICModel->SetMaxEnergy(3.2*GeV);
theProtonInelasticProcess-> RegisterMe(theProtonHEPModel);
theProtonInelasticProcess-> RegisterMe(theProtonLEPModel);
theProtonInelasticProcess-> RegisterMe(theProtonBICModel);
// add Xsection data of BIC
G4ProtonInelasticCrossSection* theProtonInelasticData
= new G4ProtonInelasticCrossSection();
theProtonInelasticProcess-> AddDataSet( theProtonInelasticData );
pManager-> AddDiscreteProcess(theProtonInelasticProcess);
// QED
G4VProcess* thepMultipleScattering = new G4MultipleScattering();
G4VProcess* thepIonisation = new G4hIonisation();
pManager-> AddProcess(thepIonisation);
pManager-> AddProcess(thepMultipleScattering);
pManager-> SetProcessOrdering(thepMultipleScattering, idxAlongStep, 1);
pManager-> SetProcessOrdering(thepIonisation, idxAlongStep, 2);
pManager-> SetProcessOrdering(thepMultipleScattering, idxPostStep, 1);
pManager-> SetProcessOrdering(thepIonisation, idxPostStep, 2);
// ---------------------------------------------------------------
// anti-proton
// ---------------------------------------------------------------
pManager= G4AntiProton::AntiProton()-> GetProcessManager();
// elastic
G4HadronElasticProcess* theapElasticProcess = new G4HadronElasticProcess();
G4LElastic* theapElasticModel = new G4LElastic();
theapElasticProcess-> RegisterMe(theapElasticModel);
pManager-> AddDiscreteProcess(theapElasticProcess);
// inelastic
G4AntiProtonInelasticProcess* theAntiProtonInelasticProcess
= new G4AntiProtonInelasticProcess();
G4LEAntiProtonInelastic* theAntiProtonLEPModel
= new G4LEAntiProtonInelastic();
G4HEAntiProtonInelastic* theAntiProtonHEPModel
= new G4HEAntiProtonInelastic();
theAntiProtonInelasticProcess-> RegisterMe(theAntiProtonLEPModel);
theAntiProtonInelasticProcess-> RegisterMe(theAntiProtonHEPModel);
pManager-> AddDiscreteProcess(theAntiProtonInelasticProcess);
G4AntiProtonAnnihilationAtRest* theAntiProtonAnnihilation
= new G4AntiProtonAnnihilationAtRest();
pManager-> AddRestProcess(theAntiProtonAnnihilation);
// QED
G4VProcess* theapMultipleScattering = new G4MultipleScattering();
G4VProcess* theapIonisation = new G4hIonisation();
pManager-> AddProcess(theapIonisation);
pManager-> AddProcess(theapMultipleScattering);
pManager->SetProcessOrdering(theapMultipleScattering, idxAlongStep, 1);
pManager->SetProcessOrdering(theapIonisation, idxAlongStep, 2);
pManager->SetProcessOrdering(theapMultipleScattering, idxPostStep, 1);
pManager->SetProcessOrdering(theapIonisation, idxPostStep, 2);
// ---------------------------------------------------------------
// mesons...
// ---------------------------------------------------------------
// ---------------------------------------------------------------
// pi+
// ---------------------------------------------------------------
pManager= G4PionPlus::PionPlus()-> GetProcessManager();
// elastic
G4HadronElasticProcess* theppElasticProcess = new G4HadronElasticProcess();
G4LElastic* theppElasticModel = new G4LElastic();
theppElasticProcess-> RegisterMe(theppElasticModel);
pManager-> AddDiscreteProcess(theppElasticProcess);
// inelastic
G4PionPlusInelasticProcess* thePionPlusInelasticProcess
= new G4PionPlusInelasticProcess();
G4LEPionPlusInelastic* thePionPlusLEPModel = new G4LEPionPlusInelastic();
G4HEPionPlusInelastic* thePionPlusHEPModel = new G4HEPionPlusInelastic();
thePionPlusInelasticProcess->RegisterMe(thePionPlusLEPModel);
thePionPlusInelasticProcess->RegisterMe(thePionPlusHEPModel);
pManager-> AddDiscreteProcess(thePionPlusInelasticProcess);
// QED
G4VProcess* theppMultipleScattering = new G4MultipleScattering();
G4VProcess* theppIonisation = new G4hIonisation();
pManager-> AddProcess(theppIonisation);
pManager-> AddProcess(theppMultipleScattering);
pManager-> SetProcessOrdering(theppMultipleScattering, idxAlongStep, 1);
pManager-> SetProcessOrdering(theppIonisation, idxAlongStep, 2);
pManager-> SetProcessOrdering(theppMultipleScattering, idxPostStep, 1);
pManager-> SetProcessOrdering(theppIonisation, idxPostStep, 2);
// ---------------------------------------------------------------
// pi-
// ---------------------------------------------------------------
pManager= G4PionMinus::PionMinus()-> GetProcessManager();
// elastic
G4HadronElasticProcess* thepmElasticProcess = new G4HadronElasticProcess();
G4LElastic* thepmElasticModel = new G4LElastic();
thepmElasticProcess->RegisterMe(thepmElasticModel);
pManager-> AddDiscreteProcess(thepmElasticProcess);
// inelastic
G4PionMinusInelasticProcess* thePionMinusInelasticProcess
= new G4PionMinusInelasticProcess();
G4LEPionMinusInelastic* thePionMinusLEPModel = new G4LEPionMinusInelastic();
G4HEPionMinusInelastic* thePionMinusHEPModel = new G4HEPionMinusInelastic();
thePionMinusInelasticProcess-> RegisterMe(thePionMinusLEPModel);
thePionMinusInelasticProcess-> RegisterMe(thePionMinusHEPModel);
pManager-> AddDiscreteProcess(thePionMinusInelasticProcess);
// QED
G4VProcess* thepmMultipleScattering = new G4MultipleScattering();
G4VProcess* thepmIonisation = new G4hIonisation();
pManager-> AddProcess(thepmIonisation);
pManager-> AddProcess(thepmMultipleScattering);
pManager-> SetProcessOrdering(thepmMultipleScattering, idxAlongStep, 1);
pManager-> SetProcessOrdering(thepmIonisation, idxAlongStep, 2);
pManager-> SetProcessOrdering(thepmMultipleScattering, idxPostStep, 1);
pManager-> SetProcessOrdering(thepmIonisation, idxPostStep, 2);
// ---------------------------------------------------------------
// K+
// ---------------------------------------------------------------
pManager= G4KaonPlus::KaonPlus()-> GetProcessManager();
// elastic
G4HadronElasticProcess* thekpElasticProcess = new G4HadronElasticProcess();
G4LElastic* thekpElasticModel = new G4LElastic();
thekpElasticProcess->RegisterMe(thekpElasticModel);
pManager->AddDiscreteProcess(thekpElasticProcess);
// inelastic
G4KaonPlusInelasticProcess* theKaonPlusInelasticProcess
= new G4KaonPlusInelasticProcess();
G4LEKaonPlusInelastic* theKaonPlusLEPModel = new G4LEKaonPlusInelastic();
G4HEKaonPlusInelastic* theKaonPlusHEPModel = new G4HEKaonPlusInelastic();
theKaonPlusInelasticProcess-> RegisterMe(theKaonPlusLEPModel);
theKaonPlusInelasticProcess-> RegisterMe(theKaonPlusHEPModel);
pManager-> AddDiscreteProcess(theKaonPlusInelasticProcess);
// QED
G4VProcess* thekpMultipleScattering = new G4MultipleScattering();
G4VProcess* thekpIonisation = new G4hIonisation();
pManager-> AddProcess(thekpIonisation);
pManager-> AddProcess(thekpMultipleScattering);
pManager-> SetProcessOrdering(thekpMultipleScattering, idxAlongStep, 1);
pManager-> SetProcessOrdering(thekpIonisation, idxAlongStep, 2);
pManager-> SetProcessOrdering(thekpMultipleScattering, idxPostStep, 1);
pManager-> SetProcessOrdering(thekpIonisation, idxPostStep, 2);
// ---------------------------------------------------------------
// K-
// ---------------------------------------------------------------
pManager= G4KaonMinus::KaonMinus()->GetProcessManager();
// elastic
G4HadronElasticProcess* thekmElasticProcess = new G4HadronElasticProcess();
G4LElastic* thekmElasticModel = new G4LElastic();
thekmElasticProcess->RegisterMe(thekmElasticModel);
pManager->AddDiscreteProcess(thekmElasticProcess);
// inelastic
G4KaonMinusInelasticProcess* theKaonMinusInelasticProcess
= new G4KaonMinusInelasticProcess();
G4LEKaonMinusInelastic* theKaonMinusLEPModel = new G4LEKaonMinusInelastic();
G4HEKaonMinusInelastic* theKaonMinusHEPModel = new G4HEKaonMinusInelastic();
theKaonMinusInelasticProcess->RegisterMe(theKaonMinusLEPModel);
theKaonMinusInelasticProcess->RegisterMe(theKaonMinusHEPModel);
pManager->AddDiscreteProcess(theKaonMinusInelasticProcess);
// QED
G4VProcess* thekmMultipleScattering = new G4MultipleScattering();
G4VProcess* thekmIonisation = new G4hIonisation();
pManager-> AddProcess(thekmIonisation);
pManager-> AddProcess(thekmMultipleScattering);
pManager->SetProcessOrdering(thekmMultipleScattering, idxAlongStep, 1);
pManager->SetProcessOrdering(thekmIonisation, idxAlongStep, 2);
pManager->SetProcessOrdering(thekmMultipleScattering, idxPostStep, 1);
pManager->SetProcessOrdering(thekmIonisation, idxPostStep, 2);
// ---------------------------------------------------------------
// K0L
// ---------------------------------------------------------------
pManager= G4KaonZeroLong::KaonZeroLong()-> GetProcessManager();
// elastic
G4HadronElasticProcess* thek0lElasticProcess = new G4HadronElasticProcess();
G4LElastic* thek0lElasticModel = new G4LElastic();
thek0lElasticProcess-> RegisterMe(thek0lElasticModel);
pManager-> AddDiscreteProcess(thek0lElasticProcess);
// inelastic
G4KaonZeroLInelasticProcess* theKaonZeroLInelasticProcess
= new G4KaonZeroLInelasticProcess();
G4LEKaonZeroLInelastic* theKaonZeroLLEPModel = new G4LEKaonZeroLInelastic();
G4HEKaonZeroInelastic* theKaonZerolHEPModel = new G4HEKaonZeroInelastic();
theKaonZeroLInelasticProcess-> RegisterMe(theKaonZeroLLEPModel);
theKaonZeroLInelasticProcess-> RegisterMe(theKaonZerolHEPModel);
pManager-> AddDiscreteProcess(theKaonZeroLInelasticProcess);
// ---------------------------------------------------------------
// K0S
// ---------------------------------------------------------------
pManager= G4KaonZeroShort::KaonZeroShort()-> GetProcessManager();
// elastic
G4HadronElasticProcess* thek0sElasticProcess = new G4HadronElasticProcess();
G4LElastic* thek0sElasticModel = new G4LElastic();
thek0sElasticProcess-> RegisterMe(thek0sElasticModel);
pManager-> AddDiscreteProcess(thek0sElasticProcess);
// inelastic
G4KaonZeroSInelasticProcess* theKaonZeroSInelasticProcess
= new G4KaonZeroSInelasticProcess();
G4LEKaonZeroSInelastic* theKaonZeroSLEPModel = new G4LEKaonZeroSInelastic();
G4HEKaonZeroInelastic* theKaonZerosHEPModel = new G4HEKaonZeroInelastic();
theKaonZeroSInelasticProcess-> RegisterMe(theKaonZeroSLEPModel);
theKaonZeroSInelasticProcess-> RegisterMe(theKaonZerosHEPModel);
pManager-> AddDiscreteProcess(theKaonZeroSInelasticProcess);
}
@@ -0,0 +1,54 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: PhysicsListLHad.hh,v 1.3 2006/06/29 15:28:37 gunter Exp $
// ====================================================================
// PhysicsListLHad.hh
//
// 2004 Q
// ====================================================================
#ifndef PHYSICS_L_HAD_H
#define PHYSICS_L_HAD_H
#include "G4VPhysicsConstructor.hh"
// ====================================================================
//
// class definition
//
// ====================================================================
class PhysicsListLHad : public G4VPhysicsConstructor {
public:
PhysicsListLHad();
~PhysicsListLHad();
virtual void ConstructParticle();
virtual void ConstructProcess();
};
#endif
@@ -0,0 +1,63 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: pydemo_wp.cc,v 1.3 2006/06/29 15:28:40 gunter Exp $
// $Name: geant4-08-01 $
// ====================================================================
// pydemo_wp.cc
//
// python wrapper for user application
// 2005 Q
// ====================================================================
#include <boost/python.hpp>
#include "MyMaterials.hh"
#include "MyDetectorConstruction.hh"
#include "MyPhysicsList.hh"
#include "G4VSensitiveDetector.hh"
using namespace boost::python;
// ====================================================================
// Expose to Python
// ====================================================================
BOOST_PYTHON_MODULE(demo_wp) {
class_<MyMaterials>("MyMaterials", "my material")
.def("Construct", &MyMaterials::Construct)
;
class_<MyDetectorConstruction, MyDetectorConstruction*,
bases<G4VUserDetectorConstruction> >
("MyDetectorConstruction", "my detector")
.def("SetSDtoScoreVoxel", &MyDetectorConstruction::SetSDtoScoreVoxel)
;
class_<MyPhysicsList, MyPhysicsList*,
bases<G4VUserPhysicsList> >
("MyPhysicsList", "my physics list")
;
}
+92
View File
@@ -0,0 +1,92 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# ==================================================================
from Geant4 import *
import demo_wp
# ==================================================================
# user actions in python
# ==================================================================
class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
"My Primary Generator Action"
def __init__(self):
G4VUserPrimaryGeneratorAction.__init__(self)
self.particleGun= G4ParticleGun(1)
def GeneratePrimaries(self, event):
self.particleGun.GeneratePrimaryVertex(event)
# ------------------------------------------------------------------
class MyRunAction(G4UserRunAction):
"My Run Action"
def EndOfRunAction(self, run):
print "*** End of Run"
print "- Run sammary : (id= %d, #events= %d)" \
% (run.GetRunID(), run.GetNumberOfEventToBeProcessed())
# ------------------------------------------------------------------
class MyEventAction(G4UserEventAction):
"My Event Action"
def EndOfEventAction(self, event):
pass
# ------------------------------------------------------------------
class MySteppingAction(G4UserSteppingAction):
"My Stepping Action"
def UserSteppingAction(self, step):
pass
#print "*** dE/dx in current step=", step.GetTotalEnergyDeposit()
preStepPoint= step.GetPreStepPoint()
track= step.GetTrack()
touchable= track.GetTouchable()
#print "*** vid= ", touchable.GetReplicaNumber()
# ==================================================================
# main
# ==================================================================
myMaterials= demo_wp.MyMaterials()
myMaterials.Construct()
myDC= demo_wp.MyDetectorConstruction()
gRunManager.SetUserInitialization(myDC)
myPL= demo_wp.MyPhysicsList()
gRunManager.SetUserInitialization(myPL)
# set user actions...
myPGA= MyPrimaryGeneratorAction()
gRunManager.SetUserAction(myPGA)
myRA= MyRunAction()
gRunManager.SetUserAction(myRA)
myEA= MyEventAction()
gRunManager.SetUserAction(myEA)
mySA= MySteppingAction()
gRunManager.SetUserAction(mySA)
# set particle gun
pg= myPGA.particleGun
pg.SetParticleByName("proton")
pg.SetParticleEnergy(230.*HEPUnit.MeV)
pg.SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.))
pg.SetParticlePosition(G4ThreeVector(0.,0.,-20.)*HEPUnit.cm)
gRunManager.Initialize()
# visualization
gApplyUICommand("/control/execute vis.mac")
# beamOn
#gRunManager.BeamOn(3)
@@ -0,0 +1,17 @@
# vis.mac
/vis/open OGLIX
#/vis/open OGLSX
/vis/scene/create
/vis/scene/add/volume
/vis/sceneHandler/attach
/vis/viewer/set/viewpointThetaPhi 90. 0.
/tracking/storeTrajectory 1
/vis/scene/add/trajectories
/vis/scene/endOfEventAction accumulate
#/vis/scene/endOfEventAction refresh
@@ -0,0 +1,24 @@
09 March 2006
Hajime Yoshida
The first version of mass attenuation coefficient
- Lesson1.py
select absorber material
set its thickness upto 500 mm
select beam particle
set its energy upto 100 MeV
set nu of events up to 100
run
and then
zoom in (x1.1) or zoom out (x0.9)
execute any G4 command but /gun/particle or /gun/energy which are
defined by the above
-oglx.mac
OGLSX => important to make zooming effective after showing trajectories
-gun.mac
@@ -0,0 +1,296 @@
#!/usr/bin/python
# ==================================================================
# python script for "measurement" of mass attenuation coefficient
#
#
# - using site-module packages
# ==================================================================
from Geant4 import *
import NISTmaterials
from EZsim import EZgeom
from EZsim.EZgeom import G4EzVolume
import EMSTDpl
import ParticleGun
from time import *
import sys
# ==================================================================
# intialize
# ==================================================================
def Configure():
# ------------------------------------------------------------------
# setup for materials
# ------------------------------------------------------------------
# simple materials for Qgeom
NISTmaterials.Construct()
# ------------------------------------------------------------------
# setup for geometry
# ------------------------------------------------------------------
#Qgeom.Construct()
EZgeom.Construct() # initialize
# ------------------------------------------------------------------
# setup for physics list
# ------------------------------------------------------------------
EMSTDpl.Construct()
# ------------------------------------------------------------------
# setup for primary generator action
# ------------------------------------------------------------------
ParticleGun.Construct()
gControlExecute("gun.mac")
# ==================================================================
# constructing geometry
# ==================================================================
def ConstructGeom():
print "* Constructing geometry..."
# reset world material
global absorber
air= G4Material.GetMaterial("G4_AIR", 1)
galactic = G4Material.GetMaterial("G4_Galactic", 1)
absorber = {} # material's dictionary to be used by a radiobutton
aluminum = G4Material.GetMaterial("G4_Al", 1)
iron = G4Material.GetMaterial("G4_Fe", 1)
silver = G4Material.GetMaterial("G4_Ag", 1)
gold = G4Material.GetMaterial("G4_Au", 1)
lead = G4Material.GetMaterial("G4_Pb", 1)
water = G4Material.GetMaterial("G4_WATER", 1)
absorber = {"air":air, "aluminum":aluminum, "iron":iron, "lead":lead, "water":water, "gold":gold}
EZgeom.SetWorldMaterial(galactic)
EZgeom.ResizeWorld(120.*cm, 120.*cm, 100.*cm)
# water phantom
global water_phantom, water_phantom_pv
water_phantom= G4EzVolume("WaterPhantom")
water_phantom.CreateBoxVolume(water, 110.*cm, 110.*cm, 10.*cm)
water_phantom_pv = water_phantom.PlaceIt(G4ThreeVector(0.,0.,0.*cm))
# ==================================================================
# main
# ==================================================================
# ------------------------------------------------------------------
# randum number
# ------------------------------------------------------------------
print "Random numbers..."
rand_engine= Ranlux64Engine()
HepRandom.setTheEngine(rand_engine)
HepRandom.setTheSeed(20050830L)
# setup...
Configure()
ConstructGeom()
# ------------------------------------------------------------------
# go...
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization not here but after "Start a run" button
gControlExecute("oglx.mac")
#gControlExecute("vrml.mac")
# creating widgets using grid layout
from Tkinter import *
class App(Frame):
def init(self):
#title and header row=0, 1
title = Label(self, text="Geant4Py for Education @ H. Yoshida Naruto Univ. of Education")
title.grid(row=0, column=1, columnspan=5)
header = Label(self, text="Measurement of Mass Attenuation Coefficient")
header.grid(row=1, column=1, columnspan=5)
#material selection row=2
materialLabel = Label(self, bg="green", text="Material")
materialLabel.grid(row=2, column=0, sticky=W)
self.materialVar = StringVar()
self.materialVar.set("water")
ra1 = { }
pos=1
for i in absorber.keys():
ra1[i] = Radiobutton(self, text=i, variable=self.materialVar, value=i)
ra1[i].grid(row=2, column=pos, sticky=W)
pos=pos+1
#absorber thickness row=3
thickLabel = Label(self, bg="green", text="Thickness (mm)")
self.thickVar = DoubleVar()
self.thickVar.set(100.0)
thick = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., resolution=0.05, tickinterval=10.0, digits=4, variable=self.thickVar)
thickLabel.grid(row=3, column=0, sticky=W)
thick.grid(row=3, column=1, columnspan=5, sticky=W)
#get logical volume and set its half length
self.solid = EZgeom.G4EzVolume.GetSold(water_phantom)
#particle row=4
particleLabel = Label(self, bg="green", text="Particle")
particleLabel.grid(row=4, column=0, sticky=W)
self.particleVar = StringVar()
self.particleVar.set("gamma")
ra1 = { }
pos1=1
for i in ("gamma", "e-"):
ra1[i] = Radiobutton(self, text=i, variable=self.particleVar, value=i)
ra1[i].grid(row=4, column=pos1, sticky=W)
pos1=pos1+1
#energy row=5
energyLabel = Label(self, bg="green", text="Energy (MeV)")
self.energyVar=StringVar()
self.energyVar.set(1)
energy = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., tickinterval=10.0, resolution=0.1, variable=self.energyVar, digits=4 )
energyLabel.grid(row=5, column=0, sticky=W)
energy.grid(row=5, column=1, columnspan=5, sticky=W)
#number of event row=6
eventLabel = Label(self, bg="green", text="Events")
self.eventVar=IntVar()
event = Scale(self, orient=HORIZONTAL, length=400, from_=1, to=100, tickinterval=10, resolution=1, variable=self.eventVar )
eventLabel.grid(row=6, column=0, sticky=W)
event.grid(row=6, column=1, columnspan=5, sticky=W)
#start a run button row=7
startBut = Button(self, bg="orange", text="Start a run", command=self.cmd_beamOn)
startBut.grid(row=0, column=0, sticky=W)
#Zoom in/out Pan X Y row=8
visLabel = Label(self, text="viewer", bg="orange")
expandBut = Button(self, text="Zoom in", command=self.cmd_expand)
shrinkBut = Button(self, text="Zoom out", command=self.cmd_shrink)
visLabel.grid(row=8, column=0, sticky=W)
expandBut.grid(row=8, column=1, sticky=W)
shrinkBut.grid(row=8, column=2, sticky=W)
upBut = Button(self, text="Up", command=self.cmd_up)
downBut = Button(self, text="Down", command=self.cmd_down)
upBut.grid(row=8, column=3, sticky=W)
downBut.grid(row=8, column=4, sticky=W)
leftBut = Button(self, text="Left", command=self.cmd_left)
rightBut = Button(self, text="Right", command=self.cmd_right)
leftBut.grid(row=8, column=5, sticky=W)
rightBut.grid(row=8, column=6, sticky=W)
# later
# resetBut = Button(self, text="Reset", command=self.cmd_reset)
# resetBut.grid(row=8, column=7, sticky=W)
# panLabel = Label(self, text="Pan X Y (mm)")
# self.panXYVar = StringVar()
# panXYEnt = Entry(self, textvariable=self.panXYVar)
# panBut = Button(self, bg="orange", text="OK", command=self.cmd_pan)
# panLabel.grid(row=8, column=3, sticky=W)
# panXYEnt.grid(row=8, column=4)
# panBut.grid(row=8, column=5)
#Geant4 command entry row = 9
# g4comLabel = Label(self, text="Geant4 command")
# self.g4commandVar = StringVar()
# commandEntry = Entry(self, textvariable=self.g4commandVar)
# comBut = Button(self, bg="orange", text="Execute", command=self.cmd_g4command)
# g4comLabel.grid(row=9, column=0, sticky=W)
# commandEntry.grid(row=9, column=1, columnspan=4, sticky=E+W)
# comBut.grid(row=9, column=5)
#exit row = 10
exitBut = Button(self, bg="red", text="End all", command=sys.exit)
exitBut.grid(row=0, column=6, sticky=W)
#on Run butto do...
def cmd_beamOn(self):
materialChosen = self.materialVar.get()
water_phantom.SetMaterial(absorber[materialChosen])
if materialChosen == "water":
water_phantom.SetColor(0., 0.9, 1.0)
if materialChosen == "air":
water_phantom.SetColor(0.9, 0.9, 1.0)
if materialChosen == "lead":
water_phantom.SetColor(0.2, 0.2, 0.2)
if materialChosen == "iron":
water_phantom.SetColor(0.7, 0.5, 0.7)
if materialChosen == "aluminum":
water_phantom.SetColor(.7, 0.9, 1.0)
if materialChosen == "gold":
water_phantom.SetColor(1., 0.9, .0)
self.solid.SetZHalfLength(self.thickVar.get() * mm/2.0)
# gControlExecute("oglx.mac") #draw for each run
gApplyUICommand("/vis/viewer/flush")
self.cmd_particle(self.particleVar.get())
self.cmd_energy(self.energyVar.get())
# TODO later to reflesh text
gApplyUICommand("/vis/scene/add/text 0 610 610 mm 20 0 0 " + " ")
gApplyUICommand("/vis/scene/add/text 0 610 610 mm 20 0 0 " + self.materialVar.get() + " = " + str(self.thickVar.get()) + "mm " + self.particleVar.get() + " = "+self.energyVar.get() + "MeV")
eventNum = self.eventVar.get()
for i in range(eventNum):
gunYZpos = str(i-eventNum/2) + ". -20. cm"
gApplyUICommand("/gun/position 0. " + gunYZpos)
gRunManager.BeamOn(1)
sleep(0.01)
# self.cmd_expand() #Zoom in to the last diaplayed OGLSX
# self.cmd_shrink()
def cmd_g4command(self):
gApplyUICommand(self.g4commandVar.get())
def cmd_particle(self, particle):
gApplyUICommand("/gun/particle " + particle)
def cmd_energy(self, penergy):
gApplyUICommand("/gun/energy " + penergy + " MeV")
def cmd_expand(self):
gApplyUICommand("/vis/viewer/zoom 1.2")
def cmd_up(self):
gApplyUICommand("/vis/viewer/pan " + " 0. 10. mm")
def cmd_down(self):
gApplyUICommand("/vis/viewer/pan " + " 0. -10. mm")
def cmd_right(self):
gApplyUICommand("/vis/viewer/pan " + " -1. 0. mm")
def cmd_left(self):
gApplyUICommand("/vis/viewer/pan " + " 1. 0. mm")
def cmd_shrink(self):
gApplyUICommand("/vis/viewer/zoom 0.8")
# def cmd_reset(self):
# gApplyUICommand("/vis/viewer/pan " + " 0. 0. mm")
def __init__(self, master=None):
Frame.__init__(self, master)
self.init()
self.grid()
app = App()
app.mainloop()
@@ -0,0 +1,40 @@
09 March 2006
26 May 2006 Geant4.8.1
Hajime Yoshida
The first version of the courseware of the mass attenuation coefficient
- Lesson1.py
select absorber material
set its thickness upto 500 mm
select beam particle
set its energy upto 100 MeV
set nu of events up to 100
run
and then
zoom in (x1.1) or zoom out (x0.9)
pan in up/down and/or right/left in the unit of mm (type in two
numbers separated by a space)
execute any G4 command but /gun/particle or /gun/energy which are
defined by the above
-oglx.mac
OGLSX => important to make zooming effective after showing trajectories.
if you want to use VRML, you have to specify the directory where *.wrl
file is stored and the VRML viewer to which the path is set:
G4VRMLFILE_DEST_DIR=/home/yoshidah/tmp/
G4VRMLFILE_VIEWER=vrmlview
And you have VRML drivers built.
G4VIS_BUILD_VRML_DRIVER=1
G4VIS_USE_VRMLFILE=1
G4VIS_BUILD_VRMLFILE_DRIVER=1
G4VIS_USE_VRML=1
-gun.mac
This is used only at the initialization time.
@@ -0,0 +1,8 @@
# gun.mac
/gun/number 1
/gun/particle e-
/gun/energy 0.2 MeV
/gun/direction 0. 0. 1.
/gun/position 0. -5. -30. cm
@@ -0,0 +1,29 @@
# vis.mac
#OpenGL Stored mode to accumulate trajectories
/vis/open OGLSX
#VRML viewer is usable if you defined env variables
#/vis/open VRML2FILE
/vis/viewer/refresh
/vis/scene/create
/vis/scene/add/volume
#/vis/scene/add/axes 0 0 0 2 m
#/vis/drawVolume
/vis/viewer/set/style s
/vis/sceneHandler/attach
/vis/viewer/set/viewpointThetaPhi 90. 0.
/vis/viewer/zoom 1.5
#/vis/scene/add/text 0 610 610 mm 20 -0 -0 Geant4Py
/tracking/storeTrajectory 1
/vis/scene/add/trajectories
/vis/scene/endOfEventAction accumulate
/vis/scene/endOfRunAction accumulate
+426
View File
@@ -0,0 +1,426 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py
#
# ExN03 : geant4/examples/novice/N03
# using site-module packages
# ==================================================================
from Geant4 import *
import Qmaterials, NISTmaterials
import ExN03geom
import ExN03pl
import ParticleGun, MedicalBeam
import sys
from time import *
from subprocess import *
import os
# ==================================================================
# main
# ==================================================================
# ------------------------------------------------------------------
# randum number
# ------------------------------------------------------------------
rand_engine= Ranlux64Engine()
HepRandom.setTheEngine(rand_engine)
HepRandom.setTheSeed(20050830L)
# ------------------------------------------------------------------
# setup for materials
# ------------------------------------------------------------------
# NIST materials
#NISTmaterials.Construct()
# ------------------------------------------------------------------
# setup for geometry
# ------------------------------------------------------------------
# normal way for constructing user geometry
exN03geom= ExN03geom.ExN03DetectorConstruction()
gRunManager.SetUserInitialization(exN03geom)
# 2nd way, short-cut way
#ExN01geom.Construct()
#ExN03geom.Construct()
# magnetic field
#exN03geom.SetMagField(0.1 * tesla)
# ------------------------------------------------------------------
# setup for physics list
# ------------------------------------------------------------------
# normal way for constructing user physics list
exN03PL= ExN03pl.ExN03PhysicsList()
gRunManager.SetUserInitialization(exN03PL)
# 2nd way, short-cut way
#ExN01pl.Construct()
#EMSTDpl.Construct()
# ------------------------------------------------------------------
# setup for primary generator action
# ------------------------------------------------------------------
# normal way for constructing user physics list
#pgPGA= ParticleGun.ParticleGunAction()
#gRunManager.SetUserAction(pgPGA)
#pg= pgPGA.GetParticleGun()
# 2nd way, short-cut way
pg= ParticleGun.Construct()
# set parameters of particle gun
pg.SetParticleByName("e-")
pg.SetParticleEnergy(50.*MeV)
pg.SetParticlePosition(G4ThreeVector(-40.,0.,0.)*cm)
pg.SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.))
# medical beam
#beam= MedicalBeam.Construct()
# ------------------------------------------------------------------
# go...
# ------------------------------------------------------------------
gRunManager.Initialize()
# beamOn
#gRunManager.BeamOn(3)
#TEST
#gProcessTable.SetProcessActivation("msc", 0)
#gProcessTable.SetProcessActivation("conv", 0)
#gProcessTable.SetProcessActivation("eBrem", 0)
#gProcessTable.SetProcessActivation("eIoni", 0)
#gProcessTable.SetProcessActivation("annihil", 0)
# visualization
# OGLSX, VRML and HEPREP sceneHandlers are all created with names
gApplyUICommand("/vis/sceneHandler/create OGLSX OGLSX")
gApplyUICommand("/vis/sceneHandler/create VRML2FILE VRML")
gApplyUICommand("/vis/sceneHandler/create HepRepFile HEPREP")
# OGLSX is the default so, viewer is created and volume is drawn
gApplyUICommand("/vis/viewer/create OGLSX oglsxviewer")
gApplyUICommand("/vis/drawVolume")
gApplyUICommand("/vis/scene/add/trajectories")
gApplyUICommand("/tracking/storeTrajectory 1")
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
gApplyUICommand("/vis/viewer/select oglsxviewer")
# viewers VRML and Wired are tested by their envs vars
# if their envs var are set, then viewers are created and drawVolume
global heprepViewer, heprepDir, heprepName
heprepViewer = os.environ.get("G4HEPREPFILE_VIEWER")
heprepDir = os.environ.get("G4HEPREPFILE_DIR")
heprepName = os.environ.get("G4HEPREPFILE_NAME")
if heprepViewer is not None:
gApplyUICommand("/vis/viewer/create HEPREP wired")
gApplyUICommand("/vis/drawVolume")
# VRML viewers name is user defined
vrmlDir = os.environ.get("G4VRML_DEST_DIR")
vrmlViewer = os.environ.get("G4VRMLFILE_VIEWER")
if vrmlViewer is not None:
gApplyUICommand("/vis/viewer/create VRML vrmlviewer")
gApplyUICommand("/vis/drawVolume")
# creating widgets using grid layout
from Tkinter import *
class App(Frame):
g4pipe = 0
def init(self):
#title and header row=0, 1
title = Label(self, text="exampleN03")
title.grid(row=0, column=1, columnspan=3)
header = Label(self, text="empowered by \n Geant4Py")
header.grid(row=1, column=1, columnspan=3)
# number of layers
layerLabel = Label(self, bg="green", text="No of layers")
self.layerVar=IntVar()
self.layerVar.set(10)
layer = Scale(self, orient=HORIZONTAL, length=400, from_=0, to=10, tickinterval=1, resolution=1, variable=self.layerVar )
layerLabel.grid(row=2, column=0, sticky=W)
layer.grid(row=2, column=1, columnspan=5, sticky=W)
#absorber material selection row=3
absorbermaterialLabel = Label(self, bg="green", text="Absorber Material")
absorbermaterialLabel.grid(row=3, column=0, sticky=W)
self.absorbermaterialVar = StringVar()
self.absorbermaterialVar.set("Lead")
ra1 = { }
pos=1
for i in ("Aluminium", "Lead"):
ra1[i] = Radiobutton(self, text=i, variable=self.absorbermaterialVar, value=i)
ra1[i].grid(row=3, column=pos, sticky=W)
pos=pos+1
#absorber thickness row=4
absorberthickLabel = Label(self, bg="green", text="Thickness (mm)")
self.absorberthickVar = DoubleVar()
self.absorberthickVar.set(10.0)
absorberthick = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., resolution=0.05, tickinterval=10.0, digits=4, variable=self.absorberthickVar)
absorberthickLabel.grid(row=4, column=0, sticky=W)
absorberthick.grid(row=4, column=1, columnspan=5, sticky=W)
#gap material selection row=5
gapmaterialLabel = Label(self, bg="green", text="Gap Material")
gapmaterialLabel.grid(row=5, column=0, sticky=W)
self.gapmaterialVar = StringVar()
self.gapmaterialVar.set("liquidArgon")
ra2 = { }
pos=1
for i in ("liquidArgon","Scintillator", "Air", "Aerogel", "Galactic" ):
ra2[i] = Radiobutton(self, text=i, variable=self.gapmaterialVar, value=i)
ra2[i].grid(row=5, column=pos, sticky=W)
pos=pos+1
#gap thickness row=6
gapthickLabel = Label(self, bg="green", text="Thickness (mm)")
self.gapthickVar = DoubleVar()
self.gapthickVar.set(5.0)
gapthick = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., resolution=0.05, tickinterval=10.0, digits=4, variable=self.gapthickVar)
gapthickLabel.grid(row=6, column=0, sticky=W)
gapthick.grid(row=6, column=1, columnspan=5, sticky=W)
#calorSizeYZ row=7
calorsizeYZLabel = Label(self, bg="green", text="SizeYZ (mm)")
self.calorsizeYZVar = DoubleVar()
self.calorsizeYZVar.set(100.0)
calorsizeYZ = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=200., resolution=0.05, tickinterval=20.0, digits=4, variable=self.calorsizeYZVar)
calorsizeYZLabel.grid(row=7, column=0, sticky=W)
calorsizeYZ.grid(row=7, column=1, columnspan=5, sticky=W)
#particle row=8
particleLabel = Label(self, bg="green", text="Particle")
particleLabel.grid(row=8, column=0, sticky=W)
self.particleVar = StringVar()
self.particleVar.set("e-")
ra1 = { }
pos1=1
for i in ("proton", "gamma", "e-", "e+", "mu-", "mu+"):
ra1[i] = Radiobutton(self, text=i, variable=self.particleVar, value=i)
ra1[i].grid(row=8, column=pos1, sticky=W)
pos1=pos1+1
#energy row=9
energyLabel = Label(self, bg="green", text="Energy (MeV)")
self.energyVar=StringVar()
self.energyVar.set(50)
energy = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=1000., tickinterval=100.0, resolution=0.1, variable=self.energyVar, digits=5 )
energyLabel.grid(row=9, column=0, sticky=W)
energy.grid(row=9, column=1, columnspan=5, sticky=W)
#number of event row=10
eventLabel = Label(self, bg="green", text="Events")
self.eventVar=IntVar()
self.eventVar.set(3)
event = Scale(self, orient=HORIZONTAL, length=400, from_=0, to=100, tickinterval=10, resolution=1, variable=self.eventVar )
eventLabel.grid(row=10, column=0, sticky=W)
event.grid(row=10, column=1, columnspan=5, sticky=W)
#start a run button row=0
startBut = Button(self, bg="orange", text="Start a run", command=self.cmd_beamOn)
startBut.grid(row=0, column=0, sticky=W)
#Zoom in/out Pan X Y row=13
# visLabel = Label(self, text="viewer", bg="orange")
# expandBut = Button(self, text="Zoom in", command=self.cmd_expand)
# shrinkBut = Button(self, text="Zoom out", command=self.cmd_shrink)
# visLabel.grid(row=13, column=0, sticky=W)
# expandBut.grid(row=13, column=1, sticky=W)
# shrinkBut.grid(row=13, column=2, sticky=W)
# panLabel = Label(self, text="Pan X Y(mm)")
# self.panXYVar = StringVar()
# panXYEnt = Entry(self, textvariable=self.panXYVar, width=6)
# panBut = Button(self, bg="orange", text="OK", command=self.cmd_pan)
# panLabel.grid(row=13, column=3, sticky=W)
# panXYEnt.grid(row=13, column=4)
# panBut.grid(row=13, column=5)
# process activate row 11 - 13
processLabel=Label(self, text="Process on/off", bg="green")
processLabel.grid(row=11, column=0, sticky=W)
procTab = {}
self.processList = ["phot", "compt", "conv", "msc", "eIoni", "eBrem", "annihil","muIoni", "muBrems", "hIoni"]
pos=1
self.processVar = {}
for i in self.processList:
self.processVar[i] = IntVar()
procTab[i] = Checkbutton(self, text=i, variable=self.processVar[i], command=self.cmd_setProcess)
if pos <= 3:
procTab[i].grid(row=11, column=pos, sticky=W)
if 4<= pos <= 7:
procTab[i].grid(row=12, column=pos-3, sticky=W)
if pos >= 8:
procTab[i].grid(row=13, column=pos-7, sticky=W)
pos=pos+1
procTab[i].select()
# set cuts row 14
cutLabel = Label(self, bg="green", text="Cut (mm)")
self.cutVar=DoubleVar()
self.cutVar.set(1.)
cut = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=10., tickinterval=1., resolution=0.005, variable=self.cutVar, digits=5 )
cutLabel.grid(row=14, column=0, sticky=W)
cut.grid(row=14, column=1, columnspan=5, sticky=W)
# set mag field row 15
magLabel = Label(self, bg="green", text="Magnetic (T)")
self.magVar=DoubleVar()
self.magVar.set(0.)
mag = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=5., tickinterval=1., resolution=0.1, variable=self.magVar, digits=3 )
magLabel.grid(row=15, column=0, sticky=W)
mag.grid(row=15, column=1, columnspan=5, sticky=W)
# viewer selection row=16
viewerLabel = Label(self, bg="green", text="Viewer")
viewerLabel.grid(row=16, column=0, sticky=W)
self.viewerVar = StringVar()
self.viewerVar.set("")
stateOfViewer = {"OpenGL":"normal", "VRML":"normal", "Wired":"normal"}
if vrmlViewer is None: stateOfViewer["VRML"] = "disabled"
if heprepViewer is None: stateOfViewer["Wired"] = "disabled"
viewers = { }
pos=1
for i in ("OpenGL", "VRML", "Wired"):
viewers[i] = Radiobutton(self, text=i, variable=self.viewerVar, value=i, command=self.cmd_viewer, state=stateOfViewer[i])
viewers[i].grid(row=16, column=pos, sticky=W)
pos=pos+1
#Geant4 command entry row = 17
g4comLabel = Label(self, text="Geant4 command", bg="orange")
self.g4commandVar = StringVar()
commandEntry = Entry(self, textvariable=self.g4commandVar, width=15)
self.g4commandVar.set("/vis/viewer/zoom 1.2")
comBut = Button(self, bg="orange", text="Execute", command=self.cmd_g4command)
g4comLabel.grid(row=17, column=0, sticky=W)
commandEntry.grid(row=17, column=1, columnspan=3, sticky=E+W)
comBut.grid(row=17, column=5)
#exit row = 0
exitBut = Button(self, bg="red", text="End all", command=sys.exit)
exitBut.grid(row=0, column=5, sticky=W)
#on Run butto do...
def cmd_beamOn(self):
exN03geom.SetNbOfLayers(self.layerVar.get())
exN03geom.SetAbsorberMaterial(self.absorbermaterialVar.get())
exN03geom.SetAbsorberThickness(self.absorberthickVar.get() * mm/2.0)
exN03geom.SetGapMaterial(self.gapmaterialVar.get())
exN03geom.SetGapThickness(self.gapthickVar.get() * mm/2.0)
exN03geom.SetCalorSizeYZ(self.calorsizeYZVar.get() * mm)
position = -self.layerVar.get()*(self.absorberthickVar.get() + self.gapthickVar.get())*1.2
exN03geom.UpdateGeometry()
exN03PL.SetDefaultCutValue(self.cutVar.get() * mm)
exN03PL.SetCutsWithDefault()
exN03geom.SetMagField(self.magVar.get() * tesla)
print "Now geometry updated"
self.cmd_particle(self.particleVar.get())
self.cmd_energy(self.energyVar.get())
print position
eventNum = self.eventVar.get()
for i in range(eventNum):
pg.SetParticlePosition(G4ThreeVector(position*mm, (i-eventNum/2)*5.*mm, 0.*cm))
gRunManager.BeamOn(1)
sleep(0.01)
gApplyUICommand("/vis/viewer/update")
def cmd_setProcess(self):
for i in self.processList:
if self.processVar[i].get() == 0:
gProcessTable.SetProcessActivation(i, 0)
print "Process " + i + " inactivated"
else:
gProcessTable.SetProcessActivation(i, 1)
print "Process " + i + " activated"
def cmd_g4command(self):
gApplyUICommand(self.g4commandVar.get())
def cmd_particle(self, particle):
gApplyUICommand("/gun/particle " + particle)
def cmd_energy(self, penergy):
gApplyUICommand("/gun/energy " + penergy + " MeV")
def cmd_viewer(self):
if self.viewerVar.get() == "OpenGL":
gApplyUICommand("/vis/viewer/select oglsxviewer")
gApplyUICommand("/vis/scene/add/trajectories")
gApplyUICommand("/tracking/storeTrajectory 1")
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
if self.viewerVar.get() == "VRML":
gApplyUICommand("/vis/viewer/select vrmlviewer")
gApplyUICommand("/vis/scene/add/trajectories")
gApplyUICommand("/tracking/storeTrajectory 1")
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
if self.viewerVar.get() == "Wired":
gApplyUICommand("/vis/viewer/select wired")
gApplyUICommand("/vis/scene/add/trajectories")
gApplyUICommand("/tracking/storeTrajectory 1")
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
if self.g4pipe == 0:
Popen(heprepViewer + " -file " + heprepDir + "/" + heprepName +".heprep", shell=True)
self.g4pipe = 1
def cmd_expand(self):
gApplyUICommand("/vis/viewer/zoom 1.2")
def cmd_pan(self):
gApplyUICommand("/vis/viewer/pan " + self.panXYVar.get() + " " + " mm")
def cmd_shrink(self):
gApplyUICommand("/vis/viewer/zoom 0.8")
def __init__(self, master=None):
Frame.__init__(self, master)
self.init()
self.grid()
app = App()
app.mainloop()
@@ -0,0 +1,77 @@
26 May 2006
revised 02 July 2006
Geant4.8.1 release
===============================================
Prerequisites for G4 environment variables.
==============================================
This scripts offers the choice of visualization systems;
one among OGLSX (OpenGL stored mode), or VRML2FILE or Wired3.
OGLSX is the default viewer and you need no environment variables.
To use VRML2FILE you have to specify its viewer which is found in your
search path and the destination directory where *.wrl file is stored.
If you don't specify the name of the viewer, you can't choose it on the panel.
For example,
setenv G4VRMLFILE_VIEWER $HOME/bin/vrmlview
setenv G4VRMLFILE_DEST_DIR $HOME/tmp/ <= terminate with /
To use Wired, download it and install under your directory. Java Runtime
Environment is necessary.
Then set, for example;
setenv G4HEPREPFILE_VIEWER $HOME/Wired/bin/wired <= any path you use
setenv G4HEPREPFILE_DIR $HOME/tmp/
setenv G4HEPREPFILE_NAME lesson2_00 <= any name you choose.
setenv G4HEPREPFILE_OVERWRITE 1 <= to reuse the file for "next event"
G4HEPREPFILE_VIEWER isn't an official Geant4 environment variable but is employed
here to control the vissssualization viewers.
The name of the HepRepFile is ${G4HEPREPFILE_NAME}.heprep which will be
stored in ${G4HEPREPFILE_DIR}.
ExN03.py script don't use VRML or Wired if their *_VIEWER isn't set.
But other env variables are also used in the script to look for the
file and to activate the viewer, you have to set all of the above variables
in the shell where you activate ExN03.py script.
NOTICE) VRML viewer blocks the window (modal), so that you have to exit it to
display another run.
********* ExN03.py script ***********
This example id derived from examples/novice/N03.
You can
- choose the materials of absorber and gap
- set the thickness of the absorber and gap
- set the lateral (in YZ plane) size of the sandwitch cal.
- choose an incedent particle
- set its energy
- set the number of events to run
- toggle on/off of the electromagnetic processes
- set cut length
- set magnetic field
- typein any Geant4 command (except related with the above functions) and execute it
How to run it?
%python ExN03.py
You can visualize with OpenGL stored mode or VRML or Wired3
You can choose either of the active viewers by pushing the
radio buttons.
=========================
NOTICE)
VRML viewer runs in the modal action, and you have to exit it
to have a new diaplay for the new run, or you want to switch to
another viewer.
Wired has the "next"/"previous" event button. So to see the next
event, first run and then "next" event. Wired doesn't block G4
and you can have Wired and OGLSX both open.
ExN03-Wired.py is OBSOLETE. Please use ExN03.py
+121
View File
@@ -0,0 +1,121 @@
#!/usr/bin/python
# ==================================================================
# An example of ploting by EmCalculator
#
# Plotting photon cross sections and stopping power with ROOT
# ==================================================================
from Geant4 import *
import NISTmaterials
from EZsim import *
# ==================================================================
# geometry setup
# ==================================================================
# ------------------------------------------------------------------
# setup
# ------------------------------------------------------------------
def Configure():
NISTmaterials.Construct()
EZgeom.Construct()
# ------------------------------------------------------------------
# constructing geometry
# ------------------------------------------------------------------
def SetMaterial(material_name):
material= gNistManager.FindOrBuildMaterial(material_name)
EZgeom.SetWorldMaterial(material)
# ==================================================================
# plot by ROOT
# ==================================================================
import ROOT
from math import log, log10, sqrt, ceil, floor
from array import array
# ------------------------------------------------------------------
# caclculate plot range
# ------------------------------------------------------------------
def plot_range(xmin, xmax, xmargin=0.):
xmaxlog= 10
xminlog= -10
if(xmax!=0.):
xmaxlog= log10(xmax)
if(xmin!=0):
xminlog= log10(xmin)
ixmaxlog= xmaxlog+0.5
ixminlog= xminlog-0.5-xmargin
return [10**ixminlog, 10**ixmaxlog]
# ------------------------------------------------------------------
# ROOT init
# ------------------------------------------------------------------
def init_root():
ROOT.gROOT.Reset()
# plot style
ROOT.gStyle.SetTextFont(82)
ROOT.gStyle.SetTitleFont(82, "X")
ROOT.gStyle.SetTitleFontSize(0.04)
ROOT.gStyle.SetLabelFont(82, "X")
ROOT.gStyle.SetTitleFont(82, "Y")
ROOT.gStyle.SetLabelFont(82, "Y")
#ROOT.gStyle.SetOptTitle(0)
ROOT.gStyle.SetErrorX(0)
canvas= ROOT.TCanvas("g4plot", "g4plot", 620, 30, 600, 600)
canvas.SetLogy()
canvas.SetLogx()
canvas.SetGrid()
return canvas
# ------------------------------------------------------------------
# do a plot
# ------------------------------------------------------------------
def make_plot(xlist, user_title, axis_titile, q_super_impose=0):
ekin_array, y_array = array('d'), array('d')
for x in xlist:
ekin_array.append(x[0])
y_array.append(x[1])
# plot range
xmin= min(ekin_array)
xmax= max(ekin_array)
xrange= plot_range(xmin, xmax)
ymin= min(y_array)
ymax= max(y_array)
yrange= plot_range(ymin, ymax, 2)
if(q_super_impose==0):
htit= user_title
global frame
frame= ROOT.TH1F("dumy", htit, 1, xrange[0], xrange[1]);
frame.SetMinimum(yrange[0]);
frame.SetMaximum(yrange[1]);
frame.SetXTitle("Kinetic Energy (MeV)")
frame.GetXaxis().SetLabelSize(0.025)
frame.GetXaxis().SetTitleSize(0.03)
frame.SetYTitle(axis_titile)
frame.GetYaxis().SetLabelSize(0.025)
frame.GetYaxis().SetTitleSize(0.03)
frame.SetStats(0)
frame.Draw()
plot= ROOT.TGraph(len(ekin_array), ekin_array, y_array)
plot.Draw("L")
plot.SetLineColor(q_super_impose+1)
return plot
+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/python
# ==================================================================
# An example of ploting by EmCalculator
#
# Plotting photon cross sections and stopping power
# ==================================================================
from Geant4 import *
import ExN03pl
import EmPlot
# initialize
EmPlot.Configure()
# user physics list
ExN03pl.Construct()
# target material
material= "G4_Cu"
EmPlot.SetMaterial(material)
# initialize G4 kernel
gRunManager.Initialize()
gRunManagerKernel.RunInitialization()
# energy
elist= []
for n in range(-3, 3):
for i in range(10,99):
elist.append(i/10.*10.**n *MeV)
# calculate stopping power
pname= "e-"
dedx_list= CalculateDEDX(pname, material, elist, 1)
xlist_tot=[]
xlist_ioni=[]
xlist_brems=[]
for x in dedx_list:
xlist_tot.append((x[0], x[1]["tot"]/(MeV*cm2/g)))
xlist_ioni.append((x[0], x[1]["ioni"]/(MeV*cm2/g)))
xlist_brems.append((x[0], x[1]["brems"]/(MeV*cm2/g)))
# make plot
myCanvas= EmPlot.init_root()
aplot= EmPlot.make_plot(xlist_tot, pname+" Stopping Power ("+material+")",
"dE/dX (MeV cm^{2}/g)")
bplot= EmPlot.make_plot(xlist_ioni, "Stopping Power ("+material+")",
"dE/dX (MeV cm^{2}/g)", 1)
cplot= EmPlot.make_plot(xlist_brems, "Stopping Power ("+material+")",
"dE/dX (MeV cm^{2}/g)", 3)
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/python
# ==================================================================
# An example of ploting by EmCalculator
#
# Plotting photon cross sections and stopping power
# ==================================================================
from Geant4 import *
import ExN03pl
import EmPlot
# initialize
EmPlot.Configure()
# user physics list
ExN03pl.Construct()
# target material
material= "G4_Pb"
EmPlot.SetMaterial(material)
# initialize G4 kernel
gRunManager.Initialize()
gRunManagerKernel.RunInitialization()
# energy
elist= []
for n in range(-3, 4):
for i in range(10,99):
elist.append(i/10.*10.**n *MeV)
# calculate cross sections
xsection_list= CalculatePhotonCrossSection(material, elist, 1)
xlist_tot=[]
xlist_comp=[]
xlist_pe=[]
xlist_conv=[]
for x in xsection_list:
xlist_tot.append((x[0]/MeV, x[1]["tot"]/(cm2/g)))
xlist_comp.append((x[0]/MeV, x[1]["compt"]/(cm2/g)))
xlist_pe.append((x[0]/MeV, x[1]["phot"]/(cm2/g)))
xlist_conv.append((x[0]/MeV, x[1]["conv"]/(cm2/g)))
# make a plot
myCanvas= EmPlot.init_root()
aplot= EmPlot.make_plot(xlist_tot, "Photon Cross Section ("+material+")",
"Cross Section (cm^{2}/g)")
bplot= EmPlot.make_plot(xlist_comp, "Photon Cross Section ("+material+")",
"Cross Section (cm^{2}/g)", 1)
cplot= EmPlot.make_plot(xlist_pe, "Photon Cross Section ("+material+")",
"Cross Section (cm^{2}/g)", 7)
dplot= EmPlot.make_plot(xlist_conv, "Photon Cross Section ("+material+")",
"Cross Section (cm^{2}/g)", 3)