Skip to content

Commit

Permalink
Some slight improvements to reporting for batch analysis.
Browse files Browse the repository at this point in the history
Now if background or exemplar cant be opened, analysis will just be stopped, rather than spitting errors for each input files.
The report templates now check for presence of foreground/background file, to help avoid templating errors.
The JSON for peaks could be invalid, causing templating errors (I guess browsers were tolerant enough to not complain).
  • Loading branch information
wcjohns committed Oct 10, 2024
1 parent 204698d commit e4d6b20
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ <h2 style="color: orange;">Warnings</h2>

<div id="GeneralInfo">
<ul style="list-style-type: none; padding: 0; margin: 0;">
{% if exists("foreground") %}
<li>
{% if exists("background") %} Foreground: {% endif %}
<table class="InfoTable">
Expand Down Expand Up @@ -179,7 +180,9 @@ <h2 style="color: orange;">Warnings</h2>
{% endif %}
</table>
</li>
{% if exists("background") %}
{% endif %} <!-- if exists("foreground") -->

{% if exists("background") %}
<li>
Background:
<table class="InfoTable">
Expand Down Expand Up @@ -278,7 +281,6 @@ <h2 style="color: orange;">Warnings</h2>
Branching ratios are being corrected for nuclide decay during measurement.
</li>
{% endif %} <!-- if ActShieldFitSetup.FitOptions.DecayDuringMeasurement -->
{% endif %} <!-- if HasFitResults -->

{% if exists("background") %}
<li>
Expand All @@ -288,7 +290,8 @@ <h2 style="color: orange;">Warnings</h2>
Background peaks are not being subtracted.
{% endif %}
</li>
{% endif %}
{% endif %} <!--if exists("background") -->
{% endif %} <!-- if HasFitResults -->

</ul>
</div> <!-- <div id="GeneralInfo"> -->
Expand Down Expand Up @@ -450,6 +453,7 @@ <h2 style="color: orange;">Warnings</h2>

</div> <!-- <div id="results" style="margin-top: 15px"> -->

{% if exists("foreground") %}
<script>
let spec_chart_specchart = new SpectrumChartD3( 'specchart', {
'title': '', 'xlabel' : 'Energy (keV)', 'ylabel': 'Counts'
Expand All @@ -469,6 +473,7 @@ <h2 style="color: orange;">Warnings</h2>
spec_chart_specchart.setData( spectrum_json );
spec_chart_specchart.setLogY( true );
</script>
{% endif %} <!-- if exists("foreground") -->

{% if exists("Shieldings") %}
{% if existsIn(Shieldings,"Shields") %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Foreground LiveTime: {% if foreground.LiveTime_s %}{{ foreground.LiveTime_s }} seconds{% endif %} {% if foreground.LiveTime %}({{ foreground.LiveTime }}){% endif %}
{% if exists("foreground") %}Foreground LiveTime: {% if foreground.LiveTime_s %}{{ foreground.LiveTime_s }} seconds{% endif %} {% if foreground.LiveTime %}({{ foreground.LiveTime }}){% endif %}{% else %}No foreground spectrum{% endif %}
{% if HasFitResults %}{% if FixedGeometryDetector %}Results given as {{ ActShieldFitSetup.FixedGeometryType }}.{% else %}Distance to source center from detector: {{ ActShieldFitSetup.Distance }}{% endif %}{% endif %}
{% if exists("Detector") %}{% if Detector %}Detector: {{ Detector.Name }} radius {{ printFixed(Detector.Radius_cm,1) }}{% endif %}{% endif %}
{% if HasFitResults %}
Expand Down
3 changes: 2 additions & 1 deletion src/BatchActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ void fit_activities_in_files( const std::string &exemplar_filename,
= fit_activities_in_file( exemplar_filename, exemplar_sample_nums,
cached_exemplar_n42, filename, options );

if( fit_results.m_result_code == BatchActivityFitResult::ResultCode::CouldntOpenExemplar )
if( (fit_results.m_result_code == BatchActivityFitResult::ResultCode::CouldntOpenExemplar)
|| (fit_results.m_result_code == BatchActivityFitResult::ResultCode::CouldntOpenBackgroundFile) )
throw runtime_error( fit_results.m_error_msg );

if( !cached_exemplar_n42 )
Expand Down
2 changes: 1 addition & 1 deletion src/GammaInteractionCalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,7 @@ std::pair<std::shared_ptr<ShieldingSourceChi2Fcn>, ROOT::Minuit2::MnUserParamete
}//for(...)

if( peaks.empty() )
throw runtime_error( "There are not peaks selected for the fit" );
throw runtime_error( "There are no peaks selected for the fit" );

double liveTime = foreground ? foreground->live_time() : 1.0f;
double realTime = foreground ? foreground->real_time() : 0.0f;
Expand Down
14 changes: 7 additions & 7 deletions src/PeakDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2729,14 +2729,14 @@ std::string PeakDef::gaus_peaks_to_json(const std::vector<std::shared_ptr<const
// And somewhat surprisingly, rounding causes visual artifacts of the continuum when
// the 'continuumEnergies' and 'continuumCounts' arrays are used, which are only accurate
// to float levels. So we will increase accuracy of the 'answer' stream here, which appears
// to be enough to avoid these artifcats, but also commented out is how we could compute
// to be enough to avoid these artifacts, but also commented out is how we could compute
// to double precision to match what happens in the JS.
const auto oldprecision = answer.precision(); //probably 6 always
answer << std::setprecision(std::numeric_limits<float>::digits10 + 1);

answer << "," << q << "continuumEnergies" << q << ":[";
for (size_t i = firstbin; i <= lastbin; ++i)
answer << (i ? "," : "") << foreground->gamma_channel_lower(i);
answer << ((i!=firstbin) ? "," : "") << foreground->gamma_channel_lower(i);
answer << "]," << q << "continuumCounts" << q << ":[";

/*
Expand All @@ -2759,14 +2759,14 @@ std::string PeakDef::gaus_peaks_to_json(const std::vector<std::shared_ptr<const
energy = SpecUtils::fullrangefraction_energy( i, coefs, nchannel, dev_pairs );
else
energy = SpecUtils::polynomial_energy( i, coefs, dev_pairs );
answer << (i ? "," : "") << energy;
answer << ((i!=firstbin) ? "," : "") << energy;
}
answer << "]," << q << "continuumCounts" << q << ":[";
}else
{
answer << "," << q << "continuumEnergies" << q << ":[";
for (size_t i = firstbin; i <= lastbin; ++i)
answer << (i ? "," : "") << foreground->gamma_channel_lower(i);
answer << ((i!=firstbin) ? "," : "") << foreground->gamma_channel_lower(i);
answer << "]," << q << "continuumCounts" << q << ":[";
}
*/
Expand All @@ -2778,7 +2778,7 @@ std::string PeakDef::gaus_peaks_to_json(const std::vector<std::shared_ptr<const
const float lower_x = foreground->gamma_channel_lower( i );
const float upper_x = foreground->gamma_channel_upper( i );
const float cont_counts = continuum->offset_integral( lower_x, upper_x, foreground );
answer << (i ? "," : "") << cont_counts;
answer << ((i!=firstbin) ? "," : "") << cont_counts;
}
answer << "]";

Expand Down Expand Up @@ -2809,10 +2809,10 @@ std::string PeakDef::gaus_peaks_to_json(const std::vector<std::shared_ptr<const

answer << "," << q << "continuumEnergies" << q << ":[";
for (size_t i = firstbin; i <= lastbin; ++i)
answer << (i ? "," : "") << hist->gamma_channel_lower(i);
answer << ((i!=firstbin) ? "," : "") << hist->gamma_channel_lower(i);
answer << "]," << q << "continuumCounts" << q << ":[";
for (size_t i = firstbin; i <= lastbin; ++i)
answer << (i ? "," : "") << hist->gamma_channel_content(i);
answer << ((i!=firstbin) ? "," : "") << hist->gamma_channel_content(i);
answer << "]";

answer << std::setprecision(9);
Expand Down

0 comments on commit e4d6b20

Please sign in to comment.