1. import ROOT
    2. import array
    3. outfile = ROOT.TFile(outfilename,"RECREATE") # Erases any existing file.
    4. # Create a one-element python array to hold the value (could also use numpy).
    5. time_arr = array.array("d" ,[0])
    6. binomial_arr = array.array("l",[0]) # And so on for every variable...
    7. # Create the tree and the branch manually.
    8. t = ROOT.TTree(treename ,"tree title")
    9. t.Branch("time", time_arr , "time/D")
    10. t.Branch("binomial", binomial_arr, "binomial/L")
    11. # D for doubles
    12. # L for integers
    13. # Now loop over the file manually:
    14. with open(infilename ,"r") as csvfile:
    15. reader = csv.reader(csvfile)
    16. for row in reader:
    17. if row[0].startswith("#"): # skip comment lines continue
    18. time_arr[0] = float(row[0]) # Important: change the CONTENT of the arrays.
    19. binomial_arr[0] = int(row[1])
    20. t.Fill()
    21. # Write the data from the TFile to the actual file on disk.
    22. outfile.Write()
    23. outfile.Close()