How to set up default value in Branch

Dear ROOT experts,

I created a code that aims to assign the specified value when entry number = -1 to each branch of TTree.
Following this code.

import ROOT as R
from array import array

def TreeClone(input_name, output_name, tree_name, enlist):
    fin = R.TFile.Open(input_name)
    intree = fin.Get(tree_name)
    fout = R.TFile(output_name,'recreate')
    run0 = array('i', [0])
    outtree = intree.CloneTree(0)
    ### Set defalut values for branch ###                                                                            
    for i in enlist:
        if i>=0:
        if i <0:
            run0 = -1

However, This code requires SetBrachAddress to be performed one branch at a time.
What ideas do you have to make sure that for every branch, a specific value corresponding to the type of the branch is assigned? (e.g. empty vector for vector, -1 for int)

Best regards,
Kosuke Kinoshita

Hi @K.Kinosh,
welcome on the ROOT forum!
To my understanding, what you’re trying to do is to clone your tree while changing the value of certain entries. Is it correct? can you please share how you set the variable enlist to pass in input to your function?


Thank you for replaying, Monica.
enlist is the list is included -1 (e.g. enlist = [1,2,-1,-1,3,4,5]).

You mention, I want to Clone the original TTree and change the value when the EntryNumber is -1.

Also, the reason for doing this is that we want to use two TTrees with different number of entries as one.

Best regards,
Kosuke Kinoshita

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