Saving python graphs to .root extension

Hi all,

I have a code written with pyroot and the products are graphs gr1, gr2 with set names name1, name2.
How can I automatically save them to some file with .root extension (for an example ‘file.root’)?
Also, graphs need to be in separate subdirectories inside file.root file

file.root----->
---------- directory1----->
gr1
---------- directory2----->
gr2

Thanks in advance.
V.

You open a ROOT file using TFile and write each graph in it using Write.

That`s not a problem, I can do it like this

file = TFile(“file.root”,“RECREATE”)
g.Write()
c1.Write()
file.Close()

But how can I create separate directories inside file.root ?

Regards,
V.

https://root.cern/doc/master/classTDirectoryFile.html#a7956f3301635ca0dd5655e8e59a35d85

Thanks you, I`ll try with that

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.