Esempio n. 1
0
 def run_zbi_stat(self):
     n_on = self.observation()
     mu_b_hat = self.background
     sigma_b = self.fullunc()
     tau = mu_b_hat / (sigma_b * sigma_b)
     n_off = tau * mu_b_hat
     P_Bi = TMath.BetaIncomplete(1. / (1. + tau), n_on, n_off + 1)
     Z_Bi = math.sqrt(2.) * TMath.ErfInverse(1 - 2. * P_Bi)
     return str(round(Z_Bi, 4))
Esempio n. 2
0
def getZbi(n_on, n_off, tau):
    P_Bi = TMath.BetaIncomplete(1. / (1. + tau), n_on, n_off + 1)
    Z_Bi = TMath.Sqrt(2) * TMath.ErfInverse(1 - 2 * P_Bi)
    return (Z_Bi)
Esempio n. 3
0
def getPbi(n_on, n_off, tau):
    P_Bi = TMath.BetaIncomplete(1. / (1. + tau), n_on, n_off + 1)
    return (P_Bi)
Esempio n. 4
0
# Generate npoints randomly with importance sampling

npoints = 1000000
xg0 = xg00 = 0
for n1 in range(npoints):
    #here do the calculation with importance sampling
    x0 = xmin**gRandom.Uniform()
    weight = x0*log(1/xmin)
    # here do the calculation using linear sampling
    # x0 = xmin+(1-xmin)*gRandom.Uniform()
    # weight = 1-xmin
    f  = g0(x0) 
    ff = weight*f
    xg0  +=  ff
    xg00 +=  ff**2

# Calculate the MC integral

xg0  /= npoints
xg00 /= npoints
sigma2 = xg00 - xg0*xg0
error  = sqrt(sigma2/npoints)
print " integral for g(x) = (1-x)**5/x is: ",xg0,"+/-", error

# Get the exact value using incomplete beta function [https://en.wikipedia.org/wiki/Beta_function]

x = 1-xmin
a = 5
b = -0.9999999999
print "Exact value ", TMath.BetaIncomplete(x, a+1, b+1) * TMath.Beta(a+1, b+1)
# Generate npoints randomly with importance sampling

xg0 = xg00 = 0
for n1 in range(npoints):
    # here do the calculation with importance sampling
    x0 = xmin**gRandom.Uniform()
    weight = x0 * log(1 / xmin)
    # here do the calculation using linear sampling
    # x0 = xmin+(1-xmin)*gRandom.Uniform()
    # weight = 1-xmin
    f = g0(x0)
    ff = weight * f
    xg0 += ff
    xg00 += ff**2

# Calculate the MC integral

xg0 /= npoints
xg00 /= npoints
sigma2 = xg00 - xg0 * xg0
error = sqrt(sigma2 / npoints)
print(" integral for g(x) = (1-x)**5/x is: ", xg0, "+/-", error)

# Get the exact value using incomplete beta function [https://en.wikipedia.org/wiki/Beta_function]

x = 1 - xmin
a = 5
b = -0.9999999999
print("Exact value ",
      TMath.BetaIncomplete(x, a + 1, b + 1) * TMath.Beta(a + 1, b + 1))