Skip to content

Commit

Permalink
Adding BPX timeline module
Browse files Browse the repository at this point in the history
  • Loading branch information
hashkar committed Oct 30, 2023
1 parent b92cee1 commit cc29b1f
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 14 deletions.
17 changes: 15 additions & 2 deletions src/nectarchain/dqm/dqm_summary_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand All @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions src/nectarchain/dqm/pixel_participation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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

Expand Down
155 changes: 155 additions & 0 deletions src/nectarchain/dqm/pixel_timeline.py
Original file line number Diff line number Diff line change
@@ -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,
)
23 changes: 17 additions & 6 deletions src/nectarchain/dqm/start_calib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand All @@ -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",
Expand All @@ -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:
Expand Down

0 comments on commit cc29b1f

Please sign in to comment.