ATLAS Offline Software
checkHVCorrections.py
Go to the documentation of this file.
1 #!/bin/env python
2 #
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 #
5 
6 from __future__ import print_function
7 
8 import ROOT
9 import os
10 
11 import PlotCalibrationGains
12 
13 import PlotCalibrationHV
14 
15 from optparse import OptionParser
16 
17 import numpy as np
18 import matplotlib.pyplot as plt
19 
20 plt.xkcd()
21 
22 if __name__ == "__main__":
23 
24  print ("Starting checkHVCorrections script")
25 
26  parser = OptionParser()
27 
28  parser.add_option("-f","--InputFile",action="store",type="string",dest="input_file_name",help="Name of input file")
29  (options, args) = parser.parse_args()
30 
31 
34  geometry_convertor.LoadReceiverPPMMap()
35 
36  ROOT.gStyle.SetPalette(1)
37  ROOT.gStyle.SetOptStat(111111)
38  ROOT.gStyle.SetCanvasColor(10)
39 
40  c1 = ROOT.TCanvas('c1','Example',200,10,700,500)
41  c2 = ROOT.TCanvas('c2','Example Partitions',200,10,700,500)
42  c2.Divide(3,2)
43 
44 # now define histograms
45 
46  h_gains_em = PlotCalibrationGains.L1CaloMap("Eta-phi map of EM gains","#eta bin","#phi bin")
47  h_gains_had = PlotCalibrationGains.L1CaloMap("Eta-phi map of HAD gains","#eta bin","#phi bin")
48 
49  h_gains_em_noHV = PlotCalibrationGains.L1CaloMap("Eta-phi map of EM gains without HV corrections","#eta bin","#phi bin")
50  h_gains_had_noHV = PlotCalibrationGains.L1CaloMap("Eta-phi map of HAD gains without HV corrections","#eta bin","#phi bin")
51 
52  h_gains_em_ratio = PlotCalibrationGains.L1CaloMap("ratio of EM gains with and without HV corrections","#eta bin","#phi bin")
53  h_gains_had_ratio = PlotCalibrationGains.L1CaloMap("ratio of HAD gains with and without HV corrections","#eta bin","#phi bin")
54 
55  h1D_gains_em_ratio = PlotCalibrationGains.EmPartitionPlots("ratio of EM gains with and without HV corrections",40,0.,2.5,"gain/gain(no HV)","N")
56  h1D_gains_had_ratio = PlotCalibrationGains.HadPartitionPlots("ratio of HAD gains with and without HV corrections",40,0.,2.5,"gain/gain(no HV)","N")
57 
58  h_corr_em = PlotCalibrationGains.L1CaloMap("Eta-phi map of mean HV corrections in EM layer","#eta bin","#phi bin")
59  h_corr_had = PlotCalibrationGains.L1CaloMap("Eta-phi map of mean HV corrections in HAD layer","#eta bin","#phi bin")
60 
61  h_corrGainPredictor_em = PlotCalibrationGains.L1CaloMap("Eta-phi map of HV corrections from Gain Predictor in EM layer","#eta bin","#phi bin")
62  h_corrGainPredictor_had = PlotCalibrationGains.L1CaloMap("Eta-phi map of HV corrections from Gain Predictor in HAD layer","#eta bin","#phi bin")
63 
64 
65  h1D_corr_em = PlotCalibrationGains.EmPartitionPlots("mean HV corrections in EM layer",40,0.,2.5,"mean HV correction","N")
66  h1D_corr_had = PlotCalibrationGains.HadPartitionPlots("mean HV corrections in HAD layer",40,0.,2.5,"mean HV correction","N")
67 
68  h_corrHVdiff_em = PlotCalibrationGains.L1CaloMap("(ratio-meanHV)/meanHV in EM layer","#eta bin","#phi bin")
69  h_corrHVdiff_had = PlotCalibrationGains.L1CaloMap("(ratio-meanHV)/meanHV in HAD layer","#eta bin","#phi bin")
70 
71  h1D_corrHVdiff_em = PlotCalibrationGains.EmPartitionPlots("(ratio-meanHV)/meanHV in EM layer",40,-0.1,0.1,"(ratio-meanHV)/meanHV","N")
72  h1D_corrHVdiff_had = PlotCalibrationGains.HadPartitionPlots("(ratio-meanHV)/meanHV in HAD layer",40,-0.1,0.1,"(ratio-meanHV)/meanHV","N")
73 
74  h_corrHVdiffGainPredictor_em = PlotCalibrationGains.L1CaloMap("(ratio-GainPredictor)/GainPredictor in EM layer","#eta bin","#phi bin")
75  h_corrHVdiffGainPredictor_had = PlotCalibrationGains.L1CaloMap("(ratio-GainPredictor)/GainPredictor in HAD layer","#eta bin","#phi bin")
76 
77 
78 # input files are define here
79 
80  fileDefault = '/afs/cern.ch/work/j/juraj/public/testarea/21.0.18/CalibrationProcessing/326189_HV/energyscanresults.sqlite'
81  fileNoHV = '/afs/cern.ch/work/j/juraj/public/testarea/21.0.18/CalibrationProcessing/326189/energyscanresults.sqlite'
82 
83  hvCorrFile = '/afs/cern.ch/work/j/juraj/public/testarea/20.7.8.3/HVDumps/hvcorrections_9jun17.sqlite'
84 
85  hvGainPredictor = '/afs/cern.ch/work/j/juraj/public/testarea/20.7.8.3/HVDumps/hvUpdate_9jun17_0p.txt'
86 
87  strategyString = 'GainOneOvEmecFcalLowEta' # defines receiver to TT mapping for EMB/EMEC overlap and hadronic FCAL
88 # strategyString = 'GainOneOvEmbFcalHighEta'
89 
90 
91  receiver_gains.LoadGainsSqlite(fileDefault)
92  receiver_gains.LoadReferenceSqlite(fileNoHV)
93 
94  hv_status = PlotCalibrationHV.L1CaloHVReader(hvCorrFile)
95 
96  strange_channel_file = open('checkHVCorrections.txt','w')
97 
98  gpReceiver,gpCool,gpEta,gpPhi,gpCorrection = np.genfromtxt(hvGainPredictor,unpack=True,dtype='str')
99 
100  gainPredictorCorrections = {}
101 
102  for iii in range(len(gpReceiver)):
103  gainPredictorCorrections[gpReceiver[iii]] = float(gpCorrection[iii])
104 
105  for i_eta in range(-49,45):
106  for i_phi in range(0,64):
107 
108  coolEm = geometry_convertor.getCoolEm(i_eta,i_phi)
109  coolHad = geometry_convertor.getCoolHad(i_eta,i_phi)
110 
111 
112  if not coolEm == '': # there is a channel for this eta-phi
113 
114  gain = receiver_gains.getGain(coolEm)
115  reference_gain = receiver_gains.getReferenceGain(coolEm)
116  receiverEm = geometry_convertor.getReceiverfromPPM(coolEm,strategyString)
117 
118  try:
119  meanEmHVCorrection = (hv_status.GetMeanCorections())[receiverEm]
120  except KeyError:
121  meanEmHVCorrection = 1.
122 
123  try:
124  gainPredictorEmHVCorrection = gainPredictorCorrections[receiverEm]
125  except KeyError:
126  gainPredictorEmHVCorrection = 1.
127 
128  if (not gain == '') and (not reference_gain == ''): # both gains should be available
129 
130  h_gains_em.Fill(i_eta,i_phi,gain)
131  h_gains_em_noHV.Fill(i_eta,i_phi,reference_gain)
132  h_corr_em.Fill(i_eta,i_phi,meanEmHVCorrection)
133  h_corrGainPredictor_em.Fill(i_eta,i_phi,gainPredictorEmHVCorrection)
134 
135  h1D_corr_em.Fill(i_eta,meanEmHVCorrection)
136  if reference_gain > 0.1 :
137  if gain/reference_gain > 0.01: # to make histo look nicer
138  h_gains_em_ratio.Fill(i_eta,i_phi,gain/reference_gain)
139  h1D_gains_em_ratio.Fill(i_eta,gain/reference_gain)
140 
141  if gainPredictorEmHVCorrection > 0.00001: # just to avoid division by zero, usually >=1.
142  relDifference = (gain/reference_gain - gainPredictorEmHVCorrection)/gainPredictorEmHVCorrection
143 
144  if relDifference > 0.001: # to make histo look nicer
145  h_corrHVdiffGainPredictor_em.Fill(i_eta,i_phi,relDifference)
146  if relDifference > 0.05: # print out interesting channels
147  strange_channel_file.write('%s %s %i %i EM corr(RampMaker)= %.4f corr(GainPredictor)= %.4f diff= %.4f \n' % (coolEm , receiverEm, \
148  i_eta , i_phi, gain/reference_gain,gainPredictorEmHVCorrection,relDifference) )
149 
150  if meanEmHVCorrection > 0.00001: # just to avoid division by zero, usually >=1.
151  relDifference = (gain/reference_gain - meanEmHVCorrection)/meanEmHVCorrection
152  if relDifference > 0.01: # to make histo look nicer
153  h_corrHVdiff_em.Fill(i_eta,i_phi,relDifference)
154 
155  h1D_corrHVdiff_em.Fill(i_eta,relDifference)
156 
157  if not coolHad == '': # there is a channel for this eta-phi
158 
159  gain = receiver_gains.getGain(coolHad)
160  reference_gain = receiver_gains.getReferenceGain(coolHad)
161  receiverHad = geometry_convertor.getReceiverfromPPM(coolHad,strategyString)
162 
163  try:
164  meanHadHVCorrection = (hv_status.GetMeanCorections())[receiverHad]
165  except KeyError:
166  meanHadHVCorrection = 1.
167 
168  try:
169  gainPredictorHadHVCorrection = gainPredictorCorrections[receiverHad]
170  except KeyError:
171  gainPredictorHadHVCorrection = 1.
172 
173 
174  if (not gain == '') and (not reference_gain == ''): # both gains should be available
175 
176  h_gains_had.Fill(i_eta,i_phi,gain)
177  h_gains_had_noHV.Fill(i_eta,i_phi,reference_gain)
178  h_corr_had.Fill(i_eta,i_phi,meanHadHVCorrection)
179  h_corrGainPredictor_had.Fill(i_eta,i_phi,gainPredictorHadHVCorrection)
180 
181  h1D_corr_had.Fill(i_eta,meanHadHVCorrection)
182 
183  if reference_gain > 0.1 :
184  if gain/reference_gain > 0.01: # to make histo look nicer
185  h_gains_had_ratio.Fill(i_eta,i_phi,gain/reference_gain)
186  h1D_gains_had_ratio.Fill(i_eta,gain/reference_gain)
187 
188  if gainPredictorHadHVCorrection > 0.00001: # to avoid accidental zeros
189  relDifference = (gain/reference_gain - gainPredictorHadHVCorrection)/gainPredictorHadHVCorrection
190  if relDifference > 0.001: # to make histo look nicer
191  h_corrHVdiffGainPredictor_had.Fill(i_eta,i_phi,relDifference)
192  if relDifference > 0.05: # print interesting channels
193  strange_channel_file.write('%s %s %i %i HAD corr(RampMaker)= %.4f corr(GainPredictor)= %.4f diff= %.4f \n' % (coolHad,receiverHad, \
194  i_eta , i_phi, gain/reference_gain,gainPredictorHadHVCorrection,relDifference) )
195 
196 
197  if meanHadHVCorrection > 0.00001:
198  relDifference = (gain/reference_gain - meanHadHVCorrection)/meanHadHVCorrection
199  if relDifference > 0.01: # to make histo look nicer
200  h_corrHVdiff_had.Fill(i_eta,i_phi,relDifference)
201  h1D_corrHVdiff_had.Fill(i_eta,relDifference)
202 
203 
204  c1.cd()
205  ROOT.gPad.SetLogy(0)
206 
207  h_gains_em.SetMinimum(0.6)
208  h_gains_em.SetMaximum(1.4)
209  h_gains_em.Draw()
210  c1.Print("checkHVCorrections.ps(")
211 
212  h_gains_had.SetMinimum(0.6)
213  h_gains_had.SetMaximum(1.4)
214  h_gains_had.Draw()
215  c1.Print("checkHVCorrections.ps")
216 
217  h_gains_em_noHV.SetMinimum(0.6)
218  h_gains_em_noHV.SetMaximum(1.4)
219  h_gains_em_noHV.Draw()
220  c1.Print("checkHVCorrections.ps")
221 
222  h_gains_had_noHV.SetMinimum(0.6)
223  h_gains_had_noHV.SetMaximum(1.4)
224  h_gains_had_noHV.Draw()
225  c1.Print("checkHVCorrections.ps")
226 
227  h_gains_em_ratio.SetMinimum(1.05)
228  h_gains_em_ratio.SetMaximum(2.2)
229  h_gains_em_ratio.Draw()
230  c1.Print("checkHVCorrections.ps")
231 
232  h_gains_had_ratio.SetMinimum(1.05)
233  h_gains_had_ratio.SetMaximum(2.2)
234  h_gains_had_ratio.Draw()
235  c1.Print("checkHVCorrections.ps")
236 
237  h_corr_em.SetMinimum(1.05)
238  h_corr_em.SetMaximum(2.2)
239  h_corr_em.Draw()
240  c1.Print("checkHVCorrections.ps")
241 
242  h_corr_had.SetMinimum(1.05)
243  h_corr_had.SetMaximum(2.2)
244  h_corr_had.Draw()
245  c1.Print("checkHVCorrections.ps")
246 
247  h_corrGainPredictor_em.SetMinimum(1.0)
248  h_corrGainPredictor_em.SetMaximum(2.1)
249  h_corrGainPredictor_em.Draw()
250  c1.Print("checkHVCorrections.ps")
251 
252  h_corrGainPredictor_had.SetMinimum(1.0)
253  h_corrGainPredictor_had.SetMaximum(2.1)
254  h_corrGainPredictor_had.Draw()
255  c1.Print("checkHVCorrections.ps")
256 
257 
258  h_corrHVdiff_em.SetMinimum(-.1)
259  h_corrHVdiff_em.SetMaximum( .1)
260  h_corrHVdiff_em.Draw()
261  c1.Print("checkHVCorrections.ps")
262 
263  h_corrHVdiff_had.SetMinimum(-.1)
264  h_corrHVdiff_had.SetMaximum( .1)
265  h_corrHVdiff_had.Draw()
266  c1.Print("checkHVCorrections.ps")
267 
268  h_corrHVdiffGainPredictor_em.SetMinimum(-.5)
269  h_corrHVdiffGainPredictor_em.SetMaximum( .5)
270  h_corrHVdiffGainPredictor_em.Draw()
271  c1.Print("checkHVCorrections.ps")
272 
273  h_corrHVdiffGainPredictor_had.SetMinimum(-.5)
274  h_corrHVdiffGainPredictor_had.SetMaximum( .5)
275  h_corrHVdiffGainPredictor_had.Draw()
276  c1.Print("checkHVCorrections.ps")
277 
278  h_corrHVdiffGainPredictor_em.SetMinimum(-.1)
279  h_corrHVdiffGainPredictor_em.SetMaximum( .1)
280  h_corrHVdiffGainPredictor_em.Draw()
281  c1.Print("checkHVCorrections.ps")
282 
283  h_corrHVdiffGainPredictor_had.SetMinimum(-.1)
284  h_corrHVdiffGainPredictor_had.SetMaximum( .1)
285  h_corrHVdiffGainPredictor_had.Draw()
286  c1.Print("checkHVCorrections.ps")
287 
288  h_corrHVdiffGainPredictor_em.SetMinimum(-.05)
289  h_corrHVdiffGainPredictor_em.SetMaximum( .05)
290  h_corrHVdiffGainPredictor_em.Draw()
291  c1.Print("checkHVCorrections.ps")
292 
293  h_corrHVdiffGainPredictor_had.SetMinimum(-.05)
294  h_corrHVdiffGainPredictor_had.SetMaximum( .05)
295  h_corrHVdiffGainPredictor_had.Draw()
296  c1.Print("checkHVCorrections.ps")
297 
298  c2.Clear()
299  c2.Divide(3,2)
300  for i_p in range(0,h1D_gains_em_ratio.nPartitions):
301  c2.cd(i_p+1)
302  if h1D_gains_em_ratio.his_partitions[i_p].GetEntries() > 0:
303  ROOT.gPad.SetLogy()
304  else:
305  ROOT.gPad.SetLogy(0)
306  h1D_gains_em_ratio.his_partitions[i_p].Draw()
307 
308  c2.Print("checkHVCorrections.ps")
309 
310  #c2.cd()
311  c2.Clear()
312  c2.Divide(3,2)
313  for i_p in range(0,h1D_gains_had_ratio.nPartitions):
314  c2.cd(i_p+1)
315  if h1D_gains_had_ratio.his_partitions[i_p].GetEntries() > 0:
316  ROOT.gPad.SetLogy()
317  else:
318  ROOT.gPad.SetLogy(0)
319  h1D_gains_had_ratio.his_partitions[i_p].Draw()
320 
321  c2.Print("checkHVCorrections.ps")
322 
323  c2.Clear()
324  c2.Divide(3,2)
325  for i_p in range(0,h1D_corr_em.nPartitions):
326  c2.cd(i_p+1)
327  if h1D_corr_em.his_partitions[i_p].GetEntries() > 0:
328  ROOT.gPad.SetLogy()
329  else:
330  ROOT.gPad.SetLogy(0)
331  h1D_corr_em.his_partitions[i_p].Draw()
332 
333  c2.Print("checkHVCorrections.ps")
334 
335  #c2.cd()
336  c2.Clear()
337  c2.Divide(3,2)
338  for i_p in range(0,h1D_corr_had.nPartitions):
339  c2.cd(i_p+1)
340  if h1D_corr_had.his_partitions[i_p].GetEntries() > 0:
341  ROOT.gPad.SetLogy()
342  else:
343  ROOT.gPad.SetLogy(0)
344  h1D_corr_had.his_partitions[i_p].Draw()
345 
346  c2.Print("checkHVCorrections.ps")
347  c2.Clear()
348  c2.Divide(3,2)
349  for i_p in range(0,h1D_corrHVdiff_em.nPartitions):
350  c2.cd(i_p+1)
351  if h1D_corrHVdiff_em.his_partitions[i_p].GetEntries() > 0:
352  ROOT.gPad.SetLogy()
353  else:
354  ROOT.gPad.SetLogy(0)
355  h1D_corrHVdiff_em.his_partitions[i_p].Draw()
356 
357  c2.Print("checkHVCorrections.ps")
358 
359  #c2.cd()
360  c2.Clear()
361  c2.Divide(3,2)
362  for i_p in range(0,h1D_corrHVdiff_had.nPartitions):
363  c2.cd(i_p+1)
364  if h1D_corrHVdiff_had.his_partitions[i_p].GetEntries() > 0:
365  ROOT.gPad.SetLogy()
366  else:
367  ROOT.gPad.SetLogy(0)
368  h1D_corrHVdiff_had.his_partitions[i_p].Draw()
369 
370  c2.Print("checkHVCorrections.ps)")
371 
372  os.system("ps2pdf checkHVCorrections.ps")
373 
374  strange_channel_file.close()
375 
PlotCalibrationHV.L1CaloHVReader
Definition: PlotCalibrationHV.py:120
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
PlotCalibrationGains.L1CaloGeometryConvertor
Definition: PlotCalibrationGains.py:59
PlotCalibrationGains.GainReader
Definition: PlotCalibrationGains.py:287
PlotCalibrationGains.EmPartitionPlots
Definition: PlotCalibrationGains.py:516
Trk::open
@ open
Definition: BinningType.h:40
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
PlotCalibrationGains.HadPartitionPlots
Definition: PlotCalibrationGains.py:565
readCCLHist.float
float
Definition: readCCLHist.py:83
PlotCalibrationGains.L1CaloMap
Definition: PlotCalibrationGains.py:15