ROOT2IDL
Introduction

Installation
CMT/CVS
tar.gz file

Usage
digi2struct
getNumDigiEvents
ntuple2struct
getNumEvents

Introduction

So...all of our data is available within ROOT files...but you really really like using IDL - what to do?  Have no fear, Root2IDL is here... 

Currently Root2IDL has been updated for ROOT 3.04.02.  Any simple ROOT ntuple can be read into IDL.  Work is underway, to first handle the standard GLAST Digi and Recon ROOT TTrees files and then to generically read in any ROOT file.  But for now... Root2IDL handles just ROOT ntuple files .

This version has been compiled and run using IDL 5.2 and IDL 5.4 (on both Windows and Linux) and IDL 5.1, 5.3 (on Windows only).

What Does it Do?

Root2IDL takes any Root ntuple file and reads the data into an IDL structure.  This IDL structure is then available for you to use within IDL.

Installation

Using CMT/CVS

root2idl is a checkout package - so follow the standard instructions for obtaining a checkout package.

Before compiling...you will need to update the root2idl requirements file so that it can find IDL on your particular system.  Update the IDL_DIR and IDL_LIB_DIR macros:

macro IDL_DIR "/afs/slac/g/ek/rsi/idl_5.4" \
VisualC "D:/rsi/IDL52"

macro IDL_LIB_DIR "${IDL_DIR}/bin/bin.linux.x86" \
VisualC "${IDL_DIR}/bin/bin.x86" \
VisualStatic "${IDL_DIR}/bin/bin.x86"

Next compile using CMT and your C++ compiler. 

For UNIX users only:
Copy the resulting *.so, *.a, and *.def files to your root2idl/idl directory.  This is necessary since the DLM file located in the idl directory must be in the same location as the root2idl libraries.

To use root2idl, you must do one of the following to properly setup your system's environment:

Use CMT to setup your enviroment.  This will setup your environment for a specific terminal/command prompt window.
Windows
Open a Command prompt
enter the root2idl/cmt directory
run "setup.bat" on Windows 
now start up IDL from the command prompt
UNIX
enter the root2idl/cmt directory
"source setup.csh"
startup IDL

Or...to permanently setup your environment to for root2idl, you can add the following environment variables to your system:
IDL_DLM_PATH - points to root2idl/v1/idl directory
IDL_PATH
(UNIX ONLY)
- points to root2idl/v1/idl directory
ROOT2IDL - points to the root2idl/v1/idl directory
Update PATH on Windows or LD_LIBRARY_PATH on UNIX to include: ROOT2IDL

Once you have updated your environment, you can then startup IDL.

Installation from TAR.GZ file

For convenience, pre-compiled versions of Root2IDL are available for download.  Please note, that not all possible combinations of operating system and IDL version are available pre-compiled.  Currently, there are versions for:
Linux:  IDL 5.2 or IDL 5.4
Windows:  IDL 5.1.1, IDL 5.2, IDL 5.3, IDL 5.4 
If your particular combination of operating system and IDL version is not represented - you will have to use the CMT/CVS instructions above.  If you run into difficulties, please contact Heather Kelly.

Root2IDL is available for download from either SLAC FTP:
ftp-glast.slac.stanford.edu/glast.u05/root2idl
OR SLAC NFS:
/nfs/farm/g/glast/u05/root2idl

Once you have obtained the file:

  1. Use gzip and tar -xvf to expand the archive or use WinZip
  2. Set up a ROOT2IDL environment variable as follows:
    setenv ROOT2IDL /myDir/root2idl/v2
  3. Either copy the contents of the setup.csh, setup.bat, or setup.sh file into your own cshrc or execute the file to setup your environment.
  4. That's it...start up IDL and try it.

Usage

A set of IDL routines are provided in the idl directory of the root2idl package. 

ntuple2struct.pro
Reads in a ROOT ntuple file and produces an IDL structure containing a list of the names of the elements in the ntuple, and a 2-D array containing the data values of the ntuple for each requested event.
The routine accepts 5 possible IDL keywords:
rootfile - the path and name of the ROOT file to process
if the ROOT file name is not provided, a dialog box will be spawned to allow you to choose the file
treePath - the name of the TTREE and the path if necessary
nevents - number of events to process
startEvent - offset into the ROOT file
ntuple - name of the new structure to contain the output
From the IDL command line:
ntuple2struct, rootfile="I:\rootfiles\myROOTNtuple.root", treePath="PDR/t1", nevents=100, startEvent = 10, ntuple = tup

The ntuple keyword denotes the name of new variable, that contains an IDL structure.  This structure contains 2 fields:  tags and arr. 
tags is an array of strings, the identifiers for each of the columns in the ntuple
arr is a 2-D array containing the data from the ntuple.  
tup.arr(0,*) returns the data from the 1st event in the ntuple.

If you are looking to retrieve data pertaining to a particular ntuple element, you can do the following - suppose you wish to find the data for TKR_Gamma_x0.  First you need to locate the position of TKR_Gamma_x0 in the data arr:
index = where(tup.tags eq "TKR_Gamma_x0", n)
index will contain the index for the TKR_Gamma_x0 element in the data array:
tup.arr(0,index) will retrieve the value of TKR_Gamma_x0 for the first event.

getNumEvents.pro
An IDL function that returns the number of events contained in a TTree in a ROOT file.
The routine accepts 2 possible IDL keywords
rootfile - the path and name of the ROOT file to process
if the ROOT file name is not provided, a dialog box will be spawned to allow you to choose the file
treePath
- the name of the TTREE and the path if necessary
From the IDL command line:
print, getNumEvents(rootfile="I:\rootfiles\myROOTNtuple.root", treePath="PDR/t1")