Skip to content

Commit 8839493

Browse files
committed
Some small fixes from use.
Add refreshing kinetic reference lines when peaks are added/removed/refreshed. Remove kinetic reference lines when they are disabled. Fix a potential uncaught excetion in ExternalRid, as well as some other small improvements. Fix using a wrong name in batch analysis warning. Add current to-do, known issues to kinetic ref lines. Set AD to me non-zero to start with in RelActAuto, for the self-attenuating shielding.
1 parent b670d8e commit 8839493

File tree

5 files changed

+120
-23
lines changed

5 files changed

+120
-23
lines changed

InterSpec/RefLineKinetic.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ struct ExternalRidResults;
4545
class D3SpectrumDisplayDiv;
4646
class DetectorPeakResponse;
4747

48+
/**
49+
TODO items:
50+
- Extend the energy lines to the full-height of the window - maybe either use a dotted line, or one with some alpha, or make the solid line, but a dot at the original height
51+
- For the random sum peaks, also show likely nuclides
52+
- When multiple nuclides are candidates, need to allow switching between them, or indicate things in some way to either cycle through them, and/or let the user
53+
- Each "catagory" of nuclides should get a different color, controllable by the color theme
54+
55+
Current shortcommings:
56+
- Cascade sums not accounted for
57+
- The filtering the number of lines for each set could def use improvement
58+
- Lines not updated when there is an energy calibration change (the auto-serch peak should also be updated - and any being searched for need to be cancelled and restarted)
59+
- Should be able to handle RID output results like DU, Uranium, HEU, Neutrons, "Sr-85/Kr85", Annihilation, etc
60+
- Having a peak with a source associated with it should _really_ increase the weight (see HPGe Lu177 spectrum for example why).
61+
- Should pick the most important line, get the profile weight for the source, and adjust the source weight a bit using this
62+
*/
4863
class RefLineKinetic : public Wt::WObject
4964
{
5065
public:
@@ -105,7 +120,11 @@ class RefLineKinetic : public Wt::WObject
105120

106121
/** Helper method to assign color to ReferenceLineInfo, applying fallback logic. */
107122
void assignColorToInput( ReferenceLineInfo &input ) const;
108-
123+
124+
void peaksAdded();
125+
void peaksRemoved();
126+
void peakModified();
127+
109128
InterSpec *m_interspec;
110129
D3SpectrumDisplayDiv *m_chart;
111130

src/BatchPeak.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,10 @@ BatchPeak::BatchPeakFitResult fit_peaks_in_file( const std::string &exemplar_fil
812812

813813
if( !exemplar_is_n42 && (options.use_exemplar_energy_cal || options.use_exemplar_energy_cal_for_background) )
814814
throw runtime_error( "Exemplar file wasnt an N42 file, but using its energy cal was specified - not allowed." );
815-
815+
816+
if( exemplar_is_n42 )
817+
818+
816819
if( exemplar_is_n42 )
817820
exemplar_n42 = exemplar;
818821
}//if( !cached_exemplar_n42 )
@@ -857,7 +860,7 @@ BatchPeak::BatchPeakFitResult fit_peaks_in_file( const std::string &exemplar_fil
857860
}//if( exemplar_is_n42 )
858861

859862
BatchPeakFitResult results;
860-
results.file_path = exemplar_filename;
863+
results.file_path = filename;
861864
results.options = options;
862865
results.exemplar = exemplar_n42;
863866
results.exemplar_sample_nums = exemplar_sample_nums;
@@ -878,8 +881,11 @@ BatchPeak::BatchPeakFitResult fit_peaks_in_file( const std::string &exemplar_fil
878881
const bool loaded = specfile->load_file( filename, SpecUtils::ParserType::Auto, filename );
879882
if( !loaded || !specfile->num_measurements() )
880883
{
881-
results.warnings.push_back( "Couldnt read in '" + filename + "' as a spectrum file -- skipping." );
882-
884+
if( SpecUtils::is_file(filename) )
885+
results.warnings.push_back( "Couldnt read in '" + filename + "' as a spectrum file -- skipping." );
886+
else
887+
results.warnings.push_back( "Could not access '" + filename + "' -- skipping." );
888+
883889
return results;
884890
}//if( !loaded )
885891
}//if( cached_spectrum ) / else

src/ExternalRidResult.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include "InterSpec_config.h"
2525

26+
#include "SpecUtils/StringAlgo.h"
27+
2628
#include "InterSpec/ExternalRidResult.h"
2729
#include "InterSpec/DecayDataBaseServer.h"
2830
#include "InterSpec/InterSpec.h"
@@ -85,13 +87,22 @@ void ExternalRidIsotope::init()
8587
if( const SandiaDecay::Element * const el = db->element(name) )
8688
{
8789
source = el;
88-
}else if( const ReactionGamma * const rctn_db = ReactionGammaServer::database() )
90+
}else if( ((name.find('(')!=std::string::npos) && (name.find(')')!=std::string::npos))
91+
|| SpecUtils::icontains(name,"ann") )
8992
{
90-
std::vector<ReactionGamma::ReactionPhotopeak> possible_rctns;
91-
rctn_db->gammas( name, possible_rctns );
92-
93-
if( !possible_rctns.empty() && possible_rctns[0].reaction ) // Take the first reaction found
94-
source = possible_rctns[0].reaction;
93+
try
94+
{
95+
std::vector<ReactionGamma::ReactionPhotopeak> possible_rctns;
96+
const ReactionGamma * const rctn_db = ReactionGammaServer::database();
97+
if( rctn_db )
98+
rctn_db->gammas( name, possible_rctns );
99+
100+
if( !possible_rctns.empty() && possible_rctns[0].reaction ) // Take the first reaction found
101+
source = possible_rctns[0].reaction;
102+
}catch( std::exception & )
103+
{
104+
// ReactionGammaServer::gammas throw if invalid reaction name.
105+
}
95106
}
96107
}//if( !nuc )
97108
}//if( std::holds_alternative<std::monostate>(source) && !name.empty() )

src/RefLineKinetic.cpp

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,14 @@ RefLineKinetic::RefLineKinetic( D3SpectrumDisplayDiv *chart, InterSpec *interspe
158158

159159
m_interspec->externalRidResultsRecieved().connect( boost::bind( &RefLineKinetic::autoRidResultsRecieved, this, boost::placeholders::_1 ) );
160160
m_interspec->colorThemeChanged().connect( boost::bind( &RefLineKinetic::colorThemeChanged, this, boost::placeholders::_1 ) );
161-
161+
PeakModel * const pmodel = m_interspec->peakModel();
162+
if( pmodel )
163+
{
164+
pmodel->rowsInserted().connect( boost::bind( &RefLineKinetic::peaksAdded, this ) );
165+
pmodel->rowsRemoved().connect( boost::bind( &RefLineKinetic::peaksRemoved, this ) );
166+
pmodel->dataChanged().connect( boost::bind( &RefLineKinetic::peakModified, this ) );
167+
}
168+
162169
// TODO: We also need to update lines after an energy calbration is done
163170
// TODO: We also need to make sure hint peaks are adjusted for energy changes
164171

@@ -244,16 +251,55 @@ void RefLineKinetic::assignColorToInput( ReferenceLineInfo &lines ) const
244251
}//void RefLineKinetic::assignColorToInput(...)
245252

246253

254+
void RefLineKinetic::peaksAdded()
255+
{
256+
if( !m_active )
257+
return;
258+
259+
m_renderFlags |= KineticRefLineRenderFlags::UpdateLines;
260+
m_chart->scheduleRenderKineticRefLine();
261+
m_current_ref_lines.reset();
262+
}
263+
264+
265+
void RefLineKinetic::peaksRemoved()
266+
{
267+
if( !m_active )
268+
return;
269+
270+
m_renderFlags |= KineticRefLineRenderFlags::UpdateLines;
271+
m_chart->scheduleRenderKineticRefLine();
272+
m_current_ref_lines.reset();
273+
}
274+
275+
276+
void RefLineKinetic::peakModified()
277+
{
278+
if( !m_active )
279+
return;
280+
281+
m_renderFlags |= KineticRefLineRenderFlags::UpdateLines;
282+
m_chart->scheduleRenderKineticRefLine();
283+
m_current_ref_lines.reset();
284+
}
285+
286+
247287
void RefLineKinetic::setActive( bool active )
248288
{
249289
if( m_active == active )
250290
return;
251291

252292
m_active = active;
253-
254-
m_renderFlags |= KineticRefLineRenderFlags::UpdateLines;
255-
m_chart->scheduleRenderKineticRefLine();
293+
256294
m_current_ref_lines.reset();
295+
if( m_active )
296+
{
297+
m_renderFlags |= KineticRefLineRenderFlags::UpdateLines;
298+
m_chart->scheduleRenderKineticRefLine();
299+
}else
300+
{
301+
m_chart->setKineticRefernceLines( vector<pair<double,ReferenceLineInfo>>{}, "" );
302+
}
257303
}//void RefLineKinetic::setActive( bool active )
258304

259305

@@ -270,6 +316,9 @@ shared_ptr<vector<pair<double,ReferenceLineInfo>>> RefLineKinetic::current_lines
270316

271317
void RefLineKinetic::autoSearchPeaksSet( const SpecUtils::SpectrumType spectrum )
272318
{
319+
if( !m_active )
320+
return;
321+
273322
m_renderFlags |= KineticRefLineRenderFlags::UpdateLines;
274323
m_chart->scheduleRenderKineticRefLine();
275324
m_current_ref_lines.reset();
@@ -1154,15 +1203,21 @@ void RefLineKinetic::startUpdateLines()
11541203
}else if( reaction_db )
11551204
{
11561205
// Try to get reaction from ReactionGamma database
1157-
vector<ReactionGamma::ReactionPhotopeak> possible_rctns;
1158-
reaction_db->gammas( result.nuclide_, possible_rctns );
1159-
1160-
if( !possible_rctns.empty() )
1206+
try
11611207
{
1162-
canonical_name = possible_rctns[0].reaction->name();
1163-
found_source = true;
1208+
vector<ReactionGamma::ReactionPhotopeak> possible_rctns;
1209+
reaction_db->gammas( result.nuclide_, possible_rctns );
1210+
1211+
if( !possible_rctns.empty() )
1212+
{
1213+
canonical_name = possible_rctns[0].reaction->name();
1214+
found_source = true;
1215+
}
1216+
}catch( std::exception & )
1217+
{
1218+
//we get here for example if nuclide did have paranthesis
11641219
}
1165-
}
1220+
}//
11661221
}//if( result.nuclide_ is nuclide ) / else
11671222

11681223
if( !found_source )

src/RelActCalcAuto.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2746,7 +2746,13 @@ struct RelActAutoCostFcn /* : ROOT::Minuit2::FCNBase() */
27462746

27472747
assert( manual_solution.m_rel_eff_eqn_coefficients.size() > manual_index );
27482748
parameters[this_rel_eff_start + 1] = manual_solution.m_rel_eff_eqn_coefficients.at(manual_index); //Areal density; both manual and auto RelEff use g/cm2
2749-
2749+
2750+
if( rel_eff_curve.phys_model_self_atten->fit_areal_density )
2751+
{
2752+
if( parameters[this_rel_eff_start + 1] < 1.0E-4 )
2753+
parameters[this_rel_eff_start + 1] = std::min( std::max( 1.0, rel_eff_curve.phys_model_self_atten->lower_fit_areal_density), rel_eff_curve.phys_model_self_atten->upper_fit_areal_density );
2754+
}//if( rel_eff_curve.phys_model_self_atten->fit_areal_density )
2755+
27502756
manual_index += 1;
27512757
}//if( options.phys_model_self_atten )
27522758

0 commit comments

Comments
 (0)