tracking-parametrisation-tuner/parameterisations/notebooks/magnet_kink_position.ipynb

1031 lines
327 KiB
Plaintext
Raw Normal View History

2023-12-19 13:00:59 +01:00
{
"cells": [
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 33,
2023-12-19 13:00:59 +01:00
"metadata": {},
"outputs": [],
"source": [
"import uproot\n",
"import awkward as ak\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"import numpy as np\n",
"import mplhep\n",
2024-02-26 16:18:03 +01:00
"\n",
2023-12-19 13:00:59 +01:00
"mplhep.style.use([\"LHCbTex2\"])\n",
2024-02-26 16:18:03 +01:00
"input_tree = uproot.open({\n",
" \"/work/cetin/LHCb/reco_tuner/data/tracking_losses_ntuple_B_def_selected.root\":\n",
" \"Selected\"\n",
"})\n",
2023-12-19 13:00:59 +01:00
"array = input_tree.arrays()\n",
2024-02-26 16:18:03 +01:00
"\n",
"array[\"dSlope_xEndT\"] = array[\"ideal_state_9410_tx\"] - array[\n",
" \"ideal_state_770_tx\"]\n",
"array[\"dSlope_xEndT_abs\"] = abs(array[\"dSlope_xEndT\"])\n",
"array[\"x_EndT_abs\"] = abs(array[\"ideal_state_9410_x\"])\n",
"\n",
"array[\"z_mag_xEndT\"] = (\n",
" array[\"ideal_state_770_x\"] - array[\"ideal_state_9410_x\"] -\n",
" array[\"ideal_state_770_tx\"] * array[\"ideal_state_770_z\"] +\n",
" array[\"ideal_state_9410_tx\"] *\n",
" array[\"ideal_state_9410_z\"]) / array[\"dSlope_xEndT\"]"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 34,
2023-12-19 13:00:59 +01:00
"metadata": {},
"outputs": [
{
"data": {
2024-02-26 16:18:03 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABMIAAAOWCAYAAAANzz7PAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXR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zsGAAAAAACAF3j+sHzgvDgsH24ql8vy+XxutwF0xDuff3LmmN/94ldd7wMAAAAXi5uf2/tmayQAeJVlWUokEhoZGdHc3Jzb7QAAAAAATtF3WyObsbi4qNu3b+snP/mJ260AcJllWVpbW5NlWbVt1NVVW6ZpanR0VMFgsLad+qhoNCrbtlUoFGrfK5fLyuVyWltbUy6XU7lc7uEdAQAAAABa1XdB2NOnT5XNZpXP57W4uKj33nvv2JipqSlNTk7q3XffVTKZJBBDX0un04rH4+e+LhgM1oU3rTr8EIpm+Xw+7e3tnfizaDSqjY2Nc9fMZrMnBlUnKZfLevDggZaWlhqOsSxLkpTL5Wpjg8GgQqGQAoGAstmsNjY2jj2gY25uTrZt164HBhnbJwEAANBP+mZr5EcffaTLly8rGo0qnU7LsqzaAflHRSIR2batb775RqZp6osvvuhxt0DnxGIx7e3tqVAoKBKJNBwbCoWUzWZr4zvBcRwVi0WlUqmGZ1+ZpqlUKqVisXhqCCZJmUxGe3t7TQVbCwsLKhQK2tvbazoEq25RPBqCRSIRZTKZWr3qfWWzWcVisdq9WZalpaUlxePxWmB3dMVXtY7jODJNs6m+AAAAAADu83wQ9ubNG129elWJRKL24bWZ8/19Pp8KhYKuXbumSCSizz77rAfdAt3h8/kUDAaVyWQ
2023-12-19 13:00:59 +01:00
"text/plain": [
"<Figure size 1200x900 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = plt.figure()\n",
2024-02-26 16:18:03 +01:00
"plt.hist(array[\"z_mag_xEndT\"],\n",
" bins=100,\n",
" range=[5100, 5700],\n",
" color=\"#2A9D8F\",\n",
" density=True)\n",
2023-12-19 13:00:59 +01:00
"plt.xlabel(r\"z$_{Mag}$ [mm]\")\n",
"plt.ylabel(\"Number of Tracks (normalised)\")\n",
2024-02-26 16:18:03 +01:00
"mplhep.lhcb.text(\"Simulation\")\n",
"plt.show()"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 35,
2023-12-19 13:00:59 +01:00
"metadata": {},
"outputs": [
{
"data": {
2024-02-26 16:18:03 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABMIAAAOWCAYAAAANzz7PAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAClyUlEQVR4nOz9X4xi953n/7+o7kSO4tBQHs1PpULKNMjz9VzNNFTvRe42BZu9iJVsDN0/xV87+mnTVGxFq59q1+COr+0yJKmblbKGztw4G2m6IZ5EyUXW0J777YLO3FmbcNqRqsSVq04TR7EyNnwv6guBKgoOcM7hz3k+JCSq+PA5b4r6A6/6fN7H1+l0OgIAAAAAAABW3Nq8CwAAAAAAAADcQBAGAAAAAAAATyAIAwAAAAAAgCcQhAEAAAAAAMATCMIAAAAAAADgCQRhAAAAAAAA8ASCMAAAAAAAAHgCQRgAAAAAAAA8gSAMAAAAAAAAnkAQBgAAAAAAAE8gCAMAAAAAAIAnEIQBAAAAAADAEwjCAAAAAAAA4AkEYQAAAAAAAPAEgjAAAAAAAAB4AkEYAAAAAAAAPIEgDAAAAAAAAJ5AEAYAAAAAAABPIAgDAAAAAACAJxCEAQAAAAAAwBMIwgAAAAAAAOAJBGEAAAAAAADwBIIwAAAAAAAAeAJBGAAAAAAAADyBIAwAAAAAAACeQBAGAAAAAAAATyAIAwAAAAAAgCcQhAEAAAAAAMATCMIAAAAAAADgCQRhc2AYhhKJxFxryOfzSiQSCgaD8vl8ikQiSqVSqlarCzUnAAAAAACAXQjCbGSapnw+39hLJBJROBy+cJ5ukDTNZWdnZ2SN1WpVwWBQ2WxWklQqldRoNJTL5VSv15VIJJRIJGSapuXH7cScAAAAAAAAdvN1Op3OvItYFfl8vhcGjdNoNIaGYeVyWalUauoaSqWSksnk0Nuq1WpvJVo6nVahUDg3JhaLqV6vKxwOq1arKRAIjDyeE3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dX366aeW71OtVpVKpWSapuLxuHK53IXbFQ3DUCwWk2maqtVqE21r7EokEqpWqwoEAjo5OZn4/oZhKBKJSDoNsWq12tBxpmkqGAxKOl2tV6lUXJ3TqlAopKOjI21uburw8HDm+dwyS92ftqXLr40e88nr0qW5r/MEls+y/k4BVhk/l8Di4ecSWDzL+nM5z7rn+pZ5jhncOZPWUiqVes3iq9WqYrHYwHbBru5t6+vrajQaU4Vg/dsip91SGA6He6uy6vW68vn80HHb29uSTvuQ9a/icmtOAAAAAAAAp8w1CMvlcnNfDSZJV65cUS6Xm+g+w7YnFotFBYNBpVIp7ezsKBaLKZFIKJ1Oq1arTX1mzP5tkcPCNquSyaQqlYoCgYCy2axSqZTq9XovaIvFYqrX64pGo3r06JECgcBc5gQAAAAAAHDCXIOwV155xdXjffDBBxfeNmkt8XhcjUZD6XRa4XB4IOCp1+s6Pj7W7du3dXJyolwuN1MA1L+KatYm8/F4vFeTYRja3t7uhXfr6+sqlUqq1WoT1evEnAAAAAAAAHabe7N8N+3s7Oh//a//Zdt84XBYhULBtvkuYkdPrbMymcxUZ690e04AAAAAAAC7eKqt9sHBwbxLAAAAAAAAwJws5YqwDz74oNeo3grDMFQoFCa6DwAAAAAAAFbLUgRhH3zwgXK5nKrVqgzDmGqOTqcjn89nc2UAAAAAAABYFgsfhN2+fVv5fF7SaZgFLLPd3V21Wq2FOFsqgL/gZxNYPPxcAouHn0tg8fBzOTlfZ4HTpZ/97GdKpVKS1FvNNUu5Pp9Pn376qS21Yb5CoZCOjo60ubmpw8PDeZfjik/b0uXXRo/55HXpkqc6/wEAAAAAls0839Mv9Iqwvb09SacBVqfTUTgcVjQaVTg
2023-12-19 13:00:59 +01:00
"text/plain": [
"<Figure size 1200x900 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2024-02-26 16:18:03 +01:00
"bins = np.linspace(-0.4, 0.4, 50)\n",
"sns.regplot(\n",
" x=ak.to_numpy(array[\"ideal_state_770_tx\"]),\n",
" y=ak.to_numpy(array[\"z_mag_xEndT\"]),\n",
" x_bins=bins,\n",
" fit_reg=None,\n",
" x_estimator=np.mean,\n",
")\n",
"plt.ylim(5100, 5700)\n",
2023-12-19 13:00:59 +01:00
"plt.xlabel(\"dx/dz(VELO)\")\n",
"plt.ylabel(\"$z_{Mag}$ [mm]\")\n",
2024-02-26 16:18:03 +01:00
"mplhep.lhcb.text(\"Simulation\")\n",
"plt.show()"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 36,
2023-12-19 13:00:59 +01:00
"metadata": {},
"outputs": [
{
"data": {
2024-02-26 16:18:03 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABMIAAAOWCAYAAAANzz7PAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAACiQklEQVR4nOzdTWxj55nm/YuqSuAgCYuUGw0IIpA2BQ/cq+4iVbPo3UTkZBYxEsRkFZAgzmJSZBw0ZqEZk67O2lbIJNoMkDFZ7o0DA11Fxp0gWfSYLPd+SmJldsGkecoBJHDl4ikmQYzE5nkXeskm9UEekueD1Pn/AAH6eHifWx9li5fu5zkhy7IsAQAAAAAAAJfcmt8NAAAAAAAAAF4gCAMAAAAAAEAgEIQBAAAAAAAgEAjCAAAAAAAAEAgEYQAAAAAAAAgEgjAAAAAAAAAEAkEYAAAAAAAAAoEgDAAAAAAAAIFAEAYAAAAAAIBAIAgDAAAAAABAIBCEAQAAAAAAIBAIwgAAAAAAABAIBGEAAAAAAAAIBIIwAAAAAAAABAJBGAAAAAAAAAKBIAwAAAAAAACBQBAGAAAAAACAQCAIAwAAAAAAQCAQhAEAAAAAACAQCMIAAAAAAAAQCARhAAAAAAAACASCMAAAAAAAAAQCQRgAAAAAAAACgSAMAAAAAAAAgUAQBgAAAAAAgEAgC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Tr/UE2F7e3uSTgIsy7IUj8eVSCQUj8clSc8+++zUGh9++KFM09T9+/f19OlTV/sFAAAAAADA8lrqIKzVag0nwRqNhnZ2duauVSgU9PzzzzvVGgA
2023-12-19 13:00:59 +01:00
"text/plain": [
"<Figure size 1200x900 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2024-02-26 16:18:03 +01:00
"bins = np.linspace(-0.25, 0.25, 50)\n",
"sns.regplot(\n",
" x=ak.to_numpy(array[\"ideal_state_770_ty\"]),\n",
" y=ak.to_numpy(array[\"z_mag_xEndT\"]),\n",
" x_bins=bins,\n",
" fit_reg=None,\n",
" x_estimator=np.mean,\n",
")\n",
"plt.ylim(5100, 5700)\n",
"\n",
2023-12-19 13:00:59 +01:00
"plt.xlabel(\"dy/dz(VELO)\")\n",
"plt.ylabel(\"$z_{Mag}$ [mm]\")\n",
2024-02-26 16:18:03 +01:00
"mplhep.lhcb.text(\"Simulation\")\n",
"plt.show()"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 37,
2023-12-19 13:00:59 +01:00
"metadata": {},
"outputs": [],
"source": [
2024-02-26 16:18:03 +01:00
"# bins = np.linspace( -300, 300, 50 )\n",
"# sns.regplot(x=ak.to_numpy(array[\"x\"]), y=ak.to_numpy(array[\"z_mag_x_fringe\"]), x_bins=bins, fit_reg=None, x_estimator=np.mean)"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 38,
2023-12-19 13:00:59 +01:00
"metadata": {},
"outputs": [],
"source": [
2024-02-26 16:18:03 +01:00
"# bins = np.linspace( -300, 300, 50 )\n",
"# sns.regplot(x=ak.to_numpy(array[\"y\"]), y=ak.to_numpy(array[\"z_mag_x_fringe\"]), x_bins=bins, fit_reg=None, x_estimator=np.mean)"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 39,
2023-12-19 13:00:59 +01:00
"metadata": {},
"outputs": [],
"source": [
2024-02-26 16:18:03 +01:00
"# bins = np.linspace( -1.0, 1.0, 50 )\n",
"# sns.regplot(x=ak.to_numpy(array[\"dSlope_out\"]), y=ak.to_numpy(array[\"z_mag_x\"]), x_bins=bins, fit_reg=None, x_estimator=np.mean)"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 40,
2023-12-19 13:00:59 +01:00
"metadata": {},
"outputs": [
{
"data": {
2024-02-26 16:18:03 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAABMIAAAOWCAYAAAANzz7PAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAACh7UlEQVR4nOz9X2xbZ5rn+/4ouzIOkqJJpYHZggR0mUR6Ujen26Q8+6CuzpTI6d5AjGQqpD1IkAQbE1FJUBgcaDpkXLl2FLKqhAMMTsaiq3EOHAS7bbJTCRLgVId0+vqMpeXqu8xUcTkFSOCei0jLrBTinXLIfaFNFilR5CK5Fv9+P4BQkvXw5SPJTkk/Pe/7emq1Wk0AAAAAAADAlJsbdQMAAAAAAADAMBCEAQAAAAAAYCYQhAEAAAAAAGAmEIQBAAAAAABgJhCEAQAAAAAAYCYQhAEAAAAAAGAmEIQBAAAAAABgJhCEAQAAAAAAYCYQhAEAAAAAAGAmEIQBAAAAAABgJhCEAQAAAAAAYCYQhAEAAAAAAGAmEIQBAAAAAABgJhCEAQAAAAAAYCYQhAEAAAAAAGAmEIQBAAAAAABgJhCEAQAAAAAAYCYQhAEAAAAAAGAmEIQBAAAAAABgJhCEAQAAAAAAYCYQhAEAAAAAAGAmEIQBAAAAAABgJhCEAQAAAAAAYCYQhAEAAAAAAGAmEIQBAAAAAABgJhCEAQAAAAAAYCYQhAEAAAAAAGAm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6uSqUyFrelAvgT/m0C44d/l8D44d8lMH74d9m7sQ7C/uEf/kHpdFqS5PF45PF4CMMw0dbX10fdAoA
2023-12-19 13:00:59 +01:00
"text/plain": [
"<Figure size 1200x900 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2024-02-26 16:18:03 +01:00
"bins = np.linspace(-1, 1, 50)\n",
"sns.regplot(\n",
" x=ak.to_numpy(array[\"dSlope_xEndT\"]),\n",
" y=ak.to_numpy(array[\"z_mag_xEndT\"]),\n",
" x_bins=bins,\n",
" fit_reg=None,\n",
" x_estimator=np.mean,\n",
")\n",
"plt.ylim(5100, 5700)\n",
"\n",
2023-12-19 13:00:59 +01:00
"plt.xlabel(\"$\\Delta$dx/dz\")\n",
"plt.ylabel(\"$z_{Mag}$ [mm]\")\n",
2024-02-26 16:18:03 +01:00
"mplhep.lhcb.text(\"Simulation\")\n",
"plt.show()"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 41,
2023-12-19 13:00:59 +01:00
"metadata": {},
2024-02-26 16:18:03 +01:00
"outputs": [],
2023-12-19 13:00:59 +01:00
"source": [
2024-02-26 16:18:03 +01:00
"# # import matplotlib.pyplot as plt\n",
"# bins = np.linspace(-2000, 2000, 50)\n",
"# sns.regplot(\n",
"# x=ak.to_numpy(array[\"x_l0\"]),\n",
"# y=ak.to_numpy(array[\"z_mag_x_fringe\"]),\n",
"# x_bins=50,\n",
"# fit_reg=None,\n",
"# x_estimator=np.mean,\n",
"# label=\"T1X1\",\n",
"# )\n",
"# sns.regplot(\n",
"# x=ak.to_numpy(array[\"x_l4\"]),\n",
"# y=ak.to_numpy(array[\"z_mag_x_fringe\"]),\n",
"# x_bins=50,\n",
"# fit_reg=None,\n",
"# x_estimator=np.mean,\n",
"# label=\"T2X1\",\n",
"# )\n",
"# sns.regplot(\n",
"# x=ak.to_numpy(array[\"x_l8\"]),\n",
"# y=ak.to_numpy(array[\"z_mag_x_fringe\"]),\n",
"# x_bins=50,\n",
"# fit_reg=None,\n",
"# x_estimator=np.mean,\n",
"# label=\"T3X1\",\n",
"# )\n",
"# plt.legend()\n",
"# plt.xlabel(\"x [mm]\")\n",
"# plt.ylabel(\"$z_{Mag}$ [mm]\")\n",
"# mplhep.lhcb.text(\"Simulation\")"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
2024-02-26 16:18:03 +01:00
"execution_count": 44,
2023-12-19 13:00:59 +01:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2024-02-26 16:18:03 +01:00
"['ideal_state_770_tx' 'dSlope_xEndT' 'dSlope_xEndT_abs' 'x_EndT_abs'\n",
" 'ideal_state_770_tx^2' 'ideal_state_770_tx dSlope_xEndT'\n",
" 'ideal_state_770_tx dSlope_xEndT_abs' 'ideal_state_770_tx x_EndT_abs'\n",
" 'dSlope_xEndT^2' 'dSlope_xEndT dSlope_xEndT_abs'\n",
" 'dSlope_xEndT x_EndT_abs' 'dSlope_xEndT_abs^2'\n",
" 'dSlope_xEndT_abs x_EndT_abs' 'x_EndT_abs^2']\n",
"intercept= 5092.708143256812\n",
"coef= {'ideal_state_770_tx': 2018.6886668629327, 'dSlope_xEndT': 389.7888543955816, 'dSlope_xEndT_abs': 1464.867616153959, 'x_EndT_abs': 0.09763035198073229, 'ideal_state_770_tx^2': -4259.173364636334, 'ideal_state_770_tx dSlope_xEndT': 887.6220587366868, 'ideal_state_770_tx dSlope_xEndT_abs': -677.4689885623392, 'ideal_state_770_tx x_EndT_abs': -0.9313147953743464, 'dSlope_xEndT^2': 179.9382929971653, 'dSlope_xEndT dSlope_xEndT_abs': 88.39317926994904, 'dSlope_xEndT x_EndT_abs': -0.19078236037510163, 'dSlope_xEndT_abs^2': 2.3666592074995823, 'dSlope_xEndT_abs x_EndT_abs': -0.48044427953929886, 'x_EndT_abs^2': 5.0288654463924435e-06}\n",
"r2 score= -0.09609938850755273\n",
"RMSE = 356.01344182664485\n"
2023-12-19 13:00:59 +01:00
]
}
],
"source": [
"from sklearn.preprocessing import PolynomialFeatures\n",
"from sklearn.linear_model import LinearRegression, Lasso, Ridge\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.pipeline import Pipeline\n",
"from sklearn.metrics import mean_squared_error\n",
"import numpy as np\n",
2024-02-26 16:18:03 +01:00
"\n",
2023-12-19 13:00:59 +01:00
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"ideal_state_770_tx\",\n",
" \"dSlope_xEndT\",\n",
" \"dSlope_xEndT_abs\",\n",
" \"x_EndT_abs\",\n",
2023-12-19 13:00:59 +01:00
"]\n",
2024-02-26 16:18:03 +01:00
"target_feat = \"z_mag_xEndT\"\n",
2023-12-19 13:00:59 +01:00
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(\n",
" data, target, test_size=0.2, random_state=42\n",
")\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly_features = poly.get_feature_names_out(input_features=features)\n",
2024-02-26 16:18:03 +01:00
"# keep = [\n",
"# \"ideal_state_770_tx^2\",\n",
"# \"dSlope_xEndT^2\",\n",
"# \"dSlope_xEndT_abs\",\n",
"# \"x_EndT_abs\",\n",
"# ]\n",
"# remove = [i for i, f in enumerate(poly_features) if f not in keep]\n",
"# X_train_model = np.delete(X_train_model, remove, axis=1)\n",
"# X_test_model = np.delete(X_test_model, remove, axis=1)\n",
"# poly_features = np.delete(poly_features, remove)\n",
2023-12-19 13:00:59 +01:00
"print(poly_features)\n",
"\n",
2024-02-26 16:18:03 +01:00
"# lin_reg = LinearRegression()\n",
"lin_reg = Lasso(alpha=0.01)\n",
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\"coef=\", dict(zip(poly_features, lin_reg.coef_)))\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
2024-02-26 16:18:03 +01:00
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(exptext: Custom Text(0.0, 1, 'LHCb'),\n",
" expsuffix: Custom Text(0.0, 1.005, 'Simulation'))"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABMIAAAOWCAYAAAANzz7PAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAADXPElEQVR4nOz9T2xb+X3v/7+ONLdIcVvpSL47G4h1OL7odxWLlO+iu4zImS5apBmT8iBF20Ut0g76uwulJqXJOrZJz2hzf0hMyrP4pWhQi7LToF1MTcrZfRexeOzsgjvhkQKMd9fSkdqiQRvr/Ba6ZEiJoij+PRKfD4CoKH34OW+KtBq+5v35fAzP8zwBAAAAAAAA59zIoAsAAAAAAAAA+oEgDAAAAAAAAEOBIAwAAAAAAABDgSAMAAAAAAAAQ4EgDAAAAAAAAEOBIAwAAAAAAABDgSAMAAAAAAAAQ4EgDAAAAAAAAEOBIAwAAAAAAABDgSAMAAAAAAAAQ4EgDAAAAAAAAEOBIAwAAAAAAABDgSAMAAAAAAAAQ4EgDAAAAAAAAEOBIAwAAAAAAABDgSAMAAAAAAAAQ4EgDAAAAAAAAEOB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1f1Q7unem5vb3e3kA6YpqlkMnnsnmyn3d+tWwqFQvXrVjvIav8dncV/OwAAAADOH4Iw4BiNup0cx/HtMrrTOM2yxJPE43GVy+UjIdTa2pqvw492Q7N+cxxHuVxOxWKx4Ub4/azjtA6/z87Dvx0AAAAAZxtBGHCMGzduNPy+n8Od4xwOfboZhFXmK5VKR65z2tM68VuVUy+z2WzTfdH6pTb
"text/plain": [
"<Figure size 1200x900 with 2 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2024-02-26 16:18:03 +01:00
"bins = np.linspace(5150, 5300, 30)\n",
"ax = sns.regplot(\n",
" x=y_test,\n",
" y=abs(y_test - y_pred_test),\n",
" x_bins=bins,\n",
" fit_reg=None,\n",
" x_estimator=np.mean,\n",
" label=\"bla\",\n",
")\n",
2023-12-19 13:00:59 +01:00
"ax2 = ax.twinx()\n",
2024-02-26 16:18:03 +01:00
"ax2.hist(y_test,\n",
" bins=30,\n",
" range=[5150, 5300],\n",
" color=\"#2A9D8F\",\n",
" alpha=0.8,\n",
" align=\"left\")\n",
2023-12-19 13:00:59 +01:00
"ax.set_xlabel(r\"z$_{Mag}$ [mm]\")\n",
"ax.set_ylabel(\"Mean Deviation [mm]\")\n",
"ax2.set_ylabel(\"Number of Tracks\")\n",
"mplhep.lhcb.text(\"Simulation\", loc=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"median_z_mag_x = np.median(array[\"z_mag_x_fringe\"])\n",
"print(median_z_mag_x)\n",
"params_per_layer = [[] for _ in range(12)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def format_array(name, intercept, coef):\n",
2024-02-26 16:18:03 +01:00
" coef = [str(c) + \"f\" for c in coef if c != 0.0]\n",
2023-12-19 13:00:59 +01:00
" intercept = str(intercept) + \"f\"\n",
" code = f\"constexpr std::array {name}\"\n",
2024-02-26 16:18:03 +01:00
" code += \"{\" + \", \".join([intercept] + list(coef)) + \"};\"\n",
2023-12-19 13:00:59 +01:00
" return code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2024-02-26 16:18:03 +01:00
"array[\"x_diff_straight_l0\"] = (array[\"x_l0\"] - array[\"x\"] - array[\"tx\"] *\n",
" (array[\"z_l0\"] - array[\"z\"]))\n",
2023-12-19 13:00:59 +01:00
"array[\"x_l0_rel\"] = array[\"x_l0\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
" # \"x_l0_rel\",\n",
2023-12-19 13:00:59 +01:00
" \"x_diff_straight_l0\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"poly_features = poly.get_feature_names_out(input_features=features)\n",
"keep = [\n",
2024-02-26 16:18:03 +01:00
" # \"tx\",\n",
" # \"ty\",\n",
" # \"x_l0_rel\",\n",
2023-12-19 13:00:59 +01:00
" \"tx^2\",\n",
2024-02-26 16:18:03 +01:00
" # \"tx x_l0_rel\",\n",
2023-12-19 13:00:59 +01:00
" \"tx x_diff_straight_l0\",\n",
" \"ty^2\",\n",
2024-02-26 16:18:03 +01:00
" # \"x_l0_rel^2\"\n",
" \"x_diff_straight_l0^2\",\n",
2023-12-19 13:00:59 +01:00
"]\n",
"remove = [i for i, f in enumerate(poly_features) if f not in keep]\n",
2024-02-26 16:18:03 +01:00
"X_train_model = np.delete(X_train_model, remove, axis=1)\n",
"X_test_model = np.delete(X_test_model, remove, axis=1)\n",
"poly_features = np.delete(poly_features, remove)\n",
2023-12-19 13:00:59 +01:00
"print(poly_features)\n",
"\n",
2024-02-26 16:18:03 +01:00
"lin_reg = LinearRegression() # Lasso(alpha=0.004)\n",
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
"print(\"coef=\", dict(zip(poly_features, lin_reg.coef_)))\n",
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l0\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[0] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l1_rel\"] = array[\"x_l1\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l1_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l1\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[1] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l2_rel\"] = array[\"x_l2\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l2_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l2\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[2] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l3_rel\"] = array[\"x_l3\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l3_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l3\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[3] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l4_rel\"] = array[\"x_l4\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l4_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l4\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[4] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l5_rel\"] = array[\"x_l5\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l5_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l5\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[5] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l6_rel\"] = array[\"x_l6\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l6_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l6\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[6] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l7_rel\"] = array[\"x_l7\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l7_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l7\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[7] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l8_rel\"] = array[\"x_l8\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l8_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l8\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[8] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l9_rel\"] = array[\"x_l9\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l9_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l9\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[9] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l10_rel\"] = array[\"x_l10\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l10_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l10\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[10] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"array[\"x_l11_rel\"] = array[\"x_l11\"] / 3000\n",
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"x_l11_rel\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"lin_reg = Lasso(alpha=0.01)\n",
2024-02-26 16:18:03 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\n",
" \"coef=\",\n",
" dict(\n",
" zip(poly.get_feature_names_out(input_features=features),\n",
" lin_reg.coef_)),\n",
")\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_l11\", lin_reg.intercept_, lin_reg.coef_))\n",
"params_per_layer[11] = [lin_reg.intercept_] + list(lin_reg.coef_)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"features = [\n",
2024-02-26 16:18:03 +01:00
" \"tx\",\n",
" \"ty\",\n",
2023-12-19 13:00:59 +01:00
" \"dSlope_fringe\",\n",
"]\n",
"target_feat = \"z_mag_x_fringe\"\n",
"\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
2024-02-26 16:18:03 +01:00
"X_train, X_test, y_train, y_test = train_test_split(data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
2024-02-26 16:18:03 +01:00
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2023-12-19 13:00:59 +01:00
"\n",
"poly_features = poly.get_feature_names_out(input_features=features)\n",
"keep = [\n",
2024-02-26 16:18:03 +01:00
" # \"tx\",\n",
" # \"ty\",\n",
" # \"dSlope_fringe\",\n",
2023-12-19 13:00:59 +01:00
" \"tx^2\",\n",
" \"tx dSlope_fringe\",\n",
" \"ty^2\",\n",
2024-02-26 16:18:03 +01:00
" \"dSlope_fringe^2\",\n",
2023-12-19 13:00:59 +01:00
"]\n",
"remove = [i for i, f in enumerate(poly_features) if f not in keep]\n",
2024-02-26 16:18:03 +01:00
"X_train_model = np.delete(X_train_model, remove, axis=1)\n",
"X_test_model = np.delete(X_test_model, remove, axis=1)\n",
"poly_features = np.delete(poly_features, remove)\n",
2023-12-19 13:00:59 +01:00
"print(poly_features)\n",
"\n",
2024-02-26 16:18:03 +01:00
"lin_reg = LinearRegression() # Lasso(alpha=0.01)\n",
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
2023-12-19 13:00:59 +01:00
"print(\"intercept=\", lin_reg.intercept_)\n",
2024-02-26 16:18:03 +01:00
"print(\"coef=\", dict(zip(poly_features, lin_reg.coef_)))\n",
2023-12-19 13:00:59 +01:00
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))\n",
"print(format_array(\"zMagnetParams_dSlope\", lin_reg.intercept_, lin_reg.coef_))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import scipy.optimize\n",
2024-02-26 16:18:03 +01:00
"\n",
"\n",
"def parabola(x, a, b, c):\n",
" return a * x**2 + b * x + c\n",
"\n",
"\n",
2023-12-19 13:00:59 +01:00
"params_1 = np.array([p[1] / params_per_layer[0][1] for p in params_per_layer])\n",
"x = [array[f\"z_l{n}\"][0] - array[\"z_ref\"][0] for n in range(12)]\n",
"print(params_1)\n",
"print(x)\n",
2024-02-26 16:18:03 +01:00
"plt.plot(x, params_1, \"o\")"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"params_3 = np.array([params_per_layer[0][3] / p[3] for p in params_per_layer])\n",
"x = [array[f\"z_l{n}\"][0] - array[\"z_ref\"][0] for n in range(12)]\n",
"print(params_3**2)\n",
"print(x)\n",
2024-02-26 16:18:03 +01:00
"plt.plot(x, params_3, \"o\")"
2023-12-19 13:00:59 +01:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from sklearn.preprocessing import PolynomialFeatures\n",
"from sklearn.linear_model import LinearRegression, Lasso\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.metrics import mean_squared_error\n",
2024-02-26 16:18:03 +01:00
"\n",
2023-12-19 13:00:59 +01:00
"feautures = [\"tx\", \"ty\", \"dSlope\"]\n",
"data = np.column_stack([ak.to_numpy(array[feat]) for feat in features])\n",
"target = ak.to_numpy(array[target_feat])\n",
"X_train, X_test, y_train, y_test = train_test_split(\n",
" data,\n",
" target,\n",
" test_size=0.2,\n",
" random_state=42,\n",
")\n",
"poly = PolynomialFeatures(degree=2, include_bias=False)\n",
"X_train_model = poly.fit_transform(X_train)\n",
"X_test_model = poly.fit_transform(X_test)\n",
2024-02-26 16:18:03 +01:00
"lin_reg = LinearRegression() # or Lasso if regularisation is needed\n",
2023-12-19 13:00:59 +01:00
"lin_reg.fit(X_train_model, y_train)\n",
"y_pred_test = lin_reg.predict(X_test_model)\n",
"print(\"r2 score=\", lin_reg.score(X_test_model, y_test))\n",
"print(\"RMSE =\", mean_squared_error(y_test, y_pred_test, squared=False))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.6",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2024-02-26 16:18:03 +01:00
"version": "3.10.12"
2023-12-19 13:00:59 +01:00
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "a2eff8b4da8b8eebf5ee2e5f811f31a557e0a202b4d2f04f849b065340a6eda6"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}