Making a pointer to histogram in subfolder to make fits


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


So I am trying to make a Macro to open and fit various histograms. The issue I keep running into is that I get Error: illegal pointer to class object pie0 0x0 169 S9_Fit957.c:21:
*** Interpreter error recovered ***

Here is the code I am using.

#include “TString.h”
#include “TF1.h”
#include “TH1F.h”
#include “TMath.h”
#include “TLegend.h”
#include “TFile.h”

void S9_Fit957()
{

TFile *f = TFile::Open("/data/x1/Detector/SiWinter20/Hist/SiERaw_Run957.root",“UDATE”);
TH1F *pie0=(TH1F *)gROOT->FindObject(“ERaw_Pie00”);
TF1 *pedFit = new TF1(“Pedestal”,“gaus(0)”,0,100);
pedFit->SetParNames(“p0”,“p1”,“p2”);
pedFit->SetParameters(1000,0.5,3);
pie0->Fit(“Pedestal”);
pedFit->Delete();
f->Delete();
pie0->Delete();
}
~

The histogram I am trying to load is ERaw_Pie00 for fitting purposes. Yet my pointer keeps failing.

Try:
TH1 *pie0; gFile->GetObject("EPieRaw/ERaw_Pie00", pie0);

That still returns Error: illegal pointer to class object pie0 0x0 1180 S9_Fit957.c:18:
*** Interpreter error recovered ***

Oh the error is now with the pointer to the fit for pie0. The line in question is

pie0->Fit(“Pedestal”)

Replace:

pedFit->Delete();
f->Delete();
pie0->Delete();

with:

delete f; // automatically deletes "pie0", too
delete pedFit;

Made those changes and I am still getting the pointer error this time it reads.

Error: illegal pointer to class object pie0 0x0 1180 S9_Fit957.c:18:
*** Interpreter error recovered ***

commenting out the line

pie0->Fit(“Pedestal”)

removed the error message. So what could be the issue with the pointer?

Attach the file for inspection.

The issue has been resolved. It all stem from a misunderstanding and not using TList.