Project

General

Profile

Beamline Simulation » History » Version 15

Version 14 (Junting Huang, 07/02/2019 05:35 PM) → Version 15/16 (Junting Huang, 07/19/2019 04:45 PM)

h1. Beamline Simulation

h2. Getting G4beamline Software

G4beamline is available on the grid. To set it up, run:
<pre>
setup G4beamline v3_04
</pre>

To run on a local computer, the latest G4beamline can be downloaded from
http://www.muonsinternal.com/muons3/G4beamline
After installation, one can run its graphical interface or the command line tool _g4bl_ in the terminal:
<pre>
g4bl input.in
</pre>

h2. Codes

All the codes for the beamline simulation are on GitHub:
https://github.com/UTKLgroup/nova.junting/tree/master/testbeam

h2. Tertiary Beam Simulation

h3. Run G4beamline

The input for the G4beamline can be generated with beamline.py. One can simply run
<pre>
python beamline.py
</pre>

It requires _rootalias.py_ which is a custom module containing some styling functions for ROOT. It can be downloaded from
https://github.com/UTKLgroup/rootrc.junting

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

After beamline.py.in is generated, one can load it using the G4beamline GUI, or run it in the terminal, for instance:
<pre>
g4bl beamline.py.in particle=proton first=1 last=1000 momentum=64000 b_field=-0.9
</pre>
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, _merge_tree.py_, borrowed from LArIAT and rewritten for NOvA, takes in the output of g4bl (_beam.root_), and restructures it:
<pre>
python merge_tree.py beam.root
</pre>
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.
<pre>
|-----------------------------------+-----------------------------------------------------------------------------------------------------------|
| 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 |
|-----------------------------------+-----------------------------------------------------------------------------------------------------------|

</pre>
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 _job_script.sh_ and _job_submit.sh_, with certain modifications on the input and output path. After the grid job finishes, one can use _hadd_ to concatenate the output files together:
<pre>
hadd -f data/concatenated_file.root `pnfs2xrootd /pnfs/nova/scratch/users/username/*.root`
</pre>
In order to use pnfs2xrootd, one may need to run setup_samweb2xrootd as defined below:
<pre>
function setup_samweb2xrootd {
kx509
kxlist -p
voms-proxy-init --rfc --voms=fermilab:/fermilab/nova/Role=Analysis --noregen

source /grid/fermiapp/products/common/etc/setups.sh
export PRODUCTS=/grid/fermiapp/products/common/db/:$PRODUCTS
setup sam_web_client
}
</pre>

h3. MC Samples

The following is an example of the beamline MC sample (after merge_tree.py, B = -0.9 T, 20 spills assuming 1M secondary beam particles per spill):
<pre>
/nova/app/users/junting/testbeam/beam/data/g4bl.b_-0.9T.proton.64000.merge_tree.root.job_1_1000.20m.edep.root
</pre>

This is used to generate NOvA detector simulation MC samples in the downstream:
<pre>
/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)
</pre>
See [[Detector Simulation]] for more details of the detector simulation procedure.

h2. Secondary Beam Simulation

All the codes for the secondary beam is in folder secondary_beam: secondary_beam.
https://github.com/UTKLgroup/nova.junting/tree/master/testbeam/secondary_beam

secondary.in:
The input to g4bl input. is secondary.in. It was obtained from Adam Watts with some modifications along the way.

secondary.watts.in: latest input file from Adam Watts.

mc5_mc6_final_as_sets_as_founds.xlsx: secondary beam alignment data
To make plots, one can use secondary.py.