def plot_charge_resolution(df_cr, poi, nsb, matched_voltage): df = df_cr.loc[df_cr['pixel'] == poi] x = df['true'] y = df['charge_res'] yerr = (1 / np.sqrt(df['n'])) / x cr = ChargeResolutionPlotter() cr._plot(x, y, yerr, label="CR") cr.plot_poisson(x) cr.plot_requirement(x) output_path = get_plot( f"d201202_tutorial_material/cr_{nsb}MHz_{matched_voltage}mV.pdf") cr.save(output_path)
class CRPlotter: def __init__(self): self.plot = ChargeResolutionPlotter() def add(self, x, y, label): self.plot._plot(x, y, None, label=label) def save(self, path): x = np.geomspace(0.1, 1000, 100) self.plot.plot_poisson(x) self.plot.plot_requirement(x) self.plot.ax.set_xlabel("Illumination (p.e.)") self.plot.ax.set_ylabel("Fractional Charge Resolution") self.plot.add_legend(loc='best') self.plot.save(path)
import numpy as np import pandas as pd from CHECLabPy.plotting.setup import Plotter from CHECLabPy.plotting.resolutions import ChargeResolutionPlotter from scipy.interpolate import RegularGridInterpolator from IPython import embed # Requirements CRREQ_2PE = ChargeResolutionPlotter.requirement(np.array([2]))[0] CRREQ_20PE = ChargeResolutionPlotter.requirement(np.array([20]))[0] CRREQ_200PE = ChargeResolutionPlotter.requirement(np.array([200]))[0] CRREQ_2000PE = ChargeResolutionPlotter.requirement(np.array([2000]))[0] CRREQ_2PE_50PDE = ChargeResolutionPlotter.requirement(np.array([2*0.5]))[0] CRREQ_20PE_50PDE = ChargeResolutionPlotter.requirement(np.array([20*0.5]))[0] CRREQ_200PE_50PDE = ChargeResolutionPlotter.requirement(np.array([200*0.5]))[0] CRREQ_2000PE_50PDE = ChargeResolutionPlotter.requirement(np.array([2000*0.5]))[0] MINIMGAMP_GAMMA_25PDE = 250 * 0.25 MINIMGAMP_PROTON_25PDE = 480 * 0.25 MINIMGAMP_GAMMA_50PDE = 250 * 0.5 MINIMGAMP_PROTON_50PDE = 480 * 0.5 class MIAContourPlot(Plotter): def __init__(self, interpolator, talk): self.interpolator = interpolator super().__init__(talk=talk) def plot_opct_vs_nsb(self, opct: np.ndarray, nsb: np.ndarray, mv_per_pe: float): xg, yg, zg = np.meshgrid(opct, nsb, mv_per_pe, indexing='ij')
import numpy as np import pandas as pd from matplotlib import pyplot as plt from scipy.interpolate import griddata from CHECLabPy.utils.files import create_directory from CHECLabPy.plotting.resolutions import ChargeResolutionPlotter # Requirements CRREQ_2PE = ChargeResolutionPlotter.requirement(np.array([2]))[0] CRREQ_100PE = ChargeResolutionPlotter.requirement(np.array([100]))[0] # CHEC-S (from data) CHECS_RATIO = 0.20581828565154767 CHECS_PULSE_WIDTH = 10.650883938789999 CHECS_UNDERSHOOT_WIDTH = 19.880996171267505 def regular_grid_interp(df, n_undershoot, n_pulse): xi = np.linspace(df['undershoot_width'].min(), df['undershoot_width'].max(), n_undershoot) yi = np.linspace(df['pulse_width'].min(), df['pulse_width'].max(), n_pulse) Xi, Yi = np.meshgrid(xi, yi) Zi_teff_50 = griddata((df['undershoot_width'], df['pulse_width']), df['teff_50'], (Xi, Yi)) Zi_cr_2pe = griddata((df['undershoot_width'], df['pulse_width']), df['cr_2pe'], (Xi, Yi)) Zi_cr_100pe = griddata((df['undershoot_width'], df['pulse_width']), df['cr_100pe'], (Xi, Yi)) df_interp = pd.DataFrame( dict( undershoot_width=Xi.ravel(),
def __init__(self): self.plot = ChargeResolutionPlotter()
def main(): poi = 1344 paths = dict( withped= "/Volumes/gct-jason/data_checs/dynamicrange_180514/tf_withped/charge_res_0.h5", poly= "/Volumes/gct-jason/data_checs/dynamicrange_180514/tf_poly/charge_res_0.h5", none= "/Volumes/gct-jason/data_checs/dynamicrange_180514/tf_none/charge_res_0.h5", pchip= "/Volumes/gct-jason/data_checs/dynamicrange_180514/tf_pchip/charge_res_0.h5", mc_0mhz= "/Volumes/gct-jason/mc_checs/dynamic_range/opct40/0mhz/charge_res_0.h5", mc_0mhz_true= "/Volumes/gct-jason/mc_checs/dynamic_range_old/0mhz/cc/charge_res_true.h5", mc_5mhz= "/Volumes/gct-jason/mc_checs/dynamic_range/opct40/5mhz/charge_res_0.h5", mc_5mhz_true= "/Volumes/gct-jason/mc_checs/dynamic_range_old/5mhz/cc/charge_res_true.h5", mc_40mhz= "/Volumes/gct-jason/mc_checs/dynamic_range/opct40/40mhz/charge_res_0.h5", mc_40mhz_true= "/Volumes/gct-jason/mc_checs/dynamic_range_old/40mhz/cc/charge_res_true.h5", withped_wb= "/Volumes/gct-jason/data_checs/dynamicrange_180514/tf_withped/charge_res_wb.h5", poly_wb= "/Volumes/gct-jason/data_checs/dynamicrange_180514/tf_poly/charge_res_wb.h5", none_wb= "/Volumes/gct-jason/data_checs/dynamicrange_180514/tf_none/charge_res_wb.h5", ) labels = dict( withped="TF With Pedestal", poly="TF Polynomial Regression", none="Pedestal Only", pchip="TF PCHIP Interpolation", mc_0mhz="MC (0 DCR)", mc_0mhz_true="MC (0 DCR, True Charge)", mc_5mhz="MC (5MHz DCR)", mc_5mhz_true="MC (5MHz DCR, True Charge)", mc_40mhz="MC (40MHz NSB)", mc_40mhz_true="MC (40MHz NSB, True Charge)", withped_wb="TF With Pedestal, Without bias", poly_wb="TF Polynomial Regression, Without bias", none_wb="Pedestal Only, Without bias", ) stores = {key: pd.HDFStore(path) for key, path in paths.items()} output_dir = "/Volumes/gct-jason/data_checs/dynamicrange_180514" if not os.path.exists(output_dir): os.makedirs(output_dir) print("Created directory: {}".format(output_dir)) keys = [ # "withped", # "poly", # "none", "pchip", "mc_0mhz", # "mc_0mhz_true", "mc_5mhz", # "mc_5mhz_true", "mc_40mhz", # "mc_40mhz_true", # "withped_wb", # "poly_wb", # "none_wb", # "pchip_wb", ] p_cr = ChargeResolutionPlotter() for key in keys: store = stores[key] label = labels[key] p_cr.set_store(store) # p_cr.plot_camera(label + " (camera)") p_cr.plot_pixel(poi, label + " (pixel {})".format(poi)) true = np.geomspace(0.1, 2000, 1000) p_cr.plot_goal(true) p_cr.plot_requirement(true) p_cr.plot_poisson(true) # p_cr.plot_opct_file() p_cr.add_legend() p_cr.save(os.path.join(output_dir, "charge_res.pdf")) keys = [ # "withped", # "poly", # "none", "pchip", "mc_0mhz", # "mc_0mhz_true", "mc_5mhz", # "mc_5mhz_true", "mc_40mhz", # "mc_40mhz_true", # "withped_wb", # "poly_wb", # "none_wb", # "pchip_wb", ] p_crwrr = ChargeResolutionWRRPlotter() for key in keys: store = stores[key] label = labels[key] p_crwrr.set_store(store) # p_crwrr.plot_camera(label + " (camera)") p_crwrr.plot_pixel(poi, label + " (pixel {})".format(poi)) true = np.geomspace(0.1, 2000, 1000) p_crwrr.plot_goal(true) p_crwrr.plot_requirement(true) p_crwrr.plot_poisson(true) # p_crwrr.plot_opct_file() p_crwrr.add_legend("best") p_crwrr.save(os.path.join(output_dir, "charge_res_wrr.pdf")) keys = [ # "withped", # "poly", # "none", "pchip", "mc_0mhz", # "mc_0mhz_true", "mc_5mhz", # "mc_5mhz_true", "mc_40mhz", # "mc_40mhz_true", # "withped_wb", # "poly_wb", # "none_wb", # "pchip_wb", ] p_mean = ChargeMeanPlotter() for key in keys: store = stores[key] label = labels[key] p_mean.set_store(store) # p_mean.plot_camera(label + " (camera)") p_mean.plot_pixel(poi, label + " (pixel {})".format(poi)) # p_mean.plot_opct_file() p_mean.add_legend("best") p_mean.save(os.path.join(output_dir, "charge_mean.pdf"))
def plot_charge_resolution(x, y, path): plot = ChargeResolutionPlotter() plot._plot(x, y, None, label="simulation") plot.plot_poisson(x) plot.plot_requirement(x) plot.ax.set_xlabel("Illumination (p.e.)") plot.ax.set_ylabel("Fractional Charge Resolution") plot.add_legend(loc='best') plot.save(path)