asc:tutorials:2014october28
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
asc:tutorials:2014october28 [2014/10/28 15:55] – [Lesson 2: Using pyROOT to read xAOD] asc | 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:// | ||
- | 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 | |
- | ====== Getting started ====== | + | [[https:// |
- | + | ||
- | 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. | + | |
- | + | ||
- | * Please make sure that your local Tier3 has the usual ATLAS setup environment based on " | + | |
- | * Several tutorial topics will require the grid access (use voms-proxy-init -voms atlas to check this). | + | |
- | + | ||
- | ANL people can use " | + | |
- | + | ||
- | First, we will setup ATLAS release. | + | |
- | + | ||
- | 1) Setup kinit if needed: | + | |
- | + | ||
- | 2) Create a bash script to setup ATLAS software. | + | |
- | + | ||
- | <code bash setup.sh> | + | |
- | # | + | |
- | export ALRB_localConfigDir="/ | + | |
- | export ATLAS_LOCAL_ROOT_BASE=/ | + | |
- | source ${ATLAS_LOCAL_ROOT_BASE}/ | + | |
- | #asetup 19.1.1.4, | + | |
- | setupATLAS | + | |
- | </ | + | |
- | and then do " | + | |
- | + | ||
- | + | ||
- | On LXPLUS: | + | |
- | <code bash setup.sh> | + | |
- | export ATLAS_LOCAL_ROOT_BASE=/ | + | |
- | alias setupATLAS=' | + | |
- | setupATLAS | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | 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): | + | |
- | < | + | |
- | setupATLAS | + | |
- | diagnostics | + | |
- | checkOS | + | |
- | </ | + | |
- | + | ||
- | * You will need a valid grid certificate registered | + | |
- | <code bash> | + | |
- | setupATLAS | + | |
- | diagnostics | + | |
- | gridCert | + | |
- | </ | + | |
- | + | ||
- | * Available disk space: | + | |
- | + | ||
- | You will need 500 MB of free space. | + | |
- | + | ||
- | < | + | |
- | https:// | + | |
- | </ | + | |
- | + | ||
- | 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 / | + | |
- | fs lq / | + | |
- | </ | + | |
- | ====== 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 ./ | + | |
- | </ | + | |
- | + | ||
- | 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 | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | 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 / | + | |
- | AOD.01482225._000140.pool.root . | + | |
- | </ | + | |
- | + | ||
- | __Method | + | |
- | + | ||
- | <code bash> | + | |
- | localSetupFAX --rootVersion=current-SL6 | + | |
- | voms-proxy-init -voms atlas | + | |
- | xrdcp $STORAGEPREFIX/ | + | |
- | </ | + | |
- | + | ||
- | __Method 3: If you work at CERN, use this file:__ | + | |
- | < | + | |
- | / | + | |
- | / | + | |
- | </ | + | |
- | + | ||
- | __Method 4: If you work at your Tier3__ | + | |
- | + | ||
- | < | + | |
- | setupATLAS | + | |
- | diagnostics | + | |
- | setMeUpData anl-oct2014 mydata | + | |
- | </ | + | |
- | The file will appear in " | + | |
- | + | ||
- | + | ||
- | Now open this file with TBrowser: | + | |
- | + | ||
- | < | + | |
- | root | + | |
- | TBrowser a | + | |
- | </ | + | |
- | + | ||
- | Click the file name using the left panel, Select " | + | |
- | 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 " | + | |
- | + | ||
- | <code bash> | + | |
- | source setup.sh | + | |
- | rcSetup -u; rcSetup Base, | + | |
- | </ | + | |
- | + | ||
- | Now you can check what versions of packages are linked: | + | |
- | + | ||
- | <code bash> | + | |
- | rc version | + | |
- | </ | + | |
- | that shows a long version of package versions. | + | |
- | + | ||
- | The let's create a new directory and put this file: | + | |
- | + | ||
- | + | ||
- | <code python " | + | |
- | # | + | |
- | + | ||
- | # Set up ROOT and RootCore: | + | |
- | import ROOT | + | |
- | ROOT.gROOT.Macro( ' | + | |
- | + | ||
- | ROOT.xAOD.Init() # Initialize the xAOD infrastructure | + | |
- | + | ||
- | fileName=" | + | |
- | treeName = " | + | |
- | + | ||
- | f = ROOT.TFile.Open(fileName) | + | |
- | t = ROOT.xAOD.MakeTransientTree( f, treeName) # Make the " | + | |
- | + | ||
- | # Print some information: | + | |
- | print( " | + | |
- | for entry in xrange( t.GetEntries() ): | + | |
- | | + | |
- | | + | |
- | | + | |
- | for el in t.ElectronCollection: | + | |
- | print( " | + | |
- | pass # end for loop over electron collection | + | |
- | pass # end loop over entries | + | |
- | f.Close() | + | |
- | </ | + | |
- | + | ||
- | 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 | + | |
- | ./ | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | 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 will you find xAOD variables without using ROOT TBrowser? Try this code: | + | |
- | + | ||
- | <code bash> | + | |
- | asetup 19.1.1.1, | + | |
- | checkSG.py AOD.01482225._000140.pool.root | + | |
- | </ | + | |
- | + | ||
- | You will see a table with the names of the variables. | + | |
- | + | ||
- | 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(" | + | |
- | </ | + | |
- | + | ||
- | Then fill it in the event loop as h1.Fill( el.trackParticle().eta() ). | + | |
- | + | ||
- | Then we will write this histogram | + | |
- | at the end (after f.Close()) | + | |
- | + | ||
- | <code python> | + | |
- | hfile=TFile(" | + | |
- | h1.Write() | + | |
- | hfile.Close() | + | |
- | </ | + | |
- | ====== Lesson 3: Analysis program to read xAOD ====== | + | |
- | + | ||
- | Now we will create a C++/ROOT analysis program and run over this input xAOD file. Do not forget to run "kinit [email protected]" | + | |
- | Use the same setup file as above. | + | |
- | + | ||
- | <code bash> | + | |
- | source setup.sh | + | |
- | mkdir lesson_3; cd lesson_3 | + | |
- | rcSetup -u; rcSetup Base, | + | |
- | rc find_packages | + | |
- | rc compile | + | |
- | </ | + | |
- | + | ||
- | 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:// | + | |
- | rc find_packages | + | |
- | rc compile | + | |
- | cd MyAnalysis/ | + | |
- | </ | + | |
- | We are ready to run the code, which is " | + | |
- | But we first should define a list with input data. This example reads file " | + | |
- | <code bash> | + | |
- | python Make_input < | + | |
- | </ | + | |
- | Now the input file is ready and we run the example as: | + | |
- | + | ||
- | <code bash> | + | |
- | testRun submitDir | + | |
- | </ | + | |
- | + | ||
- | We pass " | + | |
- | You must delete it every time you run the code (or use different output). | + | |
- | The actual analysis should be put to " | + | |
- | The output histogram is "" | + | |
- | + | ||
- | + | ||
- | + | ||
- | ====== Lesson 4: Filling 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. | + | |
- | + | ||
- | < | + | |
- | | + | |
- | </ | + | |
- | + | ||
- | in " | + | |
- | + | ||
- | 2) Then we need to modify 2 places to put histograms | + | |
- | + | ||
- | <code python> | + | |
- | MyAnalysis/ | + | |
- | Root/ | + | |
- | </ | + | |
- | + | ||
- | Let us run this code to see how it works: | + | |
- | + | ||
- | <code bash> | + | |
- | source setup.sh | + | |
- | mkdir lesson_4; cd lesson_4 | + | |
- | </ | + | |
- | + | ||
- | <code bash> | + | |
- | rcSetup -u; rcSetup Base, | + | |
- | rc find_packages | + | |
- | rc compile | + | |
- | </ | + | |
- | + | ||
- | Next we will us a simple example code that runs over multiple files located in some directory. | + | |
- | + | ||
- | <code bash> | + | |
- | curl http:// | + | |
- | wget http:// | + | |
- | rc find_packages | + | |
- | rc compile | + | |
- | cd MyAnalysis/ | + | |
- | </ | + | |
- | + | ||
- | <note warning> | + | |
- | + | ||
- | Now prepare an input file with data from a directory with xAOD files: | + | |
- | <code bash> | + | |
- | python Make_input < | + | |
- | </ | + | |
- | + | ||
- | and run the analysis: | + | |
- | + | ||
- | <code bash> | + | |
- | testRun submitDir | + | |
- | </ | + | |
- | + | ||
- | How does this work? Your analysis code is testRun.cxx. We pass " | + | |
- | The actual analysis should be put to " | + | |
- | + | ||
- | The output of this example is in " | + | |
- | + | ||
- | < | + | |
- | root | + | |
- | TBrowser a | + | |
- | </ | + | |
- | and look at the histograms of jet and muon pT. | + | |
- | + | ||
- | + | ||
- | <note tip>Read more: [[https:// | + | |
--- // | --- // |
asc/tutorials/2014october28.1414511700.txt.gz · Last modified: 2014/10/28 15:55 by asc