Hi everybody,
I am trying to fill a TTree with date from a csv file. The Date in the csv file are same floats.
This is my code:
import ROOT
import numpy as np
#------------------------ CSV --------------------------
data = open("./Daten_csv/daten.csv", "r")
#------------------------ ROOTFILE --------------------------
outputfile = ROOT.TFile("./Daten_root/test.root", "RECREATE")
T1 = ROOT.TTree("T1","ROOT tree brachnes for T1")
T2 = ROOT.TTree("T2","ROOT tree brachnes for T2")
#------------------------ Variables -----------------------------
var1_T1 = np.zeros(1)
var2_T1 = np.zeros(1)
var3_T1 = np.zeros(1)
var4_T1 = np.zeros(1)
var5_T1 = np.zeros(1)
var6_T1 = np.zeros(1)
var7_T1 = np.zeros(1)
var1_T2 = np.zeros(1)
var2_T2 = np.zeros(1)
var3_T2 = np.zeros(1)
var4_T2 = np.zeros(1)
var5_T2 = np.zeros(1)
var6_T2 = np.zeros(1)
var7_T2 = np.zeros(1)
#-----------------------------Branches---------------------------------------
T1.Branch("var1_name",var1_T1,"I")
T1.Branch("var2_name",var2_T1,"I")
T1.Branch("var3_name",var3_T1,"I")
T1.Branch("var4_name",var4_T1,"I")
T1.Branch("var5_name",var5_T1,"I")
T1.Branch("var6_name",var6_T1,"I")
T1.Branch("var7_name",var7_T1,"I")
T2.Branch("var1_name",var1_T2,"I")
T2.Branch("var2_name",var2_T2,"I")
T2.Branch("var3_name",var3_T2,"I")
T2.Branch("var4_name",var4_T2,"I")
T2.Branch("var5_name",var5_T2,"I")
T2.Branch("var6_name",var6_T2,"I")
T2.Branch("var7_name",var7_T2,"I")
# I dont wanna have the first line from the csv
counter = 0
for line in data:
if counter == 0:
counter = 1
else:
# I the difference between T1 and T2 is stored in column 1 from the csv file
if float(line.rstrip().split(",")[0]) == 0:
var1_T1[0] = float(line.rstrip().split(",")[1])
var2_T1[0] = float(line.rstrip().split(",")[2])
var3_T1[0] = float(line.rstrip().split(",")[3])
var4_T1[0] = float(line.rstrip().split(",")[4])
var5_T1[0] = float(line.rstrip().split(",")[5])
var6_T1[0] = float(line.rstrip().split(",")[6])
var7_T1[0] = float(line.rstrip().split(",")[7])
T1.Fill()
else:
var1_T2[0] = float(line.rstrip().split(",")[1])
var2_T2[0] = float(line.rstrip().split(",")[2])
var3_T2[0] = float(line.rstrip().split(",")[3])
var4_T2[0] = float(line.rstrip().split(",")[4])
var5_T2[0] = float(line.rstrip().split(",")[5])
var6_T2[0] = float(line.rstrip().split(",")[6])
var7_T2[0] = float(line.rstrip().split(",")[7])
T2.Fill()
T1.Print()
T2.Print()
data.close()
outputfile.Write()
outputfile.Close()
The csv looks like this:
SeparationVar, Var1, Var2, Var3, Var4, Var5, Var6, Var7
0,88,55,2,2,2,2,3
0,88,55,2,2,2,2,3
1,88,67,1,2,1,4,2
0,88,67,2,2,4,4,3
0,88,55,2,2,2,2,3
0,88,57,2,2,2,2,3
0,88,55,2,2,2,2,3
0,88,78,1,2,1,2,2
0,87,54,2,2,2,2,3
0,87,54,2,2,2,2,3
0,87,82,1,1,1,3,2
0,87,70,1,1,3,1,1
0,87,74,2,2,3,3,3
0,87,50,2,2,2,3,2
0,87,81,2,2,2,3,2
0,87,54,2,2,2,2,3
0,87,54,2,2,2,2,3
0,87,54,2,2,2,2,3
0,87,54,2,2,3,3,3
1,87,50,2,2,2,3,2
0,87,77,1,2,1,3,2
1,87,69,1,2,2,3,2
0,86,53,2,2,2,2,3
0,86,53,2,2,2,2,3
0,86,46,2,2,3,2,1
0,86,53,2,2,2,2,3
0,86,75,2,1,2,3,2
0,86,64,1,2,3,2,1
0,86,53,2,2,2,2,3
0,86,53,2,2,2,2,3
0,86,53,2,2,2,2,3
0,85,52,2,2,2,2,3
0,86,53,2,2,2,2,3
0,86,53,2,2,2,2,3
0,86,53,2,2,2,2,3
0,86,53,2,2,2,2,3
0,85,52,2,2,2,2,3
1,87,54,2,2,3,3,3
0,86,53,2,2,2,2,3
The problem is now that the root file has just histograms with entry-times 0.
Is there something wrong with my code? If I am doing it like this:
import ROOT
import numpy as np
print "Writing a tree"
f = ROOT.TFile("tree.root", "recreate")
t = ROOT.TTree("name_of_ttree", "tree title")
n = np.zeros(1)
t.Branch('gauss', n, 'gauss/D')
for i in xrange(100000):
n[0] = ROOT.gRandom.Gaus()
t.Fill()
f.Write()
f.Close()
The Branch looks good.
Slayezzzz