Overlay a graph in a scatter plot

Dear Experts,

I am trying to overlay a file on a scatter plot using a macro and I am trying to save it in a rootfile.
The macro is able to drawing the scatter plot and overlay the graph but, it is not writing it to the root file. In the root file I can only see the scatter plot without the graph overlaid. Here’s the macro. tgraph.C (746 Bytes)

I am afraid, i cannot send you the root file which I am using as it is very large and I don’t have it in the pc. But I have a similar root file which has the same trees and branches but has almost no entries. I think it can be used to check the macro though. Here it is:ccbar_0010_r05902_0_mdst_batch0_light-2002-janus.root (722.3 KB).

Can you please help?

Root version:5.34
Compliler: g++


With the latest root (6.22/00) and with root 5.34/38, using your sample root file and macro (only removing the cuts in tree->Draw, since there’s only 1 event in the tree), I see both plots even after closing root and opening the output root file.
A few sanity checks: you are plotting func in a very small range (1.8 to 1.83 in x); maybe it is there, but too small to see? And is that the exact same code you are using? maybe you are doing other stuff you didn’t show here, or your root is too old (try a newer version). You could also try moving this line

  TFile * f1 = new TFile("tgraph_data.root","RECREATE");

higher, e.g. before creating the canvas.