Import Geant4 8.1.0 source tree
This commit is contained in:
Executable
+121
@@ -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
|
||||
|
||||
Executable
+51
@@ -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)
|
||||
|
||||
Executable
+54
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user