Skip to content

Commit

Permalink
828 Rename MAU to MAW
Browse files Browse the repository at this point in the history
#828

[author: gonzaponte]

Following the discussion in the documentation repository, we replace
the wording MAU to MAW (Moving Average Window).

[reviewer: paolafer]

Useful fix to make the code easier to understand.
  • Loading branch information
paolafer authored and MiryamMV committed Mar 14, 2023
2 parents 8be75c6 + aaa2234 commit 2530de2
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 62 deletions.
18 changes: 9 additions & 9 deletions invisible_cities/cities/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,16 +674,16 @@ def build_pmap(ccwf, s1_indx, s2_indx, sipmzs): # -> PMap
return build_pmap


def calibrate_pmts(dbfile, run_number, n_MAU, thr_MAU):
def calibrate_pmts(dbfile, run_number, n_maw, thr_maw):
DataPMT = load_db.DataPMT(dbfile, run_number = run_number)
adc_to_pes = np.abs(DataPMT.adc_to_pes.values)
adc_to_pes = adc_to_pes[adc_to_pes > 0]

def calibrate_pmts(cwf):# -> CCwfs:
return csf.calibrate_pmts(cwf,
adc_to_pes = adc_to_pes,
n_MAU = n_MAU,
thr_MAU = thr_MAU)
n_maw = n_maw,
thr_maw = thr_maw)
return calibrate_pmts


Expand All @@ -707,17 +707,17 @@ def calibrate_with_mean(wfs):
return csf.subtract_baseline_and_calibrate(wfs, adc_to_pes)
return calibrate_with_mean

def calibrate_with_mau(dbfile, run_number, n_mau_sipm):
def calibrate_with_maw(dbfile, run_number, n_maw_sipm):
DataSiPM = load_db.DataSiPM(dbfile, run_number)
adc_to_pes = np.abs(DataSiPM.adc_to_pes.values)
def calibrate_with_mau(wfs):
return csf.subtract_baseline_mau_and_calibrate(wfs, adc_to_pes, n_mau_sipm)
return calibrate_with_mau
def calibrate_with_maw(wfs):
return csf.subtract_baseline_maw_and_calibrate(wfs, adc_to_pes, n_maw_sipm)
return calibrate_with_maw


def zero_suppress_wfs(thr_csum_s1, thr_csum_s2):
def ccwfs_to_zs(ccwf_sum, ccwf_sum_mau):
return (pkf.indices_and_wf_above_threshold(ccwf_sum_mau, thr_csum_s1).indices,
def ccwfs_to_zs(ccwf_sum, ccwf_sum_maw):
return (pkf.indices_and_wf_above_threshold(ccwf_sum_maw, thr_csum_s1).indices,
pkf.indices_and_wf_above_threshold(ccwf_sum , thr_csum_s2).indices)
return ccwfs_to_zs

Expand Down
8 changes: 4 additions & 4 deletions invisible_cities/cities/irene.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

@city
def irene(files_in, file_out, compression, event_range, print_mod, detector_db, run_number,
n_baseline, n_mau, thr_mau, thr_sipm, thr_sipm_type,
n_baseline, n_maw, thr_maw, thr_sipm, thr_sipm_type,
s1_lmin, s1_lmax, s1_tmin, s1_tmax, s1_rebin_stride, s1_stride, thr_csum_s1,
s2_lmin, s2_lmax, s2_tmin, s2_tmax, s2_rebin_stride, s2_stride, thr_csum_s2, thr_sipm_s2,
pmt_samp_wid=25*units.ns, sipm_samp_wid=1*units.mus):
Expand All @@ -70,13 +70,13 @@ def irene(files_in, file_out, compression, event_range, print_mod, detector_db,
out = "cwf")

# Corrected WaveForm to Calibrated Corrected WaveForm
cwf_to_ccwf = fl.map(calibrate_pmts(detector_db, run_number, n_mau, thr_mau),
cwf_to_ccwf = fl.map(calibrate_pmts(detector_db, run_number, n_maw, thr_maw),
args = "cwf",
out = ("ccwfs", "ccwfs_mau", "cwf_sum", "cwf_sum_mau"))
out = ("ccwfs", "ccwfs_maw", "cwf_sum", "cwf_sum_maw"))

# Find where waveform is above threshold
zero_suppress = fl.map(zero_suppress_wfs(thr_csum_s1, thr_csum_s2),
args = ("cwf_sum", "cwf_sum_mau"),
args = ("cwf_sum", "cwf_sum_maw"),
out = ("s1_indices", "s2_indices", "s2_energies"))

# Remove baseline and calibrate SiPMs
Expand Down
14 changes: 7 additions & 7 deletions invisible_cities/cities/phyllis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
subtract the baseline.
- Using the standard deconvolution algorithm to remove the effect
of the electronics and to subtract the baseline.
- Using the deconvolution algorithm with a mau to remove the effect
- Using the deconvolution algorithm with a MAW to remove the effect
of the electronics and to subtract the baseline.
The tasks performed are:
- Subtract the baseline (only in the first case).
Expand Down Expand Up @@ -65,9 +65,9 @@ def phyllis(files_in, file_out, compression, event_range, print_mod, detector_db
proc_mode, n_baseline,
min_bin, max_bin, bin_width,
number_integrals, integral_start, integral_width, integrals_period,
n_mau = 100):
n_maw = 100):
if proc_mode == "gain" : proc = pmt_deconvolver (detector_db, run_number, n_baseline )
elif proc_mode == "gain_mau" : proc = pmt_deconvolver_mau(detector_db, run_number, n_baseline, n_mau)
elif proc_mode == "gain_maw" : proc = pmt_deconvolver_maw(detector_db, run_number, n_baseline, n_maw)
elif proc_mode == "gain_nodeconv": proc = mode_subtractor (detector_db, run_number)
else : raise ValueError(f"Unrecognized processing mode: {proc_mode}")

Expand Down Expand Up @@ -133,12 +133,12 @@ def pmt_deconvolver(detector_db, run_number, n_baseline):
return deconvolute


def pmt_deconvolver_mau(detector_db, run_number, n_baseline, n_mau):
def pmt_deconvolver_maw(detector_db, run_number, n_baseline, n_maw):
deconvolute = pmt_deconvolver(detector_db, run_number, n_baseline)
def deconv_pmt_mau(rwf):
def deconv_pmt_maw(rwf):
cwf = deconvolute(rwf)
return csf.pmt_subtract_mau(cwf, n_mau)
return deconv_pmt_mau
return csf.pmt_subtract_maw(cwf, n_maw)
return deconv_pmt_maw


def mode_subtractor(detector_db, run_number):
Expand Down
6 changes: 3 additions & 3 deletions invisible_cities/cities/phyllis_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .. core.testing_utils import assert_tables_equality


@mark.parametrize("proc_opt", ('gain', 'gain_mau', 'gain_nodeconv'))
@mark.parametrize("proc_opt", ('gain', 'gain_maw', 'gain_nodeconv'))
def test_phyllis_pulsedata(config_tmpdir, ICDATADIR, proc_opt):
PATH_IN = os.path.join(ICDATADIR , 'pmtledpulsedata.h5')
PATH_OUT = os.path.join(config_tmpdir, 'pmtledpulsedata_HIST.h5')
Expand All @@ -36,7 +36,7 @@ def test_phyllis_pulsedata(config_tmpdir, ICDATADIR, proc_opt):
evts_out = h5out.root.Run.events[:nrequired]
assert_array_equal(evts_in, evts_out)

assert 'Sensors' in h5out.root
assert 'Sensors' in h5out.root
ch_in_pmt = np.array(h5in .root.Sensors.DataPMT [:])
ch_out_pmt = np.array(h5out.root.Sensors.DataPMT [:])
ch_in_sipm = np.array(h5in .root.Sensors.DataSiPM[:])
Expand All @@ -45,7 +45,7 @@ def test_phyllis_pulsedata(config_tmpdir, ICDATADIR, proc_opt):
assert np.all(ch_in_sipm == ch_out_sipm)


@mark.parametrize("proc_opt", ('gain', 'gain_mau', 'gain_nodeconv'))
@mark.parametrize("proc_opt", ('gain', 'gain_maw', 'gain_nodeconv'))
def test_phyllis_exact_result(ICDATADIR, output_tmpdir, proc_opt):
file_in = os.path.join(ICDATADIR , "pmtledpulsedata.h5")
file_out = os.path.join(output_tmpdir, f"exact_result_phyllis_{proc_opt}.h5")
Expand Down
2 changes: 1 addition & 1 deletion invisible_cities/cities/trude.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def trude(files_in, file_out, compression, event_range, print_mod,
proc_mode,
min_bin, max_bin, bin_width,
number_integrals, integral_start, integral_width, integrals_period,
n_mau = 100):
n_maw = 100):
if proc_mode not in ("subtract_mode", "subtract_median"):
raise ValueError(f"Unrecognized processing mode: {proc_mode}")

Expand Down
2 changes: 1 addition & 1 deletion invisible_cities/config/hypathia.conf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ event_range = 0, 2
thr_csum_s1 = 0.5 * pes
thr_csum_s2 = 2.0 * pes

# Set MAU thresholds for SiPM
# Set thresholds for SiPM
thr_sipm = 1.0 * pes
thr_sipm_type = "common"

Expand Down
8 changes: 4 additions & 4 deletions invisible_cities/config/irene.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ event_range = 1

n_baseline = 28000 # for a window of 800 mus

# Set MAU for calibrated sum
n_mau = 100
thr_mau = 3 * adc
# Set MAW for calibrated sum
n_maw = 100
thr_maw = 3 * adc

# Set thresholds for calibrated sum
thr_csum_s1 = 0.5 * pes
thr_csum_s2 = 1.0 * pes

# Set MAU thresholds for SiPM
# Set thresholds for SiPM
thr_sipm = 3.5 * pes
thr_sipm_type = "common"

Expand Down
10 changes: 5 additions & 5 deletions invisible_cities/core/configure_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
nbaseline = {nbaseline}
thr_trigger = {thr_trigger}
# set_mau
nmau = {nmau}
thr_mau = {thr_mau}
# set_maw
n_maw = {n_maw}
thr_maw = {thr_maw}
# set_csum
thr_csum = {thr_csum}
Expand Down Expand Up @@ -73,8 +73,8 @@
nprint = 24,
nbaseline = 26,
thr_trigger = 27,
nmau = 28,
thr_mau = 29,
n_maw = 28,
thr_maw = 29,
thr_csum = .5,
s1_tmin = 31,
s1_tmax = 32,
Expand Down
8 changes: 4 additions & 4 deletions invisible_cities/database/test_data/config/irene.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ event_range = all

n_baseline = 48000 # for a window of 800 mus

# Set MAU for calibrated sum
n_mau = 100
thr_mau = 3 * adc
# Set MAW for calibrated sum
n_maw = 100
thr_maw = 3 * adc

# Set thresholds for calibrated sum
thr_csum_s1 = 0.5 * pes
thr_csum_s2 = 2.0 * pes

# Set MAU thresholds for SiPM
# Set thresholds for SiPM
thr_sipm = 1 * pes
thr_sipm_type = "common"

Expand Down
2 changes: 1 addition & 1 deletion invisible_cities/io/histogram_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def hist_writer(file,
*,
group_name : 'options: HIST, HIST2D',
table_name : 'options: pmt, pmtMAU, sipm, sipmMAU',
table_name : 'options: pmt, pmtMAW, sipm, sipmMAW',
n_sensors : 'number of pmts or sipms',
bin_centres : 'np.array of bin centres',
compression = None):
Expand Down
26 changes: 13 additions & 13 deletions invisible_cities/reco/calib_sensors_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,38 +108,38 @@ def subtract_baseline_and_calibrate(sipm_wfs, adc_to_pes, *, bls_mode=BlsMode.me
return calibrate_wfs(bls, adc_to_pes)


def calibrate_pmts(cwfs, adc_to_pes, n_MAU=100, thr_MAU=3):
def calibrate_pmts(cwfs, adc_to_pes, n_maw=100, thr_maw=3):
"""
This function is called for PMT waveforms that have
already been baseline restored and pedestal subtracted.
It computes the calibrated waveforms and its sensor sum.
It also computes the calibrated waveforms and sensor
sum for elements of the waveforms above some value
(thr_MAU) over a MAU that follows the waveform. These
(thr_maw) over a MAW that follows the waveform. These
are useful to suppress oscillatory noise and thus can
be applied for S1 searches (the calibrated version
without the MAU should be applied for S2 searches).
without the MAW should be applied for S2 searches).
"""
MAU = np.full(n_MAU, 1 / n_MAU)
mau = signal.lfilter(MAU, 1, cwfs, axis=1)
window = np.full(n_maw, 1 / n_maw)
maw = signal.lfilter(window, 1, cwfs, axis=1)

# ccwfs stands for calibrated corrected waveforms
ccwfs = calibrate_wfs(cwfs, adc_to_pes)
ccwfs_mau = np.where(cwfs >= mau + thr_MAU, ccwfs, 0)
ccwfs_maw = np.where(cwfs >= maw + thr_maw, ccwfs, 0)

cwf_sum = np.sum(ccwfs , axis=0)
cwf_sum_mau = np.sum(ccwfs_mau, axis=0)
return ccwfs, ccwfs_mau, cwf_sum, cwf_sum_mau
cwf_sum_maw = np.sum(ccwfs_maw, axis=0)
return ccwfs, ccwfs_maw, cwf_sum, cwf_sum_maw


def pmt_subtract_mau(cwfs, n_MAU=100):
def pmt_subtract_maw(cwfs, n_maw=100):
"""
Subtract a MAU from the input waveforms.
Subtract a MAW from the input waveforms.
"""
MAU = np.full(n_MAU, 1 / n_MAU)
mau = signal.lfilter(MAU, 1, cwfs, axis=1)
window = np.full(n_maw, 1 / n_maw)
maw = signal.lfilter(window, 1, cwfs, axis=1)

return cwfs - mau
return cwfs - maw


def calibrate_sipms(sipm_wfs, adc_to_pes, thr, *, bls_mode=BlsMode.mode):
Expand Down
20 changes: 10 additions & 10 deletions invisible_cities/reco/calib_sensors_functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_subtract_baseline_valid_options_sanity_check(gaussian_sipm_signal, bls_

@mark.parametrize("wrong_bls_mode",
(0, "0", 1, "1", None, "None",
"mean", "mau", "BlsMode.mean", "BlsMode.mau"))
"mean", "maw", "BlsMode.mean", "BlsMode.maw"))
def test_subtract_baseline_raises_TypeError(wrong_bls_mode):
dummy = np.empty((2, 2))
with raises(TypeError):
Expand Down Expand Up @@ -175,24 +175,24 @@ def test_calibrate_pmts_stat(oscillating_waveform_wo_baseline,
nsigma, fraction):
(wfs, adc_to_pes,
n_samples, noise_sigma) = oscillating_waveform_wo_baseline
n_mau = n_samples // 500
n_maw = n_samples // 500

(ccwfs , ccwfs_mau ,
cwf_sum, cwf_sum_mau) = csf.calibrate_pmts(wfs, adc_to_pes,
n_mau, nsigma * noise_sigma)
(ccwfs , ccwfs_maw ,
cwf_sum, cwf_sum_maw) = csf.calibrate_pmts(wfs, adc_to_pes,
n_maw, nsigma * noise_sigma)

# Because there is only one waveform, the sum and the
# waveform itself must be the same.
assert ccwfs .size == cwf_sum .size
assert ccwfs_mau.size == cwf_sum_mau.size
assert ccwfs_maw.size == cwf_sum_maw.size

assert ccwfs [0] == approx(cwf_sum)
assert ccwfs_mau[0] == approx(cwf_sum_mau)
assert ccwfs_maw[0] == approx(cwf_sum_maw)

assert wfs[0] / adc_to_pes[0] == approx(cwf_sum)

number_of_zeros = np.count_nonzero(cwf_sum_mau == 0)
assert number_of_zeros > fraction * cwf_sum_mau.size
number_of_zeros = np.count_nonzero(cwf_sum_maw == 0)
assert number_of_zeros > fraction * cwf_sum_maw.size


@mark.parametrize("nsigma fraction".split(),
Expand All @@ -204,7 +204,7 @@ def test_calibrate_sipms_stat(oscillating_waveform_with_baseline,
(wfs, adc_to_pes,
n_samples, noise_sigma,
baseline ) = oscillating_waveform_with_baseline
#n_mau = n_samples // 500
#n_maw = n_samples // 500

ccwfs = csf.calibrate_sipms(wfs, adc_to_pes, nsigma * noise_sigma, bls_mode=csf.BlsMode.mode)

Expand Down

0 comments on commit 2530de2

Please sign in to comment.