In a charged-particle-beam (CPB) optical system situated inside a column that extends along an optical axis, a device for reducing, by cancellation, a magnetic field external to the column that otherwise would extend to inside the column, so as to magnetically shield the CPB optical system from the external magnetic field, the device comprising an active-canceler coil set situated at an axial position relative to the column and adjacent a wall of the column so as not to obstruct a trajectory of a charged particle beam propagating in the column, the coil set comprising at least one electrically energizable coil that, when electrically energized, produces a respective magnetic field of a direction and magnitude sufficient for canceling at least a portion of the external magnetic field.