styles.py
Go to the documentation of this file.
1 ###########################
2 # generic drawing styles
3 import ROOT
4 truth_colours= [ROOT.kRed, ROOT.kMagenta+2,ROOT.kBlue+2,ROOT.kCyan+2, ROOT.kGreen+2, ROOT.kGray, ROOT.kOrange]
5 data_colours = [ROOT.kBlack, ROOT.kBlue, ROOT.kGreen, ROOT.kRed]
6 lines = [0,1,2,3,0,1,2,3]
7 markers = [20,21,22,23,24,25,26]
8 ###########################
9 # parse drawing configuration options from the name of a histogram and a list of components
10 def parseDrawingConfig(plot_name, components, verbose=False):
11  import naming_schema
12  suffixes = naming_schema.standard_truth_components[1:]
13  i_truth = 0
14  # lazy man's object
15  draw_config = type('draw_config', (object,), {})()
16  draw_config.labels = []
17  draw_config.axis_labels = parseAxisLabels(plot_name)
18  draw_config.colours = []
19  draw_config.lines = []
20  draw_config.markers = []
21  draw_config.draw_options = []
22  for i,component in enumerate(components):
23  if hasattr(component, "label"):
24  label = naming_schema.datasetToLabel(component.label)
25  else:
26  label = naming_schema.datasetToLabel(component.dataset)
27  if ("-truth_components" in plot_name) and (label in draw_config.labels):
28  label = suffixes[i_truth]
29  i_truth +=1
30  if i_truth >= len(suffixes): i_truth = 0
31  draw_config.labels.append(label)
32  draw_config.lines.append(lines[i])
33  draw_config.markers.append(markers[i])
34 
35  if ("data" in draw_config.labels[-1]):
36  if ("surface" in plot_name) or ("_vs_" in plot_name):
37  if len(components) == 1:
38  draw_config.draw_options.append("COLZ")
39  else:
40  draw_config.draw_options.append("BOX")
41  elif ("contour" in plot_name):
42  draw_config.draw_options.append("L")
43  elif ("sensitivity_bestfit" in plot_name):
44  draw_config.draw_options.append("P")
45  else:
46  draw_config.draw_options.append("EX09")
47  draw_config.colours.append(data_colours[i])
48 
49  else:
50  if ("surface" in plot_name) or ("_vs_" in plot_name):
51  if len(components) == 1:
52  draw_config.draw_options.append("COLZ")
53  else:
54  draw_config.draw_options.append("BOX")
55  elif ("contour" in plot_name):
56  draw_config.draw_options.append("L")
57  elif ("sensitivity_bestfit" in plot_name):
58  draw_config.draw_options.append("P")
59  else:
60  draw_config.draw_options.append("hist9")
61  draw_config.colours.append(truth_colours[i])
62 
63  return draw_config
64 ###########################
65 # parse the axis labels from a plot name
66 def parseAxisLabels(name):
67  import naming_schema
68  import common_tools as tools
69  # histograms should follow a logical naming convention:
70  # <category>/<observable>_<reconstruction level>_<truth level>
71  # category = reco, true, mixed
72  if (not tools.isLogicalHistogramName(name)):
73  print "style: Histogram name: %s does not follow expected naming conventions"%name
74  return "x;y;"
75  if "_vs_" in name:
76  tokens = tools.getHistogramObservable(name).split("_vs_")
77  labels = "%s;%s"%(naming_schema.observableName(tokens[0]),naming_schema.observableName(tokens[1]))
78  else:
79  labels = "%s;Entries"%naming_schema.observableName(tools.getHistogramObservable(name))
80  return labels
void split(double tt, double *fr)
def parseDrawingConfig(plot_name, components, verbose=False)
parse drawing configuration options from the name of a histogram and a list of components ...
Definition: styles.py:10
def datasetToLabel(name)
convert the dataset name to a label
def observableName(name)
get a histogram observable name
def parseAxisLabels(name)
parse the axis labels from a plot name
Definition: styles.py:66