Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

XAOD Tutorial

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

xAOD Tutorial

Aims:
Browse an xAOD with ROOT
Interactive Root & PyRoot with xAOD
Analysis using ROOT
Analysis in athena & TrigDecisionTool

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

Disclaimer
I am NOT an expert. Just trying to give a flavour of what is possible.
Usual ATLAS software tutorial is a week and xAOD mini-tutorial is 2 days.
Most recent ones:
https://indico.cern.ch/event/329880/other-view?view=standard
https://indico.cern.ch/event/330324/other-view?view=standard
Useful Links:
https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/SoftwareTutorialxAODEDM

https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/SoftwareTutorialxAODAnalysisInROOT
https://twiki.cern.ch/twiki/bin/view/AtlasComputing/SoftwareTutorialxAODAnalysisInAthena

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

Setup

Standard atlas setup gives access to softwa


setupATLAS
mkdir xAODTutorial
cd xAODTutorial
rcSetup Base,2.0.10

Setup the release we want to use

export ALRB_TutorialData=/afs/cern.ch/atlas/project/PAT/tutorial/cern-oct2014/

Pointer to some data

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

Browse an xAOD with ROOT


root
$ALRB_TutorialData/r5591/mc14_8TeV.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e1727_s1933_s1911_r5
591_tid01494882_00/AOD.01494882._113691.pool.root.1
root[0] TBrowser b;
The TTree containing the variables is called CollectionTree.
You can look through and double-click to see some of the variables.
Have split the interface to objects and how the payload is stored (aux containers). In code user interacts with
the interface NOT with the auxilliary storage.

For fun we can look at a run1 AOD:


root root[0] TFile *f =
TFile::Open("$ALRB_TutorialData/mc12_14TeV.105200.McAtNloJimmy_CT10_ttbar_LeptonFilter.recon.AOD.e15
65_s1499_s1504_r4033_tid01014997_00/AOD.01014997._000081.pool.root.2");

This is already a very good thing about xAOD.


12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

Interactive ROOT with the xAOD


root [0] gROOT->Macro( "$ROOTCOREDIR/scripts/load_packages.C" );
root [1] xAOD::Init();
root [2] f = TFile::Open(
"$ALRB_TutorialData/r5591/mc14_8TeV.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e1727_s1933_s191
1_r5591_tid01494882_00/AOD.01494882._113691.pool.root.1", "READ" );
root [3] t = xAOD::MakeTransientTree( f )
root [4] t->Draw( "ElectronCollection.pt() - ElectronCollection.trackParticle().pt()" );
root [5] t->Draw( "Muons.pt()");

Once you have done MakeTransientTree can now click things in TBrowser by using root/Root
Memory/CollectionTree

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

PyROOT with the xAOD


PyROOT is very handy when you want to run a quick macro
cp /afs/cern.ch/work/h/hartj/public/xAODTutorial/xAODPythonMacro.py .

(chmod +x xAODPythonMacro.py)
./xAODPythonMacro.py

Should print some output about electrons and muons to the screen

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

Analysis using ROOT


Create a new Analysis package:
rc make_skeleton MyAnalysis
rc find_packages
rc compile

These 3 lines create a new package


and then asks RootCore to pick it up.

We will use the standard EventLoop package for looping over events.
The EventLoop package provides a script to create the skeleton of the class for you inside the
package you specify
$ROOTCOREBIN/user_scripts/EventLoop/make_skeleton MyAnalysis MyxAODAnalysis
rc find_packages
rc compile

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

Accessing the xAOD quantities from our analysis code


To do any sort of real analysis you will access the xAOD objects using a package called xAODRootAccess.
The most important class is the xAOD::TEvent class, which acts similar to the D3PDReader.
We will also use the xAOD::Init class to handle any xAOD access magic that will happen behind the scenes to the
user.
In MyAnalysis/cmt/Makefile.RootCore add

Update the package dependencies,


EventLoop should already be there

PACKAGE_DEP = EventLoop xAODRootAccess


at top of MyAnalysis/MyAnalysis/MyxAODAnalysis.h add:
// Infrastructure include(s):
#include "xAODRootAccess/Init.h"
#include "xAODRootAccess/TEvent.h"

Add header files and a new data member


Add as public:

xAOD::TEvent *m_event; //!


//! is important!!!!!

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

Accessing the xAOD quantities from our analysis code (2)

In MyAnalysis/Root/MyxAODAnalysis.ccx
In setupJob() add:

Tell EventLoop that we actually want to use the


xAODRootAccess in our job.

job.useXAOD ();
// let's initialize the algorithm to use the xAODRootAccess package
xAOD::Init( "MyxAODAnalysis" ).ignore(); // call before opening first file
In initialize() add:

Ignore return code (failure, success, and


recoverable)

m_event = wk()->xaodEvent();
Connect this member to out xAODRootAccess.
// as a check, let's see the number of events in our xAOD
Info("initialize()", "Number of events = %lli", m_event->getEntries() ); // print long long int
Now remake the package:
rc find_packages
rc compile

12/11/2014

updated our package dependencies, so from our


working directory we have to rerun rc find_packages
before compiling:

J.Kirk, UK-HLT Mini workshop, Sussex

Running our algorithm


mkdir run
cd run
cp /afs/cern.ch/work/h/hartj/public/xAODTutorial/ATestRun.cxx .
This uses a standard tool SampleHandler to manage sample management.
To execute it:
submitDir is the directory where the output of
your job is stored. If you want to run again, you
root -l 'ATestRun.cxx ("submitDir")'
either have to remove that directory or pass a
different name into ATestRun.cxx.

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

10

Running our algorithm - alternative


In order to debug problems with the code, it is often not practical to run the job from ROOT's interpreter. So,
if you encounter any problems, you should create a directory like MyAnalysis/util/, and in there put an
executable source file like MyAnalysis/util/testRun.cxx
cp /afs/cern.ch/work/h/hartj/public/xAODTutorial/testRun.cxx .
In working directory
rc compile

Then from run:


testRun submitDir

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

11

Finding out what is on the xAOD


One question everyone will have is: how do I know what information/variables are actually stored
in my xAOD for each container type?
Need to know the container type and the container key name.
We can use checkSG.py in Athena.
Setup a new lxplus session:
% setupATLAS
% asetup 19.0.3.1,slc6,gcc47,64,here
% export ALRB_TutorialData=/afs/cern.ch/atlas/project/PAT/tutorial/cern-oct2014/
% checkSG.py
$ALRB_TutorialData/r5591/mc14_8TeV.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e1727_s1933_s1911_r5
591_tid01494882_00/AOD.01494882._113691.pool.root.1
You usually need to know the container type on left (for example xAOD::CaloClusterContainer) and the key
name for the particular instance of that container you are interested in which is on the right (for example
"egClusterCollection").
% checkSG.py
/afs/cern.ch/work/h/hartj/public/valid1.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e2658_s1967_s1964_r
5856_tid01600225_00/AOD.01600225._000084.pool.root.1
12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

12

Finding out what is on the xAOD (2)


To know what variables are associated to this container, the trick I use at the moment (again maybe something
official will come along...) is to use interactive ROOT.
root -l
$ALRB_TutorialData/r5591/mc14_8TeV.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e1727_s1933_s1911_r5
591_tid01494882_00/AOD.01494882._113691.pool.root.1
root [1] CollectionTree->Print("egClusterCollection*")
You will get a printout of all variables you can access from that container
egClusterCollectionAux.rawEta : vector<float>
So in your analysis code (after setting up the TEvent and interface magic), you can access this variable from the
xAOD::CaloCluster object by calling rawEta.

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

13

Now lets look at some objects.


First some event information
In MyAnalysis/cmt/Makefile.RootCore add
PACKAGE_DEP = EventLoop xAODRootAccess xAODEventInfo
In MyAnalysis/MyAnalysis/MyxAODAnalysis.h add as public:
int m_eventCounter; //!
remember the //! is important!!!!!

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

14

Now lets look at some objects.


In MyAnalysis/Root/MyxAODAnalysis.ccx
Near the top:
// EDM includes:
#include "xAODEventInfo/EventInfo.h"
In initialize() add:
// count number of events
m_eventCounter = 0;

Add includes
zero event counter

In execute() :
// print every 100 events, so we know where we are:
if( (m_eventCounter % 100) ==0 ) Info("execute()", "Event number = %i", m_eventCounter );
m_eventCounter++;
//---------------------------- // Event information //--------------------------Increment event counter and print every 100
const xAOD::EventInfo* eventInfo = 0;
events
if( ! m_event->retrieve( eventInfo, "EventInfo").isSuccess() ){
Error("execute()", "Failed to retrieve event info collection. Exiting." );
Access eventInfo and check if data or MC
return EL::StatusCode::FAILURE;
}
// check if the event is data or MC
// (many tools are applied either to data or MC)
bool isMC = false;
// check if the event is MC
if(eventInfo->eventType( xAOD::EventInfo::IS_SIMULATION ) ){
you can copy
isMC = true; // can do something with this later
}
cp

rc find_packages
rc compile
12/11/2014

/afs/cern.ch/work/h/hartj/public/xAODTutorial/MyxAOD
Analysis_1.cxx MyxAODAnalysis.cxx
J.Kirk, UK-HLT Mini workshop, Sussex

15

Now lets look at some objects.


Offline muons:
In MyAnalysis/cmt/Makefile.RootCore add
PACKAGE_DEP = EventLoop xAODRootAccess xAODEventInfo xAODMuon
in MyAnalysis/Root/MyxAODAnalysis.ccx
#include "xAODMuon/MuonContainer.h"

In execute():
//-----------// MUONS
//-----------// get muon container of interest
const xAOD::MuonContainer* muons = 0;
if ( !m_event->retrieve( muons, "Muons" ).isSuccess() ){ // retrieve arguments: container type, container key
Error("execute()", "Failed to retrieve Muons container. Exiting." );
return EL::StatusCode::FAILURE;
}
// loop over the muons in the container
xAOD::MuonContainer::const_iterator muon_itr = muons->begin();
xAOD::MuonContainer::const_iterator muon_end = muons->end();
for( ; muon_itr != muon_end; ++muon_itr ) {
Info("execute()", " original muon pt = %.2f GeV", ((*muon_itr)->pt() * 0.001)); // just to print out something
} // end for loop over muons
12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

16

Now lets look at some objects.


Trigger muons:
Remember when we looked at the xAOD objects trigger muons were stored a xAODMuon with a different
key:
HLT_xAOD__MuonContainer_MuonEFInfo
in MyAnalysis/Root/MyxAODAnalysis.ccx in execute():
//-----------// TRIGGER MUONS
//-----------// get muon container of interest
const xAOD::MuonContainer* trmuons = 0;
if ( !m_event->retrieve( trmuons, "HLT_xAOD__MuonContainer_MuonEFInfo" ).isSuccess() ){ // retrieve arguments:
container type, container key
Error("execute()", "Failed to retrieve Muons container. Exiting." );
return EL::StatusCode::FAILURE;
}
// loop over the muons in the container
xAOD::MuonContainer::const_iterator trmuon_itr = trmuons->begin();
xAOD::MuonContainer::const_iterator trmuon_end = trmuons->end();
for( ; trmuon_itr != trmuon_end; ++trmuon_itr ) {
Info("execute()", " trigger muon pt = %.2f GeV", ((*trmuon_itr)->pt() * 0.001)); // just to print out something
} // end for loop over trigger muons

12/11/2014

you can copy


/afs/cern.ch/work/h/hartj/public/xAODTutorial/MyxAOD
and .cxx
J.Kirk, UK-HLT MiniAnalysis_2.h
workshop, Sussex
17

Check twiki page for other objects and tools, e.g. jets, GRLTool:
https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/SoftwareTutorialx
AODAnalysisInROOT

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

18

Histograms
MyAnalysis/MyAnalysis/MyxAODAnalysis.h
at top:
#include <TH1.h>
Add a hist:
TH1 *h_muonPt; //!

In MyAnalysis/Root/MyxAODAnalysis.ccx, in histInitialize :
h_muonPt = new TH1F("h_muonPt", "h_muonPt", 100, 0, 100); // muon pt [GeV]
wk()->addOutput (h_muonPt);
In execute() :
h_muonPt->Fill( ( (*muon_itr)->pt()) * 0.001); // GeV

you can copy


/afs/cern.ch/work/h/hartj/public/xAODTutorial/MyxAOD
Analysis_3.h and .cxx

rc compile
testRun submitDir

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

19

Histograms
histograms are in root file:
submitDir/hist-valid1.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e2658_s1967_s1964_r5856_tid01600225_00.root
also in hist/valid1.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e2658_s1967_s1964_r5856_tid01600225_00.root so you can
access them with SampleHandler:
Add to ATestRun.cxx
// Fetch and plot our histogram - will pop up window for interactive running
SH::SampleHandler sh_hist;
sh_hist.load (submitDir + "/hist");
TH1 *hist = sh_hist.get (valid1.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e2658_s1967_s1964_r5856_tid01600225_00")>readHist ("h_muonPt");
hist->Draw ();

Then:
root -l 'ATestRun.cxx ("submitDir")'
and you should get a up a canvas popped up with your plot.

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

20

TrigDecisionTool
Link to trigger talk in ATLAS software tutorial:
https://indico.cern.ch/event/329880/session/6/contribution/21/material/slides/0.pdf

Will look at accessing muon chains. Good place to check other signatures here:
https://svnweb.cern.ch/trac/atlasoff/browser/Trigger/TrigValidation/TrigValAlgs/tru
nk/src/TrigDecisionChecker.cxx

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

21

Will use TDTExample as an example.


In a new lxplus session:
setupATLAS
mkdir TrigAnalysisTest
cd TrigAnalysisTest
asetup 19.3.0,here
cmt co Trigger/TrigAnalysis/TrigAnalysisExamples
cd Trigger/TrigAnalysis/TrigAnalysisExamples/src
cp /afs/cern.ch/work/h/hartj/public/xAODTutorial/TDTExample.h .
cp /afs/cern.ch/work/h/hartj/public/xAODTutorial/TDTExample.cxx .

cd ../cmt
cp /afs/cern.ch/work/h/hartj/public/xAODTutorial/requirements .
gmake
cd ../../../..
mkdir run
cd run
cp /afs/cern.ch/work/h/hartj/public/xAODTutorial/TDTExampleJO.py .
athena.py TDTExampleJO.py > output.txt

12/11/2014

J.Kirk, UK-HLT Mini workshop, Sussex

22

You might also like