Skip to content

Commit

Permalink
fj-contrib (#143)
Browse files Browse the repository at this point in the history
* fj-contrib

* add fj-contrib to MANIFEST

* use lundplane

* move out of loop

* try building/linking fastjetcontribfragile

Co-authored-by: Lindsey Gray <lindsey.gray@gmail.com>
  • Loading branch information
jmduarte and lgray committed Nov 11, 2022
1 parent d87d56b commit f8e5e57
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions fastjet-contrib
Submodule fastjet-contrib added at 03f2fb
30 changes: 29 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)


Expand Down
18 changes: 7 additions & 11 deletions src/_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <fastjet/GhostedAreaSpec.hh>
#include <fastjet/JetDefinition.hh>
#include <fastjet/PseudoJet.hh>
#include <fastjet/contrib/LundGenerator.hh>

#include <pybind11/numpy.h>
#include <pybind11/operators.h>
Expand Down Expand Up @@ -1590,6 +1591,7 @@ PYBIND11_MODULE(_ext, m) {
}
jk++;

auto lund_generator = fastjet::contrib::LundGenerator();
std::vector<double> Delta_vec;
std::vector<double> kt_vec;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f8e5e57

Please sign in to comment.