Skip to content

Commit 7f9f723

Browse files
committed
Added more granular PeakDef XML versioning, and some other small cleanup.
Renamed some PeakDef member variables to avoid ambitious terminology. Made PeakDef XML versioning to be Major.Minor format, to better handle backwards compatible upgrades.
1 parent 24b6fb4 commit 7f9f723

File tree

7 files changed

+241
-143
lines changed

7 files changed

+241
-143
lines changed

InterSpec/PeakDef.h

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -384,17 +384,10 @@ class PeakDef
384384
Mean,
385385
Sigma,
386386
GaussAmplitude,
387-
LandauAmplitude, //multiplies peak ampliture (so is between 0.0 and ~0.2)
387+
LandauAmplitude, //multiplies peak amplitude (so is between 0.0 and ~0.2)
388388
LandauMode,
389389
LandauSigma,
390-
// OffsetPolynomial0,
391-
// OffsetPolynomial1,
392-
// OffsetPolynomial2,
393-
// OffsetPolynomial3,
394-
// OffsetPolynomial4,
395-
// RangeStartEnergy,
396-
// RangeEndEnergy,
397-
Chi2DOF, //for peaks that share a ROI/Continuum, this values is for entire ROI/Continuum
390+
Chi2DOF, //for peaks that share a ROI/Continuum, this values is for entire ROI/Continuum
398391
NumCoefficientTypes
399392
};//enum CoefficientType
400393

@@ -485,28 +478,22 @@ class PeakDef
485478
inline void setAmplitudeUncert( const double a );
486479

487480

488-
inline bool useForCalibration() const;
489-
inline void useForCalibration( const bool use );
481+
inline bool useForEnergyCalibration() const;
482+
inline void useForEnergyCalibration( const bool use );
490483

491484
inline bool useForShieldingSourceFit() const;
492485
inline void useForShieldingSourceFit( const bool use );
493-
494-
/** Returns if should use for DRF fit. If has not been explicitly set, will
495-
return true if their is a nuclide and transition defined, and the source
496-
gamma type is SourceGammaType::NormalGamma.
497-
\sa MakeDrf
498-
*/
499-
inline bool useForDrfFit() const;
500486

501-
/** Sets if the peak should be used or not for DRF fit.
502-
\sa MakeDrf
487+
/** Returns if should use for DRF intrinsic efficiency fit. Note that this does not check that the nuclide and transition has actually
488+
been defined.
503489
*/
504-
inline void useForDrfFit( const bool use );
490+
inline bool useForDrfIntrinsicEffFit() const;
491+
inline void setUseForDrfIntrinsicEffFit( const bool use );
492+
inline bool useForDrfFwhmFit() const;
493+
inline void setUseForDrfFwhmFit( const bool use );
494+
inline bool useForDrfDepthOfInteractionFit() const;
495+
inline void setUseForDrfDepthOfInteractionFit( const bool use );
505496

506-
/** Resets if the peak should be used for DRF fit.
507-
\sa MakeDrf
508-
*/
509-
inline void resetUseForDrfFit();
510497

511498
inline double chi2dof() const;
512499
inline bool chi2Defined() const;
@@ -824,7 +811,13 @@ class PeakDef
824811

825812
std::shared_ptr<PeakContinuum> m_continuum;
826813

827-
static const int sm_xmlSerializationVersion;
814+
/** For versioning the XML we will use a major.minor notation.
815+
Changes made to the XML that are backward compatible (e.g., will read into older version of InterSpec just fine - so this is like if you
816+
just add a field), increment the minor version. Breaking changes (e.x., a change to the name of a XML tag) increment the major version
817+
and will cause older versions of InterSpec to not read in the peak.
818+
*/
819+
static const int sm_xmlSerializationMajorVersion;
820+
static const int sm_xmlSerializationMinorVersion;
828821

829822
//A maximum of one of the following will be valid: m_parentNuclide,
830823
// m_xrayElement, or m_reaction
@@ -843,23 +836,18 @@ class PeakDef
843836
const ReactionGamma::Reaction *m_reaction;
844837
float m_reactionEnergy;
845838

846-
bool m_useForCalibration;
839+
bool m_useForEnergyCal;
847840
bool m_useForShieldingSourceFit;
841+
848842

849-
/** Variable to tell if this peak should be used in the detector response
850-
model fit; currently the MakeDRF widget only sets this when saving a N42
851-
fit.
852-
Can only take on the values {-1,0,1}.
853-
-1 means it has not been set and so some simple heuristics will be used to
854-
determine if it should be set
855-
0 means do not use
856-
1 means do use
857-
858-
///ToDo: Implement logic similar to #PeakModel::kUseForShieldingSourceFit
859-
for this variable, and maybe make it a bool. Also have MakeDrf
860-
widget update it as the user changes it in the widget.
861-
*/
862-
int m_useForDetectorResponseFit;
843+
/** Fif this peak should be used in the detector response function model fit for intrinsic efficiency */
844+
bool m_useForDrfIntrinsicEffFit;
845+
bool m_useForDrfFwhmFit;
846+
bool m_useForDrfDepthOfInteractionFit;
847+
848+
static const bool sm_defaultUseForDrfIntrinsicEffFit;
849+
static const bool sm_defaultUseForDrfFwhmFit;
850+
static const bool sm_defaultUseForDrfDepthOfInteractionFit;
863851

864852
/** Line color of the peak. Will also (currently) be used to set the fill of
865853
the peak, just with the alpha channel lowered.
@@ -1042,21 +1030,21 @@ void PeakDef::setAmplitudeUncert( const double a )
10421030
}
10431031

10441032

1045-
bool PeakDef::useForCalibration() const
1033+
bool PeakDef::useForEnergyCalibration() const
10461034
{
1047-
return ( m_useForCalibration &&
1035+
return ( m_useForEnergyCal &&
10481036
( (m_radparticleIndex>=0 && m_transition && m_parentNuclide)
10491037
|| (m_parentNuclide && (m_sourceGammaType==PeakDef::AnnihilationGamma))
10501038
|| (m_xrayElement && m_xrayEnergy>0.0)
10511039
|| (m_reaction && m_reactionEnergy>0.0)
10521040
) );
1053-
}//void useForCalibration() const
1041+
}//void useForEnergyCalibration() const
10541042

10551043

1056-
void PeakDef::useForCalibration( const bool use )
1044+
void PeakDef::useForEnergyCalibration( const bool use )
10571045
{
1058-
m_useForCalibration = use;
1059-
}//void useForCalibration( const bool use )
1046+
m_useForEnergyCal = use;
1047+
}//void useForEnergyCalibration( const bool use )
10601048

10611049

10621050
bool PeakDef::useForShieldingSourceFit() const
@@ -1086,27 +1074,42 @@ void PeakDef::useForShieldingSourceFit( const bool use )
10861074
}//void useForShieldingSourceFit( const bool use )
10871075

10881076

1089-
bool PeakDef::useForDrfFit() const
1077+
bool PeakDef::useForDrfIntrinsicEffFit() const
10901078
{
1091-
if( m_useForDetectorResponseFit == 1 )
1092-
return true;
1093-
if( m_useForDetectorResponseFit == 0 )
1094-
return false;
1095-
1096-
if( m_parentNuclide && m_transition && m_sourceGammaType==SourceGammaType::NormalGamma )
1097-
return true;
1079+
//if( !m_parentNuclide || !m_transition || (m_sourceGammaType != SourceGammaType::NormalGamma) )
1080+
// return false;
10981081

1099-
return false;
1082+
return m_useForDrfIntrinsicEffFit;
11001083
}
11011084

1102-
void PeakDef::useForDrfFit( const bool use )
1085+
1086+
void PeakDef::setUseForDrfIntrinsicEffFit( const bool use )
11031087
{
1104-
m_useForDetectorResponseFit = (use ? 1 : 0);
1088+
m_useForDrfIntrinsicEffFit = use;
11051089
}
11061090

1107-
void PeakDef::resetUseForDrfFit()
1091+
1092+
bool PeakDef::useForDrfFwhmFit() const
1093+
{
1094+
return m_useForDrfFwhmFit;
1095+
}
1096+
1097+
1098+
void PeakDef::setUseForDrfFwhmFit( const bool use )
1099+
{
1100+
m_useForDrfFwhmFit = use;
1101+
}
1102+
1103+
1104+
bool PeakDef::useForDrfDepthOfInteractionFit() const
1105+
{
1106+
return m_useForDrfDepthOfInteractionFit;
1107+
}
1108+
1109+
1110+
void PeakDef::setUseForDrfDepthOfInteractionFit( const bool use )
11081111
{
1109-
m_useForDetectorResponseFit = -1;
1112+
m_useForDrfDepthOfInteractionFit = use;
11101113
}
11111114

11121115
#endif

src/D3SpectrumDisplayDiv.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,6 @@ void D3SpectrumDisplayDiv::setSearchEnergies( const vector<pair<double,double>>
10921092

10931093
bool D3SpectrumDisplayDiv::removeDecorativeHighlightRegion( size_t uniqueid )
10941094
{
1095-
cerr << "D3SpectrumDisplayDiv::removeDecorativeHighlightRegion: uniqueid=" << uniqueid << endl;
10961095
if( uniqueid < 3 )
10971096
return false;
10981097

@@ -1103,11 +1102,15 @@ bool D3SpectrumDisplayDiv::removeDecorativeHighlightRegion( size_t uniqueid )
11031102
{
11041103
m_highlights.erase( m_highlights.begin() + i );
11051104
setHighlightRegionsToClient();
1106-
cout << "Found it" << endl;
11071105
return true;
11081106
}
11091107
}
1110-
cout << "Didnt find it" << endl;
1108+
1109+
#if( PERFORM_DEVELOPER_CHECKS )
1110+
log_developer_error( __func__, ("D3SpectrumDisplayDiv::removeDecorativeHighlightRegion:"
1111+
" Didnt find uniqueid=" + std::to_string(uniqueid)).c_str() );
1112+
#endif
1113+
11111114
return false;
11121115
}//void removeDecorativeHighlightRegions()
11131116

src/EnergyCalMultiFile.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ WFlags<ItemFlag> EnergyCalMultiFileModel::flags( const WModelIndex &index ) cons
11761176

11771177
boost::any EnergyCalMultiFileModel::headerData( int section, Wt::Orientation orientation,
11781178
int role ) const
1179-
{
1179+
{
11801180
// if( role == DisplayRole )
11811181
// {
11821182
// switch( section )
@@ -1249,10 +1249,14 @@ void EnergyCalMultiFileModel::refreshData()
12491249
if( cal && measpeaks )
12501250
{
12511251
for( const PeakPtr &peak : *measpeaks )
1252-
samplespeaks.emplace_back( peak->useForEnergyCalibration(), peak );
1252+
{
1253+
if( peak && peak->hasSourceGammaAssigned() )
1254+
samplespeaks.emplace_back( peak->useForEnergyCalibration(), peak );
1255+
}
12531256
}
12541257

1255-
peaks.push_back( samplesinfo );
1258+
if( !samplespeaks.empty() )
1259+
peaks.push_back( samplesinfo );
12561260
}//for( const IntSet &samplnums : peaksamplenums )
12571261

12581262
newdata.push_back( peaks );

src/EnergyCalTool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ bool EnergyCalTool::canDoEnergyFit()
23842384

23852385
size_t nPeaksToUse = 0;
23862386
for( const PeakModel::PeakShrdPtr &p : *peaks )
2387-
nPeaksToUse += (p && p->useForCalibration());
2387+
nPeaksToUse += (p && p->useForEnergyCalibration());
23882388

23892389
if( nPeaksToUse < 1 )
23902390
return false;
@@ -2517,7 +2517,7 @@ void EnergyCalTool::fitCoefficients()
25172517
continue;
25182518
const PeakDef &peak = *peakptr;
25192519

2520-
if( !peak.useForCalibration() )
2520+
if( !peak.useForEnergyCalibration() )
25212521
continue;
25222522

25232523
const double wantedEnergy = peak.gammaParticleEnergy();

src/GammaInteractionCalc.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -956,24 +956,24 @@ void PointSourceShieldingChi2Fcn::massFraction( double &massFrac,
956956
const std::vector<double> &errors ) const
957957
{
958958
massFrac = uncert = 0.0;
959-
typedef MaterialToNucsMap::const_iterator MaterialToNucsMapIter;
959+
960960
if( !material || !nuc )
961-
throw runtime_error( "PointSourceShieldingChi2Fcn::massFraction(): invalid "
962-
"input" );
963-
MaterialToNucsMapIter matpos = m_nuclidesToFitMassFractionFor.find(material);
961+
throw runtime_error( "PointSourceShieldingChi2Fcn::massFraction(): invalid input" );
964962

965-
if( matpos == m_nuclidesToFitMassFractionFor.end() )
963+
const auto matpos = m_nuclidesToFitMassFractionFor.find(material);
964+
965+
if( matpos == end(m_nuclidesToFitMassFractionFor) )
966966
throw runtime_error( "PointSourceShieldingChi2Fcn::massFraction(): "
967967
+ material->name + " is not a material with a variable"
968968
" mass fraction" );
969-
const std::vector<const SandiaDecay::Nuclide *> &nucs
970-
= m_nuclidesToFitMassFractionFor.find(material)->second;
971-
vector<const SandiaDecay::Nuclide *>::const_iterator pos;
969+
970+
const std::vector<const SandiaDecay::Nuclide *> &nucs = matpos->second;
971+
972972
//nucs is actually sorted by symbol name, could do better than linear search
973-
pos = std::find( nucs.begin(), nucs.end(), nuc );
974-
if( pos == nucs.end() )
973+
const auto pos = std::find( begin(nucs), end(nucs), nuc );
974+
if( pos == end(nucs) )
975975
throw runtime_error( "PointSourceShieldingChi2Fcn::massFraction(): "
976-
+nuc->symbol + " was not a nuc fit for mass fraction"
976+
+ nuc->symbol + " was not a nuc fit for mass fraction"
977977
" in " + material->name );
978978

979979
double totalfrac = 0.0;
@@ -989,8 +989,7 @@ void PointSourceShieldingChi2Fcn::massFraction( double &massFrac,
989989
}//for( const SandiaDecay::Nuclide *n : nucs )
990990

991991
size_t matmassfracstart = 0;
992-
for( MaterialToNucsMapIter iter = m_nuclidesToFitMassFractionFor.begin();
993-
iter != matpos; ++iter )
992+
for( auto iter = begin(m_nuclidesToFitMassFractionFor); iter != matpos; ++iter )
994993
{
995994
if( iter->second.size() )
996995
matmassfracstart += (iter->second.size()-1);

0 commit comments

Comments
 (0)