ATLAS Offline Software
Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
2 
3 import ROOT
4 ROOT.PyConfig.IgnoreCommandLineOptions = True
5 
6 
8  def __init__(self):
9  self.egammaLayerRecalibTool = ROOT.egammaLayerRecalibTool
10  self.output_file = ROOT.TFile("test_output.root", "recreate")
11 
12  def iscrack(self, eta):
13  aeta = abs(eta)
14  return 1.37 <= aeta <= 1.55
15 
16  def example_inputs(self):
17  inputs = ROOT.StdCalibrationInputs()
18  inputs.E0raw = 10.
19  inputs.E1raw = 20.
20  inputs.E2raw = 30.
21  inputs.E3raw = 40.
22  inputs.R = 0.
23  inputs.phi = 0.
24  return inputs
25 
26  def plot(self):
27  tunes = (
28  # high-level tunes used in the calibration tool (usually composition of low-level tunes)
29  '2011_alt_with_layer2', '2012_alt_with_layer2', 'es2017_20.7_improved', 'es2017_20.7_final',
30  # low-level tunes used in the calibration tool
31  'layer2_alt_2011_v5', "ps_2011", # used in 2011_alt_with_layer2
32  "ps_HV1", "layer2_alt_2012_v5", "ps_2012", # used in 2012_alt_with_layer2
33  "pileup_20.7", "run2_alt_with_layer2_modif", # used in es2017_20.7_final
34  "2012_alt_with_layer2_modif", # used in es2017_20.7_improved
35  "ps_EMECHV1", "layer2_alt_run2_v1", "ps_2016", # used by run2_alt_with_layer2_modif
36  )
37  for tune in tunes:
38  self.plot_tune(self.egammaLayerRecalibTool(tune), '%s.png' % tune)
39 
40  def plot2d(self):
41  self.plot_tune2d(self.egammaLayerRecalibTool('ps_HV1'), 'ps_HV1_2d_period0.png', run_number = 204931)
42  self.plot_tune2d(self.egammaLayerRecalibTool('ps_HV1'), 'ps_HV1_2d_period1.png', run_number = 204932)
43  self.plot_tune2d(self.egammaLayerRecalibTool('ps_HV1'), 'ps_HV1_2d_period2.png', run_number = 205112)
44  self.plot_tune2d(self.egammaLayerRecalibTool('ps_HV1'), 'ps_HV1_2d_period3.png', run_number = 211670)
45  self.plot_tune2d(self.egammaLayerRecalibTool('ps_HV1'), 'ps_HV1_2d_period4.png', run_number = 212619)
46  self.plot_tune2d(self.egammaLayerRecalibTool('ps_HV1'), 'ps_HV1_2d_period5.png', run_number = 212809)
47 
48  self.plot_tune2d(self.egammaLayerRecalibTool('2012'), '2012_2d_period0.png', run_number = 204931)
49  self.plot_tune2d(self.egammaLayerRecalibTool('2012'), '2012_2d_period1.png', run_number = 204932)
50  self.plot_tune2d(self.egammaLayerRecalibTool('2012'), '2012_2d_period2.png', run_number = 205112)
51  self.plot_tune2d(self.egammaLayerRecalibTool('2012'), '2012_2d_period3.png', run_number = 211670)
52  self.plot_tune2d(self.egammaLayerRecalibTool('2012'), '2012_2d_period4.png', run_number = 212619)
53  self.plot_tune2d(self.egammaLayerRecalibTool('2012'), '2012_2d_period5.png', run_number = 212809)
54 
55  self.plot_tune2d(self.egammaLayerRecalibTool('2012'), '2012_2d.png')
56  self.plot_tune2d(self.egammaLayerRecalibTool('layer1_1'), 'layer1_1_2d.png')
57  self.plot_tune2d(self.egammaLayerRecalibTool('layer1_2'), 'layer1_2_2d.png')
58 
59  self.plot_tune2d(self.egammaLayerRecalibTool('2012_alt_with_layer2'), '2012_alt_with_layer2_2d.png')
60  self.plot_tune2d(self.egammaLayerRecalibTool('es2017_20.7_improved'), 'es2017_20.7_improved_2d.png')
61 
62  def plot_compare(self):
63  self.plot_tune((self.egammaLayerRecalibTool('es2017_20.7_final'),
64  self.egammaLayerRecalibTool('es2017_20.7_improved')),
65  'es2017_20.7_final__vs__es2017_20.7_improved.png',
66  ('es2017_20.7_final', 'es2017_20.7_improved'))
67 
68  def plot_tune(self, tools, canvas_name, names=None):
69  canvas = ROOT.TCanvas(canvas_name, canvas_name)
70  canvas.Divide(2, 2)
71  canvas.mem = []
72 
73  legend = None
74  if names:
75  legend = ROOT.TLegend(0.2, 0.6, 0.8, 0.8)
76 
77  if type(tools) is not tuple:
78  tools = (tools, )
79  legend_names = names or [""] * len(tools)
80 
81  for itool, (tool, name) in enumerate(zip(tools, legend_names)):
82 
83  h0 = ROOT.TGraph()
84  h1 = ROOT.TGraph()
85  h2 = ROOT.TGraph()
86  h3 = ROOT.TGraph()
87 
88  for i in range(100):
89  inputs = self.example_inputs()
90  inputs.RunNumber = 0
91  inputs.eta = i * 0.05 - 2.5
92  inputs.E0raw = 1
93  inputs.E1raw = 1
94  inputs.E2raw = 1
95  inputs.E3raw = 1
96 
97  tool.scale_inputs(inputs)
98 
99  h0.SetPoint(i, inputs.eta, inputs.E0raw)
100  h1.SetPoint(i, inputs.eta, inputs.E1raw)
101  h2.SetPoint(i, inputs.eta, inputs.E2raw)
102  h3.SetPoint(i, inputs.eta, inputs.E3raw)
103 
104  grs = (h0, h1, h2, h3)
105  for ig, g in enumerate(grs):
106  canvas.cd(ig + 1)
107  g.SetTitle('layer %d' % ig)
108  g.SetLineColor(itool + 1)
109  g.SetMarkerColor(itool + 1)
110  g.GetXaxis().SetTitle("#eta")
111  g.GetYaxis().SetTitle("(E_{%d})-corrected / (E_{%d})-non-corrected" % (ig, ig))
112  g.SetFillStyle(0)
113  g.GetYaxis().SetTitleOffset(1.5)
114  g.Draw("APL" if not itool else "PLsame")
115  g.GetYaxis().SetRangeUser(0.92, 1.08)
116  if ig == 3 and legend:
117  legend.AddEntry(g, name)
118  canvas.mem.append(g)
119  if legend:
120  canvas.cd(4)
121  legend.Draw()
122  canvas.SaveAs(canvas_name)
123  self.output_file.cd()
124  canvas.Write()
125 
126  def plot_tune2d(self, tool, canvas_name, run_number=0):
127  canvas = ROOT.TCanvas()
128  canvas.Divide(2, 2)
129  nbins_eta = 100
130  nbins_phi = 100
131  h0 = ROOT.TH2F("h0", "h0", nbins_eta, -2.5, 2.5, nbins_phi, -3.1415, 3.1415)
132  h1 = ROOT.TH2F("h1", "h1", nbins_eta, -2.5, 2.5, nbins_phi, -3.1415, 3.1415)
133  h2 = ROOT.TH2F("h2", "h2", nbins_eta, -2.5, 2.5, nbins_phi, -3.1415, 3.1415)
134  h3 = ROOT.TH2F("h3", "h3", nbins_eta, -2.5, 2.5, nbins_phi, -3.1415, 3.1415)
135 
136  for iphi in range(nbins_phi):
137  inputs = self.example_inputs()
138  inputs.RunNumber = run_number
139  for ieta in range(nbins_eta):
140  inputs.eta = h0.GetXaxis().GetBinCenter(ieta)
141  inputs.phi = h0.GetYaxis().GetBinCenter(iphi)
142  inputs.E0raw = 1.
143  inputs.E1raw = 1.
144  inputs.E2raw = 1.
145  inputs.E3raw = 1.
146 
147  tool.scale_inputs(inputs)
148 
149  h0.SetBinContent(ieta, iphi, inputs.E0raw)
150  h1.SetBinContent(ieta, iphi, inputs.E1raw)
151  h2.SetBinContent(ieta, iphi, inputs.E2raw)
152  h3.SetBinContent(ieta, iphi, inputs.E3raw)
153 
154  grs = (h0, h1, h2, h3)
155 
156  for i, g in enumerate(grs):
157  canvas.cd(i + 1)
158  g.GetXaxis().SetTitle("#eta")
159  g.GetYaxis().SetTitle("#phi")
160  g.SetTitle("(E_{%d})-corrected / E_{%d}-non-corrected" % (i, i))
161  g.SetContour(999)
162  g.GetZaxis().SetRangeUser(0.93,
163  1.07)
164 # g.GetZaxis().SetRangeUser(0.97, 1.03)
165 # g.GetZaxis().SetRangeUser(0.985, 1.0105) # mimic Guillaume ranges
166  g.SetStats(0)
167  g.Draw("colz")
168 
169  canvas.SaveAs(canvas_name)
170 
171 if __name__ == '__main__':
172  ROOT.gROOT.ProcessLine(".x $ROOTCOREDIR/scripts/load_packages.C")
173  ROOT.gStyle.SetCanvasDefH(800)
174  ROOT.gStyle.SetCanvasDefW(800)
175  ROOT.gStyle.SetPadTickX(1)
176  ROOT.gStyle.SetPadTickY(1)
177 
178  plotter = LayerPlotter()
179  plotter.plot()
180  plotter.plot2d()
181  plotter.plot_compare()
plot.LayerPlotter.output_file
output_file
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:10
plot.LayerPlotter.plot_tune
def plot_tune(self, tools, canvas_name, names=None)
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:68
plot.LayerPlotter.egammaLayerRecalibTool
egammaLayerRecalibTool
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:9
plot.LayerPlotter.plot2d
def plot2d(self)
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:40
plot.LayerPlotter.iscrack
def iscrack(self, eta)
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:12
plot.LayerPlotter.example_inputs
def example_inputs(self)
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:16
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
plot.LayerPlotter.__init__
def __init__(self)
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:8
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
calibdata.cd
cd
Definition: calibdata.py:51
plot.LayerPlotter.plot_tune2d
def plot_tune2d(self, tool, canvas_name, run_number=0)
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:126
plot.LayerPlotter
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:7
plot.LayerPlotter.plot_compare
def plot_compare(self)
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:62
plot.LayerPlotter.plot
def plot(self)
Definition: Reconstruction/egamma/egammaLayerRecalibTool/python/plot.py:26