TGraph Objects from TFile has no color in PyROOT

Hello!

I’ve been trying to look through this forum to find a solution to something I completely don’t understand.
I can’t seem to get Marker Color, Style nor Size from a TFile containing TGraph objects using PyROOT while using ROOT works as far as I can see, and I don’t have the faintest idea of why, been trying quite a few different ways so far.

The attached scripts show the situation and the TFile, on line 44 in the filereader.py the list is supposed to hold the same values as the one in filereader.C, but it only has the default values for TGraph objects.

Any help would be greatly appreciated.

empty = []
for key in f.GetListOfKeys():
    name = key.GetName()

    title = key.GetTitle()                           
    if int(name) in checklist:
        graph = f.Get(name)
        empty.append(graph.GetMarkerColor())
        if setown:
            graph.SetMarkerStyle(style)
            graph.SetMarkerColor(color)
            graph.SetMarkerSize(size)
        graph.Draw('p')                
        tl1.AddEntry(name, title,'p')      
print empty

TGraphs.root (24.4 KB)
filereader.py (1.49 KB)
filereader.C (300 Bytes)

Hi,

I get the exact same values in filereader.C as in filereader.py … if I rewrite filereader.py to do the exact same thing as filereader.C …

Neither the code that you quote, nor the filereader.py can be executed (several variables used are left undefined). Please provide a script that runs and shows the actual problem.

Cheers,
Wim

I was certain I had double checked that the code worked properly, it was a snippet from a larger code, changed a few things too quickly. And apparently it works now after rewriting it, have to try to figure out why.

Just a quick question though, how did you rewrite it to be exactly like filereader.C? I’ve been quite unsure how to do it properly in python because of lack of pointers and casting.

Hi,

this is the .py equivalent of the posted .C:from ROOT import * f = TFile("TGraphs.root") checklist = [0, 102, 112, 122, 201, 211] setown = False empty = [] for key in f.GetListOfKeys(): graph = f.Get(name) empty.append(graph.GetMarkerColor()) print empty[-1]Cheers,
Wim