pub fn tof_to_energy(tof_us: f64, flight_path_m: f64) -> f64Expand 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_usis unphysical — the unguarded formula squares the velocity, so a negative TOF would return a positive energy, andtof_us == 0would return+∞; - a non-positive
flight_path_mis equally unphysical —flight_path_m == 0makes 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_usorflight_path_mcannot 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.