Plot changes when canvas is saved

Hello Rooters,

I observe something very strange: I divide a canvas into 4 pads and then use a custom fit to fit and draw 4 different distributions. When the macro is finished everythings looks fine, the plots are ok. But when I save the canvas as .eps file (File->Save as…) then in 2 pads (first and third) the fit (the line) decreases in height on the canvas and also inside the file (the fit values in the stat box don’t change).

Can anybody explain this behaviour and tell me a way around it?
Thanks,
Gerolf

Ps: I use ROOT 4.03/04

the last part of the macro:

TCanvas *cTile = new TCanvas(“ctile”,“ctile”,1);
cTile->Divide(2,2);
gStyle->SetOptFit(1);

cTile->cd(1);
glfit(hTile);
hTile->Draw();
cTile->Update();

cTile->cd(2);
glfit(hSmp1);
hSmp1->Draw();
cTile->Update();

cTile->cd(3);
glfit(hSmp2);
hSmp2->Draw();
cTile->Update();

cTile->cd(4);
glfit(hSmp3);
hSmp3->Draw();
cTile->Update();

Can you send a simple example reproducing the problem ?

Hi,

here is an example. If you run the macro you should get 4 distributions fitted with a landau convoluted gaussian.
If you then choose File->Save->xxx.ps then the fit on the pad 1 and 3 changes.
I gzipped the files.

If you have problems running it, please tell me.
Thank you!
Gerolf

PS: Here is the simple macro:

void simpel()
{
TFile * f = TFile::Open(“Tile_muon_ene.root”);
gSystem->Load(“glfit_cpp.so”);

TCanvas *cTile = new TCanvas(“ctile”,“ctile”,1);
cTile->Divide(2,2);
gStyle->SetOptFit(1);

cTile->cd(1);
glfit(hTile);
hTile->Draw();
cTile->Update();

cTile->cd(2);
glfit(hSmp1);
hSmp1->Draw();
cTile->Update();

cTile->cd(3);
glfit(hSmp2);
hSmp2->Draw();
cTile->Update();

cTile->cd(4);
glfit(hSmp3);
hSmp3->Draw();
cTile->Update();
}
Tile_muon_ene.root.gz (6.65 KB)
glfit.cpp.gz (2.03 KB)
glfit_cpp.so.gz (9.33 KB)

Your macro doesn’t work. I downloaded the files and executed “simple.C” . The macro hangs … can you send me a working one ?

Hello,
here is the slightly modified file. I tried it on another account. It should work (the fit takes long, ca 1 minute)

Thank you for looking at it.
Cheers Gerolf
simpel.C (480 Bytes)
glfit.cpp (5.64 KB)
Tile_muon_ene.root (7.05 KB)

Your function glconv depends on a static global “Norm”.
When the function is evaluated (when the Paint function is called),
the latest value of Norm is used.
Instead you should introduce an additional parameter to your function
and fix it at the time you compute the effective value of Norm, ie

[code]void glfitmake(TH1F *h)
{
// Double_t par[4] = {1000.,0.001,0.0004,0.0005};
func = new TF1(“gslan2”,gslan2,0,1,4);
TF1 *funfit = new TF1(“glconv”,glconv,0,1,5);

Norm = (((Double_t) h->GetBinLowEdge(h->GetNbinsX()+1))-
((Double_t) h->GetBinLowEdge(1)))/h->GetNbinsX();
gBenchmark->Reset();
gBenchmark->Start(“glfit”);
funfit->SetParameters(par[0],par[1],par[2],par[3],Norm);
funfit->FixParameter(4,Norm);
funfit->SetParNames(“Constant”,“LandauMOP”,“LandauWidth”,“GaussSigma”,“Norm”);
printf(“Starting the fit with parameter values: %f %f %f %f\n”,par[0],par[1],par[2],par[3]);
h->Fit(“glconv”);
gBenchmark->Show(“glfit”);
}

Double_t glconv(Double_t *x, Double_t par)
{
Double_t LandauWidth=par[2]0.58600;
Double_t GaussWidth=par[3];
ConvX=x[0];
return((par[0]par[4]func->Integral(-5.0GaussWidth,5.0GaussWidth,par,1.0e-8))/(LandauWidth
2.5066282746
GaussWidth));
}[/code]

Rene

Thanks a lot Rene, it seems to work now!

Gerolf