Please find the attached script.
The root file is ~9MB and not getting attached here.
I am putting it in here :
/afs/cern.ch/user/s/shilpi/public/root_error
Hi, I am also interested in extracting a TH1 histogram from a canvas and also in my case the primitive is a RooHist. I have considered the corrected macro you posted here some months ago, but at the end I need to draw the TH1 histogram not the canvas. If I put h->Draw(); instead of canvas->Draw(); , I get only the x/y axes drawn but not the points. is there a way to plot h? Thanks a lot
You probably need a way to access the RooHist rather than the underlying histogram. Since this is actually a different question, I will have better luck getting the answer by reposting your question in the Math and Stats forum.
It appears that the important and simple task of accessing histograms from canvas causes trouble from time to time. Some easy to follow and fail-safe rules are needed, because otherwise it becomes difficult to work with the data that are on a canvas.
where
histogram22Na.root is a file with several Canvases and histograms;
A - a Canvas with several histograms
Energy_spectrum_top_A - title of a histogram
Everything seems perfect, but the error I persistently get is the following:
Error: illegal pointer to class object hFra40 0x0 403 program.c:7:
*** Interpreter error recovered ***
If your histogram resides in any sub-pad, it will NOT be found by “canvas->GetPrimitive(…)”.
For some solutions see here (the “MCA” resides in the “pad1”): [url]Error fitting Histo from a Canvas
Hello,
Sorry for taking a very long time to respond. I had been busy working on other projects.
The message that I got was the following:
Energy_spectrum_top_A not found
TPad fXlowNDC=0.01 fYlowNDC=0.51 fWNDC=0.48 fHNDC=0.48 Name= A_1 Title= A_1 Option=
OBJ: TH1F Energy_spectrum_top_A Energy spectrum top A : 0 at: 0xc53cf00
TPad fXlowNDC=0.51 fYlowNDC=0.51 fWNDC=0.48 fHNDC=0.48 Name= A_2 Title= A_2 Option=
OBJ: TH1F No_events_per_channel_top_A No events top A : 0 at: 0xc5ba800
TPad fXlowNDC=0.01 fYlowNDC=0.01 fWNDC=0.48 fHNDC=0.48 Name= A_3 Title= A_3 Option=
OBJ: TH1F Energy_spectrum_bottom_A Energy spectrum bottom A : 0 at: 0xc5bb410
TPad fXlowNDC=0.51 fYlowNDC=0.01 fWNDC=0.48 fHNDC=0.48 Name= A_4 Title= A_4 Option=
OBJ: TH1F No_events_per_channel_bottom_A No events bottom A : 0 at: 0xc5bc270
Hence, I realised that the histogram was residing on a TPad, and did a modification as suggest by Mr. Coyote.
The code below appears to get the job done. Thanks.