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

Refactor veto plugins #463

Merged
merged 8 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions straxen/plugins/veto_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
help="Resolving time for fixed window coincidence [ns]."),
strax.Option('event_min_hits_nv', default=3,
help="Minimum number of fully confined hitlets to define an event."),
strax.Option('gain_model_nv', default=("CMT_model", ("to_pe_model_nv", "ONLINE")),
help='PMT gain model. Specify as (model_type, model_config)'),
strax.Option('channel_map', track=False, type=immutabledict,
help="immutabledict mapping subdetector to (min, max) "
"channel number."),
Expand All @@ -45,11 +43,6 @@ def infer_dtype(self):
self.n_channel = (self.channel_range[1] - self.channel_range[0]) + 1
return veto_event_dtype(self.name_event_number, self.n_channel)

def setup(self):
self.to_pe = straxen.get_to_pe(self.run_id,
self.config['gain_model_nv'],
self.n_channel)

Comment on lines -48 to -52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, was this ever needed actually?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only in a local version of mine. I forgot to remove it.

def get_window_size(self):
return self.config['event_left_extension_nv'] + self.config['event_resolving_time_nv'] + 1

Expand Down Expand Up @@ -439,9 +432,6 @@ def first_hitlets(hitlets_per_event: np.ndarray,
strax.Option('event_min_hits_mv', default=3,
child_option=True, parent_option_name='event_min_hits_nv',
help="Minimum number of fully confined hitlets to define an event."),
strax.Option('gain_model_mv', default=("to_pe_constant", "adc_mv"),
child_option=True, parent_option_name='gain_model_nv',
help='PMT gain model. Specify as (model_type, model_config)'),
)
class muVETOEvents(nVETOEvents):
"""Plugin which computes the boundaries of veto events.
Expand All @@ -465,11 +455,6 @@ def infer_dtype(self):
self.n_channel = (self.channel_range[1] - self.channel_range[0]) + 1
return veto_event_dtype(self.name_event_number, self.n_channel)

def setup(self):
self.to_pe = straxen.get_to_pe(self.run_id,
self.config['gain_model_mv'],
self.n_channel)

def get_window_size(self):
return self.config['event_left_extension_mv'] + self.config['event_resolving_time_mv'] + 1

Expand Down
31 changes: 7 additions & 24 deletions straxen/plugins/veto_hitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,16 @@ def setup(self):
self.to_pe[self.channel_range[0]:] = to_pe[:]

def compute(self, records_nv, start, end):
# Search again for hits in records:
hits = strax.find_hits(records_nv, min_amplitude=self.config['hit_min_amplitude_nv'])
# Merge concatenate overlapping within a channel. This is important
# in case hits were split by record boundaries. In case we
# accidentally concatenate two PMT signals we split them later again.
hits = strax.concat_overlapping_hits(hits,
self.config['save_outside_hits_nv'],
self.channel_range,
start,
end)
hits = strax.sort_by_time(hits)

# Now convert hits into temp_hitlets including the data field:
nsamples = 200
if len(hits):
nsamples = max(hits['length'].max(), nsamples)

temp_hitlets = np.zeros(len(hits), strax.hitlet_with_data_dtype(n_samples=nsamples))

# Generating hitlets and copying relevant information from hits to hitlets.
# These hitlets are not stored in the end since this array also contains a data
# field which we will drop later.
strax.refresh_hit_to_hitlets(hits, temp_hitlets)
temp_hitlets = strax.create_hitlets_from_hits(hits,
self.config['save_outside_hits_nv'],
self.channel_range,
chunk_start=start,
chunk_end=end)
del hits

# Get hitlet data and split hitlets:
strax.get_hitlets_data(temp_hitlets, records_nv, to_pe=self.to_pe)
temp_hitlets = strax.get_hitlets_data(temp_hitlets, records_nv, to_pe=self.to_pe)

temp_hitlets = strax.split_peaks(temp_hitlets,
records_nv,
Expand Down
65 changes: 0 additions & 65 deletions straxen/plugins/veto_pulse_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,71 +150,6 @@ def _correct_baseline(records):
return records


@export
@numba.njit(cache=True, nogil=True)
def clean_up_empty_records(records, record_links, only_last=True):
"""
Function which deletes empty records. Empty means data is completely
zero.

:param records: Records which shall be checked.
:param record_links: Tuple of previous and next records.
:param only_last: If true only last fragments of a pulse are deleted.
:return: non-empty records

Note:
If only_last is false, also records within a pulse can be deleted.
This may lead to unwanted consequences if it not taken into account.
"""
indicies_to_keep = np.zeros(len(records), dtype=np.int32)
n_indicies = 0
for rind, r in enumerate(records):
if only_last:
m_first = record_links[0][rind] == strax.NO_RECORD_LINK #
m_in_between = record_links[1][rind] != strax.NO_RECORD_LINK
if m_first or m_in_between:
# we are not the last record as we don't have a link on the left (i.e. are first) or have a link on the
# right
indicies_to_keep[n_indicies] = rind
n_indicies += 1
continue

if np.any(r['data'] != 0):
indicies_to_keep[n_indicies] = rind
n_indicies += 1
continue

# If we arrive here this means we will remove this record
# Hence we have to update the pulse_lengths accordingly:
length = r['length']

MAX_RECORD_I = 500 # Do not want to be stuck forever

left_links, right_links = record_links # Just to make for loop more explicit
for ind, neighbors in enumerate((left_links, right_links)):
if only_last & ind:
continue

neighbor_i = rind
ntries = 0

# Looping over all left/right neighbors and update pulse_length
while ntries < MAX_RECORD_I:
neighbor_i = neighbors[neighbor_i]
if neighbor_i == strax.NO_RECORD_LINK:
# No neighbor anymore
break
else:
records[neighbor_i]['pulse_length'] -= length
ntries += 1
if ntries == MAX_RECORD_I:
mes = 'Found more than 500 links for a single pulse this is odd.'

raise TimeoutError(mes)

return records[indicies_to_keep[:n_indicies]]


@export
@strax.takes_config(
strax.Option(
Expand Down