Skip to content

Commit

Permalink
Merge pull request #260 from AxFoundation/record_multiplier
Browse files Browse the repository at this point in the history
Add record amplitude bit shift
  • Loading branch information
JelleAalbers committed Apr 28, 2020
2 parents 64c9c73 + aa09361 commit 70da1c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions strax/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def record_dtype(samples_per_record=DEFAULT_RECORD_LENGTH):
'baseline'), np.float32),
(('Baseline RMS in ADC counts. data = baseline - data_orig',
'baseline_rms'), np.float32),
(('Multiply data by 2**(this number). Baseline is unaffected.',
'amplitude_bit_shift'), np.int16),
(('Waveform data in raw counts above integer part of baseline',
'data'), np.int16, samples_per_record),
]
Expand Down
8 changes: 5 additions & 3 deletions strax/processing/peak_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def sum_waveform(peaks, records, adc_to_pe):
for right_r_i in range(left_r_i, len(records)):
r = records[right_r_i]
ch = r['channel']
multiplier = 2**r['amplitude_bit_shift']
assert p['dt'] == r['dt'], "Records and peaks must have same dt"

shift = (p['time'] - r['time']) // dt
Expand All @@ -207,13 +208,14 @@ def sum_waveform(peaks, records, adc_to_pe):
r['time'] // dt, n_r,
p['time'] // dt, n_p)

max_in_record = r['data'][r_start:r_end].max()
p['saturated_channel'][ch] = int(max_in_record >= r['baseline'])
max_in_record = r['data'][r_start:r_end].max() * multiplier
p['saturated_channel'][ch] |= int(max_in_record >= r['baseline'])

bl_fpart = r['baseline'] % 1
# TODO: check numba does casting correctly here!
pe_waveform = adc_to_pe[ch] * (
r['data'][r_start:r_end] + bl_fpart)
multiplier * r['data'][r_start:r_end]
+ bl_fpart)

swv_buffer[p_start:p_end] += pe_waveform

Expand Down
5 changes: 3 additions & 2 deletions strax/processing/pulse_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def integrate(records):
return
for i, r in enumerate(records):
records[i]['area'] = (
r['data'].sum()
r['data'].sum() * 2**r['amplitude_bit_shift']
# Add floating part of baseline * number of samples
# int(round()) the result since the area field is an int
+ int(round((r['baseline'] % 1) * r['length'])))
Expand Down Expand Up @@ -249,6 +249,7 @@ def _find_hits(records, min_amplitude, min_height_over_noise,
min_amplitude[r['channel']],
r['baseline_rms'] * min_height_over_noise[r['channel']])
n_samples = r['length']
multiplier = 2**r['amplitude_bit_shift']

# If someone passes a length > n_samples record,
# and we don't abort here, numba will happily overrun the buffer!
Expand All @@ -258,7 +259,7 @@ def _find_hits(records, min_amplitude, min_height_over_noise,
# We can't use enumerate over r['data'],
# numba gives errors if we do.
# TODO: file issue?
x = r['data'][i]
x = r['data'][i] * multiplier

satisfy_threshold = x >= threshold
# print(x, satisfy_threshold, in_interval, hit_start)
Expand Down

0 comments on commit 70da1c5

Please sign in to comment.