Problem reading TGraphAsymmErrors

Hi

I have a simple .root file with few TGraphAsymmErrors and TH1D in. Looking with TBrowser, everything looks fine, but if I try something like

root [2] TGraphAsymmErrors *tg = (TGraphAsymmErrors*)gFile->Get("EtaLt0p9_All_Data")
tg->Draw("AP")
Error: illegal pointer to class object tg 0x0 1563  (tmpfile):1:

probably it is silly, but what am I missing ?
TFR.root (8.71 KB)

root [0] TFile *f= new TFile("TFR.root");
root [1] etaBinsH->Draw();
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [2] EtaLt0p9_All_Data->Draw();
input_line_46:2:3: error: use of undeclared identifier 'EtaLt0p9_All_Data'
 (EtaLt0p9_All_Data->Draw())
  ^
root [3] 

It looks like the name of the graph is the problem. May be the following “how to” can help you:
root.cern.ch/how/how-draw-objec … s-its-name

Check how you set the names and titles of all your graphs.
It seems to me that they all contain an “invisible” character at the very beginning.
Try:
(int)(gFile->GetListOfKeys()->At(0)->GetName())[0]

Hi

I was suspecting that - However, I cannot find where the problem in the first place might be- to define the name I do something like

[code]
TGraphAsymmErrors * effCut[3][4];
char name[100];
string s1,s2;
s1="";
s2="";
int nEtaBins = 3
TString EtaBins[3] = {“EtaLt0p9”,
“Eta0p9to1p2”,
“EtaGt1p2”};

TString Cuts[4] = {"Ratio","mT","DPhi","All"};
 for (int iEta=0; iEta<3; ++iEta) {

for (int iCut=0; iCut<nCuts; ++iCut) {
s1 = EtaBins[iEta];
s2 = Cuts[iCut];
sprintf(name, “%s_%s_Data”,s1,s2);
cout<<" The name to be used "<<name<<endl;
effCut[iEta][iCut]->SetName(name);
fileOut->cd();
effCut[iEta][iCut]->Write();

}
}
fileOut->Write();
fileOut->Close();
[/code]

which correctly returns

The name to be used EtaLt0p9_All_Data

and even more, if I do

root -l TFR.root
root [0]
Attaching file TFR.root as _file0...
root [1] gFile->ls()
TFile**		TFR.root
 TFile*		TFR.root
  KEY: TGraphAsymmErrors 	EtaLt0p9_All_Data;1	EtaLt0p9_All_Data
  KEY: TGraphAsymmErrors 	EtaLt0p9_All_MC;1	EtaLt0p9_All_MC

so, listing the file, still the “EtaLt0p9_All_Data” looks legit…

What’s exactly “EtaBins”, “Cuts”, “s1”, “s2”, “name”?

just edited my previous post

You are trying to mix “std::string”, “TString” and “char *” (in “sprintf”).
Try simply:
effCut[iEta][iCut]->SetName(EtaBins[iEta] + “_” + Cuts[iCut] + “_Data”);
or try to use:
const char *s1, *s2;