A novel invariant mass method to isolate resonance backgrounds from the chiral magnetic effect