Skip to content

Commit

Permalink
Fixed adding min,max bins so that snip_background displays properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Glowacki committed Jul 10, 2024
1 parent 6937b96 commit 348d984
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
18 changes: 14 additions & 4 deletions src/mvc/FitSpectraWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,16 +468,21 @@ void FitSpectraWidget::replot_integrated_spectra(bool snipback)
_spectra_widget->append_spectra(DEF_STR_INT_SPECTRA, _int_spec, (data_struct::Spectra<double>*) & _ev);
if (snipback)
{
Range range = get_energy_range(_int_spec->size(), &fit_params);
// TODO: Look into why memory access violation happens when streaming
_spectra_background = snip_background<double>((Spectra<double>*)_int_spec,
fit_params[STR_ENERGY_OFFSET].value,
fit_params[STR_ENERGY_SLOPE].value,
fit_params[STR_ENERGY_QUADRATIC].value,
fit_params[STR_SNIP_WIDTH].value,
0, //spectra energy start range
_int_spec->size() - 1);
range.min,
range.max);

_spectra_widget->append_spectra(DEF_STR_BACK_SPECTRA, &_spectra_background, (data_struct::Spectra<double>*) & _ev);
//TESTING
//_spectra_background = snip_background2<double>((Spectra<double>*)_int_spec, fit_params[STR_SNIP_WIDTH].value);
//_spectra_widget->append_spectra("SNIP", &_spectra_background, (data_struct::Spectra<double>*) & _ev);


}
_spectra_widget->setXLabel("Energy (keV)");
Expand Down Expand Up @@ -892,15 +897,20 @@ void FitSpectraWidget::Fit_Spectra_Click()
{
if (fit_params->at(STR_SNIP_WIDTH).bound_type != E_Bound_Type::FIXED)
{
Range range = get_energy_range(_fit_spec.size(), fit_params);
_spectra_background = snip_background<double>((Spectra<double>*) & _fit_spec,
fit_params->at(STR_ENERGY_OFFSET).value,
fit_params->at(STR_ENERGY_SLOPE).value,
fit_params->at(STR_ENERGY_QUADRATIC).value,
fit_params->at(STR_SNIP_WIDTH).value,
0, //spectra energy start range
_fit_spec.size() - 1);
range.min,
range.max);

_spectra_widget->append_spectra(DEF_STR_BACK_SPECTRA, &_spectra_background, (data_struct::Spectra<double>*) & _ev);

//TESTING
//_spectra_background = snip_background2<double>((Spectra<double>*)_int_spec, fit_params->at(STR_SNIP_WIDTH).value);
//_spectra_widget->append_spectra("SNIP", &_spectra_background, (data_struct::Spectra<double>*) & _ev);
}
}
emit signal_finished_fit();
Expand Down
3 changes: 2 additions & 1 deletion src/mvc/FitSpectraWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
#include <QPushButton>
#include <mutex>
#include <QDockWidget>
#include <QCheckBox>
#include <algorithm>
#include <mvc/MapsH5Model.h>
#include <mvc/SpectraWidget.h>
#include "mvc/FitParamsTableModel.h"
#include "mvc/FitElementsTableModel.h"
#include "mvc/FittingDialog.h"
#include <QCheckBox>
#include "data_struct/spectra.h"
#include "data_struct/fit_element_map.h"
#include "data_struct/params_override.h"
Expand Down
7 changes: 4 additions & 3 deletions src/mvc/FittingDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void FittingDialog::setSpectra(data_struct::Spectra<double>* spectra, ArrayDr en
if (spectra != nullptr)
{
_int_spec = *spectra;
data_struct::Range energy_range = data_struct::get_energy_range(_int_spec.rows(), &(_out_fit_params));
_energy_range.min = 0;
_energy_range.max = _int_spec.size() - 1;

Expand All @@ -240,10 +241,10 @@ void FittingDialog::setSpectra(data_struct::Spectra<double>* spectra, ArrayDr en
_out_fit_params[STR_ENERGY_SLOPE].value,
_out_fit_params[STR_ENERGY_QUADRATIC].value,
_out_fit_params[STR_SNIP_WIDTH].value,
0, //spectra energy start range
_int_spec.size() - 1);
energy_range.min,
energy_range.max);


data_struct::Range energy_range = data_struct::get_energy_range(_int_spec.rows(), &(_out_fit_params));
for (int i = 0; i < energy_range.min; i++)
{
_int_spec[i] = 0.0;
Expand Down

0 comments on commit 348d984

Please sign in to comment.