Skip to content
Snippets Groups Projects
Commit bb6437ab authored by Johannes Schumann's avatar Johannes Schumann
Browse files

Plotting of particle occurences

parent 2131bf83
No related branches found
No related tags found
1 merge request!1Merge python environment
Pipeline #11484 failed
...@@ -22,7 +22,6 @@ import os ...@@ -22,7 +22,6 @@ import os
import time import time
import numpy as np import numpy as np
import km3pipe as kp import km3pipe as kp
import matplotlib.pyplot as plt
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from os.path import dirname, abspath from os.path import dirname, abspath
from collections import defaultdict from collections import defaultdict
...@@ -102,23 +101,49 @@ def worker(energy, Z, anti_flag=False): ...@@ -102,23 +101,49 @@ def worker(energy, Z, anti_flag=False):
def plot(datafile, plotfile): def plot(datafile, plotfile):
import h5py import h5py
f = h5py.File(datafile, 'r') import matplotlib.pyplot as plt
data = f['xsec'][()] from matplotlib.backends.backend_pdf import PdfPages
data = data[['energy', 'Z', 'sum']] import matplotlib.colors as colors
energies = np.sort(np.unique(data['energy'])) with PdfPages(plotfile) as pdf:
Zrange = np.sort(np.unique(data['Z'])) f = h5py.File(datafile, 'r')
fig, ax = plt.subplots() data = f['xsec'][()]
h = ax.hist2d(x=data['energy'], data = data[['energy', 'Z', 'sum']]
y=data['Z'], energies = np.sort(np.unique(data['energy']))
bins=(energies, Zrange), Zrange = np.sort(np.unique(data['Z']))
weights=np.divide(data['sum'], data['energy'])) fig, ax = plt.subplots()
cb = plt.colorbar(h[3], ax=ax) h = ax.hist2d(x=data['energy'],
cb.ax.get_yaxis().labelpad = 15 y=data['Z'],
cb.ax.set_ylabel(r"$\nu$ Crosssection / E [$10^-38cm^{cm^2}/GeV$]") bins=(energies, Zrange),
plt.xlabel("Energy [GeV]") weights=np.divide(data['sum'], data['energy']))
plt.ylabel(r"Z") cb = plt.colorbar(h[3], ax=ax)
plt.xscale('log') cb.ax.get_yaxis().labelpad = 15
plt.savefig(plotfile) cb.ax.set_ylabel(r"$\nu$ Crosssection / E [$10^-38cm^{cm^2}/GeV$]")
plt.xlabel("Energy [GeV]")
plt.ylabel(r"Z")
plt.xscale('log')
pdf.savefig()
plt.close()
data = f['particles'][()]
data = data[['energy', 'Z', 'multiplicity', 'particles']]
particle_ids = np.unique(data['particles'])
for p in particle_ids:
mask = data['particles'] == p
fig, ax = plt.subplots()
tmp = data[mask]
h = ax.hist2d(x=tmp['energy'],
y=tmp['Z'],
bins=(energies, Zrange),
weights=tmp['multiplicity'],
norm=colors.LogNorm())
cb = plt.colorbar(h[3], ax=ax)
cb.ax.get_yaxis().labelpad = 15
cb.ax.set_ylabel(r"Particle Count")
plt.xlabel("Energy [GeV]")
plt.ylabel(r"Z")
plt.xscale('log')
plt.title('Particle %s' % p)
pdf.savefig()
plt.close()
class GiBUUTaskPump(kp.Module): class GiBUUTaskPump(kp.Module):
...@@ -173,7 +198,7 @@ def main(): ...@@ -173,7 +198,7 @@ def main():
if args['--Zmax']: if args['--Zmax']:
Zmax = int(args['--Zmax']) Zmax = int(args['--Zmax'])
energies = np.logspace(-1, 2, 100) energies = np.logspace(-1, 3, 100)
Zrange = range(Zmin, Zmax + 1) Zrange = range(Zmin, Zmax + 1)
tasks = {} tasks = {}
with ThreadPoolExecutor(max_workers=workers) as executor: with ThreadPoolExecutor(max_workers=workers) as executor:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment