Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First nVeto monitor plugin #634

Merged
merged 9 commits into from
Aug 20, 2021
3 changes: 2 additions & 1 deletion straxen/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions straxen/plugins/online_monitor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import strax
import numpy as np
from immutabledict import immutabledict

export, __all__ = strax.exporter()

Expand Down Expand Up @@ -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
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
@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):
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
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):
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
# 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,
JoranAngevaare marked this conversation as resolved.
Show resolved Hide resolved
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