Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chunking bug with empty instruction #183

Open
mhliu0001 opened this issue Mar 29, 2024 · 0 comments
Open

Chunking bug with empty instruction #183

mhliu0001 opened this issue Mar 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mhliu0001
Copy link
Contributor

Strax complains about data not being continuous with an empty instruction. Here is how to reproduce it:

import os
import shutil
import unittest
import tempfile
import timeout_decorator
import fuse
from _utils import build_random_csv_input

TIMEOUT = 240


class TestDetectorPhysicsCsv(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.temp_dir = tempfile.TemporaryDirectory()

        cls.test_context = fuse.context.full_chain_context(
            output_folder=cls.temp_dir.name, run_without_proper_corrections=True
        )

        cls.input_file = os.path.join(cls.temp_dir.name, "test.csv")

        cls.test_context.set_config(
            {
                "path": cls.temp_dir.name,
                "file_name": "test.csv",
            }
        )

        cls.run_number = "TestRun_00000"

    @classmethod
    def tearDownClass(cls):
        cls.temp_dir.cleanup()

    def setUp(self):
        detectorphysics_instructions = build_random_csv_input(1)
        detectorphysics_instructions["zp"] = 1
        detectorphysics_instructions.to_csv(self.input_file, index=False)

        assert os.path.exists(self.input_file)

    def tearDown(self):
        # self.temp_dir.cleanup()
        shutil.rmtree(self.temp_dir.name)
        os.makedirs(self.temp_dir.name)

    @timeout_decorator.timeout(
        TIMEOUT, exception_message="PMTResponseAndDAQ with empty input timed out"
    )
    def test_PMTResponseAndDAQ_CsvInput(self):
        self.test_context.make(self.run_number, "raw_records")


if __name__ == "__main__":
    unittest.main()
def build_random_csv_input(n):
    """Build a random input with electron ionization.
    
    This should be used in micro_physics.ChunkInput.
    Returns a Pandas Dataframe.
    
    Args:
        n (int): number of instructions to generate
    """
    df = pd.DataFrame()
    r = np.sqrt(np.random.uniform(0, 250000, n))
    t = np.random.uniform(-np.pi, np.pi, n)
    df["xp"] = r * np.cos(t)
    df["yp"] = r * np.sin(t)
    df["zp"] = np.random.uniform(-1500, -10, n)
    df["xp_pri"] = df["xp"]
    df["yp_pri"] = df["yp"]
    df["zp_pri"] = df["zp"]
    df["time"] = np.zeros(n)
    df["ed"] = np.random.uniform(1, 100, n)
    df["type"] = "e-"
    df["trackid"] = 0
    df["parenttype"] = "None"
    df["parentid"] = 0
    df["creaproc"] = "None"
    df["edproc"] = "eIoni"
    df["eventid"] = np.arange(n)
    
    return df

In this code I build a random csv input with a single interaction higher than the liquid level. Then, interactions_in_roi will be empty.

This is a rare case, but it might be necessary to look at how fuse produce chunks.

@mhliu0001 mhliu0001 added the bug Something isn't working label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant