6 from __future__
import print_function
11 import PlotCalibrationGains
13 import PlotCalibrationHV
15 from optparse
import OptionParser
18 import matplotlib.pyplot
as plt
22 if __name__ ==
"__main__":
24 print (
"Starting checkHVCorrections script")
26 parser = OptionParser()
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()
34 geometry_convertor.LoadReceiverPPMMap()
36 ROOT.gStyle.SetPalette(1)
37 ROOT.gStyle.SetOptStat(111111)
38 ROOT.gStyle.SetCanvasColor(10)
40 c1 = ROOT.TCanvas(
'c1',
'Example',200,10,700,500)
41 c2 = ROOT.TCanvas(
'c2',
'Example Partitions',200,10,700,500)
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'
83 hvCorrFile =
'/afs/cern.ch/work/j/juraj/public/testarea/20.7.8.3/HVDumps/hvcorrections_9jun17.sqlite'
85 hvGainPredictor =
'/afs/cern.ch/work/j/juraj/public/testarea/20.7.8.3/HVDumps/hvUpdate_9jun17_0p.txt'
87 strategyString =
'GainOneOvEmecFcalLowEta'
91 receiver_gains.LoadGainsSqlite(fileDefault)
92 receiver_gains.LoadReferenceSqlite(fileNoHV)
96 strange_channel_file =
open(
'checkHVCorrections.txt',
'w')
98 gpReceiver,gpCool,gpEta,gpPhi,gpCorrection = np.genfromtxt(hvGainPredictor,unpack=
True,dtype=
'str')
100 gainPredictorCorrections = {}
102 for iii
in range(len(gpReceiver)):
103 gainPredictorCorrections[gpReceiver[iii]] =
float(gpCorrection[iii])
105 for i_eta
in range(-49,45):
106 for i_phi
in range(0,64):
108 coolEm = geometry_convertor.getCoolEm(i_eta,i_phi)
109 coolHad = geometry_convertor.getCoolHad(i_eta,i_phi)
114 gain = receiver_gains.getGain(coolEm)
115 reference_gain = receiver_gains.getReferenceGain(coolEm)
116 receiverEm = geometry_convertor.getReceiverfromPPM(coolEm,strategyString)
119 meanEmHVCorrection = (hv_status.GetMeanCorections())[receiverEm]
121 meanEmHVCorrection = 1.
124 gainPredictorEmHVCorrection = gainPredictorCorrections[receiverEm]
126 gainPredictorEmHVCorrection = 1.
128 if (
not gain ==
'')
and (
not reference_gain ==
''):
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)
135 h1D_corr_em.Fill(i_eta,meanEmHVCorrection)
136 if reference_gain > 0.1 :
137 if gain/reference_gain > 0.01:
138 h_gains_em_ratio.Fill(i_eta,i_phi,gain/reference_gain)
139 h1D_gains_em_ratio.Fill(i_eta,gain/reference_gain)
141 if gainPredictorEmHVCorrection > 0.00001:
142 relDifference = (gain/reference_gain - gainPredictorEmHVCorrection)/gainPredictorEmHVCorrection
144 if relDifference > 0.001:
145 h_corrHVdiffGainPredictor_em.Fill(i_eta,i_phi,relDifference)
146 if relDifference > 0.05:
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) )
150 if meanEmHVCorrection > 0.00001:
151 relDifference = (gain/reference_gain - meanEmHVCorrection)/meanEmHVCorrection
152 if relDifference > 0.01:
153 h_corrHVdiff_em.Fill(i_eta,i_phi,relDifference)
155 h1D_corrHVdiff_em.Fill(i_eta,relDifference)
157 if not coolHad ==
'':
159 gain = receiver_gains.getGain(coolHad)
160 reference_gain = receiver_gains.getReferenceGain(coolHad)
161 receiverHad = geometry_convertor.getReceiverfromPPM(coolHad,strategyString)
164 meanHadHVCorrection = (hv_status.GetMeanCorections())[receiverHad]
166 meanHadHVCorrection = 1.
169 gainPredictorHadHVCorrection = gainPredictorCorrections[receiverHad]
171 gainPredictorHadHVCorrection = 1.
174 if (
not gain ==
'')
and (
not reference_gain ==
''):
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)
181 h1D_corr_had.Fill(i_eta,meanHadHVCorrection)
183 if reference_gain > 0.1 :
184 if gain/reference_gain > 0.01:
185 h_gains_had_ratio.Fill(i_eta,i_phi,gain/reference_gain)
186 h1D_gains_had_ratio.Fill(i_eta,gain/reference_gain)
188 if gainPredictorHadHVCorrection > 0.00001:
189 relDifference = (gain/reference_gain - gainPredictorHadHVCorrection)/gainPredictorHadHVCorrection
190 if relDifference > 0.001:
191 h_corrHVdiffGainPredictor_had.Fill(i_eta,i_phi,relDifference)
192 if relDifference > 0.05:
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) )
197 if meanHadHVCorrection > 0.00001:
198 relDifference = (gain/reference_gain - meanHadHVCorrection)/meanHadHVCorrection
199 if relDifference > 0.01:
200 h_corrHVdiff_had.Fill(i_eta,i_phi,relDifference)
201 h1D_corrHVdiff_had.Fill(i_eta,relDifference)
207 h_gains_em.SetMinimum(0.6)
208 h_gains_em.SetMaximum(1.4)
210 c1.Print(
"checkHVCorrections.ps(")
212 h_gains_had.SetMinimum(0.6)
213 h_gains_had.SetMaximum(1.4)
215 c1.Print(
"checkHVCorrections.ps")
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")
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")
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")
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")
237 h_corr_em.SetMinimum(1.05)
238 h_corr_em.SetMaximum(2.2)
240 c1.Print(
"checkHVCorrections.ps")
242 h_corr_had.SetMinimum(1.05)
243 h_corr_had.SetMaximum(2.2)
245 c1.Print(
"checkHVCorrections.ps")
247 h_corrGainPredictor_em.SetMinimum(1.0)
248 h_corrGainPredictor_em.SetMaximum(2.1)
249 h_corrGainPredictor_em.Draw()
250 c1.Print(
"checkHVCorrections.ps")
252 h_corrGainPredictor_had.SetMinimum(1.0)
253 h_corrGainPredictor_had.SetMaximum(2.1)
254 h_corrGainPredictor_had.Draw()
255 c1.Print(
"checkHVCorrections.ps")
258 h_corrHVdiff_em.SetMinimum(-.1)
259 h_corrHVdiff_em.SetMaximum( .1)
260 h_corrHVdiff_em.Draw()
261 c1.Print(
"checkHVCorrections.ps")
263 h_corrHVdiff_had.SetMinimum(-.1)
264 h_corrHVdiff_had.SetMaximum( .1)
265 h_corrHVdiff_had.Draw()
266 c1.Print(
"checkHVCorrections.ps")
268 h_corrHVdiffGainPredictor_em.SetMinimum(-.5)
269 h_corrHVdiffGainPredictor_em.SetMaximum( .5)
270 h_corrHVdiffGainPredictor_em.Draw()
271 c1.Print(
"checkHVCorrections.ps")
273 h_corrHVdiffGainPredictor_had.SetMinimum(-.5)
274 h_corrHVdiffGainPredictor_had.SetMaximum( .5)
275 h_corrHVdiffGainPredictor_had.Draw()
276 c1.Print(
"checkHVCorrections.ps")
278 h_corrHVdiffGainPredictor_em.SetMinimum(-.1)
279 h_corrHVdiffGainPredictor_em.SetMaximum( .1)
280 h_corrHVdiffGainPredictor_em.Draw()
281 c1.Print(
"checkHVCorrections.ps")
283 h_corrHVdiffGainPredictor_had.SetMinimum(-.1)
284 h_corrHVdiffGainPredictor_had.SetMaximum( .1)
285 h_corrHVdiffGainPredictor_had.Draw()
286 c1.Print(
"checkHVCorrections.ps")
288 h_corrHVdiffGainPredictor_em.SetMinimum(-.05)
289 h_corrHVdiffGainPredictor_em.SetMaximum( .05)
290 h_corrHVdiffGainPredictor_em.Draw()
291 c1.Print(
"checkHVCorrections.ps")
293 h_corrHVdiffGainPredictor_had.SetMinimum(-.05)
294 h_corrHVdiffGainPredictor_had.SetMaximum( .05)
295 h_corrHVdiffGainPredictor_had.Draw()
296 c1.Print(
"checkHVCorrections.ps")
300 for i_p
in range(0,h1D_gains_em_ratio.nPartitions):
302 if h1D_gains_em_ratio.his_partitions[i_p].
GetEntries() > 0:
306 h1D_gains_em_ratio.his_partitions[i_p].Draw()
308 c2.Print(
"checkHVCorrections.ps")
313 for i_p
in range(0,h1D_gains_had_ratio.nPartitions):
315 if h1D_gains_had_ratio.his_partitions[i_p].
GetEntries() > 0:
319 h1D_gains_had_ratio.his_partitions[i_p].Draw()
321 c2.Print(
"checkHVCorrections.ps")
325 for i_p
in range(0,h1D_corr_em.nPartitions):
327 if h1D_corr_em.his_partitions[i_p].
GetEntries() > 0:
331 h1D_corr_em.his_partitions[i_p].Draw()
333 c2.Print(
"checkHVCorrections.ps")
338 for i_p
in range(0,h1D_corr_had.nPartitions):
340 if h1D_corr_had.his_partitions[i_p].
GetEntries() > 0:
344 h1D_corr_had.his_partitions[i_p].Draw()
346 c2.Print(
"checkHVCorrections.ps")
349 for i_p
in range(0,h1D_corrHVdiff_em.nPartitions):
351 if h1D_corrHVdiff_em.his_partitions[i_p].
GetEntries() > 0:
355 h1D_corrHVdiff_em.his_partitions[i_p].Draw()
357 c2.Print(
"checkHVCorrections.ps")
362 for i_p
in range(0,h1D_corrHVdiff_had.nPartitions):
364 if h1D_corrHVdiff_had.his_partitions[i_p].
GetEntries() > 0:
368 h1D_corrHVdiff_had.his_partitions[i_p].Draw()
370 c2.Print(
"checkHVCorrections.ps)")
372 os.system(
"ps2pdf checkHVCorrections.ps")
374 strange_channel_file.close()