TTree: multiple variable length arrays

Hi,

I’d like to store several arrays in a tree, and the lengths of the arrays is variable. Thus,

	double var1[maxLength]; // first array to store
	double var2[maxLength]; // second array to store
	unsigned int var1n, var2n; // lengths of the arrays for a given event

	tree->Branch("var1n",&var1n,"var1f/i");
	tree->Branch("var2n",&var2n,"var2f/i");
	tree->Branch("var1",var1,"var1[var1f]/D");
	tree->Branch("var2",var2,"var2[var2f]/D");

This works fine.

Is it possible put var1n and var2n into the same branch (e.g. as an array)? I imagine something like this:

	double var1[maxLength]; // first array to store
	double var2[maxLength]; // second array to store
	unsigned int n[2]; // lengths of the arrays for a given event

	tree->Branch("n",n,"n[2]/i");
	tree->Branch("var1",var1,"var1[n[0]]/D");
	tree->Branch("var2",var2,"var2[n[1]]/D");

… but that doesn’t work.

So, the question is: Can something like this be done?

Motivation: I have many arrays (not just 2), and doing this would reduce the number of branches from 2N to N+1, making things much more tractable.

Thanks,
Peter

Hi Peter,

why not moving directly to std::vector then?
ROOT is able to handle it in a pretty optimised way and these day the stl is also very performant on basically all platforms.

Cheers,
Danilo

Hi Danilo,

good idea, thank you.

Cheers,
Peter