コード例 #1
0
def main(doPlot=False):

    align_point = 0.95
    wf_idx = 1

    chan = 692
    directory = "chan{}_8wfs".format(chan)

    wf_file = "training_data/chan{}_8wfs.npz".format(chan)
    conf_name = "{}.conf".format(chan_dict[chan])

    datadir = os.environ['DATADIR']
    conf_file = datadir + "siggen/config_files/" + conf_name

    detector = PPC(conf_file, wf_padding=100)

    lp = LowPassFilterModel()
    hp = HiPassFilterModel()
    im = ImpurityModelEnds(detector.imp_avg_lims, detector.imp_grad_lims,
                           detector.detector_length)
    vm = VelocityModel(include_beta=False)

    det_params = [
        9.76373631e-01, 8.35875049e-03, -5.09732644e+00, -6.00749043e+00,
        4.74275220e+06, 3.86911389e+06, 6.22014783e+06, 5.22077471e+06,
        -3.63516477e+00, -4.48184667e-01
    ]

    lp.apply_to_detector(det_params[:2], detector)
    hp.apply_to_detector(det_params[2:4], detector)
    vm.apply_to_detector(det_params[4:8], detector)
    im.apply_to_detector(det_params[8:], detector)

    data = np.load(wf_file, encoding="latin1")
    wfs = data['wfs']

    wf = wfs[wf_idx]
    wf_directory = os.path.join(directory, "wf{}".format(wf_idx))
    if os.path.isdir(wf_directory):
        if len(os.listdir(wf_directory)) > 0:
            raise OSError(
                "Directory {} already exists: not gonna over-write it".format(
                    wf_directory))
    else:
        os.makedirs(wf_directory)

    wf.window_waveform(time_point=align_point,
                       early_samples=100,
                       num_samples=125)

    fm = WaveformFitManager(wf,
                            align_percent=align_point,
                            detector=detector,
                            align_idx=100)

    fm.fit(numLevels=1000,
           directory=wf_directory,
           new_level_interval=1000,
           numParticles=3)
コード例 #2
0
def main():
    # det_name = "bege.config"
    # wp_name = "fields/bege_wpot.field"
    # ef_name= "fields/bege_ev.field"

    det_name = "P42574A_smaller.config"
    wp_name = "fields/P42574A_smaller_wpot.field"
    ef_name= "fields/P42574A_smaller_ev.field"

    det = PPC( "conf/" + det_name, verbose=False, doInit=False)

    meshmult = 10
    xtal_HV = 3500
    impAvgRange = np.linspace(-3,0, 5)
    gradientRange = np.linspace(0,2, 5)

    wp_mat, efld = det.solve_fields(meshmult, impAvgRange, gradientRange, wp_name =wp_name , ef_name=ef_name)
コード例 #3
0
ファイル: plot_tf.py プロジェクト: benshanks/mjd-analysis
def plot_effect():
    det = PPC(os.path.join(os.environ["DATADIR"], "siggen", "config_files",
                           "bege.config"),
              wf_padding=1000)
    imp_avg = -2
    imp_grad = 1.2
    det.siggenInst.SetImpurityAvg(imp_avg, imp_grad)
    wf_compare = None
    f, ax = plt.subplots(2, 1)
    for func in [fit_first_stage, fit_digitizer, fit_second_stage_lowpass]:
        func(det)
        wf_proc = np.copy(det.MakeSimWaveform(25, 0, 25, 1, 125, 0.95, 250))
        p = ax[0].plot(wf_proc)
        if wf_compare is None:
            wf_compare = wf_proc
        else:
            ax[1].plot(wf_proc - wf_compare, c=p[0].get_color())
コード例 #4
0
ファイル: tier3.py プロジェクト: clarkm1811/waffle
    def setup_detector(self):
        # ***** Get the detector set up:

        self.detector = {}
        for chan in self.chan_list:
            self.detector[chan] = PPC(self.wf_batch_conf[chan].detector_conf, wf_padding=100)
            for m in self.wf_batch_conf[chan].models:
                
                model_name,params = m[:]

                print("Applying {} to detector using:".format(model_name))
                print("   Params: {}".format(params))

                num_params = len(params)

                if model_name == "VelocityModel":
                    if (num_params == 4):
                        include_beta = False
                    else:
                        include_beta = True
                    model = VelocityModel(include_beta=include_beta)
                elif model_name == "ImpurityModelEnds":
                    model = ImpurityModelEnds(self.detector[chan])
                elif model_name == "HiPassFilterModel":
                    model = HiPassFilterModel(
                        detector=self.detector[chan],
                    )
                elif model_name == "LowPassFilterModel":
                    model = LowPassFilterModel(
                        self.detector[chan], 
                        # order=the_model.order, 
                        # include_zeros=the_model.include_zeros, 
                        # pmag_lims=the_model.pmag_lims,
                        # pphi_lims=the_model.pphi_lims, 
                        # zmag_lims=the_model.zmag_lims, 
                        # zphi_lims=the_model.zphi_lims, 
                    )
                elif model_name ==  "OvershootFilterModel":
                    model = OvershootFilterModel(self.detector[chan])
                elif model_name ==  "OscillationFilterModel":
                    model = OscillationFilterModel(self.detector[chan])
                elif model_name == "AntialiasingFilterModel":
                    model = AntialiasingFilterModel(self.detector[chan])
                elif model_name == "FirstStageFilterModel":
                    model = FirstStageFilterModel(self.detector[chan])
                elif model_name ==  "TrappingModel":
                    model = TrappingModel()
                else:
                    continue
                    # raise ValueError("model_name {} is not a valid model".format(model_name))

                print("   Applying these values to the model...")
                model.apply_to_detector(params,self.detector[chan])
            
            # For plots:
            self.width = 18
コード例 #5
0
def main():
    outDir = os.environ['LATDIR']
    #Set up an instance of a PPC detector
    det = PPC("{}/data/conf/p1_new.config".format(outDir),
              wf_padding=10000,
              maxWfOutputLength=10000)

    # Don't generate WFs beyond this
    print("Max Length (Z): {}, Max Radius (R): {}".format(
        det.detector_length, det.detector_radius))

    #Plot waveforms from a few different r/z locations
    phi = 0.
    rs = np.linspace(0, 34, 2)
    zs = np.linspace(5, 50, 2)
    # amps = [2]
    # Amplitudes from 2 to 20 ADC (1 - 10 keV)
    # amps = [2*i for i in range(1,11)]
    # amps = [1,2,3,4,5,6,7,8,9,10]
    amps = [i for i in range(1, 301)]

    # Secret Parameters without wiggles
    det.lp_num = [1.]
    det.lp_den = [1., -1.95933813, 0.95992564]
    det.hp_num = [1.0, -1.999640634643256, 0.99964063464325614]
    det.hp_den = [1, -1.9996247480008278, 0.99962475299714171]

    dataList = []
    # fig1, ax1 = plt.subplots(figsize=(10,7))

    for amp in amps:
        for i, r in enumerate(rs):
            for j, z in enumerate(zs):
                if r == 0 and z == 50: continue
                # Current version of SigGen can't generate more than 1000 samples
                wf_proc = det.MakeSimWaveform(r, phi, z, amp, 150, 0.1, 5000)
                # print(wf_proc)
                # ax1.plot(wf_proc, label = "R = {:0.2f},  Z = {:.2f} ".format(r, z))
                dataMap = {}
                dataMap['amp'] = amp
                dataMap['z'] = z
                dataMap['r'] = r
                # for idx, sample in enumerate(wf_proc):
                # dataMap['w{}'.format(idx)] = sample
                dataMap['waveform'] = wf_proc.tolist()
                dataList.append(dataMap)

    # ax1.set_xlabel("Time [{} ns steps]".format(det.time_step_size))
    # ax1.set_ylabel("Amplitude [ADC]")
    # ax1.legend()
    # plt.tight_layout()
    # plt.show()

    # Save waveforms for later -- remember, only saving 1000 samples, ~500 before and ~500 after
    df = pd.DataFrame.from_dict(dataList)
    print(df.head())
    df.to_hdf('{}/data/SigGen_WFs_full.h5'.format(outDir), 'skimTree')
コード例 #6
0
ファイル: lowpass.py プロジェクト: zachh12/waffle
def main():
    # det = Detector("GEM", "config_files/ortec4b.config", verbose=False)
    # det = PPC("conf/P42574A_imp.config")
    det = PPC( os.path.join(os.environ["DATADIR"],  "siggen", "config_files", "bege.config"), wf_padding=1000)
    imp_avg = -2
    imp_grad = 1.2
    det.siggenInst.SetImpurityAvg(imp_avg, imp_grad)

    # freq_resp(det)
    # poles(det)
    # zeros(det)
    aliasing_filter(det)
    plt.show()
コード例 #7
0
ファイル: sep.py プロジェクト: zachh12/analysis
def main():

    det = PPC("config_files/p1_new.config")
    wf_h = np.copy(det.MakeWaveform(15, 0, 15, 1)[0])
    wf_e = np.copy(det.MakeWaveform(15, 0, 15, -1)[0])
    #plt.plot(wf_h)
    #plt.plot(wf_e)
    #plt.plot(wf_h+wf_e)
    #plt.xlim(0, 800)
    #plt.show()
    #exit()
    wf = wf_h + wf_e
    dx = 1
    wf_ = np.gradient(wf, dx)
    #wf_ = np.gradient(wf_, dx)
    plt.xlim(0, 600)
    plt.plot(wf_)
    plt.show()
    wf_h = np.gradient(wf_h, dx)
    wf_h = np.gradient(wf_h, dx)
    plt.plot(wf_h - wf_)
    plt.xlim(0, 500)
    plt.show()
コード例 #8
0
ファイル: fields.py プロジェクト: zachh12/waffle
def generate_fields(conf_name, imp_min, imp_max, num_avg=5, num_grad=5, imp_uncertainty_factor = 0):
    '''
    Assume the measurements are within 50 percent of being right
    Allow the max impurity at each end to go to 1.5x the measurements
    and the min to go to 0
    find the range of impurity avg and grad that would encompass
    and generate the fields
    '''

    det = PPC( conf_name, verbose=False, doInit=False)

    meshmult = 10

    min_avg =  np.around(  0.5*( (1+imp_uncertainty_factor)*imp_max + (1+imp_uncertainty_factor)*imp_min ), 2)
    max_grad = np.around(   (-(1+imp_uncertainty_factor)*imp_max/(det.detector_length/10) ), 2)
    min_grad = np.around(   ((1+imp_uncertainty_factor)*imp_min/(det.detector_length/10) ), 2)

    impAvgRange = np.linspace(min_avg, 0, num_avg)
    gradientRange = np.linspace(min_grad,max_grad, num_grad)

    print(impAvgRange)
    print(gradientRange)

    det.solve_fields(meshmult, impAvgRange, gradientRange)
コード例 #9
0
ファイル: do_wf_plot.py プロジェクト: benshanks/mjd-analysis
def main(dir_name, wf_idx, num_samples=20 ):
    wf_idx = int(wf_idx)

    align_point = 0.95
    chan = 692
    directory = "chan{}_8wfs".format(chan)

    wf_directory = os.path.join(dir_name, "wf{}".format(wf_idx))

    wf_file = "training_data/chan{}_8wfs.npz".format(chan)
    conf_name = "{}.conf".format( chan_dict[chan] )

    datadir= os.environ['DATADIR']
    conf_file = datadir +"siggen/config_files/" + conf_name

    data = np.load(wf_file, encoding="latin1")
    wfs = data['wfs']

    wf = wfs[wf_idx]
    wf.window_waveform(time_point=0.95, early_samples=100, num_samples=125)

    detector = PPC( conf_file, wf_padding=100)

    em = ElectronicsModel(include_zeros=False)
    im = ImpurityModelEnds(detector.imp_avg_lims, detector.imp_grad_lims, detector.detector_length)
    vm = VelocityModel(include_beta=False)

    det_params = [ 9.76373631e-01,8.35875049e-03,-5.09732644e+00,-6.00749043e+00,
                   4.74275220e+06,3.86911389e+06,6.22014783e+06,5.22077471e+06,
                    -3.63516477e+00,-4.48184667e-01]

    em.apply_to_detector(det_params[:4], detector)
    vm.apply_to_detector(det_params[4:8], detector)
    im.apply_to_detector(det_params[8:], detector)


    wfm = WaveformModel(wf, align_percent=align_point, detector=detector, align_idx=100)
    plotter = WaveformFitPlotter(wf_directory, int(num_samples), wfm)

    plotter.plot_waveform()
    # plotter.plot_trace()

    plt.show()
コード例 #10
0
#!/usr/local/bin/python
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

from siggen import PPC
from scipy import signal
from scipy.ndimage.filters import gaussian_filter1d

from pygama.filters import rc_decay
from siggen.electronics import DigitalFilter

wf_length = 1000
det = PPC(os.path.join(os.environ["DATADIR"], "siggen", "config_files",
                       "bege.config"),
          wf_padding=1000,
          maxWfOutputLength=wf_length)
imp_avg = -2
imp_grad = 1.2
det.siggenInst.SetImpurityAvg(imp_avg, imp_grad)

nyq_freq = 0.5 * 1E9


def main():
    # poles(det)
    oscillation(det)
    # two_rc(det)


def two_rc(det):
コード例 #11
0
ファイル: origin.py プロジェクト: zachh12/analysis
def main():
    '''r1,r2,r3,r4,z1,z2,z3,z4 = [],[],[],[],[],[],[],[]
    sample = np.loadtxt("Posteriors/1.txt")
    for point in sample:
        r1.append(point[0])
        z1.append(point[1])
    sample = np.loadtxt("Posteriors/2.txt")
    for point in sample:
        r2.append(point[0])
        z2.append(point[1])
    sample = np.loadtxt("Posteriors/3.txt")
    for point in sample:
        r3.append(point[0])
        z3.append(point[1])
    sample = np.loadtxt("Posteriors/4.txt")
    for point in sample:
        r4.append(point[0])
        z4.append(point[1])
    #plt.scatter(r1,z1)
    #plt.scatter(r2,z2)
    #plt.xlim(0,40)
    #plt.ylim(0,40)
    #plt.show()

    '''
    #Calculate drift times
    # plt.figure()
    path = os.getenv("DATADIR")
    path = os.path.join(path, 'siggen/config_files/P42661A.conf')
    det = PPC(path)
    for i in range(0, 500):
        wf = det.GetWaveform(4, 0, 20)
    exit(1)
    dt_list = []
    nr, nz = 100, 100
    dt_map = np.ones((nr, nz)) * np.nan
    dtfrac_map = np.ones((nr, nz)) * np.nan
    for ir, r in enumerate(np.linspace(0, det.detector_radius, nr)):
        for iz, z in enumerate(np.linspace(0, det.detector_length, nz)):
            wf = det.MakeWaveform(r, 0, z, 1)
            if wf is None: continue
            dt_frac = np.argmax(wf >= 0.001)  #pulls first index >= 0.1%
            dt = det.siggenInst.GetLastDriftTime(1)
            dt_map[ir, iz] = dt
            dtfrac_map[ir, iz] = dt_frac
            dt_list.append(dt)
    color_map = plt.cm.RdYlBu_r
    normal_size = (7, 8)  #figure width x height, inches
    dt_arr = np.array(dt_list)
    plt.figure(figsize=normal_size)
    extent = (0, det.detector_radius, 0, det.detector_length)
    plt.imshow(dt_map.T,
               origin='lower',
               extent=extent,
               interpolation='nearest',
               cmap=color_map)
    plt.xlabel("Radial position [mm]")
    plt.ylabel("Axial position [mm]")
    levels = np.arange(200, 2000, 200)
    cb = plt.colorbar()
    cb.set_label('Drift Time [ns]', rotation=270, labelpad=10)
    CS = plt.contour(dt_map.T,
                     levels,
                     colors='k',
                     origin='lower',
                     extent=extent)
    plt.clabel(CS, inline=1, fmt='%1.0f ns', fontsize=10, inline_spacing=15)

    plt.tight_layout()
    plt.scatter(r1, z1, s=10)
    plt.scatter(r2, z2, s=10)
    plt.scatter(r3, z3, s=10)
    plt.scatter(r4, z4, s=10)
    plt.show()
コード例 #12
0
#!/usr/local/bin/python
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

from siggen import PPC
from scipy import signal
from waffle.models.electronics import HiPassFilterModel

em = HiPassFilterModel()

det = PPC(os.path.join(os.environ["DATADIR"], "siggen", "config_files",
                       "bege.config"),
          wf_padding=100)
imp_avg = -2
imp_grad = 1.2
det.siggenInst.SetImpurityAvg(imp_avg, imp_grad)
det.lp_order = 2

det.lp_num = [1, 2, 1]
det.lp_den = em.zpk_to_ba(0.975, 0.007)

det.hp_order = 2
mag = 1. - 10.**-5.145
phi = np.pi**-13.3
det.hp_num = [1, -2, 1]
det.hp_den = em.zpk_to_ba(mag, phi)


def main():
コード例 #13
0
def energy(list, energy, times):

    chan = 626
    conf_name = "{}.conf".format( chan_dict[chan] )
    datadir= os.environ['DATADIR']
    conf_file = datadir +"/siggen/config_files/" + conf_name
    det = PPC( conf_file, wf_padding=100)
    r = []
    z = []
    theta = []
    efit = []
    drift_length = []
    for i in list:
        dir = "../chan626_0-6avsewfs/wf" + str(int(i)) + "/posterior_sample.txt"
        post = np.loadtxt(dir)
        rtemp, ztemp, thetatemp, etemp = [], [], [], []
        for sample in post:
            try:
                rtemp.append(sample[0])
                ztemp.append(sample[1])
                thetatemp.append(sample[2])
                etemp.append(sample[3])
            except:
                rtemp.append(post[0])
                ztemp.append(post[1])
                thetatemp.append(post[2])
                etemp.append(post[3])
        r.append(rtemp[0])
        z.append(ztemp[0])
        theta.append(thetatemp[0])
        efit.append(etemp[0])
    for i in range(0, len(r)):
        length = getDriftLength(det, r[i], theta[i], z[i])
        drift_length.append(length)
    drift_length = np.array(drift_length)
    '''
    r = np.array(r)
    slope, intercept, r_value, p_value, std_err = stats.linregress(drift_length, energy)
    print("Slope :", slope)
    plt.figure(1)
    plt.title("Drift Length vs Drift Time (95%)")
    plt.scatter(times, drift_length)
    plt.ylabel("Drift Length (mm)")
    plt.xlabel("Drift Time (us)")

    plt.figure(2)
    plt.scatter(np.square(r), z)
    plt.xlabel("Radius^2 (mm)")
    plt.ylabel("Z (mm)")

    plt.figure(3)
    plt.title("Drift Length vs Energy @2614 keV Peak")
    plt.scatter(drift_length, energy)
    x = np.linspace(1, 300)
    y = x * slope + intercept
    regression = plt.plot(x, y, label="R: " + str(('%.5f'%(r_value))))
    plt.legend(loc='upper right')
    plt.xlim(.7*np.min(drift_length), 1.1*np.max(drift_length))
    plt.ylim(2610, 2620)
    plt.xlabel("Drift Length (mm)")
    plt.ylabel("Energy (keV)")
    '''
    
    #Used to calculate tau
    times = np.array(times)
    plt.close()
    #plt.show()
    plt.figure(100)
    rez = []

    xs = np.linspace(0, 300, 50000)

    for i in xs:
        energyct = energy * np.exp((drift_length)*(i/1000000))
        rez.append(np.std(energyct)*2.35)
    plt.scatter(xs, rez)
    plt.title("FWHM Minimization")
    plt.xlabel("Tau Parameter")
    plt.ylabel("FWHM @2614 keV")
    print(np.min(rez), xs[np.argmin(rez)])
    plt.show()
    exit()
    #'''
    # Make sure to tune every now and then
    tau = 5.81891637
    times = np.array(times)
    energyb = energy * np.exp((times)*(2.32213/100000))
    energyc = energy * np.exp((drift_length)*(tau/1000000))
    print("Resolution None: ", np.std(energy)*2.35)
    print("Resolution Time: ", np.std(energyb)*2.35)
    print("Resolution Length: ", np.std(energyc)*2.35)
    improv = (-100*(np.std(energyc)*2.35-np.std(energyb)*2.35)/(np.std(energyb)*2.35))
    print("% Improv t -> DL: ", improv)

    plt.figure(4)
    plt.hist(energy - np.mean(energy), bins=12, alpha=.3)
    plt.hist(energyb - np.mean(energyb), bins=12, alpha=.5)
    plt.hist(energyc - np.mean(energyc), bins=12, alpha=.5)
    plt.xlabel("Energy Distribution around Mean")
    plt.title("Energy With and w/o Correction")

    plt.figure(300)
    plt.scatter(drift_length, energyc)
    plt.title("Correction Drift Length vs Energy")
    plt.xlabel("Drift Length (mm)")
    plt.ylabel("Energy (keV)")
    fwhm = np.std(energyc) * 2.35
    plt.axhline(y=np.mean(energyc), alpha=.5, color='r')
    plt.axhspan(np.mean(energyc) - fwhm/2, np.mean(energyc) + fwhm/2, alpha=0.2, color='green')

    plt.show()
コード例 #14
0
#!/usr/local/bin/python
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

from siggen import PPC
from scipy import signal
from siggen.electronics import DigitalFilter, GretinaOvershootFilter
from pygama.filters import rc_decay

det = PPC(os.path.join(os.environ["DATADIR"], "siggen", "config_files",
                       "bege.config"),
          wf_padding=100)
imp_avg = -2
imp_grad = 1.2
det.siggenInst.SetImpurityAvg(imp_avg, imp_grad)


def main():
    skew()


def skew():

    lowpass = DigitalFilter(2)
    lowpass.num = [1, 2, 1]
    lowpass.set_poles(0.975, 0.007)

    hipass = DigitalFilter(2)
    hipass.num = [1, -2, 1]
コード例 #15
0
ファイル: training.py プロジェクト: zachh12/waffle
    def setup_detector(self):
        timeStepSize = self.conf.time_step_calc

        #TODO: wtf is going on with wf length?
        det = PPC(self.conf.siggen_conf_file, wf_padding=500)
        self.detector = det
コード例 #16
0
def main(wf, doPlot=False):

    align_point = 0.95
    wf_idx = int(wf)

    chan = 692
    datadir = os.environ['DATADIR']
    directory = "../../Data/Waveform/chan{}_wfs".format(chan)

    wf_file = datadir + "/Detector/chan{}_8wfs_DS1-1.npz".format(chan)
    conf_name = "{}.conf".format(chan_dict[chan])
    conf_file = datadir + "/siggen/config_files/" + conf_name

    detector = PPC(conf_file, wf_padding=100)

    vm = VelocityModel(include_beta=False)
    hp = HiPassFilterModel(detector)
    hp2 = HiPassFilterModel(detector)
    fs = FirstStageFilterModel(detector)
    al = AntialiasingFilterModel(detector)
    oshoot = OvershootFilterModel(detector)
    osc = OscillationFilterModel(detector)
    im = ImpurityModelEnds(detector)
    tm = TrappingModel()

    #692
    vm.apply_to_detector([4673558.84, 1776822.2, 8877288.2, 3423877.6],
                         detector)
    hp.apply_to_detector([72], detector)
    hp2.apply_to_detector([34337.7734], detector)
    fs.apply_to_detector([-1.551911234, 0.9719579, -4.99433260], detector)
    al.apply_to_detector([0.7823669278, 0.06673781], detector)
    oshoot.apply_to_detector([-5.40331742, 1.80314368], detector)
    osc.apply_to_detector([-1.9162354, 6.0421995, -1.974504, 4.948722],
                          detector)
    im.apply_to_detector([-0.147214076, -1.5064867], detector)
    tm.apply_to_detector(958.5, detector)
    '''
    #636
    vm.apply_to_detector([5068054.82, 4988240.69, 6538435.34, 5925515.5], detector)
    hp.apply_to_detector([72], detector)
    hp2.apply_to_detector([34336.51273333012], detector)
    fs.apply_to_detector([-1.6726791950686515, 0.8668817247858145, -4.752247247699966], detector)
    al.apply_to_detector([0.8081722376640458, 0.11022819946140337], detector)
    oshoot.apply_to_detector([-4.781231221813979, 0.4360771327659954], detector)
    osc.apply_to_detector([-1.7145995461740187, 3.002188106849415, -1.3480151900941126, 4.9442560336492445], detector)
    im.apply_to_detector([-0.19525537473916815, -1.906570916850837 ], detector)
    tm.apply_to_detector(935, detector)
    '''

    data = np.load(wf_file, encoding="latin1")
    wfs = data['wfs']

    wf = wfs[wf_idx]
    wf_directory = os.path.join(directory, "wf{}".format(wf_idx))
    if os.path.isdir(wf_directory):
        if len(os.listdir(wf_directory)) > 0:
            raise OSError(
                "Directory {} already exists: not gonna over-write it".format(
                    wf_directory))
    else:
        os.makedirs(wf_directory)

    wf.window_waveform(time_point=align_point,
                       early_samples=100,
                       num_samples=125)

    fm = WaveformFitManager(wf,
                            align_percent=align_point,
                            detector=detector,
                            align_idx=100)

    fm.fit(numLevels=1000,
           directory=wf_directory,
           new_level_interval=1000,
           numParticles=3)
コード例 #17
0
ファイル: fit_waveform.py プロジェクト: zachh12/analysis
def main(wf, doPlot=False):

    align_point = 0.95
    wf_idx = int(wf)

    chan = 692
    #chan = 692
    directory = "chan{}_wfs".format(chan)

    #wf_file = "training_data/chan{}_2614wfs.npz".format(chan)
    wf_file = "training_data/chan626_8wfs.npz"
    conf_name = "{}.conf".format( chan_dict[chan] )

    datadir= os.environ['DATADIR']
    conf_file = datadir +"/siggen/config_files/" + conf_name


    detector = PPC( conf_file, wf_padding=100)

    vm = VelocityModel(include_beta=False)
    hp = HiPassFilterModel(detector)
    hp2 = HiPassFilterModel(detector)
    fs = FirstStageFilterModel(detector)
    al = AntialiasingFilterModel(detector)
    oshoot = OvershootFilterModel(detector)
    osc = OscillationFilterModel(detector)
    im = ImpurityModelEnds(detector)
    tm = TrappingModel()

    #lp = LowPassFilterModel(detector)
    #hp = HiPassFilterModel(detector)

    det_params = [ 9.76373631e-01,8.35875049e-03,-5.09732644e+00,-6.00749043e+00,
                   4.74275220e+06,3.86911389e+06,6.22014783e+06,5.22077471e+06,
                    -3.63516477e+00,-4.48184667e-01]
    '''
    #OLD
    vm.apply_to_detector([8439025,5307015,9677126,5309391], detector)
    fs.apply_to_detector([-7.062660481537297308e-01, 9.778840228405032420e-01, -7.851819989636383390e+00], detector)
    al.apply_to_detector([0.5344254, 0.135507736], detector)
    oshoot.apply_to_detector([-3.8111099842, 0.140626600], detector)
    osc.apply_to_detector([-1.6800848, 3.00040593, -1.245777055, 5.0073780147], detector)
    im.apply_to_detector([-0.015571734108306538, -5.7326715464], detector)

    #672
    vm.apply_to_detector([6.330448119432486594e+06, 7.070545190569272265e+06, 6.330662440609236248e+06, 7.320939440024248324e+06], detector)
    fs.apply_to_detector([-1.50887, 9.790592e-01, -2.10503], detector)
    al.apply_to_detector([7.99097e-01, 1.160481e-02], detector)
    oshoot.apply_to_detector([-5.301815, 1.8299623], detector)
    osc.apply_to_detector([-2.185584, 6.970590, -2.2064522, 5.77401], detector)
    im.apply_to_detector([-2.739048e-01, -1.54175], detector)
    '''

    #692B
    vm.apply_to_detector([4721003, 1772756, 8980887, 3438183], detector)
    hp.apply_to_detector([72], detector)
    hp2.apply_to_detector([34830], detector)
    fs.apply_to_detector([-1.5689873968, 0.971197844, -2.6044181698976994], detector)
    al.apply_to_detector([0.8011119473597831, 0.0517397887401], detector)
    oshoot.apply_to_detector([-5.4060800418507, 1.8518756115], detector)
    osc.apply_to_detector([-2.0019835639, 5.70104877, -2.038719650, 4.9310608676], detector)
    im.apply_to_detector([-0.1088216908, -1.389909466578219], detector)
    tm.apply_to_detector(315.4664, detector)

    #672
    vm.apply_to_detector([4466455.23, 4507219.99, 6551208.72, 4926098.82], detector)
    hp.apply_to_detector([70.754], detector)
    hp2.apply_to_detector([34335.99], detector)
    fs.apply_to_detector([-1.566736274, 0.978057037, -2.04346823], detector)
    al.apply_to_detector([0.608387794, 0.1566835], detector)
    oshoot.apply_to_detector([-5.286922396, 1.71539392], detector)
    osc.apply_to_detector([-0.58336895, 5.127040064, -0.520893234, 5.0062789722], detector)
    im.apply_to_detector([-0.1740234244, -1.739642928], detector)
    tm.apply_to_detector(1243., detector)

    data = np.load(wf_file, encoding="latin1")
    wfs = data['wfs']

    wf = wfs[wf_idx]
    wf_directory = os.path.join(directory, "wf{}".format(wf_idx))
    if os.path.isdir(wf_directory):
        if len(os.listdir(wf_directory)) >0:
            raise OSError("Directory {} already exists: not gonna over-write it".format(wf_directory))
    else:
        os.makedirs(wf_directory)

    wf.window_waveform(time_point=align_point, early_samples=100, num_samples=125)

    fm = WaveformFitManager(wf, align_percent=align_point, detector=detector, align_idx=100)

    fm.fit(numLevels=1000, directory = wf_directory, new_level_interval=1000, numParticles=3)