diff --git a/.gitmodules b/.gitmodules index e4cffca2..6298a925 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "pybind11"] path = pybind11 url = https://github.com/pybind/pybind11.git +[submodule "fastjet-contrib"] + path = fastjet-contrib + url = https://github.com/cms-externals/fastjet-contrib.git diff --git a/MANIFEST.in b/MANIFEST.in index f296404b..472ba4cf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ graft src graft tests graft fastjet-core +graft fastjet-contrib graft pybind11 global-exclude .git .gitmodules include LICENSE README.md pyproject.toml setup.py setup.cfg patch_fastjet_i.txt patch_clustersequence.txt diff --git a/fastjet-contrib b/fastjet-contrib new file mode 160000 index 00000000..03f2fb3c --- /dev/null +++ b/fastjet-contrib @@ -0,0 +1 @@ +Subproject commit 03f2fb3c7e26248f5cab3d6c52fab3e112342113 diff --git a/setup.py b/setup.py index 7e5aa227..bd7fd993 100644 --- a/setup.py +++ b/setup.py @@ -27,10 +27,18 @@ DIR = pathlib.Path(__file__).parent.resolve() FASTJET = DIR / "fastjet-core" +FASTJET_CONTRIB = DIR / "fastjet-contrib" PYTHON = DIR / "src/fastjet" OUTPUT = PYTHON / "_fastjet_core" -LIBS = ["fastjet", "fastjettools", "siscone", "siscone_spherical", "fastjetplugins"] +LIBS = [ + "fastjet", + "fastjettools", + "siscone", + "siscone_spherical", + "fastjetplugins", + "fastjetcontribfragile", +] def get_version() -> str: @@ -97,6 +105,26 @@ def build_extensions(self): subprocess.run(["make", "-j"], cwd=FASTJET, env=env, check=True) subprocess.run(["make", "install"], cwd=FASTJET, env=env, check=True) + subprocess.run( + ["./configure", f"--fastjet-config={FASTJET}/fastjet-config"], + cwd=FASTJET_CONTRIB, + env=env, + check=True, + ) + subprocess.run(["make", "-j"], cwd=FASTJET_CONTRIB, env=env, check=True) + subprocess.run( + ["make", "install"], cwd=FASTJET_CONTRIB, env=env, check=True + ) + subprocess.run( + ["make", "fragile-shared"], cwd=FASTJET_CONTRIB, env=env, check=True + ) + subprocess.run( + ["make", "fragile-shared-install"], + cwd=FASTJET_CONTRIB, + env=env, + check=True, + ) + setuptools.command.build_ext.build_ext.build_extensions(self) diff --git a/src/_ext.cpp b/src/_ext.cpp index 97bd9c22..12c22e42 100644 --- a/src/_ext.cpp +++ b/src/_ext.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -1590,6 +1591,7 @@ PYBIND11_MODULE(_ext, m) { } jk++; + auto lund_generator = fastjet::contrib::LundGenerator(); std::vector Delta_vec; std::vector kt_vec; @@ -1617,17 +1619,11 @@ PYBIND11_MODULE(_ext, m) { auto prev = ptrjetoffsets[jetidx-1]; for (unsigned int j = 0; j < jets.size(); j++){ - // adapted from https://github.com/fdreyer/LundPlane/blob/master/LundGenerator.cc - PseudoJet pair, j1, j2; - pair = jets[j]; - int splittings = 0; - while (pair.has_parents(j1, j2)) { - if (j1.pt2() < j2.pt2()) std::swap(j1,j2); - double Delta = j1.delta_R(j2); - Delta_vec.push_back(Delta); - kt_vec.push_back(j2.pt() * Delta); - pair = j1; - splittings++; + auto lund_result = lund_generator.result(jets[j]); + auto splittings = lund_result.size(); + for (unsigned int k = 0; k < splittings; k++){ + Delta_vec.push_back(lund_result[k].Delta()); + kt_vec.push_back(lund_result[k].kt()); } ptrjetoffsets[jetidx] = splittings + prev;