def MakeSiggenWaveform(samp, r, z, ene, t0, smooth=1, phi=np.pi / 8): """ Use pysiggen to generate a waveform w/ arb. ADC amplitude. Thanks Ben. """ wf_length = samp # in tens of ns. This sets how long a wf you will simulate # r ranges from 0 to detector.detector_radius # phi ranges from 0 to np.pi/4 (Clint: Limit is the pcrad, set below) # z ranges from 0 to detector.detector_length (Clint: Limit is the pclen, set below) # energy sets the waveform amplitude # t0 sets the start point of the waveform # smooth is a gaussian smoothing parameter # default: r, phi, z, energy, t0, smooth = (15, np.pi/8, 15, 80, 10,15) # Probably don't mess around with anything in this block fitSamples = 1000 # ask me if you think you need to change this (you almost definitely don't) timeStepSize = 1 # don't change this, you'll break everything # Create a detector model (don't change any of this) detName = "../data/conf/P42574A_grad%0.2f_pcrad%0.2f_pclen%0.2f.conf" % ( 0.05, 2.5, 1.65) detector = Detector(detName, timeStep=timeStepSize, numSteps=fitSamples * 10. / timeStepSize, maxWfOutputLength=5000) detector.LoadFieldsGrad("../data/fields_impgrad.npz", pcLen=1.6, pcRad=2.5) # Sets the impurity gradient. Don't bother changing this detector.SetFieldsGradIdx(0) # First 3 params control the preamp shaping. # The 4th param is the RC decay, you can change that if you want. # params 5 and 6 are set not to do anything (theyre for the 2 rc constant decay model) rc_decay = 72.6 #us detector.SetTransferFunction(50, -0.814072377576, 0.82162729751, rc_decay, 1, 1) wf_notrap = np.copy( detector.MakeSimWaveform(r, phi, z, ene, t0, wf_length, h_smoothing=smooth)) timesteps = np.arange(0, wf_length) * 10 # makes it so your plot is in ns # Add charge trapping # trap_constants = [8, 28,288] # these are in microseconds # trap_constant_colors = ["red", "blue", "purple"] # for (idx, trap_rc) in enumerate(trap_constants): # detector.trapping_rc = trap_rc # wf = np.copy(detector.MakeSimWaveform(r, phi, z, ene, t0, wf_length, h_smoothing=smooth)) # ax0.plot(timesteps, wf, color = trap_constant_colors[idx], label = "%0.1f us trapping" % trap_rc ) # ax1.plot(timesteps, wf_notrap - wf, color = trap_constant_colors[idx]) # print "amplitude diff: %f" % ( (np.amax(wf_notrap) - np.amax(wf)) / np.amax(wf_notrap) ) return wf_notrap, timesteps
exit() siggen_wf_length = (max_sample_idx - np.amin(baselineLengths) + 10) * 10 output_wf_length = np.amax(wfLengths) + 1 #Create a detector model timeStepSize = 1 #ns detName = "conf/P42574A_grad%0.2f_pcrad%0.2f_pclen%0.2f.conf" % (0.05, 2.5, 1.65) det = Detector(detName, timeStep=timeStepSize, numSteps=siggen_wf_length, maxWfOutputLength=output_wf_length, t0_padding=100) det.LoadFieldsGrad(fieldFileName) det.SetFieldsGradIdx(10) def fit(directory): initializeDetectorAndWaveforms( det, wfs, ) initMultiThreading(numThreads) # Create a model object and a sampler model = Model() sampler = dnest4.DNest4Sampler(model, backend=dnest4.backends.CSVBackend( basedir="./" + directory, sep=" "))
def plot_waveforms(): wf_length = 200 #in tens of ns. This sets how long a wf you will simulate #Probably don't mess around with anything in this block fitSamples = 1000 #ask me if you think you need to change this (you almost definitely don't) timeStepSize = 1 #don't change this, you'll break everything #Create a detector model (don't change any of this) detName = "conf/P42574A_grad%0.2f_pcrad%0.2f_pclen%0.2f.conf" % (0.05, 2.5, 1.65) detector = Detector(detName, timeStep=timeStepSize, numSteps=fitSamples * 10. / timeStepSize, maxWfOutputLength=5000) detector.LoadFieldsGrad("fields_impgrad.npz", pcLen=1.6, pcRad=2.5) #sets the impurity gradient. Don't bother changing this detector.SetFieldsGradIdx(0) #First 3 params control the preamp shaping. #The 4th param is the RC decay, you can change that if you want. #params 5 and 6 are set not to do anything (theyre for the 2 rc constant decay model) rc_decay = 72.6 #us detector.SetTransferFunction(50, -0.814072377576, 0.82162729751, rc_decay, 1, 1) #r ranges from 0 to detector.detector_radius #phi ranges from 0 to np.pi/4 #z ranges from 0 to detector.detector_length #energy sets the waveform amplitude #t0 sets the start point of the waveform #smooth is a gaussian smoothing parameter r, phi, z, energy, t0, smooth = (15, np.pi / 8, 15, 80, 10, 15) trap_constants = [8, 28, 288] #these are in microseconds trap_constant_colors = ["red", "blue", "purple"] # fig1 = plt.figure(0, figsize=(20,10)) fig1 = plt.figure(0, figsize=(9, 7)) gs = gridspec.GridSpec(2, 1, height_ratios=[4, 1]) ax0 = plt.subplot(gs[0]) ax1 = plt.subplot(gs[1], sharex=ax0) ax1.set_xlabel("Digitizer Time [ns]") ax0.set_ylabel("Voltage [A.U.]") ax1.set_ylabel("Residual [A.U]") timesteps = np.arange(0, wf_length) * 10 #makes it so your plot is in ns wf_notrap = np.copy( detector.MakeSimWaveform(r, phi, z, energy, t0, wf_length, h_smoothing=smooth)) ax0.plot(timesteps, wf_notrap, color="green", label="No trapping") for (idx, trap_rc) in enumerate(trap_constants): detector.trapping_rc = trap_rc wf = np.copy( detector.MakeSimWaveform(r, phi, z, energy, t0, wf_length, h_smoothing=smooth)) ax0.plot(timesteps, wf, color=trap_constant_colors[idx], label="%0.1f us trapping" % trap_rc) ax1.plot(timesteps, wf_notrap - wf, color=trap_constant_colors[idx]) print "amplitude diff: %f" % ( (np.amax(wf_notrap) - np.amax(wf)) / np.amax(wf_notrap)) ax0.legend(loc=4) plt.show() plt.savefig("wf.pdf")
max_sample_idx = 150 #Prepare detector timeStepSize = 1 fitSamples = 200 detName = "conf/P42574A_grad%0.2f_pcrad%0.2f_pclen%0.2f.conf" % (0.05, 2.5, 1.65) detector = Detector(detName, timeStep=timeStepSize, numSteps=fitSamples * 10. / timeStepSize, maxWfOutputLength=fitSamples + max_sample_idx + 2) fieldFileName = "P42574A_fields_impgrad_0.00000-0.00100.npz" #sets the impurity gradient. Don't bother changing this detector.LoadFieldsGrad(fieldFileName) detector.SetFieldsGradIdx(33) b = 169.722312 c = -0.805889 d = 0.813206 rc1 = 72.904982 rc2 = 23.900887 rcfrac = 0.996435 fallPercentage = 0.99 detector.SetTransferFunction(b, c, d, rc1, rc2, rcfrac) h_100_mu0, h_100_beta, h_100_e0 = 337372.980584, 0.545879, 30.952525, h_111_mu0, h_111_beta, h_111_e0 = 452053.925755, 0.430484, 23.900887 detector.siggenInst.set_hole_params(h_100_mu0, h_100_beta, h_100_e0, h_111_mu0,
def main(argv): wfFileName = "P42574A_24_spread.npz" if os.path.isfile(wfFileName): data = np.load(wfFileName) wfs = data['wfs'] else: print "No saved waveforms available." exit(0) global wf wf = wfs[20] max_sample_idx = 150 fallPercentage = 0.97 wf.WindowWaveformAroundMax(fallPercentage=fallPercentage, rmsMult=2, earlySamples=max_sample_idx) baseline_length = wf.t0Guess print "wf length %d (entry %d from run %d)" % ( wf.wfLength, wf.entry_number, wf.runNumber) wf_length = wf.wfLength wf_max = np.argmax(wf.windowedWf) baseline_origin_idx = baseline_length - 30 if baseline_origin_idx < 0: print "not enough baseline!!" exit(0) initT0Padding(max_sample_idx, baseline_origin_idx) siggen_wf_length = (max_sample_idx - baseline_length + 10) * 10 global output_wf_length output_wf_length = wf_length + 1 #setup .ector timeStepSize = 1 fitSamples = 200 detName = "conf/P42574A_ben.conf" det = Detector( detName, timeStep=timeStepSize, numSteps=siggen_wf_length, maxWfOutputLength=output_wf_length, ) fieldFileName = "P42574A_fields_impgrad_0.00000-0.00100.npz" #sets the impurity gradient. Don't bother changing this det.LoadFieldsGrad(fieldFileName) det.SetFieldsGradIdx(np.int(imp_grad)) det.siggenInst.set_hole_params(h_100_mu0, h_100_beta, h_100_e0, h_111_mu0, h_111_beta, h_111_e0) det.trapping_rc = trapping_rc det.SetTransferFunction( tf_b, tf_c, tf_d, rc1, rc2, rcfrac, ) global detector detector = det directory = "" if len(argv) == 0: fit(directory) elif argv[0] == "plot": if len(argv) > 1: directory = argv[1] plot("sample.txt", directory) elif argv[0] == "plotpost": if len(argv) > 1: directory = argv[1] plot("posterior_sample.txt", directory) else: fit(argv[0])