/* Function to compute the solution to the correct photon counting signal for a coherent source. The solution is found by bisection to within 10^-2. The signal is the variable sig, the dead time is the variable dt. The corrected signal is returned from the variable sol. */ float nlexp (float sig, float dt) { int j; float x1, x2, dx, xmid; float f, fmid, sol; x1 = sig; x2 = 1.5*sig; f = sig - x1*exp(-dt*x1); fmid = sig - x2*exp(-dt*x2); sol = f < 0.0 ? (dx = x2 - x1, x1) : (dx = x1 - x2, x2); for (j = 1; j <= 40; j++){ xmid = sol + (dx *= 0.5); fmid = sig - xmid*exp(-dt*xmid); if (fmid <= 0.0) sol = xmid; if (fabs(dx) < 1e-2 || fmid == 0.0) return sol; } }