Repository navigation
Expand file tree
/
Copy pathplot-nuis
More file actions
executable file
·149 lines (132 loc) · 5.18 KB
/
Copy pathplot-nuis
File metadata and controls
executable file
·149 lines (132 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python
# python imports
import pickle
import os
import logging
# ROOT/rootpy imports
from rootpy.plotting import Canvas, Legend, Graph, Hist, get_style, set_style
from rootpy.utils.path import mkdir_p
from rootpy.plotting.utils import draw
from rootpy.plotting.style.atlas.labels import ATLAS_label
from rootpy import ROOT
from ROOT import TLine
#local imports
from statstools.plotting import parse_name, get_category, get_data, print_np
log = logging.getLogger(os.path.basename(__file__))
# set the style
style = get_style('ATLAS', shape='square')
style.SetPadLeftMargin(0.16)
style.SetTitleYOffset(1.4)
style.SetTitleSize(20)
set_style(style)
if not os.getenv('MVA_NO_BATCH', False):
ROOT.gROOT.SetBatch(True)
def get_pickle_path(WS_PATH, ws_name):
return '{0}/{1}/measurement_{1}_nuispars_scan.pickle'.format(WS_PATH, ws_name)
def plot_nuis(name, graphs, outdir):
c = Canvas()
xaxis, yaxis = c.axes(xlimits=(-3, 3), ylimits=(-1, 10))
# draw guide lines
line = TLine()
line.SetLineStyle(7)
line.SetLineWidth(2)
line.DrawLine(-3, 0, 3, 0)
line.DrawLine(-3, 1, 3, 1)
draw(graphs, pad=c, snap=False, ypadding=0, same=True,
xaxis=xaxis, yaxis=yaxis,
xtitle=print_np(name), ytitle='2#Delta[-log(L)]',
xlimits=(-3, 3), ylimits=(-1, 10))
for graph in graphs:
graph.legendstyle = 'L'
leg = Legend(graphs, leftmargin=0.1, margin=0.15,
topmargin=0.1, textsize=15)
leg.Draw()
ATLAS_label(0.68, 0.88, text="Internal", sqrts=None, pad=c, sep=0.12)
c.SaveAs(os.path.join(outdir, '{0}.png'.format(name)))
c.SaveAs(os.path.join(outdir, '{0}.eps'.format(name)))
def make_graph(values, nominal, max_value=8, **kwargs):
graph = Graph(len(values), **kwargs)
i = 0
for x, y in values:
value = 2 * (y - nominal)
# nan?
if value != value:
continue
if value > max_value:
continue
graph[i] = (x, value)
i += 1
graph.num_points = i
return graph
if __name__ == '__main__':
from rootpy.extern.argparse import ArgumentParser
from mva.categories import CATEGORIES
parser = ArgumentParser()
parser.add_argument('path')
parser.add_argument('--mass', default='125')
parser.add_argument('--ana', default='mva', choices=['mva', 'cba'])
args = parser.parse_args()
if args.ana=='mva':
categories = CATEGORIES['mva']
else:
categories = CATEGORIES['cuts']+CATEGORIES['cuts_2011']
# Step1: Retrieve NP scans of the combined WS
graphs = {}
combined_np_path = get_pickle_path(args.path, 'hh_12_combination_{0}'.format(args.mass))
if not os.path.exists(combined_np_path):
raise RuntimeError('Need the combineds WS scans to run !')
data_comb = get_data(combined_np_path)
nominal_comb = data_comb['NOMINAL']
for nuis, values in data_comb.items():
if nuis=='NOMINAL':
continue
graphs[nuis] = []
graphs[nuis].append(make_graph(values, nominal_comb, drawstyle='L', linewidth=3,
name='hh_combination_{0}'.format(nuis),
title='Combined'))
# Step 2: Retrieve all available subchannel NP scans
for dir in os.listdir(args.path):
if os.path.isdir(os.path.join(args.path, dir)):
if 'combination' in dir:
continue
log.info('channel_'+dir)
if args.mass in dir:
np_path = get_pickle_path(args.path, dir)
if '_12_' in dir:
year = 2012
elif '_11_' in dir:
year = 2011
else:
continue
_, cat_name, _ = parse_name('channel_'+dir)
log.info('{0} - {1}'.format(dir, year))
#year = get_year(dir)
if year is None:
continue
cat = get_category(cat_name, categories)
if cat is None:
continue
log.info(dir)
if os.path.exists(np_path):
data = get_data(np_path)
nominal = data['NOMINAL']
for nuis, values in data.items():
if nuis=='NOMINAL':
continue
graph = make_graph(values, nominal,
drawstyle='L',
linewidth=3,
linecolor=cat.color,
linestyle=cat.linestyle,
name='{0}_{1}'.format(dir, nuis),
title='{0}: {1}'.format(year, cat.label))
graphs[nuis].append(graph)
# Step 3: Draw the NPS scans
plots = os.path.join(args.path,
'hh_12_combination_{0}'.format(args.mass),
'nuisances_scans')
if not os.path.exists(plots):
mkdir_p(plots)
for nuis, graphs_nuis in graphs.items():
log.info(graphs_nuis)
plot_nuis(nuis, graphs_nuis, plots)