Skip to content

Commit 2394b98

Browse files
committed
better cut ui and functions
modified: src/histoer/histo2d/plot_settings.rs modified: src/histoer/histogrammer.rs modified: src/histogram_scripter/histogram_script.rs modified: src/histogram_scripter/manual_histogram_scripts.rs
1 parent fc8ff2e commit 2394b98

File tree

4 files changed

+96
-25
lines changed

4 files changed

+96
-25
lines changed

src/histoer/histo2d/plot_settings.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// use crate::cutter::Cut::HistogramCut;
21
use crate::histoer::cuts::Cut2D;
32

43
use crate::egui_plot_stuff::egui_plot_settings::EguiPlotSettings;

src/histoer/histogrammer.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -908,22 +908,16 @@ impl Histogrammer {
908908
log::info!("Reorganization complete.");
909909
}
910910

911-
pub fn retrieve_active_cuts(&self) {
912-
// for (_id, tile) in self.tree.tiles.iter() {
913-
// if let egui_tiles::Tile::Pane(Pane::Histogram2D(hist)) = tile {
914-
// let hist = hist.lock().unwrap();
915-
// let active_cuts = hist.plot_settings.cuts.clone();
916-
917-
// // Update cuts with correct column names and avoid duplicates
918-
// for mut new_cut in active_cuts.cuts {
919-
// // Set the correct column names in the Cut struct
920-
// new_cut.x_column = hist.plot_settings.cuts.x_column.clone();
921-
// new_cut.y_column = hist.plot_settings.cuts.y_column.clone();
922-
923-
// cut_handler.cuts.push(new_cut);
924-
// }
925-
// }
926-
// }
911+
pub fn retrieve_active_2d_cuts(&self) {
912+
let mut active_cuts = Vec::new();
913+
for (_id, tile) in self.tree.tiles.iter() {
914+
if let egui_tiles::Tile::Pane(Pane::Histogram2D(hist)) = tile {
915+
let hist = hist.lock().unwrap();
916+
for cut in &hist.plot_settings.cuts {
917+
active_cuts.push(cut.clone());
918+
}
919+
}
920+
}
927921
}
928922
}
929923

src/histogram_scripter/histogram_script.rs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl HistogramScript {
114114
ui.label("Custom Histogram Scripts");
115115
ui.horizontal(|ui| {
116116
if ui.button("SE-SPS").clicked() {
117-
let (columns, histograms) = sps_histograms();
117+
let (columns, histograms, cuts) = sps_histograms();
118118
for histogram in histograms {
119119
match &histogram {
120120
Configs::Hist1D(histo1d) => {
@@ -136,6 +136,8 @@ impl HistogramScript {
136136
self.new_columns.push((expression, alias));
137137
}
138138
}
139+
140+
self.cuts = cuts;
139141
}
140142

141143
ui.separator();
@@ -202,7 +204,7 @@ impl HistogramScript {
202204
.enumerate()
203205
.for_each(|(i, cut)| match cut {
204206
Cut::Cut1D(_) => cuts_1d.push((i, cut)),
205-
Cut::Cut2D(cut2d) => cuts_2d.push((i, cut2d)),
207+
Cut::Cut2D(_) => cuts_2d.push((i, cut)),
206208
});
207209

208210
// Render 1D Cuts Table
@@ -227,8 +229,39 @@ impl HistogramScript {
227229
for (index, cut1d) in cuts_1d {
228230
body.row(18.0, |mut row| {
229231
cut1d.table_row(&mut row);
232+
230233
row.col(|ui| {
231234
ui.horizontal(|ui| {
235+
if ui.button("Apply to All").clicked() {
236+
for hist_config in &mut self.hist_configs {
237+
match hist_config {
238+
Configs::Hist1D(hist1d) => {
239+
if !hist1d.cuts.contains(cut1d) {
240+
hist1d.cuts.push(cut1d.clone());
241+
}
242+
}
243+
Configs::Hist2D(hist2d) => {
244+
if !hist2d.cuts.contains(cut1d) {
245+
hist2d.cuts.push(cut1d.clone());
246+
}
247+
}
248+
}
249+
}
250+
}
251+
252+
if ui.button("Remove from All").clicked() {
253+
for hist_config in &mut self.hist_configs {
254+
match hist_config {
255+
Configs::Hist1D(hist1d) => {
256+
hist1d.cuts.retain(|cut| cut != cut1d);
257+
}
258+
Configs::Hist2D(hist2d) => {
259+
hist2d.cuts.retain(|cut| cut != cut1d);
260+
}
261+
}
262+
}
263+
}
264+
232265
if ui.button("X").clicked() {
233266
indices_to_remove_cut.push(index);
234267
}
@@ -266,6 +299,36 @@ impl HistogramScript {
266299
cut2d.table_row(&mut row);
267300
row.col(|ui| {
268301
ui.horizontal(|ui| {
302+
if ui.button("Apply to All").clicked() {
303+
for hist_config in &mut self.hist_configs {
304+
match hist_config {
305+
Configs::Hist1D(hist1d) => {
306+
if !hist1d.cuts.contains(cut2d) {
307+
hist1d.cuts.push(cut2d.clone());
308+
}
309+
}
310+
Configs::Hist2D(hist2d) => {
311+
if !hist2d.cuts.contains(cut2d) {
312+
hist2d.cuts.push(cut2d.clone());
313+
}
314+
}
315+
}
316+
}
317+
}
318+
319+
if ui.button("Remove from All").clicked() {
320+
for hist_config in &mut self.hist_configs {
321+
match hist_config {
322+
Configs::Hist1D(hist1d) => {
323+
hist1d.cuts.retain(|cut| cut != cut2d);
324+
}
325+
Configs::Hist2D(hist2d) => {
326+
hist2d.cuts.retain(|cut| cut != cut2d);
327+
}
328+
}
329+
}
330+
}
331+
269332
if ui.button("X").clicked() {
270333
indices_to_remove_cut.push(index);
271334
}

src/histogram_scripter/manual_histogram_scripts.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use crate::histoer::{
2-
// cuts::Cut,
3-
configs::Configs,
4-
};
1+
use crate::histoer::{configs::Configs, cuts::Cut};
52
use polars::prelude::*;
63
use std::f64::consts::PI;
74

@@ -51,7 +48,7 @@ pub fn get_column_names_from_lazyframe(lazyframe: &LazyFrame) -> Vec<String> {
5148

5249
#[rustfmt::skip]
5350
#[allow(clippy::all)]
54-
pub fn sps_histograms() -> (Vec<(String, String)>, Vec<Configs>) {
51+
pub fn sps_histograms() -> (Vec<(String, String)>, Vec<Configs>, Vec<Cut>) {
5552

5653
let mut new_columns = vec![];
5754
new_columns.push(("( DelayFrontRightEnergy + DelayFrontLeftEnergy ) / 2.0".into(), "DelayFrontAverageEnergy".into()));
@@ -78,6 +75,12 @@ pub fn sps_histograms() -> (Vec<(String, String)>, Vec<Configs>) {
7875
// let only_x1_plane_cut = Some(vec![Cut::new_1d("Only X1 Plane", "X1 != -1e6 && X2 == -1e6")]);
7976
// let only_x2_plane_cut = Some(vec![Cut::new_1d("Only X2 Plane", "X2 != -1e6 && X1 == -1e6")]);
8077

78+
let bothplanes_cut = Cut::new_1d("Both Planes", "X2 != -1e6 && X1 != -1e6");
79+
let only_x1_plane_cut = Cut::new_1d("Only X1 Plane", "X1 != -1e6 && X2 == -1e6");
80+
let only_x2_plane_cut = Cut::new_1d("Only X2 Plane", "X2 != -1e6 && X1 == -1e6");
81+
82+
let cuts = vec![bothplanes_cut, only_x1_plane_cut, only_x2_plane_cut];
83+
8184
let mut histograms = vec![];
8285

8386
let fp_range = (-300.0, 300.0);
@@ -93,6 +96,18 @@ pub fn sps_histograms() -> (Vec<(String, String)>, Vec<Configs>) {
9396
histograms.push(Configs::new_2d("SE-SPS/Focal Plane/X2 v X1", "X1", "X2", fp_range, fp_range, (fp_bins, fp_bins), None));
9497
histograms.push(Configs::new_2d("SE-SPS/Focal Plane/Theta v Xavg", "Xavg", "Theta", fp_range, (0.0, PI), (fp_bins, fp_bins), None));
9598

99+
let bothplanes_cut = Some(vec![Cut::new_1d("Both Planes", "X2 != -1e6 && X1 != -1e6")]);
100+
let only_x1_plane_cut = Some(vec![Cut::new_1d("Only X1 Plane", "X1 != -1e6 && X2 == -1e6")]);
101+
let only_x2_plane_cut = Some(vec![Cut::new_1d("Only X2 Plane", "X2 != -1e6 && X1 == -1e6")]);
102+
103+
histograms.push(Configs::new_1d("SE-SPS/Focal Plane/Checks/Xavg", "Xavg", fp_range, fp_bins, None));
104+
histograms.push(Configs::new_1d("SE-SPS/Focal Plane/Checks/Raw: X1", "X1", fp_range, fp_bins, None));
105+
histograms.push(Configs::new_1d("SE-SPS/Focal Plane/Checks/Both Planes: X1", "X1", fp_range, fp_bins, bothplanes_cut.clone()));
106+
histograms.push(Configs::new_1d("SE-SPS/Focal Plane/Checks/Only 1 Plane: X1", "X1", fp_range, fp_bins, only_x1_plane_cut.clone()));
107+
histograms.push(Configs::new_1d("SE-SPS/Focal Plane/Checks/Raw: X2", "X2", fp_range, fp_bins, None));
108+
histograms.push(Configs::new_1d("SE-SPS/Focal Plane/Checks/Both Planes: X2", "X2", fp_range, fp_bins, bothplanes_cut.clone()));
109+
histograms.push(Configs::new_1d("SE-SPS/Focal Plane/Checks/Only 1 Plane: X2", "X2", fp_range, fp_bins, only_x2_plane_cut.clone()));
110+
96111
// Particle Identification histograms
97112
histograms.push(Configs::new_2d("SE-SPS/Particle Identification/AnodeBack v ScintLeft", "ScintLeftEnergy", "AnodeBackEnergy", range, range, (bins,bins), None));
98113
histograms.push(Configs::new_2d("SE-SPS/Particle Identification/AnodeFront v ScintLeft", "ScintLeftEnergy", "AnodeFrontEnergy", range, range, (bins,bins), None));
@@ -135,7 +150,7 @@ pub fn sps_histograms() -> (Vec<(String, String)>, Vec<Configs>) {
135150

136151
// Delay timing relative to anodes histograms
137152

138-
(new_columns, histograms)
153+
(new_columns, histograms, cuts)
139154
}
140155
/*
141156
// // // //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

0 commit comments

Comments
 (0)