Saving array in root tree branch

Dear all,
I have problems with saving array into tree branch, and cannot resolve it on my own. From my perspective, I’m doing everything correctly. The part of the code is presented below:

fNMU = 40;
fTreeBMu->Branch("fEMuMC", fEMuMC, "fEMuMC[fNMu]/F");

While analyzing output root file, I’m getting warning:

Warning in <TBasket::ReadBasketBuffers>: basket:o6� has fNevBuf=206975230 but fEntryOffset=0, pos=6633, len=26707, fNbytes=1906419474, fObjlen=1565075932, trying to repair

and the needed tree turns out to be empty while merging several such root files, or not, but at the end useless to use as an input signal/background tree to TMVA. Can anyone give hint or help with how to look for further solution of this issue. What I clearly understand, the issue arises because of the arrays in the tree branch. Thank you!

If it is a “fixed size” array:
fTreeBMu->Branch("fEMuMC", fEMuMC, TString::Format("fEMuMC[%d]/F", fNMU));

Thanks @Wile_E_Coyote ! I forgot to mention. The array size is not fixed, but does not exceed 40. Therefore, first I declared fNMu and array in header file of my class:

Int_t fNMu;
Float_t     fEMuMC[40];

then initialized every element of array & fNMu with -1 in constructor (otherwise it gets some awful values). Maybe I should’ve initialized fNMu with 0. fNMu varies from event to event, so for every event the array size needed is different actually. And now I think maybe my declaration of 40 size arrays and assigning -1 initially affects my results of the analysis badly. But I hope that if I set tree branch in the following way:

fTreeBMu->Branch("fEMuMC", fEMuMC, TString::Format("fEMuMC[%d]/F", fNMU));

the rest of the array members will be ignored.

For “variable size” arrays, you need:

fTreeBMu->Branch("fNMu", &fNMu, "fNMu/I");
fTreeBMu->Branch("fEMuMC", fEMuMC, "fEMuMC[fNMu]/F");

Yes, initially I was doing this way, but in an output root file while accessing the branch I’m getting warning & while merging several root files, I’m getting empty tree, because these branches with arrays are not correct.

For every event, before you execute “fTreeBMu->Fill();”, you need to set the value of “fNMu” from 0 to 40 (-1 is not allowed).

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