Save TMVA plot in png

Dear experts,
I’m using ROOT TMVA and the plots are save in eps. How can I save then in png?
Regards

Dear experts,
any idea?
Regards

Be more explicit. What graph class are you exactly using? Which function do you use for saving the canvas?

Hi ferhue,

I’m using the TMVAClassification function in my own macro. I followed the tutorial TMVAClassification function.

Regards

Do you mean this?
root.cern.ch/doc/v606/TMVAClass … ource.html

Do you call the function Print or SaveAs at some point by yourself?

Anyway, just take a look at line 234 of:
root.cern.ch/doc/v606/tmvaglob_8cxx_source.html

I guess that modifying the variable gConfig().fVariablePlotting.fUsePaperStyle would do what you ask for. Or just TMVA::UsePaperStyle if it is an older version.

The Canvas methods Print or SaveAS can generate many file output formats including png.

Dear experts,
thank you for your answers. May I give you more information on what I’m doing. Indeed, I’m using the code in cc in root version 6. When it finish, I call the “TMVA::TMVAGui(“TMVA.root”)”. After I pushed the button, it creates plots in eps format in a plot directory. Now I want the plots to be in png (or pfd…), do you know how I can configure for that?
Regards
main.cc (4.29 KB)

Did you try to call this before pushing the button or opening the GUI:

TMVA::gConfig().fVariablePlotting.fUsePaperStyle=0

See line 230 of root.cern.ch/doc/v606/tmvaglob_8cxx_source.html

Hi ferhue,

if I run successively [1], then it works, but if I put it in my code, it does not work. The line you mentioned says to modify a code but as this is root TMVA, I do not see how to do that?

Regards

[1]
$ root -l
root [0] TMVA::gConfig().fVariablePlotting.fUsePaperStyle=0
(Bool_t) false
root [1] TMVA::TMVAGui(“mt/TMVA.root”)

If I understand correctly, your program just generates a file TMVA.root

Then you close ROOT. When you open the exported file with the TMVAGUI, you need to set the fUsePaperStyle variable to 0.

If you do not want to this every time, you can add this line in your rootlogon.C

Otherwise, you can modify the macro tmvaglob.cxx so that it always exports to png no matter the value of fUsePaperStyle. See in the sources /opt/root6_src/tmva/tmvagui/src/tmvaglob.cxx
root.cern.ch/doc/v606/tmvaglob_8cxx_source.html

                  cout << "--- --------------------------------------------------------------------" << endl;
  235          cout << "--- If you want to save the image as eps, gif or png, please comment out " << endl;
  236          cout << "--- the corresponding lines (line no. 239-241) in tmvaglob.C" << endl;
  237          cout << "--- --------------------------------------------------------------------" << endl;

Hi ferhue,

ok, and where can I find the file “tmvaglob.cxx”? when I do:
ls $ROOTSYS/tutorials/tmva/
I have [1] and “find $ROOTSYS tmvaglob.cxx” says "find: `tmvaglob.cxx’: No such file or directory"
Am I looking in the right directory?
Regards

[1]
-rw-r–r-- 1 cvmfs 1.9K May 31 21:45 tmva_logo.gif
-rw-r–r-- 1 cvmfs 242 May 31 21:45 sigmoid-small.png
-rw-r–r-- 1 cvmfs 1.1K May 31 21:45 makefile
-rw-r–r-- 1 cvmfs 183 May 31 21:45 line-small.png
-rw-r–r-- 1 cvmfs 60K May 31 21:45 createData.C
-rw-r–r-- 1 cvmfs 7.0K May 31 21:45 TMVARegressionApplication.C
-rw-r–r-- 1 cvmfs 14K May 31 21:45 TMVARegression.C
-rw-r–r-- 1 cvmfs 17K May 31 21:45 TMVAMultipleBackgroundExample.C
-rw-r–r-- 1 cvmfs 6.5K May 31 21:45 TMVAMulticlassApplication.C
-rw-r–r-- 1 cvmfs 6.3K May 31 21:45 TMVAMulticlass.C
-rw-r–r-- 1 cvmfs 4.0K May 31 21:45 TMVAGAexample2.C
-rw-r–r-- 1 cvmfs 6.2K May 31 21:45 TMVAGAexample.C
-rw-r–r-- 1 cvmfs 5.4K May 31 21:45 TMVAClassificationCategoryApplication.C
-rw-r–r-- 1 cvmfs 7.7K May 31 21:45 TMVAClassificationCategory.C
-rw-r–r-- 1 cvmfs 21K May 31 21:45 TMVAClassificationApplication.C
-rw-r–r-- 1 cvmfs 28K May 31 21:45 TMVAClassification.C
drwxr-xr-x 2 cvmfs 4 Jun 1 10:18 data

In the root sources:
root_src/tmva/tmvagui/src/tmvaglob.cxx

I guess you need to change that, and then call “make” again.

The alternative is to edit your rootlogon.C, which does not require to compile again.

Hi ferhue,

in my home I created 2 files:
~/.rootrc
Rint.Logon: ~/rootlogon.C
and
~/rootlogon.C
TMVA::gConfig().fVariablePlotting.fUsePaperStyle=0

but when I run root I have the error mesage:
/…/rootlogon.C:1:16: error: expected function body after function declarator
TMVA::gConfig().fVariablePlotting.fUsePaperStyle=0
^
Do you know what is wrong?
Regards

{ TMVA::gConfig().fVariablePlotting.fUsePaperStyle=0; }

Dear ferhue,
I did that and restart, I do not have error message but I still can’t get the .png file (only .eps).
Regards

Weird.

Can you check the output of this command, after starting ROOT?

cout << TMVA::gConfig().fVariablePlotting.fUsePaperStyle << endl;

It works for me, see below:

ferhue@linuxbox:/opt/root/tutorials/tmva$ root
   ----------------------------------------------------------------
  | Welcome to ROOT 6.09/01                    http://root.cern.ch |
  |                                   (c) 1995-2016, The ROOT Team |
  | Built for linuxx8664gcc                                        |
  | From heads/master@v6-09-01-191-g5683cff, Okt 20 2016, 14:31:49 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'     |
   ----------------------------------------------------------------
root [0] cout << TMVA::gConfig().fVariablePlotting.fUsePaperStyle << endl;
0
root [1] TMVA::TMVAGui()
--- Launch TMVA GUI to view input file: TMVA.root
=== Note: inactive buttons indicate classifiers that were not trained, ===
===       or functionalities that were not invoked during the training ===
root [2] --- Opening root file TMVA.root in read mode
--- --------------------------------------------------------------------
--- If you want to save the image as eps, gif or png, please comment out 
--- the corresponding lines (line no. 239-241) in tmvaglob.C
--- --------------------------------------------------------------------
Info in <TCanvas::Print>: eps file dataset/plots/variables_id_c1.eps has been created
Info in <TCanvas::Print>: file dataset/plots/variables_id_c1.png has been created
root [2] .q

Hi ferhue,

I have in root 6.06/01:

[…]$ root -l
root [0] cout << TMVA::gConfig().fVariablePlotting.fUsePaperStyle << endl;
0
root [1] TMVA::TMVAGui(“mt/TMVA.root”)
— Launch TMVA GUI to view input file: mt/TMVA.root
=== Note: inactive buttons indicate classifiers that were not trained, ===
=== or functionalities that were not invoked during the training ===
root [2] — Opening root file mt/TMVA.root in read mode
— Found directory for method: BDT::BDTD containing MVA_BDTD_S/_B
— Mean and RMS (S): 0.142985, 0.163495
— Mean and RMS (B): -0.220557, 0.276945
Info in TCanvas::Print: eps file plots/mva_BDTD.eps has been created
[…]$

Hmmm, maybe it is because of the ROOT version, but not sure…

Try instead:

{
	TMVAGlob::UsePaperStyle=0;
	//or TMVA::TMVAGlob::UsePaperStyle=0;
}