Exercise: lifetimes, decays and photon counting
Before this unit: Day 3: Bit depth and noise.
See also: Day 5: Deconvolution; Day 47: Spectral unmixing.
Goal
By the end of this exercise you should be able to:
- compute how many photons arrive after a given time, and how much of a decay wraps into the next laser period,
- estimate a lifetime by hand from the mean arrival time and from two gates, and say when each goes wrong,
- explain why lifetime, unlike intensity, does not depend on concentration, and what does change it,
- reason about pile-up and about how long a FLIM image takes,
- (math) derive the periodic decay, show that means add under convolution, and derive the two-gate formula.
Do the pen-and-paper part first, then the two demos.
Background
| Idea | What it means |
|---|---|
| Lifetime τ | mean time in the excited state; emission \propto e^{-t/\tau} |
| Fraction still to come at t | e^{-t/\tau} (37 % at τ, 5 % at 3τ) |
| Quantum yield | Q = k_r\tau: falls together with τ when a quencher is added |
| TCSPC | at most one photon timed per laser pulse; a histogram of arrival times; Poisson counts per bin |
| IRF | instrument response: the measured histogram is IRF ∗ decay + background |
| Wrap-around | fraction e^{-T/\tau} of a decay still to come when the next pulse fires (period T) |
| Pile-up | only the first photon after a pulse is timed: bright samples look too short |
| Mean arrival | \hat\tau = \langle t\rangle - \langle t\rangle_\text{IRF} (one exponential) |
| Two gates | equal width Δt: \hat\tau = \Delta t/\ln(D_1/D_2) |
By hand
B1. A decay with τ = 2 ns, 1 000 photons, no IRF and no background. (a) How many photons arrive later than 2, 4 and 6 ns after the pulse? (b) After how many nanoseconds have 99 % of the photons arrived?
B2. Two gates of 2 ns, from 0 to 2 ns and from 2 to 4 ns, hold 632 and 233 photons. (a) Estimate τ. (b) Room light adds 50 photons to each gate. What lifetime do you now estimate? And with 100 per gate? In which direction does background push the two-gate estimate?
B3. A pixel’s fluorescence photons have a mean arrival time of 3.1 ns; the IRF’s mean is 0.6 ns. (a) Estimate τ. (b) 10 % of the photons in the pixel are background, spread evenly over the 12.5 ns window. What is the measured mean arrival time now, and which lifetime would you report?
B4. Wrap-around at 80 MHz (period 12.5 ns). (a) Which fraction of a decay is still to come when the next pulse arrives, for τ = 1, 4 and 8 ns? (b) Which period would keep that fraction below 1 % for τ = 8 ns? Which repetition rate is that?
B5. Photon budget. A scanning FLIM microscope at 80 MHz detects a photon in 1 % of the pulses. (a) How long does an image of 256 × 256 pixels with 1 000 photons per pixel take? (b) Why not detect a photon in 10 % of the pulses and be ten times faster? (Of the pulses with at least one photon, 0.5 % hold two or more at a 1 % rate, 5.2 % at 10 %.)
B6. Predict. Cell A is twice as bright as a reference cell with the same lifetime of 2.5 ns. Cell B is as bright as the reference, but its lifetime is 1.5 ns. (a) Which cell points to a change in the molecules’ surroundings, and which to a change in their number? (b) Suppose the shorter lifetime in B is due to quenching. By which factor has the brightness per molecule fallen? How many more molecules must B then contain to look as bright as the reference?
B7. A dye has τ₀ = 4.0 ns and a quantum yield of 0.8. (a) Compute the radiative rate k_r and the non-radiative rate k_{nr}. (b) A quencher shortens τ to 2.0 ns. What are the new quantum yield and the quenching rate?
B1. (a) 1000\,e^{-1} = 368, 1000\,e^{-2} = 135, 1000\,e^{-3} = 50. (b) e^{-t/2} = 0.01 gives t = 2\ln 100 = 9.2 ns.
B2. (a) D_1/D_2 = 632/233 = 2.71, \tau = 2/\ln 2.71 = 2.0 ns. (These are exactly the counts of a 2 ns decay: 1000(1 - e^{-1}) = 632 and 1000(e^{-1} - e^{-2}) = 233.) (b) 2/\ln(682/283) = 2.27 ns; with 100 per gate 2/\ln(732/333) = 2.54 ns. Background adds the same number to both gates, which makes the ratio closer to 1: the decay looks flatter, the lifetime too long.
B3. (a) 3.1 - 0.6 = 2.5 ns. (b) The background’s mean is the middle of the window, 6.25 ns: 0.9 \cdot 3.1 + 0.1 \cdot 6.25 = 3.415 ns, so \hat\tau = 2.8 ns, 13 % too long.
B4. (a) e^{-12.5} = 4 \cdot 10^{-6} (nothing), e^{-3.125} = 4.4\,\%, e^{-1.5625} = 21\,\%. (b) e^{-T/8} < 0.01 needs T > 8\ln 100 = 36.8 ns, a repetition rate below 27 MHz.
B5. (a) 0.01 \times 80 \cdot 10^6 = 8 \cdot 10^5 photons per second; 256^2 \times 1000 = 6.6 \cdot 10^7 photons: 82 s. (b) At 10 % the image takes 8 s, but 5.2 % of the timed pulses had a second photon that was lost. The lost photons are the late ones, so the histogram is distorted towards early times and the lifetime comes out too short (pile-up), and differently so in bright and dim pixels.
B6. (a) B: a different lifetime means the excited molecules have a new way to lose their energy. A is most simply twice as many molecules (or brighter illumination). (b) Brightness per molecule is proportional to the quantum yield k_r\tau, so it falls by 1.5/2.5 = 0.6; B must hold 1/0.6 = 1.67 times as many molecules. Intensity alone would have said “same amount”.
B7. (a) k_r = Q/\tau = 0.8/4 = 0.20\ \text{ns}^{-1}; k_r + k_{nr} = 1/\tau = 0.25, so k_{nr} = 0.05\ \text{ns}^{-1}. (b) Q = k_r\tau = 0.2 \times 2 = 0.4; the total rate is now 1/2 = 0.5\ \text{ns}^{-1}, so the quenching rate is 0.5 - 0.25 = 0.25\ \text{ns}^{-1}.
Math questions
B8. (math) The periodic decay. Pulses arrive at times \dots, -2T, -T, 0. Each excites a decay \tau^{-1}e^{-t/\tau} (normalised). Show that the photon density in the window 0 \le t < T is p_T(t) = e^{-t/\tau}/(\tau(1 - e^{-T/\tau})), and that it integrates to 1 over the window. Which fraction of the photons in the window came from earlier pulses?
B9. (math) Means add under convolution. Let h and p be densities (non-negative, area 1). Show that h * p has area 1 and mean \langle t\rangle_h + \langle t\rangle_p. Is the same true for the variance?
B10. (math) Two gates. (a) Derive \hat\tau = \Delta t/\ln(D_1/D_2) for adjacent gates of width Δt on Ae^{-t/\tau}. (b) Show that a background b > 0 in each gate always gives \hat\tau > \tau. (c) Show that wrap-around does not bias the two-gate estimate (use B8).
B8. A photon in the window at time t comes from the pulse k periods earlier if it waited t + kT: p_T(t) = \sum_{k \ge 0}\tau^{-1}e^{-(t + kT)/\tau} = \tau^{-1}e^{-t/\tau}\sum_k (e^{-T/\tau})^k = \frac{e^{-t/\tau}}{\tau(1 - e^{-T/\tau})}. Integral: \frac{1 - e^{-T/\tau}}{1 - e^{-T/\tau}} = 1. The term k = 0 alone integrates to 1 - e^{-T/\tau}, so a fraction e^{-T/\tau} came from earlier pulses (in steady state, exactly the fraction that each decay loses to later periods).
B9. Area: \int (h * p)(t)\,dt = \iint h(u)p(t - u)\,du\,dt = \int h(u)\,du \int p(v)\,dv = 1. Mean: substitute t = u + v: \iint (u + v)h(u)p(v)\,du\,dv = \langle t\rangle_h + \langle t\rangle_p. The variance adds too (the sum of two independent random times): \sigma^2_{h*p} = \sigma^2_h + \sigma^2_p. For an exponential, \sigma^2 = \tau^2.
B10. (a) See Q8 of the quiz: D_2 = e^{-\Delta t/\tau}D_1. (b) For D_1 > D_2 > 0 and b > 0: \frac{D_1 + b}{D_2 + b} < \frac{D_1}{D_2} (cross-multiply: D_2(D_1 + b) < D_1(D_2 + b) iff b D_2 < b D_1). A smaller ratio has a smaller logarithm, so \hat\tau is larger. (c) In the window, p_T(t) = C e^{-t/\tau} with a constant C: still a pure exponential with the same τ, so the ratio of two gates is exactly e^{\Delta t/\tau}. (The mean arrival time, in contrast, is biased: the window cuts the tail.)
Explore: photons into a histogram
The demo simulates photon counting photon by photon (fixed seed): pulses, at most one timed photon per pulse, an IRF (Gaussian, width σ, with a delay), background and pile-up. The histogram has 128 bins over one period; the red curve is the expected histogram, IRF ∗ decay + background. Drag on the histogram to move the two gates; the readout gives both quick estimates.
E1. Preset one photon at a time. Watch the time line. Roughly how many pulses pass per detected photon? Why does the histogram still take the shape of the decay?
E2. Preset the log plot is a straight line (τ = 2.5 ns, 100 000 photons). Read the mean-arrival and two-gate estimates. Why is the mean-arrival estimate below 2.5 ns? (Hint: look at the first nanosecond of the histogram.)
E3. Preset the IRF blurs the start (τ = 0.8 ns, IRF σ = 0.4 ns). Compare the two estimates. Drag the gates onto the rising edge: what happens to the two-gate estimate, and why?
E4. Preset τ = 8 ns at 80 MHz. How much of each decay is still to come at the next pulse, and what do the two estimates say? Now set the pulse period to 50 ns.
E5. Preset too bright: 60 % of pulses carry a photon. Which fraction of them had two or more? What happens to both estimates, and to the shape of the histogram on the log axis? Lower the count rate until the estimates recover.
E6. Preset background flattens the tail (15 % background). Read both estimates. Make the gates narrower (1 ns) and place them right after the IRF: does that help? Why?
E7. Preset 100 photons. What can you say about τ? Change the number of photons to 1 000 and 10 000 and watch how the two estimates settle.
E1. At 5 % of pulses, about 20 pulses per photon (most of the time line is empty). Each photon is an independent draw from the arrival-time distribution, so the histogram of many such draws converges to that distribution: the decay, blurred by the IRF.
E2. Mean arrival 3.37 − IRF 1.00 = 2.37 ns; two gates (45 271 and 20 527 photons) 2.47 ns. With the IRF at 1 ns, the last part of each decay arrives after the next pulse and lands in the first nanosecond of the window (the counts before the IRF peak). Those late photons are counted as early ones, so the mean is too small. The two gates only see the exponential part, where wrap-around does not change the shape (B10c).
E3. Mean arrival 1.81 − 1.08 = 0.73 ns, two gates 0.82 ns (true 0.80). Note the IRF’s mean is 1.08 ns, not 1.00: its wide Gaussian tail wraps round the window too. On the rising edge the histogram is not an exponential (it is the IRF convolved with the decay), so the ratio D_1/D_2 is near 1 or even below it: the estimate becomes very long or undefined. The two-gate formula needs gates after the IRF.
E4. 21 % is still to come. Mean arrival 4.23 ns, two gates 8.16 ns: the window cuts the tail and wraps it round, so the mean is far too short, while the gates still see an exponential. At a period of 50 ns only 0.2 % is left, and the mean arrival gives 7.90 ns.
E5. 38.8 % of the timed pulses held two or more photons. Mean arrival 1.87 ns, two gates 1.79 ns (true 2.5): the later photons are lost, so the histogram droops at late times and is no longer straight on the log axis. Around 3 % of pulses (count-rate slider at about 50) the estimates are back near the low-rate values (2.35 and 2.45 ns, with 1.5 % multi-photon pulses).
E6. Mean arrival 2.80 ns, two gates 2.72 ns, both too long. The flat background pulls the mean towards the middle of the window and flattens the gate ratio (B2, B3). Gates of 1 ns right after the IRF give 2.67 ns: a little better, because early gates hold many fluorescence photons compared with the background, but the bias remains. Fitting a model with a background term (next unit) removes it.
E7. Mean arrival 2.41 ns, two gates 3.14 ns (41 and 22 photons): with 100 photons the two-gate estimate can be off by tens of percent, the mean arrival by about 10 %. With more photons both settle; the mean arrival keeps its small wrap-around bias. The next unit asks how good an estimate can possibly be with N photons.
Explore: a lifetime image
The cell of the unmixing day as a FLIM image (128 × 128 pixels, 64 time bins over 12.5 ns, IRF σ = 0.1 ns at 0.5 ns, Poisson counts, fixed seed). Left: intensity. Middle: the lifetime of every pixel as colour, with intensity as brightness; masked pixels are black. Right: the histogram of the clicked pixel (yellow box), or of the box around it when binning.
E8. Preset intensity lies, lifetime does not. Describe the intensity image and the lifetime image. Click a bright and a dim pixel inside the cell: what changes in the histogram, and what does not?
E9. Preset same brightness, different lifetime. Where is the 1.0 ns dye? Could you have found it in the intensity image? Then try a quencher shortens τ: why are the quenched mitochondria also dimmer?
E10. Preset too few photons per pixel: bin. The pixel at (64, 50) has 21 photons. Raise the binning to 3 × 3, 5 × 5 and 7 × 7 and read the photons and the estimates. What does the lifetime image gain, and what does it lose?
E11. Preset background pixels: mask them. What “lifetime” does a pixel outside the cell get, and why? Raise the mask threshold until the outside is black. Switch between mean arrival and two gates: which estimator is noisier inside the cell?
E8. The intensity image shows the nucleus, the mitochondria and the membrane at concentrations that vary about tenfold. The lifetime image has the same colour everywhere (one dye, 2.5 ns); only its brightness follows the intensity. A bright pixel’s histogram is higher and smoother; its slope on the log axis is the same as a dim pixel’s. The default pixel (64, 50) has 251 photons, mean arrival 2.24 ns, two gates 3.37 ns, true 2.50 ns.
E9. In the nucleus (pixel (56, 60): 401 photons, mean arrival 0.96 ns, true 1.00 ns). The intensity is flat across the cell, so intensity alone cannot see it. Quenching shortens τ and lowers the quantum yield by the same factor (B7): the quenched mitochondria emit fewer photons per molecule, so they are dimmer as well as shorter.
E10. 1 × 1: 21 photons, 2.48 ns (lucky; the image around it is speckled). 3 × 3: 201 photons, 2.46 ns; 5 × 5: 559 photons, 2.41 ns; 7 × 7: 1 099 photons, 2.47 ns. The lifetime image becomes smooth and the noise drops roughly as 1/\sqrt{\text{photons}}, but edges between compartments blur, and small structures (a mitochondrion) mix with their surroundings.
E11. The pixel at (10, 10) has 9 photons, all background, with a mean arrival of 5.70 ns after subtracting the IRF: a flat histogram’s mean is the middle of the window, so the “lifetime” is meaningless. Masking at a few tens of photons blacks out the background. The two-gate estimate is noisier: it uses only the photons in the two gates and a ratio of two small counts, while the mean arrival uses every photon.
Code
Write the algorithms of this unit yourself, in Rust. Setup, and how to run and check your code: coding exercises: getting started. Your code goes in flim/src/lifetime/exercise.rs. Times are in nanoseconds; a histogram is a list of counts in equal time bins over one laser period, and bin j is represented by its centre t_j.
C1. simulate(tau, photons, background, setup, rng): photon counting, one photon at a time, as in the first demo:
counts = zeros(number of bins)
repeat for every photon:
if a uniform random number < background:
t = uniform random time in [0, T)
else:
t = IRF delay + IRF width · (normal random number) − τ · ln(uniform random number)
t = t modulo T # wrap-around into the next period
add 1 to the bin that contains t
The checks count the photons later than 2, 4 and 6 ns (B1), the fraction in the first 2 ns of a wrapped 8 ns decay (B4, B8), and a histogram of pure background.
C2. mean_arrival(counts, period): \sum_j y_j t_j / \sum_j y_j. The checks are B3(a) and (b).
C3. two_gates(counts, period, start, width): D_1 = the counts of the bins whose centres lie in [\text{start}, \text{start} + \Delta t), D_2 = those in the next window of the same width, \hat\tau = \Delta t/\ln(D_1/D_2). The checks are B2 (with and without room light) and B10(c).
C4. lifetime_image(stack, period, irf_mean, radius, min_photons): a lifetime image from a stack of histograms, one per pixel (the third index of the stack is the time bin):
for every pixel (x, y):
h = sum of the histograms of the pixels within radius of (x, y) # binning
if the total count of h < min_photons:
τ(x, y) = 0 # masked
else:
τ(x, y) = mean arrival time of h − mean arrival time of the IRF
Then cargo run -p flim -- lifetime and open the pictures in out/lifetime/. The program first simulates 100 000 photons for three single decays (IRF at 1 ns, bins of 0.1 ns) and prints both quick estimates. Then it makes a 128 \times 128 FLIM image of synthetic nuclei, 64 bins per pixel: odd-numbered nuclei hold a 2.5 ns dye, the others the same dye quenched to 1.2 ns, and every pixel gets 8 photons of flat background. It shows the lifetime as colour (blue short, green 2.5 ns, orange long) and the intensity as brightness: without a mask, with a mask, and after 3 \times 3 binning.
C5. Read the table of the three single decays. Why does the mean arrival time give much too short a lifetime for τ = 8 ns, while the two gates do not? What does 15 % background do to each?
C6. Compare lifetime-1x1.png, lifetime-1x1-masked.png and lifetime-3x3-masked.png, and the printed means and spreads inside the nuclei. What colour is the background without a mask, and why? What does binning buy? Why do the 1.2 ns nuclei come out longer than 1.2 ns in every map?
The model solution is flim/src/lifetime/solution.rs in the download.
C5. τ = 2.5 ns: mean arrival 2.37 ns, two gates 2.50 ns. τ = 8 ns: mean arrival 4.25 ns, two gates 8.20 ns. With τ = 8 ns, 21 % of each decay is still to come at the next pulse (B4); those late photons wrap round to the start of the window and are counted as early ones, so the mean is far too small. In the window the wrapped decay is still a pure exponential with the same τ, so the ratio of two gates is unchanged (B10c). With 15 % background both estimates are too long (2.79 and 2.74 ns): the flat counts pull the mean towards the middle of the window and make the two gates more alike (B2, B3).
C6. Without a mask the background is orange-brown: its pixels hold about 8 photons, nearly all background, and their “lifetime” is the middle of the window minus the IRF (pixel (2, 2): 5.80 ns). Masking below 50 photons makes it black. Inside the 2.5 ns nuclei the estimate is 2.55 ± 0.19 ns per pixel and 2.55 ± 0.08 ns after 3 \times 3 binning: nine times the photons, less than half the spread, at the cost of sharpness at the nuclei’s edges. The 1.2 ns nuclei give 1.44 ns (1.52 binned): the 8 background photons in every pixel pull its mean arrival towards the middle of the window, 6.25 ns, as in B3(b); binning at the edges mixes in dim pixels with even more background. The quick estimates have no way to remove the background; the next unit fits it.
Where this leads
The quick estimates use the photons badly or break with background and mixtures. The next unit fits the decay through the forward model, asks how many photons a lifetime needs, and separates two lifetimes in one pixel. The phasor unit then gets two numbers per pixel with no fit at all.