Skip to content

Commit

Permalink
Some enhancements for the DQM (#101)
Browse files Browse the repository at this point in the history
* Some enhancements in the DQM:

- add an event meter when looping over events
- add an option on maximum number of events to loop on for each run slice
- add an option to disable all R0->R1 corrections

* Remove plot legends when unnecessary

---------

Co-authored-by: Jean-Philippe Lenain <[email protected]>
  • Loading branch information
jlenain and jlenain authored Feb 1, 2024
1 parent a4efd8d commit 1f3397c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/nectarchain/dqm/mean_waveforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def PlotResults(self, name, FigPath):
)
part_ax.set_xlabel("Samples")
part_ax.set_ylabel("Amplitude (DC)")
part_ax.legend()
# part_ax.legend()
part_ax.grid()

part_name = name + "_MeanWaveforms_%s_%sGain.png" % (
Expand All @@ -158,7 +158,7 @@ def PlotResults(self, name, FigPath):
full_ax.set_title("Mean Waveforms Combined Plot (%s Gain)" % gain_c)
full_ax.set_xlabel("Samples")
full_ax.set_ylabel("Amplitude (DC)")
full_ax.legend()
# full_ax.legend()
full_ax.grid()

full_name = name + "_MeanWaveforms_CombinedPlot_%sGain.png" % gain_c
Expand Down
75 changes: 45 additions & 30 deletions src/nectarchain/dqm/start_dqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

from camera_monitoring import CameraMonitoring
from charge_integration import ChargeIntegrationHighLowGain
from ctapipe.io import EventSeeker, EventSource
from ctapipe.io import EventSource
from ctapipe_io_nectarcam.constants import HIGH_GAIN, LOW_GAIN
from db_utils import DQMDB
from matplotlib import pyplot as plt
from mean_camera_display import MeanCameraDisplay_HighLowGain
from mean_waveforms import MeanWaveFormsHighLowGain
from tqdm import tqdm
from traitlets.config import Config
from trigger_statistics import TriggerStatistics

# Create an ArgumentParser object
Expand All @@ -30,6 +32,13 @@
parser.add_argument(
"-r", "--runnb", help="Optional run number, automatically found on DIRAC", type=int
)
parser.add_argument("--r0", action="store_true", help="Disable all R0->R1 corrections")
parser.add_argument(
"--max-events",
default=None,
type=int,
help="Maximum number of events to loop through in each run slice",
)
parser.add_argument("-i", "--input-files", nargs="+", help="Local input files")

parser.add_argument("input_paths", help="Input paths")
Expand Down Expand Up @@ -69,7 +78,7 @@
for arg in args.input_files[1:]:
print(arg)

# Defining and priting the options
# Defining and printing the options
PlotFig = args.plot
noped = args.noped

Expand Down Expand Up @@ -106,9 +115,22 @@ def CreateFigFolder(name, type):
cmap = "gnuplot2"

# Read and seek
reader = EventSource(input_url=path)
seeker = EventSeeker(reader)
reader1 = EventSource(input_url=path, max_events=1)
config = None
if args.r0:
config = Config(
dict(
NectarCAMEventSource=dict(
NectarCAMR0Corrections=dict(
calibration_path=None,
apply_flatfield=False,
select_gain=False,
)
)
)
)

reader = EventSource(input_url=path, config=config, max_events=args.max_events)
reader1 = EventSource(input_url=path, config=config, max_events=1)
# print(reader.file_list)

name = GetName(path)
Expand All @@ -118,26 +140,16 @@ def CreateFigFolder(name, type):

# LIST OF PROCESSES TO RUN
########################################################################################
a = TriggerStatistics(HIGH_GAIN)
b = MeanWaveFormsHighLowGain(HIGH_GAIN)
c = MeanWaveFormsHighLowGain(LOW_GAIN)
d = MeanCameraDisplay_HighLowGain(HIGH_GAIN)
e = MeanCameraDisplay_HighLowGain(LOW_GAIN)
f = ChargeIntegrationHighLowGain(HIGH_GAIN)
g = ChargeIntegrationHighLowGain(LOW_GAIN)
h = CameraMonitoring(HIGH_GAIN)

processors = list()

processors.append(a)
processors.append(b)
processors.append(c)
processors.append(d)
processors.append(e)
processors.append(f)
processors.append(g)
processors.append(h)

processors = [
TriggerStatistics(HIGH_GAIN),
MeanWaveFormsHighLowGain(HIGH_GAIN),
MeanWaveFormsHighLowGain(LOW_GAIN),
MeanCameraDisplay_HighLowGain(HIGH_GAIN),
MeanCameraDisplay_HighLowGain(LOW_GAIN),
ChargeIntegrationHighLowGain(HIGH_GAIN),
ChargeIntegrationHighLowGain(LOW_GAIN),
CameraMonitoring(HIGH_GAIN),
]

# LIST OF DICT RESULTS
Results_MeanWaveForms_HighGain = {}
Expand Down Expand Up @@ -170,19 +182,22 @@ def CreateFigFolder(name, type):
for p in processors:
p.ConfigureForRun(path, Pix, Samp, reader1)

for i, evt in enumerate(reader):
for evt in tqdm(
reader, total=args.max_events if args.max_events else len(reader), unit="ev"
):
for p in processors:
p.ProcessEvent(evt, noped)

# for the rest of the event files
for arg in args.input_files[1:]:
path2 = f"{NectarPath}/{arg}"
path2 = f"{NectarPath}/runs/{arg}"
print(path2)

reader = EventSource(input_url=path2)
seeker = EventSeeker(reader)
reader = EventSource(input_url=path2, config=config, max_events=args.max_events)

for i, evt in enumerate(reader):
for evt in tqdm(
reader, total=args.max_events if args.max_events else len(reader), unit="ev"
):
for p in processors:
p.ProcessEvent(evt, noped)

Expand Down

0 comments on commit 1f3397c

Please sign in to comment.