11 from PyCool
import cool
12 from optparse
import OptionParser
14 from PlotCalibrationGains
import L1CaloMap, L1CaloGeometryConvertor
21 if layerName == 0
or layerName == 4:
38 if layerName == 1
or layerName == 5:
52 if layerName == 2
or layerName == 6
or layerName == 21:
67 if layerName == 3
or layerName == 7:
78 if isOverlap
and layerName == 6:
88 if layerName == 8
or (layerName == 22
and TT_part ==
'EmecFcalLowEta'):
97 if layerName == 9
or (layerName == 22
and TT_part ==
'EmbFcalHighEta'):
106 if layerName == 10
or (layerName == 23
and TT_part ==
'EmecFcalLowEta'):
115 if layerName == 11
or (layerName == 23
and TT_part ==
'EmbFcalHighEta'):
157 dbSvc = cool.DatabaseSvcFactory.databaseService()
159 dbString=
'sqlite://;schema='+file_name+
';dbname=L1CALO'
161 db = dbSvc.openDatabase(dbString,
False)
162 except Exception
as e:
163 print((
'Error: Problem opening database', e))
166 folder_name =
'/TRIGGER/L1Calo/V1/Results/HVCorrections'
167 folder=db.getFolder(folder_name)
169 startUtime =
int(time.time())
170 endUtime =
int(time.time())
171 startValKey = startUtime * self.
UNIX2COOL
173 chsel = cool.ChannelSelection(0,sys.maxsize)
176 itr=folder.browseObjects(startValKey, endValKey, chsel)
177 except Exception
as e:
182 CoolId = hex(
int(row.channelId()))
183 payload = row.payload()
185 self.
MeanCorr[CoolId] = payload[
'RxMean']
187 self.
CorrLayer1[CoolId] = payload[
'LayerMean1']
188 self.
CorrLayer2[CoolId] = payload[
'LayerMean2']
189 self.
CorrLayer3[CoolId] = payload[
'LayerMean3']
190 self.
CorrLayer4[CoolId] = payload[
'LayerMean4']
206 dbSvc = cool.DatabaseSvcFactory.databaseService()
208 dbString=
'sqlite://;schema='+file_name+
';dbname=L1CALO'
210 db = dbSvc.openDatabase(dbString,
False)
211 except Exception
as e:
212 print((
'Error: Problem opening database', e))
215 folder_name =
'/TRIGGER/L1Calo/V1/Results/RxLayers'
216 folder=db.getFolder(folder_name)
218 startUtime =
int(time.time())
219 endUtime =
int(time.time())
220 startValKey = startUtime * self.
UNIX2COOL
222 chsel = cool.ChannelSelection(0,sys.maxsize)
225 itr=folder.browseObjects(startValKey, endValKey, chsel)
226 except Exception
as e:
231 CoolId = hex(
int(row.channelId()))
232 payload = row.payload()
234 self.
NCells1[CoolId] = struct.unpack(
'B'.
encode(
'utf-8'),payload[
'NCells1'].
encode(
'utf-8'))[0]
235 self.
NCells2[CoolId] = struct.unpack(
'B'.
encode(
'utf-8'),payload[
'NCells2'].
encode(
'utf-8'))[0]
236 self.
NCells3[CoolId] = struct.unpack(
'B'.
encode(
'utf-8'),payload[
'NCells3'].
encode(
'utf-8'))[0]
237 self.
NCells4[CoolId] = struct.unpack(
'B'.
encode(
'utf-8'),payload[
'NCells4'].
encode(
'utf-8'))[0]
239 self.
NLayers[CoolId] = struct.unpack(
'B'.
encode(
'utf-8'),payload[
'NLayers'].
encode(
'utf-8'))[0]
241 self.
Name1[CoolId] = struct.unpack(
'B'.
encode(
'utf-8'),payload[
'Name1'].
encode(
'utf-8'))[0]
242 self.
Name2[CoolId] = struct.unpack(
'B'.
encode(
'utf-8'),payload[
'Name2'].
encode(
'utf-8'))[0]
243 self.
Name3[CoolId] = struct.unpack(
'B'.
encode(
'utf-8'),payload[
'Name3'].
encode(
'utf-8'))[0]
244 self.
Name4[CoolId] = struct.unpack(
'B'.
encode(
'utf-8'),payload[
'Name4'].
encode(
'utf-8'))[0]
313 ROOT.gStyle.SetPalette(1)
314 ROOT.gStyle.SetOptStat(111111)
315 ROOT.gStyle.SetCanvasColor(10)
317 c1 = ROOT.TCanvas(
'c1',
'Example',200,10,700,500)
319 h_MeanCorrEmecFcalLowEta_em =
L1CaloMap(
"Mean HV corrections for EM (EMEC in overlap) ",
"#eta bin",
"#phi bin")
320 h_MeanCorrEmecFcalLowEta_had =
L1CaloMap(
"Mean HV corrections for HAD (FCAL low #eta)",
"#eta bin",
"#phi bin")
322 h_MeanCorrEmbFcalHighEta_em =
L1CaloMap(
"Mean HV corrections for EM overlap (EMB)",
"#eta bin",
"#phi bin")
323 h_MeanCorrEmbFcalHighEta_had =
L1CaloMap(
"Mean HV corrections for HAD FCAL (high #eta)",
"#eta bin",
"#phi bin")
326 h_LayerCorr_presampler =
L1CaloMap(
"HV corrections for EM presampler ",
"#eta bin",
"#phi bin")
327 h_CellFraction_presampler =
L1CaloMap(
"Fraction of HV affected cells in EM presampler",
"#eta bin",
"#phi bin")
328 h_LayerCorr_em_front =
L1CaloMap(
"HV corrections for EM front layer ",
"#eta bin",
"#phi bin")
329 h_CellFraction_em_front =
L1CaloMap(
"Fraction of HV affected cells in EM front layer",
"#eta bin",
"#phi bin")
330 h_LayerCorr_em_middle =
L1CaloMap(
"HV corrections for EM middle layer ",
"#eta bin",
"#phi bin")
331 h_CellFraction_em_middle =
L1CaloMap(
"Fraction of HV affected cells in EM middle layer",
"#eta bin",
"#phi bin")
332 h_LayerCorr_em_back =
L1CaloMap(
"HV corrections for EM back layer",
"#eta bin",
"#phi bin")
333 h_CellFraction_em_back =
L1CaloMap(
"Fraction of HV affected cells in EM back layer",
"#eta bin",
"#phi bin")
335 h_LayerCorr_em_overlap_back =
L1CaloMap(
"HV corrections for EM overlap back layer",
"#eta bin",
"#phi bin")
336 h_CellFraction_em_overlap_back =
L1CaloMap(
"Fraction of HV affected cells in EM overlap back layer",
"#eta bin",
"#phi bin")
338 h_LayerCorr_had_first =
L1CaloMap(
"HV corrections for first HAD layer (low #eta FCAL2)",
"#eta bin",
"#phi bin")
339 h_CellFraction_had_first =
L1CaloMap(
"Fraction of HV affected cells in first HAD layer (low #eta FCAL2)",
"#eta bin",
"#phi bin")
340 h_LayerCorr_had_second =
L1CaloMap(
"HV corrections for second HAD layer (high #eta FCAL2)",
"#eta bin",
"#phi bin")
341 h_CellFraction_had_second =
L1CaloMap(
"Fraction of HV affected cells in second HAD layer (high #eta FCAL2)",
"#eta bin",
"#phi bin")
342 h_LayerCorr_had_third =
L1CaloMap(
"HV corrections for third HAD layer (low #eta FCAL3)",
"#eta bin",
"#phi bin")
343 h_CellFraction_had_third =
L1CaloMap(
"Fraction of HV affected cells in third HAD layer (low #eta FCAL3)",
"#eta bin",
"#phi bin")
344 h_LayerCorr_had_fourth =
L1CaloMap(
"HV corrections for fourth HAD layer (high #eta FCAL3)",
"#eta bin",
"#phi bin")
345 h_CellFraction_had_fourth =
L1CaloMap(
"Fraction of HV affected cells in fourth HAD layer (high #eta FCAL3)",
"#eta bin",
"#phi bin")
350 geometry_convertor.LoadReceiverPPMMap()
353 input_file = input_file_name
354 print((
"Taking HV information from file",input_file ))
358 large_hv_file =
open(
'large_hv_corr.txt',
'w')
360 for ReceiverId
in list(hv_status.GetMeanCorections().
keys()):
362 MeanHVCorrection = (hv_status.GetMeanCorections())[ReceiverId]
363 CorrLayers = [0,0,0,0]
364 CorrLayers[0] = (hv_status.GetCorLayer1())[ReceiverId]
365 CorrLayers[1] = (hv_status.GetCorLayer2())[ReceiverId]
366 CorrLayers[2] = (hv_status.GetCorLayer3())[ReceiverId]
367 CorrLayers[3] = (hv_status.GetCorLayer4())[ReceiverId]
369 NLayers = (hv_status.GetNLayers())[ReceiverId]
371 AffectedCells = [0,0,0,0]
372 AffectedCells[0] = (hv_status.GetAffectedCells1())[ReceiverId]
373 AffectedCells[1] = (hv_status.GetAffectedCells2())[ReceiverId]
374 AffectedCells[2] = (hv_status.GetAffectedCells3())[ReceiverId]
375 AffectedCells[3] = (hv_status.GetAffectedCells4())[ReceiverId]
378 NCells[0] = (hv_status.GetNCells1())[ReceiverId]
379 NCells[1] = (hv_status.GetNCells2())[ReceiverId]
380 NCells[2] = (hv_status.GetNCells3())[ReceiverId]
381 NCells[3] = (hv_status.GetNCells4())[ReceiverId]
383 LayerName = [0,0,0,0]
384 LayerName[0] = (hv_status.GetName1())[ReceiverId]
385 LayerName[1] = (hv_status.GetName2())[ReceiverId]
386 LayerName[2] = (hv_status.GetName3())[ReceiverId]
387 LayerName[3] = (hv_status.GetName4())[ReceiverId]
389 PPM_ID = geometry_convertor.getPPMfromReceiver(ReceiverId)
390 eta_bin = geometry_convertor.getEtaBin(PPM_ID)
391 phi_bin = geometry_convertor.getPhiBin(PPM_ID)
393 TT_part =
'EmecFcalLowEta'
394 if geometry_convertor.isPPMFCAL(PPM_ID)
and geometry_convertor.getFCAL23RecEta(ReceiverId)==
'HighEta':
395 TT_part =
'EmbFcalHighEta'
396 if geometry_convertor.isPPMOverlap(PPM_ID)
and geometry_convertor.getOverlapLayer(ReceiverId)==
'EMB':
397 TT_part =
'EmbFcalHighEta'
407 if MeanHVCorrection > HVCutAverage
and TT_part ==
'EmecFcalLowEta':
408 if geometry_convertor.isCoolEm(PPM_ID):
409 h_MeanCorrEmecFcalLowEta_em.Fill(eta_bin,phi_bin,MeanHVCorrection)
410 large_hv_file.write(
"%3i %3i EM %12s Rx=%7s %.3f (%.3f %.3f %.3f %.3f) \n" % (eta_bin,phi_bin,PPM_ID,ReceiverId,MeanHVCorrection,CorrLayers[0],CorrLayers[1],CorrLayers[2],CorrLayers[3]))
412 if geometry_convertor.isCoolHad(PPM_ID):
413 h_MeanCorrEmecFcalLowEta_had.Fill(eta_bin,phi_bin,MeanHVCorrection)
414 large_hv_file.write(
"%3i %3i HAD %12s Rx=%7s %.3f (%.3f %.3f %.3f %.3f) \n" % (eta_bin,phi_bin,PPM_ID,ReceiverId,MeanHVCorrection,CorrLayers[0],CorrLayers[1],CorrLayers[2],CorrLayers[3]))
416 if MeanHVCorrection > HVCutAverage
and TT_part ==
'EmbFcalHighEta':
417 if geometry_convertor.isCoolEm(PPM_ID):
418 h_MeanCorrEmbFcalHighEta_em.Fill(eta_bin,phi_bin,MeanHVCorrection)
419 large_hv_file.write(
"%3i %3i EM %12s Rx=%7s %.3f (%.3f %.3f %.3f %.3f) \n" % (eta_bin,phi_bin,PPM_ID,ReceiverId,MeanHVCorrection,CorrLayers[0],CorrLayers[1],CorrLayers[2],CorrLayers[3]))
421 if geometry_convertor.isCoolHad(PPM_ID):
422 h_MeanCorrEmbFcalHighEta_had.Fill(eta_bin,phi_bin,MeanHVCorrection)
423 large_hv_file.write(
"%3i %3i HAD %12s Rx=%7s %.3f (%.3f %.3f %.3f %.3f) \n" % (eta_bin,phi_bin,PPM_ID,ReceiverId,MeanHVCorrection,CorrLayers[0],CorrLayers[1],CorrLayers[2],CorrLayers[3]))
427 for ilayer
in range(NLayers):
432 if CorrLayers[ilayer] > HVCutLayers:
433 h_LayerCorr_presampler.Fill(eta_bin,phi_bin,CorrLayers[ilayer])
434 h_CellFraction_presampler.Fill(eta_bin,phi_bin,
float(AffectedCells[ilayer])/
float(NCells[ilayer]))
436 if isEmFront(LayerName[ilayer],geometry_convertor.isPPMOverlap(PPM_ID)):
437 if CorrLayers[ilayer] > HVCutLayers:
438 h_LayerCorr_em_front.Fill(eta_bin,phi_bin,CorrLayers[ilayer])
439 h_CellFraction_em_front.Fill(eta_bin,phi_bin,
float(AffectedCells[ilayer])/
float(NCells[ilayer]))
441 if isEmMiddle(LayerName[ilayer],geometry_convertor.isPPMOverlap(PPM_ID)):
442 if CorrLayers[ilayer] > HVCutLayers:
443 h_LayerCorr_em_middle.Fill(eta_bin,phi_bin,CorrLayers[ilayer])
444 h_CellFraction_em_middle.Fill(eta_bin,phi_bin,
float(AffectedCells[ilayer])/
float(NCells[ilayer]))
446 if isEmBack(LayerName[ilayer],geometry_convertor.isPPMOverlap(PPM_ID)):
447 if CorrLayers[ilayer] > HVCutLayers:
448 h_LayerCorr_em_back.Fill(eta_bin,phi_bin,CorrLayers[ilayer])
449 h_CellFraction_em_back.Fill(eta_bin,phi_bin,
float(AffectedCells[ilayer])/
float(NCells[ilayer]))
451 if isEmOverlapBack(LayerName[ilayer],geometry_convertor.isPPMOverlap(PPM_ID)):
452 if CorrLayers[ilayer] > HVCutLayers:
453 h_LayerCorr_em_overlap_back.Fill(eta_bin,phi_bin,CorrLayers[ilayer])
454 h_CellFraction_em_overlap_back.Fill(eta_bin,phi_bin,
float(AffectedCells[ilayer])/
float(NCells[ilayer]))
459 if CorrLayers[ilayer] > HVCutLayers:
460 h_LayerCorr_had_first.Fill(eta_bin,phi_bin,CorrLayers[ilayer])
461 h_CellFraction_had_first.Fill(eta_bin,phi_bin,
float(AffectedCells[ilayer])/
float(NCells[ilayer]))
464 if CorrLayers[ilayer] > HVCutLayers:
465 h_LayerCorr_had_second.Fill(eta_bin,phi_bin,CorrLayers[ilayer])
466 h_CellFraction_had_second.Fill(eta_bin,phi_bin,
float(AffectedCells[ilayer])/
float(NCells[ilayer]))
469 if CorrLayers[ilayer] > HVCutLayers:
470 h_LayerCorr_had_third.Fill(eta_bin,phi_bin,CorrLayers[ilayer])
471 h_CellFraction_had_third.Fill(eta_bin,phi_bin,
float(AffectedCells[ilayer])/
float(NCells[ilayer]))
474 if CorrLayers[ilayer] > HVCutLayers:
475 h_LayerCorr_had_fourth.Fill(eta_bin,phi_bin,CorrLayers[ilayer])
476 h_CellFraction_had_fourth.Fill(eta_bin,phi_bin,
float(AffectedCells[ilayer])/
float(NCells[ilayer]))
479 large_hv_file.close()
483 h_MeanCorrEmecFcalLowEta_em.SetMinimum(1.)
484 h_MeanCorrEmecFcalLowEta_em.SetMaximum(2.1)
485 h_MeanCorrEmecFcalLowEta_em.Draw()
486 c1.Print(
"HVStatus.ps(")
488 h_MeanCorrEmecFcalLowEta_had.SetMinimum(1.)
489 h_MeanCorrEmecFcalLowEta_had.SetMaximum(2.1)
490 h_MeanCorrEmecFcalLowEta_had.Draw()
491 c1.Print(
"HVStatus.ps")
494 h_MeanCorrEmbFcalHighEta_em.SetMinimum(1.)
495 h_MeanCorrEmbFcalHighEta_em.SetMaximum(2.1)
496 h_MeanCorrEmbFcalHighEta_em.Draw()
497 c1.Print(
"HVStatus.ps")
499 h_MeanCorrEmbFcalHighEta_had.SetMinimum(1.)
500 h_MeanCorrEmbFcalHighEta_had.SetMaximum(2.1)
501 h_MeanCorrEmbFcalHighEta_had.Draw()
502 c1.Print(
"HVStatus.ps")
507 h_LayerCorr_presampler.SetMinimum(1.)
508 h_LayerCorr_presampler.SetMaximum(2.1)
509 h_LayerCorr_presampler.Draw()
510 c1.Print(
"HVStatus.ps")
512 h_CellFraction_presampler.SetMinimum(0.)
513 h_CellFraction_presampler.SetMaximum(1.1)
514 h_CellFraction_presampler .Draw()
515 c1.Print(
"HVStatus.ps")
517 h_LayerCorr_em_front.SetMinimum(1.)
518 h_LayerCorr_em_front.SetMaximum(2.1)
519 h_LayerCorr_em_front.Draw()
520 c1.Print(
"HVStatus.ps")
522 h_CellFraction_em_front.SetMinimum(0.)
523 h_CellFraction_em_front.SetMaximum(1.1)
524 h_CellFraction_em_front.Draw()
525 c1.Print(
"HVStatus.ps")
527 h_LayerCorr_em_middle.SetMinimum(1.)
528 h_LayerCorr_em_middle.SetMaximum(2.1)
529 h_LayerCorr_em_middle.Draw()
530 c1.Print(
"HVStatus.ps")
532 h_CellFraction_em_middle.SetMinimum(0.)
533 h_CellFraction_em_middle.SetMaximum(1.1)
534 h_CellFraction_em_middle.Draw()
535 c1.Print(
"HVStatus.ps")
537 h_LayerCorr_em_back.SetMinimum(1.)
538 h_LayerCorr_em_back.SetMaximum(2.1)
539 h_LayerCorr_em_back.Draw()
540 c1.Print(
"HVStatus.ps")
542 h_CellFraction_em_back.SetMinimum(0.)
543 h_CellFraction_em_back.SetMaximum(1.1)
544 h_CellFraction_em_back.Draw()
545 c1.Print(
"HVStatus.ps")
547 h_LayerCorr_em_overlap_back.SetMinimum(1.)
548 h_LayerCorr_em_overlap_back.SetMaximum(2.1)
549 h_LayerCorr_em_overlap_back.Draw()
550 c1.Print(
"HVStatus.ps")
552 h_CellFraction_em_overlap_back.SetMinimum(0.)
553 h_CellFraction_em_overlap_back.SetMaximum(1.1)
554 h_CellFraction_em_overlap_back.Draw()
555 c1.Print(
"HVStatus.ps")
558 h_LayerCorr_had_first.SetMinimum(1.)
559 h_LayerCorr_had_first.SetMaximum(2.1)
560 h_LayerCorr_had_first.Draw()
561 c1.Print(
"HVStatus.ps")
563 h_CellFraction_had_first.SetMinimum(0.)
564 h_CellFraction_had_first.SetMaximum(1.1)
565 h_CellFraction_had_first.Draw()
566 c1.Print(
"HVStatus.ps")
568 h_LayerCorr_had_second.SetMinimum(1.)
569 h_LayerCorr_had_second.SetMaximum(2.1)
570 h_LayerCorr_had_second.Draw()
571 c1.Print(
"HVStatus.ps")
573 h_CellFraction_had_second.SetMinimum(0.)
574 h_CellFraction_had_second.SetMaximum(1.1)
575 h_CellFraction_had_second.Draw()
576 c1.Print(
"HVStatus.ps")
578 h_LayerCorr_had_third.SetMinimum(1.)
579 h_LayerCorr_had_third.SetMaximum(2.1)
580 h_LayerCorr_had_third.Draw()
581 c1.Print(
"HVStatus.ps")
583 h_CellFraction_had_third.SetMinimum(0.)
584 h_CellFraction_had_third.SetMaximum(1.1)
585 h_CellFraction_had_third.Draw()
586 c1.Print(
"HVStatus.ps")
588 h_LayerCorr_had_fourth.SetMinimum(1.)
589 h_LayerCorr_had_fourth .SetMaximum(2.1)
590 h_LayerCorr_had_fourth.Draw()
591 c1.Print(
"HVStatus.ps")
593 h_CellFraction_had_fourth.SetMinimum(0.)
594 h_CellFraction_had_fourth.SetMaximum(1.1)
595 h_CellFraction_had_fourth.Draw()
596 c1.Print(
"HVStatus.ps)")
599 os.system(
"ps2pdf HVStatus.ps")
605 if __name__ ==
"__main__":
607 print (
"Starting PlotCalibrationHV")
609 parser = OptionParser()
611 parser.add_option(
"-f",
"--InputFile",action=
"store",type=
"string",dest=
"input_file_name",help=
"Name of input file")
613 (options, args) = parser.parse_args()