From 42ed4e687be7b4a8ef762068605f88a0f3c250fb Mon Sep 17 00:00:00 2001 From: Chris Papageorgakis Date: Fri, 16 Feb 2024 13:12:29 +0100 Subject: [PATCH 01/20] add test for masking in exclusive_constituents --- tests/test_002-exclusive_jets.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_002-exclusive_jets.py b/tests/test_002-exclusive_jets.py index b6e8376e..52b57ada 100644 --- a/tests/test_002-exclusive_jets.py +++ b/tests/test_002-exclusive_jets.py @@ -534,6 +534,41 @@ def test_exclusive_constituents_multi(): ) +def test_exclusive_constituents_masking_multi(): + array = ak.Array( + [ + [ + {"px": -0.181, "py": -0.798, "pz": -0.652, "E": 1.06}, + {"px": 0.377, "py": 0.116, "pz": -0.0749, "E": 0.425}, + ], + [ + {"px": 0.54, "py": -0.65, "pz": -0.00527, "E": 0.857}, + {"px": 0.253, "py": -0.0342, "pz": -0.0731, "E": 0.3}, + ], + [ + {"px": 0.294, "py": 0.254, "pz": -0.259, "E": 0.467}, + {"px": 4.65, "py": -1.88, "pz": -3.29, "E": 6}, + ], + [ + {"px": 1.45, "py": -0.179, "pz": -0.876, "E": 1.71}, + {"px": 12.8, "py": -1.8, "pz": -7.18, "E": 14.8}, + ], + [ + {"px": -3.55, "py": -1.64, "pz": -0.0941, "E": 3.91}, + {"px": -1.33, "py": -1.03, "pz": 0.147, "E": 1.7}, + ], + ], + with_name="Momentum4D", + ) + mask = ak.Array([True, True, False, True, True]) + jetdef = fastjet.JetDefinition(fastjet.kt_algorithm, 1) + result = fastjet.ClusterSequence( + array[mask], jetdef + ).exclusive_jets_constituent_index(njets=2) + output = ak.Array([[[1], [0]], [[0], [1]], [[1], [0]], [[0], [1]]]) + assert ak.all(result == output) + + def test_exclusive_ycut(): array = ak.Array( [ From ece217a09f1245b6d19afab95cde43a2dbded3ce Mon Sep 17 00:00:00 2001 From: Chris Papageorgakis Date: Wed, 13 Mar 2024 11:38:48 +0100 Subject: [PATCH 02/20] First attempt to fix the issue. Implemented starts & stops. --- src/_ext.cpp | 35 +++++++++++++++++------------------ src/fastjet/_generalevent.py | 15 +++++++++------ src/fastjet/_multievent.py | 18 +++++++++++------- src/fastjet/_singleevent.py | 17 +++++++++++------ 4 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/_ext.cpp b/src/_ext.cpp index 9d190311..6d77bf6a 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -33,9 +33,9 @@ typedef struct { PyObject *next; } SwigPyObject; -template -T swigtocpp(py::object obj) { // unwraps python object to get the cpp pointer - // from the swig bindings +template T swigtocpp(py::object obj) { + // unwraps python object to get the cpp pointer + // from the swig bindings auto upointer = obj.attr("this").ptr(); auto swigpointer = reinterpret_cast(upointer); auto objpointervoid = swigpointer->ptr; @@ -59,39 +59,37 @@ output_wrapper interfacemulti( py::array_t pyi, py::array_t pzi, py::array_t Ei, - py::array_t offsets, + py::array_t starts, + py::array_t stops, py::object jetdef) { - py::buffer_info infooff = offsets.request(); + // requesting buffer information of the input + py::buffer_info infostarts = starts.request(); + py::buffer_info infostops = stops.request(); py::buffer_info infopx = pxi.request(); - py::buffer_info infopy = - pyi.request(); // requesting buffer information of the input + py::buffer_info infopy = pyi.request(); py::buffer_info infopz = pzi.request(); py::buffer_info infoE = Ei.request(); - auto offptr = static_cast(infooff.ptr); + // pointers to the initial values + auto startsptr = static_cast(infostarts.ptr); + auto stopsptr = static_cast(infostops.ptr); auto pxptr = static_cast(infopx.ptr); - auto pyptr = - static_cast(infopy.ptr); // pointer to the initial value + auto pyptr = static_cast(infopy.ptr); auto pzptr = static_cast(infopz.ptr); auto Eptr = static_cast(infoE.ptr); - int dimoff = infooff.shape[0]; + int dimoff = infostarts.shape[0]; output_wrapper ow; - std::vector nevents; - std::vector offidx; - std::vector constphi; std::vector idx; - std::vector idxo; for (int i = 0; i < dimoff - 1; i++) { std::vector particles; - for (int j = *offptr; j < *(offptr + 1); j++) { + for (int j = *starts; j < *stops; j++) { particles.push_back(fj::PseudoJet(*pxptr, *pyptr, *pzptr, *Eptr)); pxptr++; pyptr++; pzptr++; Eptr++; } - std::vector jets; auto jet_def = swigtocpp(jetdef); std::shared_ptr> pj = @@ -99,7 +97,8 @@ output_wrapper interfacemulti( std::shared_ptr cs = std::make_shared(*pj, *jet_def); auto j = cs->inclusive_jets(); - offptr++; + starts++; + stops++; ow.cse.push_back(cs); ow.parts.push_back(pj); } diff --git a/src/fastjet/_generalevent.py b/src/fastjet/_generalevent.py index 3333ebff..b7922a2b 100644 --- a/src/fastjet/_generalevent.py +++ b/src/fastjet/_generalevent.py @@ -21,14 +21,15 @@ def __init__(self, data, jetdef): self._clusterable_level[i] = ak.Array( self._clusterable_level[i].layout.to_ListOffsetArray64(True) ) - px, py, pz, E, offsets = self.extract_cons(self._clusterable_level[i]) + px, py, pz, E, starts, stops = self.extract_cons(self._clusterable_level[i]) px = self.correct_byteorder(px) py = self.correct_byteorder(py) pz = self.correct_byteorder(pz) E = self.correct_byteorder(E) - offsets = self.correct_byteorder(offsets) + starts = self.correct_byteorder(starts) + stops = self.correct_byteorder(stops) self._results.append( - fastjet._ext.interfacemulti(px, py, pz, E, offsets, jetdef) + fastjet._ext.interfacemulti(px, py, pz, E, starts, stops, jetdef) ) def _check_listoffset_subtree(self, data): @@ -215,9 +216,11 @@ def extract_cons(self, array): py = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).py) pz = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).pz) E = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).E) - off = np.asarray(array.layout.stops) - off = np.insert(off, 0, 0) - return px, py, pz, E, off + starts = np.asarray(array.layout.starts) + stops = np.asarray(array.layout.stops) + starts = np.insert(starts, 0, 0) + stops = np.insert(stops, 0, 0) + return px, py, pz, E, starts, stops def _replace_multi(self): self._mod_data = self.data diff --git a/src/fastjet/_multievent.py b/src/fastjet/_multievent.py index 9358fa4e..5870d82b 100644 --- a/src/fastjet/_multievent.py +++ b/src/fastjet/_multievent.py @@ -9,15 +9,17 @@ class _classmultievent: def __init__(self, data, jetdef): self.jetdef = jetdef - # data = ak.Array(data.layout.to_ListOffsetArray64(True)) If I do this vector can't convert the coordinates self.data = data - px, py, pz, E, offsets = self.extract_cons(self.data) + px, py, pz, E, starts, stops = self.extract_cons(self.data) px = self.correct_byteorder(px) py = self.correct_byteorder(py) pz = self.correct_byteorder(pz) E = self.correct_byteorder(E) - offsets = self.correct_byteorder(offsets) - self._results = fastjet._ext.interfacemulti(px, py, pz, E, offsets, jetdef) + starts = self.correct_byteorder(starts) + stops = self.correct_byteorder(stops) + self._results = fastjet._ext.interfacemulti( + px, py, pz, E, starts, stops, jetdef + ) def _check_record(self, data): return data.layout.is_record or data.layout.is_numpy @@ -34,9 +36,11 @@ def extract_cons(self, array): py = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).py) pz = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).pz) E = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).E) - off = np.asarray(array.layout.stops) - off = np.insert(off, 0, 0) - return px, py, pz, E, off + starts = np.asarray(array.layout.starts) + stops = np.asarray(array.layout.stops) + starts = np.insert(starts, 0, 0) + stops = np.insert(stops, 0, 0) + return px, py, pz, E, starts, stops def single_to_jagged(self, array): single = ak.Array( diff --git a/src/fastjet/_singleevent.py b/src/fastjet/_singleevent.py index 2c1fa77f..0ea06091 100644 --- a/src/fastjet/_singleevent.py +++ b/src/fastjet/_singleevent.py @@ -10,13 +10,16 @@ class _classsingleevent: def __init__(self, data, jetdef): self.jetdef = jetdef self.data = self.single_to_jagged(data) - px, py, pz, E, offsets = self.extract_cons(self.data) + px, py, pz, E, starts, stops = self.extract_cons(self.data) px = self.correct_byteorder(px) py = self.correct_byteorder(py) pz = self.correct_byteorder(pz) E = self.correct_byteorder(E) - offsets = self.correct_byteorder(offsets) - self._results = fastjet._ext.interfacemulti(px, py, pz, E, offsets, jetdef) + starts = self.correct_byteorder(starts) + stops = self.correct_byteorder(stops) + self._results = fastjet._ext.interfacemulti( + px, py, pz, E, starts, stops, jetdef + ) def correct_byteorder(self, data): if data.dtype.byteorder == "=": @@ -36,9 +39,11 @@ def extract_cons(self, array): py = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).py) pz = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).pz) E = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).E) - off = np.asarray(array.layout.stops) - off = np.insert(off, 0, 0) - return px, py, pz, E, off + starts = np.asarray(array.layout.starts) + stops = np.asarray(array.layout.stops) + starts = np.insert(starts, 0, 0) + stops = np.insert(stops, 0, 0) + return px, py, pz, E, starts, stops def _check_record(self, data): return data.layout.is_record or data.layout.is_numpy From 64b3777cebfa9d60f53223231ebcea3386680765 Mon Sep 17 00:00:00 2001 From: Chris Papageorgakis Date: Wed, 13 Mar 2024 11:47:35 +0100 Subject: [PATCH 03/20] should use the pointer --- src/_ext.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/_ext.cpp b/src/_ext.cpp index 6d77bf6a..037214e3 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -83,7 +83,7 @@ output_wrapper interfacemulti( std::vector idx; for (int i = 0; i < dimoff - 1; i++) { std::vector particles; - for (int j = *starts; j < *stops; j++) { + for (int j = *startsptr; j < *stopsptr; j++) { particles.push_back(fj::PseudoJet(*pxptr, *pyptr, *pzptr, *Eptr)); pxptr++; pyptr++; @@ -97,8 +97,8 @@ output_wrapper interfacemulti( std::shared_ptr cs = std::make_shared(*pj, *jet_def); auto j = cs->inclusive_jets(); - starts++; - stops++; + startsptr++; + stopsptr++; ow.cse.push_back(cs); ow.parts.push_back(pj); } From 950086571a469728b99bb6979a74796ba5388d10 Mon Sep 17 00:00:00 2001 From: Chris Papageorgakis Date: Wed, 13 Mar 2024 12:50:08 +0100 Subject: [PATCH 04/20] start/stop are smaller than offsets array --- src/_ext.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/_ext.cpp b/src/_ext.cpp index 037214e3..9d99b5b6 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -81,7 +81,7 @@ output_wrapper interfacemulti( int dimoff = infostarts.shape[0]; output_wrapper ow; std::vector idx; - for (int i = 0; i < dimoff - 1; i++) { + for (int i = 0; i < dimoff; i++) { std::vector particles; for (int j = *startsptr; j < *stopsptr; j++) { particles.push_back(fj::PseudoJet(*pxptr, *pyptr, *pzptr, *Eptr)); @@ -96,7 +96,6 @@ output_wrapper interfacemulti( std::make_shared>(particles); std::shared_ptr cs = std::make_shared(*pj, *jet_def); - auto j = cs->inclusive_jets(); startsptr++; stopsptr++; ow.cse.push_back(cs); From 248bc92de646eb2f01a8b1e627fc1c870fadb02c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 17 Mar 2025 22:03:02 +0000 Subject: [PATCH 05/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/fastjet/_generalevent.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/fastjet/_generalevent.py b/src/fastjet/_generalevent.py index c6b622f8..235c07e5 100644 --- a/src/fastjet/_generalevent.py +++ b/src/fastjet/_generalevent.py @@ -343,10 +343,24 @@ def _check_subtree_input(self, data): return False def extract_cons(self, array): - px = np.asarray(ak.Array(array.layout.content, behavior=array.behavior, attrs=array.attrs).px) - py = np.asarray(ak.Array(array.layout.content, behavior=array.behavior, attrs=array.attrs).py) - pz = np.asarray(ak.Array(array.layout.content, behavior=array.behavior, attrs=array.attrs).pz) - E = np.asarray(ak.Array(array.layout.content, behavior=array.behavior, attrs=array.attrs).E) + px = np.asarray( + ak.Array( + array.layout.content, behavior=array.behavior, attrs=array.attrs + ).px + ) + py = np.asarray( + ak.Array( + array.layout.content, behavior=array.behavior, attrs=array.attrs + ).py + ) + pz = np.asarray( + ak.Array( + array.layout.content, behavior=array.behavior, attrs=array.attrs + ).pz + ) + E = np.asarray( + ak.Array(array.layout.content, behavior=array.behavior, attrs=array.attrs).E + ) starts = np.asarray(array.layout.starts) stops = np.asarray(array.layout.stops) starts = np.insert(starts, 0, 0) From 3e00c64f493d1df9a7f2fbb5a09f1db3cda3ce5c Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 17:21:34 -0500 Subject: [PATCH 06/20] add back missing clustering invocation --- src/_ext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_ext.cpp b/src/_ext.cpp index 9d99b5b6..d7818feb 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -80,7 +80,6 @@ output_wrapper interfacemulti( int dimoff = infostarts.shape[0]; output_wrapper ow; - std::vector idx; for (int i = 0; i < dimoff; i++) { std::vector particles; for (int j = *startsptr; j < *stopsptr; j++) { @@ -96,6 +95,7 @@ output_wrapper interfacemulti( std::make_shared>(particles); std::shared_ptr cs = std::make_shared(*pj, *jet_def); + cs->inclusive_jets(); startsptr++; stopsptr++; ow.cse.push_back(cs); From 4f86c162d04079147018865d3803f0ab7556349f Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 17:37:03 -0500 Subject: [PATCH 07/20] probably not needed, the code here could be substantially sped up. --- src/_ext.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/_ext.cpp b/src/_ext.cpp index d7818feb..2b5625b8 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -95,7 +95,6 @@ output_wrapper interfacemulti( std::make_shared>(particles); std::shared_ptr cs = std::make_shared(*pj, *jet_def); - cs->inclusive_jets(); startsptr++; stopsptr++; ow.cse.push_back(cs); From 2b1675d7531e57ff0946444e49f10183809a3475 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 17:38:02 -0500 Subject: [PATCH 08/20] remove insertion of leading zeros in starts/stops --- src/fastjet/_generalevent.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fastjet/_generalevent.py b/src/fastjet/_generalevent.py index 235c07e5..3b82507c 100644 --- a/src/fastjet/_generalevent.py +++ b/src/fastjet/_generalevent.py @@ -363,8 +363,6 @@ def extract_cons(self, array): ) starts = np.asarray(array.layout.starts) stops = np.asarray(array.layout.stops) - starts = np.insert(starts, 0, 0) - stops = np.insert(stops, 0, 0) return px, py, pz, E, starts, stops def _replace_multi(self): From 2f6f04c9d1e9c5927083d34e108b9b79fda33024 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 17:41:43 -0500 Subject: [PATCH 09/20] remove insertion of leading zeros in starts/stops --- src/fastjet/_multievent.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/fastjet/_multievent.py b/src/fastjet/_multievent.py index 5870d82b..3296e238 100644 --- a/src/fastjet/_multievent.py +++ b/src/fastjet/_multievent.py @@ -38,8 +38,6 @@ def extract_cons(self, array): E = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).E) starts = np.asarray(array.layout.starts) stops = np.asarray(array.layout.stops) - starts = np.insert(starts, 0, 0) - stops = np.insert(stops, 0, 0) return px, py, pz, E, starts, stops def single_to_jagged(self, array): @@ -56,7 +54,9 @@ def single_to_jagged(self, array): ["px", "py", "pz", "E"], parameters={"__record__": "Momentum4D"}, ), - ) + ), + behavior=array.behavior, + attrs=array.attrs, ) return single @@ -98,6 +98,7 @@ def inclusive_jets(self, min_pt): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) def unclustered_particles(self): @@ -118,6 +119,7 @@ def unclustered_particles(self): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) def exclusive_jets(self, n_jets, dcut): @@ -149,6 +151,7 @@ def exclusive_jets(self, n_jets, dcut): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) def exclusive_jets_up_to(self, n_jets): @@ -172,6 +175,7 @@ def exclusive_jets_up_to(self, n_jets): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) def exclusive_jets_ycut(self, ycut): @@ -192,6 +196,7 @@ def exclusive_jets_ycut(self, ycut): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) def constituent_index(self, min_pt): @@ -282,6 +287,8 @@ def exclusive_jets_softdrop_grooming( "pzsoftdrop": jetpz, }, depth_limit=1, + behavior=self.data.behavior, + attrs=self.data.attrs, ) return out @@ -456,6 +463,7 @@ def exclusive_subjets_up_to(self, data, nsub): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) def exclusive_subdmerge(self, data, nsub): @@ -558,6 +566,7 @@ def childless_pseudojets(self): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) def jets(self): @@ -578,6 +587,7 @@ def jets(self): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) def get_parents(self, data): @@ -604,6 +614,7 @@ def get_parents(self, data): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) def get_child(self, data): @@ -630,4 +641,5 @@ def get_child(self, data): ), ), behavior=self.data.behavior, + attrs=self.data.attrs, ) From 73c45d40163644a6e5c2232d428357c3cb904074 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 17:42:04 -0500 Subject: [PATCH 10/20] remove insertion of leading zeros in starts/stops --- src/fastjet/_singleevent.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fastjet/_singleevent.py b/src/fastjet/_singleevent.py index 0ea06091..cf172087 100644 --- a/src/fastjet/_singleevent.py +++ b/src/fastjet/_singleevent.py @@ -41,8 +41,6 @@ def extract_cons(self, array): E = np.asarray(ak.Array(array.layout.content, behavior=array.behavior).E) starts = np.asarray(array.layout.starts) stops = np.asarray(array.layout.stops) - starts = np.insert(starts, 0, 0) - stops = np.insert(stops, 0, 0) return px, py, pz, E, starts, stops def _check_record(self, data): From b34331963e37f4bef64fe8c4d6a0497022f903e0 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 17:59:02 -0500 Subject: [PATCH 11/20] let's see what's going on in this... --- src/fastjet/_generalevent.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fastjet/_generalevent.py b/src/fastjet/_generalevent.py index 3b82507c..b8f9d4da 100644 --- a/src/fastjet/_generalevent.py +++ b/src/fastjet/_generalevent.py @@ -543,6 +543,9 @@ def exclusive_jets_constituents(self, njets): np_results = self._results[i].to_numpy_exclusive_njet_with_constituents( njets ) + print("DEBUG") + print(np_results) + print("DEBUG") off = np_results[-1] out = ak.Array( ak.contents.ListOffsetArray( From 8f5946a47bfce1997c7a36fc5c49f3d28b7d809c Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 18:10:49 -0500 Subject: [PATCH 12/20] specifically use int64_t for parid --- src/_ext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_ext.cpp b/src/_ext.cpp index 2b5625b8..735a5824 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -373,9 +373,9 @@ PYBIND11_MODULE(_ext, m) { } jk++; - auto parid = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {sizepar}, {sizeof(int)})); + auto parid = py::array(py::buffer_info(nullptr, sizeof(int64_t), py::format_descriptor::value, 1, {sizepar}, {sizeof(int64_t)})); auto bufparid = parid.request(); - int *ptrid = (int *)bufparid.ptr; + int64_t *ptrid = (int64_t *)bufparid.ptr; auto eventoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {len+1}, {sizeof(int)})); auto bufeventoffsets = eventoffsets.request(); From c1c2e1a38390218cb830e6c9d7035fea2ab3e5e4 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 18:11:27 -0500 Subject: [PATCH 13/20] remove prints --- src/fastjet/_generalevent.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/fastjet/_generalevent.py b/src/fastjet/_generalevent.py index b8f9d4da..3b82507c 100644 --- a/src/fastjet/_generalevent.py +++ b/src/fastjet/_generalevent.py @@ -543,9 +543,6 @@ def exclusive_jets_constituents(self, njets): np_results = self._results[i].to_numpy_exclusive_njet_with_constituents( njets ) - print("DEBUG") - print(np_results) - print("DEBUG") off = np_results[-1] out = ak.Array( ak.contents.ListOffsetArray( From 7ab1c7231cf2eb1a85c09f69b37adaec4c3fd336 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 18:19:40 -0500 Subject: [PATCH 14/20] consistency --- src/_ext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_ext.cpp b/src/_ext.cpp index 735a5824..a5970ad7 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -373,7 +373,7 @@ PYBIND11_MODULE(_ext, m) { } jk++; - auto parid = py::array(py::buffer_info(nullptr, sizeof(int64_t), py::format_descriptor::value, 1, {sizepar}, {sizeof(int64_t)})); + auto parid = py::array(py::buffer_info(nullptr, sizeof(int64_t), py::format_descriptor::value, 1, {sizepar}, {sizeof(int64_t)})); auto bufparid = parid.request(); int64_t *ptrid = (int64_t *)bufparid.ptr; From c727a9b0de1b9e5983a6016e3b4fe9fb8669336e Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 18:33:18 -0500 Subject: [PATCH 15/20] visually inspect outputs... --- tests/test_002-exclusive_jets.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_002-exclusive_jets.py b/tests/test_002-exclusive_jets.py index 52b57ada..fd862304 100644 --- a/tests/test_002-exclusive_jets.py +++ b/tests/test_002-exclusive_jets.py @@ -566,6 +566,9 @@ def test_exclusive_constituents_masking_multi(): array[mask], jetdef ).exclusive_jets_constituent_index(njets=2) output = ak.Array([[[1], [0]], [[0], [1]], [[1], [0]], [[0], [1]]]) + + print(result.layout) + print(output.layout) assert ak.all(result == output) From 98b50ed85f194e54be760d6b99fd7f67a19e5e1a Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 18:47:38 -0500 Subject: [PATCH 16/20] the expected testing output was wrong 0/1 are flipped in index 3 --- tests/test_002-exclusive_jets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_002-exclusive_jets.py b/tests/test_002-exclusive_jets.py index fd862304..6b624b10 100644 --- a/tests/test_002-exclusive_jets.py +++ b/tests/test_002-exclusive_jets.py @@ -565,7 +565,7 @@ def test_exclusive_constituents_masking_multi(): result = fastjet.ClusterSequence( array[mask], jetdef ).exclusive_jets_constituent_index(njets=2) - output = ak.Array([[[1], [0]], [[0], [1]], [[1], [0]], [[0], [1]]]) + output = ak.Array([[[1], [0]], [[0], [1]], [[0], [1]], [[0], [1]]]) print(result.layout) print(output.layout) From 92f939d8797850ea2df8ccb8419565a0489957cf Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 18:52:22 -0500 Subject: [PATCH 17/20] remove prints --- tests/test_002-exclusive_jets.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_002-exclusive_jets.py b/tests/test_002-exclusive_jets.py index 6b624b10..a0f56b58 100644 --- a/tests/test_002-exclusive_jets.py +++ b/tests/test_002-exclusive_jets.py @@ -566,9 +566,6 @@ def test_exclusive_constituents_masking_multi(): array[mask], jetdef ).exclusive_jets_constituent_index(njets=2) output = ak.Array([[[1], [0]], [[0], [1]], [[0], [1]], [[0], [1]]]) - - print(result.layout) - print(output.layout) assert ak.all(result == output) From 69677ac84cbf9e66e55f8b87d7ac56f7ea835d5a Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 18:57:51 -0500 Subject: [PATCH 18/20] better test --- tests/test_002-exclusive_jets.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_002-exclusive_jets.py b/tests/test_002-exclusive_jets.py index a0f56b58..a97c2681 100644 --- a/tests/test_002-exclusive_jets.py +++ b/tests/test_002-exclusive_jets.py @@ -562,11 +562,13 @@ def test_exclusive_constituents_masking_multi(): ) mask = ak.Array([True, True, False, True, True]) jetdef = fastjet.JetDefinition(fastjet.kt_algorithm, 1) - result = fastjet.ClusterSequence( + result_all = fastjet.ClusterSequence( + ak.to_packed(array), jetdef + ).exclusive_jets_constituent_index(njets=2) + result_mask = fastjet.ClusterSequence( array[mask], jetdef ).exclusive_jets_constituent_index(njets=2) - output = ak.Array([[[1], [0]], [[0], [1]], [[0], [1]], [[0], [1]]]) - assert ak.all(result == output) + assert ak.all(result_mask == result_all[mask]) def test_exclusive_ycut(): From 708aa1b5b5ef445a76dd7e70b5912038e1017a46 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 18:58:22 -0500 Subject: [PATCH 19/20] remove unnecessary to_packed --- tests/test_002-exclusive_jets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_002-exclusive_jets.py b/tests/test_002-exclusive_jets.py index a97c2681..59f9e23a 100644 --- a/tests/test_002-exclusive_jets.py +++ b/tests/test_002-exclusive_jets.py @@ -563,7 +563,7 @@ def test_exclusive_constituents_masking_multi(): mask = ak.Array([True, True, False, True, True]) jetdef = fastjet.JetDefinition(fastjet.kt_algorithm, 1) result_all = fastjet.ClusterSequence( - ak.to_packed(array), jetdef + array, jetdef ).exclusive_jets_constituent_index(njets=2) result_mask = fastjet.ClusterSequence( array[mask], jetdef From 803fe00869b9a7a1d86e140b3a3361d8e1488a3a Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Mon, 17 Mar 2025 19:03:24 -0500 Subject: [PATCH 20/20] revert int64 changes, not necessary --- src/_ext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_ext.cpp b/src/_ext.cpp index a5970ad7..2b5625b8 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -373,9 +373,9 @@ PYBIND11_MODULE(_ext, m) { } jk++; - auto parid = py::array(py::buffer_info(nullptr, sizeof(int64_t), py::format_descriptor::value, 1, {sizepar}, {sizeof(int64_t)})); + auto parid = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {sizepar}, {sizeof(int)})); auto bufparid = parid.request(); - int64_t *ptrid = (int64_t *)bufparid.ptr; + int *ptrid = (int *)bufparid.ptr; auto eventoffsets = py::array(py::buffer_info(nullptr, sizeof(int), py::format_descriptor::value, 1, {len+1}, {sizeof(int)})); auto bufeventoffsets = eventoffsets.request();