@@ -2297,18 +2297,20 @@ struct RelActAutoCostFcn /* : ROOT::Minuit2::FCNBase() */
2297
2297
}// if( we failed to get covariance ) / else
2298
2298
}// if( solution.m_status == RelActCalcAuto::RelActAutoSolution::Status::Success )
2299
2299
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 ) ;
2301
2301
2302
2302
solution.m_final_parameters = parameters;
2303
2303
2304
2304
solution.m_energy_cal_adjustments [0 ] = parameters[0 ];
2305
2305
solution.m_energy_cal_adjustments [1 ] = parameters[1 ];
2306
2306
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 () ;
2308
2308
if ( success && options.fit_energy_cal )
2309
2309
{
2310
- auto new_cal = make_shared<SpecUtils::EnergyCalibration>( *cost_functor-> m_energy_cal );
2310
+ auto modified_new_cal = make_shared<SpecUtils::EnergyCalibration>( *new_cal );
2311
2311
2312
+ const double offset = parameters[0 ];
2313
+ const double gain_mult = parameters[1 ];
2312
2314
const size_t num_channel = cost_functor->m_energy_cal ->num_channels ();
2313
2315
const SpecUtils::EnergyCalType energy_cal_type = cost_functor->m_energy_cal ->type ();
2314
2316
@@ -2320,27 +2322,30 @@ struct RelActAutoCostFcn /* : ROOT::Minuit2::FCNBase() */
2320
2322
{
2321
2323
vector<float > coefs = cost_functor->m_energy_cal ->coefficients ();
2322
2324
assert ( coefs.size () >= 2 );
2323
- coefs[0 ] += parameters[ 0 ] ;
2324
- coefs[1 ] *= parameters[ 1 ] ;
2325
+ coefs[0 ] -= offset ;
2326
+ coefs[1 ] /= gain_mult ;
2325
2327
2326
2328
const auto &dev_pairs = cost_functor->m_energy_cal ->deviation_pairs ();
2327
2329
2328
2330
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 );
2330
2332
else
2331
- new_cal ->set_polynomial ( num_channel, coefs, dev_pairs );
2333
+ modified_new_cal ->set_polynomial ( num_channel, coefs, dev_pairs );
2332
2334
2333
2335
break ;
2334
2336
}// case polynomial or FRF
2335
2337
2336
-
2337
2338
case SpecUtils::EnergyCalType::LowerChannelEdge:
2338
2339
{
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;
2342
2347
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) );
2344
2349
2345
2350
break ;
2346
2351
}// case LowerChannelEdge
@@ -2349,8 +2354,8 @@ struct RelActAutoCostFcn /* : ROOT::Minuit2::FCNBase() */
2349
2354
break ;
2350
2355
}// switch( m_energy_cal->type() )
2351
2356
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 );
2354
2359
}// if( options.fit_energy_cal )
2355
2360
2356
2361
0 commit comments