Creating a TColor object in PyROOT

I’m not sure how to deal with C++ pointers within PyROOT.

I want to be able to get the RGB values for ROOT’s built-in colors via the GetRGB method. So I tried:

In [3]: ROOT.TColor.GetColor(3).GetRGB()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/Users/jeff/Work/data/<ipython console> in <module>()

AttributeError: 'int' object has no attribute 'GetRGB'

GetColor returns an integer, which in the C interpreter you can directly cast to a TColor*, but I see no way to turn this thing into a TColor in PyROOT.

Any advice?

Hi Jeff,

The return value apparently depends on how you call it( and doesn’t depend on PyRoot).

cplager@Hagrid> root -l
root [0] TColor::GetColor(3)
(Int_t)(1)
root [1] gROOT->GetColor(3)
(const class TColor*)0x10460718
cplager@Hagrid> python
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) 
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> ROOT.TColor.GetColor(3)
924
>>> ROOT.gROOT.GetColor(3)
<ROOT.TColor object ("green") at 0xd6f818>

Cheers,
Charles

1 Like