610 def PlotCalibrationGains(input_file_name="",reference_file_name="",isInputXml=False,isInputSqlite=False,isRefXml=False,isRefSqlite=False,isRefOracle=False):
612 ROOT.gStyle.SetPalette(1)
613 ROOT.gStyle.SetOptStat(111111)
614 ROOT.gStyle.SetCanvasColor(10)
616 c1 = ROOT.TCanvas(
'c1',
'Example',200,10,700,500)
617 c2 = ROOT.TCanvas(
'c2',
'Example Partitions',200,10,700,500)
620 h_gains_em = L1CaloMap(
"Eta-phi map of EM gains",
"#eta bin",
"#phi bin")
621 h_gains_had = L1CaloMap(
"Eta-phi map of HAD gains",
"#eta bin",
"#phi bin")
623 h_gains_em_fselect = L1CaloMap(
"Eta-phi map of EM gains that failed selection",
"#eta bin",
"#phi bin")
624 h_gains_had_fselect = L1CaloMap(
"Eta-phi map of HAD gains that failed selection",
"#eta bin",
"#phi bin")
626 h_chi2_em = L1CaloMap(
"Eta-phi map of EM Chi2",
"#eta bin",
"#phi bin")
627 h_chi2_had = L1CaloMap(
"Eta-phi map of HAD Chi2",
"#eta bin",
"#phi bin")
629 h_offset_em = L1CaloMap(
"Eta-phi map of EM offsets",
"#eta bin",
"#phi bin")
630 h_offset_had = L1CaloMap(
"Eta-phi map of HAD offsets",
"#eta bin",
"#phi bin")
633 h_unfitted_em = L1CaloMap(
"Eta-phi map of EM failed fits",
"#eta bin",
"#phi bin")
634 h_unfitted_had = L1CaloMap(
"Eta-phi map of HAD failed fits",
"#eta bin",
"#phi bin")
636 h_drifted_em = L1CaloMap(
"EM TTs that drifted more then 10 %",
"#eta bin",
"#phi bin")
637 h_drifted_had = L1CaloMap(
"HAD TTs that drifted more then 10 %",
"#eta bin",
"#phi bin")
640 h_gains_em_reference = L1CaloMap(
"Eta-phi map of EM gains (gain-reference)",
"#eta bin",
"#phi bin")
641 h_gains_had_reference = L1CaloMap(
"Eta-phi map of HAD gains (gain-reference)",
"#eta bin",
"#phi bin")
643 h_gains_em_reference_rel = L1CaloMap(
"Eta-phi map of EM gains: (gain-reference)/reference",
"#eta bin",
"#phi bin")
644 h_gains_had_reference_rel = L1CaloMap(
"Eta-phi map of HAD gains: (gain-reference)/reference",
"#eta bin",
"#phi bin")
647 em_partition_gains = EmPartitionPlots(
" EM gains",40,0.6,1.4,
"gain",
"N")
648 had_partition_gains = HadPartitionPlots(
" HAD gains",40,0.5,2.5,
"gain",
"N")
650 em_partition_gains_ref = EmPartitionPlots(
" EM gains - reference",40,-0.2,0.2,
"gain-reference",
"N")
651 had_partition_gains_ref = HadPartitionPlots(
" HAD gains - reference",40,-1.,1.,
"gain-reference",
"N")
653 em_partition_gains_ref_rel = EmPartitionPlots(
" EM gains-reference / reference",40,-0.2,0.2,
"(gain-reference)/reference",
"N")
654 had_partition_gains_ref_rel = HadPartitionPlots(
" HAD gains-reference / reference",40,-1.,1.,
"(gain-reference)/reference",
"N")
656 threshold_change = 0.1
658 geometry_convertor = L1CaloGeometryConvertor()
659 receiver_gains = GainReader()
661 bad_gain_file =
open(
'bad_gains.txt',
'w')
662 drifted_towers_file =
open(
'drifted_towers.txt',
'w')
664 if isInputXml
is True:
665 print (
"Taking input from xml file: ", input_file_name)
666 receiver_gains.LoadGainsXml(input_file_name)
667 elif isInputSqlite
is True:
668 print (
"Taking input from Sqlite file: ", input_file_name)
669 receiver_gains.LoadGainsSqlite(input_file_name)
671 print (
"No option for input file selected, assuming sqlite file energyscanresults.sqlite")
672 receiver_gains.LoadGainsSqlite(
"energyscanresults.sqlite")
676 print (
"Taking reference from Xml file: ",reference_file_name)
677 receiver_gains.LoadReferenceXml(reference_file_name)
678 elif isRefSqlite
is True:
679 print (
"Taking reference from Sqlite file: ",reference_file_name)
680 receiver_gains.LoadReferenceSqlite(reference_file_name)
681 elif isRefOracle
is True:
682 print (
"Taking reference from Oracle")
683 geometry_convertor.LoadReceiverPPMMap()
684 receiver_gains.LoadReferenceOracle(geometry_convertor)
686 print (
" No option for reference file, assuming Oracle")
687 geometry_convertor.LoadReceiverPPMMap()
688 receiver_gains.LoadReferenceOracle(geometry_convertor)
691 for i_eta
in range(-49,45):
692 for i_phi
in range(0,64):
694 coolEm = geometry_convertor.getCoolEm(i_eta,i_phi)
695 coolHad = geometry_convertor.getCoolHad(i_eta,i_phi)
699 gain = receiver_gains.getGain(coolEm)
700 chi2 = receiver_gains.getChi2(coolEm)
701 offset = receiver_gains.getOffset(coolEm)
702 reference_gain = receiver_gains.getReferenceGain(coolEm)
703 passes_selection = receiver_gains.passesSelection(coolEm)
705 if (
not gain ==
'')
and (
not reference_gain ==
''):
708 h_unfitted_em.Fill(i_eta,i_phi)
709 bad_gain_file.write(
'%i %i %s EM gain= %.3f \n' % (i_eta,i_phi,coolEm,
float(gain)))
710 h_gains_em_reference.Fill(i_eta,i_phi,-100.)
711 h_gains_em_reference_rel.Fill(i_eta,i_phi,-100.)
713 h_gains_em.Fill(i_eta,i_phi,gain)
714 h_chi2_em.Fill(i_eta,i_phi,chi2)
715 h_offset_em.Fill(i_eta,i_phi,offset)
716 em_partition_gains.Fill(i_eta,gain)
717 em_partition_gains_ref.Fill(i_eta,gain-reference_gain)
718 h_gains_em_reference.Fill(i_eta,i_phi,gain-reference_gain)
720 if passes_selection
is False:
721 h_gains_em_fselect.Fill(i_eta,i_phi)
722 bad_gain_file.write(
'%i %i %s EM gain= %.3f chi2= %.3f offset= %.3f \n' % (i_eta,i_phi,coolEm,
float(gain),
float(chi2),
float(offset)))
726 if reference_gain > 0:
727 em_partition_gains_ref_rel.Fill(i_eta,(gain-reference_gain)/reference_gain)
728 h_gains_em_reference_rel.Fill(i_eta,i_phi,(gain-reference_gain)/reference_gain)
729 if fabs((gain-reference_gain)/reference_gain) > threshold_change:
730 h_drifted_em.Fill(i_eta,i_phi)
731 drifted_towers_file.write(
'%i %i %s EM gain= %.3f refGain= %.3f (%.3f %%) \n' % (i_eta,i_phi,coolEm,
float(gain),
float(reference_gain),(gain-reference_gain)*100/reference_gain))
736 if not coolHad ==
'':
738 gain = receiver_gains.getGain(coolHad)
739 chi2 = receiver_gains.getChi2(coolHad)
740 offset = receiver_gains.getOffset(coolHad)
741 reference_gain = receiver_gains.getReferenceGain(coolHad)
742 passes_selection = receiver_gains.passesSelection(coolHad)
744 if (
not gain ==
'')
and (
not reference_gain ==
''):
747 h_unfitted_had.Fill(i_eta,i_phi)
748 bad_gain_file.write(
'%i %i %s HAD gain= %.3f \n' % (i_eta,i_phi,coolHad,
float(gain)))
749 h_gains_had_reference.Fill(i_eta,i_phi,-100.)
750 h_gains_had_reference_rel.Fill(i_eta,i_phi,-100.)
752 h_gains_had.Fill(i_eta,i_phi,gain)
753 h_chi2_had.Fill(i_eta,i_phi,chi2)
754 h_offset_had.Fill(i_eta,i_phi,offset)
755 had_partition_gains.Fill(i_eta,gain)
756 had_partition_gains_ref.Fill(i_eta,gain-reference_gain)
757 h_gains_had_reference.Fill(i_eta,i_phi,gain-reference_gain)
759 if passes_selection
is False:
760 h_gains_had_fselect.Fill(i_eta,i_phi)
761 bad_gain_file.write(
'%i %i %s HAD gain= %.3f chi2= %.3f offset= %.3f \n' % (i_eta,i_phi,coolHad,
float(gain),
float(chi2),
float(offset)))
765 if reference_gain > 0:
766 had_partition_gains_ref_rel.Fill(i_eta,(gain-reference_gain)/reference_gain)
767 h_gains_had_reference_rel.Fill(i_eta,i_phi,(gain-reference_gain)/reference_gain)
768 if fabs((gain-reference_gain)/reference_gain) > threshold_change:
769 h_drifted_had.Fill(i_eta,i_phi)
770 drifted_towers_file.write(
'%i %i %s HAD gain= %.3f refGain= %.3f (%.3f %%) \n' % (i_eta,i_phi,coolHad,
float(gain),
float(reference_gain),(gain-reference_gain)*100/reference_gain))
778 h_gains_em.SetMinimum(0.6)
779 h_gains_em.SetMaximum(1.4)
782 c1.Print(
"Gains.ps(")
784 h_gains_had.SetMinimum(0.6)
785 h_gains_had.SetMaximum(1.4)
799 h_gains_em_reference_rel.SetMinimum(-0.5)
800 h_gains_em_reference_rel.SetMaximum(0.5)
801 h_gains_em_reference_rel.Draw()
804 h_gains_had_reference_rel.SetMinimum(-0.5)
805 h_gains_had_reference_rel.SetMaximum(0.5)
806 h_gains_had_reference_rel.Draw()
810 h_gains_em_reference_rel.SetMinimum(-0.1)
811 h_gains_em_reference_rel.SetMaximum(0.1)
812 h_gains_em_reference_rel.Draw()
814 palette = h_gains_em_reference_rel.h_1.GetListOfFunctions().FindObject(
"palette")
816 palette.SetLabelSize(0.025)
818 h_gains_em_reference_rel.Draw()
821 h_gains_had_reference_rel.SetMinimum(-0.1)
822 h_gains_had_reference_rel.SetMaximum(0.1)
823 h_gains_had_reference_rel.Draw()
826 palette = h_gains_had_reference_rel.h_1.GetListOfFunctions().FindObject(
"palette")
828 palette.SetLabelSize(0.025)
830 h_gains_had_reference_rel.Draw()
837 h_gains_em_reference.SetMinimum(-0.5)
838 h_gains_em_reference.SetMaximum(0.5)
840 h_gains_em_reference.Draw()
843 h_gains_had_reference.SetMinimum(-0.5)
844 h_gains_had_reference.SetMaximum(0.5)
849 h_gains_had_reference.Draw()
854 h_chi2_em.SetMinimum(0.1)
855 h_chi2_em.SetMaximum(100)
861 h_chi2_had.SetMinimum(0.1)
862 h_chi2_had.SetMaximum(100)
868 h_offset_em.SetMinimum(-1.)
869 h_offset_em.SetMaximum(1.)
875 h_offset_had.SetMinimum(-1.)
876 h_offset_had.SetMaximum(1.)
884 for i_p
in range(0,em_partition_gains.nPartitions):
886 if em_partition_gains.his_partitions[i_p].
GetEntries() > 0:
890 em_partition_gains.his_partitions[i_p].Draw()
897 for i_p
in range(0,had_partition_gains.nPartitions):
899 if had_partition_gains.his_partitions[i_p].
GetEntries() > 0:
903 had_partition_gains.his_partitions[i_p].Draw()
911 for i_p
in range(0,em_partition_gains_ref.nPartitions):
913 if em_partition_gains_ref.his_partitions[i_p].
GetEntries() > 0:
917 em_partition_gains_ref.his_partitions[i_p].Draw()
924 for i_p
in range(0,had_partition_gains_ref.nPartitions):
926 if had_partition_gains_ref.his_partitions[i_p].
GetEntries() > 0:
930 had_partition_gains_ref.his_partitions[i_p].Draw()
937 for i_p
in range(0,em_partition_gains_ref_rel.nPartitions):
939 if em_partition_gains_ref_rel.his_partitions[i_p].
GetEntries() > 0:
943 em_partition_gains_ref_rel.his_partitions[i_p].Draw()
950 for i_p
in range(0,had_partition_gains_ref_rel.nPartitions):
952 if had_partition_gains_ref_rel.his_partitions[i_p].
GetEntries() > 0:
956 had_partition_gains_ref_rel.his_partitions[i_p].Draw()
964 h_gains_em_fselect.Draw()
967 h_gains_had_fselect.Draw()
974 h_unfitted_had.Draw()
975 c1.Print(
"Gains.ps)")
977 os.system(
"ps2pdf Gains.ps")
979 bad_gain_file.close()
980 drifted_towers_file.close()