TCanvas::SaveAs not saving .C correctly with RooFit

Hi,

I am using ROOT v6.04.14 in Debian 8.0. I am saving to a canvas a RooDataSet and a RooGausian, then I save the canvas as a cxx file. When I do

campoverde@johns:~/Test/Test_RooFit2/bin$ root -l roofit_ex.cxx root [0] Processing roofit_ex.cxx... In file included from input_line_9:1: /nfs/monet_3/home/campoverde/Test/Test_RooFit2/bin/roofit_ex.cxx:652:23: error: use of undeclared identifier 'x' Double_t gaus_Norm[x]_fx1[114] = { ^ /nfs/monet_3/home/campoverde/Test/Test_RooFit2/bin/roofit_ex.cxx:652:25: error: expected ';' at end of declaration Double_t gaus_Norm[x]_fx1[114] = { ^ ; /nfs/monet_3/home/campoverde/Test/Test_RooFit2/bin/roofit_ex.cxx:767:23: error: use of undeclared identifier 'x' Double_t gaus_Norm[x]_fy1[114] = { ^ /nfs/monet_3/home/campoverde/Test/Test_RooFit2/bin/roofit_ex.cxx:767:25: error: expected ';' at end of declaration Double_t gaus_Norm[x]_fy1[114] = { ^ ; /nfs/monet_3/home/campoverde/Test/Test_RooFit2/bin/roofit_ex.cxx:882:45: error: use of undeclared identifier 'x' TGraph *graph = new TGraph(114,gaus_Norm[x]_fx1,gaus_Norm[x]_fy1); ^ /nfs/monet_3/home/campoverde/Test/Test_RooFit2/bin/roofit_ex.cxx:882:62: error: use of undeclared identifier 'x' TGraph *graph = new TGraph(114,gaus_Norm[x]_fx1,gaus_Norm[x]_fy1);

The computer gives me a lot of errors. The same does not happen when I draw in the canvas objects of classes that dont belong to RooFit. How should I fix this? I attached a very short and simple example.

Cheers.
Test_RooFit2.zip (1.77 KB)

Hi,

As I can see that there is no feedback I tried to understand this. It seems that RooFit is giving objects names like gaus_Norm[x], these names are then used to build variables like gaus_Norm[x]_fx1 making the computer wonder where was x defined. It seems to me that there was a lack of communication between the ROOT developers and the RooFit developers to avoid this type of thing. The object name should of course not be gaus_Norm[x] but something more like gaus_Norm_x.

Will this ever be fixed or should we learn to live with this?

Cheers.

Sorry, I have posted this message, but I noticed now that it was not sent. Here it is

Hi,
The problem is due to the fact that the RooFit names contains “[x]” and these characters is not allowed for defining C++ variables.
It is something we need to fix in ROOT. In the mean time I suggest you just change the names by hand in the macro

Cheers

Lorenzo

Hi,

So I tried to change the name of the objects stored in the TCanvas and then call TCanvas::SaveAs() again, however it did not work. The [x] stuff kept appearing, which means that this name must be somewhere else into the RooPlot object, not just the name and when I change the name this other member still containing [x] does not change.

I solved this by making a copy of the renamed RooCurve, putting it in the RooPlot object and removing the old RooPlot. Copying the RooCurve must reset this data member value. The relevant code is below:

[code] TString tgt_1 = “[”;
TString tgt_2 = “]”;
TString rep = “_”;

TString orig_name = curve->GetName();
auto draw_options = curve->GetDrawOption();

orig_name.ReplaceAll(tgt_1, rep);
orig_name.ReplaceAll(tgt_2, rep);
curve->SetName(orig_name);
//*************************************
RooCurve *n_curve = new RooCurve(*curve);
frame.addObject(n_curve, draw_options);
frame.remove(orig_name);[/code]

Cheers.