This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Last revision Both sides next revision | ||
asc:tutorials:2014october28 [2014/10/29 12:56] asc |
asc:tutorials:2014october28 [2014/10/29 13:53] asc old revision restored (2014/10/28 16:33) |
||
---|---|---|---|
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 xAOD tutorial is merged | + | |
+ | ====== Getting started ====== | ||
+ | |||
+ | 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 | ||
+ | < | ||
+ | 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 / | ||
+ | </ | ||
+ | |||
+ | __Method 2. Use xrdcp:__ | ||
+ | |||
+ | <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 xAODPythonMacro.py> | ||
+ | # | ||
+ | |||
+ | # 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 do you know about methods of " | ||
+ | |||
+ | <code python> | ||
+ | print dir(el.trackParticle()) | ||
+ | </ | ||
+ | |||
+ | 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 | ||
+ | </ | ||
+ | |||
+ | |||
+ | <note warning> | ||
+ | To run the next example, please start from a new terminal, run rcSetup. This is needed to avoid a conflict with asetup</ | ||
+ | |||
+ | |||
+ | 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 in a file as: | ||
+ | |||
+ | <code python> | ||
+ | hfile=TFile(" | ||
+ | h1.Write() | ||
+ | hfile.Close() | ||
+ | </ | ||
+ | |||
+ | Here the code that write a ROOT histogram: | ||
+ | |||
+ | <code python xAODPythonMacro_histo.py> | ||
+ | # | ||
+ | |||
+ | 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 " | ||
+ | |||
+ | from ROOT import * | ||
+ | h1=TH1D(" | ||
+ | |||
+ | # Print some information: | ||
+ | print( " | ||
+ | for entry in xrange( t.GetEntries() ): | ||
+ | | ||
+ | | ||
+ | | ||
+ | for el in t.ElectronCollection: | ||
+ | h1.Fill( el.trackParticle().eta() ) | ||
+ | pass # end for loop over electron collection | ||
+ | |||
+ | pass # end loop over entries | ||
+ | |||
+ | hfile=TFile(" | ||
+ | h1.Write() | ||
+ | f.Close() | ||
+ | hfile.Close() | ||
+ | </ | ||
+ | |||
+ | 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, | ||
+ | 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 < | ||
+ | </ | ||
+ | |||
+ | In case if you need xAOD data, do this: | ||
+ | |||
+ | <code bash> | ||
+ | mkdir data | ||
+ | cd data | ||
+ | localSetupFAX --rootVersion=current-SL6 | ||
+ | voms-proxy-init -voms atlas | ||
+ | xrdcp $STORAGEPREFIX/ | ||
+ | xrdcp $STORAGEPREFIX/ | ||
+ | xrdcp $STORAGEPREFIX/ | ||
+ | </ | ||
+ | |||
+ | and run: | ||
+ | |||
+ | < | ||
+ | cd .. | ||
+ | python Make_input data | ||
+ | </ | ||
+ | Now inputdata.txt should pick up your xAOD files. | ||
+ | |||
+ | |||
+ | 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 (it's done already, just look what is inside of the package prepared for this lesson). | ||
+ | |||
+ | < | ||
+ | | ||
+ | </ | ||
+ | |||
+ | in " | ||
+ | |||
+ | 2) Then we need to modify 2 places to put histograms (it's done already in the example shown below) | ||
+ | |||
+ | <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 with jet and muon pT. | ||
+ | |||
+ | |||
+ | <note tip>Read more: [[https:// | ||
--- // | --- // |