Try something like this (see, for example, the TTree::Branch method description): tree.Branch("XELDET0",
&XELDET0[0],
TString::Format("XELDET0[%i]/F", nmax)); // a fixed size array
[quote=“Wile E. Coyote”]Try something like this (see, for example, the TTree::Branch method description): tree.Branch("XELDET0",
&XELDET0[0],
TString::Format("XELDET0[%i]/F", nmax)); // a fixed size array[/quote]
Ok - this “partially” works - I get the right distribution with also a “huge” spike on zero. Further, the entries appear to be 40k while should be 29k
The “XELDET0[nmax]/F” denotes a “variable size” array (and so, in advance of the “XELDET0” branch, you need an additional branch which keeps the “nmax” leaf).
In this case you should have something like (note: the address of XELDET0[0] must not change after you assigned it to a branch): const unsigned int kMax_nmax = some_value; // always make sure that nmax <= KMax_nmax
const unsigned int kMax_K = some_another_value; // always make sure that K <= KMax_K
float XELDETn[kMax_nmax][kMax_K], XELDET0[kMax_nmax];
The second argument in the “tree.Branch” call should be a pointer to the actual data, not to a string with a “name”.
See the TTree class description for what “cases” are available.
BTW. sprintf(tree_,“XELDET%i[%i]”,j); should generate a warning that the format string expects more matching arguments.
After you created the “tree” and added appropriate branches, for each “event”, simply assign values to all relevant variables (i.e. all XELDET0[0], …, XELDET0[nmax - 1]) and then call “tree.Fill()”.
No, I mean that I want to “fill” the branches in a loop, as the number of elements can change . So, I dont want to hardcode XELDET0[], XELDET1[] (as I might now know in advance how many elements will be used), rather than call & fill the trees whose name is following the XELDET0,XELDET1…XELDETelements using TString:Format (or similar) workflow like I described in my last msg.