Introduction

AthenaROOTAccess (ARA) allows to access files in Athena POOL format (such as AODs) directly from ROOT, without the using the Athena executable. It converts the persistant tree included in AOD files into a transient tree that is readable by ROOT.

More information on AthenaROOTAccess can be found at this URL: https://twiki.cern.ch/twiki/bin/view/AtlasProtected/AthenaROOTAccess

Setup with Athena v15.5.0

For this tutorial, we use Athena v15.5.0.

Create an ATLAS environment, using a local Athena release:

source ~/cmthome/setup.sh -tag=15.5.0
mkdir -p $TestArea
cd $TestArea

To test Athena, please try the following:

athena AthExHelloWorld/HelloWorldOptions.py

You do not need to check out other packages to use AthenaROOTAccess, as it is included in the Athena release.

Opening AOD files with ARA

One single file

An example is included in the AthenaROOTAccess package, in the Python script "test.py". To get it, please execute the following:

cd $TestArea
mkdir run
cd run
get_files test.py

The main lines of this script are:

import user  # look for .pythonrc.py for user init
import ROOT
import PyCintex
import AthenaROOTAccess.transientTree

# Put your AOD file here.
aodFile = 'AOD.pool.root'
f = ROOT.TFile.Open (aodFile)
assert f.IsOpen()

# Fill this in if you want to change the names of the transient branches.
branchNames = {}
#branchNames['ElectronCollection'] = 'ele'
#branchNames['PhotonCollection'] = 'gam'

tt = AthenaROOTAccess.transientTree.makeTree(f, branchNames = branchNames)

The script "test.py" opens by default the AOD file "AOD.pool.root", as pointed by the variable "aodFile". It is possible to fill this variable with the path of a local or a remote file, the same way as TFile::Open() operates in ROOT.

You can try with open of the AOD files that have been copied for the purpose of the tutorial in:

/scratch/current/atlas/calfayan/ADT09/AOD

e.g.:

ln -s /scratch/current/atlas/calfayan/ADT09/AOD/AOD.064382._00210.pool.root.1 AOD.pool.root

To open an AOD file, please execute one of the following commands:

python -i test.py

or with the Athena interpreter,

athena -i test.py

or with the ROOT CINT interpreter,

root -l
TPython::Exec("execfile('test.py')")

The "-i" option provides you with an interactive Python prompt. Once the AOD file opened, the converted tree is accessible via the Python "tt" instance.

The header "import ROOT" activates PyROOT. It makes it possible to access ROOT objects within Python. The header "import PyCintex" enables the use of REFLEX dictionaries, which are required to read AOD files within ROOT.

A set of files

It is possible to open a set of AOD files with ARA by using a

Please create a new file (e.g. tchain_test.py) including the following lines:

import ROOT, PyCintex, AthenaROOTAccess.transientTree

aodfiles = ROOT.AthenaROOTAccess.TChainROOTAccess('CollectionTree')
files = open('/scratch/current/atlas/calfayan/ADT09/AOD/aod-filelist.txt')
files_a = files.readlines()
for file in files_a:
    aodfiles.Add(file.rstrip('\n'))

tt = AthenaROOTAccess.transientTree.makeTree(aodfiles)
print "Transient tree:\n", tt
print tt.GetEntries()

The text file "aod-filelist.txt" contains a list of files with their full absolute paths.

To open the TChain, please execute:

python -i tchain_test.py

Accessing AOD files from dCache

It is possible to process an analysis with ARA using remote input files stored on dCache within datasets.

To get the list of the datasets available at the NAF, you can use the dq2 scripts:

ini dq2
dq2-list-dataset-site <site_name>

(e.g. <site_name> = DESY-HH_MCDISK)

To get the complete list of files included in a dataset, please use the following command:

ini atlas
dq2-poolFCjobO.py -v -t <dataset_name>

(e.g. <dataset_name> = mc08.106050.PythiaZee_1Lepton.merge.AOD.e347_s462_r635_t53_tid064382)

The script "dq2-poolFCjobO.py" will create a text file "files.txt" which contains the full paths of the files contained in the given dataset. A copy is available at:

/scratch/current/atlas/calfayan/ADT09/AOD/files_PythiaZee.txt

Reading an AOD file with ARA

There are three ways to read an AOD file with ARA. The most convenient one is via Python, since no comppilation is required, but the best performance is obtained when adopting a compiled C++ code.

Examples can be found in the package "AthenaROOTAccessExamples". At the NAF, for Athena v15.5.0, you can have a look at: /afs/naf.desy.de/group/atlas/software/kits/15.5.0/AtlasAnalysis/15.5.0/PhysicsAnalysis/AthenaROOTAccessExamples/

using Python (PyROOT)

Open an AOD file or a set of files as described previously. The converted tree "tt" can be handled like classic ROOT TTree. To play around, you can try the following:

More generally, with PyROOT, you can use "ROOT.<method>" to access translated ROOT methods:

ROOT.TBrowser()
htest = ROOT.TH1F("htest", "htest", 100, 0., 100.)

using CINT

The package AthenaROOTAccessExample provides an analysis he example in its "macros" directory, namely "cluster_example.C":

/afs/naf.desy.de/group/atlas/software/kits/15.5.0/AtlasAnalysis/15.5.0/PhysicsAnalysis/AthenaROOTAccessExamples/macros/cluster_example.C

For more convenience, you can get the following copy in your "run" directory (this version only processes 500 events):

cp /scratch/current/atlas/calfayan/ADT09/ara/cluster_example.C .

To open an AOD file with CINT, the python script "test.py" is still required. You can then access the TTree from the ROOT CINT interpreter (interactively). Please try out the following:

root -l
TPython::Exec("execfile('test.py')");
CollectionTree_trans = (TTree *)gROOT->Get("CollectionTree_trans");

To try the example "cluster_example.C", complete the previous lines with:

gROOT->LoadMacro("cluster_example.C");
plot(CollectionTree_trans);

From that script you should get two plots: log10(E) (-log10(-E) for negative E) and the eta distribution for the CaloCalTopoCluster collection.

using compiled C++

The example in "cluster_example.C" can also be compiled, as done when compiling the package AthenaROOTAccessExamples from which it is taken. AthenaROOTAccessExamples has already been compiled on your local node and is available.

To process the compiled code, you can simply do:

root -l
TPython::Exec("execfile('test.py')");
CollectionTree_trans = (TTree *)gROOT->Get("CollectionTree_trans");
ClusterExample ce;
ce.plot(CollectionTree_trans); 

This might take a long time as all the events are processed, but for an equal number of events, the compiled C++ method is faster.

Pseudo event display

The PseudoEventDisplay class is an alternative event display that works directly with ARA.

An r-z and r-phi view corresponding roughly to the ATLAS layout are created and the MC truth particles, clusters, jets, electrons and muons are drawn. MC particles (GEN_AOD) will get a radius proportional to the generation in the MC tree and get colored according to PDG Id. The thickness of lines is proportional to transverse energy, the thickness of vertices proportional to mass. The phi position of the ending vertex of a particle corresponds to the phi of its momentum. Clusters (CaloCalTopoCluster) are drawn in the calorimeter layer as ellipses colored proportional to their transverse energy, with the center corresponding to the actual depth of the cluster and the width and length derived from the cluster moments. Jets (Kt4H1TowerJets) are drawn as cones beyond the calorimeter layer with a fixed radius (0.4 in this example) and assigned a number corresponding to the order in Et. Jets matched to electrons and at least half their energy corresponding to the matched electron are colored black and with red stripes in the ending ellipse. Other jets are colored proportional to their transverse energy. Electrons (ElectronAODCollection) and muons (StacoMuonCollection) are drawn as red and black lines, respectively with the line length proportional to transverse momentum. Missing transverse energy (MET_RefFinal) is drawn as dashed line in the r-phi view.

Example code:

root -l
TPython::Exec("execfile('test.py')");
CollectionTree_trans = (TTree *)gROOT->Get("CollectionTree_trans");
PseudoEventDisplay ped;
ped.setJetKey("Cone4H1TopoJets",0.4,20000)
ped.plot(CollectionTree_trans,0) //draws the first event

Links

ATLAS: WorkBook/NAF/ADT09AthenaROOTAccess (last edited 2009-09-24 08:20:24 by WolfgangEhrenfeld)