How to read an array with variable dimension from a tree?

I have a “leaf” in the tree tau_N of int type, and array tau_a[tau_N] of floats. So the dimension of tau_a[tau_N] varies (in my case between 0 and 6). I’m tring to acces the values stored in tau_a[tau_N].

Example of what i tried:

#include <iostream>
#if !defined(__CINT__) || defined(__MAKECINT__)
#include <TFile.h>
#include <TTree.h>
#include <TH1F.h>
#include <TBranch.h>

TFile *f;
TTree *myTree;

Int_t t, N, A;
Int_t a[10];        //this can be the problem

void ReadFile(){

void SumE(){
	myTree = (TTree*)f->Get("Cn/t1000");
	TBranch *Brt=myTree->GetBranch("tau_N");  // this works
	TBranch *Bracc = myTree->GetBranch("tau_a");  // may be those two lines are wrong ?
	N= myTree->GetEntries();
	for (Int_t i=0;i<N;i++) {
		for (int j=0;j<t;j++) {
			if (a[j]) {A++;}         // counting how many values of the array a are non zero
		cout << A << " , " << endl;


thanks for any help, asen.
PS: I’m not very skilled in C++ so pls. some simple solutions :smiley:

What you do should work. What is the problem?
Please post a small file to test your problem.


extracting the example form longer code I’ve chanded the names of some variables and actualy the vrong variable name was the problem. Instead of

Int_t a[10];

in my original code there was

Int_t accept[10];

OK, seems like accept is not the best name for a variable. :blush: