@@ -22,7 +22,7 @@ class PMTResponseAndDAQ(FuseBaseDownChunkingPlugin):
2222 length (if needed). Finally the data is saved as raw_records.
2323 """
2424
25- __version__ = "0.1.5 "
25+ __version__ = "0.1.6 "
2626
2727 depends_on = ("photon_summary" , "pulse_ids" , "pulse_windows" )
2828
@@ -254,6 +254,11 @@ def compute_chunk(self, photons, pulse_groups):
254254 )
255255 waveform_buffer = np .zeros (length_waveform_buffer , dtype = self .dtype )
256256
257+ # Generate a random offset for noise sampling to avoid systematic biases
258+ # when using fixed event spacing (where events at the same time would get identical noise)
259+ noise_len = self .noise_data ["arr_0" ].shape [0 ]
260+ noise_offset = self .rng .integers (0 , noise_len )
261+
257262 buffer_level = build_waveform (
258263 pulse_groups ,
259264 _photons ,
@@ -266,6 +271,7 @@ def compute_chunk(self, photons, pulse_groups):
266271 self .digitizer_reference_baseline ,
267272 self .thresholds ,
268273 self .trigger_window ,
274+ noise_offset ,
269275 )
270276
271277 records = waveform_buffer [:buffer_level ]
@@ -352,6 +358,7 @@ def build_waveform(
352358 digitizer_reference_baseline ,
353359 thresholds ,
354360 trigger_window ,
361+ noise_offset = 0 ,
355362):
356363 buffer_level = 0
357364
@@ -374,7 +381,7 @@ def build_waveform(
374381 if enable_noise :
375382 # Remember to transpose the noise...
376383 pulse_waveform_buffer = add_noise (
377- pulse_waveform_buffer , pulse ["time" ], noise_data [pulse ["channel" ]]
384+ pulse_waveform_buffer , pulse ["time" ], noise_data [pulse ["channel" ]], noise_offset
378385 )
379386
380387 add_baseline (pulse_waveform_buffer , digitizer_reference_baseline )
@@ -394,13 +401,13 @@ def build_waveform(
394401
395402
396403@njit (cache = True )
397- def add_noise (array , time , noise_in_channel ):
404+ def add_noise (array , time , noise_in_channel , noise_offset = 0 ):
398405 time = np .int64 (time / 10 )
399406
400407 len_data = len (array )
401408 len_noise = len (noise_in_channel )
402409
403- index = (time + np .arange (len_data ) + 1 ) % len_noise
410+ index = (time + noise_offset + np .arange (len_data ) + 1 ) % len_noise
404411
405412 return array + noise_in_channel [index ]
406413
0 commit comments