Issues copying the format of a tree

I am trying to take a subset of events from one tree and enter the data into a tree matching the format of a different one. When I try to use the tree I made in a ML algorithm someone else made (that runs on the tree whose format I am trying to copy), I get an error. I am able to access the entries and values in the tree I made, but the results from File.ls() are slightly different between the two trees.

The tree I wanted to copy the format of produces this:

TFile**		../abcdnn-master/data/target_data.root	
 TFile*		../abcdnn-master/data/target_data.root	
  KEY: TTree	Events;1

My tree produces this:

TFile**		target_data.root	
 TFile*		target_data.root	
  KEY: TTree	Events;1	target_data

Below is the code I used to make the tree. I am guessing the issue has to do with the title but I get an error if I try to just take it out so I don’t know what to do.

class ToyTree:
    def __init__(self, name):
        self.name = name
        self.f = ROOT.TFile(name+".root","RECREATE")
        self.t = ROOT.TTree("Events", name)
        self.nJet = array('i', [0])
        self.nbJet = array('i', [0])
        self.BDT_disc = array('f', [0])
        self.ht = array('f', [0])
        self.met = array('f', [0])
        self.bjht = array('f', [0])
        self.sphericity = array('f', [0])
        self.xsecWeight = array('f', [0])
        self.t.Branch('nJet', self.nJet, 'nJets/I')
        self.t.Branch('nbJet', self.nbJet, 'nbJets/I')
        self.t.Branch('BDT_disc', self.BDT_disc, 'BDT_disc/F')
        self.t.Branch('ht', self.ht, 'ht/F')
        self.t.Branch('met', self.met, 'met/F')
        self.t.Branch('bjht', self.bjht, 'bjht/F')
        self.t.Branch('sphericity', self.sphericity, 'sphericity/F')
        self.t.Branch('xsecWeight', self.xsecWeight, 'xsecWeight/F')
    def Fill(self, event_data):
        self.nJet[0] = event_data[0]
        self.nbJet[0] = event_data[1]
        self.BDT_disc[0] = event_data[2]
        self.ht[0] = event_data[3]
        self.met[0] = event_data[4]
        self.bjht[0] = event_data[5]
        self.sphericity[0] = event_data[6]
        self.xsecWeight[0] = event_data[7]
        self.t.Fill()
    def Write(self):
        print(self.name+".root:",self.t.GetEntries()," entries")
        self.f.Write()
        self.f.Close()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

Hi @Trevor_Russell ,
sorry for the high latency, I am afraid the question is a bit too vague.

What is the error you get exactly, how do you run that code, and what is your ROOT version and operating system?

Cheers,
Enrico

This topic was automatically closed after 12 days. New replies are no longer allowed.