12from scipy.fftpack
import fft, ifft
16from array
import array
25def EvalGamComp(tin, ttrg):
29 FastTau = 851.28 * (0.88348588)
30 SlowTau = 5802.0 * (0.88348588)
31 val = Ratio * ((1. / FastTau) * np.exp(-(tin - ttrg) / FastTau)) + \
32 (1 - Ratio) * ((1. / SlowTau) * np.exp(-(tin - ttrg) / SlowTau))
36def EvalHadronComp(tin, ttrg):
37 HadronTau = 630. * (0.88348588)
40 val = ((1. / HadronTau) * np.exp(-(tin - ttrg) / HadronTau))
44def EvalAnyComp(tin, ttrg, TauIn):
48 val = ((1. / TauIn) * np.exp(-(tin - ttrg) / TauIn))
52def CalcShaperOutput(muonShaper, muonInitial, inputPreShaper, ITER):
53 impulse = (ifft(fft(muonShaper) / fft(muonInitial)))
54 outputShaper = np.real(ifft(fft(impulse) * fft(inputPreShaper)))
55 base = outputShaper[ITER]
57 while i < len(outputShaper):
58 outputShaper[i] -= base
61 print(outputShaper.max())
65def GetShaperOutput(ratio, flg, shaperMuonFunc):
71 PMT_trigger_time = 1000. * to_ns
75 ShaperDSP_output_muon_array = []
76 PMT_output_muon_array = []
79 for i
in range(0, Ns):
83 ShaperDSP_output_muon_array.append(shaperMuonFunc[i])
84 PMT_output_muon_array.append(EvalGamComp(t, PMT_trigger_time))
86 PMT_output_array.append((1 - ratio) * EvalGamComp(t, PMT_trigger_time) + ratio * (EvalHadronComp(t, PMT_trigger_time)))
88 PMT_output_array.append((2 - ratio) * EvalGamComp(t, PMT_trigger_time) +
89 (ratio - 1) * (EvalAnyComp(t, PMT_trigger_time, 10)))
92 return Time, PMT_output_array
94 return Time, PMT_output_muon_array
96 return Time, ShaperDSP_output_muon_array
98 ShaperDSP_output_array = []
100 ShaperDSP_output_array = CalcShaperOutput(ShaperDSP_output_muon_array, PMT_output_muon_array, PMT_output_array, 0)
102 ShaperDSP_output_array = CalcShaperOutput(ShaperDSP_output_muon_array, PMT_output_muon_array, PMT_output_array, 30)
106 Time_us.append(Time[j] / (1000.))
108 return Time_us, ShaperDSP_output_array
111OutputDirectory =
"./"
112if (OutputDirectory ==
""):
113 print(
"Error set output directory")
117def argument_parser():
118 parser = argparse.ArgumentParser(description=__doc__)
119 parser.add_argument(
'Low', type=int, help=
'First CellID to be processed')
120 parser.add_argument(
'High', type=int, help=
'Last CellID to be processed')
124args = argument_parser().parse_args()
130f1 = ROOT.TFile(OutputDirectory +
"PhotonShapes_Low" + str(Low) +
"_High" + str(High) +
".root",
"update")
133entries = mt.GetEntries()
138outFile = TFile(OutputDirectory +
"HadronShapes_Low" + str(Low) +
"_High" + str(High) +
".root",
"RECREATE")
139outTree = ROOT.TTree(
"HadronTree",
"")
140TimeAll_A = array(
'd', 1000 * [0.])
141ValuePhoton_A = array(
'd', 1000 * [0.])
142ValueHadron_A = array(
'd', 1000 * [0.])
143ValueDiode_A = array(
'd', 1000 * [0.])
144outTree.Branch(
"TimeAll_A", TimeAll_A,
'TimeAll_A[1000]/D')
145outTree.Branch(
"ValuePhoton_A", ValuePhoton_A,
'ValuePhoton_A[1000]/D')
146outTree.Branch(
"ValueHadron_A", ValueHadron_A,
'ValueHadron_A[1000]/D')
147outTree.Branch(
"ValueDiode_A", ValueDiode_A,
'ValueDiode_A[1000]/D')
150for i
in range(entries):
152 if (mt.PhotonArray[1] < -100):
153 for j
in range(1000):
154 ValuePhoton_A[j] = -999
156 ValueHadron_A[j] = -999
157 ValueDiode_A[j] = -999
160 Time3, ValuesHadron_A = GetShaperOutput(1, flag, mt.PhotonArray)
161 Time4, ValuesDiode_A = GetShaperOutput(2, flag, mt.PhotonArray)
162 Time6, ValuesPhoton_A = GetShaperOutput(0, flag, mt.PhotonArray)
165 for j
in range(1000):
167 ValuePhoton_A[j] = mt.PhotonArray[j * factor]
169 ValuePhoton_A[j] = ValuesPhoton_A[j * factor]
170 TimeAll_A[j] = Time3[j * factor]
171 ValueHadron_A[j] = ValuesHadron_A[j * factor]
172 ValueDiode_A[j] = ValuesDiode_A[j * factor]