Is there a way I can clear all the vectors in a struct at a time?
No, not really. But you can minimize the redundant code by putting all of this in a function:
void clear_data(data obj)
{
piplus.px.clear();
piplus.py.clear();
piplus.pz.clear();
piplus.energy.clear();
piplus.transmom.clear();
piplus.ip.clear();
piplus.ipsig.clear();
piplus.confidence();
} Then the long string of clears turns into:
clear_data(piplus);
clear_data(kminus);
clear_data(piminus);
clear_data(kplus); If you have a *plus and *minus object for every prefix then you can add another wrapper:
clear_data(data o1, data o2)
{
clear_data(o1);
clear_data(o2);
} And your code is minimized to:
clear_data(piplus, piminus);
clear_data(kplus, kminus);