root - 信州大学...

28
ROOT Which Even Monkeys Can Use Y.Shirasaki, O.Tajima 11 11 4

Upload: vannguyet

Post on 29-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • ROOTWhich Even Monkeys Can Use

    Y.Shirasaki, O.Tajima

    11 11 4

  • 1

    1 Welcome to ROOT 1

    1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    2 Histogram 3

    2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.1.1 1 . . . . . . . . . . . . . . . . . . . . . . . . . 32.1.2 fitting . . . . . . . . . . . . . . . . . . . . . . . . . 52.1.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    3 Graph 7

    3.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.1.1 . . . . . . . . . . . . . . . . . . . . . . . . . 73.1.2 . . . . . . . . . . . . . . . . . . . . . . . 8

    4 Function 10

    4.1 TF1, TF2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    5 Ntuple 13

    5.1 Ntuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135.2 . . . . . . . . . . . . . . . . . . . . . . . . 145.3 TCut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

    6 Graphics 16

    6.1 Terminal Scirpt . . . . . . . . . . . . . . . . . . . . . . . 166.2 Graphics Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    7 18

    7.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

  • 7.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207.5 Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217.6 Global Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    8 Sourcefile 22

    8.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228.2 sourcefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228.3 /.root hist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    9 ROOT 24

    9.1 Makefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    2

  • 1

    1 Welcome to ROOT

    ROOT ROOT

    1.1

    ROOT yasuhiro@s3(100)> setenv ROOTSYS /home/yasuhiro/Rootyasuhiro@s3(101)> set path=( $path ${ROOTSYS}/bin )

    yasuhiro@s3(102)> setenv LD LIBRARY PATH ${ROOTSYS}/lib

    1.2

    ROOT yasuhiro@s3(103)> root ROOT

    *******************************************

    * *

    * W E L C O M E to R O O T *

    * *

    * Version 2.22/09 19 July 1999 *

    * *

    * You are welcome to visit our Web site *

    * http://root.cern.ch *

    * *

    *******************************************

    FreeType Engine v1.1 used to render TrueType fonts.

    CINT/ROOT C/C++ Interpreter version 5.14.9, Jul 17 1999

    Type ? for help. Commands must be C++ statements.

  • 1 Welcome to ROOT 2

    Enclose multiple statements between { }.

    CINT promptroot [0]

    ROOTROOT ROOTroot [?]

    root [?] .qROOT ROOT yasuhiro@s3(104)> root

  • 3

    2 Histogram

    1

    2.1

    2.1.1 1

    TH1

    1.6

    2.0

    0.23

    ...

    root [0] TH1S h1(name, title, 150, -10, 20);

    new TH1S() 1 short int name title 150, -10, 20 150

    -10, 20

    ( h1) (filename.dat)root [1] #include root [2] ifstream data(filename.dat);root [3] double x;root [4] while (data >> x) h1.Fill(x);root [5] data.close();

    root [6] h1.Draw();

    ( 2.1)

  • 2 Histogram 4

    -10 -5 0 5 10 15 200

    500

    1000

    1500

    2000

    2500

    3000

    3500

    nameNent = 77101 Mean = 1.80011RMS = 1.88289

    title nameNent = 77101 Mean = 1.80011RMS = 1.88289

    2.1: TH1

    root [7] h1.Draw(E);

    "E"( 2.2(a))root [8] h1.Draw(L);

    "L"( 2.2(b))root [9] h1.Draw(P);

    "P"( 2.2(c))

    -10 -5 0 5 10 15 200

    500

    1000

    1500

    2000

    2500

    3000

    3500

    nameNent = 77101 Mean = 1.80011RMS = 1.88289

    title nameNent = 77101 Mean = 1.80011RMS = 1.88289

    (a)

    -10 -5 0 5 10 15 200

    500

    1000

    1500

    2000

    2500

    3000

    3500

    nameNent = 77101 Mean = 1.80011RMS = 1.88289

    title nameNent = 77101 Mean = 1.80011RMS = 1.88289

    (b)

    -10 -5 0 5 10 15 200

    500

    1000

    1500

    2000

    2500

    3000

    3500

    nameNent = 77101 Mean = 1.80011RMS = 1.88289

    title nameNent = 77101 Mean = 1.80011RMS = 1.88289

    (c)

    2.2: TH1

  • 2 Histogram 5

    -10 -5 0 5 10 15 200

    500

    1000

    1500

    2000

    2500

    3000

    3500

    nameNent = 77101 Mean = 1.80017RMS = 1.88291

    title nameNent = 77101 Mean = 1.80017RMS = 1.88291

    (a)

    -10 -5 0 5 10 15 200

    500

    1000

    1500

    2000

    2500

    3000

    3500

    nameNent = 77101 Mean = 1.80011RMS = 1.88289Chi2 / ndf = 735.2 / 79Constant= 3289.52 +- 12.2546 Mean = 1.89589 +- 0.00772947 Sigma = 1.85237 +- 0.00164245

    title nameNent = 77101 Mean = 1.80011RMS = 1.88289Chi2 / ndf = 735.2 / 79Constant= 3289.52 +- 12.2546 Mean = 1.89589 +- 0.00772947 Sigma = 1.85237 +- 0.00164245

    (b)

    2.3: fitting

    2.1.2 fitting

    h1 root [10] h1.Fit(gaus);

    Gaussian fitting gaus fitting ( 2.3(a))root [11] h1.Fit(expo);root [12] h1.Fit(pol1);root [13] h1.Fit(pol2);

    expo exponential fittingpol1 pol2 12poln(n) n fitting

    fittingroot [14] gStyle->SetOptFit();

    ( 2.3(b))

    fitting

    fitting

    p1 cos(p2x) + p3 (2.1)

    1 TF1 root [15] TF1 f1(f1, [0]*cos([1]*x)+[2]);

    h1 TH1 fitting

    root [16] f1.SetParameters(10, 1, 10);

  • 2 Histogram 6

    -1 -0.8 -0.6 -0.4 -0.2 -0 0.2 0.4 0.6 0.8 10

    10

    20

    30

    40

    50

    h1Nent = 81 Mean = -1.18061e-16RMS = 0.533035Chi2 / ndf = 148.161 / 37p0 = 19.2534 +- 1.01825 p1 = 3.6241 +- 0.0798794 p2 = 20.6145 +- 0.860159

    h1 h1Nent = 81 Mean = -1.18061e-16RMS = 0.533035Chi2 / ndf = 148.161 / 37p0 = 19.2534 +- 1.01825 p1 = 3.6241 +- 0.0798794 p2 = 20.6145 +- 0.860159

    (a)

    -1 -0.8 -0.6 -0.4 -0.2 -0 0.2 0.4 0.6 0.8 10

    10

    20

    30

    40

    50

    h1Nent = 81 Mean = -1.18061e-16RMS = 0.533035Chi2 / ndf = 511.072 / 37p0 = 6.58279 +- 0.61629 p1 = 10.1434 +- 0.112695 p2 = 9.50536 +- 0.502806

    h1 h1Nent = 81 Mean = -1.18061e-16RMS = 0.533035Chi2 / ndf = 511.072 / 37p0 = 6.58279 +- 0.61629 p1 = 10.1434 +- 0.112695 p2 = 9.50536 +- 0.502806

    (b)

    2.4: cos fitting

    TF1 Function fitting 10, 1, 10

    root [17] h1.Fit(f1);

    fitting 2.4(a) 2.4(b)root [18] f1.SetParameters(10, 10, 10);

    2.1.3

    TAxis SetRange SetRange bin X FindBin bin [-10, 20] TH1S h1 [-5, 5]

    root [0] h1 = new TH1S("name", "title", 150, -10, 20);

    ::root [5] h1->GetXaxis()->SetRange(h1->GetXaxis()->FindBin(-5),

    h1->GetXaxis()->FindBin(5));

    root [6] h1->Draw();

  • 7

    3 Graph

    2

    3.1

    3.1.1

    386.0 7.5384

    406.0 10.7109

    421.0 14.525...

    ...

    (filename.dat) float

    x[10], y[10] 10

    root [0] #include

    root [1] float x[10], y[10];

    root [2] ifstream data("filename.dat");root [3] int index=0;

    root [4] while(!data.eof()) {data >> x[index] >> y[index]; index++;}

    root [5] data.close();

    root [6] graph = new TGraph(index, x, y);

    root [7] graph->Draw("AP");

    AP

    A: P: ()

  • 3 Graph 8

    380 400 420 440 460

    8

    10

    12

    14

    16

    18

    20

    22

    Graph

    3.1: TGraph

    ( 3.1)root [6] graph->Draw(APL);

    "L"( 3.2(a))root [8] graph->Draw(APC);

    "C" ( 3.2(b))

    3.1.2

    x, y x, y x error, y error

    root [9] graph = new TGraphErrors(index, x, y, x_error, y_error);

    root [10] graph->Draw(AP);

    ( 3.3(a))fitting root [11] graph->Fit(pol1);

    1 fitting ( 3.3(b))

  • 3 Graph 9

    380 400 420 440 460

    8

    10

    12

    14

    16

    18

    20

    22

    Graph

    (a)

    380 400 420 440 460

    8

    10

    12

    14

    16

    18

    20

    22

    Graph

    (b)

    3.2: TGraph

    380 400 420 440 460 480

    6

    8

    10

    12

    14

    16

    18

    20

    22

    24

    26

    Graph

    (a)

    380 400 420 440 460 480

    6

    8

    10

    12

    14

    16

    18

    20

    22

    24

    26

    Chi2 / ndf = 0.539918 / 3

    p0 = -62.3724 +- 10.6153

    p1 = 0.18101 +- 0.0268242

    Graph Chi2 / ndf = 0.539918 / 3p0 = -62.3724 +- 10.6153

    p1 = 0.18101 +- 0.0268242

    (b) 1 fitting

    3.3: fitting

  • 10

    4 Function

    ROOT (12)plot

    4.1 TF1, TF2

    C Fortran x n xn 1

    root [0] TF1 f1(f1, x*sin(x)*exp(-0.1*x), -10, 10); f1.Draw();

    f(x) = x sin xe0.1x (4.1)

    plot -10 10 ( 4.1)2root [1] TF2 f2(f2, abs(sin(x)/x)*(cos(y)*y), -6, 6, -6, 6);

    f(x, y) =

    sinxx

    y cos y (4.2)

    plot x -6 6 y -6 6 ( 4.2)(abs() C )

    root [2] f2.Draw(surf);root [3] f2.Draw(cont1);root [4] f2.Draw(lego);

    TH2

    4.2

    fitting TF1 TF2 [0][1][2]

    root [5] TF1 f3("f3", "[0]+[1]*exp(x)", -5, 5);

  • 4 Function 11

    -10 -8 -6 -4 -2 0 2 4 6 8 10

    -10

    -5

    0

    5

    10

    15

    x*sin(x)*exp(-0.1*x)

    4.1: 1f(x) = x sin xe0.1x

    -6-4 -2

    0 24 6

    -6-4

    -20

    24

    6

    -4

    -2

    0

    2

    4

    abs(sin(x)/x)*(cos(y)*y)

    4.2: 2f(x, y) =

    sin xx

    y cos y

  • 4 Function 12

    0

    root [6] f3.SetParamters(1, 2);

    0 1 1 2 fitting

    4.3

    gaussian landau gaus landau

    double gaussian

    f(x) = 100ex2

    2 + 20ex2

    232

    root [7] TF1 f4(f4, gaus(0)+gaus(3), -10, 10);root [8] f4.SetParameters(100, 0, 1, 20, 0, 3);

  • 13

    5 Ntuple

    Ntuplentupledouble tirplequadruple nNtuple

    5.1 Ntuple

    Ntuple Ntupleroot [0] ntuple

    = new TNtuple("name", "title", "" [,]);

    Ntuple:

    x:y:z:energypx:py

    Ntupleroot [1] ifstream data("");

    root [2] float x, y, z, energy;

    root [3] while( data >> x >> y >> z >> energy)

    ntuple->Fill(x, y, z, energy);

    root [4] data.close();

    Ntuplentuple->Print();

    NtupleNtuple Draw

  • 5 Ntuple 14

    root [5] ntuple->Draw("" [,""]" [,""]);

    x x 1Dsqrt(x) x+y/z

    :

    2D3D

    x:y x y 2Dx:y:z xyz 3Dx*2:sqrt(y)

    x4 x>0 && zDraw(sqrt(x):y*2, zDraw(sqrt(x):y*2 >> hist, zDraw(sqrt(x):y*4 >>+ hist, zFit(gaus);

  • 5 Ntuple 15

    5.3 TCut

    TCut

    root [9] TCut positiveCut = "x>0 && y>0 && z>0";

    root [10] ntuple->Draw(sqrt(x):y*2, positiveCut);

    root [11] ntuple->Draw(sqrt(x):z, positiveCut);

    :

    :

    positiveCutenergyCutroot [12] ntuple->Draw(sqrt(x):y*2, positiveCut && energyCut);

  • 16

    6 Graphics

    6.1 Terminal Scirpt

    2 (1,2) (3,4)root [1] TLine l1(1, 2, 3, 4); l1.Draw();

    root [2] TBox b1(1, 2, 3, 4); b1.Draw();

    (1,2) (3,4)root [3] TArrow a1(1, 2, 3, 4); a1.Draw();

    (1,2) (3,4)

    root [4] a1.SetOption(""); a1.Draw();

    TArrow root [5] TArrow a1(1, 2, 3, 4, 0.05, ""); a1.Draw();

    0.05(0.05 ) ( (4,5) 2)root [6] TArc ar1(4, 5, 2); ar1.Draw();

    TEllipsex y TEllipse ( (2,3))root [7] TMarker m1(2, 3, 20); m1.Draw();

    20root [8] TText t1(2, 3, "Text foo bar baz"); t1.Draw();

  • 6 Graphics 17

    6.2 Graphics Editor

    ROOT Edit -> Editor

    ()

    6.3

    Set ... Attributes(... )Apply

  • 18

    7

    7.1

    Canvas Pad Canvas

    root [0] TCanvas c1("Name", "Title");

    root [1] c1.Divide(2, 2);

    x 2 ( 2)y 2 (2 2)( 4) Pad

    root [2] c1.cd(1);

    root [3] TF1 f1("f1", "sin(x)", -2, 2); f1.Draw();

    root [4] c1.cd(4);

    root [5] TF1 f2("f2", "cos(x)", -2, 2); f2.Draw();

    Pad ( 7.1)root [6] c1.cd(3);

    root [7] gPad->Divide(3, 2);

    7.2

    ROOT () TH1F

    root [8] TH1F waku("waku", "Title", 2, 350, 550);

    root [9] waku.SetMinimum(20.0);

    root [10] waku.SetMaximum(110.0);

    root [11] waku.Draw();

  • 7 19

    -2 -1.5 -1 -0.5 0 0.5 1 1.5 2

    -1

    -0.5

    0

    0.5

    1

    sin(x)

    -2 -1.5 -1 -0.5 0 0.5 1 1.5 2

    -0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    cos(x)

    7.1:

    TGraph graph root [12] graph.Draw("LP");

    root [13] c2.Update();

    TPad c2 root [14] c2.SetLogx();

    root [15] c2.SetLogy();

    Pad x y log

    root [16] c2.SetLogx(0);

    root [17] c2.SetLogy(0);

    root [18] c2.SetGridx();

    root [19] c2.SetGridy();

    grid Pad

  • 7 20

    7.3

    ROOT

    root [0] TCanvas c1("c1", "Title", 50, 50, 700, 500);

    root [1] TPaveLabel l1(0.3, 0.91, 0.7, 0.99, "Global Title");

    root [2] l1.Draw();

    root [3] TPad p1("p1", "title", 0, 0, 1, 0.9); p1.Draw(); p1.cd();

    root [4] TF1 f1("f1", "sin(x)", -3, 3); f1.Draw();

    root [5] TPaveText* t1 = gROOT.FindObject("title");

    root [6] t1.SetTextFont(131);

    root [7] t1.SetX1NDC(0.4); t1.SetX2NDC(0.6);

    root [8] t1.Draw();

    x y (axis title) TH1F h1root [9] h1.SetXTitle("Wavelength");

    root [10] h1.SetYTitle("Transparency");

    root [11] h1.GetXaxis()->SetLabelFont(112);

    root [12] h1.GetXaxis()->SetTitleOffset(.5);

    root [13] h1.GetXaxis()->SetTitleSize(.07);

    TitleOffset

    root [14] TText t1(1.8, 0.44, "text"); t1.Draw();

    (1.8, 0.44) text t1 SetTextFont() SetTextSize()

    7.4

    root [15] h1.SetFillColor(2);

    root [16] h1.SetFillStyle(3002); h1.Draw();

    root [17] h1.SetFillColor(2);

    root [18] h1.SetFillStyle(3002); h1.Draw();

    root [19] h2.SetFillColor(4);

    root [20] h2.SetFillStyle(3002); h2.Draw();

  • 7 21

    TH1 TAttLine root [21] h1.SetLineWidth(5); h1.Draw();

    7.5 Graph

    TGraph TAttLineTAttFillTAttMaker

    root [22] graph.SetFillColor(5);

    root [23] graph.SetLineColor(3);

    root [24] graph.SetLineWidth(4);

    root [25] graph.SetMarkerColor(6); graph.Draw("ALP");

    7.6 Global Style

    TH1 TGraph attribute TStyle* gStyle

    root [26] gROOT->SetStyle("Plain");

    7.7

    ROOT tcsh TAB ROOT ( ${ROOTSYS}/tutorials )

    root [27] .x gr

    TABgraph.C TAB

  • 22

    8 Sourcefile

    PostScript EPS, GIF

    8.1

    ROOT TCanvas c1root [10] c1.Print("filename.ps");

    filename.ps

    EPS GIF

    Print filename.eps EPS file-name.gif GIF

    8.2 sourcefile

    ROOTsource file () graph.cc

    #include

    void graph()

    {

    c1 = new TCanvas("c1", "Title", 0, 0, 700, 500);

    c1->SetGridx();

    c1->SetGridy();

    c1->SetFillColor(0);

    c1->Draw();

    waku = new TH1F("waku", "Title", 2, 350, 550);

    waku->SetMinimum(20.0);

  • 8 Sourcefile 23

    waku->SetMaximum(110.0);

    waku->SetDirectory(0);

    waku->SetTitleOffset(1.2);

    waku->SetXTitle("Wavelength");

    waku->SetYTitle("Transparency");

    waku->Draw("A");

    ifstream data("2dhist.dat");

    float x[500], y[500];

    int event = 0;

    while (data >> x[event] >> y[event])

    event++;

    g1 = new TGraph(event, x, y);

    g1->Draw("LP");

    c1->Update();

    c1->Print();

    }

    source file ROOT root [0] .x graph.cc

    source file 2dhist.dat

    8.3 /.root hist

    ROOT.root hist ROOT sourcefile

  • 24

    9 ROOT

    cxx g++ ROOT class library

    9.1 Makefile

    ${ROOTSYS}/test/Makefile} compile compiler option CXXFLAGS link library ROOTLIBS ROOTGLIBS Makefile :

    ROOTLIBS = -L$(ROOTSYS)/lib -lNew -lBase -lCint -lClib -lCont \

    -lFunc -lGraf -lGraf3d -lHist -lHtml -lMatrix -lMeta \

    -lMinuit -lNet -lPostscript -lProof -lTree -lUnix -lZip

    ROOTGLIBS = -lGpad -lGui -lGX11 -lX3d

    GLIBS = $(ROOTLIBS) $(ROOTGLIBS) -lXpm -lX11 -lm -lPW

    CXX = cxx

    CXXFLAGS = -O -nostdnew -D__osf__ -D__alpha -I$(ROOTSYS)/include

    LD = cxx

    LDFLAGS = -g

    TARGET = test

    OBJS = main.o

    all: ${TARGET}

    ${TARGET}: ${OBJS}

    ${CXX} ${CXXFLAGS} -o $@ ${OBJS} ${GLIBS}

    .cc.o:

    ${CXX} ${CXXFLAGS} -c $