Saving/loading canvases in .C format after using roofit

Hello,

I am using roofit in pyROOT to fit to some data and I am interested in saving the resulting plot in .C format. When I plot just the roodatahist (prior to applying and plotting any fit), I am able to save the canvas using the File>Save as option. When I try to reload this file in root, or using a TBrowser, the correct plot opens with no issues. However, once I apply the fit and plot it, this same exact procedure saves the .C file, but when trying to rerun it in root, it crashes. I’m not really sure what the issue is. I’ve attached a python file that reproduces this issue. When trying to open test_nofit.C in root, there are no issues, but when trying to open test_fit.C, it fails. Can somebody show me a better way to do this so that I can load these files with no issues?
saving_test.py (1.3 KB)
test_fit.C (10.1 KB)
test_nofit.C (6.4 KB)

Hi,

Sorry to read ROOT did not work out of the box for you in this case.
Thanks for the reproducer: I tried it with master and 6.34, however, I do not manage to reproduce the crash when running the macros representing the plot.

What ROOT version are you using?

Cheers,
Danilo

Hi,

Thanks for your response! I’m running root version 6.30/04, which I built from the conda package a couple of months ago.

How are you running the macros? I’m doing so from a root interactive session in terminal. Would it be helpful if I attached a picture of the errors I’m encountering?

Thanks again!

Hello! I could reproduce the error with ROOT 6.30.04 (see bottom of this post).

The good news is that the problem is simple: invalid C++ variable names are used in the dumped .C code, and that this got fixed in ROOT 6.32.02 onward. Please use that ROOT version for a smoother experience.

In case you want to stick an older ROOT version, I’m afraid you have to work around this problem my manually fixing the generated .C code.

Cheers!
Jonas

Processing test_fit.C...
In file included from input_line_8:1:
/afs/cern.ch/user/r/rembserj/test_fit.C:107:27: error: use of undeclared identifier 'x'
   Double_t gaussian_Norm[x]_fx1[134] = { -20.02, -20, 0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280,
                          ^
/afs/cern.ch/user/r/rembserj/test_fit.C:107:29: error: expected ';' at end of declaration
   Double_t gaussian_Norm[x]_fx1[134] = { -20.02, -20, 0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280,
                            ^
                            ;
/afs/cern.ch/user/r/rembserj/test_fit.C:116:27: error: use of undeclared identifier 'x'
   Double_t gaussian_Norm[x]_fy1[134] = { 0, 4.146547e-19, 4.146547e-19, 2.619263e-18, 1.594203e-17, 9.349329e-17, 5.283106e-16, 2.876539e-15, 1.509119e-14, 7.628666e-14, 3.715746e-13, 1.743875e-12, 7.886005e-12, 3.436139e-11, 1.442636e-10, 5.835991e-10, 2.274808e-09,
                          ^
/afs/cern.ch/user/r/rembserj/test_fit.C:116:29: error: expected ';' at end of declaration
   Double_t gaussian_Norm[x]_fy1[134] = { 0, 4.146547e-19, 4.146547e-19, 2.619263e-18, 1.594203e-17, 9.349329e-17, 5.283106e-16, 2.876539e-15, 1.509119e-14, 7.628666e-14, 3.715746e-13, 1.743875e-12, 7.886005e-12, 3.436139e-11, 1.442636e-10, 5.835991e-10, 2.274808e-09,
                            ^
                            ;
/afs/cern.ch/user/r/rembserj/test_fit.C:125:49: error: use of undeclared identifier 'x'
   TGraph *graph = new TGraph(134,gaussian_Norm[x]_fx1,gaussian_Norm[x]_fy1);
                                                ^
/afs/cern.ch/user/r/rembserj/test_fit.C:125:70: error: use of undeclared identifier 'x'
   TGraph *graph = new TGraph(134,gaussian_Norm[x]_fx1,gaussian_Norm[x]_fy1);

Hi jonas! Yup, that’s exactly the error! I did have a friend try it on their machine (they homebrew installed root, so their version should be 6.32.08) and they also bumped into the issue. I’m updating root on my linux machine now to see if the error persists there. I’ll update here if anything!

Cheers,
Aitor

Alrighty, reinstalled conda with homebrew and it works now! The only caveat is that the file HAS to be generated with the new pyROOT. Trying to load the old test_fit.C file (generated using root 6.30) with my updated root 6.32 still reproduces the error. This might be why the error still occurred on my friend’s machine. However, rerunning the reproducer with the new version of pyROOT and then opening the new test_fit.C works!

Thanks so much for your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.