You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This section will guide you trough the steps necessary to perform simple analysis in a Python analysis framework (pyana). For more detailed description of pyana consult Pyana User Manual.

Pyana is based on Python with many internal parts such as access to XTC data written in C++. There is very little overhead for accessing data from Python and pyana may be adequate for many analysis tasks. User module in pyana is an instance of Python class which defines few specific methods:

  • beginjob(self, evt, env) – called once at the beginning of the job
  • beginrun(self, evt, env) – called at the beginning of every run
  • begincalibcycle(self, evt, env) – called at the beginning of every scan
  • event(self, evt, env) – called on every event
  • endcalibcycle(self, env) – called after every scan
  • endrun(self, env) – called after every run
  • endjob(self, env) – called at the end of job

To start with the doing analysis one should have user release setup first as explained in Packages and Releases. If you have not done it yet create a package for your analysis with some unique name:

newrel ana-current my_ana_rel   # to make user release
cd my_ana_rel
sit_setup                       # never forget this!
newpkg my_ana_pkg               # to make package for analysis code

Good place to start writing analysis module is to create skeleton module from existing template:

mkdir my_ana_pkg/src
codegen -l pyana-module my_ana_pkg my_ana_mod

This will create file my_ana_pkg/src/my_ana_mod.py which you need to edit and fill with some useful code. Start your favorite editor:

vi my_ana_pkg/src/my_ana_mod.py

For example purposes we are going to use beam line data and print few interesting values on every event. For that the code will be quite simple (excluding comments):

class my_ana_mod (object) :

    def __init__ ( self ) :
        pass

    def beginjob( self, evt, env ) :
        pass

    def event( self, evt, env ) :

        time = evt.getTime()   # get event time object
        ebeam = evt.getEBeam() # get EBeam object

        # dump objects        
        print "time: %s, charge: %g, energy=%g" % \
                (time, ebeam.fEbeamCharge, ebeam.fEbeamL3Energy)

    def endjob( self, evt) :
        pass

To run this analysis start pyana giving it module name and input files:

pyana -m my_ana_pkg.my_ana_mod /reg/d/psdm/AMO/amo14110/xtc/e43-r0100-s0*

which should produce output similar to this:

time: <T:1280631930.026688363>, charge: 0.251309, energy=4386.32
time: <T:1280631930.043360843>, charge: 0.233403, energy=4393.24
time: <T:1280631930.060033392>, charge: 0.246535, energy=4400.88
time: <T:1280631930.076703847>, charge: 0.247861, energy=4396.93
time: <T:1280631930.093381914>, charge: 0.248759, energy=4380.69
time: <T:1280631930.110053067>, charge: 0.240726, energy=4401.18
time: <T:1280631930.126720938>, charge: 0.239678, energy=4387.77
time: <T:1280631930.143398446>, charge: 0.243547, energy=4384.99
...
  • No labels