root-project / root

The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
https://root.cern
Other
2.64k stars 1.26k forks source link

`TF1::DrawCopy()` does not copy histogram properties #13122

Open linev opened 1 year ago

linev commented 1 year ago

Check duplicate issues.

Description

If TF1::DrawCopy() is used to draw the function, all axis settings (which are stored in histogram) are lost.

Reproducer

This happens for instance in tutorials/math/Bessel.C macro where configured axis titles are not displayed.

ROOT version

master and all recent releases

Installation method

build from source

Operating system

OpenSUSE Linux

Additional context

No response

couet commented 1 year ago

I'll check. Thanks for the report

couet commented 1 year ago

I am not sure how to reproduce this issue. I did the following: 1) run the macro Bessel.C 2) Save the canvas to a root file 3) reopen root with that saved file and display the canvas => The plots are exactly the same as when I execute the macro directly

linev commented 1 year ago

Try to store canvas from tutorials/graphs/annotation3d.C macro.

It modifies axes properties in the macro itself - like title or some special labels.

You can do same with Bessel.C - but interactively before storing canvas to ROOT file

couet commented 1 year ago

I see that with annotation3d.C the changed labels are not stored in the canvas when it is displayed back. But it has nothing to do with DrawCopy because this macro uses only Draw.

couet commented 1 year ago

Saving it as .C also doesn't work.

linev commented 1 year ago

TF1::DrawCopy not used in tutorials. But if one modifies any of such tutorials and will try to use - it will fail.

couet commented 1 year ago

It fails already now. I am preparing a PR for the .C case first ...

couet commented 1 year ago

This one fixes the .C part: https://github.com/root-project/root/pull/13228

couet commented 1 year ago

Now we have:

auto f = new TF1("x","x",-1,1);
f->Draw();
f->GetXaxis()->ChangeLabel(5, -1, -1, -1, -1, -1,"CHANGED");
c1->SaveAs("c1.C");
c1->SaveAs("c1.root");

The changed label is saved in the .C file but not in the root file.

couet commented 1 year ago

Indeed TF1 the data member fHistogram is not persistent (see TF1.h) this member holds the axis. Therefore the axis are not persistent too and not saved in the root file. That's a design choice to not make fHistogram persistent. I do not think that can be changed.

linev commented 1 year ago

Therefore the axis are not persistent too and not saved in the root file.

Olivier, TF1::DrawCopy is not about storage in the ROOT file. It missing copying of histogram properties.

couet commented 1 year ago

@lmoneta . In this issue Serguei points out the fact that TF1::DrawCopy does not keep the axis labels and titles changes. This is normal because they are stored in the underlying histogram fHistogram and this histogram is explicitly not copied . Is there a reason behind this ? . Does it make sense to copy also the underlying histogram ?

dpiparo commented 7 months ago

@lmoneta , I am just reviving this issue since perhaps the question of @couet got lost.

ferdymercury commented 6 months ago

this histogram is explicitly not copied . Is there a reason behind this ? . Does it make sense to copy also the underlying histogram ?

I guess it was to avoid a memory leak: https://github.com/root-project/root/commit/c9e326e0dbebb4af52b58bfa3e73e80fb1f97682

ferdymercury commented 6 months ago

If TF1::DrawCopy() is used to draw the function, all axis settings (which are stored in histogram) are lost.

A workaround would be to call: TF1::Clone(); TF1::Draw(); which does copy the underlying histogram.

dpiparo commented 4 months ago

@couet is this fixed? Can the item be closed?

linev commented 4 months ago

No, issue is still there.

As mentioned - tutorials/math/Bessel.C configures x axis title, but it does not appeared when TF1::DrawCopy() is called.

dpiparo commented 1 month ago

@couet @linev is this still a problem? If yes, what is the plan to fix this?

linev commented 1 month ago

Yes, issue is still there. One need to fix TF1::DrawCopy()