|
125 | 125 | "# We first need to load the PDF set with LHAPDF\n", |
126 | 126 | "import lhapdf\n", |
127 | 127 | "import numpy as np\n", |
| 128 | + "\n", |
128 | 129 | "# `Polars` is a better alternative to Pandas (written in Rust!)\n", |
129 | 130 | "import polars as pl\n", |
130 | 131 | "\n", |
|
188 | 189 | ], |
189 | 190 | "source": [ |
190 | 191 | "predictions = grid.convolve_with_one(2212, pdf.xfxQ2, pdf.alphasQ2)\n", |
191 | | - "df_preds = pl.DataFrame({\n", |
192 | | - " \"bins\": range(predictions.size),\n", |
193 | | - " \"predictions\": predictions,\n", |
194 | | - "})\n", |
| 192 | + "df_preds = pl.DataFrame(\n", |
| 193 | + " {\n", |
| 194 | + " \"bins\": range(predictions.size),\n", |
| 195 | + " \"predictions\": predictions,\n", |
| 196 | + " }\n", |
| 197 | + ")\n", |
195 | 198 | "df_preds" |
196 | 199 | ] |
197 | 200 | }, |
|
231 | 234 | "import matplotlib.pyplot as plt\n", |
232 | 235 | "\n", |
233 | 236 | "# Experimental central values as provided by HepData\n", |
234 | | - "data_central = np.array([\n", |
235 | | - " 1223.0, 3263.0, 4983.0, 6719.0, 8051.0, 8967.0, 9561.0, 9822.0, 9721.0, 9030.0, 7748.0, 6059.0, 4385.0, 2724.0, 1584.0, 749.0, 383.0, 11.0\n", |
236 | | - "])\n", |
| 237 | + "data_central = np.array(\n", |
| 238 | + " [\n", |
| 239 | + " 1223.0,\n", |
| 240 | + " 3263.0,\n", |
| 241 | + " 4983.0,\n", |
| 242 | + " 6719.0,\n", |
| 243 | + " 8051.0,\n", |
| 244 | + " 8967.0,\n", |
| 245 | + " 9561.0,\n", |
| 246 | + " 9822.0,\n", |
| 247 | + " 9721.0,\n", |
| 248 | + " 9030.0,\n", |
| 249 | + " 7748.0,\n", |
| 250 | + " 6059.0,\n", |
| 251 | + " 4385.0,\n", |
| 252 | + " 2724.0,\n", |
| 253 | + " 1584.0,\n", |
| 254 | + " 749.0,\n", |
| 255 | + " 383.0,\n", |
| 256 | + " 11.0,\n", |
| 257 | + " ]\n", |
| 258 | + ")\n", |
237 | 259 | "\n", |
238 | 260 | "# Normalization for each bin. See Section below for more details.\n", |
239 | | - "bin_norm = np.array([0.125 for _ in range(predictions.size - 2)] + [0.250, 0.250])\n", |
| 261 | + "bin_norm = np.array(\n", |
| 262 | + " [0.125 for _ in range(predictions.size - 2)] + [0.250, 0.250]\n", |
| 263 | + ")\n", |
240 | 264 | "\n", |
241 | 265 | "fig, ax = plt.subplots(figsize=(5.6, 3.9))\n", |
242 | 266 | "# Factor of `1e3` takes into account the unit conversion into `fb`\n", |
243 | | - "ax.plot(df_preds[\"bins\"], 1e3 * bin_norm * df_preds[\"predictions\"], 's', markersize=8, label=\"theory\")\n", |
244 | | - "ax.plot(df_preds[\"bins\"], data_central, 'o', markersize=8, label=\"data\")\n", |
| 267 | + "ax.plot(\n", |
| 268 | + " df_preds[\"bins\"],\n", |
| 269 | + " 1e3 * bin_norm * df_preds[\"predictions\"],\n", |
| 270 | + " \"s\",\n", |
| 271 | + " markersize=8,\n", |
| 272 | + " label=\"theory\",\n", |
| 273 | + ")\n", |
| 274 | + "ax.plot(df_preds[\"bins\"], data_central, \"o\", markersize=8, label=\"data\")\n", |
245 | 275 | "ax.grid(True, alpha=0.5)\n", |
246 | 276 | "ax.set_yscale(\"log\")\n", |
247 | 277 | "ax.set_xlabel(\"bins\")\n", |
|
417 | 447 | "for idx, o in enumerate(grid.orders()):\n", |
418 | 448 | " orders.append(o.as_tuple())\n", |
419 | 449 | "\n", |
420 | | - "df_orders = pl.DataFrame(\n", |
421 | | - " np.array(orders),\n", |
422 | | - " schema=[\"as\", \"a\", \"lf\", \"lr\"]\n", |
423 | | - ")\n", |
| 450 | + "df_orders = pl.DataFrame(np.array(orders), schema=[\"as\", \"a\", \"lf\", \"lr\"])\n", |
424 | 451 | "df_orders.with_row_index()" |
425 | 452 | ] |
426 | 453 | }, |
|
506 | 533 | "# an associated bin normalization.\n", |
507 | 534 | "df = pl.DataFrame({})\n", |
508 | 535 | "for bin_dim in range(bin_dims):\n", |
509 | | - " df = pl.concat([df,pl.DataFrame({\n", |
510 | | - " f\"dim {bin_dim} left\": grid.bin_left(bin_dim),\n", |
511 | | - " f\"dim {bin_dim} right\": grid.bin_right(bin_dim),\n", |
512 | | - " })],how=\"vertical\",)\n", |
| 536 | + " df = pl.concat(\n", |
| 537 | + " [\n", |
| 538 | + " df,\n", |
| 539 | + " pl.DataFrame(\n", |
| 540 | + " {\n", |
| 541 | + " f\"dim {bin_dim} left\": grid.bin_left(bin_dim),\n", |
| 542 | + " f\"dim {bin_dim} right\": grid.bin_right(bin_dim),\n", |
| 543 | + " }\n", |
| 544 | + " ),\n", |
| 545 | + " ],\n", |
| 546 | + " how=\"vertical\",\n", |
| 547 | + " )\n", |
513 | 548 | "df" |
514 | 549 | ] |
515 | 550 | }, |
|
670 | 705 | ], |
671 | 706 | "source": [ |
672 | 707 | "# Load our modified grids\n", |
673 | | - "grid_nrm = pineappl.grid.Grid.read(\"./LHCB_DY_8TEV_custom_normalizations.pineappl.lz4\")\n", |
| 708 | + "grid_nrm = pineappl.grid.Grid.read(\n", |
| 709 | + " \"./LHCB_DY_8TEV_custom_normalizations.pineappl.lz4\"\n", |
| 710 | + ")\n", |
674 | 711 | "df_nbins = pl.DataFrame({\"bin normalization\": grid_nrm.bin_normalizations()})\n", |
675 | 712 | "df_nbins.with_row_index()" |
676 | 713 | ] |
|
0 commit comments