def output(bdt=0.976, probk=0.53, probmu=1.41, probe=-0.80, countoutput=False, text=False, graph=False, sigma=5): #Fit to find expected background count and exponential distribution parameter expcount, aval = f.run(file1, t1, CommonSelection, lower, upper, lowercut, uppercut, bdt, probk, probmu, probe, text=text, graph=graph) if expcount != None: #Construct full selection for efficiency calculations partselection = ("(BDT >" + str(bdt) + ") && (Kplus_PIDK_corrected > " + str(probk) + ") && (muplus_PIDmu_corrected > " + str(probmu) + ") && (eminus_PIDe_corrected > " + str(probe) + ")&& (Kplus_isMuonLoose == 0) && (Kplus_InAccMuon==1) && (Psi_M < 3000 || Psi_M >3200) && (B_BKGCAT == 10)") selection = CommonSelection + "(B_M < " + str(uppercut) + ") && (B_M > " + str(lowercut) + " ) && " + partselection #Determine the required Chisquare percentage for 2 sigma or 5 sigma Branching Ratio if int(sigma) == 2: percentage = 0.95 elif int(sigma) == 5: percentage = 0.999999426697 #Using the expected background count and required percentage, calculate the required signal count through Poisson Statistics signal = p.getExpectedLimit(expcount, percentage) #Pass the signal count and selection to the branching ratio calculator ratio, error = br.run(signal, file2, t2, selection) #return ratio and error for the purpose of a csv output and graph if countoutput == True: return ratio, error #return just the ratio, for the purpose of minimisation else: return ratio #If the fit has not converged, or expected count is 0, return error else: return float('nan')
def output(bdt=0.96, probk=-2.0, probmu=2.0, probe=2.0, countoutput=False, text=False, dynamic=False, graph =False, random=False): #Fit to find expected background count and exponential distribution parameter expcount, aval = f.run(file1, t1, CommonSelection, lower, upper, lowercut, uppercut, bdt, probk, probmu, probe, text=text, graph=graph) count = 17 significance = False maxrandomcount = 100 if random: randomcount=0 else: randomcount = maxrandomcount - 1 ratioarray = [] errorarray = [] if expcount != None: #Calculates the Branmching Ratio 100 times, and calculates a mean while randomcount != maxrandomcount: #iteratively add counts to the signal peak until it has a 5 sigma significance while significance != True: sig, entries, significance, peak, sigma, selection = s.run(file2, t2, CommonSelection, var, lower, upper, lowercut, uppercut, bdt, expcount, aval, count, probk, probmu, probe, text=text, graph=graph) if (dynamic == True) & (peak < 3.0): if sigma < (expcount * 0.2): count += (int(sigma) +1) else: count +=20 elif significance != True: count += int(sigma*0.01) +1 ratio, error = br.run(sig, entries, file2, t2, selection) randomcount += 1 ratioarray.append(ratio) errorarray.append(error) significance = False count += -5 averageratio = np.mean(ratioarray) if random: averageerror = np.mean(errorarray)/math.sqrt(float(randomcount)) print time.asctime(time.localtime()), "Final Branching Ratio is", ufloat(averageratio, averageerror) else: averageerror = np.mean(errorarray) #return ratio and error for the purpose of a csv output and graph if countoutput == True: return averageratio, averageerror #return just the ratio, for the purpose of minimisation else: return averageratio #If the fit has not converged, or expected count is 0, return error else: return float('nan')