  We show that an event-shape engineering based on the mean transverse momentum
of charged hadrons, $[p_t]$, provides an optimal handle on the strength of the
magnetic field created in central heavy-ion collisions at high energy. This is
established through quantitative evaluations of the correlation existing
between the event-by-event magnetic field produced by the spectator protons in
5.02 TeV Pb+Pb collisions and the event-by-event $[p_t]$ at a given collision
centrality. We argue that the event selection based on $[p_t]$ provides a
better handle on the magnetic field than the more traditional selection based
on the event ellipticities. Advantages brought by this new method for the
experimental search of the chiral magnetic effect are discussed.
