Error: illegal pointer to class object

Hi,

When trying to draw some histograms I receive the following error message but I cannot seem to find the source of this error.

Error: illegal pointer to class object myHist 0x0 465 MyFile.C:213:

Just to let you know I am using ‘FitSlicesY()’ on a TH2F object and then retrieve the output histograms of the fit parameters. (I checked to see if the pointer to the returned histograms is null… and it isn’t). The code compiles ok but when I try to draw any of the ‘fit parameter’ histograms thats when I run into this error.

Thanks in advance,

Craig

Could you post the shortest possible running script and data file reproducing this problem?
Rene

I have pasted my script below…

#include “MyFile.h”
#include <TFile.h>
#include <TDirectory.h>
#include <TH1D.h>
#include <TH2D.h>
#include
using namespace std;

void MakePlots()
{
TFile *rootFile = new TFile("~/H130_trig1_misal1_csc11_Muid.aan.root", “READ”);
TDirectory directory = (TDirectory) rootFile->Get(“MuonPerf”);
TH2D histogram = (TH2D) directory->Get(“muonAllResolutionPt”);
histogram->FitSlicesY();
TH1D histogram_1 = (TH1D)gDirectory->Get(“histogram_1”);
TH1D histogram_2 = (TH1D)gDirectory->Get(“histogram_2”);

if(histogram_1==0 || histogram_2==0) {
histogram_1->Draw();
histogram_2->Draw();
} else {
cout << “Retrieval of histograms from current directory was unsuccessful!” << endl;
}

}

And the header file for this is just…

#ifndef MYFILE_H
#define MYFILE_H
void MakePlots();
#endif

The root file can be found at…
/afs/cern.ch/user/w/wigleswt/public
… If you are not able to see this then I will attach it in another post

Thanks,

Craig

The generated histograms with the fit result are named using the original histogram name. Change your code like:

[code]void MakePlots()
{
TFile *rootFile = new TFile(“H130_trig1_misal1_csc11_Muid.aan.root”, “READ”);
TDirectory directory = (TDirectory) rootFile->Get(“MuonPerf”);
TH2D histogram = (TH2D) directory->Get(“muonAllResolutionPt”);
histogram->FitSlicesY();
TH1D histogram_1 = (TH1D)gDirectory->Get(“muonAllResolutionPt_1”);
TH1D histogram_2 = (TH1D)gDirectory->Get(“muonAllResolutionPt_2”);

if(histogram_1!=0 && histogram_2!=0) {
histogram_1->Draw();
histogram_2->Draw();
} else {
cout << “Retrieval of histograms from current directory was unsuccessful!” << endl;
}

} [/code]

Rene

Oh sorry… that is my fault. I tried to make the code a bit easier to read by changing the histogram names but obviuosly I forgot to change them all.

So I think even if I make the change you suggested I will still have the same problem.

Sorry about that!

Craig

so, please simplify my life, be explicit and post the exact code that you are running. I forgot to mention that your test was wrong:

if(histogram_1==0 || histogram_2==0) { I replaced it by:

if(histogram_1!=0 && histogram_2!=0) {
Rene

I didn’t post the exact code because you specifically asked for the code to be as short as possible.

Anyway I have fixed my problem. The histograms were not being retrieved successfully but I could not see this because I had not noticed the mistake I had made in the test.

Thanks for your help.

Craig