@@ -254,6 +254,52 @@ def test_fit(tmp_path):
254254 for tof_id , v in correct .items ():
255255 assert np .allclose (cal_read .model_params [tof_id ], v , rtol = 1e-2 , atol = 1e-2 )
256256
257+ def test_detect_roi_and_fit_single_channel (mock_sqs_etof_calibration_run , tmp_path , mock_etof_mono_energies , mock_etof_calibration_constants ):
258+ # use mock data
259+ pulse_timing = 'SQS_RR_UTC/TSYS/TIMESERVER'
260+ monochromator_energy = 'SA3_XTD10_MONO/MDL/PHOTON_ENERGY'
261+ digitizer = 'SQS_DIGITIZER_UTC4/ADC/1:network'
262+ digitizer_control = 'SQS_DIGITIZER_UTC4/ADC/1'
263+ pulse_energy = 'SQS_DIAG1_XGMD/XGM/DOOCS'
264+ mock_sqs_etof_calibration_run = mock_sqs_etof_calibration_run .select ([pulse_timing ,
265+ digitizer , digitizer_control ,
266+ pulse_energy , f"{ pulse_energy } :output" ,
267+ monochromator_energy ], require_all = True ).select_trains (np .s_ [10 :])
268+ channel_name = "1_A"
269+ tof_ids = [0 ]
270+ tof_channel = {}
271+ tof_channel [0 ] = AdqRawChannel (mock_sqs_etof_calibration_run ,
272+ channel_name ,
273+ digitizer = digitizer ,
274+ first_pulse_offset = 1000 )
275+ scan = Scan (mock_sqs_etof_calibration_run [monochromator_energy , "actualEnergy" ], resolution = 2 )
276+ energy_axis = np .linspace (965 , 1070 , 160 )
277+ xgm = XGM (mock_sqs_etof_calibration_run , pulse_energy )
278+ cal = CookieboxCalibration (
279+ auger_start_roi = None ,
280+ start_roi = None ,
281+ stop_roi = None ,
282+ )
283+ cal .setup (run = mock_sqs_etof_calibration_run , energy_axis = energy_axis , tof_settings = tof_channel ,
284+ xgm = xgm ,
285+ scan = scan )
286+ correct_energies = np .unique (mock_etof_mono_energies )
287+ correct_constants = np .array (mock_etof_calibration_constants )
288+ for tof_id in tof_ids :
289+ assert np .allclose (cal .tof_fit_result [tof_id ].energy , correct_energies , rtol = 1e-2 , atol = 1e-2 )
290+
291+ energy = correct_energies
292+
293+ # get calibration curve
294+ c , e0 , t0 = cal .model_params [tof_id ]
295+ ts = t0 + np .sqrt (c / (energy - e0 ))
296+
297+ c_true , e0_true , t0_true = correct_constants
298+ ts_true = t0_true + np .sqrt (c_true / (energy - e0_true ))
299+
300+ # check how well it matches
301+ assert np .allclose (ts , ts_true , rtol = 1e-2 , atol = 1e-2 )
302+
257303def test_avg_and_fit_single_channel (mock_sqs_etof_calibration_run , tmp_path , mock_etof_mono_energies , mock_etof_calibration_constants ):
258304 # use mock data
259305 pulse_timing = 'SQS_RR_UTC/TSYS/TIMESERVER'
0 commit comments