Пример #1
0
    def test_apply_to_hits_from_km3io(self):
        calib = Calibration(filename=data_path("detx/km3net_offline.detx"))
        hits = km3io.OfflineReader(data_path("offline/km3net_offline.root"))[0].hits

        chits = calib.apply(hits)
        assert 176 == len(chits.t0)
        assert np.allclose([207747.825, 207745.656, 207743.836], chits.t0.tolist()[:3])

        chits = calib.apply(hits[:3])
        assert 3 == len(chits.t0)
        assert np.allclose([207747.825, 207745.656, 207743.836], chits.t0.tolist()[:3])
Пример #2
0
    def test_detx_format_comments(self):
        det = Detector(filename=data_path("detx/detx_v1.detx"))
        assert len(det.comments) == 0

        det = Detector(filename=data_path("detx/detx_v2.detx"))
        assert len(det.comments) == 0

        det = Detector(filename=data_path("detx/detx_v3.detx"))
        assert len(det.comments) == 2
        assert " a comment line" == det.comments[0]
        assert " another comment line starting with '#'" == det.comments[1]
Пример #3
0
    def test_apply_to_hits_from_km3io_iterator(self):
        calib = Calibration(filename=data_path("detx/km3net_offline.detx"))
        f = km3io.OfflineReader(data_path("offline/km3net_offline.root"))

        for event in f:
            chits = calib.apply(event.hits)
            assert 176 == len(chits.t0)
            assert np.allclose(
                [207747.825, 207745.656, 207743.836], chits.t0.tolist()[:3]
            )
            break
Пример #4
0
    def test_correct_slewing(self):

        hits = Table(
            {
                "dom_id": [2, 3, 3],
                "channel_id": [0, 1, 2],
                "time": [10.1, 11.2, 12.3],
                "tot": [0, 10, 255],
            }
        )

        tester = self

        class HitCalibrator(Module):
            def process(self, blob):
                self.services["correct_slewing"](hits)

                a_hit = hits[0]
                tester.assertAlmostEqual(10.1 - slew(a_hit.tot), a_hit.time)

                a_hit = hits[1]
                tester.assertAlmostEqual(11.2 - slew(a_hit.tot), a_hit.time)
                return blob

        pipe = Pipeline()
        pipe.attach(CalibrationService, filename=data_path("detx/detx_v1.detx"))
        pipe.attach(HitCalibrator)
        pipe.drain(1)
Пример #5
0
    def test_apply_to_hits_with_dom_id_and_channel_id_with_wrong_calib_raises(self):
        calib = Calibration(filename=data_path("detx/detx_v1.detx"))

        hits = Table({"dom_id": [999], "channel_id": [0], "time": [10.1]})

        with self.assertRaises(KeyError):
            calib.apply(hits, correct_slewing=False)
Пример #6
0
 def test_blob_in_io_sum(self):
     p = DAQPump(filename=data_path("daq/IO_SUM.dat"))
     blob = p.next_blob()
     assert "DAQSummaryslice" in blob.keys()
     assert "DAQPreamble" in blob.keys()
     assert "DAQHeader" in blob.keys()
     assert 33 == blob["DAQSummaryslice"].n_summary_frames
Пример #7
0
 def test_assert_apply_adds_pmt_id_to_hits(self):
     calib = Calibration(filename=data_path("detx/detx_v1.detx"))
     hits = Table(
         {"dom_id": [2, 3, 3], "channel_id": [0, 1, 2], "time": [10.1, 11.2, 12.3]}
     )
     chits = calib.apply(hits, correct_slewing=False)
     self.assertListEqual([4, 8, 9], list(chits.pmt_id))
Пример #8
0
    def test_get_item(self):
        p = DAQPump(filename=data_path("daq/IO_EVT.dat"))
        blob = p[0]
        event = blob["DAQEvent"]
        assert 182 == event.n_triggered_hits
        assert 239 == event.n_snapshot_hits
        assert np.allclose(
            [806451572, 806455814, 806455814, 806483369, 806483369],
            event.triggered_hits.dom_id[:5],
        )
        assert np.allclose([23, 14, 24, 6, 11],
                           event.triggered_hits.channel_id[:5])
        assert np.allclose(
            [40380598, 40380623, 40380551, 40380835, 40380920],
            event.triggered_hits.time[:5],
        )
        assert np.allclose([4, 4, 4, 4, 22],
                           event.triggered_hits.trigger_mask[:5])

        assert np.allclose(
            [806451572, 806455814, 806455814, 806483369, 806483369],
            event.triggered_hits.dom_id[:5],
        )
        assert np.allclose([23, 17, 14, 24, 6],
                           event.snapshot_hits.channel_id[:5])
        assert np.allclose(
            [40380598, 40380623, 40380551, 40380835, 40380920],
            event.triggered_hits.time[:5],
        )
Пример #9
0
 def test_detx_v5(self):
     det = Detector(filename=data_path("detx/detx_v5.detx"))
     assert np.allclose([464.4, 564.7, 190.583],
                        det.dom_positions[808956908],
                        atol=1e-2)
     assert np.allclose([464.4, 564.7, 95.389],
                        det.dom_positions[808981864],
                        atol=1e-2)
     assert det.n_doms == 114
     assert det.det_id == 49
     assert det.n_pmts_per_dom == 31
     assert det.n_dus == 6
     assert np.allclose(
         det.doms[808981864],
         [
             1.0000000e01,
             8.0000000e00,
             3.1000000e01,
             4.6440000e02,
             5.6470000e02,
             9.5389000e01,
             9.9995400e-01,
             -7.8470000e-03,
             3.9110000e-03,
             4.0080000e-03,
             0.0000000e00,
             3.7861343e04,
         ],
         atol=1e-2,
     )
     assert np.allclose(
         np.array([
             [484.6, 564.65],
             [464.4, 564.7],
             [442.5, 567.45],
             [474.15, 583.45],
             [454.2, 583.0],
             [431.1, 583.5],
         ]),
         det.xy_positions,
     )
     assert np.allclose(
         [
             3,
             0.73205,
             0.614161,
             0.29479,
             808981864,
             10,
             8,
             13367,
             464.546,
             564.823,
             95.448,
             0,
             207862.961,
         ],
         list(det.get_pmt(808981864, 3)),
     )
Пример #10
0
 def test_process(self):
     pump = RePump(filename=data_path("daq/IO_EVT.dat"))
     blob = pump.process({})
     assert 5724 == len(blob["RawBytes"])
     blob = pump.process({})
     assert 1950 == len(blob["RawBytes"])
     blob = pump.process({})
     assert 516 == len(blob["RawBytes"])
Пример #11
0
 def test_get_blob(self):
     fname = data_path("hdf5/test_event_info.h5")
     pump = HDF5Pump(filename=fname)
     assert 44 == len(pump[0]["McTracks"])
     assert 3 == len(pump[1]["McTracks"])
     assert 179 == len(pump[2]["McTracks"])
     assert 55 == len(pump[3]["McTracks"])
     pump.finish()
Пример #12
0
 def setUp(self):
     self.fname = data_path(
         "hdf5/mcv5.40.mupage_10G.sirene.jterbr00006060.962.root.h5"
     )
     self.fobj = tempfile.NamedTemporaryFile(delete=True)
     self.out = tb.open_file(
         self.fobj.name, "w", driver="H5FD_CORE", driver_core_backing_store=0
     )
Пример #13
0
    def test_apply_without_affecting_primary_hit_table(self):
        calib = Calibration(filename=data_path("detx/detx_v1.detx"))
        hits = Table({"pmt_id": [1, 2, 1], "time": [10.1, 11.2, 12.3]})
        hits_compare = hits.copy()
        calib.apply(hits, correct_slewing=False)

        for t_primary, t_calib in zip(hits_compare, hits):
            self.assertAlmostEqual(t_primary, t_calib)
Пример #14
0
 def test_blob_in_io_evt(self):
     p = DAQPump(filename=data_path("daq/IO_EVT_legacy.dat"), legacy=True)
     blob = p.next_blob()
     assert "DAQEvent" in blob.keys()
     assert "DAQPreamble" in blob.keys()
     assert "DAQHeader" in blob.keys()
     event = blob["DAQEvent"]
     assert 13 == event.n_triggered_hits
     assert 28 == event.n_snapshot_hits
Пример #15
0
 def test_l0(self):
     with open(data_path("daq/IO_TSL0_legacy.dat"), "rb") as fobj:
         ts_info, ts_frameinfos, ts_hits = TimesliceParser(
             legacy=True)._parse_timeslice(fobj)
     assert 200 == len(ts_hits)
     assert 25 == ts_hits[0].tot
     assert np.all(ts_hits.channel_id < 31)
     assert 808447031 == ts_hits[23].dom_id
     assert 232 == ts_info[0].frame_index
Пример #16
0
    def test_floors(self):
        calib = Calibration(filename=data_path("detx/detx_v1.detx"))

        hits = Table(
            {"dom_id": [2, 6, 3], "channel_id": [0, 1, 2], "time": [10.1, 11.2, 12.3]}
        )

        floors = calib.floors(hits)
        assert np.allclose([2, 3, 3], floors)
Пример #17
0
 def test_detx_format_version_1(self):
     det = Detector(filename=data_path("detx/detx_v1.detx"))
     assert 2 == det.n_dus
     assert 6 == det.n_doms
     assert 3 == det.n_pmts_per_dom
     assert 1 == det.version
     self.assertListEqual([1.1, 1.2, 1.3], list(det.pmts.pos[0]))
     self.assertListEqual([3.4, 3.5, 3.6], list(det.pmts.pos[7]))
     self.assertListEqual([23.4, 23.5, 23.6], list(det.pmts.pos[16]))
Пример #18
0
 def test_jdetectordb_output_with_detx_v3(self):
     det = Detector(
         data_path(
             "detx/D_ORCA006_t.A02181836.p.A02181837.r.A02182001.detx"))
     assert det.utm_info is not None
     assert det.utm_info.ellipsoid == "WGS84"
     assert det.utm_info.grid == "32N"
     assert det.utm_info.easting == 256500.0
     assert det.utm_info.northing == 4743000.0
     assert det.utm_info.z == -2440.0
Пример #19
0
    def test_apply_to_hits_with_pmt_id_aka_mc_hits_from_km3io(self):
        calib = Calibration(filename=data_path("detx/KM3NeT_-00000001_20171212.detx"))
        f = km3io.OfflineReader(
            data_path(
                "offline/mcv6.gsg_nue-CCHEDIS_1e4-1e6GeV.sirene.jte.jchain.aanet.1.root"
            )
        )

        for event in f:
            chits = calib.apply(event.mc_hits)
            assert 840 == len(chits.t0)
            assert np.allclose([3, 26, 24, 4, 23, 25], chits.channel_id[:6])
            assert np.allclose([3401, 3401, 3406, 3411, 5501, 5501], chits.dom_id[:6])
            assert np.allclose([1, 1, 6, 11, 1, 1], chits.floor[:6])
            assert np.allclose([34, 34, 34, 34, 55, 55], chits.du[:6])
            assert np.allclose(
                [
                    1679.18706571,
                    1827.14262054,
                    1926.71722628,
                    2433.83097585,
                    1408.35942832,
                    1296.51397496,
                ],
                chits.time[:6],
            )
            assert np.allclose(
                [2.034, 1.847, 1.938, 2.082, -54.96, -55.034], chits.pos_x[:6]
            )
            assert np.allclose(
                [-233.415, -233.303, -233.355, -233.333, -341.346, -341.303],
                chits.pos_y[:6],
            )
            assert np.allclose(
                [65.059, 64.83, 244.83, 425.111, 64.941, 64.83], chits.pos_z[:6]
            )
            assert np.allclose([4, 4, 4, 26, 4, 4], f.mc_hits.origin[0][:6].tolist())
            assert np.allclose(
                [36835, 36881, 37187, 37457, 60311, 60315],
                f.mc_hits.pmt_id[0][:6].tolist(),
            )
            break
Пример #20
0
 def test_header_from_hdf5_file(self):
     header = HDF5Header.from_hdf5(data_path("hdf5/raw_header.h5"))
     assert "MUSIC" == header.propag[0]
     assert "seawater" == header.propag[1]
     assert 3450 == header.seabottom[0]
     self.assertAlmostEqual(12.1, header.livetime.numberOfSeconds, places=3)
     self.assertAlmostEqual(0.09, header.livetime.errorOfSeconds, places=3)
     assert 0 == header.coord_origin.x
     assert 0 == header.coord_origin.y
     assert 0 == header.coord_origin.z
     self.assertTupleEqual((0, 0, 0), header.coord_origin)
Пример #21
0
    def test_provided_detector_data(self):
        class DetectorReader(Module):
            def process(self, blob):
                assert "get_detector" in self.services
                det = self.services["get_detector"]()
                assert isinstance(det, Detector)

        pipe = Pipeline()
        pipe.attach(CalibrationService, filename=data_path("detx/detx_v1.detx"))
        pipe.attach(DetectorReader)
        pipe.drain(1)
Пример #22
0
    def test_event_info_is_not_empty(self):
        self.fname = data_path("hdf5/test_event_info.h5")

        class Printer(Module):
            def process(self, blob):
                assert blob["EventInfo"].size != 0
                return blob

        p = Pipeline()
        p.attach(HDF5Pump, filename=self.fname)
        p.attach(Printer)
        p.drain()
Пример #23
0
 def test_detx_v4(self):
     det = Detector(filename=data_path("detx/detx_v4.detx"))
     assert np.allclose([119.6, -12.2, 192.77],
                        det.dom_positions[808956908],
                        atol=1e-2)
     assert np.allclose([119.6, -12.2, 97.44],
                        det.dom_positions[808981864],
                        atol=1e-2)
     assert det.n_doms == 90
     assert det.det_id == 44
     assert det.n_pmts_per_dom == 31
     assert det.n_dus == 5
     assert np.allclose(
         det.doms[808945480],
         [
             1,
             5,
             31,
             86.500,
             9.100,
             66.821,
             1.000000,
             0.000000,
             0.000000,
             0.000000,
             0.000,
         ],
         atol=1e-2,
     )
     assert np.allclose(
         np.array([[86.5, 9.1], [86.6, 6.6], [109.6, 5.9], [97.8, -9.6],
                   [119.6, -12.2]]),
         det.xy_positions,
     )
     assert np.allclose(
         [
             3,
             0.844,
             0.449,
             0.295,
             808981864,
             5,
             8,
             13367,
             119.768,
             -12.11,
             97.5,
             0,
             207863.242,
         ],
         list(det.get_pmt(808981864, 3)),
     )
Пример #24
0
    def setUp(self):
        self.track = {
            "pos_x": 1.7524502152598151,
            "pos_y": 39.06202405657308,
            "pos_z": 130.44049806891948,
            "dir_x": 0.028617421257374293,
            "dir_y": -0.489704257367248,
            "dir_z": -0.8714188335794505,
        }

        self.det = Detector(data_path("detx/detx_v3.detx"))

        pd = km3pipe.extras.pandas()

        self.DU = pd.DataFrame(self.det.dom_table).mean()
Пример #25
0
    def test_event_info_has_correct_group_id(self):
        self.fname = data_path("hdf5/test_event_info.h5")

        class Printer(Module):
            def configure(self):
                self.index = 0

            def process(self, blob):
                assert blob["EventInfo"][0].group_id == self.index
                self.index += 1
                return blob

        p = Pipeline()
        p.attach(HDF5Pump, filename=self.fname)
        p.attach(Printer)
        p.drain()
Пример #26
0
 def test_detx_format_version_3_with_whitespace(self):
     det = Detector(filename=data_path("detx/detx_v3_whitespace.detx"))
     assert 2 == det.n_dus
     assert 6 == det.n_doms
     assert 3 == det.n_pmts_per_dom
     assert 256500.0 == det.utm_info.easting
     assert 4743000.0 == det.utm_info.northing
     assert "WGS84" == det.utm_info.ellipsoid
     assert "32N" == det.utm_info.grid
     assert -2425.0 == det.utm_info.z
     assert 1500000000.1 == det.valid_from
     assert 9999999999.0 == det.valid_until
     assert 3 == det.version
     self.assertListEqual([1.1, 1.2, 1.3], list(det.pmts.pos[0]))
     self.assertListEqual([3.4, 3.5, 3.6], list(det.pmts.pos[7]))
     self.assertListEqual([23.4, 23.5, 23.6], list(det.pmts.pos[16]))
Пример #27
0
 def test_apply_to_timeslice_hits(self):
     tshits = Table.from_template(
         {
             "channel_id": [0, 1, 2],
             "dom_id": [2, 3, 3],
             "time": [10.1, 11.2, 12.3],
             "tot": np.ones(3, dtype=float),
             "group_id": 0,
         },
         "TimesliceHits",
     )
     calib = Calibration(filename=data_path("detx/detx_v1.detx"))
     c_tshits = calib.apply(tshits, correct_slewing=False)
     assert len(c_tshits) == len(tshits)
     assert np.allclose([40, 80, 90], c_tshits.t0)
     # TimesliceHits is using int4 for times, so it's truncated when we pass in float64
     assert np.allclose([50.1, 91.2, 102.3], c_tshits.time, atol=0.1)
Пример #28
0
    def test_apply_to_hits_with_pmt_id_aka_mc_hits(self):
        calib = Calibration(filename=data_path("detx/detx_v1.detx"))

        hits = Table({"pmt_id": [1, 2, 1], "time": [10.1, 11.2, 12.3]})

        chits = calib.apply(hits, correct_slewing=False)

        assert len(hits) == len(chits)

        a_hit = chits[0]
        self.assertAlmostEqual(1.1, a_hit.pos_x)
        self.assertAlmostEqual(10, a_hit.t0)
        self.assertAlmostEqual(10.1, a_hit.time)  # t0 should not bei applied

        a_hit = chits[1]
        self.assertAlmostEqual(1.4, a_hit.pos_x)
        self.assertAlmostEqual(20, a_hit.t0)
        self.assertAlmostEqual(11.2, a_hit.time)  # t0 should not be applied
Пример #29
0
    def test_events_legacy(self):
        dp = DAQProcessor(legacy=True)

        filename = data_path("daq/IO_EVT_legacy.dat")
        with open(filename, "rb") as fobj:
            data = fobj.read()
            blob = {}
            blob["CHData"] = data
            blob[
                "CHPrefix"] = lambda x: x  # quick and dirty thing to attach fields to
            blob["CHPrefix"].tag = "IO_EVT"

            blob = dp(blob)

            assert "Hits" in blob
            hits = blob["Hits"]
            assert 13 == sum(hits.triggered)
            assert 28 == len(hits)
Пример #30
0
    def test_calibration_in_pipeline(self):
        class DummyPump(kp.Module):
            def configure(self):
                self.index = 0

            def process(self, blob):
                self.index += 1
                mc_hits = Table({"pmt_id": [1, 2, 1], "time": [10.1, 11.2, 12.3]})
                hits = Table(
                    {
                        "dom_id": [2, 3, 3],
                        "channel_id": [0, 1, 2],
                        "time": [10.1, 11.2, 12.3],
                        "tot": [0, 10, 255],
                    }
                )

                blob["Hits"] = hits
                blob["McHits"] = mc_hits
                return blob

        _self = self

        class Observer(kp.Module):
            def process(self, blob):
                assert "Hits" in blob
                assert "McHits" in blob
                assert "CalibHits" in blob
                assert "CalibMcHits" in blob
                assert not hasattr(blob["Hits"], "pmt_id")
                assert hasattr(blob["CalibHits"], "pmt_id")
                assert not hasattr(blob["McHits"], "dom_id")
                assert hasattr(blob["CalibHits"], "dom_id")
                assert np.allclose([10.1, 11.2, 12.3], blob["Hits"].time)
                assert np.allclose([42.09, 87.31, 111.34], blob["CalibHits"].time)
                assert np.allclose(blob["McHits"].time, blob["CalibMcHits"].time)
                return blob

        pipe = kp.Pipeline()
        pipe.attach(DummyPump)
        pipe.attach(Calibration, filename=data_path("detx/detx_v1.detx"))
        pipe.attach(Observer)
        pipe.drain(3)