TGraphAsymmErrors - <Handler Interpreter Exception>

Hello,
I am trying to call a file using TGraphAsymmErrors using the following lines -

c1 = new TCanvas (“c1”, " ");
TFile f1 = new TFile("/afs/cern.ch/user/s/ssaha/Beek_analysis/run/test.root");
f1->ls();
TGraphAsymmErrors * gr = (TGraphAsymmErrors
)f1->Get(“divide_hL1effvsdR_JPSI||EM8VH+by_hL1effvsdR_denom”);
gr->Draw(“AP”);
c1->Update();

It is showing the following error -
Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.
warning: null passed to a callee that requires a non-null argument [-Wnonnull] gr->Draw(“AP”);

Any hints are appreciated !
Thank you

Double check hat the name
divide_hL1effvsdR_JPSI||EM8VH+by_hL1effvsdR_denom
is correct! Do you really have a TGraphAsymmErrors object with such a long name containing special characters? You even have the f1->ls() in your code - does it print this name?

Advice:
a) don’t use special characters like | and + in names. They cause problems, for example you can’t use these these names directly in the root command line.
b) Always check the return value of Get() and don’t use unsafe C style casts. Instead, use

TGraphAsymmErrors *gr;
f1->GetObject("name of the object", gr);
if (gr == nullptr) 
    cout << "Requested object does not exist or has an incompatible type\n";

It works now ! Thank you, I will follow the advice in future.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.