Modifying values for one or a few branches in a TNtuple

I have seen examples of how to modify the contents of particular branches in a TTree, in particular this 2011 RootTalk exchange, Change content of TTree branch ,which creates a new TTree as a clone of the old one. I would like to do something similar for a simple TNtuple, but I’m somewhat hung up on the command “oldtree->SetBranchAddress(“event”,&event);”. Here event presumably refers to the top-level branch, i.e., the structure or class which defines the content of the tree. But a simple TNtuple doesn’t have such a class, so I’m not sure how to do the analogous thing. As a secondfary question, a clear explanation as to how this SetBranchAddress allows one to modify the cloned tree. Thanks very much.

Al Eisner

Hi,

the TNtuple is a specialised version of the TTree: what exactly prevents you to clone it and modify one or an arbitrary numbers of its branches as shown in the example you cite and this one Copying a branch from existing tree to a new one?

Cheers,
D

The problem in translating the procedure to a TNtuple is the SetBranchAddress line I noted. It refers to the top-level structure for the TTree, and so far as I can tell there is no named analog to that for a TNtuple, for which (I think) only the individual leaves are the branches. (The TNtuple was filled from an array of floats or doubles.) I don’t entirely understand the function of that SetBranchAddress command in the TTree case (I also asked about that in my message, but a bit garbled), but apparently it is the key to the method. Thanks.

What does:myntuple->GetListOfBranches()->ls();issues in your case?

Cheers,
Philippe.

Ah, good idea, Phillippe. At the top, before all the individual leaves, it gives me
OBJ: TObjArray TObjArray An array of objects : 0
So can I just use that? (I’ll have to figure out the precise syntax.) Still curious as to just what the SetBranchAddress is doing in this cloning context.

Thanks, Al Eisner

[quote]OBJ: TObjArray TObjArray An array of objects : 0
So can I just use that?[/quote]No … that is just the container of branches … Under that list should be some names (maybe) that you could use as parameter to SetBranchAddress … What was the output in your case?

Cheers,
Philippe.

Below that header it’s just a flat list of all the variable in the ntuple. An example line:
OBJ: TBranch BdeltaE BdeltaE : 0 at: 0x952f168

(Among this list are the few items I’d like to recompute.)

Thanks.

Any specific suggestion as to how to accomplish this? (See previous posts in thread for details.)
Or an explanation of just what the SetBranchAddress line does in the TTree analog to allow changing a value? Thanks again.

I posted this a couple of weeks ago.

“I have seen examples of how to modify the contents of particular branches in a TTree, in particular this 2011 RootTalk exchange, viewtopic.php?t=13586 ,which creates a new TTree as a clone of the old one. I would like to do something similar for a simple TNtuple, but I’m somewhat hung up on the command “oldtree->SetBranchAddress(“event”,&event);”. Here event presumably refers to the top-level branch, i.e., the structure or class which defines the content of the tree. But a simple TNtuple doesn’t have such a class, so I’m not sure how to do the analogous thing.”

I didn’t get a solution, but with some effort I worked something out. I did the SetBranchAddress using the relevant branch name from the varlist input when the TNtuple was originally created, e.g., if that name were “varx”, I use Float_t* varxptr = 0; then SetBranchAddress(“varx”,&varxptr), in the context of the method described as posted for a TTree. I tried casting the CloneTree() output to a TNtuple, but that didn’t work, because the Fill() method for a TNtuple is protected. So I finally figured out I could leave the new (cloned) ntuple as a TTree,. and that worked. Curiously, when I inspect the new file with interactive Root, that output tree is labelled as a TNtuple (like my original). Why is that? (It’s probably not all that important.)

I didn’t understand the reason for the AutoSave() after the end of the event loop in the posted TTree example. The method didn’t work until I added a Write() for the new ntuple (now tree), instead of AutoSave.

As a next step, I’d like to extract from each entry in the original ntuple an array of the variable values for use in computations (as opposed to fetching the quantities one at a time by name). Does the TNtuple::GeArgs() method do that? The documentation is a bit obscure. What if I’m using a TChain (derived from TNtuple’s in multiple files) instead?

Al Eisner