The canvas contains the list of primitives. First do canvas->ls() to see what kind of object holds the curve . Then uses GetListOfPrimitives to retrieve the TList containing this object. Then using FindObject on this TList you will be able to retrieve the object itself.
superimpose_realandMC.C (818 Bytes)
The attached code is not working and when I use GetPrimitive instead of GetListOfPrimitives the only first data points are shown.
{
auto *f = TFile::Open("CosPADistribution_realdataonly.root");
auto c = (TCanvas*)f->Get("c");
auto l = (TList*)c->GetListOfPrimitives();
auto h = (TH1F*)l->FindObject("h_CosPAReal_ptbin[1]");
auto C = new TCanvas ("C","C");
C->cd();
h->SetLineColor(2);
h->Draw("hist");
}
Thanks a lot for replying but again it shows only first point . I would like to mention that the .root file is superimposition of many histograms in one canvas saved in .root format.
I have not look in details all the histograms in the canvas. But yes this particular one seems to have only one bin.
When you do βlsβ on the canvas you get:
so several histograms appear to have the same name. It seems that the points you see under the same name when you draw the canvas are indeed spread over several histograms (with the same name) β¦
I apologize for the delay. I am sending you the program which created this canvas. Actually many histograms have been superimposed. superimpose_realdata.C (10.3 KB)
You get some histograms with the same names from different files. For instance the histogram h_CosPAReal_ptbin[0]. When you draw them in the sams canvas they appear as listed in my previous post. Therefore it is not easy to retrieve them individually from the canvas. One way to make it easier would be to rename the histograms differently just after having done the Get from the files. The method to rename an histogram is SetName.