Page History
This script lives in in /reg/g/psdm/tutorials/examplePythonexamplePython3/cfd.py and demonstrates how to run a constant-fraction-discriminator algorithm on a waveform (similar to a peak-finder for area-detectors).
Code Block |
---|
from psana import *
from pypsalg import find_edges
ds = DataSource('exp=amotut13:run=206')
det = Detector('AmoETOF.0:Acqiris.0')
import matplotlib.pyplot as plt
for nevent,evt in enumerate(ds.events()):
waveforms,times = det.raw(evt)
# find edges for channel 0
# parameters: baseline, threshold, fraction, deadtime, leading_edges
edges = find_edges(waveforms[0],0.0,-0.05,1.0,5.0,True)
# pairs of (amplitude,sampleNumber)
print(edges)
break |
Sven Augustin suggested this code to get actual times instead of sample numbers for the edges:
Code Block |
---|
import pypsalg def CFD(x, y, baseline=0.0, threshold=0.1, fraction=1.0, deadtime=5.0, leading_edges=True): if x is None or y is None: breakreturn None edges = pypsalg.find_edges(y, baseline, threshold, fraction, deadtime, leading_edges) if not edges.size: return None amplitudes, sample_numbers = edges.T # test whether the last element was found to be a peak, if so ignore it if sample_numbers[-1] >= len(y) - 1: amplitudes = amplitudes[:-1] sample_numbers = sample_numbers[:-1] # separate integer index and linearly interpolated fraction in between indices = sample_numbers.astype(int) linterp = sample_numbers % 1 # get x step size for each index and calculate interpolated x axis steps = x[1:][indices] - x[:-1][indices] times = x[indices] + steps * linterp return times, amplitudes |
Overview
Content Tools