I create two TTree in one root file and assign some branches for trees.
myfile = ROOT.TFile.Open("3j3b.root","RECREATE")
mytree_sig = ROOT.TTree("sig","Signal")
mytree_bkg = ROOT.TTree("bkg","Background")
topFs = array.array('i',[0])
topFb = array.array('i',[0])
mytree_sig.Branch("jet_GBHInit_topHadronOriginFlag",topFs,"jet_GBHInit_topHadronOriginFlag_sig/I")
mytree_bkg.Branch("jet_GBHInit_topHadronOriginFlag",topFb,"jet_GBHInit_topHadronOriginFlag_bkg/I")
# I skipped codes of other branches that work well
for k in range(10000):
topFb[0] = origin[k]
topFs[0] = origin[k]
# Here origin is a list of integers
mytree_sig.Fill()
mytree_bkg.Fill()
mytree_sig.SetDirectory(0)
mytree_bkg.SetDirectory(0)
myfile.cd()
mytree_sig.Write()
mytree_bkg.Write()
myfile.Close()
However, I finally got four TTree (two repeated trees) and weird values (should be integers) for the branch.
So, check your values in origin[k]; if they are ok, try running only the lines in your example above and if those run well, then the problem should be in the lines you didn’t show above.
I print origin[k] just before writing them and nothing looks wrong.
Using ‘l’ instead keeps most values as integers, although some still are recorded as float values (but a different value!). It meets requirements of program anyway, so thank you!
Here I should have some ‘-99’ instead of ‘1.844e19’.
I noticed that ‘jet_GBHInit_topHadronOriginFlag’ has different basket number from other branches. Could it be a problem?
You have plenty "/F" (a 32 bit floating point Float_t) branches, one "/l" (a 64 bit unsigned integer ULong64_t) branch, and no any "/I" (a 32 bit signed integer Int_t) branches.
The first 15 branches are expected to be filled by float values, so I use "/F" for them. Only the last branch is expected to be filled by integers. I used "/I" initially and it returned weird output. Didn’t you suggest to use "/l" instead of "/I" ?