Skip to content

Commit a27bb48

Browse files
committed
Fix second and later URI spectra not getting first spectrums energy calibration, when it isnt specified for the later spectra.
1 parent bc1810c commit a27bb48

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/UriSpectrum.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -2134,12 +2134,41 @@ std::shared_ptr<SpecFile> to_spec_file( const std::vector<UrlSpectrum> &spec_inf
21342134
}
21352135
}//for( auto &meas : measurements )
21362136
}//if( we can re-use energy cal ) / else
2137-
}//if( !spec.m_energy_cal_coeffs.empty() )
2137+
}else if( first_cal && (spec.m_channel_data.size() == first_cal->num_channels()) )
2138+
{
2139+
// If no energy cal specified, see if one for this number of channels was already given.
2140+
m->set_energy_calibration( first_cal );
2141+
}//if( !spec.m_energy_cal_coeffs.empty() ) / else
21382142

21392143
measurements.push_back( m );
21402144
specfile->add_measurement( m, false );
21412145
}//for( const UrlSpectrum &spec : spec_infos )
21422146

2147+
// If energy calibrations were not specified for any of the measurements, try to copy from another
2148+
// (this is unlikely to be needed, because usually the first spectrum will have energy cal, and
2149+
// the check above will fill in subsequent, but this is jic energy cal was specified for second
2150+
// one, and not first).
2151+
for( size_t i = 0; i < measurements.size(); ++i )
2152+
{
2153+
auto m = measurements[i];
2154+
assert( m );
2155+
auto cal = m->energy_calibration();
2156+
if( cal && cal->valid() )
2157+
continue;
2158+
2159+
for( size_t j = 0; j < measurements.size(); ++j )
2160+
{
2161+
auto other_cal = measurements[j]->energy_calibration();
2162+
if( (i != j) && other_cal && other_cal->valid()
2163+
&& (m->num_gamma_channels() == other_cal->num_channels()) )
2164+
{
2165+
m->set_energy_calibration( other_cal );
2166+
break;
2167+
}
2168+
}//
2169+
}//for( size_t i = 0; i < measurements.size(); ++i )
2170+
2171+
21432172
specfile->cleanup_after_load();
21442173

21452174
return specfile;

0 commit comments

Comments
 (0)