Skip to content
Snippets Groups Projects
Commit e6872721 authored by Jack Christopher Hutchinson Rolph's avatar Jack Christopher Hutchinson Rolph
Browse files

Update LightSimtastic.py

parent 11b30fc9
No related branches found
No related tags found
No related merge requests found
......@@ -8,14 +8,16 @@ import matplotlib.pyplot as plt
import scipy
import scipy.stats as stats
import scipy.signal as signal
from tqdm import tqdm, notebook
from tqdm.auto import tqdm
from itertools import repeat, chain, product, zip_longest
from operator import add
from types import SimpleNamespace
from AdditionalPDFs import borel
import json
import re
import codecs
import random
from copy import deepcopy
np.set_printoptions(suppress=True)
......@@ -331,15 +333,12 @@ class SiPMSimulation:
npXT = np.array(ns.dist_fpXT.rvs(size=nPG_sum))
ndXT = np.array(ns.dist_fdXT.rvs(size=nPG_sum))
tAp = np.array(ns.dist_ftAp.rvs(size=nPG_sum))
nAp = np.array(stats.binom.rvs(
n=np.ones(nPG_sum).astype(int),
p=(ns.pAp*(1 - np.exp(-tAp/ns.taur))),
size=nPG_sum
)
)
# nAp = np.random.binomial(n=1, p=(ns.pAp*(1 - np.exp(-tAp/ns.taur))), size=nPG_sum)
npXT_sum = np.sum(npXT)
nPG_pXT_sum = nPG_sum + npXT_sum
pg_l_d = np.ones(nlight_sum)
pg_l_t = np.asarray(ns.dist_ftlight.rvs(size=nlight_sum))
......@@ -358,12 +357,16 @@ class SiPMSimulation:
pXT_n = np.split(npXT, nPG_cumsum)[:-1]
dXT_n = np.split(ndXT, nPG_cumsum)[:-1]
Ap_n = np.split(nAp, nPG_cumsum)[:-1]
Ap_nt = np.split(tAp, nPG_cumsum)[:-1]
pg_d = [np.concatenate(elem) for elem in zip(pg_l_d, pg_dc_d)]
pg_t = [np.concatenate(elem) for elem in zip(pg_l_t, pg_dc_t)]
pg_pXT_d = [np.concatenate(elem) for elem in zip(pg_d, pXT_n)]
pg_pXT_t = [np.concatenate(elem) for elem in zip(pg_t, pg_t)]
pbar.update(1)
pbar.set_description("{0}".format(self.pb_ag_text[2]))
......@@ -440,38 +443,86 @@ class SiPMSimulation:
pbar.update(1)
pbar.set_description("{0}".format(self.pb_ag_text[4]))
Ap_d = [
np.array(
list(chain.from_iterable(
[
[1-np.exp(-elem_Ap_t/ns.tslow)]*elem_Ap_n
if(elem_Ap_n > 0 and elem_pg_d >0)
else []
for elem_pg_d, elem_pg_t, elem_Ap_n, elem_Ap_t in zip(list_pg_d, list_pg_t, list_Ap_n, list_Ap_t)
]
)
)
Ap_d = []
Ap_t = []
)
for list_pg_d, list_pg_t, list_Ap_n, list_Ap_t, in zip(pg_d, pg_t, Ap_n, Ap_nt)
]
for list_pg_pXT_d, list_pg_pXT_t in zip(pg_pXT_d, pg_pXT_t):
_Apd_list = []
_Apt_list = []
for d, t in zip(list_pg_pXT_d, list_pg_pXT_t):
Ap_t = [
np.array(
list(chain.from_iterable(
[
[elem_pg_t + elem_Ap_t]*elem_Ap_n
if(elem_Ap_n > 0 and elem_pg_d >0)
else []
for elem_pg_d, elem_pg_t, elem_Ap_n, elem_Ap_t in zip(list_pg_d, list_pg_t, list_Ap_n, list_Ap_t)
]
)
)
if(d>0):
_tAp = ns.dist_ftAp.rvs(size=int(d))
_nAp = stats.binom.rvs(
n=np.ones(int(d)).astype(int),
p=(ns.pAp*(1 - np.exp(-_tAp/ns.taur))),
size=int(d)
)
for list_pg_d, list_pg_t, list_Ap_n, list_Ap_t, in zip(pg_d, pg_t, Ap_n, Ap_nt)
]
cond_sel = (_nAp>0)
if(sum(cond_sel)>0):
_tAp = _tAp[cond_sel]
_nAp = _nAp[cond_sel]
_Apd = (1-np.exp(-_tAp/ns.tslow))*_nAp
_Apdt = t + _tAp
else:
_Apd = []
_Apdt = []
else:
_Apd = []
_Apdt = []
_Apd_list.extend(list(_Apd))
_Apt_list.extend(list(_Apdt))
Ap_d.append(_Apd_list)
Ap_t.append(_Apt_list)
Ap_d = np.array(Ap_d)
Ap_t = np.array(Ap_t)
# Ap_d = [
# np.array(
# list(chain.from_iterable(
# [
# [1-np.exp(-elem_Ap_t/ns.tslow)]*elem_Ap_n
# if(elem_Ap_n > 0 and elem_pg_d >0)
# else []
# for elem_pg_d, elem_pg_t, elem_Ap_n, elem_Ap_t in zip(list_pg_d, list_pg_t, list_Ap_n, list_Ap_t)
# ]
# )
# )
# )
# for list_pg_d, list_pg_t, list_Ap_n, list_Ap_t, in zip(pg_pXT_d, pg_pXT_t, Ap_n, Ap_t)
# ]
# Ap_t = [
# np.array(
# list(chain.from_iterable(
# [
# [elem_pg_t + elem_Ap_t]*elem_Ap_n
# if(elem_Ap_n > 0 and elem_pg_d >0)
# else []
# for elem_pg_d, elem_pg_t, elem_Ap_n, elem_Ap_t in zip(list_pg_d, list_pg_t, list_Ap_n, list_Ap_t)
# ]
# )
# )
# )
# for list_pg_d, list_pg_t, list_Ap_n, list_Ap_t, in zip(pg_pXT_d, pg_pXT_t, Ap_n, Ap_t)
# ]
pbar.update(1)
pbar.set_description("{0}".format(self.pb_ag_text[5]))
......@@ -533,7 +584,6 @@ class SiPMSimulation:
Q = np.array(ns.dist_Q.rvs(ns.n_sim))
n_ag_d = np.asarray([len(list_ag_d) for list_ag_d in ns.ag_d])
Sig1 = ns.dist_Sig1.rvs(np.sum(n_ag_d))
n_ag_d_cumsum = np.cumsum(n_ag_d)[:-1]
......@@ -670,7 +720,7 @@ class SiPMSimulation:
elif(ns.Gen_npXT == "Binomial"):
ns.dist_fpXT = scipy.stats.binom(n=1, p = ns.ppXT)
elif(ns.Gen_npXT == "Borel"):
ns.dist_fpXT = self.borel_gen(name="borel_npXT")(mu=ns.ppXT)
ns.dist_fpXT = borel(mu=ns.ppXT)
else:
raise Exception("The Prompt Cross-talk Discharge distribution mode that has been selected is invalid. Please choose from the following options: {0}".format(
", ".join(self.VariableDictionary["Gen_npXT"]["options"])))
......@@ -680,7 +730,7 @@ class SiPMSimulation:
elif(ns.Gen_ndXT== "Binomial"):
ns.dist_fdXT = scipy.stats.binom(n=1, p = ns.pdXT)
elif(ns.Gen_ndXT == "Borel"):
ns.dist_fdXT = self.borel_gen(name="borel_ndXT")(mu=ns.pdXT)
ns.dist_fdXT = borel(mu=ns.pdXT)
else:
raise Exception("The Delayed Cross-talk Discharge mode that has been selected is invalid. Please choose from the following options: {0}".format(
", ".join(self.VariableDictionary["Gen_ndXT"]["options"])))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment