Skip to content

Implement active jet area calculation with explicit ghosts (fixes #124)#240

Open
HarshitNagpal29 wants to merge 4 commits into
JuliaHEP:mainfrom
HarshitNagpal29:implement-active-jet-areas
Open

Implement active jet area calculation with explicit ghosts (fixes #124)#240
HarshitNagpal29 wants to merge 4 commits into
JuliaHEP:mainfrom
HarshitNagpal29:implement-active-jet-areas

Conversation

@HarshitNagpal29
Copy link
Copy Markdown

Dear @graeme-a-stewart, @m-fila, @mattleblanc,

I have tried implementing an initial solution for #124. This PR adds a first version of active jet area calculation using explicit ghost particles, inspired by the FastJet implementation and written to fit the existing style of this package.

What This Adds

  • GhostedAreaSpec for configuring the ghost grid
  • ClusterSequenceArea as a wrapper around ClusterSequence
  • jet_reconstruct_area(...)
  • Scalar jet area lookup with area(jet, csa)
  • Area 4-vector lookup with area_4vector(jet, csa)
  • Pure ghost identification with is_pure_ghost(jet, csa)
  • total_area and ghost metadata helpers
  • Tests for area propagation, pure-ghost filtering, default area-queryable jets, strategy rejection, and an anti-kt area sanity check

Current Scope

This first implementation supports pp algorithms with explicit ghost active areas. It intentionally does not yet implement passive areas, Voronoi areas, rho estimation, or pile-up subtraction.

For now, jet_reconstruct_area only supports RecoStrategy.N2Plain.

Note About N2Tiled

While adding tests for jet areas, I hit an existing issue with the N2Tiled strategy when used with ghosted areas:

BoundsError: attempt to access 6×15 Matrix{TiledJet} at index [94]

My current understanding is that the tiling matrix is allocated as (n_tiles_eta, n_tiles_phi), but tile_index can allow iphi == n_tiles_phi, which can produce a linear index beyond the allocated matrix size. In my case the maximum valid index should be 90, but it reached 94.

Because of this, the area implementation currently rejects tiled strategies and uses only N2Plain.

Testing

I added tests for the new area functionality. On my machine, the full test suite passes

Docs

I have not updated the docs yet, because I thought it would be better to get feedback on the API and implementation approach first.

AI usage

AI was used to help understand parts of the FastJet implementation and to generate some of the tests. I reviewed the generated material and take responsibility for the code and tests included in this PR.

Comment thread Project.toml
@m-fila m-fila self-requested a review April 28, 2026 15:24
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.23%. Comparing base (3e96272) to head (9238916).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #240      +/-   ##
==========================================
+ Coverage   82.67%   84.23%   +1.55%     
==========================================
  Files          21       22       +1     
  Lines        1403     1541     +138     
==========================================
+ Hits         1160     1298     +138     
  Misses        243      243              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/JetAreas.jl

has_dangerous_particles = false
if max_ghost_pt2 > 0.0
danger_ratio = eps(Float64)^2
Copy link
Copy Markdown
Author

@HarshitNagpal29 HarshitNagpal29 Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, can you please guide on this its little bit confusing for me that is it fine or overaggressive?

Copy link
Copy Markdown
Member

@m-fila m-fila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments from me, I didn't check the "algorithmic" part yet

Comment thread src/JetAreas.jl
n_ghosts::Int
end

function _ghost_grid_spec(spec::GhostedAreaSpec)::GhostGridSpec
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function _ghost_grid_spec(spec::GhostedAreaSpec)::GhostGridSpec
function _ghost_grid_spec(spec::GhostedAreaSpec)

Casting to GhostGridSpec isn't really needed here

Also, would it make sense to make this function a constructor of GhostGridSpec?

Comment thread src/JetAreas.jl
Comment on lines +52 to +58
function _copy_as_pseudojet(jet; cluster_hist_index::Int)
PseudoJet(px(jet),
py(jet),
pz(jet),
E(jet);
cluster_hist_index = cluster_hist_index,)
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a generic constructor for PseudoJet

function PseudoJet(jet::Any; cluster_hist_index::Int = 0)

I think there is no need to introduce a new function, the PseudoJet already has a constructor accepting any jet

Comment thread src/JetAreas.jl
Comment on lines +228 to +233
if algorithm ∉ (JetAlgorithm.Kt,
JetAlgorithm.CA,
JetAlgorithm.AntiKt,
JetAlgorithm.GenKt)
throw(ArgumentError("jet_reconstruct_area currently supports pp algorithms only"))
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if algorithm (JetAlgorithm.Kt,
JetAlgorithm.CA,
JetAlgorithm.AntiKt,
JetAlgorithm.GenKt)
throw(ArgumentError("jet_reconstruct_area currently supports pp algorithms only"))
end
if !is_pp(algorithm)
throw(ArgumentError("jet_reconstruct_area currently supports pp algorithms only"))
end

We have a function checking if algorithm is pp

Comment thread src/JetAreas.jl
jets = filter(jet -> !is_pure_ghost(jet, csa), jets)
end

return [_convert_area_result_jet(jet, T) for jet in jets]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could would be nice to avoid allocating a new array if T is already PseudoJet and there is nothing to do

Comment thread src/JetAreas.jl
Comment on lines +76 to +78
function _make_area_ghosts(spec::GhostedAreaSpec)
grid = _ghost_grid_spec(spec)
rng = isnothing(spec.seed) ? Random.default_rng() : Random.MersenneTwister(spec.seed)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More Julia-idiomatic way would be to pass an rng::AbstractRNG to a function rather than create it inside

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants