Skip to content

Commit

Permalink
Update waveform nsb tunning section of config files. Move parameter d…
Browse files Browse the repository at this point in the history
…efinition done twice in WaveformNsbTunner to init. Clarify parameter naming and add comment.
  • Loading branch information
gabemery committed Jul 11, 2024
1 parent 2a4e061 commit a294418
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lstchain/data/lstchain_lhfit_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@
},
"waveform_nsb_tuning":{
"nsb_tuning": false,
"nsb_tuning_ratio": 0.52,
"nsb_tuning_ratio": 0.5,
"spe_location": null,
"pre_computed_multiplicity": 0
"pre_computed_multiplicity": 10
},
"lh_fit_config": {
"sigma_s": [
Expand Down
5 changes: 3 additions & 2 deletions lstchain/data/lstchain_standard_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@
},
"waveform_nsb_tuning":{
"nsb_tuning": false,
"nsb_tuning_ratio": 0.52,
"spe_location": null
"nsb_tuning_ratio": 0.5,
"spe_location": null,
"pre_computed_multiplicity": 10
},
"write_interleaved_events":{
"DataWriter": {
Expand Down
27 changes: 16 additions & 11 deletions lstchain/image/modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ def __init__(self, added_nsb_fraction, original_nsb, pulse_template, charge_spe_
self.pulse_template = pulse_template
self.charge_spe_cumulative_pdf = charge_spe_cumulative_pdf
self.multiplicity = pre_computed_multiplicity

# Number of extra time sample added at the start of the time window used to inject NSB pulses
# It should be large enough to account for pulses created by NSB hits before the recorded time window
self.extra_samples = 25

self.nsb_waveforms = {}
self.nb_simulated = {}
self.rng = np.random.default_rng()
Expand All @@ -590,20 +595,20 @@ def initialise_waveforms(self, waveform, dt, tel_id):
"""
log.info(f"Pre-generating nsb waveforms for nsb tuning and telescope id {tel_id}.")
n = 25
n_pixels, n_samples = waveform.shape
baseline_correction = -(self.added_nsb_fraction * self.original_nsb[tel_id] * dt).to_value("")
nsb_waveforms = np.full((self.multiplicity * n_pixels, 2, n_samples), baseline_correction)
duration = (n + n_samples) * dt # TODO check needed time window, effect of edges
t = np.arange(-n, n_samples) * dt.to_value(u.ns)
duration = (self.extra_samples + n_samples) * dt
t = np.arange(-self.extra_samples, n_samples) * dt.to_value(u.ns)
mean_added_nsb = (self.added_nsb_fraction * self.original_nsb[tel_id] * duration).to_value("")
additional_nsb = self.rng.poisson(mean_added_nsb, self.multiplicity * n_pixels)
added_nsb_time = self.rng.uniform(-n * dt.to_value(u.ns), -n * dt.to_value(u.ns) + duration.to_value(u.ns),
added_nsb_time = self.rng.uniform(-self.extra_samples * dt.to_value(u.ns),
-self.extra_samples * dt.to_value(u.ns) + duration.to_value(u.ns),
(self.multiplicity * n_pixels, max(additional_nsb)))
added_nsb_amp = self.charge_spe_cumulative_pdf(
self.rng.uniform(size=(self.multiplicity * n_pixels, max(additional_nsb))))
nsb_waveforms[:, 0, :] += nsb_only_waveforms(
time=t[n:],
time=t[self.extra_samples:],
is_high_gain=np.zeros(self.multiplicity * n_pixels),
additional_nsb=additional_nsb,
amplitude=added_nsb_amp,
Expand All @@ -614,7 +619,7 @@ def initialise_waveforms(self, waveform, dt, tel_id):
a_lg_template=self.pulse_template[tel_id].amplitude_LG
)
nsb_waveforms[:, 1, :] += nsb_only_waveforms(
time=t[n:],
time=t[self.extra_samples:],
is_high_gain=np.ones(self.multiplicity * n_pixels),
additional_nsb=additional_nsb,
amplitude=added_nsb_amp,
Expand Down Expand Up @@ -669,22 +674,22 @@ def _tune_nsb_on_waveform_direct(self, waveform, tel_id, is_high_gain, subarray)
subarray: `ctapipe.instrument.subarray.SubarrayDescription`
"""
n = 25
n_pixels, n_samples = waveform.shape
readout = subarray.tel[tel_id].camera.readout
sampling_rate = readout.sampling_rate
dt = (1.0 / sampling_rate).to(u.s)
duration = (n + n_samples) * dt # TODO check needed time window, effect of edges
t = np.arange(-n, n_samples) * dt.to_value(u.ns)
duration = (self.extra_samples + n_samples) * dt
t = np.arange(-self.extra_samples, n_samples) * dt.to_value(u.ns)
mean_added_nsb = (self.added_nsb_fraction * self.original_nsb[tel_id] * duration).to_value("")
additional_nsb = self.rng.poisson(mean_added_nsb, n_pixels)
added_nsb_time = self.rng.uniform(-n * dt.to_value(u.ns), -n * dt.to_value(u.ns) + duration.to_value(u.ns),
added_nsb_time = self.rng.uniform(-self.extra_samples * dt.to_value(u.ns),
-self.extra_samples * dt.to_value(u.ns) + duration.to_value(u.ns),
(n_pixels, max(additional_nsb)))
added_nsb_amp = self.charge_spe_cumulative_pdf(self.rng.uniform(size=(n_pixels, max(additional_nsb))))
baseline_correction = (self.added_nsb_fraction * self.original_nsb[tel_id] * dt).to_value("")
waveform -= baseline_correction
waveform += nsb_only_waveforms(
time=t[n:],
time=t[self.extra_samples:],
is_high_gain=is_high_gain,
additional_nsb=additional_nsb,
amplitude=added_nsb_amp,
Expand Down

0 comments on commit a294418

Please sign in to comment.