Skip to content

Commit

Permalink
new histogram fill logic-- in dev but much faster and shouldnt crash …
Browse files Browse the repository at this point in the history
…with a large dataset

	modified:   Cargo.lock
	modified:   Cargo.toml
	modified:   src/histoer/histo1d/histogram1d.rs
	modified:   src/histoer/histo1d/statistics.rs
	modified:   src/histoer/histo2d/histogram2d.rs
	modified:   src/histoer/histo2d/statistics.rs
	modified:   src/histoer/histogrammer.rs
	deleted:    src/histogram_scripter/configure_auxillary_detectors.rs
	modified:   src/histogram_scripter/histogram_script.rs
	deleted:    src/histogram_scripter/histogram_ui_elements.rs
	modified:   src/histogram_scripter/manual_histogram_script.rs
	modified:   src/histogram_scripter/mod.rs
	modified:   src/util/processer.rs
  • Loading branch information
alconley committed Nov 6, 2024
1 parent 34ffd82 commit f724814
Show file tree
Hide file tree
Showing 13 changed files with 644 additions and 1,396 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ env_logger = "0.11.5"
# performant will make the compile times slower but should make the histogrammer faster
polars = { version = "0.43.1", features = ["lazy", "parquet", "performant"] }
polars-lazy = { version = "0.43.1", features = ["hist"] }
rayon = "1.10.0"
hashbrown = { version = "=0.14.5", features = ["raw"] } #needed until polars fixes

rfd = "0.15"
Expand Down
9 changes: 0 additions & 9 deletions src/histoer/histo1d/histogram1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ impl Histogram {
self.underflow = 0;
}

// Add a value to the histogram
pub fn fill(&mut self, value: f64, current_step: usize, total_steps: usize) {
if value >= self.range.0 && value < self.range.1 {
let index = ((value - self.range.0) / self.bin_width) as usize;
Expand All @@ -71,14 +70,12 @@ impl Histogram {
self.bins = counts;
}

// Get the bin edges
pub fn get_bin_edges(&self) -> Vec<f64> {
(0..=self.bins.len())
.map(|i| self.range.0 + i as f64 * self.bin_width)
.collect()
}

// Convert histogram bins to line points
pub fn update_line_points(&mut self) {
self.line.points = self
.bins
Expand All @@ -93,7 +90,6 @@ impl Histogram {
.collect();
}

// Get the bin index for a given x position.
pub fn get_bin_index(&self, x: f64) -> Option<usize> {
if x < self.range.0 || x > self.range.1 {
return None;
Expand All @@ -104,7 +100,6 @@ impl Histogram {
Some(bin_index)
}

// Get the bin centers between the start and end x values (inclusive)
pub fn get_bin_centers_between(&self, start_x: f64, end_x: f64) -> Vec<f64> {
let start_bin = self.get_bin_index(start_x).unwrap_or(0);
let end_bin = self.get_bin_index(end_x).unwrap_or(self.bins.len() - 1);
Expand All @@ -114,7 +109,6 @@ impl Histogram {
.collect()
}

// Get the bin counts between the start and end x values (inclusive)
pub fn get_bin_counts_between(&self, start_x: f64, end_x: f64) -> Vec<f64> {
let start_bin = self.get_bin_index(start_x).unwrap_or(0);
let end_bin = self.get_bin_index(end_x).unwrap_or(self.bins.len() - 1);
Expand All @@ -124,7 +118,6 @@ impl Histogram {
.collect()
}

// Get bin counts and bin center at x value
pub fn get_bin_count_and_center(&self, x: f64) -> Option<(f64, f64)> {
self.get_bin_index(x).map(|bin| {
let bin_center = self.range.0 + (bin as f64 * self.bin_width) + self.bin_width * 0.5;
Expand Down Expand Up @@ -219,7 +212,6 @@ impl Histogram {
self.fits.temp_fit = Some(fitter);
}

// Draw the histogram, fit lines, markers, and stats
pub fn draw(&mut self, plot_ui: &mut egui_plot::PlotUi) {
// update the histogram and fit lines with the log setting and draw
let log_y = self.plot_settings.egui_settings.log_y;
Expand Down Expand Up @@ -305,7 +297,6 @@ impl Histogram {
}
}

// Renders the histogram using egui_plot
pub fn render(&mut self, ui: &mut egui::Ui) {
// Display progress bar while hist is being filled
self.plot_settings.progress_ui(ui);
Expand Down
4 changes: 2 additions & 2 deletions src/histoer/histo1d/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ impl Histogram {
format!("Integral: {}", integral),
format!("Mean: {:.2}", mean),
format!("Stdev: {:.2}", stdev),
// format!("Overflow: {:}", self.overflow),
// format!("Underflow: {:}", self.underflow),
format!("Overflow: {:}", self.overflow),
format!("Underflow: {:}", self.underflow),
];

for entry in stats_entries.iter() {
Expand Down
10 changes: 6 additions & 4 deletions src/histoer/histo2d/histogram2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ impl Histogram2D {
}

// Update progress if it's being tracked
self.plot_settings.progress = Some(current_step as f32 / total_steps as f32);
let progress = current_step as f32 / total_steps as f32;
self.plot_settings.progress = Some(progress);

if self.plot_settings.progress.is_some() && (current_step % (total_steps) / 10) == 0 {
self.plot_settings.recalculate_image = true;
}
// // Recalculate the image at each 10% increment
// if (progress * 100.0) as u32 % 10 == 0 && progress > 0.0 {
// self.plot_settings.recalculate_image = true;
// }
}

// get the bin index for a given x value
Expand Down
4 changes: 2 additions & 2 deletions src/histoer/histo2d/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ impl Histogram2D {
format!("Integral: {}", stats.0),
format!("Mean: ({:.2}, {:.2})", stats.1, stats.3),
format!("Stdev: ({:.2}, {:.2})", stats.2, stats.4),
// format!("Overflow: ({:}, {:})", self.overflow.0, self.overflow.1),
// format!("Underflow: ({:}, {:})", self.underflow.0, self.underflow.1),
format!("Overflow: ({:}, {:})", self.overflow.0, self.overflow.1),
format!("Underflow: ({:}, {:})", self.underflow.0, self.underflow.1),
];

for entry in stats_entries.iter() {
Expand Down
Loading

0 comments on commit f724814

Please sign in to comment.