@@ -2134,12 +2134,41 @@ std::shared_ptr<SpecFile> to_spec_file( const std::vector<UrlSpectrum> &spec_inf
2134
2134
}
2135
2135
}// for( auto &meas : measurements )
2136
2136
}// 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
2138
2142
2139
2143
measurements.push_back ( m );
2140
2144
specfile->add_measurement ( m, false );
2141
2145
}// for( const UrlSpectrum &spec : spec_infos )
2142
2146
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
+
2143
2172
specfile->cleanup_after_load ();
2144
2173
2145
2174
return specfile;
0 commit comments