c_delay = -17 TISC_sample_length = 16 delay_type_flag = 1 average_subtract_flag = 1 correlation_mean = np.zeros(63) correlation_mean.fill(50) filter_flag = 0 debug = False timestep = 1.0 / 2600000000.0 t = np.linspace(0, timestep * num_samples, num_samples) signal_amp = SNR * 2 * noise_sigma for i in range(0, 1): a_waveform = impulse_gen(num_samples, a_delay, upsample, draw_flag=0, output_dir='output/') empty_list = np.zeros(num_samples) difference = np.amax(a_waveform) - np.amin( a_waveform) # Get peak to peak voltage a_waveform *= (1 / difference) # Normalize input a_waveform *= signal_amp # Amplify a_imp_dig_wfm = digitize(a_waveform, num_samples, num_bits, digitization_factor=noise_sigma) a_waveform = np.add( a_waveform, generate_noise(num_samples, noise_sigma, filter_flag)) b_waveform = np.concatenate( [a_waveform[-b_delay:], empty_list[:(-1) * b_delay]])
def TISC_sim(SNR, threshold, b_input_delay, c_input_delay, num_bits=3, noise_sigma=32.0, sample_freq=2600000000.0, TISC_sample_length=16, num_samples=80, upsample=10, seed=5522684, draw_flag=0, digitization_factor=32.0, output_dir="output/", boresight=0, baseline=0, debug=False): # Setup save_output_flag = 0 #if(save_output_flag): #outfile = str(output_dir+"/test.root") trigger_flag = 0 #num_bits = 3 # Number of bits available to the digitizer #num_samples = num_samples*upsample filter_flag = False #sample_frequency = 2800000000.0 def_max_sum = 0.0 def_as_max_sum = 0.0 ghi_max_sum = 0.0 ghi_as_max_sum = 0.0 timestep = 1.0 / sample_freq # Phi sectors have alternating baselines if (boresight == 0): abc_impulse_amp = 1.000 def_impulse_amp = 0.835 elif (boresight == 1): abc_impulse_amp = 0.962 def_impulse_amp = 0.885 # Fill numpy arrays with zeros a_input_noise = np.zeros(num_samples) b_input_noise = np.zeros(num_samples) c_input_noise = np.zeros(num_samples) d_input_noise = np.zeros(num_samples) e_input_noise = np.zeros(num_samples) f_input_noise = np.zeros(num_samples) time = np.zeros(num_samples) upsampled_time = np.zeros(num_samples) a_input_signal = np.zeros(num_samples) b_input_signal = np.zeros(num_samples) c_input_signal = np.zeros(num_samples) d_input_signal = np.zeros(num_samples) e_input_signal = np.zeros(num_samples) f_input_signal = np.zeros(num_samples) a_input_signal_noise = np.zeros(num_samples) b_input_signal_noise = np.zeros(num_samples) c_input_signal_noise = np.zeros(num_samples) d_input_signal_noise = np.zeros(num_samples) e_input_signal_noise = np.zeros(num_samples) f_input_signal_noise = np.zeros(num_samples) a_dig_waveform = np.zeros(num_samples) b_dig_waveform = np.zeros(num_samples) c_dig_waveform = np.zeros(num_samples) d_dig_waveform = np.zeros(num_samples) e_dig_waveform = np.zeros(num_samples) f_dig_waveform = np.zeros(num_samples) empty_list = np.zeros(num_samples) ################################### # Generate Thermal Noise a_input_noise = generate_noise(num_samples, noise_sigma, filter_flag, seed=seed + 0) b_input_noise = generate_noise(num_samples, noise_sigma, filter_flag, seed=seed + 1) c_input_noise = generate_noise(num_samples, noise_sigma, filter_flag, seed=seed + 2) d_input_noise = generate_noise(num_samples, noise_sigma, filter_flag, seed=seed + 3) e_input_noise = generate_noise(num_samples, noise_sigma, filter_flag, seed=seed + 4) f_input_noise = generate_noise(num_samples, noise_sigma, filter_flag, seed=seed + 5) ################################### ##################################### # Determine RMS of noise and signal amplitude #noise_rms = np.sqrt(np.mean((a_input_noise-noise_mean)**2,)) signal_amp = SNR * 2 * noise_sigma ##################################### a_input_noise = butter_bandpass_filter(a_input_noise) b_input_noise = butter_bandpass_filter(b_input_noise) c_input_noise = butter_bandpass_filter(c_input_noise) d_input_noise = butter_bandpass_filter(d_input_noise) e_input_noise = butter_bandpass_filter(e_input_noise) f_input_noise = butter_bandpass_filter(f_input_noise) ##################################### # Generate impulse if (SNR != 0): # Generate Signal and Amplify a_input_signal = impulse_gen(num_samples, upsample, draw_flag=draw_flag, output_dir=output_dir) difference = np.amax(a_input_signal) - np.amin( a_input_signal) # Get peak to peak voltage a_input_signal *= (1 / difference) # Normalize input a_input_signal *= signal_amp # Amplify #b_input_signal = np.concatenate([a_input_signal[:num_samples+b_input_delay],empty_list[:(-1)*b_input_delay]]) #c_input_signal = np.concatenate([a_input_signal[:num_samples+c_input_delay],empty_list[:(-1)*c_input_delay]]) b_input_signal = np.concatenate([ a_input_signal[-b_input_delay:], empty_list[:(-1) * b_input_delay] ]) c_input_signal = np.concatenate([ a_input_signal[-c_input_delay:], empty_list[:(-1) * c_input_delay] ]) a_input_signal = a_input_signal * abc_impulse_amp b_input_signal = b_input_signal * abc_impulse_amp c_input_signal = c_input_signal * abc_impulse_amp d_input_signal = a_input_signal * def_impulse_amp e_input_signal = b_input_signal * def_impulse_amp f_input_signal = c_input_signal * def_impulse_amp """ time = np.linspace(0.0,timestep*num_samples,num_samples) plt.plot(time,a_input_signal,time,b_input_signal,time,c_input_signal) plt.plot(time,d_input_signal,time,e_input_signal,time,f_input_signal) plt.plot(time,g_input_signal,time,h_input_signal,time,i_input_signal) plt.title("impulse") plt.show() """ # Add the signal to the noise a_input_signal_noise = np.add(a_input_noise, a_input_signal) b_input_signal_noise = np.add(b_input_noise, b_input_signal) c_input_signal_noise = np.add(c_input_noise, c_input_signal) d_input_signal_noise = np.add(d_input_noise, d_input_signal) e_input_signal_noise = np.add(e_input_noise, e_input_signal) f_input_signal_noise = np.add(f_input_noise, f_input_signal) """ time = np.linspace(0.0,timestep*num_samples,num_samples) plt.plot(time,a_input_signal_noise,time,b_input_signal_noise,time,c_input_signal_noise) plt.plot(time,d_input_signal_noise,time,e_input_signal_noise,time,f_input_signal_noise) #plt.plot(time,g_input_signal_noise,time,h_input_signal_noise,time,i_input_signal_noise) plt.title("impulse+noise") plt.show() """ else: a_input_signal_noise = a_input_noise b_input_signal_noise = b_input_noise c_input_signal_noise = c_input_noise d_input_signal_noise = d_input_noise e_input_signal_noise = e_input_noise f_input_signal_noise = f_input_noise ########################################## #time = np.linspace(0.0,timestep*num_samples,num_samples) #plt.plot(time,a_input_noise,time,b_input_noise,time,c_input_noise) #plt.title("noise") #plt.show() ########################################## # Digitized the incoming signal and noise (RITC) a_dig_waveform = digitize(a_input_signal_noise, num_samples, num_bits, digitization_factor) b_dig_waveform = digitize(b_input_signal_noise, num_samples, num_bits, digitization_factor) c_dig_waveform = digitize(c_input_signal_noise, num_samples, num_bits, digitization_factor) d_dig_waveform = digitize(d_input_signal_noise, num_samples, num_bits, digitization_factor) e_dig_waveform = digitize(e_input_signal_noise, num_samples, num_bits, digitization_factor) f_dig_waveform = digitize(f_input_signal_noise, num_samples, num_bits, digitization_factor) ########################################## """ time = np.linspace(0.0,timestep*num_samples,num_samples) plt.plot(time,a_dig_waveform,time,b_dig_waveform,time,c_dig_waveform) plt.plot(time,d_dig_waveform,time,e_dig_waveform,time,f_dig_waveform) #plt.plot(time,g_dig_waveform,time,h_dig_waveform,time,i_dig_waveform) plt.title("Digitized") plt.show() """ ########################################## # Run the signal through the GLITC module to get trigger trigger_flag, max_total_sum, best_angle, total_sum = sum_correlate( num_samples, a_dig_waveform, b_dig_waveform, c_dig_waveform, d_dig_waveform, e_dig_waveform, f_dig_waveform, baseline, threshold, TISC_sample_length, debug=debug) #print abc_max_sum #print def_max_sum #print ghi_max_sum ######################################### #dummy = raw_input('Press any key to close') return max_total_sum, best_angle
def TISC_sim(SNR,threshold, b_input_delay,c_input_delay,num_bits=3, noise_sigma=32.0, sample_freq=2600000000.0,TISC_sample_length=16, num_samples=74,upsample=10,cw_flag=0, cw_rms=25.0,carrier_frequency=260000000.0,modulation_frequency=1.0, seed=5522684,draw_flag=0,digitization_factor=32.0, delay_type_flag=1, output_dir="output/",average_subtract_flag=0,correlation_mean=np.zeros(44),trial_run_number=1): #print b_input_delay # Setup save_output_flag = 0 #if(save_output_flag): #outfile = str(output_dir+"/test.root") trigger_flag = 0 #num_bits = 3 # Number of bits available to the digitizer filter_flag = False #print SNR # Fill numpy arrays with zeros a_input_noise = np.zeros(num_samples) b_input_noise = np.zeros(num_samples) c_input_noise = np.zeros(num_samples) a_input_noise_test = np.zeros(num_samples) b_input_noise_test = np.zeros(num_samples) c_input_noise_test = np.zeros(num_samples) a_input_signal = np.zeros(num_samples) b_input_signal = np.zeros(num_samples) c_input_signal = np.zeros(num_samples) a_dig_waveform = np.zeros(num_samples) b_dig_waveform = np.zeros(num_samples) c_dig_waveform = np.zeros(num_samples) cw_noise = np.zeros(num_samples) empty_list = np.zeros(num_samples) ################################### # Generate Thermal Noise a_input_noise = generate_noise(num_samples,noise_sigma,filter_flag) b_input_noise = generate_noise(num_samples,noise_sigma,filter_flag) c_input_noise = generate_noise(num_samples,noise_sigma,filter_flag) #a_input_noise_test = a_input_noise #b_input_noise_test = b_input_noise #c_input_noise_test = c_input_noise ################################### #print a_input_noise[0] #print b_input_noise[0] #print c_input_noise[0] ##################################### # Determine signal amplitude signal_amp = SNR*2*noise_sigma ##################################### ################################# #Generate CW & thermal noise if cw_flag: cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,cw_rms,filter_flag) a_input_noise = np.add(a_input_noise,cw_noise) #cw_noise = generate_cw(num_samples,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) b_input_noise = np.add(b_input_noise,cw_noise) #cw_noise = generate_cw(num_samples,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) c_input_noise = np.add(c_input_noise,cw_noise) ##################################### # Filter the noise a_input_noise = butter_bandpass_filter(a_input_noise) b_input_noise = butter_bandpass_filter(b_input_noise) c_input_noise = butter_bandpass_filter(c_input_noise) #print "Filter Took: " +str(datetime.now()-start_filter) #start_signal = datetime.now() ##################################### # Generate impulse if (SNR != 0): # Generate Signal and Amplify a_input_signal = impulse_gen(num_samples,upsample,draw_flag=draw_flag,output_dir=output_dir) difference=np.amax(a_input_signal)-np.amin(a_input_signal) # Get peak to peak voltage a_input_signal *= (1/difference) # Normalize input a_input_signal *= signal_amp # Amplify b_input_signal = np.concatenate([a_input_signal[:num_samples+b_input_delay],empty_list[:(-1)*b_input_delay]]) c_input_signal = np.concatenate([a_input_signal[:num_samples+c_input_delay],empty_list[:(-1)*c_input_delay]]) # Add the signal to the noise a_input_signal = np.add(a_input_noise, a_input_signal) b_input_signal = np.add(b_input_noise, b_input_signal) c_input_signal = np.add(c_input_noise, c_input_signal) else: a_input_signal = a_input_noise b_input_signal = b_input_noise c_input_signal = c_input_noise ########################################## ########################################## # Digitized the incoming signal and noise (RITC) a_dig_waveform = digitize(a_input_signal,num_samples,num_bits,digitization_factor) b_dig_waveform = digitize(b_input_signal,num_samples,num_bits,digitization_factor) c_dig_waveform = digitize(c_input_signal,num_samples,num_bits,digitization_factor) ########################################## #print a_dig_waveform ########################################## # Run the signal through the GLITC module to get trigger if (average_subtract_flag): trigger_flag, max_sum, as_max_sum, correlation_mean, test_sum, as_test_sum = sum_correlate(num_samples,a_dig_waveform,b_dig_waveform,c_dig_waveform, threshold,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=correlation_mean,trial_run_number=trial_run_number) else: trigger_flag, max_sum, test_sum = sum_correlate(num_samples,a_dig_waveform,b_dig_waveform,c_dig_waveform, threshold,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=correlation_mean) """ if (max_sum>800): import matplotlib.pyplot as plt #print a_dig_waveform #print b_dig_waveform #print c_dig_waveform #print np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform) #print (np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform))**2 #print np.sum((np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform))**2) time = np.linspace(0.0,((num_samples*(10**9))/sample_freq), num_samples) plt.figure(1) plt.clf() plt.plot(time,a_dig_waveform) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch A") plt.savefig(output_dir+"/ch_A_large_correlation.png") plt.figure(2) plt.clf() plt.plot(time,b_dig_waveform) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch B") plt.savefig(output_dir+"/ch_B_large_correlation.png") plt.figure(3) plt.clf() plt.plot(time,c_dig_waveform) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch C") plt.savefig(output_dir+"/ch_C_large_correlation.png") plt.figure(4) plt.clf() plt.plot(time,np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform)) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("ABC Added") plt.savefig(output_dir+"/ABC_large_correlation.png") plt.figure(5) plt.clf() plt.plot(time,(np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform))**2) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("ABC Square Added") plt.savefig(output_dir+"/ABC_square_large_correlation.png") plt.figure(6) plt.clf() plt.plot(time,a_input_noise_test) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch A Thermal Noise") plt.savefig(output_dir+"/ch_A_thermal_large_correlation.png") plt.figure(7) plt.clf() plt.plot(time,b_input_noise_test) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch B Thermal Noise") plt.savefig(output_dir+"/ch_B_thermal_large_correlation.png") plt.figure(8) plt.clf() plt.plot(time,c_input_noise_test) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch C Thermal Noise") plt.savefig(output_dir+"/ch_C_thermal_large_correlation.png") plt.figure(9) plt.clf() plt.plot(time,cw_noise) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("CW Noise") plt.savefig(output_dir+"/cw_large_correlation.png") plt.show() """ ######################################### ######################################### # Output data #if(save_output_flag): # Now to more ROOT stuff #rf_tree.Fill() #f.Write() #f.Close() if draw_flag: dummy = raw_input('Press any key to close') #print "Everything took: " +str(datetime.now()-start_time) if (average_subtract_flag): return trigger_flag, max_sum, as_max_sum, correlation_mean, test_sum, as_test_sum else: return trigger_flag, max_sum
def TISC_sim(SNR,threshold, b_input_delay,c_input_delay,num_bits=3, noise_sigma=32.0, sample_freq=2600000000.0,TISC_sample_length=16, num_samples=80,upsample=10,cw_flag=0, cw_amplitude=20.0,carrier_frequency=260000000.0,modulation_frequency=1.0, seed=5522684,draw_flag=0,digitization_factor=32.0, delay_type_flag=1, output_dir="output/",average_subtract_flag=0,abc_correlation_mean=np.zeros(46), def_correlation_mean=np.zeros(44),ghi_correlation_mean=np.zeros(46),trial_run_number=1,boresight=0,baseline=0,six_phi_sector_add=False,window_length=0,window_weight=0.5, debug=False): # Setup save_output_flag = 0 #if(save_output_flag): #outfile = str(output_dir+"/test.root") trigger_flag = 0 #num_bits = 3 # Number of bits available to the digitizer #num_samples = num_samples*upsample filter_flag = False #sample_frequency = 2800000000.0 def_max_sum = 0.0 def_as_max_sum = 0.0 ghi_max_sum = 0.0 ghi_as_max_sum = 0.0 timestep = 1.0/sample_freq # Phi sectors have alternating baselines if(boresight==0): abc_impulse_amp = 1.000 def_impulse_amp = 0.835 ghi_impulse_amp = 0.776 if(baseline==0): abc_baseline = 0 def_baseline = 1 ghi_baseline = 1 elif(baseline==1): abc_baseline = 1 def_baseline = 0 ghi_baseline = 0 elif(boresight==1): abc_impulse_amp = 0.962 def_impulse_amp = 0.885 ghi_impulse_amp = 0.650 if(baseline==0): abc_baseline = 1 def_baseline = 0 ghi_baseline = 1 elif(baseline==1): abc_baseline = 1 def_baseline = 0 ghi_baseline = 0 # Fill numpy arrays with zeros a_input_noise = np.zeros(num_samples) b_input_noise = np.zeros(num_samples) c_input_noise = np.zeros(num_samples) d_input_noise = np.zeros(num_samples) e_input_noise = np.zeros(num_samples) f_input_noise = np.zeros(num_samples) g_input_noise = np.zeros(num_samples) h_input_noise = np.zeros(num_samples) i_input_noise = np.zeros(num_samples) time = np.zeros(num_samples) upsampled_time = np.zeros(num_samples) a_input_signal = np.zeros(num_samples) b_input_signal = np.zeros(num_samples) c_input_signal = np.zeros(num_samples) d_input_signal = np.zeros(num_samples) e_input_signal = np.zeros(num_samples) f_input_signal = np.zeros(num_samples) g_input_signal = np.zeros(num_samples) h_input_signal = np.zeros(num_samples) i_input_signal = np.zeros(num_samples) a_input_signal_noise = np.zeros(num_samples) b_input_signal_noise = np.zeros(num_samples) c_input_signal_noise = np.zeros(num_samples) d_input_signal_noise = np.zeros(num_samples) e_input_signal_noise = np.zeros(num_samples) f_input_signal_noise = np.zeros(num_samples) g_input_signal_noise = np.zeros(num_samples) h_input_signal_noise = np.zeros(num_samples) i_input_signal_noise = np.zeros(num_samples) a_dig_waveform = np.zeros(num_samples) b_dig_waveform = np.zeros(num_samples) c_dig_waveform = np.zeros(num_samples) d_dig_waveform = np.zeros(num_samples) e_dig_waveform = np.zeros(num_samples) f_dig_waveform = np.zeros(num_samples) g_dig_waveform = np.zeros(num_samples) h_dig_waveform = np.zeros(num_samples) i_dig_waveform = np.zeros(num_samples) empty_list = np.zeros(num_samples) ################################### # Generate Thermal Noise a_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed) b_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+1) c_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+2) d_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+3) e_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+4) f_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+5) g_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+6) h_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+7) i_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+8) ################################### ##################################### # Determine RMS of noise and signal amplitude #noise_rms = np.sqrt(np.mean((a_input_noise-noise_mean)**2,)) signal_amp = SNR*2*noise_sigma ##################################### ################################# #Generate CW noise if desired if cw_flag: cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,cw_amplitude,filter_flag) a_input_noise = np.add(a_input_noise,cw_noise)#generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) #a_input_noise += a_input_cw_noise # b_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) b_input_noise = np.add(cw_noise,b_input_noise) #c_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) c_input_noise = np.add(cw_noise,c_input_noise) #d_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) d_input_noise = np.add(cw_noise,d_input_noise) #e_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) e_input_noise = np.add(cw_noise,e_input_noise) #f_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) f_input_noise = np.add(cw_noise,f_input_noise) #g_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) g_input_noise = np.add(cw_noise,g_input_noise) #h_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) h_input_noise = np.add(cw_noise,h_input_noise) #i_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) i_input_noise = np.add(cw_noise,i_input_noise) ##################################### a_input_noise = butter_bandpass_filter(a_input_noise) b_input_noise = butter_bandpass_filter(b_input_noise) c_input_noise = butter_bandpass_filter(c_input_noise) d_input_noise = butter_bandpass_filter(d_input_noise) e_input_noise = butter_bandpass_filter(e_input_noise) f_input_noise = butter_bandpass_filter(f_input_noise) g_input_noise = butter_bandpass_filter(g_input_noise) h_input_noise = butter_bandpass_filter(h_input_noise) i_input_noise = butter_bandpass_filter(i_input_noise) ##################################### # Generate impulse if (SNR != 0): # Generate Signal and Amplify a_input_signal = impulse_gen(num_samples,upsample,draw_flag=draw_flag,output_dir=output_dir) difference=np.amax(a_input_signal)-np.amin(a_input_signal) # Get peak to peak voltage a_input_signal *= (1/difference) # Normalize input a_input_signal *= signal_amp # Amplify #b_input_signal = np.concatenate([a_input_signal[:num_samples+b_input_delay],empty_list[:(-1)*b_input_delay]]) #c_input_signal = np.concatenate([a_input_signal[:num_samples+c_input_delay],empty_list[:(-1)*c_input_delay]]) b_input_signal = np.concatenate([a_input_signal[-b_input_delay:],empty_list[:(-1)*b_input_delay]]) c_input_signal = np.concatenate([a_input_signal[-c_input_delay:],empty_list[:(-1)*c_input_delay]]) a_input_signal =a_input_signal*abc_impulse_amp b_input_signal =b_input_signal*abc_impulse_amp c_input_signal =c_input_signal*abc_impulse_amp d_input_signal =a_input_signal*def_impulse_amp e_input_signal =b_input_signal*def_impulse_amp f_input_signal =c_input_signal*def_impulse_amp g_input_signal =a_input_signal*ghi_impulse_amp h_input_signal =b_input_signal*ghi_impulse_amp i_input_signal =c_input_signal*ghi_impulse_amp """ if(boresight==0): d_input_signal = a_input_signal*0.776 # Average dB loss at -22.5 degrees e_input_signal = b_input_signal*0.776 # from Seavey measurements f_input_signal = c_input_signal*0.776 g_input_signal = a_input_signal*0.835 # Average dB loss at +22.5 degrees h_input_signal = b_input_signal*0.835 # from Seavey measurements i_input_signal = c_input_signal*0.835 elif(boresight==1): # For event between two phi sectors, the two antennas are down by about -0.5dB at a_input_signal = a_input_signal*0.885 # Average dB los at +11.25 degrees b_input_signal = b_input_signal*0.885 # from Seavey measurements c_input_signal = c_input_signal*0.885 d_input_signal = a_input_signal*0.962 # Average dB loss at -11.25 degrees e_input_signal = b_input_signal*0.962 # from Seavey measurements f_input_signal = c_input_signal*0.962 g_input_signal = a_input_signal*0.650 # Average dB loss at +-33.75 degrees h_input_signal = b_input_signal*0.650 # from Seavey measurements i_input_signal = c_input_signal*0.650 """ if(debug): time = np.linspace(0.0,timestep*num_samples,num_samples) plt.plot(time,a_input_signal,time,b_input_signal,time,c_input_signal) plt.plot(time,d_input_signal,time,e_input_signal,time,f_input_signal) plt.plot(time,g_input_signal,time,h_input_signal,time,i_input_signal) plt.title("impulse") plt.show() # Add the signal to the noise a_input_signal_noise = np.add(a_input_noise, a_input_signal) b_input_signal_noise = np.add(b_input_noise, b_input_signal) c_input_signal_noise = np.add(c_input_noise, c_input_signal) d_input_signal_noise = np.add(d_input_noise, d_input_signal) e_input_signal_noise = np.add(e_input_noise, e_input_signal) f_input_signal_noise = np.add(f_input_noise, f_input_signal) g_input_signal_noise = np.add(g_input_noise, g_input_signal) h_input_signal_noise = np.add(h_input_noise, h_input_signal) i_input_signal_noise = np.add(i_input_noise, i_input_signal) if(debug): time = np.linspace(0.0,timestep*num_samples,num_samples) #plt.plot(time,a_input_signal_noise,time,b_input_signal_noise,time,c_input_signal_noise) #plt.plot(time,d_input_signal_noise,time,e_input_signal_noise,time,f_input_signal_noise) plt.plot(time,g_input_signal_noise,time,h_input_signal_noise,time,i_input_signal_noise) plt.title("impulse+noise") plt.show() else: a_input_signal_noise = a_input_noise b_input_signal_noise = b_input_noise c_input_signal_noise = c_input_noise d_input_signal_noise = d_input_noise e_input_signal_noise = e_input_noise f_input_signal_noise = f_input_noise g_input_signal_noise = g_input_noise h_input_signal_noise = h_input_noise i_input_signal_noise = i_input_noise ########################################## #time = np.linspace(0.0,timestep*num_samples,num_samples) #plt.plot(time,a_input_noise,time,b_input_noise,time,c_input_noise) #plt.title("noise") #plt.show() ########################################## # Digitized the incoming signal and noise (RITC) a_dig_waveform = digitize(a_input_signal_noise,num_samples,num_bits,digitization_factor) b_dig_waveform = digitize(b_input_signal_noise,num_samples,num_bits,digitization_factor) c_dig_waveform = digitize(c_input_signal_noise,num_samples,num_bits,digitization_factor) d_dig_waveform = digitize(d_input_signal_noise,num_samples,num_bits,digitization_factor) e_dig_waveform = digitize(e_input_signal_noise,num_samples,num_bits,digitization_factor) f_dig_waveform = digitize(f_input_signal_noise,num_samples,num_bits,digitization_factor) g_dig_waveform = digitize(g_input_signal_noise,num_samples,num_bits,digitization_factor) h_dig_waveform = digitize(h_input_signal_noise,num_samples,num_bits,digitization_factor) i_dig_waveform = digitize(i_input_signal_noise,num_samples,num_bits,digitization_factor) ########################################## if(debug): time = np.linspace(0.0,timestep*num_samples,num_samples) #plt.plot(time,a_dig_waveform,time,b_dig_waveform,time,c_dig_waveform) #plt.plot(time,d_dig_waveform,time,e_dig_waveform,time,f_dig_waveform) plt.plot(time,g_dig_waveform,time,h_dig_waveform,time,i_dig_waveform) plt.title("Digitized") plt.show() ########################################## # Run the signal through the GLITC module to get trigger if(average_subtract_flag): abc_trigger_flag, abc_max_sum , abc_as_max_sum, abc_correlation_mean, abc_test_sum, abc_as_test_sum,as_abc_angle,abc_angle,d1,d2 = sum_correlate(num_samples,a_dig_waveform,b_dig_waveform,c_dig_waveform,threshold,abc_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=abc_correlation_mean,trial_run_number=trial_run_number) def_trigger_flag, def_max_sum , def_as_max_sum, def_correlation_mean, def_test_sum, def_as_test_sum,as_def_angle,def_angle,d1,d2 = sum_correlate(num_samples,d_dig_waveform,e_dig_waveform,f_dig_waveform,threshold,def_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=def_correlation_mean,trial_run_number=trial_run_number) ghi_trigger_flag, ghi_max_sum , ghi_as_max_sum, ghi_correlation_mean, ghi_test_sum, ghi_as_test_sum,as_ghi_angle,ghi_angle,d1,d2 = sum_correlate(num_samples,g_dig_waveform,h_dig_waveform,i_dig_waveform,threshold,ghi_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=ghi_correlation_mean,trial_run_number=trial_run_number) #abc_max_sum #print len(a_dig_waveform) else: abc_trigger_flag, abc_max_sum,abc_angle,d1 = sum_correlate(num_samples,a_dig_waveform,b_dig_waveform,c_dig_waveform,threshold,abc_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=abc_correlation_mean,trial_run_number=trial_run_number,window_length=window_length,window_weight=window_weight) def_trigger_flag, def_max_sum,def_angle,d1 = sum_correlate(num_samples,d_dig_waveform,e_dig_waveform,f_dig_waveform,threshold,def_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=def_correlation_mean,trial_run_number=trial_run_number,window_length=window_length,window_weight=window_weight) ghi_trigger_flag, ghi_max_sum,ghi_angle,d1 = sum_correlate(num_samples,g_dig_waveform,h_dig_waveform,i_dig_waveform,threshold,ghi_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=ghi_correlation_mean,trial_run_number=trial_run_number,window_length=window_length,window_weight=window_weight) #print abc_max_sum #print def_max_sum #print ghi_max_sum #if(abc_trigger_flag & def_trigger_flag & ghi_trigger_flag): #trigger_flag = True #else: #trigger_flag = False ######################################### #dummy = raw_input('Press any key to close') if (average_subtract_flag): return abc_max_sum,abc_as_max_sum,def_max_sum,def_as_max_sum,ghi_max_sum,ghi_as_max_sum,abc_correlation_mean, def_correlation_mean, ghi_correlation_mean,as_abc_angle,abc_angle,as_def_angle,def_angle,as_ghi_angle,ghi_angle else: return abc_max_sum,def_max_sum,ghi_max_sum,abc_angle,def_angle,ghi_angle
def TISC_sim(SNR,threshold, b_input_delay,c_input_delay,num_bits=3, noise_sigma=32.0, sample_freq=2600000000.0,TISC_sample_length=16, num_samples=80,upsample=10,cw_flag=0, cw_amplitude=20.0,carrier_frequency=260000000.0,modulation_frequency=1.0, seed=5522684,draw_flag=0,digitization_factor=32.0, delay_type_flag=1, output_dir="output/",average_subtract_flag=0,abc_correlation_mean=np.zeros(46), def_correlation_mean=np.zeros(44),ghi_correlation_mean=np.zeros(46),trial_run_number=1,boresight=0,baseline=0,six_phi_sector_add=False): # Setup save_output_flag = 0 #if(save_output_flag): #outfile = str(output_dir+"/test.root") trigger_flag = 0 #num_bits = 3 # Number of bits available to the digitizer #num_samples = num_samples*upsample filter_flag = False #sample_frequency = 2800000000.0 def_max_sum = 0.0 def_as_max_sum = 0.0 ghi_max_sum = 0.0 ghi_as_max_sum = 0.0 timestep = 1.0/sample_freq # Phi sectors have alternating baselines if(boresight==0): abc_impulse_amp = 1.000 def_impulse_amp = 0.835 ghi_impulse_amp = 0.776 if(baseline==0): abc_baseline = 0 def_baseline = 1 ghi_baseline = 1 elif(baseline==1): abc_baseline = 1 def_baseline = 0 ghi_baseline = 0 elif(boresight==1): abc_impulse_amp = 0.962 def_impulse_amp = 0.885 ghi_impulse_amp = 0.650 if(baseline==0): abc_baseline = 1 def_baseline = 0 ghi_baseline = 1 elif(baseline==1): abc_baseline = 1 def_baseline = 0 ghi_baseline = 0 # Fill numpy arrays with zeros a_input_noise = np.zeros(num_samples) b_input_noise = np.zeros(num_samples) c_input_noise = np.zeros(num_samples) d_input_noise = np.zeros(num_samples) e_input_noise = np.zeros(num_samples) f_input_noise = np.zeros(num_samples) g_input_noise = np.zeros(num_samples) h_input_noise = np.zeros(num_samples) i_input_noise = np.zeros(num_samples) time = np.zeros(num_samples) upsampled_time = np.zeros(num_samples) a_input_signal = np.zeros(num_samples) b_input_signal = np.zeros(num_samples) c_input_signal = np.zeros(num_samples) d_input_signal = np.zeros(num_samples) e_input_signal = np.zeros(num_samples) f_input_signal = np.zeros(num_samples) g_input_signal = np.zeros(num_samples) h_input_signal = np.zeros(num_samples) i_input_signal = np.zeros(num_samples) a_input_signal_noise = np.zeros(num_samples) b_input_signal_noise = np.zeros(num_samples) c_input_signal_noise = np.zeros(num_samples) d_input_signal_noise = np.zeros(num_samples) e_input_signal_noise = np.zeros(num_samples) f_input_signal_noise = np.zeros(num_samples) g_input_signal_noise = np.zeros(num_samples) h_input_signal_noise = np.zeros(num_samples) i_input_signal_noise = np.zeros(num_samples) a_dig_waveform = np.zeros(num_samples) b_dig_waveform = np.zeros(num_samples) c_dig_waveform = np.zeros(num_samples) d_dig_waveform = np.zeros(num_samples) e_dig_waveform = np.zeros(num_samples) f_dig_waveform = np.zeros(num_samples) g_dig_waveform = np.zeros(num_samples) h_dig_waveform = np.zeros(num_samples) i_dig_waveform = np.zeros(num_samples) empty_list = np.zeros(num_samples) ################################### # Generate Thermal Noise a_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed) b_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+1) c_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+2) d_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+3) e_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+4) f_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+5) g_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+6) h_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+7) i_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+8) ################################### ##################################### # Determine RMS of noise and signal amplitude #noise_rms = np.sqrt(np.mean((a_input_noise-noise_mean)**2,)) signal_amp = SNR*2*noise_sigma ##################################### ################################# #Generate CW noise if desired if cw_flag: cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,cw_amplitude,filter_flag) a_input_noise = np.add(a_input_noise,cw_noise)#generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) #a_input_noise += a_input_cw_noise # b_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) b_input_noise = np.add(cw_noise,b_input_noise) #c_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) c_input_noise = np.add(cw_noise,c_input_noise) #d_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) d_input_noise = np.add(cw_noise,d_input_noise) #e_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) e_input_noise = np.add(cw_noise,e_input_noise) #f_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) f_input_noise = np.add(cw_noise,f_input_noise) #g_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) g_input_noise = np.add(cw_noise,g_input_noise) #h_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) h_input_noise = np.add(cw_noise,h_input_noise) #i_input_cw_noise = generate_cw(num_samples,upsample,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) i_input_noise = np.add(cw_noise,i_input_noise) ##################################### a_input_noise = butter_bandpass_filter(a_input_noise) b_input_noise = butter_bandpass_filter(b_input_noise) c_input_noise = butter_bandpass_filter(c_input_noise) d_input_noise = butter_bandpass_filter(d_input_noise) e_input_noise = butter_bandpass_filter(e_input_noise) f_input_noise = butter_bandpass_filter(f_input_noise) g_input_noise = butter_bandpass_filter(g_input_noise) h_input_noise = butter_bandpass_filter(h_input_noise) i_input_noise = butter_bandpass_filter(i_input_noise) ##################################### # Generate impulse if (SNR != 0): # Generate Signal and Amplify a_input_signal = impulse_gen(num_samples,upsample,draw_flag=draw_flag,output_dir=output_dir) difference=np.amax(a_input_signal)-np.amin(a_input_signal) # Get peak to peak voltage a_input_signal *= (1/difference) # Normalize input a_input_signal *= signal_amp # Amplify #b_input_signal = np.concatenate([a_input_signal[:num_samples+b_input_delay],empty_list[:(-1)*b_input_delay]]) #c_input_signal = np.concatenate([a_input_signal[:num_samples+c_input_delay],empty_list[:(-1)*c_input_delay]]) b_input_signal = np.concatenate([a_input_signal[-b_input_delay:],empty_list[:(-1)*b_input_delay]]) c_input_signal = np.concatenate([a_input_signal[-c_input_delay:],empty_list[:(-1)*c_input_delay]]) a_input_signal =a_input_signal*abc_impulse_amp b_input_signal =b_input_signal*abc_impulse_amp c_input_signal =c_input_signal*abc_impulse_amp d_input_signal =a_input_signal*def_impulse_amp e_input_signal =b_input_signal*def_impulse_amp f_input_signal =c_input_signal*def_impulse_amp g_input_signal =a_input_signal*ghi_impulse_amp h_input_signal =b_input_signal*ghi_impulse_amp i_input_signal =c_input_signal*ghi_impulse_amp """ if(boresight==0): d_input_signal = a_input_signal*0.776 # Average dB loss at -22.5 degrees e_input_signal = b_input_signal*0.776 # from Seavey measurements f_input_signal = c_input_signal*0.776 g_input_signal = a_input_signal*0.835 # Average dB loss at +22.5 degrees h_input_signal = b_input_signal*0.835 # from Seavey measurements i_input_signal = c_input_signal*0.835 elif(boresight==1): # For event between two phi sectors, the two antennas are down by about -0.5dB at a_input_signal = a_input_signal*0.885 # Average dB los at +11.25 degrees b_input_signal = b_input_signal*0.885 # from Seavey measurements c_input_signal = c_input_signal*0.885 d_input_signal = a_input_signal*0.962 # Average dB loss at -11.25 degrees e_input_signal = b_input_signal*0.962 # from Seavey measurements f_input_signal = c_input_signal*0.962 g_input_signal = a_input_signal*0.650 # Average dB loss at +-33.75 degrees h_input_signal = b_input_signal*0.650 # from Seavey measurements i_input_signal = c_input_signal*0.650 """ """ time = np.linspace(0.0,timestep*num_samples,num_samples) plt.plot(time,a_input_signal,time,b_input_signal,time,c_input_signal) plt.plot(time,d_input_signal,time,e_input_signal,time,f_input_signal) plt.plot(time,g_input_signal,time,h_input_signal,time,i_input_signal) plt.title("impulse") plt.show() """ # Add the signal to the noise a_input_signal_noise = np.add(a_input_noise, a_input_signal) b_input_signal_noise = np.add(b_input_noise, b_input_signal) c_input_signal_noise = np.add(c_input_noise, c_input_signal) d_input_signal_noise = np.add(d_input_noise, d_input_signal) e_input_signal_noise = np.add(e_input_noise, e_input_signal) f_input_signal_noise = np.add(f_input_noise, f_input_signal) g_input_signal_noise = np.add(g_input_noise, g_input_signal) h_input_signal_noise = np.add(h_input_noise, h_input_signal) i_input_signal_noise = np.add(i_input_noise, i_input_signal) """ time = np.linspace(0.0,timestep*num_samples,num_samples) #plt.plot(time,a_input_signal_noise,time,b_input_signal_noise,time,c_input_signal_noise) #plt.plot(time,d_input_signal_noise,time,e_input_signal_noise,time,f_input_signal_noise) plt.plot(time,g_input_signal_noise,time,h_input_signal_noise,time,i_input_signal_noise) plt.title("impulse+noise") plt.show() """ else: a_input_signal_noise = a_input_noise b_input_signal_noise = b_input_noise c_input_signal_noise = c_input_noise d_input_signal_noise = d_input_noise e_input_signal_noise = e_input_noise f_input_signal_noise = f_input_noise g_input_signal_noise = g_input_noise h_input_signal_noise = h_input_noise i_input_signal_noise = i_input_noise ########################################## #time = np.linspace(0.0,timestep*num_samples,num_samples) #plt.plot(time,a_input_noise,time,b_input_noise,time,c_input_noise) #plt.title("noise") #plt.show() ########################################## # Digitized the incoming signal and noise (RITC) a_dig_waveform = digitize(a_input_signal_noise,num_samples,num_bits,digitization_factor) b_dig_waveform = digitize(b_input_signal_noise,num_samples,num_bits,digitization_factor) c_dig_waveform = digitize(c_input_signal_noise,num_samples,num_bits,digitization_factor) d_dig_waveform = digitize(d_input_signal_noise,num_samples,num_bits,digitization_factor) e_dig_waveform = digitize(e_input_signal_noise,num_samples,num_bits,digitization_factor) f_dig_waveform = digitize(f_input_signal_noise,num_samples,num_bits,digitization_factor) g_dig_waveform = digitize(g_input_signal_noise,num_samples,num_bits,digitization_factor) h_dig_waveform = digitize(h_input_signal_noise,num_samples,num_bits,digitization_factor) i_dig_waveform = digitize(i_input_signal_noise,num_samples,num_bits,digitization_factor) ########################################## """ time = np.linspace(0.0,timestep*num_samples,num_samples) #plt.plot(time,a_dig_waveform,time,b_dig_waveform,time,c_dig_waveform) #plt.plot(time,d_dig_waveform,time,e_dig_waveform,time,f_dig_waveform) plt.plot(time,g_dig_waveform,time,h_dig_waveform,time,i_dig_waveform) plt.title("Digitized") plt.show() """ ########################################## # Run the signal through the GLITC module to get trigger if(average_subtract_flag): abc_trigger_flag, abc_max_sum , abc_as_max_sum, abc_correlation_mean, abc_test_sum, abc_as_test_sum,as_abc_angle,abc_angle,d1,d2 = sum_correlate(num_samples,a_dig_waveform,b_dig_waveform,c_dig_waveform,threshold,abc_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=abc_correlation_mean,trial_run_number=trial_run_number) def_trigger_flag, def_max_sum , def_as_max_sum, def_correlation_mean, def_test_sum, def_as_test_sum,as_def_angle,def_angle,d1,d2 = sum_correlate(num_samples,d_dig_waveform,e_dig_waveform,f_dig_waveform,threshold,def_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=def_correlation_mean,trial_run_number=trial_run_number) ghi_trigger_flag, ghi_max_sum , ghi_as_max_sum, ghi_correlation_mean, ghi_test_sum, ghi_as_test_sum,as_ghi_angle,ghi_angle,d1,d2 = sum_correlate(num_samples,g_dig_waveform,h_dig_waveform,i_dig_waveform,threshold,ghi_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=ghi_correlation_mean,trial_run_number=trial_run_number) #abc_max_sum #print len(a_dig_waveform) else: abc_trigger_flag, abc_max_sum,abc_andle,d1 = sum_correlate(num_samples,a_dig_waveform,b_dig_waveform,c_dig_waveform,threshold,abc_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=abc_correlation_mean,trial_run_number=trial_run_number) def_trigger_flag, def_max_sum,def_angle,d1 = sum_correlate(num_samples,d_dig_waveform,e_dig_waveform,f_dig_waveform,threshold,def_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=def_correlation_mean,trial_run_number=trial_run_number) ghi_trigger_flag, ghi_max_sum,ghi_angle,d1 = sum_correlate(num_samples,g_dig_waveform,h_dig_waveform,i_dig_waveform,threshold,ghi_baseline,TISC_sample_length,delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag,correlation_mean=ghi_correlation_mean,trial_run_number=trial_run_number) #print abc_max_sum #print def_max_sum #print ghi_max_sum #if(abc_trigger_flag & def_trigger_flag & ghi_trigger_flag): #trigger_flag = True #else: #trigger_flag = False ######################################### #dummy = raw_input('Press any key to close') if (average_subtract_flag): return abc_max_sum,abc_as_max_sum,def_max_sum,def_as_max_sum,ghi_max_sum,ghi_as_max_sum,abc_correlation_mean, def_correlation_mean, ghi_correlation_mean,as_abc_angle,abc_angle,as_def_angle,def_angle,as_ghi_angle,ghi_angle else: return abc_max_sum,def_max_sum,ghi_max_sum,abc_angle,def_angle,ghi_angle
def TISC_sim(SNR,threshold, b_input_delay,c_input_delay,num_bits=3, noise_sigma=32.0, sample_freq=2600000000.0,TISC_sample_length=16, num_samples=80,upsample=10, seed=5522684,draw_flag=0,digitization_factor=32.0, output_dir="output/",boresight=0,baseline=0,debug=False): # Setup save_output_flag = 0 #if(save_output_flag): #outfile = str(output_dir+"/test.root") trigger_flag = 0 #num_bits = 3 # Number of bits available to the digitizer #num_samples = num_samples*upsample filter_flag = False #sample_frequency = 2800000000.0 def_max_sum = 0.0 def_as_max_sum = 0.0 ghi_max_sum = 0.0 ghi_as_max_sum = 0.0 timestep = 1.0/sample_freq # Phi sectors have alternating baselines if(boresight==0): abc_impulse_amp = 1.000 def_impulse_amp = 0.835 elif(boresight==1): abc_impulse_amp = 0.962 def_impulse_amp = 0.885 # Fill numpy arrays with zeros a_input_noise = np.zeros(num_samples) b_input_noise = np.zeros(num_samples) c_input_noise = np.zeros(num_samples) d_input_noise = np.zeros(num_samples) e_input_noise = np.zeros(num_samples) f_input_noise = np.zeros(num_samples) time = np.zeros(num_samples) upsampled_time = np.zeros(num_samples) a_input_signal = np.zeros(num_samples) b_input_signal = np.zeros(num_samples) c_input_signal = np.zeros(num_samples) d_input_signal = np.zeros(num_samples) e_input_signal = np.zeros(num_samples) f_input_signal = np.zeros(num_samples) a_input_signal_noise = np.zeros(num_samples) b_input_signal_noise = np.zeros(num_samples) c_input_signal_noise = np.zeros(num_samples) d_input_signal_noise = np.zeros(num_samples) e_input_signal_noise = np.zeros(num_samples) f_input_signal_noise = np.zeros(num_samples) a_dig_waveform = np.zeros(num_samples) b_dig_waveform = np.zeros(num_samples) c_dig_waveform = np.zeros(num_samples) d_dig_waveform = np.zeros(num_samples) e_dig_waveform = np.zeros(num_samples) f_dig_waveform = np.zeros(num_samples) empty_list = np.zeros(num_samples) ################################### # Generate Thermal Noise a_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+0) b_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+1) c_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+2) d_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+3) e_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+4) f_input_noise = generate_noise(num_samples,noise_sigma,filter_flag,seed=seed+5) ################################### ##################################### # Determine RMS of noise and signal amplitude #noise_rms = np.sqrt(np.mean((a_input_noise-noise_mean)**2,)) signal_amp = SNR*2*noise_sigma ##################################### a_input_noise = butter_bandpass_filter(a_input_noise) b_input_noise = butter_bandpass_filter(b_input_noise) c_input_noise = butter_bandpass_filter(c_input_noise) d_input_noise = butter_bandpass_filter(d_input_noise) e_input_noise = butter_bandpass_filter(e_input_noise) f_input_noise = butter_bandpass_filter(f_input_noise) ##################################### # Generate impulse if (SNR != 0): # Generate Signal and Amplify a_input_signal = impulse_gen(num_samples,upsample,draw_flag=draw_flag,output_dir=output_dir) difference=np.amax(a_input_signal)-np.amin(a_input_signal) # Get peak to peak voltage a_input_signal *= (1/difference) # Normalize input a_input_signal *= signal_amp # Amplify #b_input_signal = np.concatenate([a_input_signal[:num_samples+b_input_delay],empty_list[:(-1)*b_input_delay]]) #c_input_signal = np.concatenate([a_input_signal[:num_samples+c_input_delay],empty_list[:(-1)*c_input_delay]]) b_input_signal = np.concatenate([a_input_signal[-b_input_delay:],empty_list[:(-1)*b_input_delay]]) c_input_signal = np.concatenate([a_input_signal[-c_input_delay:],empty_list[:(-1)*c_input_delay]]) a_input_signal =a_input_signal*abc_impulse_amp b_input_signal =b_input_signal*abc_impulse_amp c_input_signal =c_input_signal*abc_impulse_amp d_input_signal =a_input_signal*def_impulse_amp e_input_signal =b_input_signal*def_impulse_amp f_input_signal =c_input_signal*def_impulse_amp """ time = np.linspace(0.0,timestep*num_samples,num_samples) plt.plot(time,a_input_signal,time,b_input_signal,time,c_input_signal) plt.plot(time,d_input_signal,time,e_input_signal,time,f_input_signal) plt.plot(time,g_input_signal,time,h_input_signal,time,i_input_signal) plt.title("impulse") plt.show() """ # Add the signal to the noise a_input_signal_noise = np.add(a_input_noise, a_input_signal) b_input_signal_noise = np.add(b_input_noise, b_input_signal) c_input_signal_noise = np.add(c_input_noise, c_input_signal) d_input_signal_noise = np.add(d_input_noise, d_input_signal) e_input_signal_noise = np.add(e_input_noise, e_input_signal) f_input_signal_noise = np.add(f_input_noise, f_input_signal) """ time = np.linspace(0.0,timestep*num_samples,num_samples) plt.plot(time,a_input_signal_noise,time,b_input_signal_noise,time,c_input_signal_noise) plt.plot(time,d_input_signal_noise,time,e_input_signal_noise,time,f_input_signal_noise) #plt.plot(time,g_input_signal_noise,time,h_input_signal_noise,time,i_input_signal_noise) plt.title("impulse+noise") plt.show() """ else: a_input_signal_noise = a_input_noise b_input_signal_noise = b_input_noise c_input_signal_noise = c_input_noise d_input_signal_noise = d_input_noise e_input_signal_noise = e_input_noise f_input_signal_noise = f_input_noise ########################################## #time = np.linspace(0.0,timestep*num_samples,num_samples) #plt.plot(time,a_input_noise,time,b_input_noise,time,c_input_noise) #plt.title("noise") #plt.show() ########################################## # Digitized the incoming signal and noise (RITC) a_dig_waveform = digitize(a_input_signal_noise,num_samples,num_bits,digitization_factor) b_dig_waveform = digitize(b_input_signal_noise,num_samples,num_bits,digitization_factor) c_dig_waveform = digitize(c_input_signal_noise,num_samples,num_bits,digitization_factor) d_dig_waveform = digitize(d_input_signal_noise,num_samples,num_bits,digitization_factor) e_dig_waveform = digitize(e_input_signal_noise,num_samples,num_bits,digitization_factor) f_dig_waveform = digitize(f_input_signal_noise,num_samples,num_bits,digitization_factor) ########################################## """ time = np.linspace(0.0,timestep*num_samples,num_samples) plt.plot(time,a_dig_waveform,time,b_dig_waveform,time,c_dig_waveform) plt.plot(time,d_dig_waveform,time,e_dig_waveform,time,f_dig_waveform) #plt.plot(time,g_dig_waveform,time,h_dig_waveform,time,i_dig_waveform) plt.title("Digitized") plt.show() """ ########################################## # Run the signal through the GLITC module to get trigger trigger_flag, max_total_sum,best_angle,total_sum = sum_correlate(num_samples,a_dig_waveform,b_dig_waveform,c_dig_waveform,d_dig_waveform,e_dig_waveform,f_dig_waveform,baseline,threshold,TISC_sample_length,debug=debug) #print abc_max_sum #print def_max_sum #print ghi_max_sum ######################################### #dummy = raw_input('Press any key to close') return max_total_sum,best_angle
def TISC_sim(SNR, threshold, b_input_delay, c_input_delay, num_bits=3, noise_sigma=32.0, sample_freq=2600000000.0, TISC_sample_length=16, num_samples=74, upsample=10, cw_flag=0, cw_rms=25.0, carrier_frequency=260000000.0, modulation_frequency=1.0, seed=5522684, draw_flag=0, digitization_factor=32.0, delay_type_flag=1, output_dir="output/", average_subtract_flag=0, correlation_mean=np.zeros(44), trial_run_number=1): #print b_input_delay # Setup save_output_flag = 0 #if(save_output_flag): #outfile = str(output_dir+"/test.root") trigger_flag = 0 #num_bits = 3 # Number of bits available to the digitizer filter_flag = False #print SNR # Fill numpy arrays with zeros a_input_noise = np.zeros(num_samples) b_input_noise = np.zeros(num_samples) c_input_noise = np.zeros(num_samples) a_input_noise_test = np.zeros(num_samples) b_input_noise_test = np.zeros(num_samples) c_input_noise_test = np.zeros(num_samples) a_input_signal = np.zeros(num_samples) b_input_signal = np.zeros(num_samples) c_input_signal = np.zeros(num_samples) a_dig_waveform = np.zeros(num_samples) b_dig_waveform = np.zeros(num_samples) c_dig_waveform = np.zeros(num_samples) cw_noise = np.zeros(num_samples) empty_list = np.zeros(num_samples) ################################### # Generate Thermal Noise a_input_noise = generate_noise(num_samples, noise_sigma, filter_flag) b_input_noise = generate_noise(num_samples, noise_sigma, filter_flag) c_input_noise = generate_noise(num_samples, noise_sigma, filter_flag) #a_input_noise_test = a_input_noise #b_input_noise_test = b_input_noise #c_input_noise_test = c_input_noise ################################### #print a_input_noise[0] #print b_input_noise[0] #print c_input_noise[0] ##################################### # Determine signal amplitude signal_amp = SNR * 2 * noise_sigma ##################################### ################################# #Generate CW & thermal noise if cw_flag: cw_noise = generate_cw(num_samples, upsample, sample_freq, carrier_frequency, modulation_frequency, cw_rms, filter_flag) a_input_noise = np.add(a_input_noise, cw_noise) #cw_noise = generate_cw(num_samples,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) b_input_noise = np.add(b_input_noise, cw_noise) #cw_noise = generate_cw(num_samples,sample_freq,carrier_frequency,modulation_frequency,peak_amplitude,filter_flag) c_input_noise = np.add(c_input_noise, cw_noise) ##################################### # Filter the noise a_input_noise = butter_bandpass_filter(a_input_noise) b_input_noise = butter_bandpass_filter(b_input_noise) c_input_noise = butter_bandpass_filter(c_input_noise) #print "Filter Took: " +str(datetime.now()-start_filter) #start_signal = datetime.now() ##################################### # Generate impulse if (SNR != 0): # Generate Signal and Amplify a_input_signal = impulse_gen(num_samples, upsample, draw_flag=draw_flag, output_dir=output_dir) difference = np.amax(a_input_signal) - np.amin( a_input_signal) # Get peak to peak voltage a_input_signal *= (1 / difference) # Normalize input a_input_signal *= signal_amp # Amplify b_input_signal = np.concatenate([ a_input_signal[:num_samples + b_input_delay], empty_list[:(-1) * b_input_delay] ]) c_input_signal = np.concatenate([ a_input_signal[:num_samples + c_input_delay], empty_list[:(-1) * c_input_delay] ]) # Add the signal to the noise a_input_signal = np.add(a_input_noise, a_input_signal) b_input_signal = np.add(b_input_noise, b_input_signal) c_input_signal = np.add(c_input_noise, c_input_signal) else: a_input_signal = a_input_noise b_input_signal = b_input_noise c_input_signal = c_input_noise ########################################## ########################################## # Digitized the incoming signal and noise (RITC) a_dig_waveform = digitize(a_input_signal, num_samples, num_bits, digitization_factor) b_dig_waveform = digitize(b_input_signal, num_samples, num_bits, digitization_factor) c_dig_waveform = digitize(c_input_signal, num_samples, num_bits, digitization_factor) ########################################## #print a_dig_waveform ########################################## # Run the signal through the GLITC module to get trigger if (average_subtract_flag): trigger_flag, max_sum, as_max_sum, correlation_mean, test_sum, as_test_sum = sum_correlate( num_samples, a_dig_waveform, b_dig_waveform, c_dig_waveform, threshold, TISC_sample_length, delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag, correlation_mean=correlation_mean, trial_run_number=trial_run_number) else: trigger_flag, max_sum, test_sum = sum_correlate( num_samples, a_dig_waveform, b_dig_waveform, c_dig_waveform, threshold, TISC_sample_length, delay_type_flag=delay_type_flag, average_subtract_flag=average_subtract_flag, correlation_mean=correlation_mean) """ if (max_sum>800): import matplotlib.pyplot as plt #print a_dig_waveform #print b_dig_waveform #print c_dig_waveform #print np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform) #print (np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform))**2 #print np.sum((np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform))**2) time = np.linspace(0.0,((num_samples*(10**9))/sample_freq), num_samples) plt.figure(1) plt.clf() plt.plot(time,a_dig_waveform) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch A") plt.savefig(output_dir+"/ch_A_large_correlation.png") plt.figure(2) plt.clf() plt.plot(time,b_dig_waveform) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch B") plt.savefig(output_dir+"/ch_B_large_correlation.png") plt.figure(3) plt.clf() plt.plot(time,c_dig_waveform) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch C") plt.savefig(output_dir+"/ch_C_large_correlation.png") plt.figure(4) plt.clf() plt.plot(time,np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform)) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("ABC Added") plt.savefig(output_dir+"/ABC_large_correlation.png") plt.figure(5) plt.clf() plt.plot(time,(np.add(np.add(a_dig_waveform,b_dig_waveform),c_dig_waveform))**2) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("ABC Square Added") plt.savefig(output_dir+"/ABC_square_large_correlation.png") plt.figure(6) plt.clf() plt.plot(time,a_input_noise_test) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch A Thermal Noise") plt.savefig(output_dir+"/ch_A_thermal_large_correlation.png") plt.figure(7) plt.clf() plt.plot(time,b_input_noise_test) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch B Thermal Noise") plt.savefig(output_dir+"/ch_B_thermal_large_correlation.png") plt.figure(8) plt.clf() plt.plot(time,c_input_noise_test) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Ch C Thermal Noise") plt.savefig(output_dir+"/ch_C_thermal_large_correlation.png") plt.figure(9) plt.clf() plt.plot(time,cw_noise) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("CW Noise") plt.savefig(output_dir+"/cw_large_correlation.png") plt.show() """ ######################################### ######################################### # Output data #if(save_output_flag): # Now to more ROOT stuff #rf_tree.Fill() #f.Write() #f.Close() if draw_flag: dummy = raw_input('Press any key to close') #print "Everything took: " +str(datetime.now()-start_time) if (average_subtract_flag): return trigger_flag, max_sum, as_max_sum, correlation_mean, test_sum, as_test_sum else: return trigger_flag, max_sum
a_delay = 0 b_delay = -15 c_delay = -17 TISC_sample_length = 16 delay_type_flag = 1 average_subtract_flag = 1 correlation_mean = np.zeros(63) correlation_mean.fill(50) filter_flag = 0 debug = False timestep = 1.0 / 2600000000.0 t = np.linspace(0, timestep * num_samples, num_samples) signal_amp = SNR * 2 * noise_sigma for i in range(0, 1): a_waveform = impulse_gen(num_samples, a_delay, upsample, draw_flag=0, output_dir="output/") empty_list = np.zeros(num_samples) difference = np.amax(a_waveform) - np.amin(a_waveform) # Get peak to peak voltage a_waveform *= 1 / difference # Normalize input a_waveform *= signal_amp # Amplify a_imp_dig_wfm = digitize(a_waveform, num_samples, num_bits, digitization_factor=noise_sigma) a_waveform = np.add(a_waveform, generate_noise(num_samples, noise_sigma, filter_flag)) b_waveform = np.concatenate([a_waveform[-b_delay:], empty_list[: (-1) * b_delay]]) c_waveform = np.concatenate([a_waveform[-c_delay:], empty_list[: (-1) * c_delay]]) b_waveform = np.add(b_waveform, generate_noise(num_samples, noise_sigma, filter_flag)) c_waveform = np.add(c_waveform, generate_noise(num_samples, noise_sigma, filter_flag)) d_waveform = np.add(a_waveform, generate_noise(num_samples, noise_sigma, filter_flag)) e_waveform = np.concatenate([d_waveform[-b_delay:], empty_list[: (-1) * b_delay]]) f_waveform = np.concatenate([d_waveform[-c_delay:], empty_list[: (-1) * c_delay]]) e_waveform = np.add(b_waveform, generate_noise(num_samples, noise_sigma, filter_flag))
upsample_length = upsample*sample_length impulse_sample = np.zeros(sample_length) impulse_upsample = np.zeros(upsample_length) impulse_downsample = np.zeros(sample_length) #impulse_upsample_fit_poly = np.zeros(poly_index) impulse_upsample_fit = np.zeros(upsample_length) impulse_noise_sample = np.zeros(sample_length) digitized_sample = np.zeros(sample_length) noise_sample = np.zeros(sample_length) cw_sample = np.zeros(sample_length) #noise_cw_sample = np.zeros(sample_length) time = np.linspace(0.0,((sample_length*(10**9))/sample_frequency), sample_length) impulse_sample = impulse_gen(sample_length,impulse_position,upsample,sample_frequency,draw_flag=draw_flag,output_dir=output_dir) """ upsample_time = np.linspace(0.0,((upsample_length*(10**9))/(sample_frequency*upsample)), upsample_length) plt.figure(2,figsize=(16,8)) plt.clf() plt.plot(upsample_time,impulse_upsample[0:upsample_length]) plt.xlabel("Time [ns]") plt.ylabel("Amplitude [unitless]") plt.title("Upsampled Impulse Simulation") if (save_plot_flag): plt.savefig("plots/upsample_impulse_sample.png") """ signal_amp = (2*SNR*noise_sigma) difference=np.amax(impulse_sample)-np.amin(impulse_sample) # Get peak to peak voltage