def asimov_mu_ts0(self,ts): """Return the value of the signal strength parameter for which the TS (-2*lnL) for discovery is equal to the given value.""" smin = 1E-3 smax = 1E3 while self.asimov_ts0_signal(smax) < ts: smax *= 10 while self.asimov_ts0_signal(smin) > ts: smin *= 0.1 mu = find_fn_root(self.asimov_ts0_signal,smin,smax,ts) mu_err = np.sqrt(mu**2/ts) return (mu,mu_err)
nexcess = ns+nb-mub nexcess[nexcess<=0] = 0 ts_mc = -2*(poisson_lnl(ns+nb,mub) - poisson_lnl(ns+nb,ns+nb)) ts_asimov = fn_qmu(mus+mub,mus+mub,mub) ul_mc = np.zeros(ntrial) alpha = 0.05 dlnl = pval_to_sigma(alpha)**2 for i in range(ntrial): xroot = find_fn_root(lambda t: fn_qmu((ns+nb)[:,i], (mub+nexcess)[:,i], (mub+nexcess)[:,i]+t),0,100,dlnl) ul_mc[i] = nexcess[i]+xroot sigma_mu_fn = lambda t: np.sqrt(t**2/fn_qmu(mub,mub,mub+t)) ul_asimov_qmu = find_fn_root(lambda t: fn_qmu(mub,mub,mub+t),0,100,dlnl) sigma = np.sqrt(ul_asimov_qmu**2/dlnl) ul_asimov = 1.64*sigma ul_asimov_upper = (1.64+1)*sigma ul_asimov_lower = (1.64-1)*sigma print 'SIGMA ', sigma