Quick PyROOT tests

The ROOT web site has a page How to use Use the Python PyROOT Interpreter, a good start for users of PyROOT.

Steps however are not as described in setting up your environment. The only thing you need to do in STAR is:

setenv PYTHONPATH $ROOTSYS/lib

then do two quick tests to very if the Py/ROOT binding works:

Test 1: Python from ROOT

% root
root.exe [0] p = new TPython();
root.exe [1] p->Exec("print 1+1");
2
root.exe [2] .q

Test 2 (equivalent)

% root
root.exe [0] gSystem->Load("libPyROOT");
root.exe [1] TPython::Exec("print 1+1");
2
root.exe [2] .q

Test 3: ROOT from Python

Simple test

Create a script test.py containing somehting like

#!/usr/bin/env python
import sys
from ROOT import *

def main():
        print "hello world \n"
        return

if __name__ == '__main__':
        main()

This doesn't do much but will test if the import ROOT works. If so, go to a more exciting test such as

% python
Python 2.4.6 (#1, Dec  2 2009, 14:44:07)
[GCC 4.3.2 20081007 (Red Hat 4.3.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ROOT import gROOT, TCanvas, TF1
>>> gROOT.Reset()
>>> c1 = TCanvas( 'c1', 'Example with Formula', 200, 10, 700, 500 )
>>> fun1 = TF1( 'fun1', 'abs(sin(x)/x)', 0, 10 )
>>> c1.SetGridx()
>>> c1.SetGridy()
>>> fun1.Draw()
>>> c1.Update()
>>> 

The result should be a canvas with the function drawn.

If all works, you are set.