Skip to main content

tof_to_energy

Function tof_to_energy 

Source
pub fn tof_to_energy(tof_us: f64, flight_path_m: f64) -> f64
Expand description

Convert neutron time-of-flight (μs) and flight path (m) to energy (eV).

E = ½·m_n·(L/t)²

§Domain contract

Returns f64::NAN for out-of-domain input rather than a misleading value. Both arguments must be finite and strictly positive:

  • a non-positive tof_us is unphysical — the unguarded formula squares the velocity, so a negative TOF would return a positive energy, and tof_us == 0 would return +∞;
  • a non-positive flight_path_m is equally unphysical — flight_path_m == 0 makes the velocity (and energy) 0, and a negative flight path would (after squaring) return a positive energy, masking a bad detector geometry the same way a negative TOF would;
  • a non-finite tof_us or flight_path_m cannot map to a real energy.

Callers that need to surface bad input as an error (e.g. the PyO3 boundary) check the input before calling or test the result with is_finite(); the in-crate callers (nereids_io::tof, the GUI) already guard tof > 0 && finite up-front, so this NaN sentinel never fires on valid data.