Beispiel #1
0
def GetAreas(filepath, channel_num, filter_order):
    #Parameters for calculating area of the traces
    left_lim = 925  #Left limit index value of timestep to begin calculating area
    right_lim = 1150  #Right limit index value of timestep to begin calculating area
    avg_start = 250  #The index value of timestep to begin calculation of average

    #arrays to hold data
    areas = []
    max_times = []
    time_arr = []
    y_arr = []
    clean_y_arr = []

    #Get events from run file
    events = SBCtools.BuildEventList(filepath)

    #Loop through events
    for ev in events:
        #Get traces from event
        pmt_data = SBCcode.get_event(filepath,
                                     ev,
                                     "PMTtraces",
                                     max_file_size=1300)["PMTtraces"]
        n_triggers = pmt_data["traces"].shape[0]

        #Loop through traces
        for trig in range(n_triggers):
            #Calculate the time value
            xd = 1e9 * np.arange(
                pmt_data["traces"].shape[2]) * pmt_data["dt"][trig, 0]
            #Calculate voltage value from the correct channel
            if channel_num == 0:
                y = pmt_data["traces"][trig, 0, :] * pmt_data["v_scale"][trig, 0] + \
                       pmt_data["v_offset"][trig, 0]
            else:
                y = pmt_data["traces"][trig, 1, :] * pmt_data["v_scale"][trig, 1] + \
                   pmt_data["v_offset"][trig, 1]

            #Filter the noise if the order is valid
            if filter_order != 0:
                cleaned_y = FilterData(y, filter_order)
                avg = np.average(cleaned_y[avg_start:left_lim])  #Cleaned Avg
                pmt_area = np.sum(cleaned_y[left_lim:right_lim] -
                                  avg)  #Calculate Area
                #store clean y
                clean_y_arr.append(cleaned_y)

            #If no filter applied
            else:
                avg = np.average(y[avg_start:left_lim])  #Average of raw data
                pmt_area = np.sum(y[left_lim:right_lim] - avg)  #Calculate Area

            #Append area to areas array
            areas.append(pmt_area)

            #Store time and y arrays
            y_arr.append(y)
            time_arr.append(xd)

            # #Append max times to array. Not sure if necessary, but will keep here for now
            # max_times.append(1e9 * pmt_data["dt"][trig, 0] * np.argmax(pmt_data["traces"][trig, 0, :]))

    #Return values
    return [areas, time_arr, y_arr, clean_y_arr]
Beispiel #2
0
    nbins = 2500
    #fig, ax = plt.subplots(1, 1)
    #plot_SiPM_trace(ax, SBCcode.get_event(active_event, 0, "PMTtraces")["PMTtraces"])

    # plt.ioff()
    areas = []
    max_times = []
    n_runs =  len(var_array)
    plt.ioff()
    left_lim = 800
    right_lim = 1400
    for run_ix in range(n_runs):
        sub_areas = []
        sub_max_times = []
        active_event = var_array[run_ix]
        events = SBCtools.BuildEventList(active_event)
        for ev in events:
            pmt_data = SBCcode.get_event(active_event, ev, "PMTtraces", max_file_size=1300)["PMTtraces"]
            n_triggers = pmt_data["traces"].shape[0]
            for trig in range(n_triggers):
                xd = 1e9 * np.arange(pmt_data["traces"].shape[2]) * pmt_data["dt"][trig, 0]
                yd_0 = pmt_data["traces"][trig, 0, :] * pmt_data["v_scale"][trig, 0] + \
                       pmt_data["v_offset"][trig, 0]
                yd_1 = pmt_data["traces"][trig, 1, :] * pmt_data["v_scale"][trig, 1] + \
                       pmt_data["v_offset"][trig, 1]
                good_indices = (xd < right_lim) & (xd > left_lim)
                avg = np.average(yd_0[:left_lim])
                #pmt_area = scipy.integrate.trapz(yd_1[good_indices]-avg,
                #                                 dx=1e9*pmt_data["dt"][trig, 1])
                # if np.any(yd_0 > 0.15):
                #     pmt_area = -1.
Beispiel #3
0
if __name__ == "__main__":
    raw_directory = "/bluearc/storage/SBC-18-data/"



    collection_dict = OrderedDict()
    collection_dict[0]=("20181207_0", "Everything Off (Just Noise)", "green", 1)



    for value in collection_dict.values():
        if not value[-1]:
            continue
        current_path = os.path.join(raw_directory, value[0])
        events = SBCtools.BuildEventList(current_path)
        for current_event in events:
            pmt_data = SBCcode.get_event(current_path, current_event,
                                         "PMTtraces", max_file_size=1300)["PMTtraces"]
            n_triggers = pmt_data["traces"].shape[0]
            for current_trigger in range(n_triggers):
                cutoff = 600
                timebase = (10e6*np.arange(pmt_data["traces"].shape[2])*pmt_data["dt"][current_trigger, 0])[:cutoff]
                sig1 = (pmt_data["traces"][current_trigger, 0, :] * pmt_data["v_scale"][current_trigger, 0] +\
                       pmt_data["v_offset"][current_trigger, 0])[:cutoff]
                sig2 = (pmt_data["traces"][current_trigger, 1, :] * pmt_data["v_scale"][current_trigger, 1] +\
                       pmt_data["v_offset"][current_trigger, 1])[:cutoff]
                ### To fit the signals to a sin wave
                ## Attempt to fit y=A*sin(B x + C) + D
                # D can be estimated by averaging the entire signal
                D1 = np.mean(sig1)