Dear ROOTers,
I am trying to perform a very simple task but keep getting the wrong outcome: using pyROOT to save a numpy array into a new TBranch. This is my code:
file = ROOT.TFile("trial.root","UPDATE")
tree = TTree("OutTree","OutTree")
json_file = open("bkg_preds.json", "r")
bare_output = json_file.read()
string_bare_output = json.loads(bare_output)
list_bare_output = ast.literal_eval(string_bare_output)
array_bare_output = np.array(list_bare_output)
tree.Branch("GNN_Score", array_bare_output, "GNN_Score/D")
for i in range(len(array_bare_output)):
tree.Fill()
file.Write()
file.Close()
The TBranch is wrongly filled with only-zeros. I’ve noticed that when the TBranch is set e.g. as
tree.Branch("GNN_Score", array_bare_output, "GNN_Score[128]/D")
the shape of the information in the branch looks “better” (but still wrong) where the nentries is clearly wrong (it is equal to 128*len(array_bare_output)).
The information being plotted should look roughly as (the background distribution):

whereas upon writing to the TBranch I get:

and with the [128]/D option (for example) I get:

How can this be achieved as simply as possible? Getting the right information and of course keeping the right number of entries?
Many thanks in advance for any help.
Roy
_ROOT Version: 6.22/06
_Platform: linuxx8664
_Compiler: gcc