2.0 安装与使用

欧洲核子研究中心(CERN)成立于 1954 年 9 月 29 日,总部位于瑞士日内瓦的法瑞边境上,欧洲核子研究中心拥有世界上最大的粒子物理学实验室,也是万维网的发源地。CERN 现在已经聘用大约三千名的全职员工。并有来自 80 个国籍的大约 6500 位科学家和工程师,代表 500 余所大学机构,在 CERN 进行试验。这大约占了世界上的粒子物理学圈子的一半。

由 CERN 开发的科学分析 PB 级数据的强大工具 ROOT 已经成为最著名的开源数据分析框架之一,支持 C语言与 python语言,用户可通过ROOT官网查阅手册来学习使用方法。

ROOT 支持全平台,Mac 上安装 ROOT 请使用 homebrew,其他操作系统安装方式参考官方说明

ROOT 有命令行模式、脚本模式、图形界面模式。但是经常使用图形界面会使用户很快遗忘各种类和成员函数的名称和使用方法,这在使用脚本模式处理大量数据时是非常不利的。

基本命令

安装 ROOT 后,在终端中输入root打开,并用.q命令退出:

[zhangzh@node01 ~]$ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.22/02                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Aug 17 2020, 12:46:52                 |
  | From tags/v6-22-02@v6-22-02                                      |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------
root [0] .q
[zhangzh@node01 ~]$ 

ROOT 命令行中的元命令都以.开头:

.L <文件名>                // 加载给定的文件或库
.(x|X) <文件名>[args]      // 与 .L 相同并运行带有参数的函数
.U <文件名>                // 卸载给定的文件
.I [path]                 // 显示包含路径
.help                     // 显示此信息
.q                        // 退出程序
.pwd                      // 显示当前目录、pad 和样式
.ls                       // 列出当前目录的内容
.which [file]             // 显示宏文件的路径
.help Class               // 打开该类的参考指南
.h
.help Class::Member       // 打开函数/成员的参考指南

ROOT 也和其他 Linux 命令一样有参数可选,如:

-l忽略版本信息直接进入 ROOT。

-q在执行完脚本后自动退出到 shell。

[zhangzh@node01 ~]$ root -l -q filename
waiting...

其他命令:

[zhangzh@node01 latitude]$ root --help

usage: root [-b B] [-x X] [-e E] [-n N] [-t T] [-q Q] [-l L] [-a A] [-config CONFIG] [-memstat MEMSTAT]
            [-h HELP] [--version VERSION] [--notebook NOTEBOOK] [--web WEB] [--web=<browser> WEB=<BROWSER>]
            [dir] [file:data.root] [file1.C...fileN.C]

OPTIONS:
  -b                             Run in batch mode without graphics
  -x                             Exit on exceptions
  -e                             Execute the command passed between single quotes
  -n                             Do not execute logon and logoff macros as specified in .rootrc
  -t                             Enable thread-safety and implicit multi-threading (IMT)
  -q                             Exit after processing command line macro files
  -l                             Do not show the ROOT banner
  -a                             Show the ROOT splash screen
  -config                        print ./configure options
  -memstat                       run with memory usage monitoring
  -h, -?, --help                 Show summary of options
  --version                      Show the ROOT version
  --notebook                     Execute ROOT notebook
  --web                          Display graphics in a default web browser
  --web=<browser>                Display graphics in specified web browser
  [dir]                          if dir is a valid directory cd to it before executing
  [file:data.root]               Open the ROOT file data.root
  [file1.C...fileN.C]            Execute the the ROOT macro file1.C ... fileN.C

终端中输入root filename打开 root 格式文件或脚本/宏,并于 ROOT 中查看或运行。ROOT 中同样可以使用系统命令,命令前添加.!。e.g.

[zhangzh@node01 orbitAnisotropyLatitude]$ rl
root [0] .!pwd
/home/users/z/zhangzh/grb/orbitAnisotropyLatitude
root [1] .!ls
addFileAndReadMC.c	       hpatimer_moon_sun_radec_1.cc	  Moon.c
addFileAndReadTimesSr550.c     hpatimer_moon_sun_radec_1.exe	  myMacro.log
root [2] .!ls -l
总用量 459072292
-rw-r--r-- 1 zhangzh ybj        1159 4月   8 10:10 addFileAndReadMC.c
-rw-r--r-- 1 zhangzh ybj        4736 4月   7 00:56 addFileAndReadTimesSr550.c
-rw-r--r-- 1 zhangzh ybj        2528 3月  19 22:14 hpatimer_moon_sun_radec_1.cc
-rwxr-xr-x 1 zhangzh ybj       66744 3月  19 22:17 hpatimer_moon_sun_radec_1.exe
-rw-r--r-- 1 zhangzh ybj        9051 3月  19 22:10 Moon.c
-rw-r--r-- 1 zhangzh ybj         111 3月  27 22:04 myMacro.log
root [3]

基本概念

树 TTree

Tree 是 ROOT 中的一个重要概念,它是一种用 Branch 存储和处理大量结构化数据的数据结构。TTree 可以看作是一个表格,其中每一行代表一个事件或数据点,每一列代表一个变量或数据字段。

它是 ROOT 数据分析和可视化的基础,与其他 ROOT 库中的功能和工具相结合,进行数据分析、表达和模拟等操作。在命令行模式中使用.ls和 Tree 的成员函数查看 Tree 的结构和 Branch:

->Show()   # 使用该命令可以指定查看某个编号下的branch,例如Show(24)
           # 注意:展示的数据只会保留6位有效数字,在root中仍以本身的数值存储
->Print()  # 依次打印出每个branch的数据
->Scan()   # 每次扫描25行tree中的数据
           # ->用于通过指针访问对象的成员,这三个函数都是Tree这个类的成员函数

枝 TBranch

TBranch 是 TTree 中存储数据的基本单位,每个分支对应 TTree 中的一列数据。

每个分支都有一个名称(Branch Name),用于唯一标识该分支。分支还有一个数据类型(Data Type),用于指定存储在该分支中的数据类型,如整数、浮点数、字符串等。此外,分支还可以有一个或多个维度(Dimension),用于存储数组类型的数据。

创建和使用分支的步骤:
  • 创建分支:使用 TTree 的Branch()创建一个分支,并指定分支的名称、数据类型和维度等信息。例如,可以创建一个名为energy的分支,存储浮点数类型的能量数据。

  • 填充数据:通过函数Fill()将数据填充到分支中。每次调用Fill(),都会将当前的变量值添加到分支中,并进入下一个事件或数据点。

  • 读取数据:使用 TTree 的SetBranchAddress()设置分支的地址,以便在读取数据时将数据存储到指定的变量中。通过调用GetEntry()读取 TTree 中的事件或数据点,并将数据填充到指定的变量中。

通过使用分支,可以将大量的结构化数据存储在 TTree 中,并以高效的方式进行读写和访问。分支的概念使得数据的存储和处理更加灵活和高效,适用于大型数据集的存储和分析。

E.g. 查看 Branch 的几种方法
[zhangzh@node01 cernstaff]$ rl cernstaff.root 
root [0] 
Attaching file cernstaff.root as _file0...
(TFile *) 0x265e9c0
root [1] .ls
TFile**		cernstaff.root	
 TFile*		cernstaff.root	
  KEY: TTree	T;1	CERN 1988 staff data    // perform Tree or Branch name
root [2] T->Scan()
************************************************************************************************************
*    Row   * Category. * Flag.Flag *   Age.Age * Service.S * Children. * Grade.Gra * Step.Step * Hrweek.Hr *
************************************************************************************************************
*        0 *       202 *        15 *        58 *        28 *         0 *        10 *        13 *        40 *
*        1 *       530 *        15 *        63 *        33 *         0 *         9 *        13 *        40 *
*        2 *       316 *        15 *        56 *        31 *         2 *         9 *        13 *        40 *
*        3 *       361 *        15 *        61 *        35 *         0 *         9 *         7 *        40 *
*        4 *       302 *        15 *        52 *        24 *         2 *         9 *         8 *        40 *
*        5 *       303 *        15 *        60 *        33 *         0 *         7 *        13 *        40 *
*        6 *       302 *        15 *        53 *        25 *         1 *         9 *         9 *        40 *
*        7 *       361 *        15 *        60 *        32 *         1 *         8 *         5 *        40 *
*        8 *       340 *        15 *        51 *        28 *         0 *         8 *        13 *        40 *
*        9 *       361 *        15 *        56 *        32 *         1 *         7 *        13 *        40 *
*       10 *       361 *        15 *        51 *        29 *         0 *         7 *        13 *        40 *
*       11 *       303 *        15 *        54 *        31 *         2 *         8 *        13 *        40 *
*       12 *       302 *        15 *        54 *        29 *         0 *         7 *        13 *        40 *
*       13 *       300 *        15 *        46 *        25 *         0 *         8 *         6 *        40 *
*       14 *       361 *        15 *        54 *        26 *         1 *         7 *        13 *        40 *
*       15 *       361 *        15 *        57 *        29 *         0 *         7 *        13 *        40 *
*       16 *       316 *        11 *        55 *        28 *         0 *         8 *        11 *        40 *
*       17 *       303 *        15 *        55 *        26 *         1 *         7 *        13 *        40 *
*       18 *       361 *        15 *        57 *        29 *         1 *         7 *         8 *        40 *
*       19 *       361 *        15 *        51 *        28 *         2 *         7 *        13 *        40 *
*       20 *       419 *        13 *        54 *        29 *         0 *         5 *        13 *        40 *
*       21 *       202 *        15 *        57 *        26 *         1 *        12 *        13 *        40 *
*       22 *       304 *        15 *        63 *        29 *         1 *        10 *        13 *        40 *
*       23 *       204 *        15 *        56 *        27 *         0 *        11 *         9 *        40 *
*       24 *       204 *        15 *        49 *        27 *         0 *         9 *         9 *        40 *
Type <CR> to continue or q to quit ==> q
************************************************************************************************************
(long long) 25
root [3] T->Show(24)
======> EVENT:24
 Category        = 204
 Flag            = 15
 Age             = 49
 Service         = 27
 Children        = 0
 Grade           = 9
 Step            = 9
 Hrweek          = 40
 Cost            = 0
 Division        = 
 Nation          = 
 root [4] T->Print()
******************************************************************************
*Tree    :T         : CERN 1988 staff data                                   *
*Entries :     3354 : Total =          175563 bytes  File  Size =      47246 *
*        :          : Tree compression factor =   3.69                       *
******************************************************************************
*Br    0 :Category  : Category/I                                             *
*Entries :     3354 : Total  Size=      13989 bytes  File Size  =       4919 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   2.74     *
*............................................................................*
*Br    1 :Flag      : Flag/i                                                 *
*Entries :     3354 : Total  Size=      13969 bytes  File Size  =       2165 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   6.23     *
*............................................................................*
*Br    2 :Age       : Age/I                                                  *
*Entries :     3354 : Total  Size=      13964 bytes  File Size  =       3489 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   3.86     *
*............................................................................*
*Br    3 :Service   : Service/I                                              *
*Entries :     3354 : Total  Size=      13984 bytes  File Size  =       2214 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   6.09     *
*............................................................................*
*Br    4 :Children  : Children/I                                             *
*Entries :     3354 : Total  Size=      13989 bytes  File Size  =       2110 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   6.39     *
*............................................................................*
*Br    5 :Grade     : Grade/I                                                *
*Entries :     3354 : Total  Size=      13974 bytes  File Size  =       2676 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   5.04     *
*............................................................................*
*Br    6 :Step      : Step/I                                                 *
*Entries :     3354 : Total  Size=      13969 bytes  File Size  =       2889 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   4.67     *
*............................................................................*
*Br    7 :Hrweek    : Hrweek/I                                               *
*Entries :     3354 : Total  Size=      13979 bytes  File Size  =        642 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=  21.01     *
*............................................................................*
*Br    8 :Cost      : Cost/I                                                 *
*Entries :     3354 : Total  Size=      13965 bytes  File Size  =       6939 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.94     *
*............................................................................*
*Br    9 :Division  : Division/C                                             *
*Entries :     3354 : Total  Size=      25238 bytes  File Size  =      10048 *
*Baskets :        2 : Basket Size=      32000 bytes  Compression=   2.46     *
*............................................................................*
*Br   10 :Nation    : Nation/C                                               *
*Entries :     3354 : Total  Size=      24123 bytes  File Size  =       7928 *
*Baskets :        2 : Basket Size=      32000 bytes  Compression=   2.98     *
*............................................................................*

画布 Canvas

画布是用来承载绘图的窗口或者页面。在画布上可以绘制一个或多个图形,并设置标题、坐标轴、图例等元素。画布可以个性化,如调整坐标轴的形式、范围、标题名称、轴名称等等:

Canvas 类的成员函数
root [0] TCanvas *c1 = new TCanvas("c1","c1",600,600)
(TCanvas *) 0x14d73e360
root [1] c1->
AbsCoordinates
AbsPixeltoX
AbsPixeltoXY
AbsPixeltoY
AbstractMethod
AddExec
AppendPad
AreAllSignalsBlocked
AreSignalsBlocked
AutoExec
BlockAllSignals
BlockSignals
Browse
BuildLegend
ChangedBy
CheckedHash
Class
ClassName
Class_Name
Class_Version
Clear
ClearPadSave
Cleared
Clip
ClipPolygon
ClippingCode
Clone
Close
CloseToolTip
Closed
CollectClassSignalLists
Compare
Connect
Connected
Constructor
Copy
CopyPixmap
CopyPixmaps
CreateToolTip
DeclFileLine
DeclFileName
Delete
DeleteCanvasPainter
DeleteExec
DeleteToolTip
Destroyed
Destructor
Dictionary
Disconnect
DisconnectWidget
Disconnected
DistancetoLine
DistancetoPrimitive
Divide
DivideSquare
Draw
DrawClass
DrawClassObject
DrawClone
DrawClonePad
DrawCollideGrid
DrawColorTable
DrawCrosshair
DrawFrame
Dump
EditorBar
EmbedInto
Emit
EnterLeave
Error
EventPave
Execute
ExecuteEvent
ExecuteEventAxis
Fatal
FeedbackMode
FindObject
Flush
ForceUpdate
GetAbsHNDC
GetAbsWNDC
GetAbsXlowNDC
GetAbsYlowNDC
GetAfile
GetAspectRatio
GetAstat
GetAutoExec
GetBBox
GetBBoxCenter
GetBorderMode
GetBorderSize
GetBottomMargin
GetCanvas
GetCanvasID
GetCanvasImp
GetCanvasPainter
GetCanvasPar
GetClickSelected
GetClickSelectedPad
GetContextMenu
GetCrosshair
GetDISPLAY
GetDoubleBuffer
GetDrawOption
GetDtorOnly
GetEvent
GetEventX
GetEventY
GetFillColor
GetFillStyle
GetFrame
GetFrameBorderMode
GetFrameBorderSize
GetFrameFillColor
GetFrameFillStyle
GetFrameLineColor
GetFrameLineStyle
GetFrameLineWidth
GetGLDevice
GetGridx
GetGridy
GetHNDC
GetHighLightColor
GetIconName
GetLeftMargin
GetLineColor
GetLineStyle
GetLineWidth
GetListOfClassSignals
GetListOfConnections
GetListOfExecs
GetListOfPrimitives
GetListOfSignals
GetLogx
GetLogy
GetLogz
GetMaxPickDistance
GetMother
GetName
GetNumber
GetObjectInfo
GetObjectStat
GetOption
GetPad
GetPadPaint
GetPadPar
GetPadPointer
GetPadSave
GetPainter
GetPhi
GetPixmapID
GetPrimitive
GetRange
GetRangeAxis
GetRightMargin
GetSelected
GetSelectedOpt
GetSelectedPad
GetSelectedX
GetSelectedY
GetShowEditor
GetShowEventStatus
GetShowToolBar
GetShowToolTips
GetTheta
GetTickx
GetTicky
GetTitle
GetTopMargin
GetUniqueID
GetUxmax
GetUxmin
GetUymax
GetUymin
GetView
GetView3D
GetViewer3D
GetVirtCanvas
GetWNDC
GetWh
GetWindowHeight
GetWindowTopX
GetWindowTopY
GetWindowWidth
GetWw
GetX1
GetX2
GetXfile
GetXlowNDC
GetXsizeReal
GetXsizeUser
GetXstat
GetY1
GetY2
GetYfile
GetYlowNDC
GetYsizeReal
GetYsizeUser
GetYstat
HandleInput
HandleTimer
HasConnection
HasCrosshair
HasFixedAspectRatio
HasInconsistentHash
HasMenuBar
HasViewer3D
Hash
HighLight
HighPriority
HighlightConnect
Highlighted
Iconify
ImplFileLine
ImplFileName
IncrementPaletteColor
Info
InheritsFrom
Inspect
InvertBit
IsA
IsBatch
IsBeingResized
IsDestructed
IsDrawn
IsEditable
IsEqual
IsFolder
IsGrayscale
IsModified
IsOnHeap
IsRetained
IsSortable
IsTransparent
IsVertical
IsWeb
IsZombie
LowPriority
MakeDefCanvas
MayNotUse
Message
Modified
Modify
MoveOpaque
NextPaletteColor
Notify
NumberOfConnections
NumberOfSignals
Obsolete
OpaqueMoving
OpaqueResizing
Pad
PadInHighlightMode
PadInSelectionMode
PadtoX
PadtoY
Paint
PaintBorderPS
PaintBox
PaintFillArea
PaintFillAreaHatches
PaintFillAreaNDC
PaintHatches
PaintLine
PaintLine3D
PaintLineNDC
PaintModified
PaintPadFrame
PaintPolyLine
PaintPolyLine3D
PaintPolyLineNDC
PaintPolyMarker
PaintText
PaintTextNDC
Pick
Picked
PixeltoX
PixeltoXY
PixeltoY
PlaceBox
Pop
PopTopLevelSelectable
Print
ProcessedEvent
PushSelectableObject
PushTopLevelSelectable
RaiseWindow
Range
RangeAxis
RangeAxisChanged
RangeChanged
Read
RecordLatex
RecordPave
RecursiveRemove
RedrawAxis
ReleaseViewer3D
ResetAttFill
ResetAttLine
ResetAttPad
ResetBit
ResetDrawn
ResetToolTip
ResetView3D
Resize
ResizeOpaque
ResizePad
Resized
SaveAs
SaveFillAttributes
SaveLineAttributes
SavePrimitive
SaveSource
Selected
SetAfile
SetAstat
SetAttFillPS
SetAttLinePS
SetAttMarkerPS
SetAttTextPS
SetBBoxCenter
SetBBoxCenterX
SetBBoxCenterY
SetBBoxX1
SetBBoxX2
SetBBoxY1
SetBBoxY2
SetBatch
SetBit
SetBorderMode
SetBorderSize
SetBottomMargin
SetCanvas
SetCanvasImp
SetCanvasSize
SetClickSelected
SetClickSelectedPad
SetCopyGLDevice
SetCrosshair
SetCursor
SetDoubleBuffer
SetDrawOption
SetDtorOnly
SetEditable
SetFillAttributes
SetFillColor
SetFillColorAlpha
SetFillStyle
SetFixedAspectRatio
SetFolder
SetFrameBorderMode
SetFrameBorderSize
SetFrameFillColor
SetFrameFillStyle
SetFrameLineColor
SetFrameLineStyle
SetFrameLineWidth
SetGLDevice
SetGrayscale
SetGrid
SetGridx
SetGridy
SetHighLightColor
SetLeftMargin
SetLineAttributes
SetLineColor
SetLineColorAlpha
SetLineStyle
SetLineWidth
SetLogx
SetLogy
SetLogz
SetMargin
SetMaxPickDistance
SetName
SetNumber
SetObjectStat
SetPad
SetPadSave
SetPhi
SetRealAspectRatio
SetRetained
SetRightMargin
SetSelected
SetSelectedPad
SetSupportGL
SetTheta
SetTicks
SetTickx
SetTicky
SetTitle
SetToolTipText
SetTopMargin
SetUniqueID
SetVertical
SetView
SetViewer3D
SetWindowPosition
SetWindowSize
SetXfile
SetXstat
SetYfile
SetYstat
Show
ShowGuidelines
ShowMembers
Size
StartEditing
Streamer
StreamerNVirtual
SupportAlpha
SysError
TAttBBox2D
TAttFill
TAttLine
TAttPad
TCanvas
TObject
TPad
TQObject
TVirtualPad
TestBit
TestBits
ToggleAutoExec
ToggleEditor
ToggleEventStatus
ToggleToolBar
ToggleToolTips
UnZoomed
Update
UseCurrentStyle
UseGL
UtoAbsPixel
UtoPixel
VtoAbsPixel
VtoPixel
WaitPrimitive
Warning
Write
XYtoAbsPixel
XYtoPixel
XtoAbsPixel
XtoPad
XtoPixel
YtoAbsPixel
YtoPad
YtoPixel
cd
kAutoExec
kBitMask
kCanDelete
kCannotMove
kCannotPick
kClearAfterCR
kClipFrame
kFraming
kHasUUID
kHori
kInconsistent
kInvalidObject
kIsGrayscale
kIsOnHeap
kIsReferenced
kMenuBar
kMoveOpaque
kMustCleanup
kNoContextMenu
kNotDeleted
kObjInCanvas
kOverwrite
kPrintingPS
kResizeOpaque
kShowEditor
kShowEventStatus
kShowToolBar
kShowToolTips
kSingleKey
kWriteDelete
kZombie
ls
operator delete
operator delete[]
operator new
operator new[]
operator=
x3d

画板 Pad

画板是画布上的一个独立的绘图区域,可以在上面绘制图形、直方图、函数等。画布上可以包含一个或多个图形区域,每个图形区域可以有自己的坐标轴、标题等属性。通过在画布上创建多个图形区域,可以实现多图并列,或绘制复杂的布局。

函数命名规范

  • 根类T 开头,如:TLineTTree

  • 数据成员f 开头,如:fTree

  • 成员函数以首大写字母开头,如:Loop()

  • 常数k 开头,如:kInitialSizekRed

  • 全局变量g开头,后跟大写字母,如:gEnv。 通过全局gROOT,可以访问TROOT的单个实例。例如要查找名为c1的画布,可以: gROOT->GetListOfCanvases()->FindObject("c1")

  • 获取和设置函数以首字母大写的GetSet开头,如:SetLast()GetFirst()

多命令行模式

ROOT 中也能执行多行复杂指令,执行多行命令请先键入{。e.g.

root [0] {
root [1]   int j = 0;
root [2]   for (int i = 0; i < 3; i++)
root [3]   {
root [4]     j = j + i;
root [5]     std::cout << "i = " << i << ", j = " << j << std::endl;
root [6]   }
root [7] }
i = 0, j = 0
i = 1, j = 1
i = 2, j = 3

宏模式

ROOT 宏的名称和保存宏的文件名必须匹配。e.g.

  • 在文本编辑器中创建一个新文件:

      void MacroName() {
         ...

         your lines of C++ code
         code line ends with ;
         ...
      }
  • 保存文件 ROOT 宏,使用宏名称作为文件名:MacroName.c

  • 执行宏:

  1. 在系统提示符处执行 ROOT 宏

$ root MacroName.c
  1. 在 ROOT 提示符处执行宏

root [0] .x MacroName.c
  1. 从 ROOT 会话中加载宏,然后调用函数

root [0] .L MacroName.c
root [1] MacroName()

参数传递

当脚本需要传入参数时,需要将脚本名和参数使用引号(引号包括单引和双引)、参数用括号包裹:

$ root 'filename(parameter)'

对于包含空格或者特殊字符的参数parameter,建议使用双引号包裹:

$ root 'filename("parameter1",parameter2,...)'

后台运行

有时脚本filename的运行时间可能会长达几个小时或者几天,为避免终端断连后程序退出,ROOT 支持设置后台运行,并保存输出日志log.out

$ root filename &> log.out &

批量处理模式

批量模式意味着图片将不会以 GUI 的窗口形式出现,而是在后台完成一系列操作,这非常适用于长时间大作业的处理,打开方式是在宏中添加语句:gROOT->SetBatch(kTRUE)

在脚本/宏中使用 ROOT 成员函数

在编译语句中添加root库:

g++ `root-config --cflags --libs` sample.cxx -o simple
# 设置r++=g++ `root-config --cflags --libs`后, 可使用r++ sample.cxx -o simple

图形界面模式

ROOT 库提供图形界面工具,称为 ROOT GUI,用于交互式地进行数据分析、绘图和可视化,使用户可以通过鼠标和键盘与 ROOT 库进行交互。除了菜单,你可以以图形化查看 tree 的结构,还可以在 canvas 上右击任何位置(轴、坐标点、画布、标题等)来查看和更改它们的成员函数。打开 UI 界面的命令是:

root [1] TBrowser treename    # 同样可以通过->StartViewer()成员函数打开图形界面 


参考

ROOT 官方手册

ROOT 程序例子:ls $ROOTSYS/tutorials/

ROOT 在线手册

ROOT 学习视频

Last updated