def totalEfficiencies(self, org, dir=None, flavor=''): recoLow, recoHigh, acceptance, denom = None, None, None, None for step in org.steps: for plotName in sorted(step.keys()): if 'LowNX' + flavor == plotName: recoLow = step[plotName] if 'HighNX' + flavor == plotName: recoHigh = step[plotName] if 'AccNX' + flavor == plotName: acceptance = step[plotName] if 'NX' + flavor == plotName: denom = step[plotName] acc = tuple([ r.TGraphAsymmErrors(n, d, "cl=0.683 n") for n, d in zip(acceptance, denom) ]) efflow = tuple([ r.TGraphAsymmErrors(n, d, "cl=0.683 n") for n, d in zip(recoLow, denom) ]) effhigh = tuple([ r.TGraphAsymmErrors(n, d, "cl=0.683 n") for n, d in zip(recoHigh, denom) ]) effacclow = tuple([ r.TGraphAsymmErrors(n, d, "cl=0.683 n") for n, d in zip(recoLow, acceptance) ]) effacchigh = tuple([ r.TGraphAsymmErrors(n, d, "cl=0.683 n") for n, d in zip(recoHigh, acceptance) ]) #fs = [0.4,0.6,1.,1.4] old factors for the record if not approved fs = [0.1, 0.2, 0.3, 0.6, 1., 2., 3., 6., 10.] allfs = [0.1 * a for a in fs] allfs += fs allfs += [10 * a for a in fs] allfs = [round(a, 5) for a in allfs] N = len(allfs) forbidden = [7, 8, 9, 16, 17, 18] f = 0.89 sysmap = { '1000350': 0.075, '1000150': 0.075, '400150': 0.096, '40050': 0.091, '20050': 0.10 } for i, sample in enumerate(org.samples): digits = re.findall(r'\d+', sample['name']) H, X = digits[0], digits[2] name = 'H_' + str(H) + '_X_' + str(X) sys = sysmap[H + X] ctau = self.ctau[self.sig_names.index(name)] data = {} for factor in set(allfs): data[factor] = [] for j in range(N): if j in forbidden: continue x, y = r.Double(0), r.Double(0) eff = effhigh effacc = effacchigh if j < N / 3: eff = efflow effacc = effacclow eff[i].GetPoint(j, x, y) e = f * float(y) eErr = f * eff[i].GetErrorY(j) effacc[i].GetPoint(j, x, y) ea = f * float(y) eaErr = f * effacc[i].GetErrorY(j) acc[i].GetPoint(j, x, y) a = float(y) aErr = acc[i].GetErrorY(j) #if e > 0. : eErr = e*math.sqrt(sys*sys+pow(eErr/e,2)) #else : eErr = 0. #if ea > 0. : eaErr = ea*math.sqrt(sys*sys+pow(eaErr/ea,2)) #else : eaErr = 0. factor = allfs[j] #print H,X,factor,a,aErr,e,eErr,ea,eaErr output = [(a, aErr), (e, eErr), [ea, eaErr]] data[factor].append(output) #pickle.dump(output,open(supy.whereami()+'/../results/'+dir+'/efficiencies/'+name+'_'+str(factor)+'_'+str(j)+'.pkl','w')) for factor in data.keys(): list = data[factor] ac = [obj[0][0] for obj in list if obj[0][0] > 0] acErr = [obj[0][1] for obj in list if obj[0][0] > 0] ef = [obj[1][0] for obj in list if obj[1][0] > 0] efErr = [obj[1][1] for obj in list if obj[1][0] > 0] efac = [obj[2][0] for obj in list if obj[2][0] > 0] efacErr = [obj[2][1] for obj in list if obj[2][0] > 0] if len(ef) == 0: continue e, eErr = weightedAvg(ef, efErr) a, aErr = weightedAvg(ac, acErr) ea, eaErr = weightedAvg(efac, efacErr) #eErr = e*math.sqrt(sys*sys+pow(eErr/e,2)) #eaErr = ea*math.sqrt(sys*sys+pow(eaErr/ea,2)) print H, X, factor, a, aErr, e, eErr, ea, eaErr output = [(a, aErr), (e, eErr), [ea, eaErr]] pickle.dump( output, open( supy.whereami() + '/../results/' + dir + '/efficiencies/' + name + '_' + str(factor) + '.pkl', 'w'))
eval(file[:-4].split('_')[4])) ) files2=sorted(os.listdir(dir2),key=lambda file: (eval(file[:-4].split('_')[1]), eval(file[:-4].split('_')[3]), eval(file[:-4].split('_')[4])) ) x,w=[],[] H,X=0,0 for file1,file2 in zip(files1,files2): data1,data2=pickle.load(open(dir1+'/'+file1)),pickle.load(open(dir2+'/'+file2)) strings=file1[:-4].split('_') if ((H!=strings[1] or X!=strings[3]) and H!=0): avg,err=weightedAvg(x,w) print round(avg,5),round(err,5) x,w=[],[] H,X,factor = strings[1],strings[3],eval(strings[4]) if factor != 0.1 and factor!=1 and factor!=10 : continue e1,e2 = data1[dict[option][1]],data2[dict[option][1]] if e1[0]==e2[0]==0 : continue diff = 100* 2*(e1[0]-e2[0])/(e1[0]+e2[0]) n1=pow(e1[0]/e1[1],2) n2=pow(e2[0]/e2[1],2) if n1-n2==0: continue diffe = diff*1./math.sqrt(abs(n1-n2)) #diffe=1 #diffe = 100* 4/pow(e1[0]+e2[0],2)*math.sqrt(pow(e2[0]*e1[1],2)+pow(e1[0]*e2[1],2)) x.append(diff) w.append(diffe)