From b810329e243da94fbbb6e54cf550aa63affffe1e Mon Sep 17 00:00:00 2001 From: Lanqing Yuan Date: Mon, 22 Apr 2024 14:15:05 -0500 Subject: [PATCH] Minimal example notebook (#121) * readme * bump --- notebooks/README.md | 3 + notebooks/example_minimal.ipynb | 284 ++++++++++++++++++++++++++++++++ saltax/__init__.py | 2 +- saltax/instructions/__init__.py | 2 +- saltax/match/__init__.py | 2 +- setup.py | 2 +- 6 files changed, 291 insertions(+), 4 deletions(-) create mode 100644 notebooks/example_minimal.ipynb diff --git a/notebooks/README.md b/notebooks/README.md index a06d3c0..a055848 100644 --- a/notebooks/README.md +++ b/notebooks/README.md @@ -1,6 +1,9 @@ # Notebooks These are notebooks for hopefully pedagogical purpose. Due to the sensitive information, all the outputs have been removed. +## `example_minimal.ipynb` +Quick start to get a glance at the physical scope of this package. + ## `example_events.ipynb` An example of using this framework to sprinkle events into real data, with followed analysis functions defined in this package. This notebook is using the `wfsim` based method. diff --git a/notebooks/example_minimal.ipynb b/notebooks/example_minimal.ipynb new file mode 100644 index 0000000..fb8c58d --- /dev/null +++ b/notebooks/example_minimal.ipynb @@ -0,0 +1,284 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a5455317-96ee-4586-a994-b029e6ffd853", + "metadata": {}, + "source": [ + "This is a minimal example illustrating what `saltax` can give you. \n", + "\n", + "Lanqing, Apr 22 2024" + ] + }, + { + "cell_type": "markdown", + "id": "25189e27-34bb-4107-b052-ec205aa59c08", + "metadata": {}, + "source": [ + "There will be 3 datasets in the end:\n", + "- `data`: Exactly the same as `v14` offline real data.\n", + "- `simulation`: Events reconstructed using the simulation instruction only, there is nothing else in the reconstruction process.\n", + "- `sprinkled`: Events reconstructed by mixing simulation and data. Some time it is also called `salt` and they mean the same thing. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f36c94c5-db4b-4612-8fee-426115b5f655", + "metadata": {}, + "outputs": [], + "source": [ + "import saltax\n", + "import strax\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "markdown", + "id": "c5d11265-ec2e-4660-b7ae-edc437e6c704", + "metadata": {}, + "source": [ + "Now let's define contexts in the `saltax` fasion. Here we define a `fuse`-based context. If you want a `wfsim`-based context, just do `sxenonnt` instead." + ] + }, + { + "cell_type": "markdown", + "id": "c19b2c9c-2495-4fa0-915e-e6a04a983160", + "metadata": {}, + "source": [ + "Once you define the contexts below, it will\n", + "- Try to fetch simulation instruction specified by the context\n", + "- If no instruction found, generate simulation instruction in `wfsim` format (even for `fuse`-based context. The translation to `fuse` instruction format happen later when you compute `microphysics_summary`)\n", + "- Register the `saltax` plugins as well as the `cutax` and `straxen` standard ones if not replaced." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "36da7cbc-4153-431f-99d0-8608f8d08610", + "metadata": {}, + "outputs": [], + "source": [ + "# You only need runid in context when you need to compute raw_records_simu\n", + "# salt mode: reconstruction from a mixture of data and simulation\n", + "st_salt = saltax.contexts.fxenonnt(runid=37119, saltax_mode=\"salt\")\n", + "# simu mode: reconstruction from simulation only\n", + "st_simu = saltax.contexts.fxenonnt(runid=37119, saltax_mode=\"simu\")" + ] + }, + { + "cell_type": "markdown", + "id": "5fd19212-0d3a-4204-8723-5637c145094a", + "metadata": {}, + "source": [ + "By default, the context above will simuilate flat beta ER band at 50 Hz." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "281ea430-f7d6-4530-8408-f34def5ea82a", + "metadata": {}, + "outputs": [], + "source": [ + "saltax.contexts.fxenonnt??" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3f5babb5-f65b-46c7-98a6-97d1f67bb76a", + "metadata": {}, + "outputs": [], + "source": [ + "# Just to bind the storage so we have access to the raw_records of a small run\n", + "st_salt.storage.append(strax.DataDirectory(\"/project2/lgrandi/tutorial_data\", readonly=True))\n", + "st_simu.storage.append(strax.DataDirectory(\"/project2/lgrandi/tutorial_data\", readonly=True))" + ] + }, + { + "cell_type": "markdown", + "id": "0306fe19-4582-4cc8-83af-c2bbfdaf7029", + "metadata": {}, + "source": [ + "You can take a look that some plugins are replaced while some are not." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "08d5449a-bad2-422f-89be-596b1d6b879a", + "metadata": {}, + "outputs": [], + "source": [ + "st_simu._plugin_class_registry['peaklets']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a975a0b0-f3d9-40ea-8ad8-bffd9512a9f0", + "metadata": {}, + "outputs": [], + "source": [ + "st_simu._plugin_class_registry['microphysics_summary']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee0860ef-53c8-4f86-937d-0b4d9d44c163", + "metadata": {}, + "outputs": [], + "source": [ + "st_simu._plugin_class_registry['event_info']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73f6e92b-4718-40f4-9762-e3e3309e0807", + "metadata": {}, + "outputs": [], + "source": [ + "st_simu._plugin_class_registry['cuts_basic']" + ] + }, + { + "cell_type": "markdown", + "id": "0b0c377c-48a5-49c9-8b6f-e11fb8143a60", + "metadata": {}, + "source": [ + "Now let's make some data! Note that both contexts have the same hashes until `peaklets`, where the merging happens." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15372275-acf9-412e-97d9-aba90755b24b", + "metadata": {}, + "outputs": [], + "source": [ + "st_salt.key_for(\"037119\", \"peaklets\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b7f5a7c4-adcd-407c-a2ee-88bc4b213683", + "metadata": {}, + "outputs": [], + "source": [ + "st_simu.key_for(\"037119\", \"peaklets\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7df90ab2-6888-43ea-9ba8-88102121fd7f", + "metadata": {}, + "outputs": [], + "source": [ + "st_salt.key_for(\"037119\", \"records\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "02f4a528-15c1-4185-af75-0b17e0a2bf7e", + "metadata": {}, + "outputs": [], + "source": [ + "st_simu.key_for(\"037119\", \"records\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c7a6d7d2-05f4-431b-ab6d-52606b1ad73b", + "metadata": {}, + "outputs": [], + "source": [ + "dtypes = [\"microphysics_summary\", \"raw_records_simu\", \"records\", \n", + " \"peaklets\", \"peak_basics\", \"events\", \"event_basics\", \"event_info\"]\n", + "for dt in dtypes:\n", + " st_salt.make(\"037119\", dt, save=(dt))\n", + "for dt in dtypes:\n", + " st_simu.make(\"037119\", dt, save=(dt))" + ] + }, + { + "cell_type": "markdown", + "id": "08f38a56-e888-418a-a37e-a23230dfe092", + "metadata": {}, + "source": [ + "Let's take a quick look." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21f5ad92-faa9-413d-a456-362852c54830", + "metadata": {}, + "outputs": [], + "source": [ + "events_simu = st_simu.get_array(\"037119\", \"event_info\")\n", + "events_salt = st_salt.get_array(\"037119\", \"event_info\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f3617cb5-48dc-4a11-a7f4-41635a28c2ae", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure(dpi=150)\n", + "plt.scatter(events_salt['cs1'], events_salt['cs2'], alpha=0.5, label=\"Sprinkled Dataset\")\n", + "plt.scatter(events_simu['cs1'], events_simu['cs2'], alpha=0.5, label=\"Simulated Dataset\")\n", + "plt.legend()\n", + "plt.xlim(0,100)\n", + "plt.ylim(0,6000)\n", + "plt.xlabel(\"CS1 [PE]\")\n", + "plt.ylabel(\"CS2 [PE]\")" + ] + }, + { + "cell_type": "markdown", + "id": "c5a9e3a3-321b-4526-9f7a-06ce6c05a587", + "metadata": {}, + "source": [ + "In an ideal worlad without ambience interference, all the orange dots will be fully overlapped with a blue dot. However, it seems not from the plot. You now starts to see what is ambience interference. See [here](https://xe1t-wiki.lngs.infn.it/doku.php?id=lanqing:ambience_interference_and_sprinkling) for details." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3e6c1af3-b248-46ff-b840-cbaf4dfcdb97", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.19" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/saltax/__init__.py b/saltax/__init__.py index ef2f1aa..d48dd5e 100644 --- a/saltax/__init__.py +++ b/saltax/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.0" +__version__ = "0.1.1" from . import instructions from .instructions import * diff --git a/saltax/instructions/__init__.py b/saltax/instructions/__init__.py index f68c943..d27796c 100644 --- a/saltax/instructions/__init__.py +++ b/saltax/instructions/__init__.py @@ -1,3 +1,3 @@ -__version__ = "0.1.0" +__version__ = "0.1.1" from . import generator from .generator import * diff --git a/saltax/match/__init__.py b/saltax/match/__init__.py index eda09cd..ac27e56 100644 --- a/saltax/match/__init__.py +++ b/saltax/match/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.1.0" +__version__ = "0.1.1" from . import match from .match import * from . import visual diff --git a/setup.py b/setup.py index f09cec4..a2f0971 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ author="Lanqing Yuan", description="Salting analysis framework for XENONnT.", long_description=readme, - version="0.1.0", + version="0.1.1", install_requires=requires, setup_requires=["pytest-runner"], tests_require=requires + ["pytest", "hypothesis", "boltons"],