diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ec38f9044ce9200369197068d6e9e1478e65b4b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Caches and logs +*.log + +# Jupyter Notebook checkpoints +.ipynb_checkpoints + +# Matplotlib plot images +*.png + +# Data files +*.csv +*.tsv +*.dat + +# OS files +.DS_Store +Thumbs.db + +# Virtual environment +.env/ +.venv/ +env/ +venv/ + +# IDEs +.idea/ +.vscode/ diff --git a/Example.png b/Example.png deleted file mode 100644 index f6e165d7f9a83aeb4e4875c1243cb9c9d6fc1f98..0000000000000000000000000000000000000000 Binary files a/Example.png and /dev/null differ diff --git a/LightSimtastic.py b/LightSimtastic.py index a4c72cac1fdcce455c00e63000acdd5296c16176..e3c1651c82ff60d155ab513901dd422e18fcc069 100644 --- a/LightSimtastic.py +++ b/LightSimtastic.py @@ -734,6 +734,7 @@ class SiPMSimulation: if(transients): start_time = time.time() I, t = self.ISiPM(ns, n_transients=n_transients) + #I, t = self.ISiPM(ns, ntim=6001, n_transients=n_transients) end_time = time.time() diff --git a/Main_example_2.py b/Main_example_2.py new file mode 100644 index 0000000000000000000000000000000000000000..1c7e9a6cb359581691bc066be7f1aba4998b6b46 --- /dev/null +++ b/Main_example_2.py @@ -0,0 +1,130 @@ +from LightSimtastic import SiPMSimulation +import matplotlib.pyplot as plt +import numpy as np + +################################# +# THE SIMULATION TOOL TAKES A DICTIONARY AS AN INPUT, WITH EACH OF THE VARIABLES AS KEYS. +# FOR EACH ELEMENT YOU ADD TO THE LISTS, ANOTHER SIMULATION WILL BE PERFORMED. +# THIS ALLOWS SCANS THROUGH PARAMETERS. +################################# + +variables={ +"Name_Sim":[0], #THIS CAN BE ANYTHING YOU LIKE +"mu":[1], # MEAN NUMBER OF GEIGER DISCHARGES +"ppXT":[0.0], # PROBABILITY OF PROMPT CROSS-TALK +"pdXT":[0.0], #PROBABILITY OF DELAYED CROSS-TALK +"taudXT":[25], #TIME CONSTANT FOR DELAYED CROSS-TALK (NS) +"rdXT":[0.5], #FRACTION OF DELAYED CROSS-TALK FROM ADJACENT CELLS +"pAp":[1.0], #PROBABILITY OF AFTERPULSE +"tauAp":[20.0], #TIME CONSTANT OF AFTERPULSE +"taur":[15], # SIPM RECOVERY TIME CONSTANT +"Sig0":[0.075], #WIDTH OF PEDESTAL [NORMALISED ADC] +"Sig1":[0.02], # INCREASE IN PEAK WIDTH PER ADDITIONAL DISCHARGE [NORMALISED ADC] +"DCR":[0.0], # DARK COUNT RATE [GHZ] +"Sigt":[0.2], # ELECTRONICS NOISE FOR CURRENT TRANSIENT (FOR TRANSIENT) +"GSig":[0.75], # WIDTH OF ELECTRONICS NOISE TRANSFER FUNCTION (FOR TRANSIENT) +"tslow":[15], # TIME CONSTANT FOR SLOW PART OF PULSE +"tfast":[15], # TIME CONSTANT FOR FAST PART OF PULSE +"rfast":[1.0], # PROPORTION OF SLOW/FAST +"start_tgate":[-300], # GATE START TIME [NS] +"len_tgate":[600], # LENGTH OF GATE +"t0":[300], # STARTING POINT OF GATE +"tl0":[0], #GAUSSIAN MEAN OF PRIMARY GEIGER DICHARGE TIME DISTRIBUTION +"tl1":[0.1], #GAUSSIAN WIDTH OF PRIMARY GEIGER DICHARGE TIME DISTRIBUTION +"tl2":[0], #FREE PARAMETER +"Gen_mu":["Poisson"], # NUMBER PRIMARY GEIGER DISCHARGE PDF +"Gen_tmu":["Gauss"], # TIME OF PRIMARY GEIGER DISCHARGE PDF +"Gen_gain":["Gauss"], # GAIN PDF (FOR TRANSIENT) +"Gen_npXT":["Binomial"], #NUMBER PROMPT X-TALK DISCHARGE DISTRIBUTION +"Gen_ndXT":["Binomial"], #NUMBER PROMPT X-TALK DISCHARGE DISTRIBUTION +"Gen_tdXT":["Exp"], #TIME DELAYED X-TALK DISTRIBUTION +"Gen_nAP":["Binom"], #NUMBER AFTER DISTRIBUTION +"Gen_tAP":["Exp"], #AFTERPULSE TIME DISTRIBUTION +"Gen_noise":["Gauss"] #ELECTRONIC NOISE DISTRIBUTION (FOR TRANSIENT) +} + +################################# +# CREATE A SIPM SIMULATION CLASS OBJECT +################################# + +s = SiPMSimulation() + +################################# +# ADD VARIABLES +################################# + +s.AddVariables(variables) + +n_events = int(1e2) +iterplot=0 + +################################# +# SIMULATE +################################# + +#s.Simulate(n_events, transients=False) +s.Simulate(n_events, transients=True, n_transients=n_events) + +################################# +# EXTRACT SIMULATION DATAFRAME +################################# + +df = s.pars + +################################# +# TRANSIENT +################################# +I = df.iloc[0]["Transients"]['I'] +t = df.iloc[0]["Transients"]['t'] + +if iterplot>0: + # Iterative plot + wave_sum = np.sum(I, axis=0) + wave_avg = wave_sum / len(I) + x_min = t.min(); x_max = t.max() + y_min = -1; y_max = 2.5 #np.max(I)+1 + + fig, ax = plt.subplots(figsize=(15.5,10.5)) + plt.rc('font', size=20) + plt.ion() + plt.show() + + for index in range(iterplot): + ax.clear() + ax.plot(t, I[index], color='blue', label='Transient '+str(index),linewidth=0.2) + #ax.plot(t, wave_avg, color='red', label='Average transient',linewidth=0.2) + + ax.grid(True, which='both', linestyle=':', linewidth=0.5, color='lightgrey') + ax.set_xlim([x_min, x_max]) + ax.set_ylim([y_min, y_max]) + ax.set_xlabel('Time [ns]',loc='right') + ax.set_ylabel('Intensity [a.u.]',loc='top') + ax.set_title('Transients') + ax.legend() + plt.draw() + plt.pause(0.01) + input(" ") + plt.ioff() + plt.close() + +################################# +# EXTRACT CHARGE SPECTRUM +################################# + +Qs = df.iloc[0]["ChargeSpectrum"] + +################################# +# PLOT +################################# + +plt.figure(figsize=(15.5,10.5)) +H, edges = np.histogram(Qs, bins=1000) +edges = edges[:-1]+(edges[1]-edges[0]) +plt.plot(edges, H) +plt.title("Simulated Charge Spectrum") +plt.yscale("log") +plt.xticks(fontsize=25) +plt.yticks(fontsize=25) +plt.xlabel("# GD", fontsize=25), +plt.savefig("./Example.png") + diff --git a/README.md b/README.md index eee04065242456e95445334d56a8c1971cea3185..c4595954ccdb4a376d1200c579745a692772f11b 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,21 @@ To get started, have a look at ```Example.py``` as well as ```ExampleTransients. ## References E. Garutti, R. Klanner, J. Rolph, J. Schwandt: _Simulation of the response of SiPMs; Part I: Without saturation effects_. [doi.org/10.1016/j.nima.2021.165853](https://doi.org/10.1016/j.nima.2021.165853) + + +# Installation +Clone the repository: +``` +git clone https://gitlab.rrz.uni-hamburg.de/uhhdetlab/sipm/lightsimtastic.git +``` +In the main folder of the repository run: +``` +pip install -r requirements.txt +``` +to install all the required python packages (best in a new python virtual environment) + +## Usage +Create/modify Main_example.py: +``` +python Main_example.py +``` \ No newline at end of file diff --git a/__pycache__/AdditionalPDFs.cpython-36.pyc b/__pycache__/AdditionalPDFs.cpython-36.pyc deleted file mode 100644 index a3a9c2233096a3e8c53df840ff7de2202f912ea1..0000000000000000000000000000000000000000 Binary files a/__pycache__/AdditionalPDFs.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/LightSimtastic.cpython-36.pyc b/__pycache__/LightSimtastic.cpython-36.pyc deleted file mode 100644 index f28c81b2d49b775f4378b3a3104db5ecf63c13ea..0000000000000000000000000000000000000000 Binary files a/__pycache__/LightSimtastic.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/SiPMSimulation.cpython-36.pyc b/__pycache__/SiPMSimulation.cpython-36.pyc deleted file mode 100644 index a202d1aaed5270b83942bf4a9e314b262640eb48..0000000000000000000000000000000000000000 Binary files a/__pycache__/SiPMSimulation.cpython-36.pyc and /dev/null differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..ed0f2c86bec615a71ded6574e53fdcfe77573a50 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +matplotlib +numpy +tqdm +pandas +scipy