How to set TStyle in compiled code

Dear all,

i’m using root libraries in a c++ compiled code to make analysis.
I would like to set the style of canvas, histos, … , using TStyle in the same way i was doing when using macro loaded in ROOT.
Before i wrote something like this in my macro:


where “myStyle” was defined in rootlogon.C

Now i haven’t a root session running and so a gROOT to call,
how can i do ?


You can always use gROOT (be it in interactive or batch mode).
Also, note that rootlogon.C should also be executed by your batch program if the information about its location is available in your $ROOTSYS/etc/system.rootrc or $HOME/.rootrc


Hi Rene,

i’m not sure we are speaking of the same thing: i’m running a c++ code
which includes headers of ROOT classes to create, fill and save histograms to a root file. So i’m not running in batch mode, if for batch mode we are referring to running with root.exe -b -q macro.C
I would like also to save my histograms to eps files directly from my c++ code, i can do it using TCanvas (i guess) but i don’t know if it’s possible to set the style of all canvas and histograms once for all (like i do in interactive or batch mode with gROOT->SetStyle(…)).

Do you think is it possible ?
Many thanks for your comments :slight_smile:


As soon as you use a class from ROOT like TCanvas, etc, you automatically get an instance of the TROOT singleton that is pointed by gROOT, ie you can always use gROOT, even if you do not use root.exe.


To be clear, in a source file :

#include "Style_mystyle.C" … Style_mystyle(); gROOT->SetStyle("mystyle"); gROOT->ForceStyle(); // Not sure if necessary but anywayswhere Style_mystyle.C is the style file (as generated by the style editor, for instance).

[quote](like i do in interactive or batch mode with gROOT->SetStyle(…)). [/quote]For all intent and purpose the ‘batch mode’ is the same as the situation you have with “directly from my c++ code”.