Skip to content

Commit b2b472f

Browse files
kawahoKa Wa Hopre-commit-ci[bot]matthewfeickertlgray
authored
feat: adding groomed jet radius and momentum balance variables for softdrop groomed jet (#312)
* adding groomed jet radius and momentum balance for softdrop groomed jet * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * adding to test_exclusive_jets_softdrop_grooming test * separating problematic call * clean up C++ a little * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use make_shared instead * ensure we have a valid softdrop result before asking for info * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use numeric_limits * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * turn on verbosity * try dangerous workaround * remove verbosity flag setting --------- Co-authored-by: Ka Wa Ho <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Matthew Feickert <[email protected]> Co-authored-by: Lindsey Gray <[email protected]>
1 parent 25326da commit b2b472f

File tree

6 files changed

+94
-8
lines changed

6 files changed

+94
-8
lines changed

src/_ext.cpp

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// https://github.com/scikit-hep/fastjet/blob/main/LICENSE
33

44
#include <algorithm>
5+
#include <cmath>
56
#include <cstdlib>
67
#include <iostream>
8+
#include <limits>
79
#include <unordered_map>
810
#include <vector>
911

@@ -1655,6 +1657,8 @@ PYBIND11_MODULE(_ext, m) {
16551657
std::vector<double> jet_groomed_m;
16561658
std::vector<double> jet_groomed_E;
16571659
std::vector<double> jet_groomed_pz;
1660+
std::vector<double> jet_groomed_delta_R;
1661+
std::vector<double> jet_groomed_symmetry;
16581662

16591663
fastjet::contrib::RecursiveSymmetryCutBase::SymmetryMeasure sym_meas = fastjet::contrib::RecursiveSymmetryCutBase::SymmetryMeasure::scalar_z;
16601664
if (symmetry_measure == "scalar_z") {
@@ -1687,19 +1691,39 @@ PYBIND11_MODULE(_ext, m) {
16871691
rec_choice = fastjet::contrib::RecursiveSymmetryCutBase::RecursionChoice::larger_E;
16881692
}
16891693

1690-
fastjet::contrib::SoftDrop* sd = new fastjet::contrib::SoftDrop(beta, symmetry_cut, sym_meas, R0, mu_cut, rec_choice/*, subtractor*/);
1694+
auto sd = std::make_shared<fastjet::contrib::SoftDrop>(beta, symmetry_cut, sym_meas, R0, mu_cut, rec_choice/*, subtractor*/);
16911695

16921696
for (unsigned int i = 0; i < css.size(); i++){ // iterate through events
16931697
auto jets = css[i]->exclusive_jets(n_jets);
16941698
for (unsigned int j = 0; j < jets.size(); j++){
16951699
auto soft = sd->result(jets[j]);
1700+
if( soft != 0 ) {
1701+
jet_groomed_pt.push_back(soft.pt());
1702+
jet_groomed_eta.push_back(soft.eta());
1703+
jet_groomed_phi.push_back(soft.phi());
1704+
jet_groomed_m.push_back(soft.m());
1705+
jet_groomed_E.push_back(soft.E());
1706+
jet_groomed_pz.push_back(soft.pz());
1707+
1708+
// horrificaly dangerous hack around the fact that
1709+
// fastjet's custom sharedptr doesn't obey const
1710+
// correctness and this makes llvm-gcc very sad
1711+
fastjet::PseudoJetStructureBase* structure_ptr = soft.structure_non_const_ptr();
1712+
fastjet::contrib::SoftDrop::StructureType* as_sd = (fastjet::contrib::SoftDrop::StructureType*)structure_ptr;
1713+
jet_groomed_delta_R.push_back(as_sd->delta_R());
1714+
jet_groomed_symmetry.push_back(as_sd->symmetry());
1715+
} else {
1716+
jet_groomed_pt.push_back(std::numeric_limits<double>::quiet_NaN());
1717+
jet_groomed_eta.push_back(std::numeric_limits<double>::quiet_NaN());
1718+
jet_groomed_phi.push_back(std::numeric_limits<double>::quiet_NaN());
1719+
jet_groomed_m.push_back(std::numeric_limits<double>::quiet_NaN());
1720+
jet_groomed_E.push_back(std::numeric_limits<double>::quiet_NaN());
1721+
jet_groomed_pz.push_back(std::numeric_limits<double>::quiet_NaN());
1722+
jet_groomed_delta_R.push_back(std::numeric_limits<double>::quiet_NaN());
1723+
jet_groomed_symmetry.push_back(std::numeric_limits<double>::quiet_NaN());
1724+
}
1725+
16961726
nconstituents.push_back(soft.constituents().size());
1697-
jet_groomed_pt.push_back(soft.pt());
1698-
jet_groomed_eta.push_back(soft.eta());
1699-
jet_groomed_phi.push_back(soft.phi());
1700-
jet_groomed_m.push_back(soft.m());
1701-
jet_groomed_E.push_back(soft.E());
1702-
jet_groomed_pz.push_back(soft.pz());
17031727
for (unsigned int k = 0; k < soft.constituents().size(); k++){
17041728
consts_groomed_px.push_back(soft.constituents()[k].px());
17051729
consts_groomed_py.push_back(soft.constituents()[k].py());
@@ -1720,6 +1744,8 @@ PYBIND11_MODULE(_ext, m) {
17201744
auto jet_m = py::array(jet_groomed_m.size(), jet_groomed_m.data());
17211745
auto jet_E = py::array(jet_groomed_E.size(), jet_groomed_E.data());
17221746
auto jet_pz = py::array(jet_groomed_pz.size(), jet_groomed_pz.data());
1747+
auto jet_delta_R = py::array(jet_groomed_delta_R.size(), jet_groomed_delta_R.data());
1748+
auto jet_symmetry = py::array(jet_groomed_symmetry.size(), jet_groomed_symmetry.data());
17231749

17241750
return std::make_tuple(
17251751
consts_px,
@@ -1732,7 +1758,9 @@ PYBIND11_MODULE(_ext, m) {
17321758
jet_phi,
17331759
jet_m,
17341760
jet_E,
1735-
jet_pz
1761+
jet_pz,
1762+
jet_delta_R,
1763+
jet_symmetry
17361764
);
17371765
}, R"pbdoc(
17381766
Performs softdrop pruning on jets.

src/fastjet/_generalevent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ def exclusive_jets_softdrop_grooming(
678678
jetmass = ak.Array(ak.contents.NumpyArray(np_results[8]))
679679
jetE = ak.Array(ak.contents.NumpyArray(np_results[9]))
680680
jetpz = ak.Array(ak.contents.NumpyArray(np_results[10]))
681+
jetdeltaR = ak.Array(ak.contents.NumpyArray(np_results[11]))
682+
jetsymmetry = ak.Array(ak.contents.NumpyArray(np_results[12]))
681683

682684
self._out.append(
683685
ak.zip(
@@ -691,6 +693,8 @@ def exclusive_jets_softdrop_grooming(
691693
"phisoftdrop": jetphi,
692694
"Esoftdrop": jetE,
693695
"pzsoftdrop": jetpz,
696+
"deltaRsoftdrop": jetdeltaR,
697+
"symmetrysoftdrop": jetsymmetry,
694698
},
695699
depth_limit=1,
696700
behavior=self.data.behavior,

src/fastjet/_multievent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ def exclusive_jets_softdrop_grooming(
273273
jetmass = ak.Array(ak.contents.NumpyArray(np_results[8]))
274274
jetE = ak.Array(ak.contents.NumpyArray(np_results[9]))
275275
jetpz = ak.Array(ak.contents.NumpyArray(np_results[10]))
276+
jetdeltaR = ak.Array(ak.contents.NumpyArray(np_results[11]))
277+
jetsymmetry = ak.Array(ak.contents.NumpyArray(np_results[12]))
276278

277279
out = ak.zip(
278280
{
@@ -285,6 +287,8 @@ def exclusive_jets_softdrop_grooming(
285287
"phisoftdrop": jetphi,
286288
"Esoftdrop": jetE,
287289
"pzsoftdrop": jetpz,
290+
"deltaRsoftdrop": jetdeltaR,
291+
"symmetrysoftdrop": jetsymmetry,
288292
},
289293
depth_limit=1,
290294
behavior=self.data.behavior,

src/fastjet/_singleevent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ def exclusive_jets_softdrop_grooming(
251251
jetmass = ak.Array(ak.contents.NumpyArray(np_results[8]))
252252
jetE = ak.Array(ak.contents.NumpyArray(np_results[9]))
253253
jetpz = ak.Array(ak.contents.NumpyArray(np_results[10]))
254+
jetdeltaR = ak.Array(ak.contents.NumpyArray(np_results[11]))
255+
jetsymmetry = ak.Array(ak.contents.NumpyArray(np_results[12]))
254256

255257
out = ak.zip(
256258
{
@@ -263,6 +265,8 @@ def exclusive_jets_softdrop_grooming(
263265
"phisoftdrop": jetphi,
264266
"Esoftdrop": jetE,
265267
"pzsoftdrop": jetpz,
268+
"deltaRsoftdrop": jetdeltaR,
269+
"symmetrysoftdrop": jetsymmetry,
266270
},
267271
depth_limit=1,
268272
)

tests/test_002-exclusive_jets.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ def test_exclusive_jets_softdrop_grooming():
234234
{"px": 32.45, "py": 63.21, "pz": 543.14, "E": 599.56},
235235
],
236236
"msoftdrop": 488.2395243115817,
237+
"deltaRsoftdrop": 0.009873899817126915,
238+
"symmetrysoftdrop": 0.49727522889673303,
237239
"ptsoftdrop": 142.88274528437645,
238240
"etasoftdrop": 2.726117171791057,
239241
"phisoftdrop": 1.1012644074821902,
@@ -275,6 +277,18 @@ def test_exclusive_jets_softdrop_grooming():
275277
rtol=1e-12,
276278
atol=0,
277279
),
280+
ak.isclose(
281+
ak.Array([softdrop_output.deltaRsoftdrop]),
282+
ak.Array([softdrop.deltaRsoftdrop]),
283+
rtol=1e-12,
284+
atol=0,
285+
),
286+
ak.isclose(
287+
ak.Array([softdrop_output.symmetrysoftdrop]),
288+
ak.Array([softdrop.symmetrysoftdrop]),
289+
rtol=1e-12,
290+
atol=0,
291+
),
278292
ak.isclose(
279293
ak.Array([softdrop_output.ptsoftdrop]),
280294
ak.Array([softdrop.ptsoftdrop]),
@@ -352,6 +366,8 @@ def test_exclusive_jets_softdrop_grooming_multi():
352366
],
353367
),
354368
"msoftdrop": ak.Array([488.2395243115817, 488.2395243115817]),
369+
"deltaRsoftdrop": ak.Array([0.009873899817126915, 0.009873899817126915]),
370+
"symmetrysoftdrop": ak.Array([0.49727522889673303, 0.49727522889673303]),
355371
"ptsoftdrop": ak.Array([142.88274528437645, 142.88274528437645]),
356372
"etasoftdrop": ak.Array([2.726117171791057, 2.726117171791057]),
357373
"phisoftdrop": ak.Array([1.1012644074821902, 1.1012644074821902]),
@@ -393,6 +409,18 @@ def test_exclusive_jets_softdrop_grooming_multi():
393409
rtol=1e-12,
394410
atol=0,
395411
),
412+
ak.isclose(
413+
ak.Array([softdrop_output.deltaRsoftdrop]),
414+
ak.Array([softdrop.deltaRsoftdrop]),
415+
rtol=1e-12,
416+
atol=0,
417+
),
418+
ak.isclose(
419+
ak.Array([softdrop_output.symmetrysoftdrop]),
420+
ak.Array([softdrop.symmetrysoftdrop]),
421+
rtol=1e-12,
422+
atol=0,
423+
),
396424
ak.isclose(
397425
ak.Array([softdrop_output.ptsoftdrop]),
398426
ak.Array([softdrop.ptsoftdrop]),

tests/test_008-dask.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ def dask_multi_test_exclusive_jets_softdrop_grooming():
179179
{"px": 32.45, "py": 63.21, "pz": 543.14, "E": 599.56},
180180
],
181181
"msoftdrop": ak.Array([488.2395243115817, 488.2395243115817]),
182+
"deltaRsoftdrop": ak.Array(
183+
[0.009873899817126915, 0.009873899817126915]
184+
),
185+
"symmetrysoftdrop": ak.Array(
186+
[0.49727522889673303, 0.49727522889673303]
187+
),
182188
"ptsoftdrop": ak.Array([142.88274528437645, 142.88274528437645]),
183189
"etasoftdrop": ak.Array([2.726117171791057, 2.726117171791057]),
184190
"phisoftdrop": ak.Array([1.1012644074821902, 1.1012644074821902]),
@@ -220,6 +226,18 @@ def dask_multi_test_exclusive_jets_softdrop_grooming():
220226
rtol=1e-12,
221227
atol=0,
222228
),
229+
ak.isclose(
230+
ak.Array([softdrop_output.deltaRsoftdrop]),
231+
ak.Array([softdrop.deltaRsoftdrop]),
232+
rtol=1e-12,
233+
atol=0,
234+
),
235+
ak.isclose(
236+
ak.Array([softdrop_output.symmetrysoftdrop]),
237+
ak.Array([softdrop.symmetrysoftdrop]),
238+
rtol=1e-12,
239+
atol=0,
240+
),
223241
ak.isclose(
224242
ak.Array([softdrop_output.ptsoftdrop]),
225243
ak.Array([softdrop.ptsoftdrop]),

0 commit comments

Comments
 (0)