Optimized process for the fabrication of mesoscopic magnetic structures