Skip to content

Instantly share code, notes, and snippets.

@oschulz
Last active January 13, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oschulz/e471c2e6c7dcd7ea10a5 to your computer and use it in GitHub Desktop.
Save oschulz/e471c2e6c7dcd7ea10a5 to your computer and use it in GitHub Desktop.
Using CERN ROOT GUI features from Julia
# Copyright (C) 2016 Oliver Schulz <oschulz@mpp.mpg.de>
# Licensed under the MIT License: http://opensource.org/licenses/MIT
# Note: Currently only works with ROOT-5, not ROOT-6, due to LLVM clashes
# between Cling and Julia.
using Cxx
using Distributions
incdir = strip(readall(`root-config --incdir`))
libdir = strip(readall(`root-config --libdir`))
addHeaderDir(incdir, kind=C_System)
Libdl.dlopen(joinpath(libdir, "libHist.so"), Libdl.RTLD_GLOBAL)
Libdl.dlopen(joinpath(libdir, "libGui.so"), Libdl.RTLD_GLOBAL)
cxxinclude("TSystem.h")
cxxinclude("TApplication.h")
cxxinclude("TBrowser.h")
cxxinclude("TCanvas.h")
cxxinclude("TH1D.h")
immutable ROOT_GUI
root_app
root_timer
julia_timer
end
_global_root_gui = Nullable{ROOT_GUI}()
ROOT_GUI() = begin
root_app = icxx"""
TApplication *app = new TApplication("", 0, 0);
app->SetReturnFromRun(true);
app;
"""
# Timer is necessary, else ROOT's event loop will usually block for a long
# time (why?). See also the source code of ROOT's TQRootApplication.
root_timer = icxx"""
TTimer *timer = new TTimer(20);
timer->Start(20, false);
timer;
"""
julia_timer = Timer(timer::Timer -> root_gui_cycle(), 0, 0.1)
ROOT_GUI(root_app, root_timer, julia_timer)
end
root_gui_init() = if isnull(_global_root_gui)
global _global_root_gui = Nullable(ROOT_GUI())
nothing
end
root_gui_cycle() = icxx"""
// gApplication->StartIdleing();
gSystem->InnerLoop();
// gApplication->StopIdleing();
"""
typealias TH1D Cxx.CppPtr{Cxx.CxxQualType{Cxx.CppBaseType{:TH1D},(false,false,
false)},(false,false,false)}
fill(hist::TH1D, x) = icxx""" $hist->Fill($x); $hist; """
draw(hist::TH1D) = icxx""" $hist->Draw(); $hist; """
# == Demo =============================================================
root_gui_init()
# tbrowser = icxx""" new TBrowser(); """
hist = icxx""" new TH1D("hist", "Hist", 100, -20, 20); """
dist = Normal(0.0, 5.0)
@time for i in 1:10000
fill(hist, rand(dist))
end
draw(hist)
icxx""" $hist->Fit("gaus"); $hist; """
draw(hist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment