Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
fd117d5
Create readme.md
Patchouligoo Oct 28, 2020
80c03c1
Add files via upload
Patchouligoo Oct 28, 2020
5ea78bd
bug fixed
Patchouligoo Nov 15, 2020
6f7bbdb
bug fixed
Patchouligoo Nov 15, 2020
a469cd8
bug fixed
Patchouligoo Nov 15, 2020
81dafcb
bug fixed
Patchouligoo Nov 15, 2020
32516b7
add freedom in phi
Patchouligoo Mar 7, 2021
1648316
files added
Patchouligoo Mar 7, 2021
3f8dfb5
files added
Patchouligoo Mar 7, 2021
3d83fc5
move down bethe bloch by 2 to account the fact that either electrons …
Patchouligoo Mar 7, 2021
6032cf6
move down bethe bloch by 2 to account the fact that either electrons …
Patchouligoo Mar 7, 2021
96e34ab
modified the entire coordinate system such that now the detector is f…
Patchouligoo Mar 14, 2021
a3d67aa
bug fixed
Patchouligoo Mar 21, 2021
bd63b07
bug fixed
Patchouligoo Mar 26, 2021
1e9460a
added 2 files to simulate photon and plot its the interaction corss s…
Patchouligoo Mar 26, 2021
053e22f
change length from pixel counts into um unit
Patchouligoo Mar 31, 2021
de77151
bug fixed
Patchouligoo Mar 31, 2021
c709505
add 4 files that plots the detector efficiency region and low energy …
Patchouligoo Apr 7, 2021
4bca996
add root output
Patchouligoo Apr 7, 2021
2b2a72b
bug fixed
Patchouligoo Apr 11, 2021
fa7d236
add features that save figures
Patchouligoo May 30, 2021
d128d79
add features that save figures
Patchouligoo May 30, 2021
35efe1f
Create readme.txt
Patchouligoo Oct 3, 2021
653c974
Create readme.txt
Patchouligoo Oct 3, 2021
61de4ec
Add files via upload
Patchouligoo Oct 3, 2021
80e66a7
Update readme.txt
Patchouligoo Oct 3, 2021
b6f2353
Create readme.txt
Patchouligoo Oct 3, 2021
d445617
Add files via upload
Patchouligoo Oct 3, 2021
cca602a
Create readme.txt
Patchouligoo Oct 3, 2021
b00c02d
Add files via upload
Patchouligoo Oct 3, 2021
461f8e8
Update readme.txt
Patchouligoo Oct 3, 2021
6f63f20
Update readme.txt
Patchouligoo Oct 3, 2021
b992fa7
Update readme.txt
Patchouligoo Oct 3, 2021
e11d739
Add Bayer Filter professing
Patchouligoo Oct 12, 2021
654135c
Update README.md
Patchouligoo Dec 12, 2021
fab430d
Update README.md
Patchouligoo Dec 21, 2021
a0a37d0
Delete source_measurement_replace.conf
Patchouligoo Jun 2, 2022
45e9bbf
Add files via upload
Patchouligoo Jun 2, 2022
0151768
Update source_measurement_replace.conf
Patchouligoo Jun 2, 2022
2e9f85e
Update readme.txt
Patchouligoo Jun 2, 2022
c9bbd2a
Delete Image_process_colored.py
Patchouligoo Jun 2, 2022
cb414e5
Delete MuonSimulator.py
Patchouligoo Jun 2, 2022
9075b62
Delete Single_plot.py
Patchouligoo Jun 2, 2022
c6e858b
Delete deco_rand_muon_simulator.py
Patchouligoo Jun 2, 2022
ab4850f
Delete random_generator.py
Patchouligoo Jun 2, 2022
dd43ae9
Add latest version
Patchouligoo Jun 2, 2022
16100f5
Update readme.txt
Patchouligoo Jun 2, 2022
e8d0776
Delete Hillas_calculation.py
Patchouligoo Jun 2, 2022
71ec276
Delete plot_pixel_hist.py
Patchouligoo Jun 2, 2022
339d6fe
Update readme.txt
Patchouligoo Jun 2, 2022
51c491b
Create readme.txt
Patchouligoo Jun 2, 2022
965902d
Add files via upload
Patchouligoo Jun 2, 2022
316b298
Add files via upload
Patchouligoo Jun 2, 2022
7d82aeb
Update image_cleaning.py
Patchouligoo Jun 2, 2022
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
110 changes: 110 additions & 0 deletions Electron_detector_eff_analyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
from matplotlib.colors import ListedColormap
import seaborn as sns
import os
plt.style.use("IceCube")
import matplotlib as mpl
import numpy as np

class DECOLeptonAnalyzer():
r'''This class is for making plots like the ones in the
notebook that read in a bunch of simulated files
and make analysis level plots'''

def __init__(self, pid, phi, thickness):
self.pid = pid

self.thichness = thickness

self.phi = phi


def read_hit_file(self, filename):
f = open(filename, 'r')

xhits, yhits, charge = [], [], []

# skip first 2 lines
f.readline()
f.readline()

x, y, c = [], [], []

flag = 1
while 1:

temp = f.readline().split()

if len(temp) < 1 or temp[0] == '#':
break

if temp[0] == '===':
continue
if temp[0] == '---':
if flag == 1:
flag = 0
else:
xhits.append(x)
yhits.append(y)
charge.append(c)
x, y, c = [], [], []

else:
x.append(float(temp[1][:-1]))
y.append(float(temp[2][:-1]))
c.append(float(temp[3][:-1]))

if len(x) > 0:
xhits.append(x)
yhits.append(y)
charge.append(c)

return xhits, yhits, charge




def get_E_deposited(self, en, ang, posz):
x, y, c = self.read_hit_file(
"./output/{}/{}_posz_{}_theta_{}_phi_{}_thickiness_{}_highstats.txt".format(self.pid, round(posz, 3), en, float(ang),
float(self.phi), self.thichness))

dE_list = []

for i in range(len(c)):
dE_list.append(np.array(c[i]).sum() * 3.62)

dE_list = np.array(dE_list)

return dE_list.mean(), dE_list.std()



energy = "10keV"

theta = '90'
phi = '0'
particle_type = 'e-'

dep_thickness = 26.3

z_pos = np.linspace(-1 * dep_thickness/2, dep_thickness/2, 100)

a = DECOLeptonAnalyzer(particle_type, phi, dep_thickness)

E_list = []
err_list = []

for z in z_pos:
mean_val, std_val = a.get_E_deposited(energy, theta, z)

E_list.append(mean_val)
err_list.append(std_val)

f = plt.figure()
plt.errorbar(z_pos, E_list, yerr=err_list)
plt.xlabel("initial z position in um")
plt.ylabel("calibrated E in eV")
plt.show()
164 changes: 164 additions & 0 deletions Electron_detector_eff_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
r'''Class that handles various inputs and systematic parameters
and simulates muons'''
import os, sys
import subprocess
from pipes import quote
from math import *
import numpy as np

class DECOMuonSimulator():
r'''Simulator class for muons that uses allpix
and GEANT'''

def __init__(self, pid, energy, pos, theta, **kwargs):
self.pid = pid #Particle id, ie mu+, e-
self.pos = pos
self.energy = energy
self.theta = float(theta)
self.phi = float(kwargs.pop('phi', 0.))
self.depletion_thickness = float(kwargs.pop('depletion_thickness', 26.3))
#todo: NOTE: in unit of um !!!!!!!
# Set other possible systematics with kwargs, including
# electric fields, pixel size, etc.

self.path_to_root = os.getenv('DECO_ROOT_PATH')
self.path_to_geant = os.getenv('DECO_GEANT_PATH')
self.path_to_allpix = os.getenv('DECO_ALLPIX_PATH')
self.base_command = self.path_to_allpix + ' -c ./htc_wildfire/source_measurement.conf -o'

def write_source_file(self, n_events, want_plot):

with open('./htc_wildfire/source_measurement_replace.conf', 'r') as f:
data = f.readlines()
data[3] = data[3].format(n_events)

data[18] = data[18].format(str(self.pos[0]) + " " + str(self.pos[1]) + " " + str(self.pos[2]) + "um")

theta = pi - radians(self.theta)
phi = radians(self.phi)
dirx = 1*sin(theta)*cos(phi)
diry = 1*sin(theta)*sin(phi)
dirz = 1*cos(theta)

data[20] = data[20].format(str(dirx) + " " + str(diry) + " " + str(dirz))

if want_plot == 'true':
data[38] = data[38].format('true' + "\n" + "output_linegraphs = true \n output_plots_step = 100ps \n output_plots_align_pixels = true \n output_plots_use_pixel_units = true")
else:
data[38] = data[38].format("false")


with open('./htc_wildfire/source_measurement.conf', 'w') as wf:
wf.writelines(data)
wf.close()

"""
def write_detector_file(self):
# USE THE PARAMETERS TO REWRITE DETECTOR FILE
with open('./htc_wildfire/detector_replace.conf', 'r') as f:
data = f.readlines()
data[-2] = data[-2].format(self.phi, self.theta, 0)
with open('./htc_wildfire/detector.conf', 'w') as wf:
wf.writelines(data)
wf.close()

with open('./htc_wildfire/htc_wildfire_shielded_replace.conf', 'r') as f:
data = f.readlines()
data[4] = data[4].format(self.depletion_thickness)
with open('./htc_wildfire/htc_wildfire_shielded.conf', 'w') as wf:
wf.writelines(data)
wf.close()
"""

def set_output_file_name(self):
# write unique file name depending on parameters
if not os.path.exists("./output"):
os.system("mkdir ./output")
if not os.path.exists("./output/" + str(self.pid)):
os.system("mkdir ./output/" + str(self.pid))

self.outfile = str(self.pid) + "/" + "{}_posz_{}_theta_{:.1f}_phi_{:.1f}_thickiness_{:.1f}_highstats.txt".format(round(self.pos[2], 3), self.energy, self.theta, self.phi, self.depletion_thickness)
pass


def get_output_file_name(self):
try:
return self.outfile
except:
self.set_output_file_name()
return self.outfile


def run_simulation(self, n_events, want_charge_plot='false'):

self.source_local_env()
# Run the allpix simulation

output_file = self.get_output_file_name()
self.write_source_file(n_events, want_charge_plot)

my_command = self.base_command[:]

my_command += ' DepositionGeant4.particle_type="{}"'.format(self.pid)
my_command += ' -o DepositionGeant4.source_energy="{}"'.format(self.energy)
my_command += ' -o TextWriter.file_name="' + output_file + '"'

"""check if simulated using file name"""
if self.check_if_simulated(output_file) is True:
print("has been simulated")
return

subprocess.call(my_command, shell=True)

return


def check_if_simulated(self, filename):
# Check to see if simulation has already been run for
# this set of parameters

if not os.path.exists("./output/" + filename):
return False

return True



def source_local_env(self):
geant = self.path_to_geant + "/bin/geant4.sh"
root = self.path_to_root + "/bin/thisroot.sh"

pass
# Run source scripts for ROOT and GEANT if the
# simulation doesn't work


dep_thickness = 26.3 #um
pos_list = []

z_pos = np.linspace(-1 * dep_thickness/2, dep_thickness/2, 100)

for i in range(len(z_pos)):
pos_list.append([0, 0, z_pos[i]])

#angles = ['0', '15', '30', '45', '60', '75']

#phis = ['0', '15', '30', '45', '60', '75', '90']

energy = ['10keV']
angles = ['90']
phis = ['0']
particle_type = 'e-'


want_charge_plot = "false"

for ene in energy:
for ang in angles:
for azi in phis:
for pos in pos_list:
a = DECOMuonSimulator(particle_type, ene, pos, ang, phi=azi, depletion_thickness=str(dep_thickness))

a.run_simulation(100, want_charge_plot)


Loading