In your macro, you unconditionally access pointers without prior checking that they are not null (e.g. in mctrack_vec(*mctrack_handle) you do not check “mctrack_handle”).
You also unconditionally access vector elements without prior checking that its size is big enough (e.g. in a.at(0).X() in you do not check that a.size() > 0).
You can easily “reproduce” your error:
Thank you @Wile_E_Coyote. Indeed for many cases I found that a.size()==0 which causes this error. Now I simply used an IF condition to skip over a.size()==0 events.