ra4_stats  0341147a0dc35f80f4e12c6003afb76a38e2ed6e
plot_variations.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import os, sys, re
3 import glob
4 import string
5 from array import array
6 from pprint import pprint
7 import math
8 import ROOT
9 from ROOT import TMath
10 from ROOT import TColor
11 
12 inputfile = "master_redo.txt"
13 
14 #"masteroutput5.txt"
15 # First, cat all output files from send_variations into a single text file
16 # each output file has from send_variations has a single line with an identifier, and a value (limit or significance)
17 
19  with open(inputfile) as f:
20  lines = [line.rstrip('\n').split() for line in open(inputfile)] # this returns a list of pairs: [identifiying information, value of significance/limit]
21  return lines
22 
23 
24 
25 results = get_results_list()
26 
27 
28 
29 #version = "mj_comparison"
30 version = "original_comparison"
31 ###### Setting up plot definitions:
32 
33 #Make a plot for each entry in Frames
34 #Each frame has a graph for each entry defined in variations
35 #X axis is xvariable
36 
37 #####Warning: Variations MusT NOT BE A SUBSET OF EACH OTHER: EG MJdef_mj and MJdef_mj14 . Instead use MJdef_mj_
38 
39 xvariable = "lumi" # this will be the x axis
40 if "mj_comparison" in version:
41  variations = [["MJdef_mj_","threshold_400"],["MJdef_mj_","threshold_350"],["MJdef_mj14","threshold_400"],["MJdef_mj14","threshold_350"]]
42  var_names = ["R = 1.2, threshold = 400 GeV","R = 1.2, threshold = 350 GeV","R = 1.4, threshold = 400 GeV","R = 1.4, threshold = 350 GeV"]
43  var_colors = [36,36,49,49]
44 
45 
46 if "original_comparison" in version:
47  variations = [["binning_nominal","veto_off"],["binning_nominal","veto_on"],["binning_alternate","veto_off"],["binning_alternate","veto_on"]] # Each list will define one set of limits/sigs to be plotted as one TGraph
48  var_names = ["RA4 2015","RA4 2015 + veto","Alternate binning","Alternate binning + veto"] #Legend names for each TGraph
49  var_colors =[30,30,46,46]
50 
51 
52 var_linestyles = [1,7,1,7]
53 var_markerstyles = [20,22,20,22]
54 frames = [["mGluino-1600_mLSP-1000","sig_str0"],["mGluino-1600_mLSP-1000","sig_str1"],["mGluino-1800_mLSP-200","sig_str0"],["mGluino-1800_mLSP-200","sig_str1"],["mGluino-1400_mLSP-1000","sig_str0"],["mGluino-1400_mLSP-1000","sig_str1"]] # limit, sig plots for compressed, noncompressed
55 frame_titles = ["T1tttt(1600,1000) Limit","T1tttt(1600,1000) Significance","T1tttt(1800,200) Limit","T1tttt(1800,200) Significance","T1tttt(1400,1000) Limit","T1tttt(1400,1000) Significance"]
56 
57 ### for Full sim points:
58 #frames = [["mGluino-1200_mLSP-800","sig_str0"],["mGluino-1200_mLSP-800","sig_str1"],["mGluino-1500_mLSP-100","sig_str0"],["mGluino-1500_mLSP-100","sig_str1"]] # limit, sig plots for compressed, noncompressed
59 #frame_titles = ["T1tttt(1200,800) Limit","T1tttt(1200,800) Significance","T1tttt(1500,100) Limit","T1tttt(1500,100) Significance"]
60 
61 
62 
63 #####Cosmetics
64 
65 ROOT.gROOT.SetBatch(ROOT.kTRUE) #prevent th1->Draw() from trying to open X11 window
66 ROOT.gStyle.SetCanvasDefW(600);
67 ROOT.gStyle.SetCanvasDefH(600);
68 ROOT.gStyle.SetTitleOffset(1.2,"x")
69 ROOT.gStyle.SetTitleOffset(1.7,"y")
70 ROOT.gStyle.SetPadLeftMargin(0.14)
71 ROOT.gStyle.SetPadBottomMargin(0.14)
72 ROOT.gStyle.SetLabelFont(42)
73 ROOT.gStyle.SetTitleFont(42)
74 
75 #######
76 
77 #####Reading values and plotting them
78 
79 xmin=4
80 xmax=21
81 for ifr,frame in enumerate(frames):
82  graphs = []
83  for var in variations:
84  pairs = []
85  for line in results:
86  use_this_line = True
87  for attribute in frame: # Find out if this line belongs in this frame
88  if attribute not in line[0]:
89  use_this_line = False
90  break
91  if use_this_line: #Correct frame, but does it belong in this variation?
92  for attribute in var:
93  if attribute not in line[0]:
94  use_this_line = False
95  break
96 
97  if use_this_line:
98  yval = line[1]
99  xval = line[0].split(xvariable)[1].split("_")[0].split("ifb")[0] # this finds the string in the identifier between "xvariable" (lumi) and the next underscore. Removes trailing "ifb" just in case
100  pairs.append([float(xval),float(yval)])
101  #results.remove(line) #Each line is used exactly once, so remove this one from the list
102 
103  pairs.sort()
104  x = [pair[0] for pair in pairs] # convert from list of pairs to x list and y list for TGraph
105  y = [pair[1] for pair in pairs]
106  graph = ROOT.TGraph(len(x),array("d",x),array("d",y)) #ROOT sucks
107  graphs.append(graph)
108 
109  c = ROOT.TCanvas()
110  leg = ROOT.TLegend(0.14,0.7,0.48,0.9)
111  ymax = 3
112  ymin = 0
113  title = frame_titles[ifr]+";Luminosity [ifb]; Expected Significance;"
114  if "sig_str0" in frame:
115  ymax = 3
116  ymin = 0
117  title = frame_titles[ifr]+";Luminosity [ifb]; Expected Limit;"
118 
119  histframe = ROOT.TH2F("frame","",10,xmin,xmax,10,ymin,ymax)
120 
121  histframe.SetStats(0)
122 
123  histframe.SetTitle(title)
124  histframe.Draw()
125  for i,graph in enumerate(graphs):
126  graph.SetName(var_names[i])
127  graph.SetLineColor(var_colors[i])
128  graph.SetLineStyle(var_linestyles[i])
129  graph.SetMarkerColor(var_colors[i])
130  graph.SetMarkerStyle(var_markerstyles[i])
131 
132  graph.Draw("lp same")
133  leg.AddEntry(graph,var_names[i],"lp")
134 
135  leg.Draw("same")
136  c.Print(version+"_"+frame[0]+"_"+frame[1]+".pdf")