slac-lcls / smalldata_tools

code to facilitate production of LCLS small data files and the analysis thereof
12 stars 11 forks source link

ENH: recording damage stats for FEE spectrometer #179

Closed fredericpoitevin closed 11 months ago

fredericpoitevin commented 11 months ago

It'd be useful to plot when the FEE spectrometer has damaged events.

Aaron Brewster monitors it using this script, maybe we could adapt it into smalldata_tools?

import psana
from matplotlib import pyplot as plt
import numpy as np
import sys

runs = [int(r) for r in sys.argv[1:]]

good = 0
bad = 0
events = []

for r in runs:
  ds = psana.DataSource('exp=mfxl1013621:run=%d:idx'%r)
  d = psana.Detector('FEE-SPEC0')
  pr = list(ds.runs())[0]
  times = pr.times()
  data = None
  total = 0
  #for i in range(500):
  for i in range(len(times)):
    e = pr.event(times[i])
    f = d.get(e)
    if f:
      print(r, i)
      good += 1
      events.append(1)
    else:
      print(r, i, 'no fee')
      bad += 1
      events.append(0)
      continue
    if data is None:
      data = f.hproj().astype(float)
    else:
      data += f.hproj().astype(float)
    total += 1
  print(total)
  data /= total
  #data = data[:-2]
  print(good, bad, good+bad)
  plt.plot(range(len(data)), data, '-')
plt.legend(["%d"%r for r in runs])
plt.title("FEE spec for L10136 runs")
plt.xlabel("Pixels")
plt.ylabel("Mean counts")

plt.figure()
plt.plot(range(len(events)), events, '-')
plt.title("FEE presence over time")
plt.xlabel("Event number")
plt.ylabel("FEE present (1 yes, 0 no")
plt.show()

When run, this prints:

10 0 no fee
10 1 no fee
10 2 no fee
10 3 no fee
...
10 63
10 64
10 65
10 66
10 67
10 68

and then plots image image

fredericpoitevin commented 11 months ago

@gadorlhiac just pointed out to me that we already had it:

import h5py
f = h5py.File('/sdf/data/lcls/ds/mfx/mfxl1013621/hdf5/smalldata/mfxl1013621_Run0010.h5')
fee = f['damage/FEE_SPEC0'][()]
image
fredericpoitevin commented 11 months ago

Feature request: have it plot automatically in the Summary tab

fredericpoitevin commented 11 months ago

Thank you Gabriel!!!

image