How to get contours from TList by pyROOT?

Dear experts,

I want to use pyroot to get contours.
I followed the ContourList.C to get contours of 1sigma, 2sigma CLs.
In this example:

   // Get Contours
   TObjArray *conts = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");

When I transfer to pyroot as following:

conts=ROOT.gROOT.GetListOfSpecials().FindObject("contours")
gr_1sigma=conts.At(0).First()
gr_2sigma=conts.At(1).First()

I got following errors:

Traceback (most recent call last):
  File "plot2D.py", line 67, in <module>
    gr_1sigma=conts.At(0).First()
AttributeError: 'TObject' object has no attribute 'At'

Do you know a way to solve this? Thank you in any case!

Cheers,
Jie


ROOT Version: 6.22/00
Platform: MAC OS
Compiler: Not Provided


Hi,

Could you check whether the conts Python object is actually pointing to a C++ object?

You can just print it, does it say what you see below?

>>> print(conts)
<cppyy.gbl.TObject object at 0x0>

Hi,

Yes, I see the same output.

Jie

Then what I believe happens is that there is no object called contours in the list of specials. What you get back is a Python proxy to a C++ null pointer.

Perhaps @couet can clarify why countours is not in the list of specials in the code you are running.

In C++ it is there. See the C++ code.

@couet could you point to what line in the C++ code makes countours appear in the list of specials? That could give us a hint about the problem in the translation to Python.

Option LIST is the trick (see documentation)

// Draw contours as filled regions, and Save points
   HistStreamFn->Draw("CONT Z LIST");
   c->Update(); // Needed to force the plotting and retrieve the contours in TGraphs

Hi Couet,
Thank you. It works now.