G4 Beamline Validation
G4 Beamline Validation
Validation
Tom Roberts
Muons, Inc.
[email protected]
June 2012
http://g4beamline.muonsinc.com
As most of the physics processes implemented in G4beamline come directly from Geant4, the
validation performed by the Geant4 collaboration is directly applicable. This document will
merely summarize their results, and provide references. Some particularly important processes,
such as transport and multiple scattering, have been tested independently, and those results are
reported here.
This document does not discuss how to use G4beamline; for that, see the “G4beamline User’s
Guide” [1]. The input files used for specific tests of G4beamline are included in the Validation
directory of the distribution, starting with release 2.8.
Except as noted, the tests described here were performed using G4beamline 2.06, which uses
Geant.9.3p01. Most of the Geant4 Collaboration’s tests used earlier versions.
Some authors distinguish between verification and validation, using the first to mean testing that
the code performs as intended, and the second to mean its physics accuracy. This document
makes no such distinction – if the code is wrong the physics cannot be correct.
Here is a histogram for events with -4.9 < y < 4.9 (i.e. within the vertical region of the box),
showing the right edge (x) has an accuracy better than 2 nanometers:
1600
1400
1200
1000
800
600
400
200
0
4.99996 4.99998 5 5.00002 5.00004
The random number generator comes from CLHEP [4], and is the default HepJamesRandom
generator, described in [5]. It is documented to provide independent random streams for seeds
between 0 and 900,000,000 (inclusive), which exceeds the normal range of event numbers in
G4beamline. It is not feasible to perform a useful test of this generator here, see the references
for details.
In most cases, the test was written at the same time as the feature being tested. Most tests have
simple physical situations and quantitative checks on some value(s) that were generated by the
program; in most cases, these internal checks of the test have been verified manually. That is,
most of these tests not only verify consistency among releases, but also verify that for at least
one instance, the basic operation of the feature is correct.
For example, test78 tests the setdecay command, which permits the user to change the decay
parameters of particles (a capability intended for testing and background studies). test78 does the
following:
1. Changes pi+ to decay with equal branching ratios into (e+ nu_e) and (mu+ nu_mu), and a
lifetime of 0.1 ns.
2. Changes mu+ to decay with a lifetime of 1E20 ns (i.e. they never decay, to avoid
confusing the particle counts).
3. Makes deuterons be unstable (!), decaying into (tau+ gamma) with a lifetime of 0.1 ns.
4. Changes tau+ to have a lifetime of 1E20 ns (i.e. they never decay).
5. Runs with a beam of 50 deuterons and 100 pi+, over 10 meters.
6. Checks that at the end of the simulation (z=10000 mm) there were 50±1 tau+,
50±12 mu+, and 50±12 e+ (values outside those ranges make the test fail).
The artificially short lifetimes ensure that all pi+ and all deuterons decay (!), and the ±12 values
for particle counts accommodate statistical variations. This is a highly unphysical simulation, but
the presence of those particle counts at the end does imply that the setdecay command performed
as intended. Note that this just tests for basic operation, and details such as energy and
momentum conservation are not checked. The setdecay command has several major cases
Another example is test12 testing the multipole command, which creates a beamline element
with a multipole magnetic field. It places 5 elements with quadrupole, sextupole, octopole,
decapole, and dodecapole fields. It then uses the printfield command to print the Bx and By fields
in the x-z and y-z planes inside all of them, verifying they are correct to within 0.0002 tesla. The
multipole command has five internal cases for the different multipoles, and test12 was written to
check one instance of each; this is another unit test turned into a regression test. The values of
the fields were checked manually when the test was written.
A third example is test68 testing the polycone command, which generates an element consisting
of an absorber shaped as multiple cones in a line. It creates and places a polycone, and then
surrounds it with several cylinders that should or should not intersect the polycone, and checks
the correctness of those intersections. It also checks that beam propagates through the polycone
without error. Unit testing of the polycone command relied heavily on visualization, which
cannot easily be translated into automated tests.
These tests are in the directory test of the G4beamline distribution. As of release 2.06 the list of
these tests is:
The primary link for “Validation and Testing” of Geant4 from the Geant4 Collaboration is:
http://geant4.web.cern.ch/geant4/results/results.shtml.
Test 1
To check particle transport, one thousand 25 MeV/c electrons were tracked in the x-z plane
normal to a uniform 0.01 Tesla magnetic field along y, with initial sigmaXp=0.1. These tracks
have a circumference of about 52 meters. The maximum step length (maxStep) was varied from
1 mm to 1 meter, and the position in x when returning to its starting point is histogrammed for
1000 tracks. Remember that this step is the “physics step”, and integrating the equations of
motion in the EM field uses smaller steps controlled by the tracking parameters. In this plot,
|mean|+2*sigma is plotted, providing an upper bound on the error for >95% of the tracks (fewer
tracks exceed 2*sigma than for a Gaussian); the value for maxStep=1 mm cannot be read from
the plot; it is 0.015 micron:
6
mean+2*sigma (microns)
0 3
10 102 10
maxStep (mm)
After one circle, the momentum of each track is observed to be within 0.000001 MeV/c of the
initial 25.000000 MeV/c beam; all tracks have a y value within 0.01 micron of the correct value,
0.0. The transit time for each track is within 0.0001 ns of the correct value, 174.8111 ns – for
these parameters the period is (MKS):
T = 2 π m γ / (q B)
= 6.28318531 * 9.1093821×10−31 * 48.934002 / (1.6021765×10−19 * 0.01)
= 174.8111 ns
As expected, the real-time speed of tracking depends strongly on the value of maxStep:
maxStep (mm) Tracks / sec
1 2.1
10 20.8
100 200
1000 >500
Test 2
A second test is to check that particles move in straight lines through vacuum with no fields. A
proton beam with zero emittance and meanXp=0.000001 (i.e. dx/dz = 1 microradian) has every
particle at y=0.0 and x=10000.0 at z=1E10, to the accuracy of a float (tracking is performed in
double precision, but the NTuple uses float-s). This test has the default maxStep=100 (mm), and
took ~800 seconds to track each particle for 10,000 km (100 million steps).
The simulation tracks a single muon with decay disabled, in a uniform B field with no
quadrupoles. The plot is of the z component of polarization, sampled every turn at z=0; the muon
started with polarization=(0,0,1) at z=0.
For 3.094 GeV/c mu+ with three polarization states, the Ptot distributions are correct:
For all six targets, the largest contributions to Chisq come from bins in the range 0.02 < Angle <
0.05. These are neither in the center nor in the tail. In all cases, at least 1/3 of the Chisq comes
from a single bin; for the three worst targets, more than half of the Chisq comes from a single
bin.
The following plot is from the PDG “Review Tables and Plots” section on “Passage of particles
through matter” [8], fig. 27.1. The red dots were computed using G4beamline 1.16 (Geant4
600
3.3 Hadronic400
Interactions
The primary link for the Geant4 Collaborations webpage on “Physics Validation and
Verification” for hadronic physics processes is:
200
http://geant4.web.cern.ch/geant4/results/validation_plots.htm. A very tiny sample of
representative plots is copied here.
0
Comparison to HARP 2inclusive
4 proton6 production
8 data,
10 p A 12→ p X, 14
20º < angle
16 < 50º. The
transition region of QGSP_BERT just above 10 GeV
Beam momentum (GeV/c) is quite evident. Plot is from
arXiv:1006.3429.
o o
HARP-CDP pA→pX 20 <Θ<50
1600
Ta QGSP_BERT
Cu
1400 Be
Cross-section (mbarn)
1200
1000
800
600
400
200
0
2 4 6 8 10 12 14 16
Beam momentum (GeV/c)
π– → e– ν (1.230E-4)
µ
G4beamline adds these modes. The other rare-decay modes have not been implemented, due to
the complexity of modeling 3- and 4-body decays; they are a factor of 1000 (or more) below the
above. Moreover, unlike these modes, they do not generate additional backgrounds for the Mu2E
experiment [9], which is the primary customer for this.
The setdecay command can be used to modify particles’ decay modes, including changing their
lifetime, adding and removing specific modes, and changing their branching ratios (e.g. for
testing background rejection, pions could be forced to always decay into these normally rare
modes).
The decay products from 1,000,000 π+ decays, with µ+ decays inhibited, are:
-13 999875 mu+
-11 125 e+
12 125 nu_e
14 999875 nu_mu
The decay products from 1,000,000 π– decays, with µ– decays inhibited, are:
-14 999886 anti_nu_mu
-12 114 anti_nu_e
11 114 e-
13 999886 mu-
The user sets the initial value of deltaT (the time increment between steps); the
collectiveComputation() function can modify it, if necessary, depending on the detailed needs of
each computation.
Note that when using macroparticles to simulate larger bunches, each macroparticle is tracked as
a single particle in the usual way, but their generated fields are multiplied by the macroparticle
charge. It is non-trivial to determine what to do when one of the particles decays or interacts; it is
easy to greatly increase the number of macroparticles, beyond the capabilities of memory or
CPU. At present, the entire macroparticle follows the decay or interaction, which means the
statistical accuracy can be poor (many more macroparticles are needed for accuracy).
The following plots compare standard tracking with collective tracking, using a
collectiveComputation() that only monitors the tracks. The beam is 100,000 µ+ with momentum
200 MeV/c and zero emittance, incident on a 20 mm slab of iron, followed by a virtualdetector to
generate the plots. The collective time step is 0.01 ns. All secondaries and decay products are
included in the plots. The standard tracking is plotted as black points with errorbars; the
For the expansion of a Gaussian bunch of 1012 µ+ expanding in free space, all three computations
give the same result (to the width of the lines in the plots), but their CPU time requirements are
very different, and they scale much differently with (# macroparticles), as shown here:
All three computations can handle multiple bunches of arbitrary particles, but spacechargeps and
spacecharge require a reference particle for each bunch.
This algorithm scales as (# macroparticles)2, and is not computationally feasible for more than
~1,000 macroparticles. It was decided early on that the availability of a rigorously correct
computation would permit the testing of other, more efficient approximations and algorithms (it
is correct for the macroparticles used; whether that corresponds accurately to a real beam bunch
is a different question, usually answered in the negative).
A uniform current of 1,000 Amps, at radius 0.1 m, has B=0.002 T. This is tested by generating
8,001 macroparticles2 with charge +0.001 Coulomb, spaced uniformly 1 cm apart, moving at
10,000 meter/sec in the +z direction, centered at z=0. At (x,y,z)=(100,0,0), Bx= 0.00199999
Tesla; at (x,y,z)=(0,200,0), Bx=-0.000999988 Tesla. These are the correct values and directions
to 5 significant digits.
There is no input file for these tests; they are executed automatically by the code whenever the
spacechargelw command is used. There is an assert() to ensure they are correct.
The computation scales in many ways, and tests of proper scaling behavior were made for
variations in:
• Macroparticle radius
• Macroparticle charge density exponent K
• Time step deltaT
• Total charge in the bunch
• Pz (longitudinal 3-momentum)
• R0 (initial radius of the bunch)
• Particle mass
• Sign of particle charge
The scaling for number of macroparticles (total charge held constant) is violated in minor ways,
as described in the next paragraph.
1
This macroparticle is exactly at rest; its trajectory was generated manually, without any tracking.
2
These macroparticle trajectories were also generated manually, without any tracking.
3
The run with 10,000 macroparticles took 14 hours of CPU time, for a mere 400 mm of travel.
FFTW 3.2.2 [12] is used to implement the fast Fourier transforms. The beam-frame grid is
doubled in all three dimensions so the cyclical convolution via FFTs yields the correct potential
for infinite boundary conditions [13]. As the Green’s function includes the boundary conditions,
the difficulties of spacechargeps are avoided.
A uniform current of 1,000 Amps, at radius 0.1 m, has B=0.002 T. This is tested by generating
501 macroparticles with charge +0.001 Coulomb, spaced uniformly 1 cm apart, moving at
10,000 meter/sec in the +z direction, centered at z=0. At (x,y,z)=(100,0,0), Bx= 0.001971 Tesla.
There is no input file for these tests; they are executed automatically by the code whenever the
spacecharge command is used. There is an assert() to ensure they are correct.
Here are plots of the E field at a fixed point in space as a function of time, during the transit of a
bunch consisting of two Gaussians. The total bunch is 1012 µ+ with Pz=200 MeV/c, consisting of
two Gaussian distributions in space with σx=σy=2mm, σz=0.2mm, separated by 4mm along z.
The spacechargelw computation is a red line, and the spacecharge computation is black dots;
they use exactly the same set of 2,000 macroparticles. It is clear that some spatial resolution is
lost, due to the spatial averaging inherent in a grid, but that the computation is correct within the
approximation that defines its limitations. x=2 is well inside the bunch and the grid; x=9 is
outside the bunch but inside the grid.
The computation scales in many ways, and tests of proper scaling behavior were made for
variations in:
• Time step deltaT
• Total charge in the bunch
• Pz (longitudinal 3-momentum)
• R0 (initial radius of the bunch)
• Particle mass
• Sign of particle charge
The plot below keeps the total charge of the bunch constant, but varies the number of
macroparticles from 2,000 to 100,000. The grid is 65x65x513; its physical size is kept between
3/2 and 2 times the 99th percentile of the bunch dimensions. The vertical axis is the scaled radius
of the bunch and the horizontal axis is the scaled position along z of the bunch center; both axes
are scaled by factors involving Pz, particle mass, initial radius, and total charge – see the
textbook for details. The three red lines correspond to three initial conditions:
Reducing the grid to 33x33x257 (factor of 8 fewer grid points) does not affect the agreement
very much. This plot has 100,000 macroparticles.
Bz = 32 π N I / (53/2 a 10)
where I is the current in amperes, a is the coil radius in cm, N is the number of turns, and Bz is
given in gauss. The coil separation is of course equal to their radius. For N=1, I=10000 A, a=50
cm, this formula gives 179.84 gauss. G4beamline gives 0.017984 tesla, which is the same.
Bz = µ0 N I (cos α - cos β) / 2 L
Where µ0 is 4π×10-7, N is the number of turns, I is the current in amps, L is the solenoid length in
meters, and α and β are angles from the point on the axis to the ends of the solenoid; Bz is given
in tesla. The following plot compares this formula to G4beamline, for a solenoid of radius 200
mm and a length of 2,000 mm, centered at z=0. The formula is a black line and the G4beamline
data are red points:
5.2 genericbend
This plot of field lines shows how artificial the region containing the field is – the field is valid
only within the aperture, and within the aperture extended outside. In particular, the field is zero
inside the iron. The fringe field does not include effects from the sides, only the top and bottom.
The field lines are in 3-D, and this side view does not accurately reflect their density; it does
show the behavior of the fringe fields. The field lines look reasonable; to really appreciate this
you must run it and manipulate the image in real time to look at it from different directions.
The sum of the By entries in the trace file is 500.501, corresponding approximately to the field
integral ∫Bydl in tesla-mm. The correct value is 500.000, so the fringe-field computation has
indeed preserved the field integral, to within the accuracy of this simple integration technique.
5.3 genericquad
This plot of field lines shows how artificial the region containing the field is – the field is valid
only within the aperture, and within the aperture extended outside. In particular, the field is zero
inside the iron. The field lines are in 3-D, and these views do not accurately reflect their density,
but the side view does show the behavior of the fringe fields.
Test 2
Marco Apollonio has compared the G4beamline genericquad field to that of three TypeQC
quadrupole magnets in a row. The following plot compares field maps generated by Tosca to the
genericquad field. The mirror plates are 1-inch iron plates at the front and back to “reflect” the
field and thus reduce the extent of the fringe field along the axis; genericquad has no mirror
plates. The Tosca-generated maps were validated against measurements of one magnet, but the
details have been lost. This is a large quadrupole magnet with a pole-tip radius of 171 mm and an
overall length of 1,046 mm; its large diameter-to-length ratio implies that fringe fields are
important. Drawings of the magnet are on pages 11-12 of
http://hep04.phys.iit.edu/cooldemo/micenotes/public/pdf/MICE0065/MICE0065.pdf.
The following plot is of By along a line parallel to the z axis but off axis in x.
(Some field lines appear to be in the edge of the iron; they are not. This picture is rotated slightly
to ensure the field lines are visible.)
5.5 fieldmap
This plot of field lines shows a fieldmap with Bz proportional to x*y, looking from the z axis;
the field is valid only in a 1-meter cube, shown in dark gray. The field lines look reasonable; to
really appreciate this you must run it and manipulate the image in real time to look at it from
different directions.
5.6 fieldexpr
This plot of field lines shows a fieldmap with Bz proportional to x*y, looking from the z-axis;
the field is valid only in a 1-meter cube, shown in dark green. The field lines look reasonable; to
really appreciate this you must run it and manipulate the image in real time to look at it from
different directions.
5.7 multipole
These plots of field lines show multipoles from dipole thru dodecapole, looking from the z-axis.
The field lines look reasonable; to really appreciate this you must run it and manipulate the
image in real time to look at it from different directions. The field lines are in 3-D, and these
views do not accurately reflect their density.
5.8 pillbox
These plots of E-field (left) and B-field (right) lines show a pillbox looking from the z-axis, at 90
degrees in the RF cycle (max fields). The field lines look reasonable; to really appreciate this you
must run it and manipulate the image in real time to look at it from different directions). The
inner red circle is a window for muon accelerators. The field lines are in 3-D, and these views do
not accurately reflect their density.
Test 2
The magnitude of the RF B-field has been compared to a pillbox modeled in Superfish by
Milorad Popovic. The value was correct to 0.1%. This was comparing the maximum B-field for a
given accelerating voltage in a given pillbox geometry. The details have been lost.
Test 3
Shahid Ahmed of JLab has tested deflecting/crabbing cavity beam dynamics studies and made a
comparison of simulations with different codes. The figures show comparison of deflection and
displacement of an 11 GeV electron passing through the axis of the superconducting deflecting
cavity.
The following plots compare the equilibrium orbits for helicaldipole (blue) to the helical
solenoid (red). The discrepancies between the two systems are at the 0.01 mm level.
5.10 absorber
The absorber command uses polycones and tubs to implement a complex absorber geometry.
Visualization and tracking are consistent with its definition. The details have been lost.
5.11 material
G4beamline materials use the NIST database implemented by the Geant4 collaboration. Here is a
comparison of selected materials between G4beamline and the PDG “Particle Physics Booklet”,
July 2008:
Material Density (g/cm3) Radiation Length (m) Nucl. Interact. Length (m)
G4beamline PDG G4beamline PDG G4beamline PDG
LH2 0.07080 0.071 8.904 8.879 4.982 7.324
LiH 0.820 0.820 0.971 0.971 0.732 0.830
He 0.000166 0.000166 5,671 5,682 3,343 4,277
Li 0.534 0.534 1.550 1.550 1.252 1.335
Be 1.848 1.848 0.353 0.353 0.395 0.421
C 2.000 2.210 0.213 0.193 0.401 0.193
Al 2.699 2.699 0.0890 0.0889 0.389 0.397
The densities and radiation lengths are consistent, but the nuclear interactions lengths differ
substantially. It’s not clear what this means. Note that G4beamline (Geant4) tracking does not
use the nuclear interaction length directly, instead it uses a more accurate and much more
complicated technique based on cross-sections and densities.
5.12 cosmicraybeam
This command does not reproduce recent measurements very well (factors of 2-4), and needs to
be completely re-done.
Test 1
As a test of visualization consistency with tracking, a 10-by-10 array of cylinders was
constructed, and tracks were sent into it. The cylinders hit by the tracks are identified by the
steppingVerbose output, which can be compared to the picture below (1,1 is lower left in red,
10,10 is upper right). Careful examination in the viewer showed which cylinders were hit and
which were missed, in agreement with the steppingVerbose output from tracking.