2770 views
# xAOD EDM For the moment the best way to understand what variables you can access for each object, you should look at the code. The EDM code can be browsed online here: [athena/Event/xAOD (git)](https://gitlab.cern.ch/atlas/athena/tree/21.2/Event/xAOD). In most cases, it should be clear which package in the structure to look at. For example if you are interested in [taus](https://gitlab.cern.ch/atlas/athena/tree/master/Event/xAOD/xAODTau), you would look at the xAODTau package. For each xAOD EDM package you can either choose a particular tag of that package (corresponding to the version in your Athena or Analysis Release versions), or you can look in the master version to see the latest version. ## Browsing the xAOD with the TBrowser Now let's open the xAOD in ROOT, and open a TBrowser for browsing: ```bash root $ALRB_TutorialData/mc16_13TeV.410470.PhPy8EG_A14_ttbar_hdamp258p75_nonallhad.deriv.DAOD_PHYS.e6337_s3126_r10201_p4172/DAOD_PHYS.21569875._001323.pool.root.1 root[0] TBrowser b; ``` You will get lots and lots of warnings about dictionaries not available, don't worry about those for now. The TTree containing the variables is called `CollectionTree`. Feel free to open that TTree and play with the items inside. You can print this or open it in TBrowser. Can you find and understand the variables that were discussed in the lectures? Can you see how the variables are organized? Look and compare containers with and without `Aux`, representing the Auxillary store. When looking at the xAOD in the TBrowser we need to be aware of this, but when working interactively, or with a macro, or a full-blown compile analysis, we will interact with the xAOD objects through an interface and don't need to explicitly worry about this auxillary store business. ## Interactive ROOT Unfortunately using TBrowser through `ssh` and X11 forwarding can be slow and painful. If you want to see what is contained in the `CollectionTree` for this file you can open it interactively in ROOT Setup your ATLAS environment and release ``` setupATLAS asetup AnalysisBase,21.2.139 (or AthAnalysis) # and start root ``` ``` ## Then within root you can use the following root [0] #include <xAODRootAccess/Init.h> root [1] xAOD::Init() root [2] f = TFile::Open( "$ALRB_TutorialData/mc16_13TeV.410470.PhPy8EG_A14_ttbar_hdamp258p75_nonallhad.deriv.DAOD_PHYS.e6337_s3126_r10201_p4172/DAOD_PHYS.21569875._001323.pool.root.1", "READ" ); root [3] TTree* t = (TTree*)f->Get("CollectionTree") root [4] t->Print() ``` This will print all the variables available and stored in the TTree. You can select the variables you want using wildcards. For example to print variables relevant to tau objects, you could do `t->Print("TauJets*")`, you will see the variables ending with 'AuxDyn'. Remember from Attila's talk that all the physics objects inherit from `IParticle` so you should also have access to pt() and eta() etc. For example it is possible to draw the tau pT with `t->Draw("TauJetsAuxDyn.pt")`. Reading your xAOD file and reviewing the contents like this is sometimes useful in interactive ROOT but there are better ways. ## PyROOT with the xAOD PyROOT is very handy when you want to run a quick macro (it's also fun for bigger analyses too). Especially with the current updates to PyROOT with the latest ROOT version 6.22.00, it is a viable option for many studies and parts of the analysis. Here we will create a little PyROOT script to print to screen some xAOD quantities. With your favorite editor create and open the new python script, `xAODPythonMacro.py`, and fill it with this content: ```python #!/usr/bin/env python # Import ROOT: import ROOT # Initialize the xAOD infrastructure: if(not ROOT.xAOD.Init().isSuccess()): print("Failed xAOD.Init()") # Set up the input files: tutorialPath = "$ALRB_TutorialData" fullTutorialPath = ROOT.gSystem.ExpandPathName(tutorialPath) fileName = fullTutorialPath + "/mc16_13TeV.410470.PhPy8EG_A14_ttbar_hdamp258p75_nonallhad.deriv.DAOD_PHYS.e6337_s3126_r10201_p4172/DAOD_PHYS.21569875._001323.pool.root.1" treeName = "CollectionTree" # default when making transient tree anyway f = ROOT.TFile.Open(fileName) # Make the "transient tree": t = ROOT.xAOD.MakeTransientTree( f, treeName) # Print some information: print( "Number of input events: %s" % t.GetEntries() ) for entry in xrange( 0,100): # let's only run over the first 100 events for this example t.GetEntry( entry ) print( "Processing run #%i, event #%i" % ( t.EventInfo.runNumber(), t.EventInfo.eventNumber() ) ) print( "Number of electrons: %i" % len( t.Electrons ) ) # loop over electron collection for i in xrange( t.Electrons.size()): el = t.Electrons.at(i) print( " Electron trackParticle eta = %g, phi = %g" % ( el.trackParticle().eta(), el.trackParticle().phi() ) ) pass # end for loop over electron collection pass # end loop over entries # clear transient trees to avoid crash at end of job ROOT.xAOD.ClearTransientTrees() ``` Make sure to go through each line of this and make sure you understand what is going on. You can now run this with `python xAODPythonMacro.py` or use `chmod +x xAODPythonMacro.py` to make it executable and use the command `./xAODPythonMacro.py`. You should now see the printouts for each electron in each event from the 100 you ran over. ### Things to try Depending on your Python and ROOT knowledge you may be able to take this further. - Modify this python script to loop over the other objects in an event and find some of the variables who heard referenced in the recorded material. - Maybe draw and save some histograms of interesting variables to you. - Apply some cuts - Look into using RDataFrame (very useful) Some ROOT resources for you to look through [ROOT Tutorial](https://www.nevis.columbia.edu/~seligman/root-class/RootClass2019.pdf) and [new things in ROOT](https://indico.cern.ch/event/860971/contributions/3626494/attachments/1973542/3283729/The_Latest_from_ROOT_2020.01.22..pdf)