Writing the Drivers in Jython

The case for Jython

Let's consider the following case: You are an experienced org.lcsim user and have a range of Drivers that perform various tasks for you. You would like a summer student to help you with some coding, but the student has no programming experience whatsoever.
Rather than having to waste two weeks teaching the details of the Java language, you could create an Example in Jython, an object-oriented scripting language that can be learned in a few days.

We are now going to load and execute a Java Driver and a Jython Driver simultaneously. The results of both Drivers will be displayed in the JAS3 sidebar, just like always.

The Jython wrapper

If you want to use Drivers written in Jython, you will have to use a little wrapper script. That should not be much of a hassle, since your program is likely split up into various Drivers already anyway. (If not, it probably should be). In this case, all you have to do is replace your current Java wrapper with the Jython version.

Preparation

Please save mainLoop.py, Analysis102.py and psiMuMu.slcio to your harddisk. psiMuMu.slcio is a small datasample, Analysis102.py is a slightly modified Jython version of the Java module and mainLoop.py is the wrapper that takes care of loading the analysis module correctly.

Step-by-Step analysis in JAS3

  1. Please open the Analysis101 example from the Help->Examples->org.lcsim menu.
  2. Compile it with <F9>
  3. Load the mainLoop.py script

    Just like you (may) have to add the location of your Java Modules to the JAS3 Classpath, you (may) have to add the location of your Jython modules to the
    PythonPath. This is done by uncommenting the two lines

     # import sys
    # sys.path.append('full path to Python module')

    and modifying the second one to show the location of Analysis102.py
    Unfortunately, with Jython you cannot take advantage of the 'TreePlayer' bar of JAS3, but have to load the SLCIO file explicitly. Please make also sure that the line

    input = File("psiMuMu.slcio")

    shows the correct location of the input file

  4. execute the script with <F2>
    • Please notice that Clouds created by the Analysis102 module show up in the sidebar in addition to the ones created by the Analysis101 example

You can add your own analysis modules by replacing

loop.add(Analysis101())
loop.add(Analysis102())

with your analysis modules

Don't forget to import your Java modules with

import MyJavaAanalysisModule

and your Jython modules with

from MyJythonModuleName import MyJythonClassName
  • No labels