Skip to content

Commit 75f34f8

Browse files
committedJan 7, 2025·
Merge branch 'master' of github.com:sandialabs/InterSpec
2 parents 1c77100 + febd7ea commit 75f34f8

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed
 

‎src/RelActCalcAuto.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,18 +2297,20 @@ struct RelActAutoCostFcn /* : ROOT::Minuit2::FCNBase() */
22972297
}//if( we failed to get covariance ) / else
22982298
}//if( solution.m_status == RelActCalcAuto::RelActAutoSolution::Status::Success )
22992299

2300-
solution.m_num_function_eval_total = cost_functor->m_ncalls;
2300+
solution.m_num_function_eval_total = static_cast<int>( cost_functor->m_ncalls );
23012301

23022302
solution.m_final_parameters = parameters;
23032303

23042304
solution.m_energy_cal_adjustments[0] = parameters[0];
23052305
solution.m_energy_cal_adjustments[1] = parameters[1];
23062306

2307-
shared_ptr<const SpecUtils::EnergyCalibration> new_cal = cost_functor->m_energy_cal;
2307+
shared_ptr<const SpecUtils::EnergyCalibration> new_cal = solution.m_foreground->energy_calibration();
23082308
if( success && options.fit_energy_cal )
23092309
{
2310-
auto new_cal = make_shared<SpecUtils::EnergyCalibration>( *cost_functor->m_energy_cal );
2310+
auto modified_new_cal = make_shared<SpecUtils::EnergyCalibration>( *new_cal );
23112311

2312+
const double offset = parameters[0];
2313+
const double gain_mult = parameters[1];
23122314
const size_t num_channel = cost_functor->m_energy_cal->num_channels();
23132315
const SpecUtils::EnergyCalType energy_cal_type = cost_functor->m_energy_cal->type();
23142316

@@ -2320,27 +2322,30 @@ struct RelActAutoCostFcn /* : ROOT::Minuit2::FCNBase() */
23202322
{
23212323
vector<float> coefs = cost_functor->m_energy_cal->coefficients();
23222324
assert( coefs.size() >= 2 );
2323-
coefs[0] += parameters[0];
2324-
coefs[1] *= parameters[1];
2325+
coefs[0] -= offset;
2326+
coefs[1] /= gain_mult;
23252327

23262328
const auto &dev_pairs = cost_functor->m_energy_cal->deviation_pairs();
23272329

23282330
if( energy_cal_type == SpecUtils::EnergyCalType::FullRangeFraction )
2329-
new_cal->set_full_range_fraction( num_channel, coefs, dev_pairs );
2331+
modified_new_cal->set_full_range_fraction( num_channel, coefs, dev_pairs );
23302332
else
2331-
new_cal->set_polynomial( num_channel, coefs, dev_pairs );
2333+
modified_new_cal->set_polynomial( num_channel, coefs, dev_pairs );
23322334

23332335
break;
23342336
}//case polynomial or FRF
23352337

2336-
23372338
case SpecUtils::EnergyCalType::LowerChannelEdge:
23382339
{
2339-
vector<float> lower_energies = *cost_functor->m_energy_cal->channel_energies();
2340-
for( float &energy : lower_energies )
2341-
energy = parameters[0] + (parameters[1] * energy);
2340+
assert( new_cal->channel_energies() );
2341+
if( !new_cal->channel_energies() || new_cal->channel_energies()->empty() )
2342+
throw runtime_error( "Invalid lower channel energies???" );
2343+
2344+
vector<float> lower_energies = *new_cal->channel_energies();
2345+
for( float &x : lower_energies )
2346+
x = (x - offset) / gain_mult;
23422347

2343-
new_cal->set_lower_channel_energy( num_channel, std::move(lower_energies) );
2348+
modified_new_cal->set_lower_channel_energy( num_channel, std::move(lower_energies) );
23442349

23452350
break;
23462351
}//case LowerChannelEdge
@@ -2349,8 +2354,8 @@ struct RelActAutoCostFcn /* : ROOT::Minuit2::FCNBase() */
23492354
break;
23502355
}//switch( m_energy_cal->type() )
23512356

2352-
new_cal = new_cal;
2353-
solution.m_spectrum->set_energy_calibration( new_cal );
2357+
new_cal = modified_new_cal;
2358+
solution.m_spectrum->set_energy_calibration( modified_new_cal );
23542359
}//if( options.fit_energy_cal )
23552360

23562361

0 commit comments

Comments
 (0)
Please sign in to comment.