The optimum target is one that favors producing the particles of interest, but does not absorb them. E872 needs neutrinos, elementary particles that react with matter so little that they can travel through the earth itself without being significantly absorbed. That experiment's target consists of a thick block of tungsten, in which pions materialize and decay into neutrinos. The rest of the beamline is mostly absorbent shielding, to take everything but the neutrinos out of the beam. E831, on the other hand, needs a beam of photons that would be completely absorbed by a metal target.
Experimenters focus the primary proton beam down to a narrow spot illuminating their target.
Again, they make trade-offs. The smallest spots give the most intense beams, but focusing the bems too strongly could melt the target. Directly downstream from the target, experimenters select for the particles they're interested in. A magnetic field sweeps charged particles out of the way. The neutral kaons are not affected by magnetic fields, and emerge in all directions.