Creating and running our steering macro

Last update: 19 Jun 2022 [History] [Edit]

To actually run this Athena algorithm we need a configuration file describing how to use it, a so called job options file. While this isn’t exactly what happens (see main Athena tutorial), it is often quite helpful to think of this as a simple python file in which you create and configure all the C++ algorithms and tools that you will be using.

tip This is only needed when working in Athena, inside EventLoop this will not be used. As such if you know that you will never work in Athena you can leave this out (or add it later).

Create a new file called MyAnalysis/share/ You can really put this anywhere, but it is probably a good idea to keep it in your source area (which is in version control), probably even in your package. Fill this new file, MyAnalysis/share/, with the following:

#See: for more details about anything here

testFile = os.getenv("ALRB_TutorialData") + '/mc21_13p6TeV.601229.PhPy8EG_A14_ttbar_hdamp258p75_SingleLep.deriv.DAOD_PHYS.e8357_s3802_r13508_p5057/DAOD_PHYS.28625583._000007.pool.root.1'

#override next line on command line with: --filesInput=XXX
jps.AthenaCommonFlags.FilesInput = [testFile] 

#Specify AccessMode (read mode) ... ClassAccess is good default for xAOD
jps.AthenaCommonFlags.AccessMode = "ClassAccess" 

# Create the algorithm's configuration.
from AnaAlgorithm.DualUseConfig import createAlgorithm
alg = createAlgorithm ( 'MyxAODAnalysis', 'AnalysisAlg' )

# later on we'll add some configuration options for our algorithm that go here

# Add our algorithm to the main alg sequence
athAlgSeq += alg

# limit the number of events (for testing purposes)
theApp.EvtMax = 500

# optional include for reducing printout from athena

Read over the comments carefully to understand what is happening. Notice that we will only run over the first 500 events (for testing purposes). Obviously if you were doing a real analysis you would want to remove that statement to run over all events in a sample.

tip The way of creating an algorithm we are showing you above is the dual-use way, i.e. it is the same in EventLoop and Athena. The traditional Athens-only way of creating the algorithm is to use:

alg = CfgMgr.MyxAODAnalysis('AnalysisAlg')

Add the following lines to MyAnalysis/CMakeLists.txt to enable the use of your jobOptions file:

# Install files from the package:
atlas_install_joboptions( share/* )

To make sure that the newly used file gets installed and can be found we need to recompile (we need to call cmake explicitly as we did create a new file):

cd ../build/
cmake ../source/

tip Don’t forget to run source x86_64-*/

OK, now the big moment has come. Within your run directory execute your job options with athena:

cd ../run
athena MyAnalysis/


If your algorithm does not run, make sure that you have defined the environment variable ALRB_TutorialData, as explained here.

If it still doesn’t run, there is sometimes an issue with the “Shebang” line. You can just override this and directly run with python using python ../build/x86_64-centos7-gcc8-opt/bin/

tip You can specify the number of events your job processes with the --evtMax option (-1, the default, means process all events):

athena MyAnalysis/ --evtMax=-1 

tip You can override the input files used with –filesInput option:

athena MyAnalysis/ --filesInput=another.file.root 

⭐️ Bonus Exercise

  • Create a second instance of your algorithm (with a different name) and add it to the job. Can you see if the two algorithms are running in series or in parallel?
  • Add a command line option that allows you to change your input filepath