I’d like to return a histogram object from one function to be used within another. I am returning the histogram, among other variables. Later, I use this histogram to make a RooDataHist. However, it seems that whatever is being returned loses its histogram type and therefore it is not a histogram anymore. For example
Now this gives me an error where I initialise rHist because it needs a TH1F as the last parameter. but since I passed it between functions, the histogram lost its TH1F type. I tried getting the histogram via ROOT.gDirectory.Get(“histname”), but that still doesn’t hold its type. What can I do?
Thanks for replying, but I read somewhere that once I pass the histogram out of the scope of the function, it loses its type. I am not too sure of how ROOT and python work behind the scenes so I can’t comment there. Nevertheless, within that same post, I found a solution. An example would be:
def a_function():
var1 = "test"
var2 = 34
histogram = ROOT.TH1F("hist","hist",200,1,5)
histogram = ROOT.gDirectory.Get("hist")
#This line is the important one
histogram.SetDirectory(0)
return var1, var2, histogram
def another_function():
var1, var2, histogram = a_function()
#Do whatever with histogram now
histogram.Draw()