from ROOT import TFile, TTree, gRandom from array import array # make new root file with new tree file = TFile("tree.root", 'recreate') tree = TTree("tree_name", "tree title") # create 1 dimensional float arrays as fill variables, in this way the float # array serves as a pointer which can be passed to the branch px = array('d',[0]) phi = array('d',[0]) # create the branches and assign the fill-variables to them as doubles (D) tree.Branch("px", px, 'normal/D') tree.Branch("phi", phi, 'uniform/D') # create some random numbers, assign them into the fill variables and call Fill() for i in xrange(10000): px[0] = gRandom.Gaus(20,2) phi[0] = gRandom.Uniform(2*3.1416) tree.Fill() # write the tree into the output file and close the file file.Write() file.Close()