diff --git a/straxen/contexts.py b/straxen/contexts.py index c027733e3..453de9ada 100644 --- a/straxen/contexts.py +++ b/straxen/contexts.py @@ -192,7 +192,8 @@ def xenonnt_online(output_folder='./strax_data', readonly=not we_are_the_daq, take_only=('veto_intervals', 'online_peak_monitor', - 'event_basics',))] + 'event_basics', + 'online_monitor_nv'))] # Remap the data if it is before channel swap (because of wrongly cabled # signal cable connectors) These are runs older than run 8797. Runs diff --git a/straxen/plugins/online_monitor.py b/straxen/plugins/online_monitor.py index dd1c640cc..b05168c5d 100644 --- a/straxen/plugins/online_monitor.py +++ b/straxen/plugins/online_monitor.py @@ -1,5 +1,6 @@ import strax import numpy as np +from immutabledict import immutabledict export, __all__ = strax.exporter() @@ -175,3 +176,65 @@ def area_width_hist(self, data): range=self.config['area_vs_width_bounds'], bins=self.config['area_vs_width_nbins']) return hist.T + + +@export +@strax.takes_config( + strax.Option( + 'channel_map', + track=False, + type=immutabledict, + help="immutabledict mapping subdetector to (min, max) \ + channel number.") +) +class OnlineMonitorNV(strax.Plugin): + """ + Plugin to write data of nVeto detector to the online-monitor. + Data that is written by this plugin should be small (~MB/chunk) + to not overload the runs-database. + + This plugin takes 'hitlets_nv' and 'events_nv'. Although they are + not strictly related, they are aggregated into a single data_type + in order to minimize the number of documents in the online monitor. + + Produces 'online_monitor_nv' with info on the hitlets_nv and events_nv + """ + + depends_on = ('hitlets_nv', 'events_nv') + provides = 'online_monitor_nv' + data_kind = 'online_monitor_nv' + __version__ = '0.0.2' + rechunk_on_save = False + + def infer_dtype(self): + min_pmt, max_pmt = self.config['channel_map']['nveto'] + n_pmt = (max_pmt - min_pmt) + 1 + dtype = [ + (('Start time of the chunk', 'time'), + np.int64), + (('End time of the chunk', 'endtime'), + np.int64), + (('hitlets_nv per channel', 'hitlets_nv_per_channel'), + (np.int64, n_pmt)), + (('events_nv per chunk', 'events_nv_per_chunk'), + np.int64) + ] + return dtype + + def compute(self, hitlets_nv, events_nv, start, end): + # General setup + res = np.zeros(1, dtype=self.dtype) + res['time'] = start + res['endtime'] = end + min_pmt, max_pmt = self.config['channel_map']['nveto'] + n_pmt = (max_pmt - min_pmt) + 1 + + # Count number of hitlets_nv per PMT + hitlets_channel_count, _ = np.histogram(hitlets_nv['channel'], + bins=n_pmt, + range=[min_pmt, max_pmt + 1]) + res['hitlets_nv_per_channel'] = hitlets_channel_count + + # Count number of events_nv per chunk + res['events_nv_per_chunk'] = len(events_nv) + return res