Sei sulla pagina 1di 55

kCC1 8as|cs

ueb MohapaLra
1hls lecLure ls based on lermllab 8CC1 LuLorlal and 8CC1 lecLure ln CL8n summer school
lnLroducLlon
WPA1 lS 8CC1 ?
8CC1 ls an ob[ecL orlenLed framework
lL has a C/C++ lnLerpreLer (Cln1) and C/C++ compller (ACLlC)
8CC1 ls used exLenslvely ln Plgh Lnergy hyslcs for daLa
analysls"
- 8eadlng and wrlLlng daLa flles
- CalculaLlons Lo produce ploLs, numbers and flLs.
WP? 8CC1 ?
lL can handle large flles (ln C8) conLalnlng n-Luples and
PlsLograms
MulLlplaLform sofLware
lLs based on wldely known programmlng language C++
lLs free
CuLllne of Lhls lecLure
Cvervlew of 8CC1 framework
Cul and command llne baslcs
Cln1: lnLerpreLer for C and C++ code
Craphs, PlsLograms and 8ooL 1rees
luncLlons and flLLlng
Learnlng 8CC1
hLLp://rooL.cern.ch/rooL/1uLorlals.hLml
hLLp://rooL.cern.ch/rooL/Pow1o.hLml
hLLp://www-rooL.fnal.gov/rooL/
hLLp://www.slac.sLanford.edu/8l8CC1/www/doc/w
orkbook/rooL[1,2,3}/rooL[1,2,3}.hLml
8CC1 Malllng LlsLs
rooLLalk[rooL.cern.ch
hLLp://rooL.cern.ch/rooL/rooLLalk/AbouL8ooL1alk.hLml
8ooL lnLeracLlve Sesslon
8ASn exporL 8CC1S?S=/cern/rooL
exporL Lu_Ll88A8?_A1P=$8CC1S?S/llb:$Lu_Ll88A8?_A1P
exporL A1P=$8CC1S?S/bln:$A1P
1CSP seLenv 8CC1S?S /cern/rooL
seLenv Lu_Ll88A8?_A1P $8CC1S?S/llb:$Lu_Ll88A8?_A1P
seLenv A1P $8CC1S?S/bln:$A1P
SeL 8CC1S?S Lo Lhe dlrecLory where 8CC1 ls lnsLalled
Add 8CC1 llbrarles Lo Lhe Lu_Ll88A8?_A1P
lnclude Lhe 8CC1 execuLable blnary flles Lo Lhe blnary paLh
?ou may add Lhe above llnes Lo your ~/.cshrc or ~/.bashrc
?ou may deflne your rooL seLLlngs ln ~/.rooLlogon.C
PlsLory of all commands are sLored ln ~/.rooL_hlsL
Cb[ecL CrlenLed ConcepLs
Members: a has a"
relaLlonshlp Lo Lhe
class.
lnherlLance: an ls a"
relaLlonshlp Lo Lhe
class.
Class: Lhe descrlpLlon of a Lhlng" ln Lhe sysLem
Cb[ecL: lnsLance of a class
MeLhods: funcLlons for a class
Event
Track Segment Vertex
Momentum MassSquare
InterceptAtVert
HAS A HAS A HAS A
HAS A HAS A HAS A
TObject
IS A
1he lramework CrganlzaLlon
*.h
...
cint
makecint
new
proofd
proofserv
rmkdepend
root
root.exe
rootcint
root-config
rootd
bin
$ROOTSYS
libCint.so
libCore.so
libEG.so
*libEGPythia.so
*libEGPythia6.so
libEGVenus.so
libGpad.so
libGraf.so
libGraf3d.so
libGui.so
libGX11.so
*libGX11TTF.so
libHist.so
libHistPainter.so
libHtml.so
libMatrix.so
libMinuit.so
libNew.so
libPhysics.so
libPostscript.so
libProof.so
*libRFIO.so
*libRGL.so
libRint.so
*libThread.so
libTree.so
libTreePlayer.so
libTreeViewer.so
*libttf.so
libX3d.so
libXpm.a
Aclock.cxx
Aclock.h
Event.cxx
Event.h
EventLinkDef.h
Hello.cxx
Hello.h
MainEvent.cxx
Makefile
Makefile.in
Makefile.win32
README
TestVectors.cxx
Tetris.cxx
Tetris.h
eventa.cxx
eventb.cxx
eventload.cxx
guitest.cxx
hsimple.cxx
hworld.cxx
minexam.cxx
stress.cxx
tcollbm.cxx
tcollex.cxx
test2html.cxx
tstring.cxx
vlazy.cxx
vmatrix.cxx
vvector.cxx
lib test tutorials
include
* Optional
Installation
EditorBar.C
Ifit.C
analyze.C
archi.C
arrow.C
basic.C
basic.dat
basic3d.C
benchmarks.C
canvas.C
classcat.C
cleanup.C
compile.C
copytree.C
copytree2.C
demos.C
demoshelp.C
dialogs.C
dirs.C
ellipse.C
eval.C
event.C
exec1.C
exec2.C
feynman.C
fildir.C
file.C
fillrandom.C
first.C
fit1.C
fit1_C.C
fitslicesy.C
formula1.C
framework.C
games.C
gaxis.C
geometry.C
gerrors.C
gerrors2.C
graph.C
h1draw.C
hadd.C
hclient.C
hcons.C
hprod.C
hserv.C
hserv2.C
hsimple.C
hsum.C
hsumTimer.C
htmlex.C
io.C
latex.C
latex2.C
latex3.C
manyaxis.C
multifit.C
myfit.C
na49.C
na49geomfile.C
na49view.C
na49visible.C
ntuple1.C
oldbenchmarks.C
pdg.dat
psexam.C
pstable.C
rootalias.C
rootenv.C
rootlogoff.C
rootlogon.C
rootmarks.C
runcatalog.sql
runzdemo.C
second.C
shapes.C
shared.C
splines.C
sqlcreatedb.C
sqlfilldb.C
sqlselect.C
staff.C
staff.dat
surfaces.C
tcl.C
testrandom.C
tornado.C
tree.C
two.C
xyslider.C
xysliderAction.C
zdemo.C
user lnLerfaces
.q u|t
.L macro.C Load a macro flle
.x macro.C Load and execuLe a macro flle
.x macro.C++ Complle and execuLe
Cul 8aslcs
ulsplay Lhe browser
18rowser b,
SLarL rooL
> rooL
CulL rooL ([usL ln case)
rooL[0]>.q
ulsplaylng a PlsLogram
ulsplay a hlsLogram
1he Canvas
Cpen Lhe rooL flle
8rowse Lhe flle
8aslc navlgaLlon by Cllcklng
LefL Cllck
selecL Lhe ob[ecL
drag Lhe ob[ecL
reslze Lhe ob[ecL
8lghL Cllck
conLexL menu
class::name
meLhods
Mlddle Cllck
acLlvaLe canvas
freezes evenL sLaLus bar
1he uraw anel
llLLlng, Colorlng, and Zoomlng
Addlng a gausslan flL
Colorlng Lhe hlsLogram
Zoomlng/unzoomlng
Addlng Cb[ecLs Lo Lhe Canvas
1he LdlLor
Addlng an Arrow
Addlng 1exL
Addlng anoLher ad
Add a ad
SelecL Lhe new ad
uraw a hlsLogram
Add a LlLle for Lhe axls
Modlfylng Lhe SLaLlsLlcs
1he Canvas ln Lhe
8rowser
SeLLlng Lhe (7)
sLaLlsLlcs opLlons
defaulL = 0001111
8eadlng & SLorlng uaLa ln 8ooL
uaLa can be read from flles/daLabase/neLwork
uaLa ls generally sLored as a 11ree/1nLuple (
slmllar Lo a Lable wlLh rows and columns )
Lach row represenLs an evenL
Lach column represenLs a quanLlLy
1rees can be creaLed from ASCll flles.
8ead daLa from ASCll flle Lo 8ooL llle
bas|c.dat tree.C
-1.102279 -1.799389 4.432822
1.867178 -0.396622 3.842313
-0.324181 1.868321 3.766139
-0.380611 0.969128 1.084074
0.332434 -0.212309 0.330281
-0.184934 1.187303 1.443902
0.203643 -0.770148 0.633417
1.079222 -0.327389 1.271904
-0.274919 -1.721429 3.038899
2.047779 -0.062677 4.197329
-0.438677 -1.443219 2.293266
0.304731 -0.884636 0.873442
-0.712336 -0.222392 0.336881
-0.271866 1.181767 1.470484
0.886202 -0.634106 1.213209
-2.033332 0.327648 4.421883
-1.439047 -0.463998 2.344113
1.230661 -0.003630 1.314339
0.088787 1.883329 3.362347
-0.314134 -0.329161 0.207040
-0.198233 0.646070 0.436712
-1.636217 1.049331 3.778762
1.221109 0.814383 2.134327
1.413133 1.349837 4.398942
-0.174494 -1.330937 1.801841
-1.464173 -0.912864 2.977124
. . .
#lnclude "8losLream.h"
vold Lree() [
lfsLream ln,
ln.open(lorm("baslc.daL")),
lloaL_L x,y,z,
lnL_L nllnes = 0,
1llle *f = new 1llle("baslc.rooL","8LC8LA1L"),
1P1l *h1 = new 1P1l("h1","x dlsLrlbuLlon",100,-4,4),
1nLuple *nLuple = new 1nLuple("nLuple","daLa from
ascll flle","x:y:z"),
whlle (1) [
ln >> x >> y >> z,
lf (!ln.good()) break,
lf (nllnes < 3) prlnLf("x=8f, y=8f, z=8f\n",x,y,z),
h1->llll(x),
nLuple->llll(x,y,z),
nllnes++,
}
prlnLf(" found d polnLs\n",nllnes),
ln.close(),
f->WrlLe(),
}
8ead Lhe 8ooL flle and Lhe 1ree
18rowser L,
nLuple->Scaln(),
n1uple->rlnL(),
WhaL do we learn from Lhls Macro
now to Commands
CreaLe a 8ooL flle ?
1llle *f = new 1llle("baslc.rooL","8LC8LA1L"),
//opLlon: nLW, C8LA1L, 8LC8LA1L, uuA1L, or 8LAu
//8ook and flll hlsLograms and Lrees
//------
f->WrlLe(), //wrlLe Lhe flle
f->Close(), //close Lhe flle
8ook and flll a hlsLogram ?
1P1l *h1 = new 1P1l("h1","x dlsLrlbuLlon",100,-4,4),
/*do some calculaLlon and geL Lhe parameLer LhaL you wanL Lo
flll*/
h1->llll(x),
8ook and flll a Lree ?
1nLuple *nLuple = new 1nLuple("nLuple","daLa from ascll
flle","x:y:z"),
/*do some calculaLlon and geL Lhe parameLer LhaL you wanL Lo
flll*/
nLuple->llll(x,y,z),
Cln1 uaLa Lypes
lnL_L and lloaL_L
(see hLLp://rooL.cern.ch/rooL/hLml/LlsLCf1ypes.hLml )
8ooL uaLa 1ypes
C++ type Size (bytes) ROOT types Size (bytes)
F ORTRAN
analog
(unsigned)char 1
(U)Char_t
1 CHARACTER*1
(unsigned)short
(int)
2
(U)Short_t
2 INTEGER*2
(unsigned)int 2 or 4
(U)Int_t
4 INTEGER*4
(unsigned)long
(int)
4 or 8
(U)Long_t
8 INTEGER*8
float 4
Float_t
4 REAL*4
double 8 (=4)
Double_t
8 REAL*8
long double 16 (= double) REAL*16
Pow Lo Complle a Macro ?
kunn|ng the macro
root [0] .x tree.C or,
root [0] .L tree.C
root [1] tree()
Comp|||ng the macro
root [0] .L tree1.C++
root [1] ma|n()
#lnclude "8losLream.h"
vold Lree()[
lfsLream ln,
ln.open(lorm("baslc.daL")),
lloaL_L x,y,z,
lnL_L nllnes = 0,
1llle *f = new 1llle("baslc.rooL","8LC8LA1L"),
1P1l *h1 = new 1P1l("h1","x dlsLrlbuLlon",100,-4,4),
1nLuple *nLuple = new 1nLuple("nLuple","daLa from ascll flle","x:y:z"),
whlle (1) [
ln >> x >> y >> z,
lf (!ln.good()) break,
lf (nllnes < 3) prlnLf("x=8f, y=8f, z=8f\n",x,y,z),
h1->llll(x),
nLuple->llll(x,y,z),
nllnes++,
}
prlnLf(" found d polnLs\n",nllnes),
ln.close(),
f->WrlLe(),
f->Close(),
}
#lnclude "8losLream.h"
#lnclude "1llle.h"
#lnclude "1P1.h"
#lnclude "1nLuple.h"
lnL maln() [
lfsLream ln,
ln.open(lorm("baslc.daL")),
lloaL_L x,y,z,
lnL_L nllnes = 0,
1llle *f = new 1llle("baslc.rooL","8LC8LA1L"),
1P1l *h1 = new 1P1l("h1","x dlsLrlbuLlon",100,-4,4),
1nLuple *nLuple = new 1nLuple("nLuple","daLa from ascll flle","x:y:z"),
whlle (1) [
ln >> x >> y >> z,
lf (!ln.good()) break,
lf (nllnes < 3) prlnLf("x=8f, y=8f, z=8f\n",x,y,z),
h1->llll(x),
nLuple->llll(x,y,z),
nllnes++,
}
prlnLf(" found d polnLs\n",nllnes),
ln.close(),
f->WrlLe(),
f->Close(),
reLurn 0,
}
PlsLograms ln 8ooL: 1u, 2u and 3u
lloaLs: Max bln conLenL - 7 dlglLs
uouble: Max bln conLenL - 14 dlglLs
1u PlsLograms: 1P1
1P1l *name = new 1P1l("name","1lLle", 8lns, lowesL
bln, hlghesL bln),
Lxample:
1P1l *h1 = new 1P1l("h1","x dlsLrlbuLlon",100,-4,4),
h1->llll(x),
h1->uraw(),
PlsLogram roperLles
Command arameters
h1.CeLMean() Mean
h1.CeL8MS() 8ooL of varlance
h1.CeLMaxlmum(), Maxlmum bln conLenL
h1.CeLMaxlmum8ln(lnL bln_number), locaLlon of maxlmum
h1.CeL8lnCenLer(lnL bln_number), CenLer of bln
h1.CeL8lnConLenL(lnL bln_number), ConLenL of bln
PlsLogram CosmeLlcs
h1.SetMarkerSty|e(),
h1.SeLllllColor(),
PlsLogram cosmeLlcs: Llnes
L|neSty|e
h1->SetL|neSty|e(),
L|neCo|or
h1.SetL|neCo|or(),
1u PlsLogram
Cverlapplng
h1->uraw(),
h2->uraw(same"),
llL ( wlll be covered ln
deLall laLer)
h1->llL(gaus"),
Canvas: an area mapped Lo a wlndow
Command Act|on
c1 = new
1Canvas(c1","1lLle, w, h)
CreaLes a new canvas wlLh wldLh equal Lo w
number of plxels and helghL equal Lo h
number of plxels.
c1->ulvlde(2,2), ulvldes Lhe canvas Lo 4 pads.
c1->cd(3) SelecL Lhe 3
rd
ad
c1->SeLCrldx(),
c1->SeLCrldy(),
c1->SeLLogy(),
?ou can seL grld along x and y axls.
?ou can also seL log scale ploLs.
Canvas: uemo.
rooL [1] c1 = new
1Canvas("c1","1lLle",800,600),
rooL [2] c1->ulvlde(2,2),
rooL [3] c1->cd(1),
rooL [4] h1->uraw(),
rooL [3] c1->cd(2),
rooL [6] h2->uraw(),
rooL [7] c1->cd(3),
rooL [8] h1->SeLLlneColor(2)
rooL [9] h2->SeLLlneColor(4)
rooL [10] h1->uraw(),
rooL [11] h2->uraw("same"),
rooL [12] c1->cd(4),
rooL [13] h1->llL("gaus"),
2u PlsLograms: 1P2
1P2l *name = new 1P2l("name","1lLle", x8lns,
low xbln, up xbln, y8lns, low ybln, up y bln),
Lxample:
1P2l *h12 = new 1P2l("h12","x vs y",100,-
4,4,100, -4, 4),
h12->llll(x,y),
h12->uraw(),
3u PlsLograms: 1P3
1P3l *name = new 1P3l("name","1lLle", x8lns, low xbln, up
xbln, y8lns, low ybln, up ybln, z8lns, low zbln, up zbln),
Lxample:
1P3l *h123 = new 1P3l("h123","x vs y vs z",100,-4,4,100, -4,
4,100,0,20),
h123->llll(x,y,z),
h123->uraw(),
PlsLogram urawlng CpLlons
" SAML": Superlmpose on prevlous plcLure ln Lhe same pad.
" C?L": use cyllndrlcal coordlnaLes.
" CL": use polar coordlnaLes.
" SP": use spherlcal coordlnaLes.
" S8": use pseudo-rapldlLy/phl coordlnaLes.
" LLCC": uraw a lego ploL wlLh hldden llne removal.
" LLCC1": uraw a lego ploL wlLh hldden surface removal.
" LLCC2": uraw a lego ploL uslng colors Lo show Lhe cell conLenLs.
" Su8l": uraw a surface ploL wlLh hldden llne removal.
" Su8l1": uraw a surface ploL wlLh hldden surface removal.
" Su8l2": uraw a surface ploL uslng colors Lo show Lhe cell conLenLs.
" Su8l3": Same as Su8l wlLh a conLour vlew on Lhe Lop.
" Su8l4": uraw a surface ploL uslng Couraud shadlng.
Su8l3": Same as Su8l3 buL only Lhe colored conLour ls drawn.
noLe: lease check chapLer 3 ln user's gulde Lo learn more abouL opLlons.
Craphs
Craphlcs ob[ecL made of Lwo arrays x
and ?, holdlng Lhe x, y coordlnaLes of
n polnLs
Craphs:
lnL_L n = 20,
uouble_L x[n], y[n],
for (lnL_L l=0, l<n, l++)[
x[l] = l*0.1,
y[l] = 10*sln(x[l]+0.2), }
1Craph *gr1 = new 1Craph (n, x, y),
gr1->uraw("AC*"),
Craph urawlng CpLlons
AC*
A8
Al
AL
Superlmpose Lwo Craphs
1Craph *gr1 = new 1Craph(n,x,y),
1Craph *gr2 = new 1Craph(n,x1,y1),
gr1->SeLLlneColor(4),
gr1->uraw("AC*"),
gr2->SeLLlneWldLh(3),
gr2->SeLMarkerSLyle(21),
gr2->SeLLlneColor(2),
gr2->uraw("C"),
Craph wlLh Lrror bar
lloaL_L x[n] = [-.22,.03,.23,.33,.3,.61,.7,.83,.89,.93},
lloaL_L y[n] = [1,2.9,3.6,7.4,9,9.6,8.7,6.3,4.3,1},
lloaL_L ex[n] = [.03,.1,.07,.07,.04,.03,.06,.07,.08,.03},
lloaL_L ey[n] = [.8,.7,.6,.3,.4,.4,.3,.6,.7,.8},
gr = new 1CraphLrrors(n,x,y,ex,ey),
olar Craphs
CeneraLe or calculaLe r" and LheLa"
1Crapholar * gr1 = new 1Crapholar(1000,r,LheLa),
gr1->uraw(),
11ree
Savlng daLa ln a Lable wlLh rows
represenLlng Lhe evenL and columns
represenLlng quanLlLles.
kCC1 1ree
SLore large quanLlLles of same-class ob[ecLs
11ree class ls opLlmlzed Lo reduce dlsk space and enhance
access speed
11ree can hold all klnd of daLa
1nLuple ls a 11ree LhaL ls llmlLed Lo only hold floaLlng-polnL
numbers
lf we do noL use 11ree, we need Lo
read each evenL ln lLs enLlreLy lnLo memory
exLracL Lhe parameLers from Lhe evenL
CompuLe quanLlLles from Lhe same
flll a hlsLogram
CreaLe a 8ooL 11ree/1nLuple
1flle *l = new
1flle(LesL.rooL",8LC8LA1L),
11ree *1 = new 11ree("1","LesL"),
1->8ranch("x",&x,"x/l"),
1->8ranch("y",&y,"x/l"),
1->8ranch("z",&z,"x/l"),
// 8ead/or calculaLe x,y and z
1->llll(),
1->Close(),
l->Close(),
1flle *l = new
1flle(LesL.rooL",8LC8LA1L),
1nLuple *1 = new 1nLuple("nLuple","daLa
from ascll flle","x:y:z"),
// 8ead/or calculaLe x,y and z
1->llll(x,y,z),
1->Close(),
l->Close(),
uraw: 1->uraw(x"),
1->rlnL(), //rlnL Lhe 8ooL
ConLenL
1->Scan(),//scan Lhe 8ooL rows and columns
lay wlLh 8ooL 1ree
Command Act|on
1->rlnL(), rlnLs Lhe conLenL of Lhe Lree
1->Scan(), Scans Lhe rows and columns
1->uraw(x"), uraw a branch of Lree
Pow Lo apply cuLs:
1->uraw(x","x>0"),
1->uraw(x","x>0 && y>0"),
uraw x" when x>0"
uraw x" when boLh x >0 and y >0
1->uraw(y"," ,"same"), Superlmpose y" on x"
1->uraw(y:x"), Make y vs x" 2d scaLLer ploL
1->uraw(z:y:x"), Make z:y:x" 3d ploL
1->uraw(sqrL(x*x+y*y)"), loL calculaLed quanLlLy
1->uraw(x>>h1"), uump a rooL branch Lo a hlsLogram
lay wlLh 8ooL 1ree
CreaLe PlsLogram from 8ooL 1ree
rooL [2] 1P1l *h1 = new 1P1l("h1","hlsL from Lree",30, -4, 4),
rooL [3] 1->uraw("x>>h1"),
Pow Lo deal wlLh number of large 8ooL
flles wlLh same Lrees ?
1Chaln chaln("1"), // name of Lhe Lree ls Lhe
argumenL
chaln.Add("flle1.rooL"),
chaln.Add("flle2.rooL"),
chaln.Add("flle3.rooL"),
?ou can draw x" from all Lhe flles ln Lhe chaln aL Lhe
same Llme
chaln.uraw("x"),
llLLlng PlsLograms ln 8ooL
PlsLograms (1-u,2-u,3-u and roflles) can be flLLed wlLh a
user speclfled funcLlon vla 1P1::llL.
lL uses Mlnul1 as Lhe mlnlmlzaLlon rouLlne for flLLlng,
llLLlng PlsLogram wlLh llL anel
Same as: h1->llL(gaus"),
llLLlng MulLlple Sub 8anges
llLLlng MulLlple Sub 8anges
conLd.
uouble_L par[9],
1l1 *g1 = new 1l1("g1","gaus",83,93),
1l1 *g2 = new 1l1("g2","gaus",98,108),
1l1 *g3 = new 1l1("g3","gaus",110,121),
1l1 *LoLal = new 1l1("LoLal","gaus(0)+gaus(3)+gaus(6)",83,123),
LoLal->SeLLlneColor(2),
h->llL(g1,"8"),
h->llL(g2,"8+"),
h->llL(g3,"8+"),
g1->CeLarameLers(&par[0]),
g2->CeLarameLers(&par[3]),
g3->CeLarameLers(&par[6]),
LoLal->SeLarameLers(par),
h->llL(LoLal,"8+"),
llLLlng wlLh Comblnlng luncLlons
llLLlng wlLh 8oollL
(hLLp://rooflL.sourceforge.neL/)
8oollL packages provlde a LoolklL for modellng Lhe expecLed dlsLrlbuLlon
of evenLs ln a physlcs analysls
Models can be used Lo perform llkellhood flLs, produce ploLs, and generaLe
"Loy MonLe Carlo" samples for varlous sLudles
nexL LecLure
Analysls of Muon CallbraLlon
SlmulaLlon uaLa wlLh 8CC1

Potrebbero piacerti anche