Trying to read TLeafs (Tleaves?) containing variable length arrays, getting segfault

Version of root: ROOT 6.15/01
Version of madgraph: 2.6.5

The TTree I am working with is what is generated by running the madgraph tutorial with Pythia8 and Delphes enabled, limiting the number of events to 10. So that is generating p p > t t~. You can find it here https://mega.nz/#F!3PwQEAyR!fd_F-Rys68aFGEokEPRz-Q if it helps. If it print a section of the tree I can see;


root [31] tree->Print()
******************************************************************************
*Tree    :Delphes   : Analysis tree                                          *
*Entries :       10 : Total =         2637906 bytes  File  Size =     943112 *
*        :          : Tree compression factor =   2.66                       *
******************************************************************************
*Br    0 :Event     : Int_t Event_                                           *
*Entries :       10 : Total  Size=      11595 bytes  File Size  =        128 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.27     *
*............................................................................*
*Br    1 :Event.fUniqueID : UInt_t fUniqueID[Event_]                         *
*Entries :       10 : Total  Size=        782 bytes  File Size  =        135 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.28     *
*............................................................................*
*Br    2 :Event.fBits : UInt_t fBits[Event_]                                 *
*Entries :       10 : Total  Size=        762 bytes  File Size  =        135 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.25     *
*............................................................................*
*Br    3 :Event.Number : Long64_t Number[Event_]                             *
*Entries :       10 : Total  Size=        807 bytes  File Size  =        155 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.35     *
*............................................................................*
*Br    4 :Event.ReadTime : Float_t ReadTime[Event_]                          *
*Entries :       10 : Total  Size=        777 bytes  File Size  =        171 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.01     *
*............................................................................*
*Br    5 :Event.ProcTime : Float_t ProcTime[Event_]                          *
*Entries :       10 : Total  Size=        777 bytes  File Size  =        172 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.00     *
*............................................................................*
*Br    6 :Event.ProcessID : Int_t ProcessID[Event_]                          *
*Entries :       10 : Total  Size=        782 bytes  File Size  =        135 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.28     *
*............................................................................*
*Br    7 :Event.MPI : Int_t MPI[Event_]                                      *
*Entries :       10 : Total  Size=        752 bytes  File Size  =        131 *
*Baskets :        1 : Basket Size=      64000 bytes  Compression=   1.27     *
*............................................................................*
*Br    8 :Event.Weight : Float_t Weight[Event_]                              *
*Entries :       10 : Total  Size=        767 bytes  File Size  =        137 *

My aim is to be able to connect particles in the .root file to particles in the .lhe file, so this requires iterating over particles individually.

Variables of fixed size i do not have a problem reading. For example;

*............................................................................*                                 
*Br   48 :Particle_size : Particle_size/I                                    *                                 
*Entries :       10 : Total  Size=        644 bytes  File Size  =        123 *                                 
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.00     *                                 
*............................................................................*

Can be read like;

int particle_size_here;
tree->SetBranchAddress("Particle_size", &particle_size_here);
tree->GetEvent(0);
cout<< particle_size_here
returns 1879    

Getting particle PID is not working so well, however;

*............................................................................*                                 
*Br   23 :Particle.PID : Int_t PID[Particle_]                                *                                 
*Entries :       10 : Total  Size=      67007 bytes  File Size  =      12063 *                                 
*Baskets :        2 : Basket Size=      64000 bytes  Compression=   5.50     *                                 
*............................................................................*   

I have tried a number of things here, most of them result in no data getting put into the variable, or a segfault. For example;

Int_t particle_PID_array[2000];  // For event 0 this ought to be larg enough since it exceeds particle size
tree->SetBranchAddress("Particle.PID", &particle_PID_array);
tree->GetEntry(0)
*** seg fault ***

I feel like this is probably a simple misunderstanding of how to work with pointers/memory but I’m not getting it. I have tried lots of small variations in syntax to no avail. Please can someone give me a minimal working example?

If you don’t know how to deal with your tree, see how various flavours of automatically generated “analysis skeletons” deal with it.