Skip to content

Commit

Permalink
fixes 2d hist bin transofrm to 2 axis
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Oct 11, 2024
1 parent a0ff599 commit 53a56a8
Show file tree
Hide file tree
Showing 18 changed files with 9,211 additions and 2,563 deletions.
6 changes: 6 additions & 0 deletions debug/.ipynb_checkpoints/Untitled-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
2,847 changes: 322 additions & 2,525 deletions debug/.ipynb_checkpoints/histo2d-checkpoint.ipynb

Large diffs are not rendered by default.

316 changes: 316 additions & 0 deletions debug/Untitled.ipynb

Large diffs are not rendered by default.

58 changes: 54 additions & 4 deletions debug/histo2d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,75 @@
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 1,
"id": "45563c8b-4735-4fd4-940a-e3ed0b6eaf41",
"metadata": {},
"outputs": [],
"source": [
"import babyyoda as grogu\n",
"from matplotlib import pyplot as plot\n",
"from babyyoda import loc"
"from babyyoda import loc\n",
"import yoda as yd"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 2,
"id": "62324cf2-abda-44c1-be2c-ab439577f4eb",
"metadata": {},
"outputs": [],
"source": [
"hists = grogu.read_yoda(\"../tests/test_histo2d_v2.yoda\")\n",
"h = hists[\"/ALICE_2020_I1797621/GGPdfXQ\"]"
"h = hists[\"/ALICE_2020_I1797621/GGPdfXQ\"]\n",
"\n",
"yd.write([h.target], \"test_histo2d_v3.yoda\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "6731d1bc-093b-4445-a213-eb3230e72536",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.0"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h.binAt(300, 4000).sumW()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4ed6e9b2-8864-41be-bafd-15eb8da68982",
"metadata": {},
"outputs": [
{
"ename": "ValueError",
"evalue": "loc 3.0 is not in the range of [(1e-06, 1.318257e-06), (1.318257e-06, 1.737801e-06), (1.737801e-06, 2.290868e-06), (2.290868e-06, 3.019952e-06), (3.019952e-06, 3.981072e-06), (3.981072e-06, 5.248075e-06), (5.248075e-06, 6.91831e-06), (6.91831e-06, 9.120108e-06), (9.120108e-06, 1.202264e-05), (1.202264e-05, 1.584893e-05), (1.584893e-05, 2.089296e-05), (2.089296e-05, 2.754229e-05), (2.754229e-05, 3.630781e-05), (3.630781e-05, 4.786301e-05), (4.786301e-05, 6.309573e-05), (6.309573e-05, 8.317638e-05), (8.317638e-05, 0.0001096478), (0.0001096478, 0.000144544), (0.000144544, 0.0001905461), (0.0001905461, 0.0002511886), (0.0002511886, 0.0003311311), (0.0003311311, 0.0004365158), (0.0004365158, 0.0005754399), (0.0005754399, 0.0007585776), (0.0007585776, 0.001), (0.001, 0.001318257), (0.001318257, 0.001737801), (0.001737801, 0.002290868), (0.002290868, 0.003019952), (0.003019952, 0.003981072), (0.003981072, 0.005248075), (0.005248075, 0.00691831), (0.00691831, 0.009120108), (0.009120108, 0.01202264), (0.01202264, 0.01584893), (0.01584893, 0.02089296), (0.02089296, 0.02754229), (0.02754229, 0.03630781), (0.03630781, 0.04786301), (0.04786301, 0.06309573), (0.06309573, 0.08317638), (0.08317638, 0.1096478), (0.1096478, 0.144544), (0.144544, 0.1905461), (0.1905461, 0.2511886), (0.2511886, 0.3311311), (0.3311311, 0.4365158), (0.4365158, 0.5754399), (0.5754399, 0.7585776), (0.7585776, 1.0)]",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[6], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mh\u001b[49m\u001b[43m[\u001b[49m\u001b[43mloc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m3.\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43mloc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m4.\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241m.\u001b[39msumW()\n",
"File \u001b[0;32m~/.local/lib/python3.12/site-packages/babyyoda/histo2D.py:161\u001b[0m, in \u001b[0;36mHisto2D.__getitem__\u001b[0;34m(self, slices)\u001b[0m\n\u001b[1;32m 159\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(slices, \u001b[38;5;28mtuple\u001b[39m):\n\u001b[1;32m 160\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(slices) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m2\u001b[39m:\n\u001b[0;32m--> 161\u001b[0m ix, iy \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__get_indices\u001b[49m\u001b[43m(\u001b[49m\u001b[43mslices\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 162\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(ix, \u001b[38;5;28mint\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(iy, \u001b[38;5;28mint\u001b[39m):\n\u001b[1;32m 163\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__get_by_indices(ix, iy)\n",
"File \u001b[0;32m~/.local/lib/python3.12/site-packages/babyyoda/histo2D.py:151\u001b[0m, in \u001b[0;36mHisto2D.__get_indices\u001b[0;34m(self, slices)\u001b[0m\n\u001b[1;32m 150\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__get_indices\u001b[39m(\u001b[38;5;28mself\u001b[39m, slices):\n\u001b[0;32m--> 151\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__get_x_index\u001b[49m\u001b[43m(\u001b[49m\u001b[43mslices\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__get_y_index(slices[\u001b[38;5;241m1\u001b[39m])\n",
"File \u001b[0;32m~/.local/lib/python3.12/site-packages/babyyoda/histo2D.py:139\u001b[0m, in \u001b[0;36mHisto2D.__get_x_index\u001b[0;34m(self, slices)\u001b[0m\n\u001b[1;32m 137\u001b[0m ix \u001b[38;5;241m=\u001b[39m slices\n\u001b[1;32m 138\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(slices, loc):\n\u001b[0;32m--> 139\u001b[0m ix \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m__get_index_by_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mslices\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43maxes\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 140\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m ix\n",
"File \u001b[0;32m~/.local/lib/python3.12/site-packages/babyyoda/histo2D.py:132\u001b[0m, in \u001b[0;36mHisto2D.__get_index_by_loc\u001b[0;34m(self, loc, bins)\u001b[0m\n\u001b[1;32m 130\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m a \u001b[38;5;241m<\u001b[39m\u001b[38;5;241m=\u001b[39m loc\u001b[38;5;241m.\u001b[39mvalue \u001b[38;5;129;01mand\u001b[39;00m loc\u001b[38;5;241m.\u001b[39mvalue \u001b[38;5;241m<\u001b[39m b:\n\u001b[1;32m 131\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m bins\u001b[38;5;241m.\u001b[39mindex((a, b)) \u001b[38;5;241m+\u001b[39m loc\u001b[38;5;241m.\u001b[39moffset\n\u001b[0;32m--> 132\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mloc \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mloc\u001b[38;5;241m.\u001b[39mvalue\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is not in the range of \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mbins\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mValueError\u001b[0m: loc 3.0 is not in the range of [(1e-06, 1.318257e-06), (1.318257e-06, 1.737801e-06), (1.737801e-06, 2.290868e-06), (2.290868e-06, 3.019952e-06), (3.019952e-06, 3.981072e-06), (3.981072e-06, 5.248075e-06), (5.248075e-06, 6.91831e-06), (6.91831e-06, 9.120108e-06), (9.120108e-06, 1.202264e-05), (1.202264e-05, 1.584893e-05), (1.584893e-05, 2.089296e-05), (2.089296e-05, 2.754229e-05), (2.754229e-05, 3.630781e-05), (3.630781e-05, 4.786301e-05), (4.786301e-05, 6.309573e-05), (6.309573e-05, 8.317638e-05), (8.317638e-05, 0.0001096478), (0.0001096478, 0.000144544), (0.000144544, 0.0001905461), (0.0001905461, 0.0002511886), (0.0002511886, 0.0003311311), (0.0003311311, 0.0004365158), (0.0004365158, 0.0005754399), (0.0005754399, 0.0007585776), (0.0007585776, 0.001), (0.001, 0.001318257), (0.001318257, 0.001737801), (0.001737801, 0.002290868), (0.002290868, 0.003019952), (0.003019952, 0.003981072), (0.003981072, 0.005248075), (0.005248075, 0.00691831), (0.00691831, 0.009120108), (0.009120108, 0.01202264), (0.01202264, 0.01584893), (0.01584893, 0.02089296), (0.02089296, 0.02754229), (0.02754229, 0.03630781), (0.03630781, 0.04786301), (0.04786301, 0.06309573), (0.06309573, 0.08317638), (0.08317638, 0.1096478), (0.1096478, 0.144544), (0.144544, 0.1905461), (0.1905461, 0.2511886), (0.2511886, 0.3311311), (0.3311311, 0.4365158), (0.4365158, 0.5754399), (0.5754399, 0.7585776), (0.7585776, 1.0)]"
]
}
],
"source": [
"h[loc(3.0), loc(4.0)].sumW()"
]
},
{
Expand Down
Loading

0 comments on commit 53a56a8

Please sign in to comment.