Saving a plot in a .ps file without a poping up canvas

Hi,

I have a very cool application to visualize my data that uses the Root GUI classes so that I can visualize the properties of the events stored in my tree.
I would like to include the option of saving plots (not the same ones that I show in the screen) for certain events that I may consider interesting. The problem is that I have to define an extra TCanvas c1 in my code to put these plots so that I can do c1->Print(“file.ps”).
This canvas pops up in the screen and I would like to suppress that, as I have already a window showing the event…
So I would like to know how can I create a TCanvas without it appearing on the screen.

Thanks for your help

Berta

Hi Berta,

[quote]This canvas pops up in the screen and I would like to suppress that, as I have already a window showing the event… [/quote] Is the window where you show the event a TRootEmbeddedCanvas?

If the answer is “yes”, the following code will save the plot without drawing an extra canvas on the screen:

TCanvas *c3 = fEc1->GetCanvas(); c3->Print("file.ps"); where fEc1 is a pointer to TRootEmbeddedCanvas in your application.

If the answer is “no”, it will be good if you can provide a small running example that will help us to understand your needs.

Cheers, Ilka

Hi ,

Sorry for my late reply and thanks for your advide. The problem is that if I try to do what you asked and I get a TRootEmbeddedCanvas, the plot that I want to save in the .ps file apears in the GUI that I have created. But this is not what I was wanting. My problem is that I have a very cool GUI where I can define a canvas “canvas_show” showing some plots from an event and this works fine, but I want to save a different set of plots, and this is why I have to define a new canvas, “canvas_save” that I wouls lkie to not pop up. If you need more information, just let me know.

Cheers

Berta

Hi Berta,

A small running example of your GUI may help.

Thank you, Ilka

Hi Ilka,

Attached you have a very simplied version of the .C file of the PViewer class that we have created.
It has the DoSave method that creates a new .eps file and then a canves called spSaveCanvas where I draw the plots that I want to save in.eps format. The main PViewer method is called from another program by means of:

TApplication theApp(“App”,&argc,argv);
PViewer *mfrm = new PViewer(700,700);
mfrm->SetPStuff(pio,a,e,pab);
theApp.Run();

So as you seen mfm creates a window named “Raw Event Display” where I plot the things of my event that I consider importamt. This window has buttons, and one of them is “Save”.

Let me know if you need more information.

Thanks!!

Berta
example.C (1.85 KB)

Hi Berta,

Thank you for provided code. The batch mode of ROOT allows you to create plots without showing them on the screen, but you cannot have the GUI in this case. So, as a possible solution could be that using your Save button you store the objects you want to have in .eps files in a .root file and in a separate session you run root in batch mode and create all those files. Setting gROOT in batch mode in a middle of an interactive session has side effects on the running GUI.

I have asked our graphics expert for another possible solution and if there is any we will let you know.

Cheers, Ilka

I have just tried the following lines of code:

gROOT->ProcessLine("gROOT->SetBatch()"); TCanvas c; c.Print("c.ps"); gROOT->ProcessLine("gROOT->SetBatch(kFALSE)"); and I see a .ps file was created and it seems the GUI runs with no side effect.

The example you sent is not a running macro and I cannot test this code with it. Please have a try and let me know.

Thank you, Ilka