Beamline Simulation » History » Version 14

« Previous - Version 14/16 (diff) - Next » - Current version
Junting Huang, 07/02/2019 05:35 PM

Beamline Simulation

Getting G4beamline Software

G4beamline is available on the grid. To set it up, run:

setup G4beamline v3_04

To run on a local computer, the latest G4beamline can be downloaded from
After installation, one can run its graphical interface or the command line tool g4bl in the terminal:



All the codes for the beamline simulation are on GitHub:

Tertiary Beam Simulation

Run G4beamline

The input for the G4beamline can be generated with One can simply run


It requires which is a custom module containing some styling functions for ROOT. It can be downloaded from

Note that in
  • beamline.write() produces to be given as input to g4bl.
  • beamline.plot_position() generates a plot with the coordinates of each beamline component.

After is generated, one can load it using the G4beamline GUI, or run it in the terminal, for instance:

g4bl particle=proton first=1 last=1000 momentum=64000 b_field=-0.9

It produces a file named beam.root which contains a NTuple for each detector. Each entry of a NTuple is a particle that passes the corresponding detector.

Another script,, borrowed from LArIAT and rewritten for NOvA, takes in the output of g4bl (beam.root), and restructures it:

python beam.root

It produces an output file named merge_tree.root in which each tree contains the information of one spill and has the name of "EventTree_Spill + spill number". Each entry of the tree is for a particle that enters the NOvA test beam detector, and contains the information of that particle at each beamline detector including its positions, momenta, etc. Naming convention of the tree leaves follows the scheme of "variable name + detector name". The meaning for each leaf is summarized in the table below.
| leaf (omitting the detector name) | meaning                                                                                                   |
| SpillID                           | spill ID, starts from 1                                                                                   |
| EventID                           | this is the index for the secondary beam particle on target, and starts from 0                            |
| TrackID                           | track ID, each particle should have an unique track ID in an event                                        |
| TrackPresent                      | whether this particle passes through this detector                                                        |
| x, y, z                           | x, y, z position in the detector coordinate system at which the particle passes through                   |
| Px, Py, Pz                        | x, y, z momentum in the detector coordinate system with which the particle passes through                 |
| PDGidnova                         | PDG code of the particle, for instance, electron is 11                                                    |
| Edep                              | energy deposition in the active region of the detector, for instance, for Cherenkov, it is the CO2 volume |
| ParentID                          | track ID of its parent                                                                                    |

The information here (stored in merge_tree.root) will be passed to the detector simulation (see Detector Simulation). This is the end of the beamline simulation.

To run jobs on the Fermigrid, one can use and, with certain modifications on the input and output path. After the grid job finishes, one can use hadd to concatenate the output files together:

hadd -f data/concatenated_file.root `pnfs2xrootd /pnfs/nova/scratch/users/username/*.root`

In order to use pnfs2xrootd, one may need to run setup_samweb2xrootd as defined below:
function setup_samweb2xrootd {
    kxlist -p
    voms-proxy-init --rfc --voms=fermilab:/fermilab/nova/Role=Analysis --noregen

    source /grid/fermiapp/products/common/etc/
    export PRODUCTS=/grid/fermiapp/products/common/db/:$PRODUCTS
    setup sam_web_client

MC Samples

The following is an example of the beamline MC sample (after, B = -0.9 T, 20 spills assuming 1M secondary beam particles per spill):


This is used to generate NOvA detector simulation MC samples in the downstream:

/nova/app/users/junting/testbeam/det/data/text_gen.g4bl.b_-0.9T.proton.64000.merge_tree.root.job_1_1000.20m.edep.root (noise particle included)
/nova/app/users/junting/testbeam/det/data/text_gen.g4bl.b_-0.9T.proton.64000.merge_tree.root.job_1_1000.20m.edep.exclude_noise.root (noise particle excluded)

See Detector Simulation for more details of the detector simulation procedure.

Secondary Beam Simulation

All the codes for the secondary beam is in folder secondary_beam.
The input to g4bl is It was obtained from Adam Watts with some modifications along the way.

To make plots, one can use