g4beamline

g4beamline is a program to run geant4 simulations of beamlines. It is designed to be easy to use, extremely flexible, and easily extensible.

Extending the g4beamline program

Additional elements and commands can easily be added to the g4beamline program by simply deriving additional classes from BLElement or BLCommand. The source has lots of examples of each. The basic idea is that for each command or element the .cc file defines a global default instance, and the default constructor registers the command with BLCommand so it can be used in the input file. Virtual functions from BLCommand define the parameters of the command (see BLCommand for details). New elements can be placed (via the "place" command) as usual.

Implementation Notes

The commands for an input file are all implemented as individual classes in individual .cc files, derived from BLCommand. The class BLCommand handles reading the input file, parsing commands, parsing command arguments (both positional and named), and implementing first-character commands (/, *, #, and !). Derived commands simply declare their arguments (via calls to argString(), argInt(), and argDouble()), and handleNamedArgs() manages putting the values from the command line into the class variables. Conventionally, the class name, filename, and command name are interrelated:

	command name:	example
	class name:	BLCMDexample
	file name:	BLCMDexample.cc
Most commands do not require a .hh file, as the class is used only in the class's .cc file. Exceptions are classes used by other commands (e.g. BLCMDcoil is used by BLCMDsolenoid).

Beamline elements are also implemented as individual classes in individual .cc files, derived from BLElement (which is derived from BLCommand, so every element includes a command to create an instance of the element). The place command places instances of a given element into the current group.

The class BLManager interfaces to BLRunManager, and implements all of the user customization classes (G4UserSteppingAction, G4UserDetectorConstruction, etc.). Element classes can register with BLManager to have a UserSteppingAction() function called for every reference-particle or beam step referring to a specific G4VPhysicalVolume. For a simple example of this see BLCMDvirtualdetector.cc.

g4beamline