RUBYROOT
The RubyRoot package allows to use most of the potentiality of the C++
ROOT package inside
RUBY . ROOT is the Object Oriented Data
Analysis Framework developed at CERN ,
the European Laboratory for Particle Physics.
The package
- Latest version: v1.0.4 (13 February 2004)
- Download: RubyRoot.tgz
(Thanks to Hitoshi Takahashi for his corrections.)
Terms of agreement
The terms of agreement for this package derive directly from the Ruby and ROOT
licenses and terms of agreement, i.e.:
Similar projects
- Another project to wrap Root classes into Ruby,
not using SWIG (dedicated wrapping) and trying to
implement things a more Ruby-ish way:
ruby-root
Author: Elias Athanasopoulos
- There is the intention to integrate in the near future
languages like Python and Ruby as an alternative to the
standard ROOT interpreter.
Present Requirements
- A Linux environment (tested successfully on Redhat7.3 and RedHat9.0)
- SWIG version 1.3.20 or higher (tested on v1.3.20):
http://www.swig.org
(You may be able to skip this last requirement if you have access to
the public /afs/cern.ch directories. See the "README" file in the
distribution for more details).
Installation, usage and features
- Read carefully the "README" file in the distribution for details.
- Only a (hopefully reasonable) subset of all ROOT classes is included in the distribution. Again, please read the "README" file to find out how to add more classses during installation if necessary.
Example
#!/usr/bin/env ruby
require 'ROOT'
include ROOT
# This line is not required for "batch" scripts
app = TRint.new("My Application",0,[])
chfile = "test.root"
outfile = TFile.new(chfile,"RECREATE","Test histograms")
hist = TH1F.new("hist","Test",100,-5.0,5.0)
gr = ROOT::gRandom
gr.SetSeed(123456)
10000.times do
vargauss = gr.Gaus(0.0,1.0)
hist.Fill(vargauss)
end
hist.Fit "gaus"
outfile.Write
puts "\n Output histograms written in file '%s'" % chfile
# This line is not required for "batch" scripts
app.Run
- Few more examples can be found in the "examples/" subdirectory.
Good to know
and then run it at the end with "app.Run" (see example above).
- Constants in Ruby begin with a capital letter. This means that you must use
"KRed, KBlue, ...", and not "kRed, kBlue, ...". "kFALSE" and "kTRUE" are
not constants, but wrapped as global methods, so they should be accessed
as "ROOT::kFALSE" and "ROOT::kTRUE", respectively. You can also use
Ruby "false" and "true", but watch carefully the cases in which ROOT
expects and integer, and not a boolean value ("0" is "true" in Ruby).
- ROOT methods destroying objects, like "my_file.Close" will give errors.
Ruby applies its automatic procedures to destroy them and, in this
case, will find out that there is no object to destroy.
- Whenever an Int_t, Float_t or Double_t argument is passed by reference, it
is assumed to be INPUT/OUTPUT. From the practical point of view:
gr = ROOT::gRandom
xin, yin = 0.0, 0.0
xout, yout = gr.Rannor(xin,yin)
instead of the C++ instructions:
TRandom* gr = gRandom;
Float_t xout = 0.0;
Float_t yout = 0.0;
gr.Rannor(xout,yout);
which will overwrite the original null values.
- You can use Ruby arrays whenever ROOT expects a C-int or a C-float
array as input. Example:
a = [0.0, 1.0, 2.0]
b = [-1.0, 0.0, 1.0]
my_graph = TGraph.new(3, a, b)
for the C++ instructions:
int found;
my_tree->SetBranchStatus("my_branch",1,found);
if (found) { ...
To do
- Not all the Root methods are accessible.
In particular, dealing with some pointers requires further thinking.
- Create a class equivalent to "TRint", to allow a natural interactive analysis inside "irb". See "examples/example3.rb" for a possible approach at present.
- Export the procedure to non-Linux platforms.
Juan Alcaraz,
Last update: March 4, 2004