Skip to main content

laddu_core/variables/
mandelstam.rs

1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4
5use super::Variable;
6use crate::{
7    data::{DatasetMetadata, EventLike},
8    quantum::Channel,
9    reaction::Reaction,
10    LadduResult,
11};
12
13/// A struct used to calculate Mandelstam variables (`s`, `t`, or `u`).
14#[derive(Clone, Debug, Serialize, Deserialize)]
15pub struct Mandelstam {
16    reaction: Reaction,
17    channel: Channel,
18}
19
20impl Display for Mandelstam {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        write!(f, "Mandelstam(channel={})", self.channel)
23    }
24}
25
26impl Mandelstam {
27    /// Constructs the Mandelstam variable for the given `channel` using the supplied [`Reaction`].
28    pub fn new(reaction: Reaction, channel: Channel) -> Self {
29        Self { reaction, channel }
30    }
31}
32
33#[typetag::serde]
34impl Variable for Mandelstam {
35    fn bind(&mut self, metadata: &DatasetMetadata) -> LadduResult<()> {
36        let _ = metadata;
37        Ok(())
38    }
39
40    fn value(&self, event: &dyn EventLike) -> f64 {
41        let resolved = self
42            .reaction
43            .resolve_two_to_two(event)
44            .unwrap_or_else(|err| panic!("failed to evaluate reaction Mandelstam: {err}"));
45        match self.channel {
46            Channel::S => resolved.s(),
47            Channel::T => resolved.t(),
48            Channel::U => resolved.u(),
49        }
50    }
51}