Create a TTree from looping over histograms

Dear Co-rooters,

It’s the first time that I am trying to create a TTree and I am a bit confused…

The idea is the following : I have a root file that contains histograms. I want to loop over them in order to make some calculations and store those in variables (say x, y, z), in a new root file.

This new root file will contain one TTree and some TBranches, each one corresponding to the aforementioned variables(i.e. x, y, z).

The thing is that I see that there are several cases on how to construct TBranches ( ), but I am very confused on how to fill them.

For instance TBranch *branch = tree->Branch(branchname, &p_object, bufsize, splitlevel) how can I choose the address, or the bufsize?

Any idea or advice on how to do it?

Thanks in advance!

grep -r ‘->Branch’ ${ROOTSYS}/tutorials/tree/

This gives nothing on lxplus.
The ROOTSYS variable is not defined…

See the “tutorials” subdirectory of your ROOT distribution (binary or source code).

How can I do that?

Sorry, but I’ve never done something like that before…

You can also find all the tree tutorials on the web: … _tree.html
Note if your you tree is that simple an Tuple might be enough. Like the one created here:

From the “tree tutorials on the web”, see:

Note that the tree tutorials on the web have a better look here: … _tree.html as the macro are executed when the doc is built every night and their output are shown. :slight_smile:

Olivier gives links to ROOT 6 tutorials while I give ROOT 5. There is no guarantee that ROOT 6 tutorials work with ROOT 5 while the opposite should be the case (in principle, you should be able to find ROOT tutorials for your own version in your “${ROOTSYS}/tutorials” subdirectory).

In that particular case the tutorials are the same. The ROOT 6 version on the web, showing the output, makes them easier to scan to find what you are looking for. (and they are guarantied to work with 6 as they are run every night to generate the doc). As Pepe said you can find all of them as .C files in ${ROOTSYS}/tutorials/tree.