Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 205 additions & 0 deletions icaro/analysis/monitoring/MCTruthMonitor.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# This notebook produces meaningful plots of the MC true information to monitor MC production "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import os\n",
"import sys\n",
"\n",
"import numpy as np\n",
"import tables as tb\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"\n",
"from invisible_cities.io.mchits_io import load_mchits\n",
"from invisible_cities.io.mchits_io import load_mcparticles\n",
"\n",
"from invisible_cities.database import load_db\n",
"\n",
"from invisible_cities.icaro.hst_functions import hist\n",
"from invisible_cities.icaro.hst_functions import hist2d\n",
"from invisible_cities.icaro.hst_functions import hist2d_profile\n",
"from invisible_cities.icaro.hst_functions import labels\n",
"\n",
"from invisible_cities.core.system_of_units_c import units"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"DetGeo = load_db.DetectorGeo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"energies = []\n",
"Xorigin = []\n",
"Yorigin = []\n",
"Zorigin = []\n",
"partE = []\n",
"numpart = []\n",
"for number in range(0,1):\n",
" for p in range(0,1):\n",
"\n",
" PATH_IN = \"/path/to/data/dst_NEXT_v1_00_05_Tl_ACTIVE_{0}_{1}_7bar_PMP_10000.h5\".format(number, p)\n",
" print('Analyzing file {}'.format(PATH_IN))\n",
" try:\n",
" load_mchits(PATH_IN)\n",
" except ValueError:\n",
" continue\n",
" except OSError:\n",
" continue\n",
" hit_dict = load_mchits(file_name)\n",
" for _, hits in hit_dict.items():\n",
" e = 0.\n",
" for hit in hits:\n",
" # Check that only the hits of the ACTIVE volume are considered\n",
" if hit.pos[2] < DetGeo.ZMAX[0] and hit.pos[0] < DetGeo.XMAX[0] and hit.pos[0] > DetGeo.XMIN[0]:\n",
" e += hit.E\n",
" Xorigin.append(hit.pos[0]) \n",
" Yorigin.append(hit.pos[1]) \n",
" Zorigin.append(hit.pos[2]) \n",
" energies.append(e)\n",
" particle_dict = load_mcparticles(PATH_IN)\n",
" \n",
" for ide, particles in particle_dict.items():\n",
" numpart.append(len(particles))\n",
" for _, p in particles.items():\n",
" partE.append(p.E)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Total energy of events"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure();\n",
"fig.set_figwidth(16.0)\n",
"fig.set_figheight(12.0)\n",
"plt.hist(energies, bins=1000, range=((0.,3)), label='Event energy')\n",
"plt.xlabel('Energy (MeV)')\n",
"plt.ylabel('Counts/bin')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## XY position of hits"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure();\n",
"ax1 = fig.add_subplot(111);\n",
"fig.set_figheight(10.0)\n",
"fig.set_figwidth(13.0)\n",
"\n",
"plt.hist2d(Xorigin,Yorigin, bins=100)\n",
"plt.colorbar()\n",
" \n",
"plt.xlabel(\"x (mm)\");\n",
"plt.ylabel(\"y (mm)\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## XZ position of hits "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure();\n",
"ax1 = fig.add_subplot(111);\n",
"fig.set_figheight(10.0)\n",
"fig.set_figwidth(13.0)\n",
"\n",
"plt.hist2d(Xorigin,Zorigin, bins=100)\n",
"plt.colorbar()\n",
" \n",
"plt.xlabel(\"x (mm)\");\n",
"plt.ylabel(\"z (mm)\");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Number of particles per event"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.hist(numpart, bins=30, label='Number of particles')\n",
"plt.xlabel('Number of particles in one event')\n",
"plt.ylabel('Counts/bin')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading