How to draw histogram from a leaf variable

Firstly, the root file name in your macro is not the one you shared. Anyway, if I correct it (to 3097_anasig_mc_002.root), I don’t get a crash, the macro finishes and I get:

If you look at the tree:

root [1] track->Print()
******************************************************************************
*Tree    :track     :                                                        *
*Entries :    11504 : Total =         9786239 bytes  File  Size =    5700944 *
*        :          : Tree compression factor =   1.71                       *
******************************************************************************
*Br    0 :indexmc   : indexmc/I                                              *
*Entries :    11504 : Total  Size=      46659 bytes  File Size  =       8926 *
*Baskets :        2 : Basket Size=      32000 bytes  Compression=   5.17     *
*............................................................................*
*Br    1 :pdgid     : pdgid[indexmc]/I                                       *
*Entries :    11504 : Total  Size=     364898 bytes  File Size  =     107722 *
*Baskets :       13 : Basket Size=      32000 bytes  Compression=   3.38     *
*............................................................................*
*Br    2 :motheridx : motheridx[indexmc]/I                                   *
*Entries :    11504 : Total  Size=     364966 bytes  File Size  =      73308 *
*Baskets :       13 : Basket Size=      32000 bytes  Compression=   4.97     *
*............................................................................*
etc.

pdgid, motheridx, etc are not “leaf variables inside the indexmc branch”; all of them are leaves (you can also see this on a TBrowser) and in fact pdgid and motheridx are vectors/arrays with size, at any given event, given by the value of indexmc at that event.
You can search this forum for posts about ways to read arrays or vectors from trees, or check out several ideas here: