one of the nice features of python is the ability to add object attributes after object construction. I was trying to use this to add some attributes to the ROOT histogram classes/objects.
The problem I am trying to solve is the fact that ROOT separates the drawing information into the canvas object, whereas from an analysis point of view, its the histogram that I want to look a certain way (say a 2D hist that I always want to draw in TEXT mode on a double log scale).
Instead of wrapping the ROOT class in a new class that adds some class members, I was hoping to just attach/add those attributes python style and look them up when I am drawing the histogram.
However, the naive approach did not work :
temp = TH1D(“name”, “name”, x_l, x_u, x_b)
temp._normalization = "ONE"
temp._drawOption = “TEXT”
myHistDict[temp.GetName] = temp
…later in code…
for hist in myHistDict :
norm = hist._normalization #this fails with: AttributeError: ‘TH1D’ object has no attribute ‘_normalization’
I also noticed that the dictionary of the ROOT object TH1D is empty?! Shouldn’t it feature the member variables, or are they hidden (how?).
In order to understand why the above does not work, I would also appreciate any reference on how the ROOT C++ objects relate to python objects.
Thanks for any explanations.