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

Public config #288

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
200 changes: 200 additions & 0 deletions examples/6_Public_Config.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Public Config\n",
"\n",
"fuse now supports to run simulations with a public configuration file resembling the ones used for simulations within the XENONnT collaboration. Where ever possible we set the configuration values to values published in XENON papers. For resources like e.g. maps we use dummy inputs with fixed values. Simulations with the public configuration file will not be able to fully simulate the XENONnT detector but they can be used to get a starting point for simulations of a similar detector or to work on reconstruction algorithms based on data similar to XENONnT data."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports and Data Preparation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import fuse\n",
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Similar to example 3_csv_input we will run a small simulation with mono energetic gammas. First we create a csv file listing the energy deposits of the gammas. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def monoenergetic_source(n, energy): # number of photons, energy of photons\n",
" df = pd.DataFrame()\n",
"\n",
" # radius and depth are in mm for microphysics instructions\n",
" r = np.sqrt(np.random.uniform(0, 435600, n)) # 435600 = radius of TPC in mm^2\n",
" theta = np.random.uniform(-np.pi, np.pi, n)\n",
" df[\"xp\"] = r * np.cos(theta)\n",
" df[\"yp\"] = r * np.sin(theta)\n",
" df[\"zp\"] = np.random.uniform(-1500, 0, n) # 0 is the position of the gate electrode\n",
"\n",
" df[\"xp_pri\"] = df[\"xp\"]\n",
" df[\"yp_pri\"] = df[\"yp\"]\n",
" df[\"zp_pri\"] = df[\"zp\"]\n",
"\n",
" df[\"ed\"] = np.array([energy] * n)\n",
" # if the times are all zero they are distributed according to source_rate by fuse\n",
" # custom interaction times in nanoseconds can also be used e.g np.arange(n)*1e9\n",
" df[\"time\"] = np.zeros(n)\n",
" df[\"eventid\"] = np.arange(n)\n",
"\n",
" df[\"type\"] = np.repeat(\"gamma\", n)\n",
"\n",
" df[\"trackid\"] = np.ones(n)\n",
" df[\"parentid\"] = np.zeros(n, dtype=np.int32)\n",
" df[\"creaproc\"] = np.repeat(\"None\", n)\n",
" df[\"parenttype\"] = np.repeat(\"None\", n)\n",
" df[\"edproc\"] = np.repeat(\"None\", n)\n",
"\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"microphysics_instructions = monoenergetic_source(100, 200)\n",
"microphysics_instructions.to_csv(\"monoenergetic_200keV.csv\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Simulation\n",
"\n",
"Now that we have some input data, we can set up the simulation config. This time we will use the new public_config_context. Resources for the simulation can be found in the files folder. Feel free to run simulations with your own configuration arguments and resources to see how your detector would react to the energy deposits!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"st = fuse.context.public_config_context(output_folder=\"./fuse_data\")\n",
"\n",
"st.set_config(\n",
" {\n",
" \"path\": \".\",\n",
" \"file_name\": \"monoenergetic_200keV.csv\",\n",
" \"n_interactions_per_chunk\": 250,\n",
" }\n",
")\n",
"\n",
"run_number = \"00000\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Running the Simulation\n",
"\n",
"First lets run the microphysics simulation. For more details please take a look at the corresponding example notebooks."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"st.make(\"00000\", \"microphysics_summary\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ms = st.get_df(\"00000\", \"microphysics_summary\")\n",
"ms.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we run the detector simulation up to raw_records."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"st.make(\"00000\", \"raw_records\")\n",
"rr = st.get_array(\"00000\", \"raw_records\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"single_rr = rr[0]\n",
"\n",
"\n",
"x = np.arange(110) * single_rr[\"dt\"]\n",
"\n",
"plt.plot(x, single_rr[\"data\"], color=\"black\", label=\"Records Data\")\n",
"plt.xlabel(\"Time (ns)\")\n",
"plt.ylabel(\"ADC\")\n",
"plt.legend()\n",
"\n",
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "work",
"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.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
601 changes: 601 additions & 0 deletions examples/files/Averaged_spe_distributions.csv

Large diffs are not rendered by default.

Binary file added examples/files/Poisson_noise.npz
Binary file not shown.
10 changes: 10 additions & 0 deletions examples/files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Public config files

This directory contains a public configuration for fuse. It ca be use to run fuse simulations with settings close to the XENONnT detector.

| File-name | Short description |Used for |
| --------- | --------- | --------- |
| `XENONnT_public_config.json` | Public XENONnT simulation configuration | Settings for all plugins |
| `Poisson_noise.json` | Randomly sampled noise | Waveform building |
| `Averaged_spe_distributions.json` | XENONnT SPE distributions averaged over all channels. | Waveform Building |
| `fake_to_pe.npy` | Constant dummy gain values | multiple places |
Loading