Saving canvas to root file without displaying it

Hi there,

I am writing a root macro which produces a canvas with some circles drawn in it, and saves it to a new root file. The only thing that bothers me is that when I run the macro it displays the canvas.

Is it possible to draw the canvas only in the new root file and not display it?

Thanks a lot!!

run in batch mode
root -b


I would like to give my function a “silent” mode, where it just saves the canvases without displaying them.

Any way to do that not in batch mode ?[/list]

use gROOT->SetBatch(kTRUE/kFALSE)


1 Like

.perfect.thanks !


I fill canvases into a branch in a tree and then I write the tree. I’m just interested in saving the canvases, I don’t want to display them. In the canvas there’re a TGraph instance and its fit function.

When I use

as suggested, effectively there’s no pop up window from any canvas but at the same time then when I load the output tree with the canvas branch, all the canvases exist but they’re empty, i.e. there’re neither graph points nor function in it (on the display). So, the batch mode is not only stopping the canvases from displaying but it also empties the content of the canvas.

A possible reason may be that I save the graph and its fit function into the canvas by using the Draw() command

I looked up and tried to find a drawing option to prevent poping up but I didn’t find anything (perhaps because Draw() is meant to display a plot). Any suggestion? How could I save TGraph, TF1, TH1 instances in a canvas without displaying it nor discarding the content (as it’s happing on kTRUE batch mode)?

Thanks in advance,

P.S.: My ROOT version is 5.30/00.

You need the option A to make sur a graph is drawn.


I encounter the same problem. I create canvases only to paste histograms on them and save them as pdf files. It is disturbing to see tens of canvases popping on and off the screen.
However, I don’t work inside Root, I use g++ to compile my code.
Consequently my compiler does not recognise an object called gROOT.

How can you create ROOT canvases if you are not using ROOT ?
The gROOT object should be define if you are using ROOT libraries…

So, you know how to use #include preprocessor directive, right? Do you include “TCanvas.h” and other things?

Consequently you have to include “TROOT.h” to use gROOT, otherwise, indeed, compiler knows nothing about ROOT or any of its entities.

Thank you tpotchep,
using # include “TROOT.h” works.