Skip to content

Commit

Permalink
WaveformNsbTunner => WaveformNsbTuner
Browse files Browse the repository at this point in the history
  • Loading branch information
moralejo committed Aug 1, 2024
1 parent fbd2c19 commit 20d04bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
16 changes: 9 additions & 7 deletions lstchain/image/modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'calculate_noise_parameters',
'random_psf_smearer',
'set_numba_seed',
'WaveformNsbTunner',
'WaveformNsbTuner',
]

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -556,7 +556,7 @@ def calculate_required_additional_nsb(simtel_filename, data_dl1_filename, config
# Just the product of added_nsb and original_nsb (first two arguments
# below) is relevant! Units "GHz" (p.e./ns)
nsb_tuner = [None]
# We now create the instances of WaveformNsbTunner to add the different
# We now create the instances of WaveformNsbTuner to add the different
# levels of noise to the MC waveforms.
# NOTE: the waveform gets updated every time, the noise addition is
# cumulative (hence the np.diff):
Expand All @@ -568,8 +568,9 @@ def calculate_required_additional_nsb(simtel_filename, data_dl1_filename, config
# just creates it with a single value, for tel_id
nsb = {tel_id: nsb_rate * u.GHz for tel_id in
config['source_config']['LSTEventSource']['allowed_tels']}
nsb_tuner.append(WaveformNsbTunner(nsb, pulse_templates,
charge_spe_cumulative_pdf, 10))
nsb_tuner.append(WaveformNsbTuner(nsb, pulse_templates,
charge_spe_cumulative_pdf,
pre_computed_multiplicity=10))
# last argument means it will precompute 10 * 1855 (pixels) * 2 (gains)
# noise waveforms to pick from during the actual introduction of the noise

Expand Down Expand Up @@ -626,8 +627,9 @@ def calculate_required_additional_nsb(simtel_filename, data_dl1_filename, config
mc_reader = EventSource(input_url=simtel_filename, config=Config(config))
nsb = {tel_id: extra_nsb * u.GHz for tel_id in
config['source_config']['LSTEventSource']['allowed_tels']}
tuner = WaveformNsbTunner(nsb, pulse_templates,
charge_spe_cumulative_pdf, 10)
tuner = WaveformNsbTuner(nsb, pulse_templates,
charge_spe_cumulative_pdf,
pre_computed_multiplicity=10)
final_mc_qped = []
numevents = 0
for event in mc_reader:
Expand Down Expand Up @@ -659,7 +661,7 @@ def custom_function(x, a, b, c):
"""
return a + b * x ** c

class WaveformNsbTunner:
class WaveformNsbTuner:
"""
Handles the injection of additional NSB pulses in waveforms.
"""
Expand Down
18 changes: 9 additions & 9 deletions lstchain/image/tests/test_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_tune_nsb_on_waveform():
from ctapipe_io_lst import LSTEventSource
from scipy.interpolate import interp1d
from lstchain.io.io import get_resource_path
from lstchain.image.modifier import WaveformNsbTunner
from lstchain.image.modifier import WaveformNsbTuner
from lstchain.data.normalised_pulse_template import NormalizedPulseTemplate

waveform = np.array(
Expand All @@ -108,21 +108,21 @@ def test_tune_nsb_on_waveform():
charge_spe_cumulative_pdf = interp1d(spe_integral, spe[0], kind='cubic',
bounds_error=False, fill_value=0.,
assume_sorted=True)
nsb_tunner = WaveformNsbTunner(added_nsb_rate,
pulse_templates,
charge_spe_cumulative_pdf,
pre_computed_multiplicity=0)
nsb_tunner = WaveformNsbTuner(added_nsb_rate,
pulse_templates,
charge_spe_cumulative_pdf,
pre_computed_multiplicity=0)
nsb_tunner.tune_nsb_on_waveform(waveform, 1, gain, subarray)
assert np.any(waveform != 0)
assert np.isclose(np.mean(waveform), 0.0, atol=0.2)
waveform = np.array(
[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]
)
nsb_tunner = WaveformNsbTunner(added_nsb_rate,
pulse_templates,
charge_spe_cumulative_pdf,
pre_computed_multiplicity=10)
nsb_tunner = WaveformNsbTuner(added_nsb_rate,
pulse_templates,
charge_spe_cumulative_pdf,
pre_computed_multiplicity=10)
nsb_tunner.tune_nsb_on_waveform(waveform, 1, gain, subarray)
assert np.any(waveform != 0)
assert np.isclose(np.mean(waveform), 0.0, atol=0.2)
10 changes: 5 additions & 5 deletions lstchain/reco/r0_to_dl1.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from ..calib.camera import load_calibrator_from_config
from ..calib.camera.calibration_calculator import CalibrationCalculator
from ..image.cleaning import apply_dynamic_cleaning
from ..image.modifier import calculate_required_additional_nsb, WaveformNsbTunner
from ..image.modifier import calculate_required_additional_nsb, WaveformNsbTuner
from .reconstructor import TimeWaveformFitter
from ..image.muon import analyze_muon_event, tag_pix_thr
from ..image.muon import create_muon_table, fill_muon_event
Expand Down Expand Up @@ -442,10 +442,10 @@ def r0_to_dl1(
nsb_per_tel = {tel_id: nsb_tuning_rate * u.GHz for tel_id in
allowed_tels}

nsb_tuner = WaveformNsbTunner(nsb_per_tel,
pulse_templates,
charge_spe_cumulative_pdf,
pre_computed_multiplicity)
nsb_tuner = WaveformNsbTuner(nsb_per_tel,
pulse_templates,
charge_spe_cumulative_pdf,
pre_computed_multiplicity)
else:
logger.warning('NSB tuning on waveform active in config but file is real data, option will be ignored')
nsb_tuning = False
Expand Down

0 comments on commit 20d04bb

Please sign in to comment.