hep data analysis using root · hep data analysis using root week 4 § compiling binaries and...
TRANSCRIPT
HEPdataanalysisusingROOTweek4
§ Compilingbinariesandlibraries§ ROOTasadependency§ Bindingstootherlanguages
Week4
• Compilingbinariesandlibraries– fastercode– opAmalTTree::Branch()-ing
• ROOTasadependency– includingROOTinyourowncode
• Bindingstootherlanguages– PyROOT– theothers
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+
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 *
Vectorbenchmarkingexample
• WhatistheoverheadofusingSTLvectorsand/orROOTcontainers?– comparedtousingbarearrays
• TofillSTLvectorswithnonbasicdatatypes– mustcompiletheuserobject
• TakealookathTp://www.hep.shef.ac.uk/people/perkin/containerBenchmarking.C
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
BacktoTTree::Branch()
• ROOTexpects…
wriAngauserobject
• Verylightweightexample– ‘PlainOldData’class
Vectorbenchmarkingexample
• Filluserobjectforeachtrial
Vectorbenchmarkingexample
• Filluserobjectforeachtrial
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
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
Aside:TTree::MakeClass
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
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
IllustraA
vem
akefi
le
IllustraA
vem
akefi
le
IllustraA
vem
akefi
le
Bindingstootherlanguages
• SofarhaveworkedwithC++bindingstoROOT– withcaveatofCINTisms/ROOTish
• Whatotherbindingsareavailable– Fortran(legacy)– Python(whatIuseforanalysis)– Ruby – R
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
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
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
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'>
PyROOTsnippets
• Argumentunpacking
– neat!
>>> def cat(a='',b=''):... ... return a+b... >>> s = ["abc","def"]>>> c = cat(*s)>>> c'abcdef'>>>
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'>>>>
Closingremarks
• Whistle-stoptourof– compilaAon,dependenciesandPyROOT
• I’llemailoutmylinux/command-linecheatsheetlatertoday– usefuloneliners
• AnyquesAons?
end
backups