f_calib.close()

# get DAQ quantities (only scalars)
df, filenames = ut.analysis.get_data_daq(fname, daq_labels, sacla_converter, t0=0, selection=sel)

# get laser on/off tags
is_laser_on_tags = df[df.is_laser == 1].index.tolist()
is_laser_off_tags = df[df.is_laser == 0].index.tolist()

# get spectra from Von Hamos, using laser on / off tags
#roi = [[0, 1024], [325, 335]]  # X, Y
ap = ImagesProcessor(facility="SACLA")
ap.add_analysis('get_projection', args={"axis": 1})
ap.add_analysis('get_mean_std')
ap.set_dataset('/run_%s/detector_2d_1' % run)
ap.add_preprocess("set_thr", args={"thr_low": 65})

# get the total spectra
results_on = ap.analyze_images(fname, tags=is_laser_on_tags)
spectrum_on = results_on["get_projection"]["spectra"].sum(axis=0)
results_off = ap.analyze_images(fname, tags=is_laser_off_tags)
spectrum_off = results_off["get_projection"]["spectra"].sum(axis=0)

spectrum_off = spectrum_off / spectrum_off.sum()
spectrum_on = spectrum_on / spectrum_on.sum()

# this is the average image from the Von Hamos
sum_image_on = results_on["get_mean_std"]["images_mean"]

# Plot!
plt.subplot(1, 2, 1)