Creating TTrees from Monte Carlo Events

From EIC
Jump to navigation Jump to search
CreateROOTTreeFromGenerators.C is deprecated. For a description of the new tree-building code, see BuildTree.

Monte Carlo events generated by RAPGAP, PYTHIA and PEPSI can be converted to a ROOT TTree format using the macro CreateROOTTreeFromGenerators.C. The macro contains a function named CreateROOTTreeFromGenerators() which reads and parses the Monte Carlo events and creates and fills a TTree to store the data. The macro can be found in the directory

/afs/rhic.bnl.gov/eic/MACROS/

Before it can be run the macro must be compiled in ROOT. This can be done using ROOT's Automatic Compiler ACLiC. To do this, load the macro in an interactive ROOT session with '++' appended to its name:

root [0] .L CreateROOTTreeFromGenerators.C++

This will generate the shared library file CreateROOTTreeFromGenerators_C.so. When you compile the macro the shared library is then automatically loaded into ROOT. In subsequent ROOT sessions you do not need to recompile the macro (unless it has been modified); the shared library can be loaded via

root [0] gSystem->Load("CreateROOTTreeFromGenerators_C.so");

Running the Macro

Once the shared library is loaded, the function CreateROOTTreeFromGenerators() can be called. It takes three arguments, the first of which is mandatory and the second and third of which are optional:

  • The first argument is a character string giving the name of the input Monte Carlo event file.
  • The second argument is the directory in which to write the output file. By default this is the current directory (".").
  • The third argument is the maximum number of events to process. The default value will cause the macro to process all events in the input file.

Note that you do not need to specify which of the aforementioned Monte Carlo generators was used to generate the events; the macro will automatically determine this from the input file and parse the events appropriately. For example, to process the first 100,000 events in the file "myPythiaEvents.txt":

root [1] CreateROOTTreeFromGenerators( "myPythiaEvents.txt", ".", 100000 );

This will generate a ROOT file named "myPythiaEvents.root" in the current directory containing a TTree named "EICTree". Each entry in the TTree contains one event, with particle-wise quantities stored in arrays. The total number of events and particles processed and the running time are also printed to the screen when the function completes.