From 9b787dfaa92190f7dde6baa36604d8271a979390 Mon Sep 17 00:00:00 2001
From: fuchenxi <1256257282@qq.com>
Date: Tue, 11 Feb 2025 16:26:39 +0800
Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=94=B9=E5=90=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 __main__.py                                 | 12 ++----
 particle/g4_sic_energy_deposition.py        |  4 +-
 {timeres => resolution}/__init__.py         |  0
 {timeres => resolution}/add_noise.py        | 11 +++---
 {timeres => resolution}/time_scan.py        |  0
 tct/{source.py => laser.py}                 | 42 ++++++++++-----------
 tct/tct_signal.py                           |  4 +-
 tct/tct_signal_scan.py                      |  4 +-
 {spaceres => telescope}/__init__.py         |  0
 {spaceres => telescope}/telescope_acts.py   |  2 +-
 {spaceres => telescope}/telescope_g4.py     |  0
 {spaceres => telescope}/telescope_signal.py |  6 +--
 util/math.py                                |  1 +
 13 files changed, 41 insertions(+), 45 deletions(-)
 rename {timeres => resolution}/__init__.py (100%)
 rename {timeres => resolution}/add_noise.py (98%)
 rename {timeres => resolution}/time_scan.py (100%)
 rename tct/{source.py => laser.py} (91%)
 rename {spaceres => telescope}/__init__.py (100%)
 rename {spaceres => telescope}/telescope_acts.py (98%)
 rename {spaceres => telescope}/telescope_g4.py (100%)
 rename {spaceres => telescope}/telescope_signal.py (98%)

diff --git a/__main__.py b/__main__.py
index 523154d..14a4fdb 100755
--- a/__main__.py
+++ b/__main__.py
@@ -59,11 +59,11 @@ parser_gen_signal.add_argument('-amp', '--amplifier', type=str, help='amplifier'
 parser_gen_signal.add_argument('-s', '--scan', type=int, help='instance number for scan mode')
 parser_gen_signal.add_argument('--job', type=int, help='flag of run in job')
 
-parser_spaceres = subparsers.add_parser('spaceres', help='space resolution calculation')
-parser_spaceres.add_argument('label', help='LABEL to identify spaceres files')
+parser_telescope = subparsers.add_parser('telescope', help='telescope')
+parser_telescope.add_argument('label', help='LABEL to identify telescope files')
 
-parser_spaceres = subparsers.add_parser('timeres', help='time resolution calculation')
-parser_spaceres.add_argument('det_name', help='name of the detector')
+parser_telescope = subparsers.add_parser('resolution', help='resolution calculation for time, space and energy')
+parser_telescope.add_argument('det_name', help='name of the detector')
 
 parser_tct = subparsers.add_parser('tct', help='TCT simulation')
 parser_tct.add_argument('label', help='LABEL to identify TCT options')
@@ -87,11 +87,7 @@ if len(sys.argv) == 1:
 
 kwargs = vars(args)
 
-submodules = ['asic', 'cce', 'cflm', 'current', 'draw', 'elec', 'field', 'fpga', 'gen_signal', 'particle', 'spaceres', 'tct', 'timeres', 'bmos']
-
 submodule = kwargs['subparser_name']
-if submodule not in submodules:
-    raise NameError(submodule)
 
 if kwargs['batch'] != 0:
     batch_level = kwargs['batch']
diff --git a/particle/g4_sic_energy_deposition.py b/particle/g4_sic_energy_deposition.py
index eedaa71..f373d75 100755
--- a/particle/g4_sic_energy_deposition.py
+++ b/particle/g4_sic_energy_deposition.py
@@ -172,7 +172,7 @@ class SiC_LGAD_DetectorConstruction(g4b.G4VUserDetectorConstruction):#鏄痝4b.G4V
         self.fMagFieldMessenger = g4b.G4GlobalMagFieldMessenger(fieldValue)
         self.fMagFieldMessenger.SetVerboseLevel(1)
 #鍒涘缓绮掑瓙鍒濆鍖栦俊鎭紝鍖呮嫭浣嶇疆锛屽姩閲忥紝鑳介噺锛�
-class SIC_LGAD_PrimaryGeneratorAction(g4b.G4VUserPrimaryGeneratorAction):
+class SiC_LGAD_PrimaryGeneratorAction(g4b.G4VUserPrimaryGeneratorAction):
 
     def __init__(self):
         super().__init__()
@@ -294,7 +294,7 @@ class SiC_LGAD_aActionInitialization(g4b.G4VUserActionInitialization):
         self.SetUserAction(SiC_LGAD_RunAction())
 
     def Build(self):
-        self.SetUserAction(SIC_LGAD_PrimaryGeneratorAction())
+        self.SetUserAction(SiC_LGAD_PrimaryGeneratorAction())
         self.SetUserAction(SiC_LGAD_RunAction())
         eventAction = SiC_LGAD_aEventAction()
         self.SetUserAction(eventAction)
diff --git a/timeres/__init__.py b/resolution/__init__.py
similarity index 100%
rename from timeres/__init__.py
rename to resolution/__init__.py
diff --git a/timeres/add_noise.py b/resolution/add_noise.py
similarity index 98%
rename from timeres/add_noise.py
rename to resolution/add_noise.py
index b594633..3b3cec6 100644
--- a/timeres/add_noise.py
+++ b/resolution/add_noise.py
@@ -769,7 +769,7 @@ def save_time_resolution(input_file,sigma,error,efficiency,sigma_jitter,Landau_t
         f.write(str(sigma) + "," + str(error) + ","
                 + str(efficiency) + "," + str(sigma_jitter) + "," + str(Landau_timing) + "\n")
 
-def save_gain_efficiency(input_file, max_voltage, error_max_voltage, current_integral, error_current_integral):
+def save_charge(input_file, max_voltage, error_max_voltage, current_integral, error_current_integral):
     o_ls=input_file.split("/")[:]
     out_file=output(__file__, o_ls[2])+"/gain_efficiency_scan.csv"
 
@@ -851,11 +851,10 @@ def main(kwargs):
     out_root_f.Close()
     save_time_resolution(input_file,sigma,error,efficiency,sigma_jit,Landau_timing)  
 
-    if "lgad3D" in det_model:
-        # Draw gain efficiency, max voltage and current integral
-        max_voltage, error_max_voltage = draw_max_voltage(rset.max_voltage,output_path)
-        current_integral, error_current_integral = draw_current_integral(rset.current_integral,output_path)
-        save_gain_efficiency(input_file, max_voltage, error_max_voltage, current_integral, error_current_integral)
+    # Draw max voltage and current integral
+    max_voltage, error_max_voltage = draw_max_voltage(rset.max_voltage,output_path)
+    current_integral, error_current_integral = draw_current_integral(rset.current_integral,output_path)
+    save_charge(input_file, max_voltage, error_max_voltage, current_integral, error_current_integral)
 
 if __name__ == '__main__':
     args = sys.argv[1:]
diff --git a/timeres/time_scan.py b/resolution/time_scan.py
similarity index 100%
rename from timeres/time_scan.py
rename to resolution/time_scan.py
diff --git a/tct/source.py b/tct/laser.py
similarity index 91%
rename from tct/source.py
rename to tct/laser.py
index 7acd15e..b4cdaac 100644
--- a/tct/source.py
+++ b/tct/laser.py
@@ -6,7 +6,7 @@ import numpy as np
 
 from gen_signal.build_device import Detector
 
-class TCTTracks():
+class LaserInjection():
     """
     Description:
         Transfer Carrier Distribution from Laser Coordinate System 
@@ -15,7 +15,7 @@ class TCTTracks():
     ---------
     my_d : R3dDetector
         the Detector
-    laser : dict
+    laser_dic : dict
         the Parameter List of Your Laser
     x_rel,y_rel,z_rel:
         the Normalized Coordinate for Laser Focus 
@@ -24,42 +24,42 @@ class TCTTracks():
     ---------
         2021/09/13
     """
-    def __init__(self, my_d, laser):
+    def __init__(self, my_d: Detector, laser_dic: dict):
         #technique used
-        self.model = laser["laser_model"]
-        self.tech = laser["tech"]
-        self.direction = laser["direction"]
+        self.model = laser_dic["laser_model"]
+        self.tech = laser_dic["tech"]
+        self.direction = laser_dic["direction"]
         #material parameters to certain wavelength of the beam
-        self.refractionIndex = laser["refractionIndex"]
+        self.refractionIndex = laser_dic["refractionIndex"]
         if self.tech == "SPA":
-            self.alpha = laser["alpha"] # m^-1
+            self.alpha = laser_dic["alpha"] # m^-1
         if self.tech == "TPA":
-            self.beta_2 = laser["beta_2"]
+            self.beta_2 = laser_dic["beta_2"]
         #laser parameters
-        self.wavelength = laser["wavelength"]*1e-3 #um
-        self.temporal_FWHM = laser["temporal_FWHM"]
-        self.pulse_energy = laser["pulse_energy"]
-        self.spacial_FWHM = laser["spacial_FWHM"]#um
-        self.central_time = laser["central_time"]
-        if "l_Reyleigh" not in laser:
+        self.wavelength = laser_dic["wavelength"]*1e-3 #um
+        self.temporal_FWHM = laser_dic["temporal_FWHM"]
+        self.pulse_energy = laser_dic["pulse_energy"]
+        self.spacial_FWHM = laser_dic["spacial_FWHM"]#um
+        self.central_time = laser_dic["central_time"]
+        if "l_Reyleigh" not in laser_dic:
             w_0 = self.spacial_FWHM / (2 * np.log(2))**0.5
             self.l_Rayleigh = np.pi*w_0**2*self.refractionIndex/self.wavelength
         else:
-            self.l_Rayleigh = laser["l_Rayleigh"]#um
+            self.l_Rayleigh = laser_dic["l_Rayleigh"]#um
         #the size of the detector
         self.lx = my_d.l_x#um
         self.ly = my_d.l_y
         self.lz = my_d.l_z
         #relative and absolute position of the focus
-        self.fx_rel = laser["fx_rel"]
-        self.fy_rel = laser["fy_rel"]
-        self.fz_rel = laser["fz_rel"]
+        self.fx_rel = laser_dic["fx_rel"]
+        self.fy_rel = laser_dic["fy_rel"]
+        self.fz_rel = laser_dic["fz_rel"]
         self.fx_abs = self.fx_rel * self.lx
         self.fy_abs = self.fy_rel * self.ly
         self.fz_abs = self.fz_rel * self.lz
         #accuracy parameters
-        self.r_step = laser["r_step"]#um
-        self.h_step = laser["h_step"]#um
+        self.r_step = laser_dic["r_step"]#um
+        self.h_step = laser_dic["h_step"]#um
       
         self.mesh_definition(my_d)
 
diff --git a/tct/tct_signal.py b/tct/tct_signal.py
index 36e2407..e6bf5f8 100644
--- a/tct/tct_signal.py
+++ b/tct/tct_signal.py
@@ -16,7 +16,7 @@ from gen_signal import build_device as bdv
 from field import devsim_field as devfield
 from current import cal_current as ccrt
 from elec import readout as rdo
-from .source import TCTTracks
+from .laser import LaserInjection
 from util.output import output, create_path
 from gen_signal.draw_save import draw_current
 
@@ -63,7 +63,7 @@ def main(kwargs):
         amplifier = my_d.amplifier
 
     my_f = devfield.DevsimField(my_d.device, my_d.dimension, voltage, my_d.read_out_contact, my_d.irradiation_flux)
-    my_l = TCTTracks(my_d, laser_dic)
+    my_l = LaserInjection(my_d, laser_dic)
 
     my_current = ccrt.CalCurrentLaser(my_d, my_f, my_l)
     path = output(__file__, my_d.det_name, my_l.model)
diff --git a/tct/tct_signal_scan.py b/tct/tct_signal_scan.py
index 9f87abf..6c2642d 100644
--- a/tct/tct_signal_scan.py
+++ b/tct/tct_signal_scan.py
@@ -24,7 +24,7 @@ from elec import readout as rdo
 from gen_signal import draw_save
 from util.output import output
 
-from .source import TCTTracks
+from .laser import LaserInjection
 
 
 def batch_loop(my_d, my_f, my_g4p, amplifier, g4_seed, total_events, instance_number):
@@ -85,7 +85,7 @@ def job_main(kwargs):
         amplifier = my_d.amplifier
 
     my_f = devfield.DevsimField(my_d.device, my_d.dimension, voltage, my_d.read_out_contact, my_d.irradiation_flux)
-    my_l = TCTTracks(my_d, laser_dic)
+    my_l = LaserInjection(my_d, laser_dic)
 
     my_current = ccrt.CalCurrentLaser(my_d, my_f, my_l)
     path = output(__file__, my_d.det_name, my_l.model)
diff --git a/spaceres/__init__.py b/telescope/__init__.py
similarity index 100%
rename from spaceres/__init__.py
rename to telescope/__init__.py
diff --git a/spaceres/telescope_acts.py b/telescope/telescope_acts.py
similarity index 98%
rename from spaceres/telescope_acts.py
rename to telescope/telescope_acts.py
index a007c57..3140a82 100755
--- a/spaceres/telescope_acts.py
+++ b/telescope/telescope_acts.py
@@ -47,7 +47,7 @@ def main():
 
     field = acts.ConstantBField(acts.Vector3(0, 0, 1 * u.T))
 
-    outputDir = Path.cwd() / "output/spaceres/telescope_acts"
+    outputDir = Path.cwd() / "output/telescope/telescope_acts"
     if not outputDir.exists():
         outputDir.mkdir()
     inputDir = Path.cwd() / "setting/acts"
diff --git a/spaceres/telescope_g4.py b/telescope/telescope_g4.py
similarity index 100%
rename from spaceres/telescope_g4.py
rename to telescope/telescope_g4.py
diff --git a/spaceres/telescope_signal.py b/telescope/telescope_signal.py
similarity index 98%
rename from spaceres/telescope_signal.py
rename to telescope/telescope_signal.py
index 14ba421..7c4c5f0 100644
--- a/spaceres/telescope_signal.py
+++ b/telescope/telescope_signal.py
@@ -136,7 +136,7 @@ class Telescope:
         
         Name = "fit"+str(DUT)
         now = time.strftime("%Y_%m%d_%H%M")
-        path = os.path.join("output/spaceres/taichu_v1", str(now),'' )
+        path = os.path.join("output/telescope/taichu_v1", str(now),'' )
         #print(path)
         
         """ If the path does not exit, create the path"""
@@ -228,7 +228,7 @@ class Telescope:
         label.Draw()
         
         now = time.strftime("%Y_%m%d_%H%M")
-        path = os.path.join("output/spaceres/taichu_v1", str(now),'' )
+        path = os.path.join("output/telescope/taichu_v1", str(now),'' )
         #print(path)
         
         """ If the path does not exit, create the path"""
@@ -528,7 +528,7 @@ def taichu_v2(label=""):
     canvas.Draw()
     Name = "Res vs size"
     now = time.strftime("%Y_%m%d_%H%M")
-    path = os.path.join("output/spaceres/taichu_v2", str(now),'' )
+    path = os.path.join("output/telescope/taichu_v2", str(now),'' )
     """ If the path does not exit, create the path"""
     if not os.access(path, os.F_OK):
         os.makedirs(path) 
diff --git a/util/math.py b/util/math.py
index 924fde9..019b475 100644
--- a/util/math.py
+++ b/util/math.py
@@ -100,6 +100,7 @@ def get_common_interpolate_3d(data):
     return f
 
 def signal_convolution(signal_original: ROOT.TH1F, signal_convolved: ROOT.TH1F, pulse_responce_function_list: list[Callable[[float],float]]):
+    # assume so and sc share same bin width
     so = signal_original
     sc = signal_convolved
     st = ROOT.TH1F("signal_temp","signal_temp",so.GetNbinsX(),so.GetXaxis().GetXmin(),so.GetXaxis().GetXmax())
-- 
GitLab