def _quantile(self,nbkg=None,xedge=None,ncounts=None,fraction=0.68): if nbkg is None: nbkg = self._nbkg if ncounts is None: ncounts = self._ncounts if xedge is None: xedge = self._xedge # print 'nbkg ', nbkg # print 'sum(counts) ', np.sum(ncounts) ncounts_cum = np.cumsum(ncounts) nbkg_cum = self._bkg_fn(xedge)*nbkg nex_cum = copy.copy(ncounts_cum) nex_cum -= nbkg_cum cdf = nex_cum/float(nex_cum[-1]) x = percentile(xedge,cdf,fraction) # plt.figure() # plt.plot(xedge,ncounts) # plt.plot(xedge,self._bkg_fn(xedge)*nbkg) # plt.figure() # plt.plot(xedge,ncounts_cum) # plt.plot(xedge,nbkg_cum) # plt.figure() # plt.plot(xedge,cdf) # plt.axhline(fraction) # plt.axvline(x) # plt.gca().grid(True) # plt.show() return x
def _quantile(self,non=None,noff=None,fraction=0.68): if non is None: non = self._non if noff is None: noff = self._noff non_cum = np.cumsum(non) noff_cum = np.cumsum(noff) nex_cum = copy.copy(non_cum) nex_cum -= self._alpha*noff_cum non_tot = non_cum[-1] noff_tot = noff_cum[-1] nex_tot = non_tot-self._alpha*noff_tot cdf = nex_cum/nex_tot x = percentile(self._axis.edges,cdf,fraction) return x