Skip to content

Commit c047720

Browse files
author
Arthur Glowacki
committed
Works on POLAR dataset
1 parent b5aa916 commit c047720

3 files changed

Lines changed: 53 additions & 59 deletions

File tree

src/core/process_whole.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ DLL_EXPORT data_struct::Fit_Count_Dict<T_real>* generate_fit_count_by_shell_dict
167167
data_struct::Fit_Count_Dict<T_real>* element_fit_counts_dict = new data_struct::Fit_Count_Dict<T_real>();
168168
for (auto& e_itr : *elements_to_fit)
169169
{
170+
element_fit_counts_dict->emplace(std::pair<std::string, data_struct::ArrayXXr<T_real> >(e_itr.first, data_struct::ArrayXXr<T_real>()));
171+
element_fit_counts_dict->at(e_itr.first).resize(height, width);
170172
for (auto& s_itr : e_itr.second->generate_roi_centers_per_shell())
171173
{
172174
element_fit_counts_dict->emplace(std::pair<std::string, data_struct::ArrayXXr<T_real> >(e_itr.first + "_" + s_itr.first, data_struct::ArrayXXr<T_real>()));
@@ -210,35 +212,26 @@ DLL_EXPORT bool fit_single_spectra(fitting::routines::Base_Fit_Routine<T_real>*
210212
std::unordered_map<std::string, T_real> counts_dict;
211213
fit_routine->fit_spectra(model, spectra, elements_to_fit, counts_dict);
212214
//save count / sec
213-
for (auto& el_itr : *elements_to_fit)
215+
for (auto& itr : *out_fit_counts)
214216
{
215-
(*out_fit_counts)[el_itr.first](i, j) = counts_dict[el_itr.first] / spectra->elapsed_livetime();
217+
if (counts_dict.count(itr.first) > 0)
218+
{
219+
itr.second(i, j) = counts_dict[itr.first] / spectra->elapsed_livetime();
220+
}
221+
//(*out_fit_counts)[el_itr.first](i, j) = counts_dict[el_itr.first] / spectra->elapsed_livetime();
216222
}
217223
(*out_fit_counts)[STR_NUM_ITR](i, j) = counts_dict[STR_NUM_ITR];
218224

219225
(*out_fit_counts)[STR_RESIDUAL](i, j) = counts_dict[STR_RESIDUAL];
220226
// add total fluorescense yield
221227
if (out_fit_counts->count(STR_TOTAL_FLUORESCENCE_YIELD))
222228
{
223-
(*out_fit_counts)[STR_TOTAL_FLUORESCENCE_YIELD](i, j) = spectra->sum();
229+
(*out_fit_counts)[STR_TOTAL_FLUORESCENCE_YIELD](i, j) = spectra->sum() / spectra->elapsed_livetime();
224230
}
225231
// add sum coherent and compton
226232
if (out_fit_counts->count(STR_SUM_ELASTIC_INELASTIC_AMP) > 0 && counts_dict.count(STR_COHERENT_SCT_AMPLITUDE) > 0 && counts_dict.count(STR_COMPTON_AMPLITUDE) > 0)
227233
{
228234
(*out_fit_counts)[STR_SUM_ELASTIC_INELASTIC_AMP](i, j) = counts_dict[STR_COHERENT_SCT_AMPLITUDE] + counts_dict[STR_COMPTON_AMPLITUDE];
229-
// add total fluorescense yield
230-
if (out_fit_counts->count(STR_TOTAL_FLUORESCENCE_YIELD))
231-
{ // (sum - (elastic + inelastic)) / live time
232-
(*out_fit_counts)[STR_TOTAL_FLUORESCENCE_YIELD](i, j) = (spectra->sum() - (*out_fit_counts)[STR_SUM_ELASTIC_INELASTIC_AMP](i, j)) / spectra->elapsed_livetime();
233-
}
234-
}
235-
else
236-
{
237-
// add total fluorescense yield
238-
if (out_fit_counts->count(STR_TOTAL_FLUORESCENCE_YIELD))
239-
{
240-
(*out_fit_counts)[STR_TOTAL_FLUORESCENCE_YIELD](i, j) = spectra->sum() / spectra->elapsed_livetime();
241-
}
242235
}
243236

244237
return true;

src/data_struct/fit_element_map.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -443,33 +443,35 @@ template<typename T_real>
443443
std::unordered_map<std::string, T_real> Fit_Element_Map<T_real>::generate_roi_centers_per_shell()
444444
{
445445
std::unordered_map<std::string, T_real> map;
446-
if (_shell_type == Electron_Shell::K_SHELL)
446+
if (_element_info != nullptr)
447447
{
448-
map["ka1"] = _element_info->xrf["ka1"];
449-
map["ka2"] = _element_info->xrf["ka2"];
450-
map["kb1"] = _element_info->xrf["kb1"];
451-
map["kb2"] = _element_info->xrf["kb2"];
452-
}
453-
else if (_shell_type == Electron_Shell::L_SHELL)
454-
{
455-
map["la2"] = _element_info->xrf["la2"];
456-
map["lb1"] = _element_info->xrf["lb1"];
457-
map["lb2"] = _element_info->xrf["lb2"];
458-
map["lb3"] = _element_info->xrf["lb3"];
459-
map["lb4"] = _element_info->xrf["lb4"];
460-
map["lg1"] = _element_info->xrf["lg1"];
461-
map["lg2"] = _element_info->xrf["lg2"];
462-
map["lg3"] = _element_info->xrf["lg3"];
463-
map["lg4"] = _element_info->xrf["lg4"];
464-
map["ll"] = _element_info->xrf["ll"];
465-
map["ln"] = _element_info->xrf["ln"];
466-
}
467-
else if (_shell_type == Electron_Shell::M_SHELL)
468-
{
469-
map["ma1"] = _element_info->xrf["ma1"];
470-
map["ma2"] = _element_info->xrf["ma2"];
471-
map["mb"] = _element_info->xrf["mb"];
472-
map["mg"] = _element_info->xrf["mg"];
448+
if (_shell_type == Electron_Shell::K_SHELL)
449+
{
450+
map["ka2"] = _element_info->xrf["ka2"];
451+
map["kb1"] = _element_info->xrf["kb1"];
452+
map["kb2"] = _element_info->xrf["kb2"];
453+
}
454+
else if (_shell_type == Electron_Shell::L_SHELL)
455+
{
456+
map["la2"] = _element_info->xrf["la2"];
457+
map["lb1"] = _element_info->xrf["lb1"];
458+
map["lb2"] = _element_info->xrf["lb2"];
459+
map["lb3"] = _element_info->xrf["lb3"];
460+
map["lb4"] = _element_info->xrf["lb4"];
461+
map["lg1"] = _element_info->xrf["lg1"];
462+
map["lg2"] = _element_info->xrf["lg2"];
463+
map["lg3"] = _element_info->xrf["lg3"];
464+
map["lg4"] = _element_info->xrf["lg4"];
465+
map["ll"] = _element_info->xrf["ll"];
466+
map["ln"] = _element_info->xrf["ln"];
467+
}
468+
else if (_shell_type == Electron_Shell::M_SHELL)
469+
{
470+
map["ma1"] = _element_info->xrf["ma1"];
471+
map["ma2"] = _element_info->xrf["ma2"];
472+
map["mb"] = _element_info->xrf["mb"];
473+
map["mg"] = _element_info->xrf["mg"];
474+
}
473475
}
474476
return map;
475477
}

src/fitting/routines/roi_fit_routine.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,26 @@ optimizers::OPTIMIZER_OUTCOME ROI_Fit_Routine<T_real>::fit_spectra(const models:
9090
Fit_Element_Map<T_real>* element = e_itr.second;
9191
if (element != nullptr)
9292
{
93-
if(_separate_shells == false)
94-
{
95-
left_roi = static_cast<unsigned int>(std::round(((element->center() - element->width()) - energy_offset) / energy_slope));
96-
right_roi = static_cast<unsigned int>(std::round(((element->center() + element->width()) - energy_offset) / energy_slope));
97-
98-
if (right_roi >= n_mca_channels)
99-
{
100-
right_roi = n_mca_channels - 2;
101-
}
102-
if (left_roi > right_roi)
103-
{
104-
left_roi = right_roi - 1;
105-
}
93+
94+
left_roi = static_cast<unsigned int>(std::round(((element->center() - element->width()) - energy_offset) / energy_slope));
95+
right_roi = static_cast<unsigned int>(std::round(((element->center() + element->width()) - energy_offset) / energy_slope));
10696

107-
size_t spec_size = (right_roi - left_roi) + 1;
108-
out_counts[e_itr.first] = spectra->segment(left_roi, spec_size).sum();
97+
if (right_roi >= n_mca_channels)
98+
{
99+
right_roi = n_mca_channels - 2;
109100
}
110-
else
101+
if (left_roi > right_roi)
102+
{
103+
left_roi = right_roi - 1;
104+
}
105+
106+
size_t spec_size = (right_roi - left_roi) + 1;
107+
out_counts[e_itr.first] = spectra->segment(left_roi, spec_size).sum();
108+
if (_separate_shells)
111109
{
112110
for (auto& s_itr : element->generate_roi_centers_per_shell())
113111
{
112+
std::string save_name = e_itr.first + "_" + s_itr.first;
114113
left_roi = static_cast<unsigned int>(std::round(((s_itr.second - element->width()) - energy_offset) / energy_slope));
115114
right_roi = static_cast<unsigned int>(std::round(((s_itr.second + element->width()) - energy_offset) / energy_slope));
116115

@@ -124,7 +123,7 @@ optimizers::OPTIMIZER_OUTCOME ROI_Fit_Routine<T_real>::fit_spectra(const models:
124123
}
125124

126125
size_t spec_size = (right_roi - left_roi) + 1;
127-
out_counts[e_itr.first+"_"+s_itr.first] = spectra->segment(left_roi, spec_size).sum();
126+
out_counts[save_name] = spectra->segment(left_roi, spec_size).sum();
128127
}
129128
}
130129
}

0 commit comments

Comments
 (0)