ATLAS Offline Software
PlotRamps.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 from __future__ import print_function
4 
5 from ROOT import gDirectory, gPad, gStyle, kYellow, TCanvas, TFile, TPaveLabel
6 from optparse import OptionParser
7 
8 def passesSelection(gain,offset):
9  if ((gain > 0.5 and gain <1.6) and (offset > -10 and offset < 10)):
10  return True
11  else:
12  return False
13 
14 
15 def PlotRamps(input_file_name=None):
16 
17  if input_file_name is None:
18  print ("No input file name, assuming graphs.root")
19  input_file_name = "graphs.root"
20 
21  gStyle.SetPalette(1)
22  gStyle.SetOptStat(111111)
23  gStyle.SetOptFit(11)
24  gStyle.SetCanvasColor(10)
25  gStyle.SetFrameFillColor(10)
26  gStyle.SetTitleFillColor(0)
27  gStyle.SetTitleBorderSize(1)
28  gStyle.SetStatBorderSize(1)
29  gStyle.SetStatFontSize(0.075)
30  gStyle.SetStatY(0.6)
31  gStyle.SetStatX(1.)
32 
33  gStyle.SetTitleFontSize(0.075)
34 
35  gStyle.SetPadTopMargin(0.10)
36  gStyle.SetPadBottomMargin(0.12)
37  gStyle.SetPadRightMargin(0.12)
38  gStyle.SetPadLeftMargin(0.12)
39  gStyle.SetHatchesSpacing(4.0)
40 
41  c1 = TCanvas('c1','Example',200,10,700,500)
42  c1.Divide(8,9)
43 
44  graphs = TFile(input_file_name)
45  key_list = graphs.GetListOfKeys()
46 
47  nPlot = 0
48  nPage = 0
49 
50  c1.Print("rampPlots.pdf(")
51 
52  list_of_histos=[]
53 
54  for iii in key_list:
55  list_of_histos.append(iii.GetName())
56 
57 # list_of_histos.sort()
58 
59  list_of_histos_dec=[int(iii,base = 16) for iii in list_of_histos]
60  list_of_histos_dec.sort()
61  list_of_histos = [hex(iii) for iii in list_of_histos_dec]
62 
63 # for iii in list_of_histos:
64 # print (iii)
65 
66  page_ppm = list_of_histos[0][:-4]
67 
68  for my_name in list_of_histos:
69 
70  my_graph = gDirectory.Get(my_name)
71  graph_ppm = my_name[:-4]
72 
73  if (nPlot % 64) == 0 or (not graph_ppm == page_ppm): # end of page
74  if (nPage==0) and (nPlot==0):
75  print ("start plotting")
76  else:
77  c1.cd(0)
78  ppm_number=page_ppm[-1]
79  ppm_crate =page_ppm[2:-2]
80  if len(ppm_crate) == 0:
81  ppm_crate='0'
82  title = "PP " + ppm_crate + " PPM " + ppm_number
83  ltit = TPaveLabel(0.35,0.90,0.65,1.0,title)
84  ltit.SetTextAlign(22)
85  ltit.SetTextSize(0.70)
86  ltit.SetFillStyle(0)
87  ltit.SetBorderSize(0)
88  ltit.Draw()
89 
90 # print (title, " ", ppm_crate, " ", ppm_number )
91  c1.Print("rampPlots.pdf")
92  c1.Clear()
93  c1.Divide(8,9)
94  nPage = nPage+1
95  page_ppm = graph_ppm
96  nPlot=0
97 
98  c1.cd(nPlot % 64 +1+8)
99  my_graph.SetMarkerStyle(21)
100  my_graph.SetMarkerSize(0.75)
101  my_graph.SetLineWidth(1)
102 
103  my_graph.GetYaxis().SetRangeUser(0.,my_graph.GetXaxis().GetXmax())
104 
105  my_graph.GetXaxis().SetTitleSize(0.04)
106  my_graph.GetYaxis().SetTitleSize(0.04)
107  my_graph.GetXaxis().SetTitleOffset(1.5)
108  my_graph.GetYaxis().SetTitleOffset(1.5)
109 # my_graph.GetXaxis().SetLabelSize(0.03)
110 # my_graph.GetYaxis().SetLabelSize(0.03)
111  my_graph.GetXaxis().SetLabelSize(0.04)
112  my_graph.GetYaxis().SetLabelSize(0.04)
113 
114  my_graph.GetXaxis().SetLabelOffset(0.04)
115  my_graph.GetYaxis().SetLabelOffset(0.015)
116  my_graph.GetXaxis().SetTitle("L1Calo energies")
117  my_graph.GetYaxis().SetTitle("Calo energies")
118 
119  function_list = my_graph.GetListOfFunctions()
120  offset = function_list[0].GetParameter(0)
121  slope = function_list[0].GetParameter(1)
122  if not passesSelection(slope,offset):
123  gPad.SetFrameFillColor(kYellow)
124 
125  my_graph.Draw("APL")
126  nPlot = nPlot+1
127 
128 
129  c1.cd(0)
130  ppm_number=page_ppm[-1]
131  ppm_crate =page_ppm[2:-2]
132  if len(ppm_crate) == 0:
133  ppm_crate='0'
134  title = "PP " + ppm_crate + " PPM " + ppm_number
135  ltit = TPaveLabel(0.35,0.90,0.65,1.0,title)
136  ltit.SetTextAlign(22)
137  ltit.SetTextSize(0.70)
138  ltit.SetFillStyle(0)
139  ltit.SetBorderSize(0)
140  ltit.Draw()
141 
142  c1.Print("rampPlots.pdf")
143 
144  c1.Print("rampPlots.pdf)")
145  print ("Finished!")
146 
147 if __name__ == "__main__":
148 
149  print ("Starting PlotRamps")
150 
151  parser = OptionParser()
152  parser.add_option("-f","--InputFile",action="store",type="string",dest="input_file_name",help="Name of input file")
153  (options, args) = parser.parse_args()
154 
155  PlotRamps(options.input_file_name)
PlotRamps
Definition: PlotRamps.py:1
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
PlotRamps.PlotRamps
def PlotRamps(input_file_name=None)
Definition: PlotRamps.py:15
PlotRamps.passesSelection
def passesSelection(gain, offset)
Definition: PlotRamps.py:8