diff --git a/.gitignore b/.gitignore index d5e4f15f8c02ac458b0019ffbb99d969fdc719db..7873152158376d664554b88f3bbe656fffb618c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -**/__pycache__ \ No newline at end of file +**/__pycache__ +raser.egg-info +dist \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/elec/__init__.py b/elec/__init__.py index d27eaa89491145bfae88c2f3b7f3617678e2d296..d739f8f0f1e7023f5f18d988e16eb4003da1ad22 100644 --- a/elec/__init__.py +++ b/elec/__init__.py @@ -9,9 +9,12 @@ def main(kwargs): subprocess.run(['ngspice -b -r t1.raw output/T1_tmp.cir'], shell=True) if label == 'drs4_get_analog': import subprocess - subprocess.run(['ngspice -b -r drs4_analog.raw paras/drs4_analog.cir'], shell=True) + subprocess.run(['ngspice -b -r drs4_analog.raw paras/circuitdrs4_analog.cir'], shell=True) if label == 'drs4_get_fig': from . import drs4_get_fig drs4_get_fig.main() + if label == 'HPK-Si-LGAD-CCE': + from . import cce_alpha + cce_alpha.main() else: raise NameError(label) \ No newline at end of file diff --git a/elec/cce_alpha.py b/elec/cce_alpha.py index fb613de8bde6848b036d115e7d8d8ee273047601..a5bb3016580bb46bf6c8e3dc6a697e468b63c698 100644 --- a/elec/cce_alpha.py +++ b/elec/cce_alpha.py @@ -1,104 +1,99 @@ import ROOT import os -import numpy -import sys -import math - -def read_file(file_path,wave_name): +def read_file(file_path, wave_name): with open(file_path + '/' + wave_name, 'r') as f: - lines = f.readlines() points = lines[6:] - time, volt = [],[] + time, volt = [], [] for point in points: try: - time.append(float(point.strip('\n').strip().split(',')[3])*1e9) - volt.append(float(point.strip('\n').strip().split(',')[4])*1e3) + time.append(float(point.strip('\n').strip().split(',')[0]) * 1e9) + volt.append(float(point.strip('\n').strip().split(',')[1]) * -1e3) except Exception as e: pass - return time,volt + return time, volt -def get_max(time_list,volt_list): +def filter_csv_files(folder_path): + csv_files = [] + for file in os.listdir(folder_path): + if file.endswith(".csv"): + csv_files.append(file) + return csv_files +def get_max(time_list, volt_list): volt_max = 0. time_max = 0. index_max = 0 for i in range(len(volt_list)): - if(volt_list[i]>volt_max): + if volt_list[i] > volt_max: time_max = time_list[i] volt_max = volt_list[i] index_max = i - return time_max,volt_max,index_max - -def get_baseline(time_list,volt_list,time_win): + return time_max, volt_max, index_max +def get_baseline(time_list, volt_list, time_win): time_start = time_list[0] time_end = time_start + time_win count = 0. total = 0. for i in range(len(time_list)): - if(time_list[i] < time_end): - total += volt_list[i] + if time_list[i] < time_end: + total += volt_list[i] count += 1. - baseline = total/count + baseline = total / count return baseline -def get_charge(time_list,volt_list,baseline): - +def get_charge(time_list, volt_list, baseline): volt_cut_baseline_list = [] for i in range(len(volt_list)): - volt_cut_baseline_list.append(volt_list[i]-baseline) + volt_cut_baseline_list.append(volt_list[i] - baseline) - time_max,volt_max,index_max = get_max(time_list,volt_cut_baseline_list) + time_max, volt_max, index_max = get_max(time_list, volt_cut_baseline_list) - time_bin = time_list[1]-time_list[0] + time_bin = time_list[1] - time_list[0] tmp_integrate = 0. - + tmp_index = index_max while True: - if(volt_cut_baseline_list[tmp_index]<0.): break - tmp_integrate += volt_cut_baseline_list[tmp_index]*time_bin + if volt_cut_baseline_list[tmp_index] < 0.: + break + tmp_integrate += volt_cut_baseline_list[tmp_index] * time_bin tmp_index -= 1 - - tmp_index = index_max+1 + + tmp_index = index_max + 1 while True: - if(volt_cut_baseline_list[tmp_index]<0.): break - tmp_integrate += volt_cut_baseline_list[tmp_index]*time_bin + if volt_cut_baseline_list[tmp_index] < 0.: + break + tmp_integrate += volt_cut_baseline_list[tmp_index] * time_bin tmp_index += 1 - charge = tmp_integrate*(1e-12)/50/100*(1e15) + charge = tmp_integrate * (1e-12) / 50 / 10 * (1e15) return charge def main(): - - input_name = sys.argv[1] - path = '/scratchfs/atlas/lizaiyi/data/alpha_readout/' + input_name - waves = os.listdir(path) - time,volt = [],[] - window = 1000 - - c = ROOT.TCanvas('c','c',1500,600) - c.Divide(2,1) - charge_graph = ROOT.TH1F('charge','charge',100,20,1000) - volt_graph = ROOT.TH1F('volt',"volt",100,0,1500) - - for wave in waves: - - print(wave) - time,volt = read_file(path,wave) - time_max,volt_max,index_max = get_max(time,volt) - baseline = get_baseline(time,volt,window) - charge = get_charge(time,volt,baseline) - if charge > 30 and charge < 1000: + path = './output/gen_signal/HPK-Si-LGAD-CCE/batch' + csv_files = filter_csv_files(path) + + c = ROOT.TCanvas('c', 'c', 1500, 600) + c.Divide(2, 1) + charge_graph = ROOT.TH1F('charge', 'charge', 15, 40, 100) + volt_graph = ROOT.TH1F('volt', "volt", 20, 15, 35) + + for csv_file in csv_files: + print(csv_file) + time, volt = read_file(path, csv_file) + time_max, volt_max, index_max = get_max(time, volt) + baseline = get_baseline(time, volt, 1000) + charge = get_charge(time, volt, baseline) + if 30 < charge < 1000: charge_graph.Fill(charge) volt_graph.Fill(volt_max) - + charge_graph.GetXaxis().SetTitle('Charge [fC]') - volt_graph.GetXaxis().SetTitle('Volt [mV]') c.cd(1) @@ -107,7 +102,7 @@ def main(): c.cd(2) volt_graph.Draw() - c.SaveAs('./output/'+ input_name + '_distribution.pdf') + c.SaveAs('./output/HPK-Si-LGAD-CCE_distribution.pdf') if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/elec/ele_readout.py b/elec/ele_readout.py index 20058ee6d11f1a199496956ae9de70e2899c7599..b43712752bd3103939cd6a44b301a04e79fb9f8f 100644 --- a/elec/ele_readout.py +++ b/elec/ele_readout.py @@ -100,6 +100,7 @@ class Amplifier: self.CDet_j = 0 # CSA readout mode self.qtot = [0.0]*self.read_ele_num + # self.qtot = [0.0] # get total charge for k in range(self.read_ele_num): i=0 @@ -185,7 +186,7 @@ class Amplifier: def fill_CSA_out(self,i,j,dif_shaper_Q): """ Fill CSA out variable""" - self.shaper_out_Q[i+j] += self.tau_rise/(self.tau_fall-self.tau_rise) \ + self.shaper_out_Q[i+j] += self.tau_fall/(self.tau_fall+self.tau_rise) \ * dif_shaper_Q*(math.exp(-j*self.time_unit / self.tau_fall)-math.exp( - j*self.time_unit/self.tau_rise)) @@ -196,9 +197,9 @@ class Amplifier: * math.exp(-j*self.time_unit/self.tau_scope) self.Iout_BB_RC[i+j] += (dif_shaper_Q)/self.tau_BBA \ * math.exp(-j*self.time_unit/self.tau_BBA) - self.BBGraph[i+j] = self.BBGain * self.Iout_BB_RC[i+j] + self.BBGraph[i+j] = 1e3 * self.BBGain * self.Iout_BB_RC[i+j] R_in = 50 # the input impedance of the amplifier - self.Vout_scope[i+j] = self.BBGain * R_in * self.Iout_BB_RC[i+j] + self.Vout_scope[i+j] = R_in * self.Iout_C50[i+j] # if (abs(self.BBGraph[i+j]) > 800): # self.BBGraph[i+j] = 800*self.BBGraph[i+j]/abs(self.BBGraph[i+j]) @@ -221,9 +222,9 @@ class Amplifier: self.shaper_out_V[i] = 0.0 elif self.CDet_j == 0: - #self.shaper_out_V[i] = self.shaper_out_Q[i]*self.trans_imp\ - # * 1e15*self.qtot[k]*Qfrac/self.sh_max - self.shaper_out_V[i] = self.shaper_out_Q[i]*self.trans_imp/(self.CDet*1e-12) #C_D=3.7pF + self.shaper_out_V[i] = self.shaper_out_Q[i]*self.trans_imp\ + * 1e15*self.qtot[k]*Qfrac/self.sh_max + # self.shaper_out_V[i] = self.shaper_out_Q[i]*self.trans_imp/(self.CDet*1e-12) #C_D=3.7pF elif self.CDet_j ==1: self.shaper_out_V[i] = self.shaper_out_Q[i]*self.trans_imp\ diff --git a/elec/ngspice.py b/elec/ngspice.py index 51b093d0e302aba89683b825b738eef3c9cba511..cf323767f061060bfb2587208d49fc193c46f4bb 100644 --- a/elec/ngspice.py +++ b/elec/ngspice.py @@ -1,5 +1,5 @@ def ngspice(input_c, input_p): - with open('./paras/T1.cir', 'r') as f: + with open('./paras/circuitT1.cir', 'r') as f: lines = f.readlines() lines[113] = 'I1 2 0 PWL('+str(input_c)+') \n' lines[140] = 'tran 0.1p ' + str((input_p[len(input_p) - 2])) + '\n' diff --git a/elec/t1_create.py b/elec/t1_create.py index caddb30ee3fdacca1445d5442da26fe6180a74eb..70df9e24cbd56f7fadb3adaf7d58419232083b9c 100644 --- a/elec/t1_create.py +++ b/elec/t1_create.py @@ -70,7 +70,7 @@ if number>=1: input_c.append(str(0)) input_p=','.join(input_c) - with open('/scratchfs/atlas/xingchenli/raser/paras/T1.cir', 'r') as f: + with open('/scratchfs/atlas/xingchenli/raser/paras/circuitT1.cir', 'r') as f: lines = f.readlines() lines[113] = 'I1 2 0 PWL('+str(input_p)+') \n' lines[140] = 'tran 0.1p ' + str((input_c[len(input_c) - 2])) + '\n' @@ -142,7 +142,7 @@ else: input_c.append(str(0)) input_p=','.join(input_c) - with open('/scratchfs/atlas/xingchenli/raser/paras/T1.cir', 'r') as f: + with open('/scratchfs/atlas/xingchenli/raser/paras/circuitT1.cir', 'r') as f: lines = f.readlines() lines[113] = 'I1 2 0 PWL('+str(input_p)+') \n' lines[140] = 'tran 0.1p ' + str((input_c[len(input_c) - 2])) + '\n' diff --git a/particle/__init__.py b/particle/__init__.py index 32d705136747f56e2d1fb41aa4220f6d1f87f9b8..6dfde866ecc0968ecbbc9fce0b9aba666228863a 100644 --- a/particle/__init__.py +++ b/particle/__init__.py @@ -10,7 +10,7 @@ def main(kwargs): cflm.main() elif label == "test": from . import g4_sic_energy_deposition - command="./cfg/gui.mac" + command="./paras/g4macro/gui.mac" g4_sic_energy_deposition.main() else: raise NameError(label) \ No newline at end of file diff --git a/particle/cflm.py b/particle/cflm.py index d429e693957bbfba6cb2fd25486c5e6a069148ac..5fa9f2d6588cb67eae8ef882d2b4420062d6dff5 100755 --- a/particle/cflm.py +++ b/particle/cflm.py @@ -299,7 +299,7 @@ def main(): UImanager = g4b.G4UImanager.GetUIpointer() - UImanager.ApplyCommand("/control/execute cfg/init_vis.mac") + UImanager.ApplyCommand("/control/execute paras/g4macro/init_vis.mac") UImanager.ApplyCommand('/run/initialize') UImanager.ApplyCommand('/tracking/verbose 2') diff --git a/particle/g4_sic_energy_deposition.py b/particle/g4_sic_energy_deposition.py index bedbebba3613e0b1f20b7bad962e42f3548c0d71..9d790de73ffe37cd027bd08de256ddd96b78470b 100755 --- a/particle/g4_sic_energy_deposition.py +++ b/particle/g4_sic_energy_deposition.py @@ -317,7 +317,7 @@ def main(): UImanager = g4b.G4UImanager.GetUIpointer() - UImanager.ApplyCommand("/control/execute cfg/init_vis.mac")#鍒濆鍖栧彲瑙嗗寲閰嶇疆 + UImanager.ApplyCommand("/control/execute paras/g4macro/init_vis.mac")#鍒濆鍖栧彲瑙嗗寲閰嶇疆 UImanager.ApplyCommand('/run/initialize')#鍒濆鍖栬繍琛岋紝鍑嗗寮€濮嬫ā鎷� UImanager.ApplyCommand("/gun/particle ion") diff --git a/particle/g4si_itk.py b/particle/g4si_itk.py index edc20c6d17c086f600c6bfc57afb57dcfdb5e79f..350c6b6837977c2a194ff60bfec73ca2cb2ac2ae 100644 --- a/particle/g4si_itk.py +++ b/particle/g4si_itk.py @@ -41,7 +41,7 @@ class SiITk: visManager = g4b.G4VisExecutive() visManager.Initialize() UImanager = g4b.G4UImanager.GetUIpointer() - UImanager.ApplyCommand('/control/execute init_vis.mac') + UImanager.ApplyCommand('/control/execute paras/g4macro/init_vis.mac') else: UImanager = g4b.G4UImanager.GetUIpointer() UImanager.ApplyCommand('/run/initialize') diff --git a/particle/g4simulation.py b/particle/g4simulation.py index b70647c6e059bf98b55f58c935a677a2a7a3f02b..71e303d0a8b12c7a3f53f0a0dd9fa0ad668e2077 100644 --- a/particle/g4simulation.py +++ b/particle/g4simulation.py @@ -88,7 +88,7 @@ class Particles: visManager = g4b.G4VisExecutive() visManager.Initialize() UImanager = g4b.G4UImanager.GetUIpointer() - UImanager.ApplyCommand('/control/execute init_vis.mac') + UImanager.ApplyCommand('/control/execute paras/g4macro/init_vis.mac') else: UImanager = g4b.G4UImanager.GetUIpointer() UImanager.ApplyCommand('/run/initialize') diff --git a/spaceres/telescope_jiaqi.py b/spaceres/telescope_jiaqi.py index 745cb294a5eef1494633a751c0bd444cff7f2936..918cfdd30fe70b0a9e47889782b66d9240e2f58b 100755 --- a/spaceres/telescope_jiaqi.py +++ b/spaceres/telescope_jiaqi.py @@ -622,7 +622,7 @@ if ui == None: UImanager.ApplyCommand(command+fileName) else: # interactive mode - UImanager.ApplyCommand("/control/execute ./cfg/init_vistelescope.mac") + UImanager.ApplyCommand("/control/execute ./paras/g4macro/init_vistelescope.mac") if ui.IsGUI(): - UImanager.ApplyCommand("/control/execute ./cfg/gui.mac") + UImanager.ApplyCommand("/control/execute ./paras/g4macro/gui.mac") ui.SessionStart() diff --git a/tct/tct_analysis.py b/tct/tct_analysis.py index 1a0e13c7299065ade05b9cd4e5e72357b973d86a..fbdf3b8c566f9c68b1c9706598c8acd360ad9942 100644 --- a/tct/tct_analysis.py +++ b/tct/tct_analysis.py @@ -15,7 +15,7 @@ import sys import ROOT import math import numpy as np - + sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import raser diff --git a/tct/tct_signal.py b/tct/tct_signal.py index c6f9a84c421bb6290515947443874ffd17cce512..e08a73adab33d52250b5edbd202e07435a546739 100644 --- a/tct/tct_signal.py +++ b/tct/tct_signal.py @@ -44,7 +44,7 @@ if "ngspice" in args: my_current.save_current(dset,my_d,my_l,my_f,"fx_rel") input_p=ngsip.set_input(dset,my_current,my_l,my_d,"fx_rel") input_c=','.join(input_p) - with open('paras/T1.cir', 'r') as f: + with open('paras/circuitT1.cir', 'r') as f: lines = f.readlines() lines[113] = 'I1 2 0 PWL('+str(input_c)+') \n' lines[140] = 'tran 0.1p ' + str((input_p[len(input_p) - 2])) + '\n' diff --git a/tct/tct_t1.py b/tct/tct_t1.py index 0d903c837378cc6576a5660fec424940fd906053..5701fd72fdb1311889549c60b6b98b650b062c3c 100644 --- a/tct/tct_t1.py +++ b/tct/tct_t1.py @@ -64,7 +64,7 @@ t_start = t1 t_rise = t2 - t1 t_fall = t3 - t2 -with open('paras/T1.cir', 'r') as f: +with open('paras/circuitT1.cir', 'r') as f: lines = f.readlines() lines[113] = 'I1 2 0 pulse(0 ' + str(c_max) + 'u ' + str(t_start) + 'n ' + str(t_rise) + 'n ' + str(t_fall) + 'n 0.00000001n ' + str((T_ele[len(T_ele) - 1])) + 'n 0)\n' lines[140] = 'tran 0.1p ' + str((T_ele[len(T_ele) - 1])) + 'n\n' diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/test_draw.py b/tests/test_draw.py new file mode 100644 index 0000000000000000000000000000000000000000..553444b67db4d02eb0951da36f9aa0e47b0ac47f --- /dev/null +++ b/tests/test_draw.py @@ -0,0 +1,13 @@ +import unittest + +class TestSum(unittest.TestCase): + def test_draw(self): + """ + Test draw functions + """ + data = [1, 2, 3] + result = sum(data) + self.assertEqual(result, 6) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_field.py b/tests/test_field.py new file mode 100644 index 0000000000000000000000000000000000000000..b3ce17650d8b1ca16a652ea7ba0b0f5ab17e338f --- /dev/null +++ b/tests/test_field.py @@ -0,0 +1,13 @@ +import unittest + +class TestSum(unittest.TestCase): + def test_field_cal_gen_devsim_db(self): + """ + Test field cal gen_devsim_db + """ + data = [1, 2, 3] + result = sum(data) + self.assertEqual(result, 6) + +if __name__ == '__main__': + unittest.main() diff --git a/timeres/add_noise.py b/timeres/add_noise.py index cca5ad512620be854a96400de8b32b6b3a48fc60..2448b03c0fc014b284cc9e063b984e7e5e4d7de4 100644 --- a/timeres/add_noise.py +++ b/timeres/add_noise.py @@ -17,8 +17,8 @@ import ROOT import math from util.output import output -noise_avg = -0.133 -noise_rms = 2.671 +noise_avg = -0.001 +noise_rms = 0.01 # ROOT file parameters difinition Events=array('i',[0]) @@ -169,7 +169,8 @@ class AddNoise: random_gauss = ROOT.gRandom.Gaus for j in range (0,len(list_c)): time= float(list(filter(None,list_c[j].split(",")))[0]) - noise_height=random_gauss(noise_avg,noise_rms) + # noise_height=random_gauss(noise_avg,noise_rms) + noise_height=0 ampl_nps=-float(list(filter(None,list_c[j].split(",")))[1])+noise_height ampl_s=-float(list(filter(None,list_c[j].split(",")))[1]) self.time_list.append(time)