Joint analysis of gravitational-wave and electromagnetic data of mergers: breaking an afterglow model degeneracy in GW170817 and in future events