Is this loop over tracks really necessary?
Just call w = vtx.trackWeight(trackBaseRef);
The weight will be 0 if the track is not in the vertex list.