def makePlots(ratios_J100,ratios_J75,J100inputfileform,J75inputfileform,makeCombinedPlot = False): (dataset, luminosity, cutstring) = ("J100yStar06", 29.3*1000, "|y*| < 0.6" ) if len(ratios_J100) == 1: cutstring += " " + names['%1.2f'%(ratios_J100[0])] J100_plots = getGaussianLimits( J100inputfileform, ratios_J100, dataset, luminosity, cutstring, makePlot = not makeCombinedPlot) (dataset, luminosity, cutstring) = ("J75yStar03", 3.57*1000, "|y*| < 0.3") if len(ratios_J100) == 1: cutstring += " " + names['%1.2f'%(ratios_J75[0])] J75_plots = getGaussianLimits( J75inputfileform, ratios_J75, dataset, luminosity, cutstring, makePlot = not makeCombinedPlot) if makeCombinedPlot: allobserved = [] allexpected = [] allexpected1Sigma = [] allexpected2Sigma = [] all_ratios = list(set().union(ratios_J100,ratios_J75)) all_ratios.sort() for r in all_ratios: SR_dicts = [J100_plots,J75_plots] allobserved.append([d[r]['obs'] if r in d else None for d in SR_dicts]) allexpected.append([d[r]['exp'] if r in d else None for d in SR_dicts]) allexpected1Sigma.append([d[r]['exp1'] if r in d else None for d in SR_dicts if r == 0]) allexpected2Sigma.append([d[r]['exp2'] if r in d else None for d in SR_dicts if r == 0]) # Initialize painter myPainter = Morisot() # Internal if len(ratios_J100) > 1 or len(ratios_J75) > 1: myPainter.setColourPalette("Tropical") else: myPainter.setColourPalette("ATLAS") myPainter.setLabelType(2) myPainter.cutstring = '#scale[0.9]{|y*| < 0.3, m_{jj} < 700 GeV};#scale[0.9]{|y*| < 0.6, m_{jj} > 700 GeV}' outfolder = "./plots/" outname = outfolder+"GenericGaussians_Combined" if len(ratios_J100) == 1 and len(ratios_J75) == 1 and ratios_J100[0] == ratios_J75[0]: outname += "_" + str(int(ratios_J75[0]*100)) myPainter.cutstring += ";"+names['%1.2f'%(ratios_J75[0])].replace('Res.','detector resolution') myPainter.drawSeveralObservedExpectedLimits(allobserved,allexpected,allexpected1Sigma,allexpected2Sigma,\ [names['%1.2f'%r] for r in all_ratios],outname,"m_{G} [GeV]",\ "#sigma #times #it{A} #times BR [pb]",[3.57*1000,29.3*1000],13,400,1850,2E-2,300,[],\ ATLASLabelLocation="BottomL",cutLocation="Left",doLegendLocation="Left" if len(ratios_J100) == 1 else "Center")
def getModelLimits(ptCut, coupling, these_massvals,individualLimitFiles, sig_dict, limitsDictOut, \ cutstring = '', xname = "M_{Z'} [GeV]", yname = "#sigma #times #it{A} #times BR [pb]" ): print ptCut, " ", coupling # Initialize painter myPainter = Morisot() myPainter.setColourPalette("ATLAS") myPainter.cutstring = cutstring #myPainter.setEPS(True) myPainter.setLabelType( 2) # Sets label type i.e. Internal, Work in progress etc. # See below for label explanation # 0 Just ATLAS # 1 "Preliminary" # 2 "Internal" # 3 "Simulation Preliminary" # 4 "Simulation Internal" # 5 "Simulation" # 6 "Work in Progress" thisobserved = ROOT.TGraph() thisexpected = ROOT.TGraph() thisexpected_plus1 = ROOT.TGraph() thisexpected_minus1 = ROOT.TGraph() thisexpected_plus2 = ROOT.TGraph() thisexpected_minus2 = ROOT.TGraph() thistheory = ROOT.TGraph() #for mass in these_massvals: for mass in masses: import glob #file_list = glob.glob(individualLimitFiles.format(signal,mass)) individualLimitFiles = individualLimitFiles.replace("PPP", ptCut) individualLimitFiles = individualLimitFiles.replace("CCC", coupling) individualLimitFiles = individualLimitFiles.replace("MMM", str(mass)) file_list = glob.glob( individualLimitFiles.format(ptCut, coupling, mass)) print "individualLimitFiles", individualLimitFiles print("file_list: ", file_list) if len(file_list) == 0: continue allCLs = [] PE_CLs = [] for f in file_list: file = ROOT.TFile.Open(f) if not file or not file.Get("CLOfRealLikelihood"): continue CL = file.Get("CLOfRealLikelihood")[0] PE_tree = file.Get("ensemble_test") if not PE_tree or not CL: continue for event in PE_tree: PE_CLs.append( event.GetBranch("95quantile_marginalized_2"). GetListOfLeaves().At(0).GetValue()) allCLs.append(CL) if len(allCLs) == 0: continue expCLs = GetCenterAndSigmaDeviations(PE_CLs) print mass, allCLs[0], expCLs[2], len(PE_CLs) m = float(mass) / 1000. obsCL = allCLs[0] / luminosity expCLs = [e / luminosity for e in expCLs] thisobserved.SetPoint(thisobserved.GetN(), m, obsCL) thisexpected_minus2.SetPoint(thisexpected_minus2.GetN(), m, expCLs[0]) thisexpected_minus1.SetPoint(thisexpected_minus1.GetN(), m, expCLs[1]) thisexpected.SetPoint(thisexpected.GetN(), m, expCLs[2]) thisexpected_plus1.SetPoint(thisexpected_plus1.GetN(), m, expCLs[3]) thisexpected_plus2.SetPoint(thisexpected_plus2.GetN(), m, expCLs[4]) #c = SignalCouplings[signal] #print sig_dict[c] #signal_info = sig_dict[c]['%1.2f'%m] #signal_acc = signal_info['acc'] #signal_thxsec = signal_info['theory'] #signal_info['exp'] = expCLs[2] #signal_info['obs'] = obsCL #signal_info['exp+1'] = expCLs[3] #signal_info['exp+2'] = expCLs[4] #signal_info['exp-1'] = expCLs[1] #signal_info['exp-2'] = expCLs[0] #if c not in limitsDictOut: limitsDictOut[c] = {} limitsDictOut = {} #limitsDictOut['%1.2f'%m] = signal_info #t#histheory.SetPoint(thistheory.GetN(),m,signal_acc*signal_thxsec) #if not c in ZPrimeLimits: ZPrimeLimits[c] = {} #ZPrimeLimits[c][m] = {'obs':obsCL,'exp':expCLs[2],'th':signal_acc*signal_thxsec} if thisobserved.GetN() == 0: print "No limits found for couping: ", coupling, "ptCut: ", ptCut return limitsDictOut thisexpected1 = makeBand(thisexpected_minus1, thisexpected_plus1) thisexpected2 = makeBand(thisexpected_minus2, thisexpected_plus2) outputName = folderextension + "Limits_pH" + ptCut + '_gSM' + coupling + "_" + dataset + plotextension xlow = 'automatic' # (int(masses[signal][0]) - 100)/1000. xhigh = 'automatic' #(int(masses[signal][-1]) + 100)/1000. #myPainter.drawLimitSettingPlotObservedExpected(thisobserved,thisexpected,thisexpected1, thisexpected2, thistheory,SignalTitles[signal],\ # outputName, xname,yname,luminosity,Ecm,xlow,xhigh,2E-4,100,False) myPainter.drawLimitSettingPlotObservedExpected(thisobserved,thisexpected,thisexpected1, thisexpected2,"",\ "",outputName, xname,yname,luminosity,Ecm,xlow,xhigh,2E-4,100,False) return limitsDictOut
def getGaussianLimits( inputfileform, ratios, dataset, luminosity, cutstring, makePlot = True, outfolder = "./plots/"): basicInputFiles = {} for r in ratios: basicInputFiles[r] = [] import glob file_list = glob.glob(inputfileform) for f in file_list: ratio_str = f.split('.')[-2].split('_')[-1] if ratio_str == 'resolutionwidth': ratio = 0.0 else: ratio = float(ratio_str)/1000. if ratio in basicInputFiles: basicInputFiles[ratio].append(f) # Initialize painter myPainter = Morisot() # Internal myPainter.setLabelType(2) myPainter.cutstring = cutstring #myPainter.setLabelType(1) minMassVal = {} values = {} mass_list = [] allobserved = [] allexpected = [] allexpected1Sigma = [] allexpected2Sigma = [] results = {} for r in ratios: values[r] = {} for f in basicInputFiles[r]: file = ROOT.TFile.Open(f) CLs = file.Get("CLsPerMass_widthToMass%d"%(r*1000)) masses = file.Get("massesUsed") if masses == None: continue for i,mass in enumerate(masses) : #if dataset == "J100" and mass < 700: continue if "J75" in dataset and not makePlot and mass > 700: continue if mass > 1850: continue mass_list += [mass] PE_tree = file.Get("ensemble_tree_%d_%d"%(mass,r*1000)) PE_CLs = [] for event in PE_tree: PE_CLs.append( event.GetBranch("95quantile_marginalized_1").GetListOfLeaves().At(0).GetValue() ) expCLs = GetCenterAndSigmaDeviations(PE_CLs) #print mass, CLs[i]/luminosity, [e/luminosity for e in expCLs] if mass not in values[r]: values[r][mass] = {'obs': [], 'exp': [], 'PEs': [] } values[r][mass]['obs'].append(CLs[i]/luminosity) values[r][mass]['exp'].append(expCLs[2]/luminosity) values[r][mass]['PEs'] += [e/luminosity for e in PE_CLs] mass_list = sorted(list(set(mass_list))) thisobserved = ROOT.TGraph() thisexpected = ROOT.TGraph() thisexpected_plus1 = ROOT.TGraph() thisexpected_minus1 = ROOT.TGraph() thisexpected_plus2 = ROOT.TGraph() thisexpected_minus2 = ROOT.TGraph() for m in mass_list : if m not in values[r]: continue expCLs = GetCenterAndSigmaDeviations(values[r][m]['PEs']) print r, m, values[r][m]['obs'][0], values[r][m]['exp'][0], len(values[r][m]['PEs']) thisobserved.SetPoint( thisobserved.GetN(),m,values[r][m]['obs'][0]) thisexpected_minus2.SetPoint(thisexpected_minus2.GetN(),m,expCLs[0]) thisexpected_minus1.SetPoint(thisexpected_minus1.GetN(),m,expCLs[1]) thisexpected.SetPoint( thisexpected.GetN(),m,expCLs[2]) thisexpected_plus1.SetPoint( thisexpected_plus1.GetN(),m,expCLs[3]) thisexpected_plus2.SetPoint( thisexpected_plus2.GetN(),m,expCLs[4]) allobserved.append(thisobserved) allexpected.append(thisexpected) thisexpected1Sigma = makeBand(thisexpected_minus1,thisexpected_plus1) thisexpected2Sigma = makeBand(thisexpected_minus2,thisexpected_plus2) if r == 0: allexpected1Sigma.append(thisexpected1Sigma) allexpected2Sigma.append(thisexpected2Sigma) else: allexpected1Sigma.append(ROOT.TGraph()) allexpected2Sigma.append(ROOT.TGraph()) results[r] = {'obs':thisobserved, 'exp': thisexpected,'exp1': thisexpected1Sigma,'exp2': thisexpected2Sigma} if makePlot: #print ratios #print [names['%1.2f'%r] for r in ratios] myPainter.drawSeveralObservedExpectedLimits(allobserved,allexpected,allexpected1Sigma,allexpected2Sigma,[names['%1.2f'%r] for r in ratios],outfolder+"GenericGaussians_"+dataset,"m_{G} [GeV]",\ "#sigma #times #it{A} #times BR [pb]",luminosity,13,400,2000,1E-2,50,[],ATLASLabelLocation="BottomR",cutLocation="Left") return results
ratios_J75 = [0.0, 0.05, 0.07, 0.10] inputfileform = indir+"results/data2017/runSWIFT2016_J75yStar06/GenericGaussians_3p57_doSwift_*" J75_plots = getGaussianLimits( inputfileform, ratios_J75, dataset, luminosity, cutstring, makePlot = not makeCombinedPlot) ''' if makeCombinedPlot: allobserved = [] allexpected = [] allexpected1Sigma = [] allexpected2Sigma = [] all_ratios = list(set().union(ratios_J100,ratios_J75)) all_ratios.sort() for r in all_ratios: SR_dicts = [J100_plots,J75_plots] allobserved.append([d[r]['obs'] if r in d else None for d in SR_dicts]) allexpected.append([d[r]['exp'] if r in d else None for d in SR_dicts]) allexpected1Sigma.append([d[r]['exp1'] if r in d else None for d in SR_dicts if r == 0]) allexpected2Sigma.append([d[r]['exp2'] if r in d else None for d in SR_dicts if r == 0]) # Initialize painter myPainter = Morisot() # Internal myPainter.setLabelType(2) myPainter.cutstring = 'J75 |y*| < 0.3, 3.57 fb^{-1} J100 |y*| < 0.6, 29.3 fb^{-1}' outfolder = "./plots/" myPainter.drawSeveralObservedExpectedLimits(allobserved,allexpected,allexpected1Sigma,allexpected2Sigma,[names['%1.2f'%r] for r in all_ratios],outfolder+"GenericGaussians_Combined","m_{G} [GeV]",\ "#sigma #times #it{A} #times BR [pb]",0,13,400,2000,1E-2,50,[],ATLASLabelLocation="byLegend",cutLocation="BottomL",labels=["J75 |y*| < 0.3, 3.57 fb^{-1}","J100 |y*| < 0.6, 29.3 fb^{-1} "])
shiftedgraphs = [] d1, d2 = ROOT.Double(0), ROOT.Double(0) findMaxRange = 0 for graph in graphs: newgraph = graph.Clone() newgraph.SetName(graph.GetName() + "_scaled") for np in range(newgraph.GetN()): newgraph.GetPoint(np, d1, d2) newgraph.SetPoint(np, d1 / 1000.0, d2) if d1 / 1000 > findMaxRange: findMaxRange = d1 / 1000 shiftedgraphs.append(newgraph) trueMaxRange = round(findMaxRange * 2) / 2 + 0.5 myPainter.cutstring = "|y*| < 0.6" myPainter.drawSeveralObservedLimits(shiftedgraphs,names,folderextension+"GenericGaussians"+plotextension,"m_{G} [TeV]",\ "#sigma #times #it{A} #times BR [pb]",luminosity,13,0.9,7.2,1E-2,50,[],ATLASLabelLocation="BottomR",cutLocation="Left") print "For table in note:" # mostMasses = results[sorted(results.keys())[0]] print results.keys()[0] groupMasses = [] for key, value in results.iteritems(): # groupMasses = groupMasses + value.keys() groupMasses = list(set(groupMasses)) print groupMasses mostMasses = sorted(groupMasses) for mass in sorted(mostMasses): sys.stdout.write("{0}".format(float('%.3g' % (mass / 1000.0))))