Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
import sys
import os
import array
import time
import subprocess
import ROOT
from field import build_device as bdv
from . import cflm
from field import devsim_field as devfield
from current import cal_current as ccrt
from elec.set_pwl_input import set_pwl_input as pwlin
from util.output import output
import json
import re
import numpy
def get_signal():
geant4_json = "./raser/cflm/cflm.json"
with open(geant4_json) as f:
g4_dic = json.load(f)
detector_json = "./setting/detector/"
with open(os.path.join(detector_json , g4_dic['DetModule'])) as q:
det_dic = json.load(q)
start = time.time()
det_name = det_dic['det_name']
my_d = bdv.Detector(det_name)
voltage = det_dic['bias']['voltage']
amplifier = det_dic['amplifier']
print(my_d.device)
print(voltage)
my_f = devfield.DevsimField(my_d.device, my_d.dimension, voltage, 1, my_d.l_z)
my_g4p = cflm.cflmG4Particles(my_d)
my_current = ccrt.CalCurrentG4P(my_d, my_f, my_g4p, 0)
if 'ngspice' in amplifier:
save_current(my_d, my_current, g4_dic, my_f = devfield.DevsimField(my_d.device, my_d.dimension, voltage, 1, my_d.l_z))
pwlin(f"raser/cflm/output/{g4_dic['CurrentName'].split('.')[0]}_pwl_current.txt", 'raser/cflm/ucsc.cir', 'raser/cflm/output/')
subprocess.run([f"ngspice -b -r ./xxx.raw raser/cflm/output/ucsc_tmp.cir"], shell=True)
del my_f
end = time.time()
print("total_time:%s"%(end-start))
def save_current(my_d, my_current, g4_dic, my_f):
time = array.array('d', [999.])
current = array.array('d', [999.])
fout = ROOT.TFile(os.path.join("raser/cflm/output/", g4_dic['CurrentName'].split('.')[0]) + ".root", "RECREATE")
t_out = ROOT.TTree("tree", "signal")
t_out.Branch("time", time, "time/D")
for i in range(my_f.read_ele_num):
t_out.Branch("current"+str(i), current, "current"+str(i)+"/D")
for j in range(my_current.n_bin):
current[0]=my_current.sum_cu[i].GetBinContent(j)
time[0]=j*my_current.t_bin
t_out.Fill()
t_out.Write()
fout.Close()
file = ROOT.TFile(os.path.join("raser/cflm/output/", g4_dic['CurrentName'].split('.')[0]) + ".root", "READ")
tree = file.Get("tree")
pwl_file = open(os.path.join("raser/cflm/output/", f"{g4_dic['CurrentName'].split('.')[0]}_pwl_current.txt"), "w")
for i in range(tree.GetEntries()):
tree.GetEntry(i)
time_pwl = tree.time
current_pwl = tree.current0
pwl_file.write(str(time_pwl) + " " + str(current_pwl) + "\n")
pwl_file.close()
file.Close()