diff --git a/src/nectarchain/dqm/dqm_summary_processor.py b/src/nectarchain/dqm/dqm_summary_processor.py index a9edaf28..c087d7e4 100644 --- a/src/nectarchain/dqm/dqm_summary_processor.py +++ b/src/nectarchain/dqm/dqm_summary_processor.py @@ -34,10 +34,11 @@ def PlotResults( def WriteAllResults(self, path, DICT): data2 = Table() data1 = Table() + data0 = Table() data = Table() hdulist = fits.HDUList() for i, j in DICT.items(): - if i == "Results_TriggerStatistics": + if (i == "Results_TriggerStatistics"): for n2, m2 in j.items(): data2[n2] = m2 hdu2 = fits.BinTableHDU(data2) @@ -47,7 +48,13 @@ def WriteAllResults(self, path, DICT): for n1, m1 in j.items(): data1[n1] = m1 hdu1 = fits.BinTableHDU(data1) - hdu1.name = "MWF" + hdu1.name = "MWF" + + elif (i == "Results_PixelTimeline_HighGain") or (i == "Results_PixelTimeline_LowGain"): + for n0, m0 in j.items(): + data0[n0] = m0 + hdu0 = fits.BinTableHDU(data0) + hdu0.name = "BPX" else: for n, m in j.items(): @@ -62,10 +69,16 @@ def WriteAllResults(self, path, DICT): hdulist.append(hdu1) except: print("No MWF studies requests") + try: + hdulist.append(hdu0) + except: + print("No Pixel Timeline studies requests") try: hdulist.append(hdu) except: print("No Camera studies requests") + + FileName = path + '_Results.fits' print(FileName) hdulist.writeto(FileName, overwrite=True) diff --git a/src/nectarchain/dqm/pixel_participation.py b/src/nectarchain/dqm/pixel_participation.py index 86c94b70..c13bd8fd 100644 --- a/src/nectarchain/dqm/pixel_participation.py +++ b/src/nectarchain/dqm/pixel_participation.py @@ -16,8 +16,6 @@ def ConfigureForRun(self, path, Pix, Samp, Reader1): self.Pix = Pix self.Samp = Samp - self.CameraAverage = np.zeros(self.Pix) - self.CameraAverage_ped = np.zeros(self.Pix) self.counter_evt = 0 self.counter_ped = 0 @@ -27,8 +25,6 @@ def ConfigureForRun(self, path, Pix, Samp, Reader1): self.cmap = "gnuplot2" self.cmap2 = "gnuplot2" - self.CameraAverage = [] - self.CameraAverage_ped = [] self.BadPixels_ped = np.zeros(self.Pix) self.BadPixels = np.zeros(self.Pix) @@ -45,12 +41,12 @@ def ProcessEvent(self, evt, noped): if evt.trigger.event_type.value == 32: # count peds self.counter_ped += 1 - BadPixels_ped1 = list(map(int, pixelBAD)) + BadPixels_ped1 = list(map(int, pixelBAD[pixels])) self.BadPixels_ped += BadPixels_ped1 else: self.counter_evt += 1 - BadPixels1 = list(map(int, pixelBAD)) + BadPixels1 = list(map(int, pixelBAD[pixels])) self.BadPixels += BadPixels1 return None diff --git a/src/nectarchain/dqm/pixel_timeline.py b/src/nectarchain/dqm/pixel_timeline.py new file mode 100644 index 00000000..7df9173a --- /dev/null +++ b/src/nectarchain/dqm/pixel_timeline.py @@ -0,0 +1,155 @@ +from dqm_summary_processor import dqm_summary +from matplotlib import pyplot as plt +from ctapipe.visualization import CameraDisplay +from ctapipe.instrument import CameraGeometry +from ctapipe.coordinates import EngineeringCameraFrame +import numpy as np + + +class PixelTimeline_HighLowGain(dqm_summary): + def __init__(self, gaink): + self.k = gaink + return None + + def ConfigureForRun(self, path, Pix, Samp, Reader1): + # define number of pixels and samples + self.Pix = Pix + self.Samp = Samp + + + self.counter_evt = 0 + self.counter_ped = 0 + + self.camera = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame()) + self.camera2 = CameraGeometry.from_name("NectarCam-003").transform_to(EngineeringCameraFrame()) + + self.cmap = "gnuplot2" + self.cmap2 = "gnuplot2" + + + self.SumBadPixels_ped = [] + self.SumBadPixels = [] + + def ProcessEvent(self, evt, noped): + pixelBAD = evt.mon.tel[0].pixel_status.hardware_failing_pixels[self.k] + pixel = evt.nectarcam.tel[0].svc.pixel_ids + if len(pixel) < self.Pix: + pixel21 = list(np.arange(0, self.Pix - len(pixel), 1, dtype=int)) + pixel = list(pixel) + pixels = np.concatenate([pixel21, pixel]) + else: + pixels = pixel + + if evt.trigger.event_type.value == 32: # count peds + self.counter_ped += 1 + self.counter_evt += 1 + BadPixels_ped1 = list(map(int, pixelBAD[pixels])) + SumBadPixelsEvent_ped = sum(BadPixels_ped1) + self.SumBadPixels_ped.append(SumBadPixelsEvent_ped) + self.SumBadPixels.append(0) + + else: + self.counter_evt += 1 + self.counter_ped += 1 + BadPixels1 = list(map(int, pixelBAD[pixels])) + SumBadPixelsEvent = sum(BadPixels1) + self.SumBadPixels.append(SumBadPixelsEvent) + self.SumBadPixels_ped.append(0) + + return None + + def FinishRun(self): + + self.BadPixelTimeline_ped = np.array(self.SumBadPixels_ped, dtype=float)/self.Pix + self.BadPixelTimeline = np.array(self.SumBadPixels, dtype=float)/self.Pix + print(self.BadPixelTimeline) + print( self.BadPixelTimeline_ped) + + + + + def GetResults(self): + # INITIATE DICT + self.PixelTimeline_Results_Dict = {} + + # ASSIGN RESUTLS TO DICT + if self.k == 0: + + if self.counter_evt > 0: + self.PixelTimeline_Results_Dict[ + "CAMERA-BadPixTimeline-PHY-HIGH-GAIN" + ] = self.BadPixelTimeline + + + if self.counter_ped > 0: + self.PixelTimeline_Results_Dict[ + "CAMERA-BadPixTimeline-PED-HIGH-GAIN" + ] = self.BadPixelTimeline_ped + + + if self.k == 1: + if self.counter_evt > 0: + self.PixelTimeline_Results_Dict[ + "CAMERA-BadPixTimeline-PHY-LOW-GAIN" + ] = self.BadPixelTimeline + + if self.counter_ped > 0: + self.PixelTimeline_Results_Dict[ + "CAMERA-BadPixTimeline-PED-LOW-GAIN" + ] = self.BadPixelTimeline_ped + + + return self.PixelTimeline_Results_Dict + + def PlotResults(self, name, FigPath): + self.PixelTimeline_Figures_Dict = {} + self.PixelTimeline_Figures_Names_Dict = {} + + # titles = ['All', 'Pedestals'] + if self.k == 0: + gain_c = "High" + if self.k == 1: + gain_c = "Low" + + if self.counter_evt > 0: + fig1, disp = plt.subplots() + plt.plot(np.arange(self.counter_evt), self.BadPixelTimeline*100, label = "Physical events") + plt.legend() + plt.xlabel("Timeline") + plt.ylabel("BPX fraction (%)") + plt.title("BPX Timeline %s gain (ALL)" % gain_c) + + full_name = name + "_BPX_Timeline_%sGain_All.png" % gain_c + FullPath = FigPath + full_name + self.PixelTimeline_Figures_Dict[ + "BPX-TIMELINE-ALL-%s-GAIN" % gain_c + ] = fig1 + self.PixelTimeline_Figures_Names_Dict[ + "BPX-TIMELINE-ALL-%s-GAIN" % gain_c + ] = FullPath + + plt.close() + + if self.counter_ped > 0: + fig2, disp = plt.subplots() + plt.plot(np.arange(self.counter_ped), self.BadPixelTimeline_ped*100, label = "Pedestal events") + plt.legend() + plt.xlabel("Timeline") + plt.ylabel("BPX fraction (%)") + plt.title("BPX Timeline %s gain (PED)" % gain_c) + + full_name = name + "_BPX_Timeline_%sGain_Ped.png" % gain_c + FullPath = FigPath + full_name + self.PixelTimeline_Figures_Dict[ + "BPX-TIMELINE-PED-%s-GAIN" % gain_c + ] = fig2 + self.PixelTimeline_Figures_Names_Dict[ + "BPX-TIMELINE-PED-%s-GAIN" % gain_c + ] = FullPath + + plt.close() + + return ( + self.PixelTimeline_Figures_Dict, + self.PixelTimeline_Figures_Names_Dict, + ) diff --git a/src/nectarchain/dqm/start_calib.py b/src/nectarchain/dqm/start_calib.py index 55d9fdd7..13c1210f 100644 --- a/src/nectarchain/dqm/start_calib.py +++ b/src/nectarchain/dqm/start_calib.py @@ -14,6 +14,7 @@ from trigger_statistics import TriggerStatistics from camera_monitoring import CameraMonitoring from pixel_participation import PixelParticipation_HighLowGain +from pixel_timeline import PixelTimeline_HighLowGain from db_utils import DQMDB @@ -128,8 +129,10 @@ def CreateFigFolder(name, type): f = ChargeIntegration_HighLowGain(HIGH_GAIN) g = ChargeIntegration_HighLowGain(LOW_GAIN) h = CameraMonitoring(HIGH_GAIN) -e = PixelParticipation_HighLowGain(HIGH_GAIN) -f = PixelParticipation_HighLowGain(LOW_GAIN) +i = PixelParticipation_HighLowGain(HIGH_GAIN) +j = PixelParticipation_HighLowGain(LOW_GAIN) +k = PixelTimeline_HighLowGain(HIGH_GAIN) +l = PixelTimeline_HighLowGain(LOW_GAIN) processors = list() @@ -141,23 +144,28 @@ def CreateFigFolder(name, type): processors.append(f) processors.append(g) processors.append(h) -processors.append(e) -processors.append(f) +processors.append(i) +processors.append(j) +processors.append(k) +processors.append(l) # LIST OF DICT RESULTS +Results_TriggerStatistics = {} Results_MeanWaveForms_HighGain = {} Results_MeanWaveForms_LowGain = {} Results_MeanCameraDisplay_HighGain = {} Results_MeanCameraDisplay_LowGain = {} Results_ChargeIntegration_HighGain = {} Results_ChargeIntegration_LowGain = {} -Results_TriggerStatistics = {} Results_CameraMonitoring = {} Results_PixelParticipation_HighGain = {} Results_PixelParticipation_LowGain = {} +Results_PixelTimeline_HighGain = {} +Results_PixelTimeline_LowGain = {} NESTED_DICT = {} # The final results dictionary + NESTED_DICT_KEYS = [ "Results_TriggerStatistics", "Results_MeanWaveForms_HighGain", @@ -169,8 +177,11 @@ def CreateFigFolder(name, type): "Results_CameraMonitoring", "Results_PixelParticipation_HighGain", "Results_PixelParticipation_LowGain", + "Results_PixelTimeline_HighGain", + "Results_PixelTimeline_LowGain", ] -# NESTED_DICT_KEYS = ["Results_CameraMonitoring"] + +#NESTED_DICT_KEYS = ["Results_PixelParticipation_HighGain", "Results_PixelTimeline_HighGain"] # START for p in processors: