Reading vector of structs from TTree


I have filled a TTree according to the struct ‘particle’, which contains a vector of structs of the type ‘cluster’:

struct cluster {
    Double_t x0, y0, z0, t0, ec;
    Int_t nc;
    std::vector<Double_t> x1, y1, z1, t1, e1, vx1, vy1, vz1;

struct particle {
    TString type;
    Double_t x0, y0, z0, vx0, vy0, vz0, e0, t0;
    Int_t noClusters;
    Double_t lambda, stoppingPower;
    std::vector<cluster> clusters;

For filling the TTree, I have made the dictionaries for both particle and the cluster structures. Now I want to read the tree (e.g. the size of the cluster vector) with the following code:

gROOT->ProcessLine(".L loader.c+"); // loading dictionaries
TTree *pTree = (TTree*)f->Get("pTree"); // read TTree from file
std::vector<cluster> *c;
pTree->SetBranchAddress("clusters", &c);

Int_t it = (Int_t)pTree->GetEntries();
for(int i=0; i<it; i++) {

    std::cout << c.size() std::endl;

When I run this code, ROOT crashes with the following errors:

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
#5  0x00007f66937e1d60 in ROOT::TCollectionProxyInfo::Pushback<std::vector<cluster, std::allocator<cluster> > >::resize(void*, unsigned long) () from /afs/
#6  0x00007f669c3df070 in TGenCollectionProxy::Allocate(unsigned int, bool) () from /afs/
#7  0x00007f669aa9a8e0 in TBranchElement::ReadLeavesCollection(TBuffer&) () from /afs/
#8  0x00007f669aa91aaf in TBranch::GetEntry(long long, int) () from /afs/
#9  0x00007f669aa9cba6 in TBranchElement::GetEntry(long long, int) () from /afs/
#10 0x00007f669aadbe8c in TTree::GetEntry(long long, int) () from /afs/
#11 0x00000000004185aa in main ()

Does anybody know what I’m doing wrong?
I’m using ROOT version 5.34/10 on lxplus.


Hi Jan,

could you post your loader.c file and the code you wrote to fill the tree and write it in the root file?


std::vector<cluster> *c = 0;
std::vector<cluster> *c = new std::vector<cluster>;
std::cout << c->size() << std::endl;

Thanks, the initialization of the std::vector<cluster> did the job!



Could someone point the code please? i have a similar issue when booking an std vector of struct inside AthAlgorithm code.


Hi @mhufnage,

See the fix in the post above, i.e. Reading vector of structs from TTree - #3 by Wile_E_Coyote. Otherwise, feel free to open a new topic.