Hi Guys,
I’m trying to convert a phasespace file (binary, 4M histories, x/y/z/px/py etc) to a root file which much have the following leaf-list structure
PhaseSpaceTree
PhaseSpaceBranch
x
y
....
Between reading and writing the phasespace must be ordered on eventID (important).
While this seems easy enough, I’ve been struggling for the greater part of three days so any and all help would be appreciated. I’ve been working in python, but if someone could provide me with C code/help I could manage.
So far I’ve managed two things.
-
Convert the binary file (200MB) to a .root file within a few seconds. However, it’s only PhaseSpaceTree, and then the variables (x/y/z) as branches. No basket called PhaseSpaceBranch. Using numpy2root, so no branches (Maybe this is where my issue is).
-
Convert the binary file (200MB) to a correct setup with tree → branch → leaves. Done by using pyROOT to create the tree, then the branch, then for every row in a pandas sorted dataframe unpack the row, commit to root data structure, and fill the tree. Takes upwards of 10 mins.
So while option 2 works, it’s not a viable option (720 phasespaces). As it’s been bothering me for awhile, any help would be appreciated. I’ve pretty much exhausted google now.
Working, but snippet of slow code
gROOT.ProcessLine(
"struct data_t {\
Float_t x;\
...
Int_t PB_id;\
};" );
de = pandas.DataFrame(data)
data = ROOT.data_t()
f = TFile( 'testslowin.root', 'RECREATE' )
tree = TTree( 'PhaseSpaceTree', 'Branch recreated' )
tree.Branch( 'PhaseSpaceBranch', data, 'x/F:y/F:z/F:px/F:py/F:pz/F:Ekin/F:wepl/F:pdgID/I:trackID/I:event/I:PB_id/I' )
for row in de.iterrows():
series = row[1]
#print(series["x"])
px = series["py"]
py = series["py"]
pz = 1-py*py-px*px
data.x = series["x"] # assign as integer
data.y = series["y"]
data.z = series["z"]
data.px = px
data.py = py
data.pz = pz
data.Ekin = series["ekin"]
data.datawepl = series["w"]
data.pdgID = series["pdg"]
data.trackID = series["trackID"]
data.event = series["eventID"]
data.PB_id = series["parentID"]
tree.Fill()
tree.Print()
tree.Write()
ROOT Version: 6.24/02
Platform: Linux
Compiler: Not Provided