-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathNewPlotResults.py
More file actions
126 lines (104 loc) · 4.77 KB
/
NewPlotResults.py
File metadata and controls
126 lines (104 loc) · 4.77 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
import argparse
import sys
import os
import glob
import ROOT
import Plotting.PlotStyle as PS
import Plotting.Paintable as Paintable
import Plotting.Depiction as Depiction
import Plotting.Database as Database
import importlib
import PlotConf_CustomAnalysis
import ImageNames as imn
from collections import OrderedDict
def collectPaintables(definition):
paintables = {}
for key, item in definition.items():
if "Stack" in key: paintables["Stack"] = Paintable.StackPaintable("stack", definition["Stack"])
elif "data" in key: paintables["data"] = Paintable.DataPaintable("data", definition["data"])
else: paintables[key] = Paintable.OverlayPaintable(key, definition[key])
return paintables
def collectDepictions(configuration):
depictions = []
definitions = configuration["Definitions"]
for depiction in configuration["Order"]:
if definitions[depiction]["type"] == "Main" : depictions.append(Depiction.MainDepiction( definitions[depiction], depiction))
if definitions[depiction]["type"] == "Ratio" : depictions.append(Depiction.RatioDepiction( definitions[depiction], depiction))
if definitions[depiction]["type"] == "Agreement": depictions.append(Depiction.AgreementDepiction( definitions[depiction], depiction))
return depictions
def initializeDepictions(Depictions):
n = len(Depictions)
if n == 1:
Depictions[0].initializeDepiction( 0.0, 0.0, 1.0, 1.0, 0.05, 0.2)
elif n == 2:
Depictions[0].initializeDepiction( 0.0, 0.35, 1.0, 1.0, 0.08, 0.004)
Depictions[1].initializeDepiction( 0.0, 0.02, 1.0, 0.35, 0.007, 0.05)
elif n == 3:
Depictions[0].initializeDepiction( 0.0, 0.5, 1.0, 1.0, 0.1, 0.01)
Depictions[1].initializeDepiction( 0.0, 0.3, 1.0, 0.5, 0.025, 0.025)
Depictions[2].initializeDepiction( 0.0, 0.0, 1.0, 0.3, 0.017, 0.5)
else:
print "Not Supported Yet"
sys.exit()
bottomPad = Depictions[-1].pad
bottomPad.SetBottomMargin(0.1/bottomPad.GetAbsHNDC())
def drawItem(x, y, text, font = 42, size = 0.03, align = 11):
l = ROOT.TLatex()
l.SetNDC();
l.SetTextAlign(align)
l.SetTextFont(font);
l.SetTextSize(size)
l.DrawLatex(x,y,text);
def writeXaxisTitle(Paintables):
xAxisTitle = Database.histoptions.get("xtitle", Paintables[Paintables.keys()[0]].getHistogram().GetXaxis().GetTitle())
[p.getHistogram().SetXTitle("") for p in Paintables.values()]
drawItem(0.95, 0.0675, xAxisTitle, 42, 0.045, 33)
def ATLASLabel( x, y):
drawItem(x , y, "ATLAS", 72, 0.03)
drawItem(x+0.1, y, "Open Data", 42, 0.03)
def drawLegend(paintables, paintingOrder):
y1 = 0.92
y2 = y1 - 0.03*sum([i.getNumberOfLegendItems() for i in paintables.values()])
legend = ROOT.TLegend(0.70,y1,0.90,y2)
legend.SetBorderSize(0)
for key in paintingOrder:
paintables[key].addToLegend(legend)
legend.Draw()
return legend
def DrawPlot(configuration, histlocation):
print "Drawing plot: " + histlocation
#tImage = ROOT.TImageDump("Output/" + imn.ImageDic[histlocation]+ ".gif")
canvas = ROOT.TCanvas( histlocation, "title", 900, 900 )
Paintables = collectPaintables(configuration["Paintables"])
Depictions = collectDepictions(configuration["Depictions"])
initializeDepictions(Depictions)
ATLASLabel(0.2,0.90)
writeXaxisTitle(Paintables)
# legend has to be attached to canvas otherwise the garbage collector deletes it
canvas.legend = drawLegend(Paintables, Depictions[0].PaintingOrder)
[d.drawDepiction(Paintables) for d in Depictions]
canvas.SaveAs("Output/" + imn.ImageDic[histlocation]+ ".gif")
#======================================================================
def plot_results(histograms):
"""
Main function to be executed when starting the code.
"""
ROOT.gROOT.SetBatch()
ROOT.TGaxis.SetMaxDigits(4)
ROOT.TH1.AddDirectory(False)
PS.setStyle();
#parser = argparse.ArgumentParser( description = 'Plotting Tool using YAML files for configuration' )
#parser.add_argument('configfile', type=str, help='configuration file to be used')
#configModuleName = "PlotConf_CustomAnalysis"
#args = parser.parse_args()
#configModuleName = args.configfile.replace("/", ".").strip(".py")
configuration = PlotConf_CustomAnalysis.config
for histogram in histograms:
Database.UpdateDataBase(configuration, histogram)
DrawPlot(configuration, histogram)
Database.config = dict()
Database.histoptions = OrderedDict()
Database.rootFiles = dict()
#======================================================================
#if __name__ == "__main__":
# main( sys.argv[1:] )