From what I understand, all of the vtxTrkRef here belong to thePV by construction.
Your check of weight()>0 corresponds to selecting tracks with weights >= 1./255., just because the weight is stored as a short (1 byte).

If you want to preserve the functionality exactly, take out the loop over thePV tracks outside of the loop over all general tracks, 
and get the list of needed trackRefs. These needed trackRefs can then be checked later.
This should reduce the CPU use here by two orders of magnitude or more.