Convert MCNP PTRAC file to a ROOT TTree

This software takes an MCNP PTRAC file, in ASCII format, and converts it to a ROOT TTree data structure. An energy spectrum histogram is also created. The TTree and histogram are saved to a ROOT file. A companion ROOT script (ptracTree.C) opens the ROOT file, finds the TTree and loops over the events, creating simple histograms that are displayed in a TCanvas. The script serves as a backbone script to be modified with a more sophisticated analysis of the events. The codes (ptrac2root.cpp and ptracTree.C) are well-documented with comments and instructions.

Compilation and installation

Included is a Makefile to compile the code. Simply execute the Makefile with,

$ make
$ make install

The executable ptrac2root is readily available in /usr/local/bin/.

Execution

The PTRAC file generated after execution of an MCNP simulation is converted by running ptrac2root,

$ ptrac2root <MCNP input filename> [NCH] [NMAX]

The MCNP input file is required, whereas NCH and NMAX are optional arguments. NCH and EMAX are the number of channels (16384 by default) and the maximum energy (20 MeV by default) of the histogram, respectively.

For instance, the simulation from "Co-60 source and Ge crystal inside a concrete room", is converted from PTRAC to ROOT by,

$ ptrac2root co60 4096 2
opened ROOT file co60.root
decoding file co60p
closed PTRAC file co60p
******************************************************************************
*Tree :co60 : MCNP co60 *
*Entries : 25996 : Total = 835654 bytes File Size = 621880 *
* : : Tree compression factor = 1.34 *
******************************************************************************
*Br 0 :events : x/F:y/F:z/F:u/F:v/F:w/F:e/F:t/F *
*Entries : 25996 : Total Size= 835279 bytes File Size = 621116 *
*Baskets : 27 : Basket Size= 32000 bytes Compression= 1.34 *
*............................................................................*
TFile** co60.root
TFile* co60.root
OBJ: TTree co60 MCNP co60 : 0 at: 0x561641f980c0
OBJ: TH1F MCNP E co60 E co60 : 0 at: 0x561642144f40
KEY: TH1F MCNP E co60;1 E co60
KEY: TTree co60;1 MCNP co60
closed ROOT file co60.root

25996 histories read, 27395 events processed, 25996 events saved

and the histogram would have 4096 channels and an energy range of [0,2] MeV. The histogram can be retrieved and displayed within a ROOT file browser window,

$ root
root [0] new TBrowser

or with the spectrum.C script,

$ root
root [0] .L spectrum.C
root [1] plot()

included in every MCNP simulation.

The TTree is read and the events analyzed with the ROOT script ptracTree.C. First copy the script and rootTree.h to the working directory, and then execute the script,

$ root
root [0] .L ptracTree.C
root [1] ptracTree("co60")
opened ROOT file co60.root
******************************************************************************
*Tree :co60 : MCNP co60 *
*Entries : 25996 : Total = 835542 bytes File Size = 621880 *
* : : Tree compression factor = 1.34 *
******************************************************************************
*Br 0 :events : x/F:y/F:z/F:u/F:v/F:w/F:e/F:t/F *
*Entries : 25996 : Total Size= 835167 bytes File Size = 621116 *
*Baskets : 27 : Basket Size= 32000 bytes Compression= 1.34 *
*............................................................................*

Several histograms are created, for example,

This is a 2D histogram of the directions of cosine of the events.

Dependencies

This software has been developed and tested using the GNU C++ compiler with the 2011 C++ standard.

The make utility is standard in most Linux distributions. In Debian-based systems, install make with,

$ sudo apt-get install make

Current version of ROOT can be downloaded, compiled and installed in most Linux distributions. In Debian-based systems, the tutorial "Installing CERN ROOT on Debian GNU/Linux 12 (bookworm)" may be of use.

Terms of Use and License

Before buying this software, please read our Terms of Use and License.

List of Files

Included in this software package are the following files:

  • ptrac2root.cpp (program to convert PTRAC file to a ROOT TTree)
  • rootTree.h (header file)
  • ptracTree.C (ROOT script to analyze TTree events)
  • Makefile
  • README (documentation)
  • terms.md (terms of use)
  • license.md (license)