Is it possible to nest trees?

I’ve had a bit more of a think about my problem (reposted below) after reading some more of the documentation.

Basically I want to be able to have a set of trees - with identical structure. I want to be able to select any or all of the trees and then select any or all of the branches of the selected trees. I can think of the following possible ways to do this, but I’m not sure which will be the best (most efficient/fastest access). Maybe there are other ways I haven’t thought of…

  1. Is the best way to do this to nest trees ? Is this posssible ? (i.e. can a tree have an entry which is in turn a tree ?)

  2. Should I store the individual trees in a container ? If so which would be most suitable (TClonesArray, TObjArray) ?

  3. Could I store the trees in folders ? How would I go about doing this ?

  4. Should the trees be stored in seperate root files and chained ? (This seems to me at first sight to be inefficient - I will end up with a LOT of files)

Any help very much appreciated,

elc


My previous post


Hi,
I’m relatively new to root - using 3.10/01 WIN32GDK on XP

basically my data is a series of different runs (around 200 different setups), each identified by a string, and then many events in each run, each event is described by seven pieces of data.

I have structured my tree as eight branches - one for the run name and seven others for each event field, eg.

tree->Branch(“Run”,&Run,“Run/C”);

for the runs and e.g.

tree->Branch(“dow”,&dow,“dow/I”);

for one of the data fields.

I want to do the same analysis on each run, sometimes seperately for testing, sometimes for each run in turn in one batch job, and sometimes to look at some properties of all runs in one analysis.

I use something like

sprintf(query1, “dow > 5 && Run== “%s””, run);
tree->Draw(“swp>> tdg”,query1,"");

to fill histos for my analysis.

The problem is when i use the query above to look at the data for a particular run it takes a very long time as (I think) it scans all the runs. Can I make it read only one run ? Do i need to split the “Run” branch ?
If so how do i select a particular run name (subbranch) ? SetBranch ?

Would i have to put my runs in seperate root files ? I’d much rather not do this if possible.

I hope this makes sense, please let me know if not,

many thanks in advance,

elc

[quote=“elc”]I’ve had a bit more of a think about my problem (reposted below) after reading some more of the documentation.

Basically I want to be able to have a set of trees - with identical structure. I want to be able to select any or all of the trees and then select any or all of the branches of the selected trees. I can think of the following possible ways to do this, but I’m not sure which will be the best (most efficient/fastest access). Maybe there are other ways I haven’t thought of…

  1. Is the best way to do this to nest trees ? Is this posssible ? (i.e. can a tree have an entry which is in turn a tree ?)

If your trees have identical structure, you can group them via a TChain. A TChain
has a list of files or TChains (recursive).
Semantics of a TChain and TTree are the same.

  1. Should I store the individual trees in a container ? If so which would be most suitable (TClonesArray, TObjArray) ?

Well, this depends on your object model.
Typically TClonesArray will give you the best performance & functionality. See an example in $ROOTSYS/test/Event.h,cxx

  1. Could I store the trees in folders ? How would I go about doing this ?

You store Trees into files. Files may have subdirectories like a file system.
A file or directory may contain one or more Trees. Most users store one single tree per file.

  1. Should the trees be stored in seperate root files and chained ? (This seems to me at first sight to be inefficient - I will end up with a LOT of files)

It is up to you. You can store each run as a new Tree in a separate file or open a previous file in update mode and continue to fill your Tree. The first mode is recommended if you have to work in a parallel environment and do not want to manage concurrent access to the same file.

Rene

Any help very much appreciated,

elc


My previous post


Hi,
I’m relatively new to root - using 3.10/01 WIN32GDK on XP

basically my data is a series of different runs (around 200 different setups), each identified by a string, and then many events in each run, each event is described by seven pieces of data.

I have structured my tree as eight branches - one for the run name and seven others for each event field, eg.

tree->Branch(“Run”,&Run,“Run/C”);

for the runs and e.g.

tree->Branch(“dow”,&dow,“dow/I”);

for one of the data fields.

I want to do the same analysis on each run, sometimes seperately for testing, sometimes for each run in turn in one batch job, and sometimes to look at some properties of all runs in one analysis.

I use something like

sprintf(query1, “dow > 5 && Run== “%s””, run);
tree->Draw(“swp>> tdg”,query1,"");

to fill histos for my analysis.

The problem is when i use the query above to look at the data for a particular run it takes a very long time as (I think) it scans all the runs. Can I make it read only one run ? Do i need to split the “Run” branch ?
If so how do i select a particular run name (subbranch) ? SetBranch ?

Would i have to put my runs in seperate root files ? I’d much rather not do this if possible.

I hope this makes sense, please let me know if not,

many thanks in advance,

elc[/quote]

That’s exactly what I needed. Looks like chains are the best solution for my data. Thank you very much for prompt reply,

elc