Skip to content
Snippets Groups Projects
Commit a420a5d8 authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Update documentation

parent 1166f2c7
No related branches found
No related tags found
No related merge requests found
......@@ -27,8 +27,11 @@ fn main() -> Result<(), OpossumError> {
})),
);
let i_bs = scenery.add_element("Beam splitter", BeamSplitter::new(0.5));
let filter_spectrum=Spectrum::from_csv("NE03B.csv")?;
let i_f = scenery.add_element("Filter", IdealFilter::new(FilterType::Spectrum(filter_spectrum))?);
let filter_spectrum = Spectrum::from_csv("NE03B.csv")?;
let i_f = scenery.add_element(
"Filter",
IdealFilter::new(FilterType::Spectrum(filter_spectrum))?,
);
let i_d1 = scenery.add_element("Detector 1", Detector::default());
scenery.connect_nodes(i_s1, "out1", i_bs, "input1")?;
......
......@@ -6,7 +6,7 @@ use crate::{
lightdata::{DataEnergy, LightData},
optic_node::{Dottable, LightResult, Optical},
optic_ports::OpticPorts,
spectrum::{unify_spectrum, Spectrum},
spectrum::{merge_spectra, Spectrum},
};
type Result<T> = std::result::Result<T, OpossumError>;
......@@ -67,8 +67,8 @@ impl BeamSplitter {
_ => return Err(OpossumError::Analysis("expected DataEnergy value".into())),
}
}
let out1_spec = unify_spectrum(out1_1_spectrum, out2_2_spectrum);
let out2_spec = unify_spectrum(out1_2_spectrum, out2_1_spectrum);
let out1_spec = merge_spectra(out1_1_spectrum, out2_2_spectrum);
let out2_spec = merge_spectra(out1_2_spectrum, out2_1_spectrum);
let mut out1_data: Option<LightData> = None;
let mut out2_data: Option<LightData> = None;
if let Some(out1_spec) = out1_spec {
......
......@@ -210,12 +210,7 @@ impl OpticScenery {
})
.collect::<HashMap<String, Option<LightData>>>()
}
fn set_outgoing_edge_data(
&mut self,
idx: NodeIndex,
port: String,
data: Option<LightData>,
) {
fn set_outgoing_edge_data(&mut self, idx: NodeIndex, port: String, data: Option<LightData>) {
let edges = self.g.edges_directed(idx, petgraph::Direction::Outgoing);
let edge_ref = edges
.into_iter()
......
......@@ -38,7 +38,7 @@ impl Spectrum {
}
if range.start >= range.end {
return Err(OpossumError::Spectrum(
"wavelength range must be in ascending order".into(),
"wavelength range must be in ascending order and not empty".into(),
));
}
if range.start <= Length::zero() || range.end <= Length::zero() {
......@@ -316,6 +316,13 @@ impl Spectrum {
.map(|d| (d.0 - d.1).clamp(0.0, f64::abs(d.0 - d.1)))
.collect();
}
/// Generate a plot of this [`Spectrum`].
///
/// Generate a x/y spectrum plot as SVG graphics with the given filename. This function is meant mainly for debugging purposes.
///
/// # Panics
///
/// ???
pub fn to_plot(&self, filename: &str) {
let root = SVGBackend::new(filename, (800, 600)).into_drawing_area();
root.fill(&WHITE).unwrap();
......@@ -326,7 +333,7 @@ impl Spectrum {
.margin(5)
.x_label_area_size(40)
.y_label_area_size(40)
.build_cartesian_2d(x_left * 1.0E9..x_right * 1.0E9, 0.0..y_top*1E-9)
.build_cartesian_2d(x_left * 1.0E9..x_right * 1.0E9, 0.0..y_top * 1E-9)
.unwrap();
chart
......@@ -341,7 +348,7 @@ impl Spectrum {
self.lambdas
.iter()
.zip(self.data.iter())
.map(|x| (*x.0 * 1.0E9, *x.1 *1E-9)), // y values are displayed in 1/nm
.map(|x| (*x.0 * 1.0E9, *x.1 * 1E-9)), // y values are displayed in 1/nm
&RED,
))
.unwrap();
......@@ -449,7 +456,13 @@ pub fn create_nd_glass_spectrum(energy: f64) -> Spectrum {
.unwrap();
s
}
pub fn unify_spectrum(s1: Option<Spectrum>, s2: Option<Spectrum>) -> Option<Spectrum> {
/// Helper function for adding two spectra.
///
/// This function allows for adding two (maybe non-existing = None) spectra with different bandwidth.
/// The resulting spectum is created such that both spectra are contained. The resolution corresponds
/// to the highest (average) resolution of both spectra. If one spectrum is `None` the other spectrum is
/// returned respectively. If both spectra a `None` then also `None`is returned.
pub fn merge_spectra(s1: Option<Spectrum>, s2: Option<Spectrum>) -> Option<Spectrum> {
if s1.is_none() && s2.is_none() {
None
} else if s1.is_some() && s2.is_none() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment