The G4beamline Tutorial given at LEMC 2008 was videotaped by Fermilab Visual Media Services. part 1
part 2
Click here
for a Flash video giving a simple example of using G4beamline.
G4beamline is now available for Windows XP , for Macintosh OS X (Intel), and for Linux (Intel).
General
G4beamline is a single-particle tracking program based on the
Geant4
simulation toolkit. It is specifically designed for the simulation of beamlines.
The key aspect of g4beamline is that the input file defining the simulation is not significantly more complicated than the problem being simulated (by contrast, any C++ simulation program will inherently be significantly more complicated than the problem) — G4beamline isolates the user from programming complexities. To make this possible, g4beamline does not give the user all of the power and flexibility of the underlying Geant4 toolkit; it does, however, provide enough flexibility to simulate many different systems that can be considered "beamlines" one way or another. For instance, there is a "cosmic-ray beam", and the notion of "beamline" is rather flexible. In use, one normally just lays out the beamline elements along the beam centerline, using "centerline coordinates" that rotate appropriately whenever needed (e.g. when a bending magnet is placed, or at a target to take a secondary beam off at an angle).
Note that no programming at all is required to simulate systems that use beamline elements already in g4beamline's repertoire. This includes bending magnets, quadrupoles, solenoids, materials of all types in the shape of boxes, cylinders, tubes, spheres, and polycones, pillbox RF cavities, and a few specialized elements for muon cooling. The distribution includes an executable program that runs on Windows Xp, Mac OS X (Intel), or on most modern versions of Linux (it has been tested to run on all RedHat-drived distributions since 7.1, including Fedora Core 1-8). Moreover, the visualization capabilities of Geant4 are available with no further effort, including visualization using OpenInventor, OpenGL, HepRep, DAWN, VRML, and other viewers (as long as your system supports X-windows with the GLX extension). The internal design of the program makes it relatively simple to add new commands and beamline elements to its repertoire (this does, however, require C++ programming).
A major limitation of g4beamline is that at present it does not simulate the performance of real-world detectors. It implements "virtual" detectors which sample the tracks that intersect them with the precision of a float, and measure all tracking variables (X,Y,Z,Px,Py,Pz,t,PDGid). Each virtualdetector generates an NTuple in the output file, which can be histogrammed with the appropriate program. NTuples can be written to Root or ASCII files, and the
historoot program is included to make it easy o generate plots using Root. So g4beamline will tell you where the particles go, but won't give details of real-world detector outputs.
Another limitation of g4beamline is that at present it does not implement parameterized placements of volumes. These are required for a practical implementation of the many segments of modern detectors.
Please join and use our
G4beamline forum. You can self-register using the LOGIN module at the left (valid email required), and immediately start posting to the forum.
Getting Started
G4beamline is distributed as a tarball for Linux/Intel, For Windows XP, and for Mac OS/Intel, available
here. More details are contained in the
G4beamline User's Guide
, and in the README-*.txt files.
Linux (Intel)
If you intend to install and run G4beamline on your Linux desktop, and it is already running either KDE or Gnome (or a similar X Windows desktop), and the OpenGL and Motif extensions are already installed on your system, then this Quick Start Guide is for you. If you are doing something more complicated (e.g. you have a Windows desktop and use Exceed to connect to a Linux server), then this may help, but you'll probably need to read README-Linux.txt. These instructions assume you are using the bash shell; for other shells modify them accordingly.
The details are available in
README-Linux.txt
.
The setup script will assist you in adding the G4beamline programs into a directory in your PATH.
This takes 5-10 minutes to run more than 50 tests. the output should end with "All Tests Passed".
- Now move to the examples directory and look at the examples; try the following:
cd $HOME/g4beamline-VERSION/examples
# first visualize the system
g4bl example1.in viewer=best
# (play with the viewer, then ^C)
# then generate NTuples for histogramming
g4bl example1.in
# and histogram the NTuples
historoot g4beamline.root
# (play with HistoRoot, then exit)
... similarly for the other examples ...
| Files and Directories in the G4beamline Tarball
|
| G4beamlineUsersGuide.pdf | User's Guide
|
| HISTORY.txt | The development history of the program.
|
| INSTALL.txt | Instructions for installation and building g4beamline.
|
| Magnets | Directory containing some magnetic field maps used in the examples.
|
| README.txt | A general introduction to g4beamline.
|
| Windows | Directory containing some window profiles used in the examples.
|
| bin | Directory containing excutable programs and scripts.
|
| gui | Directory containing Java classes and images for the graphical user interface
|
| data | Directory containing the physics data required by Geant4.
|
| examples | Directory containing some examples.
|
| g4beamline.ppt | A PowerPoint® presentation about g4beamline.
|
| help.txt | A copy of the current help text.
|
| ldd.txt | A list of the shared objects required by g4beamline (for debugging the installation).
|
| lib | Directory containing required libraries.
|
| packages | Directory containing packages required for building g4beamline (contained in the -devel- tarball only.
|
| source | Directory containing the g4beamline source (contained in the -devel- tarball only).
|
| todolist.txt | Decription of items still to be done.
|
| viewer.def | A file that controls how the different viewers are handled.
|
Windows XP
This release for Windows XP includes a standard Windows installer which puts shortcuts onto your desktop and into the start menu. It can also be used with the Cygwin command-line.
Macintosh OS X (Intel)
This release for Mac OS X supports only the recent Intel Processors. See
README-MacOSX.txt
. Installation and startup is essentially the same as for Linux (above), except Mac OS X is called "Darwin".
Documentation
Here is a recent
G4beamline User's Guide
. It is updated for each release and included in the execution tarball.
Here is internal documentation for all classes in G4beamline:
Doxygen
.
New Feature Requests
G4beamline is developed in a
user-driven methodology that encourages rapid release cycles and user contributions. To request a new feature, simply join the G4beamline forum and post a message describing your request in as much detail as possible. here's the current list of things users have suggested (in no particular order):
- Space charge computations
- polarized physics
- very low energy physics (< 100 eV)
- better handling of exceptions and faults
- electron emission from an arbitrary surface, weighted by E^n
- permit use of local coordinates in virtualdetector
- user-defined cuts per volume and per material
- implement the general particle generator
- implement importance sampling, and the ability for users to easily control cross-sections
- add the new solids that Geant4 supports not in G4beamline
- fringe fields in sector bends
- let printf also print fields
- implement a method to compute the total energy deposited in an object, and put it into an NTuple
- configurable background color in viewers
- asymmetric scaling in viewers (e.g. magnify x and y for long beamlines)
- can the RF frequency in a ring be tuned so the reference particle has an integral number of cycles?
- implement Fano and Tollestrup models for multiple scattering
- automate small installation errors
- permit the user to define solids directly and build up objects via boolean operations (etc.)
Download
The installer or tarball contains everything required to run the program, except for the prerequisites listed below, and some physics data needed for low energy physics processes (e.g. thermal neutrons — see the Geant4 website).
Please join and use our
G4beamline forum. You can self-register using the LOGIN module at the left (valid email required), and immediately start posting to the forum.
G4beamline release 1.14b is now available (20-JUNE-2008).
This release uses Geant4 9.1.p01. It is
just like release 1.14 except that several bugs have been fixed and a few new features have been implemented. It is an
incremental release, and the User's guide has not been updated, so use the online help (either in the GUI or via the help command).
Major Changes:
- Objects can be placed inside a genericbend (new argument openAperture)
- Extended-precision is available in steppingFormat (see help)
- Bugs in sphere are fixed
- Bugs in beam command after a corner are fixed
- Eventcuts interface to historoot is completed.
- historoot now works with root 1.18 (including Mac OS 10.5, leopard).
- multiple runs in the GUI use different events.
- the major changes for 1.14 also apply
Known Bugs:
- The Windows version does not run on Windows Vista.
- The Windows version will crash in physics-list QGSP for hadrons over 12 GeV; there is no such problem on Linux or Mac OS.
- The LISAPhysicsList does not work.
- In Windows, if the .root file is open (e.g. in HistoRoot), then G4beamline cannot write to it, and crashes with a cryptic message (assert failed ntuple!=0 && n==nFields). To avoid, use File/CloseAllFiles in Historoot.
- If Root is not properly installed, G4beamline may issue an error message about not being able to open bool.h — this is benign and can be ignored.
We are working to resolve all of these issues. Microsoft has released a new version of VC++ specifically targeted for Windows Vista, so there is hope the first two bugs will be resolved soon.
Linux
1. cd to your HOME directory (or other directory into which you want to install)
2. download g4beamline-1.14b-Linux-g++.tgz
3. tar -xzf g4beamline-1.14b-Linux-g++.tgz
4. rm g4beamline-1.14b-Linux-g++.tgz (optional clean-up)
5. cd g4beamline-1.14b-Linux-g++
6. ./setup
The setup script will guide you through adding the G4beamline programs into a directory in your PATH.
Note: you may need to install openmotif from your Linux distribution (libXm.so.3).
The programs are:
- g4bl — runs g4beamline
- g4blgui — runs the same GUI used by default on Windows
- historoot — provides a GUI to the Root histogramming capabilities
Mac OS X 10.4, 10.5 (Intel)
1. cd to your HOME directory (or other directory into which you want to install)
2. download g4beamline-1.14b-Darwin-g++.tgz
3. tar -xzf g4beamline-1.14b-Darwin-g++.tgz
4. rm g4beamline-1.14b-Darwin-g++.tgz (optional clean-up)
5. cd g4beamline-1.14b-Darwin-g++
6. ./setup
The setup script will guide you through adding the G4beamline programs into a directory in your PATH.
Note: you may need to use Fink Commander to install lesstif (libXm.2.0.1.dylib).
The programs are:
- g4bl — runs g4beamline
- g4blgui — runs the same GUI used by default on Windows
- historoot — provides a GUI to the Root histogramming capabilities
Note the G4beamline viewers all use X-windows, but the GUIs (g4blgui, historoot) run native Mac OS (i.e. quartz). This means that to use a viewer you must run
g4bl from an Xterm window, which you get by running the X-Windows application (automatic on Leopard).
Windows
G4beamline-1.14b.msi
This is an installer — just download and double-click it and it will install itself in the usual way, including putting shortcuts onto your desktop and into the Start menu. If you have installed Cygwin, you can also use the command-line programs in the same way as on Linux and Mac OS. Note you cannot run the tests without Cygwin (at present they are command-line only).
Source
First download the release for your platform and install it as above, then un-tar this tarball
g4beamline-1.14b-source.tgz
into the top g4beamline-1.14b-* directory. See BUILD.txt for a detailed description of how I build G4beamline on all 3 platforms.
G4beamline release 1.14 is now available (1-MAR-2008).
[+]
This release uses Geant4 9.1.p01.
Prerequisites:
- Java (1.5 or later), required for the GUI; g4beamline itself does not use Java
- Root (5.12 thru 5.16), required to use HistoRoot; g4beamline itself does not need Root installed (it includes the Root libraries it needs)
- tcl (any version), required for the tests; g4beamline itself does not use tcl
- Motif, OpenMotif, or LessTif on Linux and Mac
Known Bugs:
- The Windows version does not run on Windows Vista.
- The Windows version will crash in physics-list QGSP for hadrons over 12 GeV; there is no such problem on Linux or Mac OS.
- The LISAPhysicsList does not work.
- historoot does not work with Root version 5.18; it does work with versions 5.12, 5.14, and 5.16.
- Multiple runs in the GUI simply re-run the same events.
- In Windows, if the .root file is open (e.g. in HistoRoot), then G4beamline cannot write to it, and crashes with a cryptic message (assert failed ntuple!=0 && n==nFields). To avoid, use File/CloseAllFiles in Historoot.
- If Root is not properly installed, G4beamline may issue an error message about not being able to open bool.h — this is benign and can be ignored.
We are working to resolve all of these issues. Microsoft has released a new version of VC++ specifically targeted for Windows Vista, so there is hope the first two bugs will be resolved soon.
Major Changes
- By default the coil command now determines maxR to meet the tolerance, rather than setting it to innerRadius — this takes a lot more memory, but means you will not get incorrect results for rotated coils.
- new command: extrusion. Extrudes an arbitrary polygon in X-Y along Z.
- most materials are available from the NIST database, so you don't need to look them up; see "help material" for details.
- virtualdetector and particlefilter now have an innerRadius argument, so they can be a tube or a solid cylinder.
- new command: tracker. It implements track-fitting to hits in trackerplanes.
- the file argument of absorber has changed: previously it prepended "Windows/" to the argument, removed.
- There is a new parameter Zcl, which is always set to the downstream end of the previous object placed, in centerline coordinates.
- New command: newparticlentuple. Generates an NTuple for all particle creations (including the beam).
There are also numerous bug fixes and improvements.
Linux
1. cd to your HOME directory (or other directory into which you want to install)
2. download g4beamline-1.14-Linux-g++.tgz
3. tar -xzf g4beamline-1.14-Linux-g++.tgz
4. rm g4beamline-1.14-Linux-g++.tgz (optional clean-up)
5. cd g4beamline-1.14-Linux-g++
6. ./setup
The setup script will guide you through adding the G4beamline programs into a directory in your PATH.
Note: you may need to install openmotif from your Linux distribution (libXm.so.3).
The programs are:
- g4bl — runs g4beamline
- g4blgui — runs the same GUI used by default on Windows
- historoot — provides a GUI to the Root histogramming capabilities
Mac OS X 10.4 (Intel)
1. cd to your HOME directory (or other directory into which you want to install)
2. download g4beamline-1.14-Darwin-g++.tgz
3. tar -xzf g4beamline-1.14-Darwin-g++.tgz
4. rm g4beamline-1.14-Darwin-g++.tgz (optional clean-up)
5. cd g4beamline-1.14-Darwin-g++
6. ./setup
The setup script will guide you through adding the G4beamline programs into a directory in your PATH.
Note: you may need to use Fink Commander to install lesstif (libXm.2.0.1.dylib).
The programs are:
- g4bl — runs g4beamline
- g4blgui — runs the same GUI used by default on Windows
- historoot — provides a GUI to the Root histogramming capabilities
Note the G4beamline viewers all use X-windows, but the GUIs (g4blgui, historoot) run native Mac OS (i.e. quartz). This means that to use a viewer you must run
g4bl from an Xterm window, which you get by running the X-Windows application.
Windows
G4beamline.msi
This is an installer — just download and double-click it and it will install itself in the usual way, including putting shortcuts onto your desktop and into the Start menu. If you have installed Cygwin, you can also use the command-line programs in the same way as on Linux and Mac OS. Note you cannot run the tests without Cygwin (at present they are command-line only).
Source
First download the release for your platform and install it as above, then un-tar this tarball
g4beamline-1.14-source.tgz
into the top g4beamline-1.14-* directory. See BUILD.txt for a detailed description of how I build G4beamline on all 3 platforms.
G4beamline release 1.13 is now available (21-Sep-2007).
[+]
This release uses Geant4 9.0.p01. Root is now the default format for all NTuples (HistoScope is still available on Linux).
Prerequisites:
- Java (1.5 or later), required for the GUI; g4beamline itself does not use Java
- Root (5.12 thru 5.16), required to use HistoRoot; g4beamline itself does not need Root installed (it includes the Root libraries it needs)
- tcl (any version), required for the tests; g4beamline itself does not use tcl
Download for Linux:
g4beamline-1.13-Linux-g++.tgz
Just un-tar the tarball in $HOME (tar -xzf file.tgz), add its bin to your PATH, and use it as before. There are two new commands:
- g4blgui — runs the same GUI used by default on Windows
- historoot — provides a GUI to the Root histogramming capabilities
Download for Mac OS X 10.4 (Intel):
g4beamline-1.13-Darwin-g++.tgz
(The remarks for Linux all apply.) Note the viewers all use X-windows, but the GUIs (g4blgui, historoot) run native Mac OS (i.e. quartz).
Download for Windows:
G4beamline-1.13.msi
This is an installer — just double-click it and it will install itself in the usual way, including putting shortcuts onto your desktop and into the Start menu. If you have installed Cygwin, you can also use the command-line programs in the same way as on Linux and Mac OS. Note you cannot run the tests without Cygwin (at present they are command-line only). viewer=best now uses OpenInventor, but the Wired3 viewer remains in the install package.
Download the source:
g4beamline-1.13-source.tgz
(Download the release for your platform and install it, then un-tar this tarball into the top g4beamline-1.13-* directory.)
G4beamline release 1.12 is now available (07-May-2007).
[+]
This release uses Geant4 8.3. Root is now the default format for all NTuples (HistoScope is still available on Linux).
Prerequisites:
- Java (1.5 or later), required for the GUI; g4beamline itself does not use Java
- Root (5.12 or later), required to use HistoRoot; g4beamline itself does not need Root installed (it includes the Root libraries it needs)
- tcl (any version), required for the tests; g4beamline itself does not use tcl
Download for Linux:
g4beamline-1.12-Linux-g++.tgz
Just un-tar the tarball in $HOME (tar -xzf file.tgz), add its bin to your PATH, and use it as before. There are two new commands:
- g4blgui — runs the same GUI used by default on Windows
- historoot — provides a GUI to the Root histogramming capabilities
Download for Mac OS X 10.4 (Intel):
g4beamline-1.12-Darwin-g++.tgz
(The remarks for Linux all apply.) Note the viewers all use X-windows, but the GUIs (g4blgui, historoot) run native Mac OS (i.e. quartz).
Download for Windows:
G4beamline-1.12.msi
This is an installer — just double-click it and it will install itself in the usual way, including putting shortcuts onto your desktop and into the Start menu. If you have installed Cygwin, you can also use the command-line programs in the same way as on Linux and Mac OS. Note you cannot run the tests without Cygwin (at present they are command-line only). viewer=best now uses OpenInventor, but the Wired3 viewer remains in the install package.
Download the source:
g4beamline-1.12-source.tgz
(Download the release for your platform and install it, then un-tar this tarball into the top g4beamline-1.12-* directory.)
G4beamline version 1.11 is not released; it was used for extensive debugging of the Windows version.
[+]
G4beamline release 1.10 is now available (07-February-2007).
[+]
Root is now the default format for all NTuples (HistoScope is available on Linux only).
Prerequisites:
- Java (1.5 or later), required for the GUI; g4beamline itself does not use Java
- Root (5.12 on Linux, 5.14 on Mac OS and Windows); g4beamline will not run without Root
- tcl (any version), required for the tests; g4beamline itself does not use tcl
Download for Linux:
g4beamline-1.10-Linux-g++.tgz
Just un-tar the tarball in $HOME (tar -xzf file.tgz), add its bin to your PATH, and use it as before. There are two new commands:
- g4blgui — runs the same GUI used by default on Windows
- historoot — provides a GUI to the Root histogramming capabilities
Download for Mac OS X 10.4 (Intel):
g4beamline-1.10-Darwin-g++.tgz
(The remarks for Linux all apply.)
Download for Windows:
g4beamline-1.10-WIN32-VC.msi
This is an installer — just double-click it and it will install itself in the usual way, including putting shortcuts onto your desktop and into the Start menu. If you have installed Cygwin, you can also use the command-line programs in the same way as on Linux and Mac OS. For now this is a trial version of Advanced Installer, so accept the screen that says that. Note you cannot run the tests without Cygwin (at present they are command-line only).
This release uses Geant4 8.2.
The development tarball is not available at this time.
G4beamline release 1.09 has been withdrawn.
While it passes all tests, several of the examples exhibit anomalous behavior on Mac OS X and on Windows.
This has been traced to a binary file incompatibility between Mac OS and Windows — only if you run the examples on the two different OSs in the same directory will you see this. Fixed in release 1.10.
G4beamline release 1.08 is now available (18-December-2006).
[+]
Download the Execution tarball
g4beamline-1.08.tgz
This release uses Geant4 8.2, which greatly improves the accuracy of multiple scattering. It also supports Root input and output files.
The development tarball is not available at this time.
G4beamline release 1.07 is now available (6-November-2006).
[+]
Download the Execution tarball
g4beamline-1.07.tgz
Download the Development tarball
g4beamline-devel-1.07.tgz
Fixes a bug that occasionally caused some tracks to miss a Z-position for printf, profile, or zntuple. Uses Geant4 8.1 patch-01.
G4beamline release 1.06 (15-October-2006).
[+]
Download the Execution tarball
g4beamline-1.06.tgz
Download the Development tarball
g4beamline-devel-1.06.tgz
New commands: randomize, tune, printf, profile, and zntuple. See the new section in the User's Guide on Tuning. Uses Geant4 version 8.1.
G4beamline release 1.05 (8-July-2006).
[+]
Download the Execution tarball
g4beamline-1.05.tgz
Download the Development tarball
g4beamline-devel-1.05.tgz
The primary new feature is this release uses Geant 4 release 8.1. There are many changes to physics processes, including muon and electron multiple scattering.
G4beamline release 1.04 (21-MAY-2006).
[+]
Download the Execution tarball
g4beamline-1.04.tgz
Download the Development tarball
g4beamline-devel-1.04.tgz
The primary new feature is the ability to use multiple $paramname values in an argument, and to use expressions in numeric arguments. There are also some minor bug fixes (see HISTORY.txt for details).
The build problem mentioned in 1.02 remains.
G4beamline release 1.03 (10-MAY-2006).
[+]
Download the Execution tarball
g4beamline-1.03.tgz
Download the Development tarball
g4beamline-devel-1.03.tgz
NOTE: all previous versions of g4beamline had a serious bug related to object arguments on the place command — units were not applied properly, and for some objects the change in arguments simply did not get done properly. Fortunately, the most common such arguments (e.g. current for a magnet or solenoid) did work properly. Arguments on the object commands were not affected. Release 1.03 completely re-designed the handling of arguments, and it now works properly. Many object arguments cannot be changed on the place command; these are now documented and such changes are prevented.
The build problem mentioned in 1.02 remains.
G4beamline release 1.02 (26-MAR-2006).
[+]
Download the Execution tarball
g4beamline-1.02.tgz
Download the Development tarball
g4beamline-devel-1.02.tgz
Known Bug: There is a problem building g4beamline using gcc version 4.X. This occurs when building the BLphysics library, and is related to "functor templates". This is Geant4 code, and a fix will probably have to wait until g4beamline moves to Geant4 release 8.X. This problem does not occur for gcc version 3.X (which is used to build the distribution). It probably applies to all releases of g4beamline on this page. This does not apply to users who just download g4beamline and use it, only to users who download g4beamline-devel and then build it on a system that uses gcc version 4.X.
G4beamline release 1.01 (18-FEB-2006).
[+]G4beamline release 1.0 (6-FEB-2006).
[+]
Support
Please join and use our
G4beamline forum. You can self-register using the LOGIN module at the left (valid email required), and immediately start posting to the forum.
Example
A simple example input file is example1.in, a simulation of a simple Gaussian beam going into 4 virtual detectors. As you can see, there are a handful of general definitions (the physics and beam commands), and then you just define the elements you need (box Beam, virtualdetector Det) and place them where they go (the 5 place commands). With the included HistoScope program, this is all that is needed to visualize the system, and to generate the histograms below (and, of course, many more).
* example1.in 4/2/03 TJR
*
* Simple example g4beamline input file:
* a 200 MeV mu+ Gaussian beam is tracked through 1-meter drift
* spaces into four detectors
# QGSP is the "default" physics use-case for High Energy Physics
physics QGSP
# the beam is nominally headed in the +Z direction
beam gaussian particle=mu+ nEvents=1000 beamZ=0.0 \
sigmaX=10.0 sigmaY=10.0 sigmaXp=0.100 sigmaYp=0.100 \
meanMomentum=200.0 sigmaP=4.0 meanT=0.0 sigmaT=0.0
# BeamVis just shows where the beam comes from
box BeamVis width=100.0 height=100.0 length=0.1 material=Vacuum color=1,0,0
place BeamVis z=0
# define the detector
virtualdetector Det radius=1000.0 color=0,1,0
# place four detectors, putting their number into their names
place Det z=1000.0 rename=Det#
place Det z=2000.0 rename=Det#
place Det z=3000.0 rename=Det#
place Det z=4000.0 rename=Det#
Here is the OpenInventor graphics system displaying this example. Note the red BeamVis and the four green Det-s, plus three blue mu+ tracks. In the real viewer you can use the mouse to zoom, pan, and rotate the image in real time, and select wireframe mode so you can look inside solid objects.
Here is a set of histograms generated by HistoScope from this example. In the HistoScope program you can interactively use the mouse to select an NTuple, select which field(s) of the NTuple to plot, create new variables in terms of the NTuple fields, zoom and pan the plot axes, and apply cuts. You can interactively vary the cut values and watch the effect on the plot in real time, and can combine multiple plots into a single image, as was done here. There are many types of plots, including the simple histograms shown here.