The problem of the cosmic-ray induced background in neutral pion production measurements with barium fluoride multidetectors is discussed. As a reference example, the response to cosmic rays of the MEDEA photon spectrometer is studied. The interaction of the cosmic radiation with the experimental filter has been treated by means of full Monte Carlo computer simulations with the GEANT3 code. The results of the simulations are compared with experimental data and general criteria to minimize the cosmic background are discussed.