Segfault, strange behavior with TTree::SetBranchAddress, GetEntry

I wrote a script, attached below, that copies the some of the content of a file’s existing tree into another tree in such a way that for branches whose values is a TVectorT, each the entry in the vector get their own event.

makeObEventTree.C (3.95 KB)

To do this, I’m making a lot of calls to TTree::SetBranchAddress,Branch, including for each variable in objVars (lines 37-88). I noticed that if I include all of these variables, there is a segfault. HOWEVER, if I comment out most of them and only leave a couple, the program runs fine and the new tree is created.

Also, if I comment out line 132 treeR->GetEntry(event), then there is no crash. Additionally, running it on different root files generated similar to the attached one, this program often runs fine and creates a good tree. I’m really stumped as to why this is occurring.

Thanks,
Sri
histo_TTJets_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_1.root (1.8 MB)

Hi Sri,

The problem is that one of the assumption in your script does not hold for this file. Namely:

136 for(int obj=0; obj < objValues[0]-size(); obj++){ 137 for(int j=0; j < objVars.size(); j++){ 138 allVals[globalVars.size()+j] = (*objValues[j])[obj]; 139 } assumes that for all ‘j’ the value of objValues[j]->size() is less than objValues[0]-size().

For event == 0 and j == 22, this is unfortunately incorrect as the value of objValues[22]->size() is zero.

Cheers,
Philippe.