hep data analysis using root · hep data analysis using root week 4 § compiling binaries and...

29
HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Upload: others

Post on 10-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

HEPdataanalysisusingROOTweek4

§  Compilingbinariesandlibraries§  ROOTasadependency§  Bindingstootherlanguages

Page 2: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Week4

•  Compilingbinariesandlibraries–  fastercode– opAmalTTree::Branch()-ing

•  ROOTasadependency–  includingROOTinyourowncode

•  Bindingstootherlanguages– PyROOT–  theothers

Page 3: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

macroscompiledasbinaries

•  Ranacompiledmacrolastweek– usethe‘+’decoraAon

•  fromthecommandline(asabove)– orfromCINT

$ root mathcoreVectorCollection.C+Time for new Vector 0.113157 0.12*******************************************************************************Tree :t1 : Tree with new LorentzVector **Entries : 10000 : Total = 1854232 bytes File Size = 1667895 *

root [1] .x mathcoreVectorCollectionC+

Page 4: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Compilinglibraries

•  CompilaAonproducesasharedobjectlibrary– youcanlinkanycodeagainstit

•  LibrariescanbeloadedintoCINT– andthemethodscalled

root [0] gSystem->Load("mathcoreVectorCollection_C.so");root [1] mathcoreVectorCollection() Time for new Vector 0.177571 0.12*******************************************************************************Tree :t1 : Tree with new LorentzVector **Entries : 10000 : Total = 1854232 bytes File Size = 1667862 ** : : Tree compression factor = 1.11 *

Page 5: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Vectorbenchmarkingexample

•  WhatistheoverheadofusingSTLvectorsand/orROOTcontainers?– comparedtousingbarearrays

•  TofillSTLvectorswithnonbasicdatatypes– mustcompiletheuserobject

•  TakealookathTp://www.hep.shef.ac.uk/people/perkin/containerBenchmarking.C

Page 6: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages
Page 7: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Vectorbenchmarkingexample

•  Results

•  Now,fillaTTreewithresultsovermanytrials– howtodoit?

array array : Real Time = 0.03 seconds Cpu Time = 0.03 secondsminimal array : Real Time = 0.05 seconds Cpu Time = 0.04 secondsTLVec array : Real Time = 0.08 seconds Cpu Time = 0.08 secondsarray vec : Real Time = 0.03 seconds Cpu Time = 0.03 secondsminimal vec : Real Time = 0.03 seconds Cpu Time = 0.03 secondsTLVec vec : Real Time = 0.04 seconds Cpu Time = 0.04 secondsarray vec push_back : Real Time = 0.04 seconds Cpu Time = 0.03 secondsminimal vec push_back : Real Time = 0.04 seconds Cpu Time = 0.05 secondsTLVec vec push_back : Real Time = 0.04 seconds Cpu Time = 0.03 secondsminimal TClonesArray : Real Time = 0.12 seconds Cpu Time = 0.11 secondsTLVec TClonesArray : Real Time = 0.11 seconds Cpu Time = 0.12 seconds

Page 8: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

BacktoTTree::Branch()

•  ROOTexpects…

Page 9: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

wriAngauserobject

•  Verylightweightexample–  ‘PlainOldData’class

Page 10: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Vectorbenchmarkingexample

•  Filluserobjectforeachtrial

Page 11: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Vectorbenchmarkingexample

•  Filluserobjectforeachtrial

Page 12: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Vectorbenchmarkingexample

•  Results

array array

minimal array

TLVec array

array vec

minimal vec

TLVec vec

array vec push_back

minimal vec push_back

TLVec vec push_back

minimal TClonesArray

TLVec TClonesArray

cpu time (s)

210

310

Page 13: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Aside:TTree::MakeClass

•  Reallyusefulmethod– AutomaAcallywritescodetoreadanyTTree

•  Takealookat/runthefilesproduced– commentsinstructonusage

•  CancopewithmorecomplexTTreestoo

root [4] benchTree->MakeClass()Info in <TTreePlayer::MakeClass>: Files: benchTree.h and benchTree.C generated from TTree: benchTree(Int_t)0root [5] .q

Page 14: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Aside:TTree::MakeClass

Page 15: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

ROOTasadependency

•  i.e.compileabinarythatcallsROOT– useroot-config!

•  providespathtoincludesandlibraries–  toseeallROOTconfiguraAons

perkair:testMacros perkin$ root-config –config

--prefix=/Users/perkin/t2k/ROOT/v5r34p18n02/Darwin-x86_64 --etcdir=/Users/perkin/t2k/ROOT/v5r34p18n02/Darwin-x86_64 --disable-afs --disable-alien --disable-builtin-afterimage --enable-builtin-ftgl --enable-builtin-freetype --enable-builtin-pcre --enable-builtin-zlib --disable-castor --disable-chirp --disable-cintex --disable-explicitlink --disable-fftw3 --enable-gdml --disable-gfal --disable-globus --disable-krb5 --disable-ldap --disable-monalisa --with-mysql-incdir=/Users/perkin/t2k/MYSQL/v5r051an01/Darwin-x86_64/include/mysql --with-mysql-libdir=/Users/perkin/t2k/MYSQL/v5r051an01/Darwin-x86_64/lib/mysql --disable-odbc --disable-oracle --disable-pgsql --disable-pythia6 --disable-qt --disable-qtgsi --disable-reflex --enable-roofit --enable-minuit2 --disable-ruby --disable-rfio --disable-rpath --disable-sapdb --disable-shadowpw --enable-soversion --disable-srp --disable-ssl --disable-table --enable-unuran --disable-winrtdebug --enable-gsl-shared --with-gsl-incdir=/Users/perkin/t2k/GSL/v1r15p0n00/Darwin-x86_64/include --with-gsl-libdir=/Users/perkin/t2k/GSL/v1r15p0n00/Darwin-x86_64/lib

Page 16: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

HelloWorld

perkair:testMacros perkin$ c++ $(root-config --cflags) -I$ROOTSYS/include -o dependencyTest.o -c dependencyTest.cxx perkair:testMacros perkin$ c++ $(root-config --cflags) $(root-config --libs) -I$ROOTSYS/include -o depTest dependencyTest.oclang: warning: argument unused during compilation: '-pthread'

perkair:testMacros perkin$ ./depTest Hello World! Here's a random number: 0.977113

Page 17: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

IllustraA

vem

akefi

le

Page 18: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

IllustraA

vem

akefi

le

Page 19: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

IllustraA

vem

akefi

le

Page 20: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Bindingstootherlanguages

•  SofarhaveworkedwithC++bindingstoROOT– withcaveatofCINTisms/ROOTish

•  Whatotherbindingsareavailable– Fortran(legacy)– Python(whatIuseforanalysis)– Ruby – R

Page 21: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

pythoncompaAbility

•  Languagesupportnotenabledbydefault– pythonenabledforthisversiononhepcluster

•  CannowcallROOTfrominsidepython

$ source /usr/local/root/5.32-00-py26/bin/thisroot.sh

$ pythonPython 2.6.6 (r266:84292, Jul 22 2015, 16:47:47) [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import ROOT>>> ROOT.gRandom.Rndm()0.999741748906672

Page 22: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

PyROOT•  Whybother?!

–  implicittypingandgenerallymoreelegantsyntax–  stringmanipulaAon

•  Easeofuseforplo]ngdata–  TTree::Drawbasedcutsallstringbased

•  lessefficientforcodeexecuAon –  but,pythonisagluinglanguage

•  shouldsAllruncompiledC/Fortran/MATLAB/whateverunderneath•  HandlingofTClonesArraysofuserobjectsmuchneaterin

python–  variablesareuntyped

•  hence,notypedefs(totruncatethelong,longnames)•  ordynamiccasAngs(ofretrievedobjects)arerequired

Page 23: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

PyROOTsnippets

•  pythonlistscancontainanything– andhaveneaterindexing

>>> import ROOT>>> ROOT.gRandom.Rndm()0.999741748906672>>> myList = ['abc', 123, ROOT.gRandom]>>> print myList['abc', 123, <ROOT.TRandom* object ("Random3") at 0x7fd04fdaedc0>]>>> myList[-1].Rndm()0.16290987539105117

Page 24: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

PyROOTsnippets

•  EasysorAng>>> myList.sort(key=lambda x : type(x))>>> print(myList)[<ROOT.TRandom* object ("Random3") at 0x7fd04fdaedc0>, 123, 'abc']>>> for l in myList:... print type(l)... <class 'ROOT.TRandom'><type 'int'><type 'str'>

Page 25: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

PyROOTsnippets

•  Argumentunpacking

– neat!

>>> def cat(a='',b=''):... ... return a+b... >>> s = ["abc","def"]>>> c = cat(*s)>>> c'abcdef'>>>

Page 26: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

PyROOTsnippets

•  PyROOTknowstypeofobjects– don’thavetorecastTObjectintoderivedtype

•  Many,manymoreexamplesoutthere–  takealook

>>> import ROOT>>> f = ROOT.TFile.Open("containerBenchmarkingLoops.root")TClass::TClass:0: RuntimeWarning: no dictionary for class BenchmarkBranch is available>>> t = f.Get("benchTree")>>> type(t)<class 'ROOT.TTree'>>>>

Page 27: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

Closingremarks

•  Whistle-stoptourof– compilaAon,dependenciesandPyROOT

•  I’llemailoutmylinux/command-linecheatsheetlatertoday– usefuloneliners

•  AnyquesAons?

Page 28: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

end

Page 29: HEP data analysis using ROOT · HEP data analysis using ROOT week 4 § Compiling binaries and libraries § ROOT as a dependency § Bindings to other languages

backups