User Tools

Site Tools


asc:tutorials:2014october28

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
asc:tutorials:2014october28 [2014/10/28 20:17]
asc [Lesson 2: Using pyROOT to read xAOD]
asc:tutorials:2014october28 [2014/10/29 13:55] (current)
asc
Line 1: Line 1:
-====== xAOD tutorial at ANL. October 28, 2014 ====== 
-This tutorial is based on CERN 
-[[https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/SoftwareTutorialxAODAnalysisInROOT | SoftwareTutorialxAODAnalysisInROOT wiki]]. 
-However, the lessons given below are simplified for a faster start. Also, the last 2 lessons are designed for the ANL cluster that uses condor for job submissions. 
-In addition, we we will test US ATLAS connect as explained at the bottom of this page. 
  
- +The day 1 tutorial was merged with day 2. Please use  
-====== Getting started ====== +[[https://atlaswww.hep.anl.gov/asc/wikidoc/doku.php?id=asc:tutorials:2014october| this link]].
- +
-We would like to encourage you all to obtain a computer account already at your local Tier3. +
-That is the recommended way to do the tutorials since, eventually, you may want to run your +
-xAOD analysis at home institutes.  If needed, we can also provide you an account at Argonne Tier3. +
- +
-  * Please make sure that your local Tier3 has the usual ATLAS setup environment based on "cvmfs"+
-  * Several tutorial topics will require the grid access (use voms-proxy-init -voms atlas to check this). +
-     +
-ANL people can use "atlas1.hep.anl.gov" or atlas2.hep.anl.gov. +
-     +
-First, we will setup ATLAS release.  +
- +
-1) Setup kinit if needed:  **kinit [email protected]** where username is your user name on lxplus. This step is normally not needed. +
- +
-2) Create a bash script to setup ATLAS software. The method below works at ANL: +
- +
-<code bash setup.sh> +
-#!/bin/bash +
-export ALRB_localConfigDir="/share/sl6/cvmfs/localConfig" +
-export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase +
-source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh +
-#asetup 19.1.1.4,slc6,here # setup ATLAS release when needed +
-setupATLAS +
-</code> +
-and then do "source setup.sh". This works at ANL/ASC. Make a similar script when using lxplus or other Tier3 as explained in [[https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/SoftwareTutorialxAODAnalysisInROOT#1_Setup_the_Analysis_Release | CERN tutorial]]. +
- +
- +
-On LXPLUS: +
-<code bash setup.sh> +
-export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase +
-alias setupATLAS='source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh' +
-setupATLAS +
-</code> +
- +
- +
-To run tutorials, you can check these requirements (prepared by Asoka De Silva): +
- +
-  * You can check that your computer is ATLAS ready by doing (SL, SLC, CentOS) version 6): +
-<code> +
-setupATLAS +
-diagnostics +
-checkOS +
-</code> +
- +
-  * You will need a valid grid certificate registered with LCG and installed  in $HOME/.globus. You can check that your grid credentials are good by doing: +
-<code bash> +
-setupATLAS +
-diagnostics +
-gridCert +
-</code> +
- +
-   * Available disk space: +
- +
-You will need 500 MB of free space.  It can be $HOME or any other  location - note the location as you will be asked for it. If you are running on lxplus, you can request your home dir quota be increased to 10GB or request up to an additional 100GB of workspace.  To ask for space, go to (use your lxplus username below) +
- +
-<code>  +
-https://resources.web.cern.ch/resources/Manage/AFS/Settings.aspx?login=<your lxplus username> +
-</code>  +
- +
-You may need to request repeatedly to get the full quota (it is granted in increments.). To check how much quota you have on /afs (eg on lxplus), type fs lq; eg. +
- +
-<code bash> +
-fs lq /afs/cern.ch/user/d/desilva +
-fs lq /afs/cern.ch/work/d/desilva # for workspace if you have it +
-</code> +
-====== Lesson 1: Looking at a xAOD file ====== +
- +
-Let's us take a look at a typical xAOD file. You can open it with ROOT TBrowser to study its structure. +
- +
-<code bash> +
-mkdir lesson_1 +
-cd ./lesson_1 +
-</code> +
- +
-Now we need to get an example xAOD file. You can do all the checks above plus data for this tutorial as: +
- +
-<code bash> +
-setupATLAS +
-diagnostics +
-setMeUp anl-oct2014 +
-</code> +
- +
- +
-If you want to get an example xAOD file without running the above command, let's do it slowly:  +
- +
- +
-__Method 1. If you are at ANL, copy it__: +
-<code bash> +
-cp /data/nfs/chakanau/tutorial_xAOD_long/valid2.117050.PowhegPythia_P2011C_ttbar.digit.AOD.e2657_s1933_s1964_r5534_tid01482225_00/AOD.01482225._000140.pool.root.1 \ +
-AOD.01482225._000140.pool.root . +
-</code> +
- +
-__Method 2. Use xrdcp:__ +
- +
-<code bash> +
-localSetupFAX --rootVersion=current-SL6 +
-voms-proxy-init -voms atlas +
-xrdcp $STORAGEPREFIX/atlas/rucio/valid2:AOD.01482225._000140.pool.root.1 AOD.01482225._000140.pool.root.1 +
-</code> +
- +
-__Method 3: If you work at CERN, use this file:__ +
-<code> +
-/afs/cern.ch/atlas/project/PAT/xAODs/r5597/data12_8TeV.00204158.physics_JetTauEtmiss.recon.AOD.r5597/AOD.01495682._003054.pool.root.1 +
-/afs/cern.ch/atlas/project/PAT/xAODs/r5591/mc14_8TeV.117050.PowhegPythia_P2011C_ttbar.recon.AOD.e1727_s1933_s1911_r5591/AOD.01494882._111853.pool.root.1 +
-</code> +
- +
-__Method 4: If you work at your Tier3__ +
- +
-<code> +
-setupATLAS +
-diagnostics +
-setMeUpData anl-oct2014 mydata +
-</code> +
-The file will appear in "mydata/tutorial/anl-oct2014/datase/" directory +
- +
- +
-Now open this file with TBrowser: +
- +
-<code> +
-root +
-TBrowser a +
-</code> +
- +
-Click the file name using the left panel, Select "CollectionTree" and  find a branch with the extension "Aux" (for example, "AntiKt4TruthJetsAux") and then plot "AntiKt4TruthJetsAux.pt". See other detail in [[https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/SoftwareTutorialxAODEDM#Browsing_the_xAOD_with_the_TBrow | CERN  +
-tutorial]] +
- +
- +
- +
- +
-====== Lesson 2: Using pyROOT to read xAOD ====== +
- +
-Now we will read the above line in Python and print some values for electron (eta and phi) +
- +
-First, we setup our environment in the directory "lesson_1" that has the xAOD file: +
- +
-<code bash> +
-source setup.sh +
-rcSetup -u; rcSetup Base,2.0.12 +
-</code> +
- +
-Now you can check what versions of packages are linked: +
- +
-<code bash> +
-rc version +
-</code> +
-that shows a long version of package versions. +
- +
-The let's create a new directory and put this file: +
- +
- +
-<code python xAODPythonMacro.py> +
-#!/usr/bin/env python +
- +
-# Set up ROOT and RootCore: +
-import ROOT +
-ROOT.gROOT.Macro( '$ROOTCOREDIR/scripts/load_packages.C'+
- +
-ROOT.xAOD.Init() # Initialize the xAOD infrastructure +
- +
-fileName="AOD.01482225._000140.pool.root" # Set up the input files +
-treeName = "CollectionTree" # default when making transient tree anyway +
- +
-f = ROOT.TFile.Open(fileName) +
-t = ROOT.xAOD.MakeTransientTree( f, treeName) # Make the "transient tree" +
- +
-# Print some information: +
-print( "Number of input events: %s" % t.GetEntries() ) +
-for entry in xrange( t.GetEntries() ): +
-   t.GetEntry( entry ) +
-   print( "Processing run #%i, event #%i" % ( t.EventInfo.runNumber(), t.EventInfo.eventNumber() ) ) +
-   print( "Number of electrons: %i" % len( t.ElectronCollection ) ) +
-   for el in t.ElectronCollection:  # loop over electron collection +
-      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 +
-f.Close()    +
-</code> +
- +
-If you copy this script, correct indentation (the lines should start from the column position 0). This is a good for your to learn this code!  +
-Then run it as: +
- +
-<code bash> +
-chmod +x xAODPythonMacro.py +
-./xAODPythonMacro.py +
-</code> +
- +
- +
-Using this code, one can fill histograms. But the code runs slow. Below we will show how to use C++/ROOT compiled code to  +
-run over this file. +
- +
-How do you know about methods of "el.trackParticle()"? You can print methods of this object as: +
- +
-<code python> +
-print dir(el.trackParticle()) +
-</code> +
- +
-How will you find xAOD variables without using ROOT TBrowser? Try this code: +
- +
-<code bash> +
-asetup 19.1.1.1,slc6,gcc47,64,here +
-checkSG.py AOD.01482225._000140.pool.root +
-</code> +
- +
- +
-<note warning> +
-To run the next example, please start from a new terminal, run rcSetup. This is needed to avoid a conflict with asetup</note> +
- +
- +
-Now you can fill a histogram in this Python code. You should create a histogram before the event loop: +
- +
-<code python> +
-from ROOT import * +
-h1=TH1D("eta","eta",20,-4,4) +
-</code> +
- +
-Then fill it in the event loop as  h1.Fill( el.trackParticle().eta() ). Then we will write this histogram in  a file as: +
- +
-<code python> +
-hfile=TFile("test.root","RECREATE","ANL tutorial"+
-h1.Write() +
-hfile.Close() +
-</code> +
- +
-Here the code that write a ROOT histogram: +
- +
-<code python xAODPythonMacro_histo.py> +
-#!/usr/bin/env python +
- +
-import ROOT +
-ROOT.gROOT.Macro( '$ROOTCOREDIR/scripts/load_packages.C'+
- +
-ROOT.xAOD.Init() # Initialize the xAOD infrastructure +
- +
-fileName="AOD.01482225._000140.pool.root" # Set up the input files +
-treeName = "CollectionTree" # default when making transient tree anyway +
- +
-f = ROOT.TFile.Open(fileName) +
-t = ROOT.xAOD.MakeTransientTree( f, treeName) # Make the "transient tree" +
- +
-from ROOT import * +
-h1=TH1D("eta","eta",20, -4,4) +
- +
-# Print some information: +
-print( "Number of input events: %s" % t.GetEntries() ) +
-for entry in xrange( t.GetEntries() ): +
-   t.GetEntry( entry ) +
-   print( "Processing run #%i, event #%i" % ( t.EventInfo.runNumber(), t.EventInfo.eventNumber() ) ) +
-   print( "Number of electrons: %i" % len( t.ElectronCollection ) ) +
-   for el in t.ElectronCollection:  # loop over electron collection +
-      h1.Fill( el.trackParticle().eta() ) +
-      pass # end for loop over electron collection +
- +
-   pass # end loop over entries +
- +
-hfile=TFile("test.root","RECREATE","ANL tutorial"+
-h1.Write() +
-f.Close() +
-hfile.Close() +
-</code> +
- +
-Now open the root file and look at the histogram. +
-====== Lesson 3: C++/ROOT program to read xAOD ====== +
- +
-Now we will create a C++/ROOT analysis program and run over this input xAOD file. +
-Use the same setup file as above. +
- +
-<code bash> +
-source setup.sh +
-mkdir lesson_3; cd lesson_3 +
-rcSetup -u; rcSetup Base,2.0.12 +
-rc find_packages  # find needed packages +
-rc compile        # compiles them +
-</code> +
- +
-This takes some time to compile. Next we will us a simple example code that runs over multiple files located in some directory +
- +
-<code bash> +
-curl http://atlaswww.hep.anl.gov/asc/xaod_tutor_oct2014/MyAnalysis_lesson3.tgz | tar -xz;  +
-rc find_packages    # find this package +
-rc compile          # compiles it +
-cd MyAnalysis/util  # go to the analysis code +
-</code> +
-We are ready to run the code, which is "testRun.cxx"   +
-But we first should define a list with input data. This example reads file "inputdata.txt" with location of xAOD files. You can create it as: +
-<code bash> +
-python Make_input <directory with xAOD files> +
-</code> +
-Now the input file is ready and we run the example as: +
- +
-<code bash> +
-testRun submitDir   # runs over all files inside inputdata.txt   +
-</code> +
- +
-We pass "submitDir" which will be the output directory with ROOT file. +
-You must delete it every time you run the code (or use different output).  +
-The actual analysis should be put to "Root/MyxAODAnalysis.cxx" (will come back to this later). +
-The output histogram is ""submitDir/hist-sample.root" (which is almost empty). +
- +
- +
- +
-====== Lesson 4Filling histograms ====== +
- +
-Now we will make a number of changes to the above program. We will fill 2 histograms with pT of jets and muons. +
-To do this we will need a number of changes: +
- +
-1) We need to link several ATLAS packages.  +
- +
-<code> +
- PACKAGE_DEP = EventLoop xAODRootAccess xAODEventInfo GoodRunsLists xAODJet xAODTrigger xAODEgamma JetSelectorTools JetResolution xAODMuon +
-</code> +
- +
-in "cmt/Makefile.RootCore". We linked more packaged than needed to illustrate what can be linked.  Use "rc version" to check their versions. +
- +
-2) Then we need to modify 2 places to put histograms  +
- +
-<code python> +
-MyAnalysis/MyxAODAnalysis.h # used to define pointers to histograms +
-Root/MyxAODAnalysis.cxx     # initialized histograms and our analysis code that loops over jets and muons +
-</code> +
- +
-Let us run this code to see how it works: +
- +
-<code bash> +
-source setup.sh +
-mkdir lesson_4; cd lesson_4 +
-</code> +
- +
-<code bash> +
-rcSetup -u; rcSetup Base,2.0.12 +
-rc find_packages  # find needed packages +
-rc compile        # compiles  +
-</code> +
- +
-Next we will us a simple example code that runs over multiple files located in some directory. +
- +
-<code bash> +
-curl http://atlaswww.hep.anl.gov/asc/xaod_tutor_oct2014/MyAnalysis_lesson4.tgz tar -xz;  +
-wget http://atlaswww.hep.anl.gov/asc/xaod_tutor_oct2014/data12_8TeV.periodAllYear_DetStatus-v61-pro14-02_DQDefects-00-01-00_PHYS_StandardGRL_All_Good.xml +
-rc find_packages    # find this package +
-rc compile          # compiles it +
-cd MyAnalysis/util  # go to the analysis code  +
-</code> +
- +
-<note warning>The main analysis is in Root/MyxAODAnalysis.cxx. Please change the path to goodrunlist (on line 108) and recompile with "rc compile". </note> +
- +
-Now prepare an input file with  data from a  directory with xAOD files: +
-<code bash> +
-python Make_input <directory with xAOD files> +
-</code> +
- +
-and run the analysis: +
- +
-<code bash> +
-testRun submitDir   # runs over all files inside inputdata.txt   +
-</code> +
- +
-How does this work? Your analysis code is testRun.cxx. We pass "submitDir" which will be the output directory with ROOT file. +
-The actual analysis should be put to "Root/MyxAODAnalysis.cxx" as explained above. This example has an access to muon and jet containers, plus it reads goodrunlist. +
- +
-The output of this example is in "submitDir/hist-sample.root". Open  it with ROOT: +
- +
-<code> +
-root +
-TBrowser a +
-</code> +
-and look at the histograms of jet and muon pT. +
- +
- +
-<note tip>Read more:  [[https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/SoftwareTutorialxAODAnalysisInROOT#7_Creating_and_saving_histograms | Creating_and_saving_histograms]]</note>+
  
  --- //[[[email protected]|Sergei Chekanov]] 2014/10/28 07:49//  --- //[[[email protected]|Sergei Chekanov]] 2014/10/28 07:49//
asc/tutorials/2014october28.1414527445.txt.gz · Last modified: 2014/10/28 20:17 by asc