{'fraction_non_alphanumeric': 0.03788290737719775, 'fraction_numerical': 0.014822870722816345, 'mean_word_length': 4.593556381660471, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Optimal pulse processing, pile-up decomposition and applications of silicon drift detectors at LCLS

Silicon drift detectors (SDDs) revolutionized spectroscopy in fields as diverse as geology and dentistry. For a subset of experiments at ultra-fast, x-ray free-electron lasers (FELs), SDDs can make substantial contributions. Often the unknown spectrum is interesting, carrying science data, or the background measurement is useful to identify unexpected signals. Many measurements involve only several discrete photon energies known a priori, allowing single event decomposition of pile-up and spectroscopic photon counting. We designed a pulse function and demonstrated that the signal amplitude and rise time are obtained for each pulse by fitting, thus removing the need for pulse shaping. By avoiding pulse shaping, rise times of tens of nanoseconds resulted in reduced pulse pile-up and allowed decomposition of remaining pulse pile-up at photon separation times down to hundreds of nanoseconds while yielding time-of-arrival information with precision of 10 nanoseconds. Waveform fitting yields simultaneously high energy resolution and high counting rates (2 orders of magnitude higher than current digital pulse processors). We showed that pile-up spectrum fitting is relatively simple and preferable to pile-up spectrum deconvolution. We developed a photon pile-up statistical model for constant intensity sources, extended it to variable intensity sources (typical for FELs) and used it to fit a complex pile-up spectrum. We subsequently developed a Bayesian pile-up decomposition method that allows decomposing pile-up of single events with up to 6 photons from 6 monochromatic lines with 99% accuracy. The usefulness of SDDs will continue into the x-ray FEL era of science. Their successors, the ePixS hybrid pixel detectors, already offer hundreds of pixels, each with similar performance to an SDD, in a compact, robust and affordable package

Abstract-Silicon drift detectors (SDDs) revolutionized spectroscopy in fields as diverse as geology and dentistry. For a subset of experiments at ultra-fast, x-ray free-electron lasers (FELs), SDDs can make substantial contributions. Often the unknown spectrum is interesting, carrying science data, or the background measurement is useful to identify unexpected signals. Many measurements involve only several discrete photon energies known a priori, allowing single event decomposition of pile-up and spectroscopic photon counting. We designed a pulse function and demonstrated that the signal amplitude (i.e., proportional to the detected energy and obtained from fitting with the pulse function), rise time, and pulse height are interrelated and at short peaking times the pulse height and pulse area are not optimal estimators for detected energy; instead, the signal amplitude and rise time are obtained for each pulse by fitting, thus removing the need for pulse shaping. By avoiding pulse shaping, rise times of tens of nanoseconds resulted in reduced pulse pile-up and allowed decomposition of remaining pulse pile-up at photon separation times down to hundreds of nanoseconds while yielding time-of-arrival information with precision of 10 nanoseconds. Waveform fitting yields simultaneously high energy resolution and high counting rates (2 orders of magnitude higher than current digital pulse processors). At pulsed sources or high photon rates, photon pile-up still occurs. We showed that pileup spectrum fitting is relatively simple and preferable to pile-up spectrum deconvolution. We developed a photon pile-up statistical model for constant intensity sources, extended it to variable intensity sources (typical for FELs) and used it to fit a complex pile-up spectrum. We subsequently developed a Bayesian pile-up decomposition method that allows decomposing pile-up of single events with up to 6 photons from 6 monochromatic lines with 99% accuracy. The usefulness of SDDs will continue into the xray FEL era of science. Their successors, the ePixS hybrid pixel detectors, already offer hundreds of pixels, each with similar performance to an SDD, in a compact, robust and affordable package.

A. Silicon Drift Detectors at Free-Electron Laser Sources
Silicon drift detectors (SDDs) [1] are a well-established technology that has revolutionized spectroscopy in fields as diverse as geology and dentistry. At a first glance it would seem that detectors with such a slow response would not be suitable for the new ultra-fast x-ray free-electron lasers (FEL) coming online [2]. However, FELs require a range of detectors with different specifications to cover the applications space [3], [4], [5]. For a subset of experiments at FELs, SDDs can make substantial contributions [6], [7].
Free-electron laser (FEL) pulses are typically very short (in the order of tens of femtoseconds). LCLS typically produces pulses at a rate of 120 Hz. While each FEL pulse can contain 10 12 to 10 13 x-ray photons, the experiment design (e.g., optics, sample, detector position, filters, collimators) can reduce the number of detected photons to several per pulse.
Photon pile-up with usual sources (e.g., x-ray tubes, scanning electron microscopes) typically occurs at different time intervals, resulting in changes of the waveform shape. However, at FEL sources, the signal from photons detected in a small detector area (e.g., through a small collimator aperture onto an SDD) arrive at nearly the same time. This results in a waveform with the same shape as when detecting individual photons, and a pulse height corresponding to their aggregated energy.
While photons detected at different radii in an SDD arrive at nearly the same time, different radii result in different drift times and consequently, in changes in the waveform shape.
Many measurements involve only several distinct photon energies known a priori, significantly simplifying photon pileup analysis. Often the unknown spectrum is interesting, carrying science data, or the background measurement is useful to identify unexpected signals.
We investigate the performance of silicon drift detectors at x-ray FELs. In particular we study the ability to decompose the pile-up spectrum that results from various combinations of a few wavelengths and the possibility of separately recording photons that are absorbed at different radii (thus having varying drift times).

B. Pulse Processing
The typical approach to pulse processing in detection with a wide range of detectors (scintillation, gas, high purity germanium, SDD, transition edge) is to preamplify the detector arXiv:1706.01211v2 [physics.ins-det] 19 Mar 2019 signal, perform pulse shaping, and collect histograms of the resulting pulse peak heights [8].
When individual waveforms are (partially) overlapping, pulse pile-up occurs, modifying pulse height and resulting in spectrum distortion [9]. This can be classified in two broad classes: (1) long term, "tail" pile-up, resulting in resolution degradation (further called "pulse pile-up"); and (2) coincidences (overlapping in the peaking part), resulting mainly in sum distortion, further called "photon pile-up".
Both pile-up mechanisms occur with increasing probability for larger pulse shaping and decay times. Short peaking times result in a noise increase (e.g., for SDDs, increasing hyperbolically with decreasing peaking times [10]).
To mitigate this problem, often pulse processors have a slow channel for energy resolution and a fast channel for time resolution and pile-up rejection [11]. Signals arriving within short time intervals will not be separated by the pile-up rejection; instead, they result in photon pile-up. Considerable effort has been invested on mathematical descriptions of spectrum distortion in the presence of pile-up and pile-up rejection (e.g., [9], [12]) and spectrum correction (e.g., [13], [14]).
Current commercial pulse processors typically perform pulse shaping with digital filters in the frequency domain [15], reducing costs and improving stability compared to analog pulse shaping, while taking advantage of current fieldprogrammable gate arrays (FPGAs).
As an alternative to pulse shaping of scintillator signals, [16] predicted dispensing with analog processing and using fast ADC conversion followed by software waveform fitting.
By eliminating pulse shaping, the rise time can be much shorter, significantly reducing pile-up. Pile-up pulses can be fitted in real time with a fixed, expected pulse shape [17]; pulse shape variation results in significant residuals and rejection [17]. This approach yields energy and time-of-arrival of individual photons in multi-pulse pile-up while enabling higher rates of detection (e.g., ≈ 190 kc s −1 with 10 % rejection) [17].
For SDDs, different drift times result in different amounts of diffusion, and consequently, different rise times. In the absence of pulse shaping, these differences in rise times are significant. We show that the signal amplitude (i.e., proportional to the detected energy and obtained from fitting with the pulse function), rise time and pulse height are interrelated; variation in rise times of individual pulses must be taken into account in a function fit for optimal energy resolution in the absence of pulse shaping. With this approach, pulse rejection is not necessary, and we achieve a pulse separation of ≈ 730 ns (corresponding to ≈ 1.4 Mc s −1 ).
Computing power, memory, storage and data transfer rates continue to improve, making it likely that pulse processing will continue to transition towards full software processing (taking advantage of increasing computation resources and fulfilling the promise of largely avoiding pulse pile-up).

C. Pile-up Reduction
We define "one photon peaks" as the peaks in the energy histogram (spectrum) corresponding to detection of single photons, "two photon peaks" as peaks corresponding to the  aggregated energy resulting from detection of the pile-up of two photons (with the same energy or not), etc. We also define the "average photon rate" λ as the number of photons in all events divided by the number of events, and will often refer to it as "photon rate". As a consequence of the Poissonian counting statistic, the one photon peak area is a non-injective, nonlinear, peakshaped function of the corresponding average photon rate. For low rates, the peak area can be used to approximate the photon rate directly. At higher photon rates, the dependency becomes nonlinear, and beyond a certain point (average rate λ = 1 photon/event) decreases. Measuring higher average photon rates accurately benefits from using the pile-up peaks instead of deconvolving them.
We present here an accurate model for photon pile-up of discrete spectra with increasing complexity, from monochromatic through bicolor to general and use it for fitting a discrete spectrum, effectively deconvolving it. We further expand the model to include variable intensity sources with a gamma distribution, typical for, e.g., FEL sources.
Other approaches to single event Bayesian decomposition of photon pile-up use complex iterative Markov chain Monte Carlo [18] or χ 2 fitting [19]. Both are optimized for x-ray astronomy, expecting limited pile-up, complex spectra, and iteratively analyzing each event, updating the spectrum, and repeating until convergence. They are highly complex and relatively slow.
Using the photon pile-up model we developed a Bayesian pile-up decomposition method which yields the individual photon energies for each photon pile-up event and evaluate its accuracy to 99% for a spectrum with photon pile-up of up to 6 photons from 6 monochromatic lines.

A. Experimental Set-up
The experiments were performed at the Linac Coherent Light Source (LCLS) at SLAC National Accelerator Laboratory. Two LCLS instruments were used, X-ray Pump-Probe (XPP) [20] and Coherent X-ray Imaging (CXI) [21]. Fig. 1 shows a schematic diagram of the CXI experimental chamber, with a Fe target and an SDD detector.
We projected FEL beam pulses of ≈ 9 keV photons on an Fe target (at FELs, the photon energy and beam intensity are somewhat variable from pulse to pulse), resulting in a detected signal composed of scattered 9 keV radiation together with Fe fluorescence (Fe Kα at 6.40 keV and Fe Kβ at 7.06 keV).
We used a standard Amptek XR-100SDD detector with a resolution of 125 eV full width at half maximum (FWHM) at 5.9 keV, an active area of 25 mm 2 and thickness of 500 µm.
To observe and characterize the differences between the central and peripheral areas of the SDD, we mounted in front of the SDD a collimator with two cylindrical apertures (0.5 mm diameter), placed over the SDD such that one aperture was aligned with the center of the SDD and the other was at a 2.5 mm radius towards the periphery of the SDD. We will subsequently refer them as the "central" and "peripheral" apertures.
Using collimators to convert standard SDDs to position sensitive detectors comes at the cost of reduced fill factor in our experiment, with each each aperture passing about 0.8 % of the detector area. However, a large number of photons was present and the reduced fill factor was not an issue. In practice, apertures can be useful to limit the number of photons reaching the detector.

B. Waveform Acquisition and Processing
The SDD preamplifier output was connected to the Amptek PX5 pulse processor, with the SDD current amplified and high-pass filtered in the PX5 preamplifier and prefilter blocks, respectively; for details and conceptual diagram see [22]. The analog prefilter output of the pulse processor was routed to the PX5 AUX1 analog port.
The PX5 pulse processor does not provide the analog prefilter output signal directly; instead, this signal is digitized by the PX5 ADC at 80 MHz, subsequently synthesized by the PX5 DAC at 10 MHz, and then routed to the PX5 AUX1 analog output; see details and conceptual diagram in [22]. In Appendix A we describe the method used for recovery of ADC input waveforms from the raw measured waveforms.
The analog signal waveforms were then acquired by an Acquiris high-speed digitizer, with 8192 samples at 100 MHz for each FEL pulse and triggered pulse by pulse by the low jitter LCLS trigger signal. We will use the term "events" to refer to individual acquisitions from single FEL pulses. Each event resulted in one single waveform. We acquired 354 304 events and corresponding waveforms at 120 events per second.

C. Pulse Function
The pulse height analysis can be optimally performed in the frequency domain [15]. Here we chose to perform the analysis in the time domain, allowing accurate reconstruction of timing, clipping and pile-up of pulses.
An individual pulse has a shape characterized by a relatively rapid increase near the arrival time t 0 and a relatively slow Step Example of pulse function f (x) (solid black line, Eq. 2) obtained by multiplying a gradual step function (dotted red line) with an exponential decay (dashed red line); for reference, a commonly used function with exponential peaking f * (t) is shown with a thin blue line. exponential decay towards zero afterwards. An often used pulse function is: which assumes that the peaking occurs as an exponential decay towards 1 with peaking time τ p (corresponding to the peaking time of pulse shaping) multiplied by an exponential decay with decay time τ d (corresponding to the time constant of the prefilter high-pass filter). The typical pulse function f * (t) is illustrated in Fig. 2 by the thin blue line (usually the peaking time is chosen to be much longer than rise times, in the order of microseconds instead of tens of nanoseconds, leading to a much slower pulse onset). After high-pass filtering in the analog prefilter, and in the absence of pulse shaping, peaking is fast, with a slower onset and ending resulting from charge diffusion. We can parametrize this behavior by using a smooth step function with time constant τ s (corresponding to the SDD and preamplifier rise time): with the step factor, decay factor and their product (i.e., pulse function f (t)) indicated in Fig. 2 by the dotted red line, dashed red line and thick black line, respectively.

D. Pulse Function Characteristics
We compare the characteristics of the typical pulse function f * (t) and the modified pulse function f (t), relating their characteristics to the detected signal. Eq. 1 and 2 are translation invariant; in this subsection we conveniently choose a time origin t 0 = 0 to simplify the analysis of the pulse function.

1) Pulse Height:
We can obtain the relation between pulse height max f (t) and signal amplitude A by finding t 1 where the first derivative of the pulse function f (t) is zero: and substituting Eq. 3 into Eq. 1, 2: 2) Pulse Area: The pulse area can be calculated: where csc is the cosecant function.

3) Discussion:
In subsection III-B we show that the step time (or rise time) τ s changes with location (central or peripheral), thus changing the ratios between fitting parameter A, pulse height, and pulse area. However, using function f (t) for pulse processing allows recovering the position, time and pulse pile-up for each event, without pulse shaping.
For {τ s , τ p } τ d , the equations above are simplified to: thus for long peaking and decay times, the signal amplitude, pulse height and pulse area show a similar behavior.

E. Two Pulse Pile-up Decomposition
In this experiment we use a single channel SDD, which provides a single waveform for each event; at FELs, photons arrive to the detector plane nearly at the same time. Due to the two apertures and differences in drift time between the central and peripheral areas, the waveforms contain two partially overlapping pulses with amplitudes proportional to the energy of photons detected through each aperture.
To account for the nonzero baseline, clipping of larger signals (V > 0.3 V), and the superposition of two pulses with two different amplitudes and arrival times, we extend Eq. 2 to: where the c and p superscripts denote parameters specific for the central and the peripheral aperture, respectively. Each individual waveform was then fitted (least squares) with the function in Eq. 7, where the signals induced by photons entering through the central and peripheral apertures have amplitudes A c and A p , arrival times t c 0 and t p 0 , with 'decay' and 'step' times denoted by τ d , τ c s and τ p s , offset y 0 and maximum (clipping) digitized voltages y max . Signal amplitudes for either aperture are collected in histograms. Fig. 3 shows an example of waveform (red dots) and corresponding least squares fit (black line), with 3 photons entering through the central aperture and 1 photon entering through the peripheral aperture.

F. Photon Pile-up Statistics at Constant Beam Intensity
For a single, monochromatic line i with average detection rate λ i , the probability of a pile-up event with j photons in one acquisition is given by the Poisson distribution: where j is an exponent (unlike elsewhere in this paper, where superscript j is typically an index). 1) Peak area and detection rate: The relationship between 1 photon peak area (i.e., detection probability P 0 i ) and average detection rate λ i for 1 photon peaks is: For low rates, lim λi→0 λ i e −λi = λ i , resulting in the usual approximation: However, for relatively high rates in the presence of pile-up, the full form must be used. Solving Eq. 9 for λ i we obtain two solutions: where W 0 (x) and W −1 (x) are the principal and −1 solutions provided by the Lambert-W functions.
Eq. 11 reflects the fact that a 1-photon peak area corresponds to two different average detection rates λ i on either side of λ i = 1 photon/event, thus it is a degenerate measure of photon rate. For low rates (λ i < 1 photon/event), the 1 photon peak area can be used; however, for high rates, the pile-up peaks must be considered.

G. Photon Pile-up Statistics with FEL Beams
The self-amplified spontaneous emission process at FELs results in significant pulse-to-pulse intensity variation, often described by a gamma probability distribution function [23]: where Γ is the gamma function, with average rate λ = αβ Γ and shape parameter α. For simplicity we replace β Γ with λ/α. The gamma distribution of FEL pulse intensities results in a "stretching" of the Poisson distribution corresponding to the average FEL intensity. The stretching effect resulting from the variability of the FEL beam intensity can be calculated as a weighted average of the Poisson distributions corresponding to different FEL pulse intensities, weighted by their probability: (integrated with [24]). Note that Eq. 13 is a generalized form of the Poisson distribution in Eq. 8, which can be recovered in the limit lim α→∞ Γ P j i = P j i . In this paper we used Eq. 13 where applicable; Eq. 8 is provided for reference and should be used for data measured with sources of constant intensity.
1) Peak area and detection rate: The relationship between 1 photon peak area (i.e., detection probability P 0 i ) and detection rate λ i for one photon peaks results by setting j = 1 in Eq. 13: which can be solved numerically for λ i . As in Eq. 11, Eq. 14 yields two solutions on either side of λ i = 1 photon/event (on average), thus the photon pile-up peaks must be considered for evaluating λ i .
H. Peak Shape 1) Peak width dependency on energy: At energy E, the noise r.m.s. is given by the electronic noise σ 0 and an energy dependent noise component (including, i.e., Fano noise) √ σ 1 E, added quadratically: Using this simplified form allows fitting peak shapes with only two global fitting parameters, σ 0 and σ 1 , resulting in increased fitting stability.
2) Normal distribution: We used a normal distribution function for modeling peak shapes of single peaks i (corresponding to the monochromatic lines at energies E i ): 3) Version 1 generalized normal distribution: In practice we observe that the peaks display "heavy tails"; we expect this to be specific to this experiment, see subsection IV-B2 for details. To model heavy tails, we use a version 1 generalized normal distribution: where β is the shape parameter (e.g., a parameter β = 2 reverts this function to the normal distribution). 4) General peak shape: Combining the two distributions above we obtain the peak function: where η is the fraction of photons in heavy tails.

I. Photon Pile-up Spectra
In this subsection we deduce increasingly complex pileup spectra: (1) one photon peak spectrum, (2) pile-up of monochromatic line, (3) pile-up of two lines (useful in, e.g., pump-probe experiments), to (4) pile-up of multiple lines.
Note that for all calculated spectra we use probability density functions (PDFs). To obtain histograms from PDFs we multiply the PDF value at each histogram bin position with the number of events N and the histogram bin size.
1) One photon spectrum (i.e., no pile-up): The 1 photon fitting function is the sum of the peaks of L discrete lines and zero peak (E 0 = 0): which is subsequently used to fit (least squares) the areas A i of the N peaks and the background b j .
2) Pile-up of a single line (i.e., monochromatic beam): The general form for peaks corresponding to j photons from line i is: The total number of photons detected from line i can be obtained by summation over Eq. 16 with a resulting spectrum: where N is the number of pulses.
3) Pile-up of two lines: The photon pile-up of two lines {i 1 , i 2 } can be obtained similarly: The resulting 0 to M photon spectrum is: Eq. 23 contains M +2 2 terms corresponding to the binomial expansion coefficient: 4) Pile-up of multiple lines: The photon pile-up of L lines The resulting 0 to M photon spectrum is: Eq. 26 contains L+M L terms; the algorithm complexity is O(n!), increasing rapidly for large numbers of lines L and photons M .

J. Pile-up Spectrum Fitting and Decomposition
Eq. 26 accurately describes the photon pile-up of multiple lines and could be used for χ 2 fitting of entire spectra. In spectrum fitting we added a third degree polynomial background to the theoretical spectrum: The number of counts per histogram bin has a Poisson distribution with an expected error r.m.s. of √ y; we add 1 to account for bins with zero counts, obtaining for each histogram bin an expected error y err ≈ 1 + √ y (adimensional). This error estimate is used for weighting individual bins in spectrum fitting.
The variance of the resulting fitting parameters is the principal diagonal of the covariance matrix [25]; its square root yields the r.m.s. error of the fitting parameter.
Eq. 26 allows obtaining the average photon rates λ i directly, eliminating the need for pile-up deconvolution; the number of photons from each line i is N λ i , where N is the number of events observed.

K. Bayesian Decomposition of Single Event Photon Pile-up
The probability that a particular energy E belongs to each of the L+M 1) Maximum likelihood estimation of photon pile-up decomposition: For each detected energy E, we construct a 924 element column vector P(E), with each of the 924 rows containing the probability that energy E belongs to the 924 corresponding pile-up peaks, calculated from individual terms in Eq. 26.
The P(E) row with the maximum value indicates the most likely pile-up peak (i.e., maximum likelihood estimator for the pile-up peak).
2) Error in estimating pile-up peaks: The estimated error of peak assignment is and the total error is the weighted average of the energy dependent Err(E) with the probability density function of the energy S(E): This yields the error rate of pile-up peak identification.
3) Error in estimating number of photons: For estimating the error rate of photon identification, we simulate 10 6 events, with numbers of photons sampled randomly from their respective distributions. For each simulated event we simulate an energy response by sampling one value from the corresponding distribution Eq. 16, and then recontructing the individual photon energies as above. We generate a 6 × 6 confusion matrix C, with rows representing simulated photons and columns representing assigned photons after single event pile-up reconstruction.
The error rate of single event Bayesian decomposition of photon pile-up can be calculated from the ratio between the sum of the diagonal and the sum of all cells in confusion matrix C: 4) Discussion: While the error rates of the Bayesian, maximum likelihood decomposition depend strongly on the spectrum characteristics, the method presented here can be applied to estimate deomposition errors in any other spectrum.

III. PULSE PROCESSING RESULTS
Time results from fitting Eq. 7 are summarized in Fig. 4 with (a) histograms of arrival times (central and peripheral), (b) decay characteristic time (common) and (c) step characteristic times (central and peripheral).

A. Pulse Arrival Times and Interaction Radii
Arrival time results are shown in Fig. 4 (a); the pulse arrival times for the central aperture (black line, t 0 = 34.842 ± 0.012 µs) and peripheral (red line, t p = 35.574 ± 0.037 µs) are clearly separated.
As the photons reach the SDD surface nearly at the same time, the difference of 732 ns in pulse arrival times is due to the charge drift time between the SDD periphery and center [26]. The arrival time jitter (12 ns r.m.s. in the center and 37 ns r.m.s. in the periphery) is significantly lower than the difference of arrival times, allowing precise pulse by pulse measurement of arrival times (and corresponding interaction radii), effectively turning the SDD into a position sensitive detector with tens of independent position channels and in-creasing resolution towards the center.

B. Decay and Step Characteristic Times
The decay time shown in Fig. 4 (b), τ d = 3.269 ± 0.035µs, corresponds to the nominal 3.2 µs time constant of the highpass filter of the analog prefilter [22], and has a relatively small variation (σ/mean ≈ 1.1 %).
The step characteristic times depicted in Fig. 4 (c) are clearly different, with a faster step transition in the central compared to the peripheral area; as both signals are processed identically, the difference is due to the supplementary charge diffusion between the periphery and center.

C. Optimal Estimator for Photon Energy
Several estimators for detected photon energy can be considered: the pulse height, pulse area, and fitted signal amplitudes A (Eq. 7). In the absence of pulse shaping, step characteristic times can differ significantly (subsection III-B), resulting in different behaviors of these estimators (as described in subsection II-D).
For each event, the central and peripheral signal amplitudes A c and A p were obtained by fitting individual event waveforms with Eq. 7. The pulse height and area were estimated from the fit parameters with Eq. 4 and Eq. 5, respectively; using fit parameters and Eq. 4 to estimate pulse height significantly reduced the high frequency noise.
In Fig. 5, we show the histograms of (a) fitted signal amplitudes, (b) pulse height, and (c) pulse area, with histograms of central pulses indicated by red squares, peripheral pulses with blue dots, and their sum with the black line.
The optimal energy resolution of the SDD is achieved at the best separation of the partially overlapping peaks (Fe Kα and Fe Kβ) of the sum histogram. The extent of separation can be quantified using the valley-to-peak ratio (V/P) [27], defined as the ratio of the heights of the trough between the peaks and of the highest peak, respectively. The ratios are indicated in the figure.
The optimal estimator for photon energy in the absence of pulse shaping is the fitted signal amplitude A, with a V/P ratio of 0.024, while using the pulse area or pulse height results in higher V/P ratios (0.076 and 0.089, respectively) and decreased energy resolution and gain matching between the center and the periphery of the SDD.
In typical pulse processing, the dependence on peaking time is mitigated by increasing peaking time τ p through pulse shaping (typically with a rise time in the order of microseconds), reducing the effect of variations in τ s and preserving the energy resolution. However, pulse shaping results in slower pulse onset and consequently reduced peak separation and reduced counting rates [28]. Using function f (t) (Eq. 2) for pulse fitting allows keeping both the high energy resolution and high counting rate while eliminating the effect of variations in peaking times.

D. Virtual Multichannel Spectra from Single SDD
Signal amplitudes A c , A p resulting from fitting measurements with Eq. 7 are shown in Fig. 6 with a bi-dimensional  [27] of the sum histogram; note that with typical pulse shaping (raise times in the order of microseconds to minimize loss of energy resolution), the individual contributions of photons entering through the central and peripheral apertures can't be separated and the counting rate is limited [28]; the optimal estimator for photon energy in the absence of pulse shaping is the fitted signal amplitude A, with a V/P ratio of 0.024.
histogram of the two amplitudes (A p along the x axis, A c along the y axis, logarithmic z axis). Multiple clusters of different combinations of energies can be observed. Fig. 6 inset shows the area corresponding to 1 photon entering through each of the two apertures (in total, 2 photons). Three lines can be identified along each axis, with energies Fe Kα (6.40 keV), Fe Kβ (7.06 keV), and the nominal (9 keV) FEL line. Pile-up of 2 photons sampled from 3 lines each yields 3 2 = 9 ellipsoids. The pattern corresponding to Fig. 6 inset repeats, with increasing complexity and (for this photon rate) decreasing intensity, for higher numbers of photons along each of the axes in Fig. 6. However, the pile-up results in clearly separable ellipsoids from each combination of (1) number of photons of each individual energy entering through (2) each of the 2 apertures.
The ellipsoids are more elongated along an axis at 3π/4 (rotated counterclockwise from the x axis), meaning that the sum of the two amplitudes is typically more accurate than the individual amplitudes or their difference. This is to be expected, as the sum of the amplitudes for signals entering through both apertures can be evaluated using many more samples compared to the difference of the amplitudes (limited to the relatively small set of samples between t c 0 and t p 0 , see for example Fig. 3).

E. Gain and Offset Calibration
To calibrate the energy of the SDD signals, we fitted the positions of the peaks corresponding to 0, Fe Kα and Fe Kβ (three highest peaks) in the signal amplitude histograms, shown in Fig. 5 (a), for both the central and peripheral areas of the SDD. The resulting gain and offset values are summarized in Table I. The central gain and peripheral gains are similar, with a ratio of 0.994 ± 0.001.

IV. PHOTON PILE-UP AND DECOMPOSITION
The signal amplitudes A c , A p resulting from fitting with Eq. 7 were scaled with the corresponding gains and offsets in Table I and histogrammed to calculate the corresponding spectra.

A. Single Photon Spectrum
In Fig. 7 we show a spectrum of (mostly) single photons (up to 10 keV) entering through either aperture (red dots). The plot is shown on a square root scale to facilitate the simultaneous visualisation of both intense and weak lines. Along the 3 expected lines, there are a few other lines present.
We fitted this spectrum with a simple model of 7 independent Gaussian peaks (6 fundamental lines plus 1 zero peak) and a third degree polynomial background. This allows us to measure the positions of the peaks, their widths and their areas. Table II lists   nominal 9 keV line from the FEL beam, and labeled the peaks accordingly. We also determined the beam energy (9.06 keV).
The small peak at ≈ 8 keV does not represent a new fundamental line; it is the pile-up of the Al Kα and Fe Kα 1 photon peaks. While also Kβ peaks of Al, Ti and Cr must be present, their yield is much lower than the corresponding Kα yield; multiplied with their low Kα intensity, their contribution can be neglected. The peak areas in Table II provide a first indication of the intensities of the different peaks; however, using peak areas as a proxies for average detection rates yields accurate rate estimations only when each of the λ i rates is much smaller than 1 photon/event (subsection II-F) and ignoring the FEL distribution of beam intensities (subsection II-G). The peak width estimates have large estimated errors in the peaks with low statistics, and the reduced chi-squared statistic is relatively large (χ 2 ν = 73.4), due to the "heavy tails". This simple, typical analysis illustrates the limitations of using only 1 photon peaks. In next subsection (IV-B) we will address these limitations with an appropriate pile-up fitting model.  Fig. 7. Red dots show, on a square root y scale, the spectrum of the photons entering through both apertures up to 10 keV; this plot reveals three more discrete energies (between 0 and Fe Kα) in addition to the three expected ones; black line depicts the least squares fit using 7 Gaussian peaks and a second degree polynomial background (dotted line); this allows us to identify the three small peaks (as Al Kα, Ti Kα, and Cr Kα), and determine the beam energy (9.06 keV); the small peak at ≈ 8 keV is not a new peak, but the pile-up of the Al Kα and Fe Kα peaks; while also Kβ peaks of Al, Ti and Cr must be present, their contribution is small and can be neglected. The black line depicts the least squares fit using a fitting model with theoretical peak positions of the 7 fundamental lines (zero peak, Al Kα, Ti Kα, Cr Kα, Fe Kα, Fe Kβ, and 9.06 keV), using Eq. 26 with the appropriate changes (substituting Eq. 14 and 18 for Eq. 8 and 16, respectively, to account for the distribution of the FEL beam intensity and the observed "heavy tails" of peaks).

B. Photon Pile-up Spectrum and Decomposition
The fit accurately reproduces most features in the data set, resulting in a small reduced chi-squared statistic χ 2 ν = 3.71 and reproducing all characteristics of the plethora of peaks. For the 3 most intense lines (Fe Kα, Fe Kβ, and 9.06 keV) we indexed the peaks with corresponding 3 digit labels. These peaks dominate the higher energy pile-up and can still be clearly separated.
1) Average photon rate: Fitting the pile-up spectrum with the pile-up model yields estimates of photon rates in individual lines (Table III). For peaks with good statistics, the relative error is small (0.23 % for Fe Kα and 0.63 % for Fe Kβ), increasing to 14 % for the peak with lowest statistics, Cr Kα.
For the entire spectrum, the most likely photon pile-up decomposition results in a number of photons N λ i from each line i, where N is the number of events. The average rate for all photons λ = λ i = 1.7746 ± 0.0046 photons/event, with a majority of Fe Kα photons (1.4322 ± 0.0041 photons/event). 2) Noise: For Mn Kα monochromatic radiation (i.e., 5.89 keV), we obtain a line width of 2.355 σ 2 0 + σ 1 · 5.89 keV = 241 eV FWHM. On average, we observe a fraction η = 9.1 % of photons in the "heavy tails", with a distribution shape parameter β = 0.798 (details in subsection II-H).
The "heavy tails" and a significant fraction of noise are most likely a consequence of severe undersampling of the analog prefilter output: the step times (or rise times) we observed in the absence of pulse shaping (τ c s = 21.0 ns and τ p s = 43.3 ns) were much shorter than the sampling period (100 ns, corresponding to 10 MHz ADC rate of the PX5, see Appendix for details). While fitting evaluates pulse height accurately despite undersampling, the optimal estimator for detected energy is signal amplitude (subsection III-C), thus imprecision in determining step times τ s results in loss of energy resolution (as described in subsection II-D by Eq. 4). We expect the energy resolution of the pulse fitting method presented here to approach the theoretical 128 eV FWHM with improved sampling (≥ 100 MHz) while maintaining the pulse separation (720 ns, similar to a counting rate of 1.4 Mc s −1 and no rejection).
Current pulse processors can be tuned to yield a high counting rate, or a high energy resolution, or a compromise between the two, by choosing an appropriate peaking time. The Amptek XR-100SDD and PX5 digital pulse processor can yield an energy resolution of 240 eV at Mn Kα with a peaking time of ≈ 0.1 µs and acquisition rate of 80 MHz [28], resulting in a maximum output count rate of ≈ 1 Mc s −1 [28] with ≈ 60 % rejection rate [28]; we demonstrated improved results with function fitting of severely undersampled waveforms.
The Amptek XR-100SDD and PX5 digital pulse processor can also yield an energy resolution of 130 eV at Mn Kα with a peaking time of 10 µs and acquisition rate of 80 MHz [28], resulting in a maximum output count rate of 20 kc s −1 [28] with ≈ 60 % rejection rate [28]. With optimal sampling (≥ 100 MHz s −1 ), we expect ≈ 2 orders of magnitude higher counting rates than current pulse processing approaches while achieving close to the theoretical limit in energy resolution.
3) FEL statistics: Using the appropriate model (Eq. 13) which takes into account the gamma distribution of FEL pulses (subsection II-G), we obtain an intensity distribution parameter α = 17.9. Note that this parameter is specific to the current experiment and depends on beam characteristics, optics, etc. For reference, a constant intensity beam has a shape α → ∞.

C. Single Event Bayesian Decomposition of Photon Pile-up
The maximum likelihood decomposition and error estimates depend strongly on the detected spectrum; in this subsection we use the spectrum characteristics obtained in previous subsection (IV-B) and detailed in Table III; we ignored in these estimates the "heavy tails" to estimate error rates that are representative for most SDD setups (including the "heavy tails" increases the error rates by a factor of 2.4).
1) Pile-up peak error: Fig. 9 shows a single event decomposition approach. Using the method described in subsec-tion II-H, we calculated the probability S(E) of each energy E, depicted in Fig. 9 (a), and with the method described in subsection II-K2 the error probability Err peak (E), shown in Fig. 9 (b). The error rate of peak identification is 1.11 %.
2) Maximum likelihood decomposition: For each energy E we estimated the maximum likelihood decomposition in numbers of photons from each line, described in subsection II-K1 and indicated in Fig. 9 (c). Note that both the maximum likelihood decomposition and error estimate depend strongly on the spectrum characteristics (summarized in Table III).
3) Photon error: To estimate the error rate in decomposition of photon pile-up, we simulated 10 6 events with characteristics described by Table III, using the method described in subsection II-K3, generating numbers of photons, calculating their pile-up, adding the appropriate noise and then using the We collected the results, for each event, in a confusion matrix, shown in Table IV; rows correspond to simulated photons, while columns correspond to the maximum likelihood decomposition. Cell (i, j) represents how many photons from line i were allocated to line j. Successfully decomposed photons are added to the diagonal. The error rate of photon allocation is 1.05 %. Assuming the same spectrum and a detector operating at the Fano limit, we obtain an error rate of photon allocation of 0.64 %. 4) Using multiple apertures: Splitting the pile-up signal in two independent signals using the apertures reduces the photon error rate by avoiding pile-up of large numbers of photons, where the density of pile-up peaks becomes higher. Using two apertures we obtained a reduction in error rate of photon allocation to 0.55 % (and 0.31 % with a detector at the Fano limit).
Splitting the pile-up signal in two also reduces the number of pile-up peaks to consider, increasing computation speed; e.g., for the spectrum discussed here, using M = 6 photons guarantees that less than 10 −4 of the events have more than M counts in one line. Splitting the pile-up signal in two results in a maximum number of photons of M = 4. With L = 6 lines, this is a reduction from 924 to 210 pile-up peaks while doubling the number of calculations, thus speeding up fitting by a factor 2.2.
V. EPIXS PIXEL DETECTORS: SDD SUCCESSORS ePixS [29], [30] is a 2D, charge integrating, hybrid pixel detector with an array of 10 × 10 500 µm × 500 µm pixels, where each pixel has a spectroscopic performance (noise σ of 8 e − or ≈ 30 eV, and measured line width of ≈ 215 eV FWHM at Mn Kα) approaching that of SDDs. The ePixS camera is built on the ePix platform [31], providing a large number of spectroscopic imaging pixels in a compact, robust and affordable camera package [32]. Fig. 10 shows an 55 Fe source spectrum (Mn Kα at 5.90 keV and Mn Kβ at 6.49 keV lines) measured with an ePixS detector (reproduced with permission from [32]). The spectrum is collected in all pixels individually and shown in a single plot here. The ePixS energy resolution is similar to the energy resolution we observed for the Amptek SDD in subsection IV-B. ePixS is a charge integrating pixel detector, providing only the total signal collected by each pixel in each FEL pulse. As a direct result, the pulse processing described in subsections II-C to II-E is not applicable to ePixS.
However, with the same area as the single channel SDD presented here (25 mm 2 ) and 100 independent pixels (i.e., position sensitive independent channels) with similar energy resolution, an ePixS detector can measure much higher photon rates with limited pile-up and similar spectroscopic performance, while being intrinsically position-sensitive.
For the remaining pile-up, fitting and decomposition described in subsections II-F to II-K are applicable, yielding similar results to those presented here for SDDs: 100 pixels

VI. CONCLUSION
In standard spectroscopy applications there is often a complex spectrum with a multitude of peaks which must be resolved and matched to specific elements.
In contrast, at x-ray FELs there are often only a few photon energies involved in an experiment, with significant photon pile-up. The discrete spectrum significantly reduces the complexity of pile-up decomposition. SDDs can bring significant contributions at FELs in (1) photon counting, (2) spectrum measurements, and (3) background measurements and set-up optimization.
We present a pulse processing method based on fitting individual, overlapping pulses with pulse functions (a combination of gradual step function and exponential decay) which allows extracting (in the time domain) precise amplitude and timing information in the presence of pulse pile-up and clipping.
We demonstrate that, in the absence of pulse shaping, the pulse height or pulse area are not optimal estimators for the detected photon energy (due to variation in peaking times). Instead, the optimal estimator is signal amplitude, obtained (together with the rise time) by fitting each pulse waveform with the pulse function. This removes the need for pulse shaping, resulting in fast pulse onset and improved pulse separation, allowing fitting of multiple pulse pile-up.
We show that partially overlapping peaks can be separated, down to differences in time-of-arrival of ≈ 700 ns (corresponding to ≈ 1.4 Mc s −1 and no rejection), while yielding pulse time-of-arrival with precision of 10 ns.
Typical pulse processing involves a compromise between counting rate (with short rise times) and energy resolution (long rise times through pulse shaping) by choosing an appropriate peaking time.
Both high energy resolution and high counting rates can be achieved by fitting the waveform in the absence of pulse shaping. We demonstrated improved results compared to current pulse processing, despite severely undersampled waveforms. With improved sampling, we expect a high energy resolution (≈ 130 keV) while achieving ≈ 2 orders of magnitude higher counting rates than current pulse processing methods.
While we demonstrate the usage of this pulse processing method with an SDD and pulsed FEL source, it can be extended to any detector with rapid response (e.g., SDD, transition edge sensors) and x-ray source (e.g., FEL, synchrotron, x-ray tube). In SDDs at pulsed sources, the timing can be used to recover the interaction radii.
At pulsed sources, or at short time intervals between two photons, photon pile-up occurs and the photon rates are not accurately described by the standard proxy, i.e., area of one photon peaks.
Instead, the photon pile-up of a discrete detected spectrum can be accurately described and fitted with the photon pileup model presented here, yielding precise estimates of the photon rates in individual lines and effectively decomposing the spectrum. We also extended the model to include the stretching of the Poissonian statistics of pile-up introduced by sources with variable intensity (e.g., FELs).
We present a Bayesian decomposition approach which allows accurate decomposition of individual photon energies in single pile-up events, and estimating its error rate in the order of 1 % (99 % accuracy) for the spectrum discussed in this paper (average rate λ = 1.78 photons/event, with pile-up of up to 6 photons from 6 monochromatic lines).
The photon pile-up and Bayesian decomposition presented here are useful not only for SDDs but for any applications of pile-up decomposition (e.g., spectroscopy with transition edge sensors [33], low-noise spectroscopic imaging with integrating pixel detectors [34]), or even usual pulse processing with pile-up rejection (two photons with small differences in timeof-arrival will not be distinguished by the pile-up rejection, resulting in pile-up).
The usefulness of silicon drift detectors will continue into the x-ray FEL era of science. Their successors, the ePixS spectroscopic, hybrid pixel detectors already offer hundreds of pixels with similar performance in a compact, robust and affordable package, particularly useful in x-ray FELs [35]. The AUX1 analog signal of PX5 does not provide the analog prefilter output signal directly [22]. Instead, it is digitized by the ADC at 80 MHz and subsequently synthesized by the DAC at 10 MHz [22]. This is clearly visible in the raw data, shown with small blue dots in Fig. 11; each DAC change results in a transient signal with an exponential decay from the current output towards the target output. The time constant of the DAC exponential low pas filter is τ = 43.5 ns in our setup.
To recover the initial signal from the transient exponential decay segments, we fitted each 100 ns (10 samples) segment of raw data between 2 DAC updates with an exponential decay: where t o is the time offset of the first sample in the current segment, y ADC the new target output. The PX5 DAC and Acquiris were not synchronized and their time offset changed in each waveform. However, the offset can be recovered from the data by using t o as a global waveform fitting parameter and minimizing χ 2 .
The resulting fit is indicated with a black line for one waveform in Fig. 11. The dashed red line and large red dots indicate the reconstructed time and amplitude of the DAC output, correcting for the system low-pass filtering. Correcting distortions introduced by the ADC, DAC and exponential lowpass filtering results in significantly improved results.
Arrival times are calculated from time t = 0 corresponding to the arrival of the trigger signal that precedes each FEL pulse, with t ≈ 35 µs determined by the experimental layout and cable lengths.