From 1da6921c0d104188d173afb911c206c893b0b660 Mon Sep 17 00:00:00 2001
From: fuchenxi <1256257282@qq.com>
Date: Sun, 22 Sep 2024 22:46:23 +0800
Subject: [PATCH] =?UTF-8?q?Amplifier=E5=AE=9A=E4=B9=89=E4=B8=8ECalCurrent?=
 =?UTF-8?q?=E8=A7=A3=E8=80=A6=E5=90=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 elec/ele_readout.py           | 25 ++++++++++++-------------
 gen_signal/gen_signal_main.py |  4 ++--
 tct/tct_signal.py             |  2 +-
 tct/tct_t1.py                 |  2 +-
 4 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/elec/ele_readout.py b/elec/ele_readout.py
index 1ec8d03..8bd795b 100644
--- a/elec/ele_readout.py
+++ b/elec/ele_readout.py
@@ -14,7 +14,6 @@ import json
 
 import ROOT
 
-from current.cal_current import CalCurrent
 from util.math import signal_convolution
 
 time_step = 50e-12
@@ -53,7 +52,7 @@ class Amplifier:
     ---------
         2024/09/14
     """
-    def __init__(self, my_current: CalCurrent, amplifier_name: str, time_step = time_step):
+    def __init__(self, currents: list[ROOT.TH1F], amplifier_name: str, time_step = time_step):
         self.ele = []
 
         ele_json = "./setting/electronics/" + amplifier_name + ".json"
@@ -61,11 +60,11 @@ class Amplifier:
             self.amplifier_parameters = json.load(f)
 
         self.ele_name = self.amplifier_parameters['ele_name']
-        self.read_ele_num = my_current.read_ele_num
+        self.read_ele_num = len(currents)
 
         self.amplifier_define()
-        self.fill_amplifier_output(my_current, time_step)
-        self.set_scope_output(my_current)
+        self.fill_amplifier_output(currents, time_step)
+        self.set_scope_output(currents)
 
     def amplifier_define(self):
         """
@@ -161,20 +160,20 @@ class Amplifier:
             self.pulse_responce = pulse_responce_BB
             self.scale = scale_BB
 
-    def fill_amplifier_output(self, my_current, time_step):
+    def fill_amplifier_output(self, currents: list[ROOT.TH1F], time_step):
         for i in range(self.read_ele_num):
-            sum_cu = my_current.sum_cu[i]
-            n_bin = sum_cu.GetNbinsX()
-            t_bin = sum_cu.GetBinWidth(0)
+            cu = currents[i]
+            n_bin = cu.GetNbinsX()
+            t_bin = cu.GetBinWidth(0)
             time_duration = n_bin * t_bin
             self.ele.append(ROOT.TH1F("electronics %s"%(self.ele_name)+str(i+1), "electronics %s"%(self.ele_name),
                                 int(time_duration/time_step), 0, time_duration))
             self.ele[i].Reset()
-            signal_convolution(sum_cu, self.pulse_responce, self.ele[i])
+            signal_convolution(cu, self.pulse_responce, self.ele[i])
     
-    def set_scope_output(self, my_current):
+    def set_scope_output(self, currents: list[ROOT.TH1F]):
         for i in range(self.read_ele_num):
-            sum_cu = my_current.sum_cu[i]
-            input_Q_tot = sum_cu.Integral()
+            cu = currents[i]
+            input_Q_tot = cu.Integral()
             output_Q_max = self.ele[i].GetMaximum()
             self.ele[i].Scale(self.scale(output_Q_max, input_Q_tot))
diff --git a/gen_signal/gen_signal_main.py b/gen_signal/gen_signal_main.py
index 1a7ea28..2a05157 100644
--- a/gen_signal/gen_signal_main.py
+++ b/gen_signal/gen_signal_main.py
@@ -101,7 +101,7 @@ def main(kwargs):
         subprocess.run(['ngspice -b -r t0.raw output/T0_tmp.cir'], shell=True)
         ng.plot_waveform()
     else:
-        ele_current = rdout.Amplifier(my_current, amplifier)
+        ele_current = rdout.Amplifier(my_current.sum_cu, amplifier)
         draw_save.draw_plots(my_d,ele_current,my_f,my_g4p,my_current)
     
     del my_f
@@ -145,7 +145,7 @@ def batch_loop(my_d, my_f, my_g4p, amplifier, g4_seed, total_events, instance_nu
         if len(my_g4p.p_steps[event-start_n]) > 5:
             effective_number += 1
             my_current = ccrt.CalCurrentG4P(my_d, my_f, my_g4p, event-start_n)
-            ele_current = rdout.Amplifier(my_current, amplifier)
+            ele_current = rdout.Amplifier(my_current.sum_cu, amplifier)
             draw_save.save_signal_time_resolution(my_d,event,ele_current,my_g4p,start_n,my_f)
             del ele_current
     detection_efficiency =  effective_number/(end_n-start_n) 
diff --git a/tct/tct_signal.py b/tct/tct_signal.py
index 1caca25..f4f9789 100644
--- a/tct/tct_signal.py
+++ b/tct/tct_signal.py
@@ -85,7 +85,7 @@ def main(kwargs):
         subprocess.run(['ngspice -b -r t0.raw output/T0_tmp.cir'], shell=True)
         ng.plot_waveform()
     else:
-        ele_current = rdout.Amplifier(my_current, amplifier)
+        ele_current = rdout.Amplifier(my_current.sum_cu, amplifier)
     
     if kwargs['scan'] != None: #assume parameter alter
         key = my_l.fz_rel
diff --git a/tct/tct_t1.py b/tct/tct_t1.py
index cb27db0..7cc4d52 100644
--- a/tct/tct_t1.py
+++ b/tct/tct_t1.py
@@ -26,7 +26,7 @@ my_f = raser.FenicsCal(my_d, dset.fenics)
 my_l = raser.TCTTracks(my_d, dset.laser)
 
 my_current = raser.CalCurrentLaser(my_d, my_f, my_l)
-ele_current = raser.Amplifier(my_current, dset.amplifier)
+ele_current = raser.Amplifier(my_current.sum_cu, dset.amplifier)
 save_TTree.save_signal_TTree(dset,my_d,my_l.fx_rel,ele_current,my_f)
 my_current.save_current(dset,my_d,my_l,my_f,"fx_rel")
 
-- 
GitLab