  We derive the explicit expression for the Casimir energy between a sphere and
a 1D grating, in terms of the sphere and grating reflection matrices, and valid
for arbitrary materials, sphere radius, and grating geometric parameters. We
then numerically calculate the Casimir energy between a metallic (gold) sphere
and a dielectric (fused silica) lamellar grating at room temperature, and
explore its dependence on the sphere radius, grating-sphere separation, and
lateral displacement. We quantitatively investigate the geometrical dependence
of the interaction, which is sensitive to the grating height and filling
factor, and show how the sphere can be used as a local sensor of the Casimir
force geometric features. To this purpose we mostly concentrate on separations
and sphere radii of the same order of the grating parameters (here of the order
of one micrometer). We also investigate the lateral component of the Casimir
force, resulting from the absence of translational invariance. We compare our
results with those obtained within the proximity force approximation (PFA).
When applied to the sphere only, PFA overestimates the strength of the
attractive interaction, and we find that the discrepancy is larger in the
sphere-grating than in the sphere-plane geometry. On the other hand, when PFA
is applied to both sphere and grating, it provides a better estimate of the
exact results, simply because the effect of a single grating is underestimated,
thus leading to a partial compensation of errors.
