IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
plot_pile_up.py
1"""
2Fluorescence decay pile-up
3==========================
4In single photon counting at high count rates subseqentially emitted
5photons cannot be detected. This effect is called pile up, as it changes
6the the shape of fluorescence decay curves. This examples illustrates
7how pile-up changes the shape of fluorescence decays.
8"""
9import pylab as plt
10import numpy as np
11import sys
12try:
13 import scipy.stats
14except ImportError:
15 print("To run this example, please first install the 'scipy'")
16 print("Python module.")
17 sys.exit(0)
18import IMP.bff
19
20n_channels = 128
21irf_position, irf_width = 1.0, 0.2
22time_axis = np.linspace(0, 10, n_channels)
23dt = time_axis[1] - time_axis[0]
24
25irf = scipy.stats.norm.pdf(time_axis, loc=irf_position, scale=irf_width)
26lifetime_spectrum = np.array([100., 4])
27data = np.zeros_like(irf)
28stop = len(irf)
29start = 0
30
31IMP.bff.decay_fconv(fit=data, irf=irf, x=lifetime_spectrum, start=start, stop=stop, dt=dt)
32
33
34# %%
35# The number the model is scaled to a number of photons typically recorded in a eTCSPC
36# experiment. In an eTCSPC experiment usually 1e6 - 20e6 photons are recorded.
37#
38# The pile up depends on the instrument dead time, the repetition rate used to excite
39# the sample and the total number of registered photons. Here, to highlight the effect
40# of pile up an unrealistic combination of the measurement time and the number of photons
41# is used. In modern counting electronics the dead time is often around 100 nano
42# seconds.
43#
44# In this example there is no data. Thus, the model without pile up is used as
45# "data". In a real experiment use the experimental histogram in the data argument.
46
47period = 8.0
48pile_up_parameter = {
49 'repetition_rate': 1./period * 1000., # Repetition rate is in MHz
50 'instrument_dead_time': 120., # Instrument dead time nano seconds
51 'measurement_time': 0.001, # Measurement time in seconds
52 'pile_up_model': "coates"
53}
54
55data_with_pileup = np.copy(data)
57 model=data_with_pileup,
58 data=data,
59 **pile_up_parameter
60)
61
62fig = plt.figure()
63ax = fig.add_subplot(1, 1, 1)
64ax.semilogy(data_with_pileup, label='with pileup')
65ax.semilogy(data, label='no pileup')
66ax.set_ylim(10, 100)
67ax.legend()
68
Bayesian Fluorescence Framework.
void decay_fconv(double *fit, double *x, double *lamp, int numexp, int start, int stop, double dt=0.05)
Convolve lifetime spectrum with instrument response (fast convolution, low repetition rate).
void decay_add_pile_up_to_model(double *model, int n_model, double *data, int n_data, double repetition_rate, double instrument_dead_time, double measurement_time, std::string pile_up_model="coates", int start=0, int stop=-1)
Add a pile-up distortion to the model function.