ATLAS Offline Software
Loading...
Searching...
No Matches
PlotRamps.py
Go to the documentation of this file.
1# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3
4from ROOT import gROOT, gDirectory, gPad, gStyle, kYellow, kGray, TCanvas, TFile, TPaveLabel, TH1F
5from optparse import OptionParser
6
7
8def 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
14def getCrate( coolId ):
15 return (coolId & 0xf000000) >> 24
16
17def getModule( coolId ):
18 return (coolId & 0x00f0000) >> 16
19
20def getMcm( coolId ):
21 return (coolId & 0x0000f00) >> 8
22
23def getChannel( coolId ):
24 return (coolId & 0x000000f) >> 0
25
26def getLogicalChannel(mcm, chn):
27 return mcm*4+chn
28
29def getCoolId(crt,mod,mcm,chn):
30 id = 0 | (crt<<24) | (1<<20) | (mod<<16) | (mcm<<8) | (chn<<0)
31 return id
32
33def getCoolIdLog(crt,mod,logchn):
34 mcm = int( logchn/4 )
35 chn = logchn % 4
36 return getCoolId(crt,mod,mcm,chn)
37
38def PlotRamps(input_file_name=None):
39
40 if input_file_name is None:
41 print ("No input file name, assuming graphs.root")
42 input_file_name = "graphs.root"
43
44 gROOT.SetBatch( True )
45 gStyle.SetPalette(1)
46 gStyle.SetOptStat(111111)
47 gStyle.SetOptFit(11)
48 gStyle.SetCanvasColor(10)
49 gStyle.SetFrameFillColor(10)
50 gStyle.SetTitleFillColor(0)
51 gStyle.SetTitleBorderSize(1)
52 gStyle.SetStatBorderSize(1)
53 gStyle.SetStatFontSize(0.075)
54 gStyle.SetStatY(0.9)
55 gStyle.SetStatX(0.5)
56
57 gStyle.SetTitleFontSize(0.075)
58 gStyle.SetPaperSize(gStyle.kA4)
59
60 gStyle.SetPadTopMargin(0.10)
61 gStyle.SetPadBottomMargin(0.12)
62 gStyle.SetPadRightMargin(0.12)
63 gStyle.SetPadLeftMargin(0.12)
64 gStyle.SetHatchesSpacing(4.0)
65
66 canvas = TCanvas('canvas','Ramps',200,10,1000,750)
67 canvas.SetBatch( True )
68
69 graphs = TFile(input_file_name)
70 key_list = graphs.GetListOfKeys()
71
72 pdfFileName = 'rampPlots.pdf'
73 canvas.Print( pdfFileName + '[' )
74
75 # Book and style a template histogram to later draw the graph into
76 histo = TH1F("foo","foo",300,0.,300.)
77 histo.SetMinimum(0.)
78 histo.SetMaximum(300.)
79 histo.GetXaxis().SetTitle("L1Calo energy")
80 histo.GetYaxis().SetTitle("Calo energy")
81 histo.GetXaxis().SetTitleSize(0.04)
82 histo.GetYaxis().SetTitleSize(0.04)
83
84 # Initialise a 2D map to indicate present modules
85 modPresent = [ [ False for module in range(16) ] for crate in range(8) ]
86
87 # creates sorted list of numerical coolIds
88 list_of_histos=[]
89 for key in key_list:
90 keyStr = key.GetName()
91 keyInt = int(keyStr, base = 16)
92 list_of_histos.append( keyInt )
93 # Update list of present modules
94 modPresent[getCrate(keyInt)][getModule(keyInt)] = True
95
96 # loop over crates, modules, and channels
97 for ppCrt in range(8):
98 for ppMod in range(16):
99 # Check that this module is present
100 if not modPresent[ppCrt][ppMod]: continue
101
102 # Loop over 64 channels per module
103 for logChn in range(64):
104 coolId = getCoolIdLog( ppCrt, ppMod,logChn)
105 my_graph = gDirectory.Get(hex(coolId))
106
107 if ( logChn % 64 ) == 0: # new page
108 canvas.Clear()
109 canvas.cd()
110 gStyle.SetOptTitle(0)
111 gStyle.SetOptStat(0)
112 gPad.SetRightMargin(0.1)
113 gPad.SetLeftMargin(0.1)
114 gPad.SetTopMargin(0.0)
115 gPad.SetBottomMargin(0.1)
116
117 canvas.Divide(8,9,-1,-1)
118
119 title = "Crate %d PPM %d: L1Calo (x) vs Calo (y) Energies" % ( ppCrt, ppMod )
120 ltit = TPaveLabel(0.35,0.90,0.65,1.0,title)
121 ltit.SetTextAlign(22)
122 ltit.SetTextSize(0.40)
123 ltit.SetFillStyle(0)
124 ltit.SetBorderSize(0)
125 ltit.Draw()
126
127 canvas.cd( logChn + 9 )
128
129 # Draw template histogram and graph, if it exists
130 histo.Draw()
131
132 if ( my_graph ):
133 # Fetch function results
134 function_list = my_graph.GetListOfFunctions()
135 my_fit = function_list[0]
136 offset = my_fit.GetParameter(0)
137 slope = my_fit.GetParameter(1)
138 if not passesSelection(slope,offset):
139 gPad.SetFrameFillColor(kYellow-9)
140 #Style and draw graph
141 my_graph.SetMarkerStyle(34)
142 my_graph.SetMarkerSize(0.8)
143 my_fit.SetLineWidth(1)
144 my_fit.SetLineStyle(1)
145 my_graph.Draw("P")
146 else:
147 gPad.SetFrameFillColor(kGray)
148
149 # End of page, so print it
150 if ( logChn == 63 ):
151 canvas.Print( pdfFileName )
152
153 # closing file
154 canvas.Print( pdfFileName + ']' )
155 print ("Finished!")
156
157if __name__ == "__main__":
158
159 print ("Starting PlotRamps")
160
161 parser = OptionParser()
162 parser.add_option("-f","--InputFile",action="store",type="string",
163 dest="input_file_name",help="Name of input file")
164 (options, args) = parser.parse_args()
165
166 PlotRamps(options.input_file_name)
getLogicalChannel(mcm, chn)
Definition PlotRamps.py:26
getMcm(coolId)
Definition PlotRamps.py:20
getChannel(coolId)
Definition PlotRamps.py:23
getCoolId(crt, mod, mcm, chn)
Definition PlotRamps.py:29
getCoolIdLog(crt, mod, logchn)
Definition PlotRamps.py:33
getCrate(coolId)
Definition PlotRamps.py:14
getModule(coolId)
Definition PlotRamps.py:17
passesSelection(gain, offset)
Definition PlotRamps.py:8