Skip to content

Commit

Permalink
Merge branch 'develop' into simulate_trigger_channels_rnog
Browse files Browse the repository at this point in the history
  • Loading branch information
fschlueter committed Nov 21, 2024
2 parents d953c21 + 7159b59 commit 62385f6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
4 changes: 2 additions & 2 deletions NuRadioReco/detector/RNO_G/db_mongo_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,8 @@ def get_channel_signal_chain(self, channel_signal_id, measurement_name=None, ver
supp_info = {k.replace(component + "_", ""): additional_information[k] for k in additional_information
if re.search(component, k)}

if re.search("_\d+", component, re.IGNORECASE):
collection_suffix = re.findall("(_\d+)", component, re.IGNORECASE)[0]
if re.search("_[0-9]+", component, re.IGNORECASE):
collection_suffix = re.findall("(_[0-9]+)", component, re.IGNORECASE)[0]
collection_component = component.replace(collection_suffix, "")
else:
collection_component = component
Expand Down
2 changes: 1 addition & 1 deletion NuRadioReco/detector/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def Detector(*args, **kwargs):

else:
raise ValueError(f'Unknown source specifed (\"{source}\"). '
f'Must be one of \"json\", \"sql\", "\dictionary\", \"mongo\"')
f'Must be one of \"json\", \"sql\", \"dictionary\", \"mongo\"')

has_reference_entry = _find_reference_entry(station_dict)

Expand Down
2 changes: 1 addition & 1 deletion NuRadioReco/detector/detector_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from tinydb_serialization import Serializer
import six # # used for compatibility between py2 and py3
import warnings
from astropy.utils.exceptions import ErfaWarning
from erfa import ErfaWarning
import NuRadioReco.utilities.metaclasses

logger = logging.getLogger('NuRadioReco.detector')
Expand Down
2 changes: 1 addition & 1 deletion NuRadioReco/framework/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class stationParameters(Enum):
distance_correlations = 30
shower_energy = 31 #: the energy of the shower
viewing_angles = 32 #: reconstructed viewing angles. A nested map structure. First key is channel id, second key is ray tracing solution id. Value is a float
flagged_channels = 60 #: a set of flagged channel ids (calculated by readLOFARData and adjusted by stationRFIFilter)
flagged_channels = 60 #: a defaultdict of flagged NRR channel ids with as value a list of the reason(s) for flagging (used in readLOFARData, stationRFIFilter)
cr_dominant_polarisation = 61 #: the channel orientation containing the dominant cosmic ray signal (calculated by stationPulseFinder)
dirty_fft_channels = 62 #: a list of FFT channels flagged as RFI (calculated by stationRFIFilter)

Expand Down
47 changes: 29 additions & 18 deletions NuRadioReco/modules/trigger/simpleThreshold.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import numpy as np
import time
import logging
from datetime import timedelta

from NuRadioReco.modules.base.module import register_run
from NuRadioReco.utilities import units
from NuRadioReco.framework.parameters import stationParameters as stnp
from NuRadioReco.framework.trigger import SimpleThresholdTrigger
from NuRadioReco.modules.trigger.highLowThreshold import get_majority_logic
import numpy as np
import time
import logging



def get_threshold_triggers(trace, threshold):
"""
calculats a simple threshold trigger
Calculats a simple threshold trigger.
Parameters
----------
trace: array of floats
the signal trace
The signal trace
threshold: float
the threshold
The threshold
Returns
-------
triggered bins: array of bools
the bins where the trigger condition is satisfied
The bins where the trigger condition is satisfied
"""

return np.abs(trace) >= threshold
Expand All @@ -49,7 +52,7 @@ def run(self, evt, station, det,
coinc_window=200 * units.ns,
trigger_name='default_simple_threshold'):
"""
simulate simple trigger logic, no time window, just threshold in all channels
Simulate simple trigger logic, no time window, just threshold in all channels
Parameters
----------
Expand All @@ -75,56 +78,64 @@ def run(self, evt, station, det,

sampling_rate = station.get_channel(station.get_channel_ids()[0]).get_sampling_rate()
dt = 1. / sampling_rate
triggerd_bins_channels = []

if triggered_channels is None:
for channel in station.iter_channels():
channel_trace_start_time = channel.get_trace_start_time()
break
else:
channel_trace_start_time = station.get_channel(triggered_channels[0]).get_trace_start_time()

triggerd_bins_channels = []
channels_that_passed_trigger = []
for channel in station.iter_channels():
channel_id = channel.get_id()
if triggered_channels is not None and channel_id not in triggered_channels:
self.logger.debug("skipping channel {}".format(channel_id))
continue

if channel.get_trace_start_time() != channel_trace_start_time:
self.logger.warning('Channel has a trace_start_time that differs from the other channels. The trigger simulator may not work properly')

trace = channel.get_trace()
if(isinstance(threshold, dict)):

if isinstance(threshold, dict):
threshold_tmp = threshold[channel_id]
else:
threshold_tmp = threshold

triggerd_bins = get_threshold_triggers(trace, threshold_tmp)
triggerd_bins_channels.append(triggerd_bins)
if True in triggerd_bins:

if np.any(triggerd_bins):
channels_that_passed_trigger.append(channel.get_id())

has_triggered, triggered_bins, triggered_times = get_majority_logic(
triggerd_bins_channels, number_concidences, coinc_window, dt)

# set maximum signal aplitude
max_signal = 0
if(has_triggered):
if has_triggered:
for channel in station.iter_channels():
max_signal = max(max_signal, np.abs(channel.get_trace()[triggered_bins]).max())
station.set_parameter(stnp.channels_max_amplitude, max_signal)
trigger = SimpleThresholdTrigger(trigger_name, threshold, triggered_channels,
number_concidences)

trigger = SimpleThresholdTrigger(trigger_name, threshold, triggered_channels, number_concidences)
trigger.set_triggered_channels(channels_that_passed_trigger)

if has_triggered:
trigger.set_triggered(True)
trigger.set_trigger_time(triggered_times.min() + channel_trace_start_time) #trigger_time= earliest trigger_time from start of trace + start time of trace with respect to moment of first interaction = trigger time from moment of first interaction
trigger.set_trigger_time(triggered_times.min() + channel_trace_start_time)
self.logger.debug("station has triggered")
else:
trigger.set_triggered(False)
self.logger.debug("station has NOT triggered")

station.set_trigger(trigger)

self.__t += time.time() - t

def end(self):
from datetime import timedelta
self.logger.setLevel(logging.INFO)
dt = timedelta(seconds=self.__t)
self.logger.info("total time used by this module is {}".format(dt))
return dt

0 comments on commit 62385f6

Please sign in to comment.