Skip to content

Commit 3a188b1

Browse files
committed
Add more batch options.
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.
1 parent 293b56d commit 3a188b1

File tree

12 files changed

+780
-236
lines changed

12 files changed

+780
-236
lines changed

InterSpec/BatchActivity.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <string>
3232
#include <vector>
3333

34+
#include <boost/optional.hpp>
35+
3436
#include "InterSpec/BatchPeak.h"
3537

3638
// Forward declarations
@@ -62,6 +64,8 @@ namespace BatchActivity
6264
{
6365
bool use_bq = false;
6466
std::shared_ptr<DetectorPeakResponse> drf_override;
67+
boost::optional<double> distance_override;
68+
bool hard_background_sub;
6569
};//struct BatchActivityFitOptions
6670

6771

@@ -77,13 +81,20 @@ namespace BatchActivity
7781
CouldntInitializeStaticResources,
7882
NoExemplar,
7983
CouldntOpenExemplar,
84+
ErrorPickingSpectrumFromExemplar,
8085
CouldntOpenInputFile,
8186
CouldntOpenBackgroundFile,
8287
NoInputSrcShieldModel,
8388
ForegroundSampleNumberUnderSpecified,
8489
BackgroundSampleNumberUnderSpecified,
90+
InvalidLiveTimeForHardBackSub,
91+
SpecifiedDistanceWithFixedGeomDet,
92+
ErrorWithHardBackgroundSubtract,
93+
ErrorApplyingExemplarEneCalToFore,
8594

8695
ForegroundPeakFitFailed,
96+
BackgroundPeakFitFailed,
97+
NoExistingBackgroundPeaks,
8798
NoFitForegroundPeaks,
8899
NoDetEffFnct,
89100
InvalidDistance,

InterSpec/BatchPeak.h

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SpecMeas;
3838
namespace SpecUtils
3939
{
4040
class Measurement;
41+
class EnergyCalibration;
4142
}//namespace SpecUtils
4243

4344

@@ -71,6 +72,8 @@ namespace BatchPeak
7172
std::string output_dir;
7273
std::string background_subtract_file;
7374
std::set<int> background_subtract_samples;
75+
bool use_existing_background_peaks;
76+
bool use_exemplar_energy_cal_for_background;
7477

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

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

112119
bool success;
113120
std::vector<std::string> warnings;
@@ -137,6 +144,33 @@ namespace BatchPeak
137144
std::set<int> foreground_sample_numbers,
138145
const BatchPeakFitOptions &options );
139146

147+
/** Function that applies the energy calibration from the exemplar spectrum, to a spectrum from a different file.
148+
149+
@param energy_cal The energy calibration to apply to `to_spectrum`, and optionally `to_specfile`
150+
@param to_spectrum The spectrum, which may or may not be in `to_specfile`, to apply the energy calibration from `from_spectrum`
151+
@param to_specfile The (optional) spectrum file to apply the energy calibration to; this will also take care of shifting peak energies
152+
@param used_sample_nums The sample numbers used to create the `to_spectrum` from the `to_specfile` - used to keep peaks from
153+
being moved twice.
154+
*/
155+
void propagate_energy_cal( const std::shared_ptr<const SpecUtils::EnergyCalibration> &energy_cal,
156+
std::shared_ptr<SpecUtils::Measurement> &to_spectrum,
157+
std::shared_ptr<SpecMeas> &to_specfile,
158+
const std::set<int> &used_sample_nums );
159+
160+
/** Finds the spectrum, peaks, and sample numbers to use from the exemplar file.
161+
162+
@param [out] exemplar_spectrum Will be set to the spectrum to use as the exemplar spectrum (may be a sum of
163+
multiple Measurements)
164+
@param [out] exemplar_peaks Will be set to the peaks to use from the exemplar file.
165+
@param [in|out] exemplar_sample_nums Sample numbers to use in the exemplar file. If non-empty, these sample
166+
number will be used to retrieve the spectrum to use. Contents will be set to the used sample numbers.
167+
@param [in] exemplar_n42 The spectrum file to retrieve the spectrum/peaks for
168+
*/
169+
void get_exemplar_spectrum_and_peaks(
170+
std::shared_ptr<const SpecUtils::Measurement> &exemplar_spectrum,
171+
std::shared_ptr<const std::deque<std::shared_ptr<const PeakDef>>> &exemplar_peaks,
172+
std::set<int> &exemplar_sample_nums,
173+
const std::shared_ptr<const SpecMeas> &exemplar_n42 );
140174
}//namespace BatchPeak
141175

142176
#endif //BatchPeak_h

InterSpec/GammaInteractionCalc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ struct SourceDetails
572572
const SandiaDecay::Nuclide *nuclide = nullptr;
573573
double activity = 0.0;
574574
double activityUncertainty = 0.0;
575+
/** If the activity is fit for.
576+
577+
Note: if source type is `ShieldingSourceFitCalc::ModelSourceType::Intrinsic`, then this value will be false,
578+
even if a shielding dimension is being fit for.
579+
*/
575580
bool activityIsFit = false;
576581
double nuclideMass = 0.0;
577582
double age = 0.0;

InterSpec/ShieldingSourceFitCalc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ namespace ShieldingSourceFitCalc
9797

9898
//activity: in units of PhysicalUnits
9999
double activity;
100+
/** If the activity is fit for.
101+
102+
Note: if source type is `ShieldingSourceFitCalc::ModelSourceType::Intrinsic`, then this value will be false,
103+
even if a shielding dimension is being fit for.
104+
*/
100105
bool fitActivity;
101106

102107
//age: in units of PhysicalUnits::second

InterSpec_resources/static_text/ShieldSourceFitLog/act_fit.tmplt.html

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ <h1 class="title">
148148
<td> {% if existsIn(foreground,"SerialNumber") %} {{ foreground.SerialNumber }} {% else %} -- {% endif %} </td>
149149
{% if foreground.HasGps %}
150150
<th>lat/lon:</th>
151-
<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>
151+
<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>
152152
{% endif %}
153153
</tr>
154154
{% if foreground.HasInstrumentRid %}
@@ -449,8 +449,30 @@ <h1 class="title">
449449
</script>
450450

451451

452-
453-
452+
{% if existsIn(Shieldings,"Shields") %}
453+
##for shield in Shieldings.Shields
454+
{% if shield.FitAnyMassFraction %}
455+
<div class="mass_frac_{{ shield.Name }}" style="margin-top: 15px">
456+
Mass fractions for {{ shield.Name }}:
457+
<table class="InfoTable">
458+
<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>
459+
<tbody>
460+
##for shieldSrc in shield.SelfAttenSources
461+
<tr>
462+
<td>{{ shieldSrc.Nuclide }}</td>
463+
<td>{{ printFixed(shieldSrc.MassFraction,6) }}</td>
464+
<td>{{ shieldSrc.IsFittingMassFraction }}</td>
465+
<td>{% if existsIn(shieldSrc,"MassFractionUncert") %} {{ printFixed(shieldSrc.MassFractionUncert,6) }} {% endif %}</td>
466+
<td>{% if existsIn(shieldSrc,"Activity") %} {{ shieldSrc.Activity }} {{ shieldSrc.ActivityPostFix }} {% endif %}</td>
467+
<td>{% if existsIn(shieldSrc,"ActivityUncert") %} {{ shieldSrc.ActivityUncert }} {{ shieldSrc.ActivityPostFix }} {% endif %}</td>
468+
</tr>
469+
##endfor
470+
</tbody>
471+
</table>
472+
</div>
473+
{% endif %}
474+
##endfor
475+
{% endif %}
454476

455477

456478

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

479-
480501
## for src in Sources
481502
{{ 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 }}
482503
## endfor

InterSpec_resources/static_text/ShieldSourceFitLog/std_summary.tmplt.csv

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ Setup
99
{% if exists("ExemplarSampleNumbers") %}Exemplar samples: {{ ExemplarSampleNumbers }}{% endif %}
1010

1111

12-
Filename, Nuclide, Activity, ActivityUncertainty, ActivityUncertainty (%), NuclideAge, NuclideAgeUncertainty
12+
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
1313
## for file in Files
1414
## for src in file.Sources
15-
{{ 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 %}
15+
{{ file.Filename }}, {{ src.Nuclide }}, {{ src.Activity }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert }}{% endif %}, {% if src.ActivityIsFit %}{{ src.ActivityUncertPercent }}%{% endif
16+
%}, {{ src.Activity_uCi }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert_uCi }}{% endif
17+
%}, {{ src.Activity_pCi }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert_pCi }}{% endif
18+
%}, {{ src.Activity_bq }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert_bq }}{% endif
19+
%}, {{ src.Activity_MBq }}, {% if src.ActivityIsFit %}{{ src.ActivityUncert_MBq }}{% endif
20+
%}, {{ src.Age }}, {% if src.AgeIsFit %}{{ src.AgeUncert }}{% endif %}
1621
## endfor
1722
## endfor

InterSpec_resources/static_text/ShieldSourceFitLog/std_summary.tmplt.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,31 @@ <h1 class="title">
247247
</table>
248248
</div> <!-- <div id="sources" style="margin-top: 25px"> -->
249249

250+
{% if existsIn(file.Shieldings, "Shields") %}
251+
##for shield in file.Shieldings.Shields
252+
{% if shield.FitAnyMassFraction %}
253+
<div class="mass_frac_{{ shield.Name }}" style="margin-top: 15px">
254+
Mass fractions for {{ shield.Name }}:
255+
<table class="InfoTable">
256+
<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>
257+
<tbody>
258+
##for shieldSrc in shield.SelfAttenSources
259+
<tr>
260+
<td>{{ shieldSrc.Nuclide }}</td>
261+
<td>{{ printFixed(shieldSrc.MassFraction,6) }}</td>
262+
<td>{{ shieldSrc.IsFittingMassFraction }}</td>
263+
<td>{% if existsIn(shieldSrc,"MassFractionUncert") %} {{ printFixed(shieldSrc.MassFractionUncert,6) }} {% endif %}</td>
264+
<td>{% if existsIn(shieldSrc,"Activity") %} {{ shieldSrc.Activity }} {{ shieldSrc.ActivityPostFix }} {% endif %}</td>
265+
<td>{% if existsIn(shieldSrc,"ActivityUncert") %} {{ shieldSrc.ActivityUncert }} {{ shieldSrc.ActivityPostFix }} {% endif %}</td>
266+
</tr>
267+
##endfor
268+
</tbody>
269+
</table>
270+
</div>
271+
{% endif %}
272+
##endfor
273+
{% endif %}
274+
250275
<div style="margin-top: 20px">
251276
<ul style="list-style-type: none; padding: 0; margin: 0;">
252277
<li>There were {{ file.NumDof }} parameters fit for</li>

0 commit comments

Comments
 (0)