diff --git a/invisible_cities/cities/irene_test.py b/invisible_cities/cities/irene_test.py index a3f7a4151..ad17eb67c 100644 --- a/invisible_cities/cities/irene_test.py +++ b/invisible_cities/cities/irene_test.py @@ -25,6 +25,7 @@ from .. types.symbols import SiPMThreshold from .. database.load_db import DetDB +from .. database.load_db import DataSiPM from .. io .pmaps_io import load_pmaps from . irene import irene @@ -495,3 +496,44 @@ def test_irene_other_sample_widths(ICDATADIR, config_tmpdir): got = getattr( output_file.root, table) expected = getattr(true_output_file.root, table) assert_tables_equality(got, expected) + + +@ignore_warning.no_config_group +def test_irene_masked_sipms_pyrrha(ICDIR, config_tmpdir): + # Test that masked SiPMs are handled in Pyrrha + run_number = 16016 + + PATH_IN = os.path.join(ICDIR, 'database/test_data/', 'run_16016_0000_ldc1_trg0.waveforms_1evt.h5') + PATH_OUT = os.path.join(config_tmpdir, 'run_16016_0000_ldc1_trg0.waveforms_1evt_pmaps.h5') + + nrequired = 1 + + conf = configure('dummy invisible_cities/config/irene_pyrrha.conf'.split()) + cutting_params = conf['cutting_params'].copy() + cutting_params.update(run_number = run_number, + detector_db = DetDB.next100) + conf.update(dict(run_number = run_number, + detector_db = DetDB.next100, + files_in = PATH_IN, + file_out = PATH_OUT, + event_range = (0, nrequired), + cutting_params = cutting_params)) + + cnt = irene(**conf) + assert cnt.events_in > 0 + + # Find masked SiPMs in DB and compare to the PMAP output + detector_info = DataSiPM(DetDB.next100, run_number) + active_sipms = np.array(detector_info.Active).astype(bool) + masked_ids = set(np.where(~active_sipms)[0]) + + pmaps_out = load_pmaps(PATH_OUT) + + found_masked = [] + for evt, pmap in pmaps_out.items(): + for s2si in pmap.s2s: + for sipm_id in s2si.sipms.ids: + if sipm_id in masked_ids: + found_masked.append((evt, sipm_id)) + + assert not found_masked, (f"Masked SiPMs leaked through pyrrha: {found_masked}") diff --git a/invisible_cities/database/test_data/run_16016_0000_ldc1_trg0.waveforms_1evt.h5 b/invisible_cities/database/test_data/run_16016_0000_ldc1_trg0.waveforms_1evt.h5 new file mode 100644 index 000000000..479a297d8 --- /dev/null +++ b/invisible_cities/database/test_data/run_16016_0000_ldc1_trg0.waveforms_1evt.h5 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:868fbfa631384070f1dafecc2cf5f00315882df95d9c6414362304300a6e0f78 +size 10021820 diff --git a/invisible_cities/reco/wfm_functions.py b/invisible_cities/reco/wfm_functions.py index d13c15115..37759de01 100644 --- a/invisible_cities/reco/wfm_functions.py +++ b/invisible_cities/reco/wfm_functions.py @@ -318,9 +318,10 @@ def spatial_selection_method(wfs : np.ndarray, selected_ids : Array of shape (n_sipms,) containing the indices of the selected SiPMs. selected_wfs : 2D array of shape (n_selected_sipms, n_time_bins) with the waveforms of the selected SiPMs. """ - detector_info = load_db.DataSiPM(detector_db, run_number) - sipm_x = np.array(detector_info.X) - sipm_y = np.array(detector_info.Y) + detector_info = load_db.DataSiPM(detector_db, run_number) + active_sipms = detector_info.Active.values.astype(bool) + sipm_x = detector_info.X.values[active_sipms] + sipm_y = detector_info.Y.values[active_sipms] if selection_method is SiPMSelectionMethod.median_std_method: starting_ids = median_std_method(wfs, **selection_kwargs) @@ -347,4 +348,3 @@ def spatial_selection_method(wfs : np.ndarray, selected_wfs = wfs[selected_ids] return selected_ids, selected_wfs -