Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sandialabs/InterSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohns committed Apr 7, 2023
2 parents 551d0a2 + 6a53bca commit 4d6bb1f
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 38 deletions.
5 changes: 3 additions & 2 deletions InterSpec/EnergyCalTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,16 @@ class EnergyCalTool : public Wt::WContainerWidget

/** Sets the energy calibration of the specified SpecMea/SampleNumber/Detector to the given energy calibration.
Updates peaks only if one of the calibrations being set corresponds to a calibration being set.
Updates peaks only if `adjust_peaks` is true, and one of the calibrations being set corresponds to a calibration being set.
Note, does not call #EnergyCalTool::doRefreshFromFiles or #InterSpec::refreshDisplayedCharts (which #applyCalChange does),
so you should call these functions after you call into this function all the times you currently will.
Throws std::exception on error.
*/
void setEnergyCal( std::shared_ptr<const SpecUtils::EnergyCalibration> new_cal,
const MeasToApplyCoefChangeTo &changemeas );
const MeasToApplyCoefChangeTo &changemeas,
const bool adjust_peaks );

/** Adds a deviation pair from the graphical calibration. Adds the deviation pair measurements
the user has selected in the GUI (e.g., Back/For/Sec, visible detectors, entire file, etc).
Expand Down
5 changes: 2 additions & 3 deletions InterSpec/InterSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,8 @@ class InterSpec : public Wt::WContainerWidget
enum SetSpectrumOptions
{
CheckToPreservePreviousEnergyCal = 0x01,
CheckForRiidResults = 0x02

// TODO: it seems both these options are the same everywhere - maybe go back and just use a bool
CheckForRiidResults = 0x02,
SkipParseWarnings = 0x04
};//SetSpectrumOptions


Expand Down
11 changes: 8 additions & 3 deletions InterSpec_resources/RelActManualGui.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
div.RelActManualGui
{
overflow-x: hidden;
}

.RelActNucCol
{

/* Use a fixed width for now. */
width: 188px;
overflow-x: hidden;
}

.RelActNucCol .ToolTabColumnTitle
{
/* Set the approx with for when no nuclides are inserted.*/
min-width: 175px;
}

.ManRelEffNucDisp.Wt-panel
Expand Down Expand Up @@ -165,6 +169,7 @@
.RelActNucCol .ToolTabTitledColumnContent
{
overflow-y: auto;
overflow-x: hidden;
}


Expand Down
51 changes: 30 additions & 21 deletions src/EnergyCalTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ void EnergyCalTool::applyCALpEnergyCal( std::map<std::string,std::shared_ptr<con

if( tochange.detectors.size() == 1 )
{
setEnergyCal( new_cal, tochange );
setEnergyCal( new_cal, tochange, true );
}else
{
// Check to see if all detectors are using the same energy calibration, and if so, set the
Expand Down Expand Up @@ -1878,17 +1878,29 @@ void EnergyCalTool::applyCALpEnergyCal( std::map<std::string,std::shared_ptr<con
applyCalChange( old_disp_cal, new_cal, { tochange }, false );
}else
{
setEnergyCal( new_cal, tochange );
setEnergyCal( new_cal, tochange, true );
}
}//if( we are changing a single detector ) / else
}else
{
// We will apply the input calibration on a detector-by-detector basis, requiring the
// input to have info for every relevant detector.
//
// Note, I *think* it should be the case applyCalChange(...) will do the shifting of peaks
// appropriately, if we apply the energy calibration detector by detector - but this also looks
// a bit dicey, so need to be checked.
// We will only adjust peak positions if the detectors energy calibration is the
// `suggested_sum_energy_calibration`, and even then, only once.
// (note: not trusting disp_spec->energy_calibration() to be same as
// `suggested_sum_energy_calibration` - but I think we could).
bool adjusted_peaks = false;
shared_ptr<const SpecUtils::EnergyCalibration> display_cal;
try
{
display_cal = tochange.meas->suggested_sum_energy_calibration( disp_samples, disp_detectors );
}catch( std::exception & )
{
}

if( !display_cal )
display_cal = old_disp_cal;

string missing_dets, extra_dets;
for( const auto &det : tochange.detectors )
Expand Down Expand Up @@ -1953,15 +1965,20 @@ void EnergyCalTool::applyCALpEnergyCal( std::map<std::string,std::shared_ptr<con
throw runtime_error( "The number of new calibration channels ("
+ std::to_string( new_cal->num_channels() )
+ " doesnt match old calibration ("
+ std::to_string( old_disp_cal->num_channels() )
+ std::to_string( old_cal->num_channels() )
+ ") for detector '" + det + "'." );

MeasToApplyCoefChangeTo det_specific_tochange = tochange;

det_specific_tochange.detectors.clear();
det_specific_tochange.detectors.insert( det );

setEnergyCal( new_cal, det_specific_tochange );
// We will adjust the peak energies, only if the calibrations being changed contain the
// display energy calibration.
const bool adjust_peaks = !adjusted_peaks && (display_cal == old_cal);
adjusted_peaks |= adjust_peaks;

setEnergyCal( new_cal, det_specific_tochange, adjust_peaks );
}//for( const string &det : detectors_to_apply )
}//if( det_to_cal.size() == 1 ) / else

Expand Down Expand Up @@ -2441,7 +2458,7 @@ void EnergyCalTool::applyCalChange( std::shared_ptr<const SpecUtils::EnergyCalib


void EnergyCalTool::setEnergyCal( shared_ptr<const SpecUtils::EnergyCalibration> new_cal,
const MeasToApplyCoefChangeTo &changemeas )
const MeasToApplyCoefChangeTo &changemeas, const bool adjust_peaks )
{
using namespace SpecUtils;

Expand Down Expand Up @@ -2478,7 +2495,7 @@ void EnergyCalTool::setEnergyCal( shared_ptr<const SpecUtils::EnergyCalibration>
{
assert( 0 );
throw runtime_error( "EnergyCalTool::setEnergyCal: measurement to change must be foreground,"
" background, or secondary spec displaye" );
" background, or secondary spec displayed" );
}


Expand All @@ -2487,13 +2504,6 @@ void EnergyCalTool::setEnergyCal( shared_ptr<const SpecUtils::EnergyCalibration>
const shared_ptr<const SpecUtils::EnergyCalibration> display_cal
= changemeas.meas->suggested_sum_energy_calibration( dispsamples, dispdets );

// We will adjust the peak energies, only if the calibrations being changed contain the display
// energy calibration.
// Note that this does still leave some room for peaks to get adjusted multiple times if multiple
// detectors share an energy calibration, and you call this function multiple times from a loop
// in an order... maybe we should add some other mechanism
bool adjust_peaks = false;

try
{
for( const int sample : changemeas.sample_numbers )
Expand All @@ -2519,9 +2529,8 @@ void EnergyCalTool::setEnergyCal( shared_ptr<const SpecUtils::EnergyCalibration>
+ " channels but calibration being set has "
+ to_string(new_cal->num_channels()) );


if( new_cal == display_cal )
adjust_peaks = true;
//if( display_cal == meas_old_cal )
// adjust_peaks = true;

old_to_new_cals[meas_old_cal] = new_cal;
}//for( const string &detname : change.detectors )
Expand All @@ -2532,11 +2541,11 @@ void EnergyCalTool::setEnergyCal( shared_ptr<const SpecUtils::EnergyCalibration>

throw runtime_error( msg );
}//try catch


// Now go through and translate the peaks, but we wont actually update them to the SpecMeas
// until we know we can update all the peaks
const set<set<int>> peaksamples = changemeas.meas->sampleNumsWithPeaks();
const set<set<int>> peaksamples = adjust_peaks ? changemeas.meas->sampleNumsWithPeaks()
: set<set<int>>();

// The peaks position (i.e., mean channel number) is determined by
// #SpecFile::suggested_sum_energy_calibration, however we may be applying an energy
Expand Down
2 changes: 1 addition & 1 deletion src/InterSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9563,7 +9563,7 @@ void InterSpec::setSpectrum( std::shared_ptr<SpecMeas> meas,


//Lets see if there are any parse warnings that we should give to the user.
if( meas && !sameSpecFile )
if( meas && !sameSpecFile && !(options & InterSpec::SetSpectrumOptions::SkipParseWarnings) )
{
Wt::WApplication *app = wApp;

Expand Down
8 changes: 8 additions & 0 deletions src/RelActManualGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ RelActManualGui::RelActManualGui( InterSpec *viewer, Wt::WContainerWidget *paren
wApp->useStyleSheet( "InterSpec_resources/RelActManualGui.css" );

addStyleClass( "EnergyCalTool RelActManualGui" );

// If the widget gets to less than about 1145px wide, then Wt layout will start shrinking
// the columns, even though they are fixed or minimum sized. When this happens if we dont
// set the vertical overflow to hidden, a useless horizantal scrollbar will show up on the
// entire bottom of the widget (but it only will ever scroll for like 5 px - probably just
// padding somewhere), even though each column will also get scrollbars or be squeezed.
setOverflow( Overflow::OverflowHidden, Wt::Orientation::Horizontal );

init();
}//RelActManualGui constructor
Expand Down Expand Up @@ -788,6 +795,7 @@ void RelActManualGui::init()

WContainerWidget *resultContent = new WContainerWidget();
resultContent->addStyleClass( "ToolTabTitledColumnContent ResultColumnContent" );
resultContent->setMinimumSize(350, WLength::Auto );
collayout->addWidget( resultContent, 1, 0 );
collayout->setRowStretch( 1, 1 );
m_layout->addWidget( resCol, 0, 3 );
Expand Down
66 changes: 58 additions & 8 deletions src/SpecMeasManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,15 +1775,27 @@ bool SpecMeasManager::handleCALpFile( std::istream &infile, SimpleDialog *dialog
return true;
}//if( !currdata )

const size_t nchannel = currdata->num_gamma_channels();
set<string> fore_gamma_dets;
const shared_ptr<SpecMeas> foreground = m_viewer->measurment( SpecUtils::SpectrumType::Foreground );
const set<int> &fore_samples = m_viewer->displayedSamples( SpecUtils::SpectrumType::Foreground );
const vector<string> fore_dets = m_viewer->detectorsToDisplay( SpecUtils::SpectrumType::Foreground );

if( !foreground )
return false;

const size_t num_display_channel = currdata->num_gamma_channels();
map<string,shared_ptr<const SpecUtils::EnergyCalibration>> det_to_cal;

const std::streampos start_pos = infile.tellg();

while( infile.good() )
{
string name;
const auto cal = EnergyCal::energy_cal_from_CALp_file( infile, nchannel, name );

// Note that num_display_channel is for the displayed data - the individual detectors may
// have different numbers of channels - we'll fix this up after initially loading the cal
// (we need to know the detectors name the cal is for in order to fix it up)
shared_ptr<SpecUtils::EnergyCalibration> cal = EnergyCal::energy_cal_from_CALp_file( infile, num_display_channel, name );

if( !cal )
{
Expand Down Expand Up @@ -1817,15 +1829,52 @@ bool SpecMeasManager::handleCALpFile( std::istream &infile, SimpleDialog *dialog
continue;
}

// The calbiration may not be for the correct number of channels, for files that have detectors
// with differnt num channels; we'll check for this here and fix the calibration up for this
// case.
// We could also do this for `name.empty()` case, but we shouldnt need to, I dont think.
if( !name.empty() )
{
for( const int sample_num : fore_samples )
{
const auto m = foreground->measurement(sample_num, name);
const size_t nchan = m ? m->num_gamma_channels() : size_t(0);
if( nchan > 3 )
{
if( nchan != num_display_channel )
{
try
{
switch( cal->type() )
{
case SpecUtils::EnergyCalType::Polynomial:
case SpecUtils::EnergyCalType::UnspecifiedUsingDefaultPolynomial:
cal->set_polynomial( nchan, cal->coefficients(), cal->deviation_pairs() );
break;

case SpecUtils::EnergyCalType::FullRangeFraction:
cal->set_full_range_fraction( nchan, cal->coefficients(), cal->deviation_pairs() );
break;

case SpecUtils::EnergyCalType::LowerChannelEdge:
case SpecUtils::EnergyCalType::InvalidEquationType:
break;
}//switch( cal->type() )
}catch( std::exception &e )
{
cerr << "Failed to change number of channels for energy calibration: " << e.what() << endl;
}
}//if( m->num_gamma_channels() != num_display_channel )

break;
}//if( nchan > 3 )
}//for( const int sample_num : fore_samples )
}//if( !name.empty() )

det_to_cal[name] = cal;
}//while( true )

set<string> fore_gamma_dets;
const shared_ptr<SpecMeas> foreground = m_viewer->measurment( SpecUtils::SpectrumType::Foreground );
const set<int> &fore_samples = m_viewer->displayedSamples( SpecUtils::SpectrumType::Foreground );
const vector<string> fore_dets = m_viewer->detectorsToDisplay( SpecUtils::SpectrumType::Foreground );

if( det_to_cal.empty() || !foreground )
if( det_to_cal.empty() )
{
infile.seekg( start_pos, ios::beg );
return false;
Expand Down Expand Up @@ -3197,6 +3246,7 @@ void SpecMeasManager::displayFile( int row,
{
options |= InterSpec::SetSpectrumOptions::CheckToPreservePreviousEnergyCal;
options |= InterSpec::SetSpectrumOptions::CheckForRiidResults;
options |= InterSpec::SetSpectrumOptions::SkipParseWarnings;
}

m_viewer->setSpectrum( measement_ptr, background_sample_numbers,
Expand Down

0 comments on commit 4d6bb1f

Please sign in to comment.