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.
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/ATestRun_jobOptions.py
. 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/ATestRun_jobOptions.py
, with the following:
#See: https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/SoftwareTutorialxAODAnalysisInCMake 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
include("AthAnalysisBaseComps/SuppressLogging.py")
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.
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/*_jobOptions.py )
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/
make
Don’t forget to run source x86_64-*/setup.sh
OK, now the big moment has come. Within your run
directory execute
your job options with athena:
cd ../run
athena MyAnalysis/ATestRun_jobOptions.py
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 usingpython ../build/x86_64-centos7-gcc8-opt/bin/ATestRun_jobOptions.py
You can specify the number of events your job processes with the
--evtMax
option (-1, the default, means process all events):athena MyAnalysis/ATestRun_jobOptions.py --evtMax=-1
You can override the input files used with –filesInput option:
athena MyAnalysis/ATestRun_jobOptions.py --filesInput=another.file.root