jimmij
1
Hello,
I’m trying to do the following:
const Int_t nbins=2;
const Int_t nbins2=3;
struct mystruct
{
Double_t N[nbins][nbins2];
};
void func()
{
struct mystruct myone;
TTree tr("abc","tree");
tr.Branch("a",&nbins,"nbins/I");
tr.Branch("b",&nbins2,"nbins2/I");
tr.Branch("c",myone.N,"N[nbins][nbins2]/D");
myone.N[0][1]=4;
tr.Fill();
tr.Scan("N");
}
If N is 1D array such code works well. It also works well If I explicit write a dimensions of array:
tr.Branch("c",myone.N,"N[2][3]/D"); //instead of N[nbins][nbins2]
Is there a way to have 2D arrays and number of dimensions declared as a const variable?
pcanal
2
TTree’s leaflist mechanism only support one variable dimension (and several fixed dimensions).
Cheers,
Philippe.
pcanal
4
Hi,
If you really need a double variable array, you should use a higher level structure (for example a vector<vector >)
Cheers,
Philippe.
jimmij
5
Thanks for hint.
What about some workaround:
const Int_t nbins=2;
const Int_t nbins2=3;
const Int_t dim=nbins*nbins2;
struct mystruct
{
Double_t N[nbins][nbins2];
};
void wiocha()
{
struct mystruct myone;
TTree tr("abc","tree");
tr.Branch("a",&dim,"dim/I");
tr.Branch("b",myone.N,"N[dim]/D");
myone.N[0][0]=1;
myone.N[0][1]=2;
myone.N[0][2]=3;
myone.N[1][0]=4;
myone.N[1][1]=5;
myone.N[1][2]=6;
tr.Fill();
tr.Scan("N");
}
It seems to works ok.
May I expect some unexpected behavior?
pcanal
6
this is fine (but TTree::Draw will only know about one dimension)
Philippe
Hi,
If you say
tr.Branch(“c”,myone.N,“N[2][3]/D”);
works and
tr.Branch(“c”,myone.N,“N[nbins][nbins2]/D”);
doesn’t
try:
TString bvar(“N[”);
bvar += nbins;
bvar += “][”;
bvar += nbins2;
bvar += “]/D”;
tr.Branch(“c”,myone.N,bvar.Data());
I use this technique a lot.
A nice day to all,
Rui