Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Examples

python.doc


`Python' Analysis Mode


Python is an interpreted, interactive, object-oriented programming language. It is often compared to Tcl, Perl, Scheme or Java.

The file example.py shows an example of a Python program which can be processed interactively as: "python -i example.py". If you only need to execute the script and exit (⇒ no graphics, no extra Python commands), you may just type: "example.py".

You can find simple introductions to Python in: http://www.python.org/doc/Intros.html . Python is naturally available in ROOT via PyROOT .


The Python mode has been tested to work only with ROOT versions ≥ 4.01


Interpreted analyses are well suited for small or medium size data samples, for which computer time is not the critical issue, while you want to code just few instructions, maybe interactively.

Some AMS/PyROOT specific issues follow:

#!/usr/bin/env python
### If the default python version is too old, try for instance:
###    /usr/bin/env /afs/cern.ch/asis/i386_redhat72/usr.local/bin/python2.2
import ams_utils
from ROOT import AMSChain, AMSEventList, TFile, TH1F

ams = AMSChain()
ams.Add("../files/test.root")
#ams.Add("http://pcamsf0.cern.ch/f2dah1/MC/AMS02/2004A/protons/el.pl1.10200/738197524.0000001.root")
#ams.Add("rfio:/castor/cern.ch/ams/MC/AMS02/2004A/protons/el.pl1.10200/738197524.0000001.root")

hfile = TFile("amstest.root", "RECREATE")

list = AMSEventList()

hrig = TH1F("hrig", "Momentum (GeV)", 50, -10.0, 10.0)

for ev in ams:
      for part in ev.ParticleList():
            hrig.Fill(part.Momentum)
            if ev.nVertex()>0:
                  list.Add(ev)  ## Add to list of selected events
                  ev.Fill()     ## write it into output ROOT file

hrig.Draw()
hfile.Write()
list.Write("select.list")

print "We have processed %d events" % len(ams)
print "Histograms saved in '%s'" % hfile.GetName()


Generated on Fri Oct 10 10:39:23 2008 for AMSRoot by  doxygen 1.3.9.1