Skip to content

Commit

Permalink
Minimal example notebook (#121)
Browse files Browse the repository at this point in the history
* readme

* bump
  • Loading branch information
FaroutYLq authored Apr 22, 2024
1 parent ade44ce commit b810329
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 4 deletions.
3 changes: 3 additions & 0 deletions notebooks/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
284 changes: 284 additions & 0 deletions notebooks/example_minimal.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion saltax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1.0"
__version__ = "0.1.1"

from . import instructions
from .instructions import *
Expand Down
2 changes: 1 addition & 1 deletion saltax/instructions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
from . import generator
from .generator import *
2 changes: 1 addition & 1 deletion saltax/match/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
from . import match
from .match import *
from . import visual
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit b810329

Please sign in to comment.