I probably have a very simple question for you experts, but nevertheless i have not found the answer to it myself the entire day:
I am trying to simply save a set of TF1 and one list of strings for each TF1 in a tree, like this:
>file
>tree1
>TF1_1
>list_1 (for example ["x","y","z"])
>TF1_2
>list_2 (for example ["x","y","z"])
>tree2
>TF1_1
>list_1 (for example ["x","y","z"])
>TF1_2
>list_2 (for example ["x","y","z"])
The problem is: I have no clue, how to do this. I found many tutorials on writing trees, but none could help me. I thought i found the solution with this a = ROOT.TF1("g","gaus",0,10)
a.SetParameters(2,4,6)
tree = ROOT.TTree( 'testTree', 'Test histogram tree' )
tree.Branch('fun_branch','TF1',a) for the TF1, but somehow i do not store the TF1 but the class of the TF1.
did you call tree.Write() before closing the file? Otherwise, give a full example that fails, so that I can debug it. Beyond that, all I can do is refer to the documentation/tutorials that you have already found.
Hi! Yes I wrote the file. Sry - I made a new exampleCode. I know, this is really basic stuff, but somehow i don’t find the right method for me in any tutorials / examples. All I can find is how to save events in trees or this type of storing i show here, and nowhere i can find how to store lists.
outputFile=ROOT.TFile("test" + ".root", "RECREATE")
a = ROOT.TF1("g","gaus",0,10)
a.SetParameters(2,4,6)
tree = ROOT.TTree( 'testTree', 'Test histogram tree' )
tree.Branch('fun_branch','TF1',a)
outputFile.Write()
outputFile.Close()
certainly you need ‘tree.Fill()’. It is guaranteed NOT to work w/o that.
With Fill, the code works fine for me.
Not sure what you are looking at for “appearance of the fun_branch”. Try first the file size between w/ and w/o Fill, to see that something at least is being stored.