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
Last revision Both sides next revision
asc:tutorials:2014october28 [2014/10/28 15:55]
asc [Lesson 2: Using pyROOT to read xAOD]
asc:tutorials:2014october28 [2014/10/29 13:53]
asc old revision restored (2014/10/28 16:33)
Line 95: Line 95:
 __Method 1. If you are at ANL, copy it__: __Method 1. If you are at ANL, copy it__:
 <code bash> <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 +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
-AOD.01482225._000140.pool.root .+
 </code> </code>
  
Line 104: Line 103:
 localSetupFAX --rootVersion=current-SL6 localSetupFAX --rootVersion=current-SL6
 voms-proxy-init -voms atlas voms-proxy-init -voms atlas
-xrdcp $STORAGEPREFIX/atlas/rucio/valid2:AOD.01482225._000140.pool.root.1 AOD.01482225._000140.pool.root.1+xrdcp $STORAGEPREFIX/atlas/rucio/valid2:AOD.01482225._000140.pool.root.1 AOD.01482225._000140.pool.root
 </code> </code>
  
Line 120: Line 119:
 setMeUpData anl-oct2014 mydata setMeUpData anl-oct2014 mydata
 </code> </code>
-The file will appear in "mydata/tutorial/anl-oct2014/datase/" directory+The file will appear in "mydata/tutorial/anl-oct2014/database/" directory
  
  
Line 157: Line 156:
  
  
-<code python "xAODPythonMacro.py>+<code python xAODPythonMacro.py>
 #!/usr/bin/env python #!/usr/bin/env python
  
Line 196: Line 195:
 Using this code, one can fill histograms. But the code runs slow. Below we will show how to use C++/ROOT compiled code to  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. 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: How will you find xAOD variables without using ROOT TBrowser? Try this code:
Line 204: Line 209:
 </code> </code>
  
-You will see a table with the names of the variables. 
  
-Now you can fill histogram in this Python code:+<note warning> 
 +To run the next example, please start from new terminal, run rcSetup. This is needed to avoid a conflict with asetup</note>
  
-You should create a histogram before the event loop:+ 
 +Now you can fill a histogram in this Python code. You should create a histogram before the event loop:
  
 <code python> <code python>
 from ROOT import * from ROOT import *
-h1=TH1D("eta","eta",20, -4,4)+h1=TH1D("eta","eta",20,-4,4)
 </code> </code>
  
-Then fill it in the event loop as  h1.Fill( el.trackParticle().eta() ).  +Then fill it in the event loop as  h1.Fill( el.trackParticle().eta() ). Then we will write this histogram in  a file as:
- +
-Then we will write this histogram +
-at the end (after f.Close())+
  
 <code python> <code python>
Line 225: Line 228:
 hfile.Close() hfile.Close()
 </code> </code>
-====== 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]".+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. Use the same setup file as above.
  
Line 251: Line 293:
 python Make_input <directory with xAOD files> python Make_input <directory with xAOD files>
 </code> </code>
 +
 +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/atlas/rucio/valid2:AOD.01482225._000140.pool.root.1 .
 +xrdcp $STORAGEPREFIX/atlas/rucio/valid2:AOD.01482225._000141.pool.root.1 .
 +xrdcp $STORAGEPREFIX/atlas/rucio/valid2:AOD.01482225._000142.pool.root.1 .
 +</code>
 +
 +and run:
 +
 +<code>
 +cd ..
 +python Make_input data
 +</code>
 +Now inputdata.txt should pick up your xAOD files.
 +
 +
 Now the input file is ready and we run the example as: Now the input file is ready and we run the example as:
  
Line 269: Line 333:
 To do this we will need a number of changes: To do this we will need a number of changes:
  
-1) We need to link several ATLAS packages. +1) We need to link several ATLAS packages (it's done already, just look what is inside of the package prepared for this lesson)
  
 <code> <code>
Line 277: Line 341:
 in "cmt/Makefile.RootCore". We linked more packaged than needed to illustrate what can be linked.  Use "rc version" to check their versions. 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 +2) Then we need to modify 2 places to put histograms (it's done already in the example shown below)
  
 <code python> <code python>
Line 329: Line 393:
 TBrowser a TBrowser a
 </code> </code>
-and look at the histograms of jet and muon pT.+and look at the histograms with jet and muon pT.
  
  
asc/tutorials/2014october28.txt · Last modified: 2014/10/29 13:55 by asc