ROOT for R's Interpreter (Package Prototype)
- Currently supports a limited number of classes and each class with a limited number of methods.
- This worked well under linux and supports eventloop that lets you use the graphic system ROOT under R
- It is a demonstration that aims to show how to instantiate objects of ROOT in R, the graphic power of ROOT can be used in R and achieves that could read and write files ROOT objects in this case of TF1 and TH1F classes.
- global objects as gSystem, gROOT, gPad etc .. can be created by importing ROOT in R similarly as in the ROOT environment.
What is not done?
- The method GetRange
? in TF1 for example require a double reference to get value, this is not supported in R but I am developing a system to get this values through specials pointers.
- support for windows and macosx
- A system that wrap all classes with all methods(similar to PyROOT) very difficult in R! :C
ROOTR now support some ROOT's classes with some few methods in R's interpreter using the package ROOT.
To give support for ROOT's classes and it's methods, all was wrapped and exported to R's envoriment through R's submodules.
The supported classes are TF1, TCanvas, TGraph, TRint, TFile and TSystem(a wrap for gSystem object).
NOTE: The R's package require the environment variable ROOTSYS to work.
I write a ROOT package for R and is very simple to install it from sources.
NOTE 1: from repo
https://github.com/omazapa/root in the branch v6-02-00-patches-r-pkg
NOTE 2: compile with option --enable-r see
ROOTR Cling
cd $ROOTSYS/bindings/r/pkg/
R CMD build ROOT
R -e "install.packages('ROOT_1.0.tar.gz')"
rm -rf ROOT_1.0.tar.gz ROOT.Rcheck/
NOTE: or run bash install.sh in $ROOTSYS/bindings/r/pkg/
You can import the R package with require(ROOT) or library(ROOT)
You can import a specific library(Module) using LoadModule
?
require(ROOT)
ROOT::LoadModule('Hist')
Using TF1 from ROOT and plot using R's graphics system.
require(ROOT)
ROOT::LoadModule('Hist')
ROOT::LoadModule('Gpad')
c1 <- new(TCanvas,'c1','dilog',1)
dilog <- new(TF1,'dilog','TMath::DiLog(x)',0,2*pi)
dilog$SetRange(0,2*pi)
dilog$Draw('') #plotting with ROOT's graphics system
c1$Update()
Writting
require(ROOT)
LoadModule('RIO')
LoadModule('Hist')
LoadModule('Gpad')
rfile <- new(TFile,'rfile.root','recreate')
gamma <- new(TF1,'gamma','TMath::Gamma(x)',0.1,2*pi)
gamma$Write('gamma')
hgaus <- new(TH1F,'hgaus','histo from a gaussian', 100, -3, 3)
hgaus$FillRandom('gaus',10000)
hgaus$Write('hgaus')
rfile$Flush()
rfile$Close()
Reading
require(ROOT)
LoadModule('RIO')
LoadModule('Hist')
LoadModule('Gpad')
rfilein <- new(TFile,'rfile.root','read')
hobj <- rfilein$Get('hgaus')
print(hobj)
hgaus <- new(TH1F,hobj)
c2 <- new(TCanvas,'c2','hgaus')
hgaus$Draw()
c2$Update()
gobj <- rfilein$Get('gamma')
print(gobj)
f1 <- new(TF1,gobj)
c1<-new(TCanvas,'c1','gamma')
f1$Draw()
c1$Update()
rfilein$Close('')