{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting Started\n", "In this notebook you will learn how to run your first simulation with fuse.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import fuse\n", "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setting up the simulation context\n", "\n", "Just like for our XENON analysis software, fuse simulations are run in a so called context. The context defines which plugins are used and how they are configured. For this tutorial we will run a so called \"full chain\" simulation. This means that our input will be a root file from a Geant4 simulation and our output will be raw_records. \n", "\n", "To build our context we can use the `xenonnt_fuse_full_chain_simulation` function provided by fuse. If you want a general public context you can take a look at the `public_config_context` context defined if `fuse.context`.\n", "\n", "After building the context we need to tell fuse which file to use as input. This is done via the config options `path` and `file_name`. To set these options we can use the `set_config` method of the context. Any other config option can be changed in the same way." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "st = fuse.context.xenonnt_fuse_full_chain_simulation(\n", " output_folder=\"./fuse_data\",\n", " simulation_config=\"sr0_dev\",\n", ")\n", "\n", "st.set_config(\n", " {\n", " \"path\": \"/project2/lgrandi/xenonnt/simulations/testing\",\n", " \"file_name\": \"pmt_neutrons_100.root\",\n", " \"entry_stop\": 10,\n", " }\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Running the simulation\n", "Now we have everything ready for the first simulation. We will tell fuse to simulate raw_records via the command `st.make(run_number, 'raw_records')`. The first argument is the run number, which is used to identify the data afterwards. The second argument is the data type we want to simulate and save. We can in principle use any run_number we like." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "run_number = \"00000\"\n", "st.make(run_number, \"raw_records\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With default settings fuse will only save `microphysics_summary`and `raw_records`. The first one is the output of the microphysics simulation corresponding to the previously used epix software. The second one is the output of the full chain simulation (microphysics, detector physics and PMT + DAQ simulation) corresponding to the output of WFSin. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Loading the data\n", "Now that our simulation finished we can load the simulaiton result. This is also done via the methods strax provides. You can either use `st.get_array(run_number, \"target)` to get the data in numpy format or use `st.get_df(run_number, \"target\")` to get a pandas dataframe. Please note that not all data types can be loaded as dataframe. First lets look at the output of the microphysics simulation. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "microphysics_summary = st.get_df(run_number, \"microphysics_summary\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "microphysics_summary.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lets look at the `raw_records` next. They need to be loaded as numpy array. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "raw_records = st.get_array(run_number, \"raw_records\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will end this notebook with a simple plot of one `raw_record`. If you want to learn more about fuse, please have a look at the other notebooks." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "record_to_plot = raw_records[42]\n", "\n", "time = np.linspace(\n", " record_to_plot[\"time\"],\n", " record_to_plot[\"time\"] + record_to_plot[\"length\"] * record_to_plot[\"dt\"],\n", " record_to_plot[\"length\"],\n", ")\n", "\n", "plt.plot(time, record_to_plot[\"data\"][0 : record_to_plot[\"length\"]])\n", "\n", "plt.xlabel(\"Time (ns)\")\n", "plt.ylabel(\"Amplitude (ADC)\")\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }