Skip to content

Commit

Permalink
Add more batch options.
Browse files Browse the repository at this point in the history
Added option to specify a different distance when fitting act/shield.
Add option to do hard background subtract.
Add option to use existing background peaks.
Add option to apply exemplar energy cal to background.
Fixed up a few more issues.
Fix some issues with templates.
  • Loading branch information
wcjohns committed Sep 12, 2024
1 parent 293b56d commit 3a188b1
Show file tree
Hide file tree
Showing 12 changed files with 780 additions and 236 deletions.
11 changes: 11 additions & 0 deletions InterSpec/BatchActivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <string>
#include <vector>

#include <boost/optional.hpp>

#include "InterSpec/BatchPeak.h"

// Forward declarations
Expand Down Expand Up @@ -62,6 +64,8 @@ namespace BatchActivity
{
bool use_bq = false;
std::shared_ptr<DetectorPeakResponse> drf_override;
boost::optional<double> distance_override;
bool hard_background_sub;
};//struct BatchActivityFitOptions


Expand All @@ -77,13 +81,20 @@ namespace BatchActivity
CouldntInitializeStaticResources,
NoExemplar,
CouldntOpenExemplar,
ErrorPickingSpectrumFromExemplar,
CouldntOpenInputFile,
CouldntOpenBackgroundFile,
NoInputSrcShieldModel,
ForegroundSampleNumberUnderSpecified,
BackgroundSampleNumberUnderSpecified,
InvalidLiveTimeForHardBackSub,
SpecifiedDistanceWithFixedGeomDet,
ErrorWithHardBackgroundSubtract,
ErrorApplyingExemplarEneCalToFore,

ForegroundPeakFitFailed,
BackgroundPeakFitFailed,
NoExistingBackgroundPeaks,
NoFitForegroundPeaks,
NoDetEffFnct,
InvalidDistance,
Expand Down
38 changes: 36 additions & 2 deletions InterSpec/BatchPeak.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SpecMeas;
namespace SpecUtils
{
class Measurement;
class EnergyCalibration;
}//namespace SpecUtils


Expand Down Expand Up @@ -71,6 +72,8 @@ namespace BatchPeak
std::string output_dir;
std::string background_subtract_file;
std::set<int> background_subtract_samples;
bool use_existing_background_peaks;
bool use_exemplar_energy_cal_for_background;

/** The directory to allow report template to look in to include other templates.
If specified, then the standard report directory cant be used.
Expand Down Expand Up @@ -106,8 +109,12 @@ namespace BatchPeak
std::set<int> sample_numbers;
std::deque<std::shared_ptr<const PeakDef>> fit_peaks;

/** Background spectrum that was subtracted from the foreground, to make `spectrum`, if any. */
std::shared_ptr<const SpecUtils::Measurement> background;
/** Background spectrum that was subtracted from the foreground, to make `spectrum`, if any.
The background subtraction can either be on a peak-by-peak basis, or a hard
background subtraction, see `BatchPeakFitOptions::use_exemplar_energy_cal_for_background`.
*/
std::shared_ptr<SpecUtils::Measurement> background;

bool success;
std::vector<std::string> warnings;
Expand Down Expand Up @@ -137,6 +144,33 @@ namespace BatchPeak
std::set<int> foreground_sample_numbers,
const BatchPeakFitOptions &options );

/** Function that applies the energy calibration from the exemplar spectrum, to a spectrum from a different file.
@param energy_cal The energy calibration to apply to `to_spectrum`, and optionally `to_specfile`
@param to_spectrum The spectrum, which may or may not be in `to_specfile`, to apply the energy calibration from `from_spectrum`
@param to_specfile The (optional) spectrum file to apply the energy calibration to; this will also take care of shifting peak energies
@param used_sample_nums The sample numbers used to create the `to_spectrum` from the `to_specfile` - used to keep peaks from
being moved twice.
*/
void propagate_energy_cal( const std::shared_ptr<const SpecUtils::EnergyCalibration> &energy_cal,
std::shared_ptr<SpecUtils::Measurement> &to_spectrum,
std::shared_ptr<SpecMeas> &to_specfile,
const std::set<int> &used_sample_nums );

/** Finds the spectrum, peaks, and sample numbers to use from the exemplar file.
@param [out] exemplar_spectrum Will be set to the spectrum to use as the exemplar spectrum (may be a sum of
multiple Measurements)
@param [out] exemplar_peaks Will be set to the peaks to use from the exemplar file.
@param [in|out] exemplar_sample_nums Sample numbers to use in the exemplar file. If non-empty, these sample
number will be used to retrieve the spectrum to use. Contents will be set to the used sample numbers.
@param [in] exemplar_n42 The spectrum file to retrieve the spectrum/peaks for
*/
void get_exemplar_spectrum_and_peaks(
std::shared_ptr<const SpecUtils::Measurement> &exemplar_spectrum,
std::shared_ptr<const std::deque<std::shared_ptr<const PeakDef>>> &exemplar_peaks,
std::set<int> &exemplar_sample_nums,
const std::shared_ptr<const SpecMeas> &exemplar_n42 );
}//namespace BatchPeak

#endif //BatchPeak_h
5 changes: 5 additions & 0 deletions InterSpec/GammaInteractionCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ struct SourceDetails
const SandiaDecay::Nuclide *nuclide = nullptr;
double activity = 0.0;
double activityUncertainty = 0.0;
/** If the activity is fit for.
Note: if source type is `ShieldingSourceFitCalc::ModelSourceType::Intrinsic`, then this value will be false,
even if a shielding dimension is being fit for.
*/
bool activityIsFit = false;
double nuclideMass = 0.0;
double age = 0.0;
Expand Down
5 changes: 5 additions & 0 deletions InterSpec/ShieldingSourceFitCalc.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ namespace ShieldingSourceFitCalc

//activity: in units of PhysicalUnits
double activity;
/** If the activity is fit for.
Note: if source type is `ShieldingSourceFitCalc::ModelSourceType::Intrinsic`, then this value will be false,
even if a shielding dimension is being fit for.
*/
bool fitActivity;

//age: in units of PhysicalUnits::second
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h1 class="title">
<td> {% if existsIn(foreground,"SerialNumber") %} {{ foreground.SerialNumber }} {% else %} -- {% endif %} </td>
{% if foreground.HasGps %}
<th>lat/lon:</th>
<td colspan="2"> <a target="_blank" rel="noopener noreferrer" href="https://maps.google.com/?q={{ printFixed(foreground.Latitude,7) }},{{ printFixed(foreground.Longitude,7) }}">{{ printFixed(foreground.Latitude,7) }}{{ printFixed(foreground.Longitude,7) }}</a> </td>
<td colspan="2"> <a target="_blank" rel="noopener noreferrer" href="https://maps.google.com/?q={{ printFixed(foreground.Latitude,7) }},{{ printFixed(foreground.Longitude,7) }}">{{ printFixed(foreground.Latitude,7) }},{{ printFixed(foreground.Longitude,7) }}</a> </td>
{% endif %}
</tr>
{% if foreground.HasInstrumentRid %}
Expand Down Expand Up @@ -449,8 +449,30 @@ <h1 class="title">
</script>




{% if existsIn(Shieldings,"Shields") %}
##for shield in Shieldings.Shields
{% if shield.FitAnyMassFraction %}
<div class="mass_frac_{{ shield.Name }}" style="margin-top: 15px">
Mass fractions for {{ shield.Name }}:
<table class="InfoTable">
<thead><tr><th>Nuclide</th><th>Mass Fraction</th><th>Fit Mass Frac?</th><th>Mass Fraction Uncert</th><th>Activity</th><th>ActivityUncert</th></tr></thead>
<tbody>
##for shieldSrc in shield.SelfAttenSources
<tr>
<td>{{ shieldSrc.Nuclide }}</td>
<td>{{ printFixed(shieldSrc.MassFraction,6) }}</td>
<td>{{ shieldSrc.IsFittingMassFraction }}</td>
<td>{% if existsIn(shieldSrc,"MassFractionUncert") %} {{ printFixed(shieldSrc.MassFractionUncert,6) }} {% endif %}</td>
<td>{% if existsIn(shieldSrc,"Activity") %} {{ shieldSrc.Activity }} {{ shieldSrc.ActivityPostFix }} {% endif %}</td>
<td>{% if existsIn(shieldSrc,"ActivityUncert") %} {{ shieldSrc.ActivityUncert }} {{ shieldSrc.ActivityPostFix }} {% endif %}</td>
</tr>
##endfor
</tbody>
</table>
</div>
{% endif %}
##endfor
{% endif %}



Expand All @@ -476,7 +498,6 @@ <h1 class="title">
##endfor
{% endif %}


## for src in Sources
{{ src.Nuclide }} fit activity {{ src.Activity }}{% if src.ActivityIsFit %} with uncertainty {{ src.ActivityUncert }} ({{ src.ActivityUncertPercent }}) {% endif %} at {% if src.AgeIsFit %}assumed {% else %}fit {% endif %} age {{ src.Age }}
## endfor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ Setup
{% if exists("ExemplarSampleNumbers") %}Exemplar samples: {{ ExemplarSampleNumbers }}{% endif %}


Filename, Nuclide, Activity, ActivityUncertainty, ActivityUncertainty (%), NuclideAge, NuclideAgeUncertainty
Filename, Nuclide, Activity, ActivityUncertainty, ActivityUncertainty (%), Activity (uCi), ActivityUncertainty (uCi), Activity (pCi), ActivityUncertainty (pCi), Activity (bq), ActivityUncertainty (bq), Activity (mega-bq), ActivityUncertainty (mega-bq), NuclideAge, NuclideAgeUncertainty
## for file in Files
## for src in file.Sources
{{ file.Filename }},{{ src.Nuclide }}, {{ src.Activity }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert }}{% endif %}, {% if src.ActivityIsFit %}{{ src.ActivityUncertPercent }}%{% endif %}, {{ src.Age }}, {% if src.AgeIsFit %}{{ src.AgeUncert }}{% endif %}
{{ file.Filename }}, {{ src.Nuclide }}, {{ src.Activity }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert }}{% endif %}, {% if src.ActivityIsFit %}{{ src.ActivityUncertPercent }}%{% endif
%}, {{ src.Activity_uCi }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert_uCi }}{% endif
%}, {{ src.Activity_pCi }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert_pCi }}{% endif
%}, {{ src.Activity_bq }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert_bq }}{% endif
%}, {{ src.Activity_MBq }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert_MBq }}{% endif
%}, {{ src.Age }}, {% if src.AgeIsFit %}{{ src.AgeUncert }}{% endif %}
## endfor
## endfor
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,31 @@ <h1 class="title">
</table>
</div> <!-- <div id="sources" style="margin-top: 25px"> -->

{% if existsIn(file.Shieldings, "Shields") %}
##for shield in file.Shieldings.Shields
{% if shield.FitAnyMassFraction %}
<div class="mass_frac_{{ shield.Name }}" style="margin-top: 15px">
Mass fractions for {{ shield.Name }}:
<table class="InfoTable">
<thead><tr><th>Nuclide</th><th>Mass Fraction</th><th>Fit Mass Frac?</th><th>Mass Fraction Uncert</th><th>Activity</th><th>ActivityUncert</th></tr></thead>
<tbody>
##for shieldSrc in shield.SelfAttenSources
<tr>
<td>{{ shieldSrc.Nuclide }}</td>
<td>{{ printFixed(shieldSrc.MassFraction,6) }}</td>
<td>{{ shieldSrc.IsFittingMassFraction }}</td>
<td>{% if existsIn(shieldSrc,"MassFractionUncert") %} {{ printFixed(shieldSrc.MassFractionUncert,6) }} {% endif %}</td>
<td>{% if existsIn(shieldSrc,"Activity") %} {{ shieldSrc.Activity }} {{ shieldSrc.ActivityPostFix }} {% endif %}</td>
<td>{% if existsIn(shieldSrc,"ActivityUncert") %} {{ shieldSrc.ActivityUncert }} {{ shieldSrc.ActivityPostFix }} {% endif %}</td>
</tr>
##endfor
</tbody>
</table>
</div>
{% endif %}
##endfor
{% endif %}

<div style="margin-top: 20px">
<ul style="list-style-type: none; padding: 0; margin: 0;">
<li>There were {{ file.NumDof }} parameters fit for</li>
Expand Down
Loading

0 comments on commit 3a188b1

Please sign in to comment.