Skip to content
Snippets Groups Projects
Select Git revision
  • f656f1051b32b613747474190bc462dab98d1bde
  • main default protected
  • sumlab
  • dev/test_tobias
  • jack.rolph-main-patch-16563
  • jack.rolph-main-patch-96201
  • jack.rolph-main-patch-18340
  • jack.rolph-main-patch-15793
  • jack.rolph-main-patch-74592
  • 1.0.0
10 results

example.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    example.py 2.28 KiB
    
    import os
    import sys
    import numpy as np
    import pandas as pd
    from PeakOTron import PeakOTron
    from joblib import dump
    from time import time
    
    
    print("--------------------")
    print('EXAMPLE SIPM CALIBRATION RUN')
    print("--------------------")
    
    
    out_dict = {}
    files_to_fit = []
    
    ## Find all histograms in directory 
    for root, dirs, files in os.walk("./data/hamamatsu_pcb6/Light"):
         
            for file in files:
                
                if file.endswith(".txt"):
                    files_to_fit.append([file, os.path.join(root, file)])
                    
    
    ## Print files.
    print("Files to fit:")
    for i, (file, _) in enumerate(files_to_fit):
        print('File {0}: {1}'.format(i, file))
        
        
        
    SiPM = "PM1125NS_SBO"
    
    
    ## Loop thorough files
    for i, (file, path) in enumerate(files_to_fit):
        items = file.split('_')
    
        V = float(items[2].replace('V', '').replace('p', '.'))
            
    
        ## Load files. 
        data = np.loadtxt(path, skiprows=8)
    
        ## Create a PeakOTron Fit Object. 
        f_data = PeakOTron(verbose=True)
    
        ## Perform fit. 
        time_start = time.time()
        f_data.Fit(data, 
              tau=21.953,  #SLOW PULSE COMPONENT TIME CONSTANT (ns)
              t_gate=104, #GATE LENGTH (ns)
              t_0 = 64, #INTEGRATION TIME BEFORE GATE (ns)               
              tau_R=21.953,
              truncate_nG=0.333
                  
        ) #BINNING RULE "knuth", "freedman", "scott" - use bw= #### to override. it is still required for DCR calculation. 
        time_end = time.time()
    
        print("Fit took {:3.3f} s".format(time_end - time_start))
    
        f_data.PlotFit(xlabel="ADC", save_directory="./Results/{0}_fit.png".format(os.path.splitext(file)[0]))
        
    
        
        dump(f_data, "./Results/{0}".format(os.path.splitext(file)[0]))
        
        
        
        fit_out = {}
        fit_val, fit_err = f_data.GetFitResults()
        for key, val in fit_val.items():
            print("{:s} : {:3.3E}".format(key, val))
        
        fit_out["SiPM"] = SiPM
        fit_out["V"] = V
    
        for key, value in fit_err.items():
            fit_out["d_{:s}".format(key)] = value
    
        fit_out.update(fit_val)
        out_dict.update()
        if out_dict == {}:
            for key in fit_out.keys():
                out_dict[key] = []
    
        for key in fit_out.keys():
            out_dict[key].append(fit_out[key])
    
    
    
    df = pd.DataFrame.from_dict(out_dict)
    df.to_csv("./fit_results_{:s}.csv".format(SiPM))