ROOT has a built in C++ interpreter called Cling. One example of using Cling is:
% root root [0] TF1 f1("f1", "sin(x)/x", -10.0, 10.0) root [1] f1.Draw()
Note that the terminating “;” is not required at the end of each line.
Or you can write a ROOT macro, which is a collection of lines.
// file name = myprog1.C void myprog1(){ TCanvas *c1 = new TCanvas("c1" ,"Test" ,0 ,0 ,600 ,400) ; c1->SetGrid( ) ; TF1 *f1 = new TF1("f1", "sin(x)/x", -10.0, 10.0); f1->Draw(); c1->Update(); }
You can execute your macros either by:
% root myprog1.C // or % root root [0] .x myprog1.C
Your macros can also be compiled by adding some “dressing code”.
https://root.cern.ch/root/htmldoc/guides/primer/ROOTPrimer.html#interpretation-and-compilation
// file name = myprog2.C //include some header files, not necessary for Cling. #include "TApplication.h" #include "TROOT.h" #include "TCanvas.h" #include "TF1.h" using namespace std; void myprog2() { TCanvas *c1 = new TCanvas("c1", "Test", 0, 0, 600, 400); c1->SetGrid(); TF1 *f1 = new TF1("f1", "sin(x)/x", -10.0, 10.0); f1->Draw(); c1->Update(); } void StandaloneApplication(int argc, char** argv) { myprog2(); } int main (int argc, char** argv) { TApplication app("ROOT Application", &argc, argv); StandaloneApplication(app.Argc(), app.Argv()); app.Run(); return 0; }
% g++ -o myprog2 myprog2.C `root-config --cflags --libs` ./myprog2
Finally, you can use a set of bindings called PyROOTto interface to Python.
# file name = myprog3.py from ROOT import TCanvas, TF1 c1=TCanvas("c1" ,"Test" ,0 ,0 ,600 ,400) c1.SetGrid () f1=TF1("f1", "sin(x)/x", -10.0, 10.0) f1.Draw() c1.Update() raw_input('Press <ret> to end -> ')
% python myprog3.py