Nested tree structure

Hello people,

I would like to setup a “nested/deep” tree structure for parallel processing on GPU…
Actually up to now, I had a quite basic usage of trees (int, double, vectors, and some custom structure leaves).

I would like to setup a tree structure with “nested” branches as following:

  • “id” branch
  • “prefix” branch (should be string)
  • “array1d” holding a 1D vector (non-fixed size, expecting about 1 to 100 entries)
  • “h2d” holding 2D histograms (possibly 1 to 10 histograms)
  • “subtree” nested tree structure (one entry per histogram that I would like to access using TTree::GetEntry somehow)

My issue is rather about this complex subtree structure.

Anybody has some suggestion how I could perform this ?
Or perhaps how I should better organize my tree ?

Thank you very much
Marco

Helping a bit, but not sure I can achieve advanced structures

Hi @meyerma ,

TTree branches can contain arbitrary C++ types, so one solution is to use branches that contain complex types which will in turn correspond to sub-branches in the TTree (up to some maximum nesting depth after which nested data members won’t be accessible directly as branches). For this you can check Trees - ROOT and I/O of custom classes - ROOT .

The other option is to manually create your branch hierarchy, I’m not sure what the best way to do that is, @pcanal might be able to point to an example.

Cheers,
Enrico

Hi @eguiraud

In the end, my main goal is to be able to see the sub-structure using TBrowser.
I am trying to learn about this splitlevel at the moment looking at your links.
I think this and custom structure might be what I am looking for :slight_smile:

I have also read about Tree “folder”, in some old root documentation.

Thank you so much for your advices again.
M.

Here is what I ended with :slight_smile:

 struct Example
 {
       Int_t id;
       char* prefix;
       TLorentzVector lv_dummy;

       std::vector<int> test;

       struct SubExample { Float_t x,y,z; };

       struct SubExample ex1;
            struct SubExample ex2;
};

TTree *fTree = new TTree(this->GetUniqueID("data"), "");

            static struct Example MyExample1;

            MyExample1.id = 1;
            MyExample1.prefix = "str";
            MyExample1.ex1 = {0,0,0};
            MyExample1.ex2 = {1,1,1};
            MyExample1.lv_dummy.SetPxPyPzE(0,0,100,100);

            fTree->Branch("MyExample1.", "Example", &MyExample1);

            fTree->Fill();
            fTree->Print();

Additionally, I declared the structure in the LinkDef.h file.
It did the job because I can now see substructure. I adapted the subtree branch in a different way.

This is more of a confort issue, but I would like to use my custom structure to build the tree structure.

Let say I have a nested structure like:

struct {
   branch1;
   branch2;
   branch3;
}

At the moment, I have a tree like:

"master.branch1"
"master.branch2"
"master.branch3"

However I would like to go with:

"branch1"
"branch2"
"branch3"

Any idea how to do this without setting each branch individually ?

Hi @meyerma ,

TBrowser should be able to show pretty much any data stored in TTrees, you should be covered no matter what you do.

I don’t think that’s possible, to have individual branches you need to create individual branches.

Cheers,
Enrico

This is the recommended setting as it avoid confusion if you had more than one type of objects (i.e. more than one top level branch) in your TTree (where the distinct class may have similar or identical data member names).

However I would like to go with:

If you mean just the names, you can remove the trailing dot and use:

fTree->Branch("MyExample1", "Example", &MyExample1);

but it will still have a top level branch (visible in the TBrowser named “MyExample1”

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