Skip to content

Commit ef30962

Browse files
committed
add recombination schemes to C-bindings
1 parent 6e2578d commit ef30962

File tree

6 files changed

+69
-32
lines changed

6 files changed

+69
-32
lines changed

compile/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ int main(int argc, char *argv[]) {
6161
jetreconstruction_JetAlgorithm algorithm = JETRECONSTRUCTION_JETALGORITHM_CA;
6262
double R = 3.0;
6363
jetreconstruction_RecoStrategy strategy = JETRECONSTRUCTION_RECOSTRATEGY_BEST;
64+
jetreconstruction_RecombinationScheme recombination = JETRECONCSTRUCTION_RECOMBINATIONSCHEME_ESCHEME;
6465
6566
jetreconstruction_ClusterSequence cluster_seq;
66-
int ret = jetreconstruction_jet_reconstruct(particles, len, algorithm, R, strategy,
67-
&cluster_seq);
68-
if (ret != JETRECONSTRUCTION_STATUSCODE_OK){
67+
jetreconstruction_StatusCode sc = jetreconstruction_jet_reconstruct(particles, len, algorithm, R,
68+
strategy, recombination, &cluster_seq);
69+
if (sc != JETRECONSTRUCTION_STATUSCODE_OK){
6970
/*An error occurred check the value or stderr for more information*/
7071
return 1;
7172
}

compile/downstream/jetreconstruction_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void printJetsResult(const jetreconstruction_JetsResult *results) {
5454

5555
int main(int argc, char *argv[]) {
5656
clock_t start_time = clock();
57-
int sc = 0;
57+
jetreconstruction_StatusCode sc = 0;
5858
#ifdef JETRECONSTRUCTION_COMPILER_PACKAGECOMPILER
5959
init_julia(0, NULL);
6060
#endif
@@ -68,10 +68,12 @@ int main(int argc, char *argv[]) {
6868
jetreconstruction_JetAlgorithm algorithm = JETRECONSTRUCTION_JETALGORITHM_CA;
6969
double R = 3.0;
7070
jetreconstruction_RecoStrategy strategy = JETRECONSTRUCTION_RECOSTRATEGY_BEST;
71+
jetreconstruction_RecombinationScheme recombination =
72+
JETRECONCSTRUCTION_RECOMBINATIONSCHEME_ESCHEME;
7173

7274
jetreconstruction_ClusterSequence cluster_seq;
7375
sc = jetreconstruction_jet_reconstruct(particles, len, algorithm, R, strategy,
74-
&cluster_seq);
76+
recombination, &cluster_seq);
7577
assert(sc == JETRECONSTRUCTION_STATUSCODE_OK);
7678

7779
printClusterSequence(&cluster_seq);

compile/include/JetReconstruction.h.in

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ typedef enum {
103103
JETRECONSTRUCTION_RECOSTRATEGY_N2TILTED = 2 /**< The tiled N2 strategy. */
104104
} jetreconstruction_RecoStrategy;
105105

106+
/**
107+
* @enum jetreconstruction_RecombinationScheme
108+
* @brief Enumeration representing the different recombination schemes used in
109+
* jet reconstruction.
110+
*/
111+
typedef enum {
112+
JETRECONCSTRUCTION_RECOMBINATIONSCHEME_ESCHEME = 0,
113+
JETRECONCSTRUCTION_RECOMBINATIONSCHEME_PTSCHEME = 1,
114+
JETRECONCSTRUCTION_RECOMBINATIONSCHEME_PT2SCHEME = 2,
115+
} jetreconstruction_RecombinationScheme;
116+
106117
/**
107118
* @struct jetreconstruction_PseudoJet
108119
* @brief A struct representing a pseudojet, a four-momentum object used in
@@ -138,7 +149,8 @@ typedef struct {
138149
*/
139150
jetreconstruction_StatusCode
140151
jetreconstruction_PseudoJet_init(jetreconstruction_PseudoJet *ptr, double px,
141-
double py, double pz, double E, long cluter_hist_index);
152+
double py, double pz, double E,
153+
long cluter_hist_index);
142154

143155
/**
144156
* @struct jetreconstruction_HistoryElement
@@ -235,6 +247,8 @@ static inline void jetreconstruction_ClusterSequence_free_members(
235247
* @param[in] algorithm The algorithm to use for jet reconstruction.
236248
* @param[in] R The jet radius parameter.
237249
* @param[in] strategy The jet reconstruction strategy to use.
250+
* @param[in] recombination_scheme The recombination scheme used for combining
251+
* particles.
238252
* @param[out] result A pointer to which a cluster sequence containing the
239253
* reconstructed jets and the merging history will be stored.
240254
* @return An integer status code indicating the success or failure. See common
@@ -244,6 +258,7 @@ jetreconstruction_StatusCode jetreconstruction_jet_reconstruct(
244258
const jetreconstruction_PseudoJet *particles, size_t particles_length,
245259
jetreconstruction_JetAlgorithm algorithm, double R,
246260
jetreconstruction_RecoStrategy strategy,
261+
jetreconstruction_RecombinationScheme recombination_scheme,
247262
jetreconstruction_ClusterSequence *result);
248263

249264
/**

compile/precompile_execution.jl

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dummy code to call and cache compilation of all C-bindings
22
# The numeric values don't make sense and are used only to select correct dispatch
33

4-
using JetReconstruction: PseudoJet, RecoStrategy, JetAlgorithm
4+
using JetReconstruction: PseudoJet, RecoStrategy, JetAlgorithm, RecombinationScheme
55
using JetReconstruction.C_JetReconstruction: jetreconstruction_PseudoJet_init,
66
C_ClusterSequence,
77
jetreconstruction_ClusterSequence_free_members_,
@@ -33,27 +33,33 @@ assert_ok(jetreconstruction_PseudoJet_init(jets_ptr, 0.0, 1.0, 2.0, 3.0, 1))
3333
assert_ok(jetreconstruction_PseudoJet_init(jets_ptr + sizeof(PseudoJet), 1.0, 2.0, 3.0,
3434
4.0, 2))
3535

36-
for algorithm in [JetAlgorithm.AntiKt, JetAlgorithm.CA, JetAlgorithm.Kt]
37-
for strategy in [RecoStrategy.N2Plain, RecoStrategy.N2Tiled, RecoStrategy.Best]
38-
assert_ok(jetreconstruction_jet_reconstruct(jets_ptr, jets_len, algorithm, R,
39-
strategy,
40-
clustersequence_ptr))
36+
for algorithm in [JetAlgorithm.AntiKt, JetAlgorithm.CA, JetAlgorithm.Kt],
37+
strategy in [RecoStrategy.N2Plain, RecoStrategy.N2Tiled, RecoStrategy.Best],
38+
recombination in [
39+
RecombinationScheme.EScheme,
40+
RecombinationScheme.PtScheme,
41+
RecombinationScheme.Pt2Scheme
42+
]
4143

42-
assert_ok(jetreconstruction_inclusive_jets(clustersequence_ptr, 0.0, results_ptr))
43-
jetreconstruction_JetsResult_free_members_(results_ptr)
44+
assert_ok(jetreconstruction_jet_reconstruct(jets_ptr, jets_len, algorithm, R,
45+
strategy, recombination,
46+
clustersequence_ptr))
47+
48+
assert_ok(jetreconstruction_inclusive_jets(clustersequence_ptr, 0.0,
49+
results_ptr))
50+
jetreconstruction_JetsResult_free_members_(results_ptr)
4451

45-
if algorithm != JetAlgorithm.AntiKt
46-
assert_ok(jetreconstruction_exclusive_jets_njets(clustersequence_ptr,
47-
Csize_t(2),
48-
results_ptr))
49-
jetreconstruction_JetsResult_free_members_(results_ptr)
52+
if algorithm != JetAlgorithm.AntiKt
53+
assert_ok(jetreconstruction_exclusive_jets_njets(clustersequence_ptr,
54+
Csize_t(2),
55+
results_ptr))
56+
jetreconstruction_JetsResult_free_members_(results_ptr)
5057

51-
assert_ok(jetreconstruction_exclusive_jets_dcut(clustersequence_ptr, 1.0,
52-
results_ptr))
53-
jetreconstruction_JetsResult_free_members_(results_ptr)
58+
assert_ok(jetreconstruction_exclusive_jets_dcut(clustersequence_ptr, 1.0,
59+
results_ptr))
60+
jetreconstruction_JetsResult_free_members_(results_ptr)
5461

55-
jetreconstruction_ClusterSequence_free_members_(clustersequence_ptr)
56-
end
62+
jetreconstruction_ClusterSequence_free_members_(clustersequence_ptr)
5763
end
5864
end
5965
Libc.free(jets_ptr)

src/C_JetReconstruction/C_JetReconstruction.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ Minimal C bindings for JetReconstruction.jl
33
"""
44
module C_JetReconstruction
55

6-
using ..JetReconstruction: JetAlgorithm, RecoStrategy, PseudoJet, ClusterSequence,
7-
HistoryElement, jet_reconstruct,
8-
exclusive_jets, inclusive_jets
6+
using ..JetReconstruction: JetAlgorithm, RecoStrategy,
7+
RecombinationScheme, RecombinationMethods,
8+
PseudoJet, ClusterSequence, HistoryElement,
9+
jet_reconstruct, exclusive_jets, inclusive_jets
910
using EnumX
1011

1112
"""
@@ -225,6 +226,7 @@ end
225226
algorithm::JetAlgorithm.Algorithm,
226227
R::Cdouble,
227228
strategy::RecoStrategy.Strategy,
229+
recombination_scheme::RecombinationScheme.Recombine,
228230
result::Ptr{C_ClusterSequence{U}})::Cint where {T, U}
229231
230232
Internal helper functions for calling `jet_reconstruct` with C-compatible data-structers.
@@ -233,8 +235,9 @@ Internal helper functions for calling `jet_reconstruct` with C-compatible data-s
233235
- `particles::Ptr{T}`: Pointer to an array of pseudojet objects used for jet reconstruction.
234236
- `particles_length::Csize_t`: The length of `particles`` array.
235237
- `algorithm::JetAlgorithm.Algorithm`: The algorithm to use for jet reconstruction.
236-
- `R::Cdouble`: The jet radius parameter..
238+
- `R::Cdouble`: The jet radius parameter.
237239
- `strategy::RecoStrategy.Strategy`: The jet reconstruction strategy to use.
240+
- `recombination_scheme::RecombinationScheme.Recombine`: The recombination scheme used for combining particles.
238241
- `result::Ptr{C_ClusterSequence{U}}`: A pointer to which a cluster sequence containing the reconstructed jets and the merging history will be stored.
239242
240243
# Returns
@@ -248,11 +251,13 @@ function c_jet_reconstruct(particles::Ptr{T},
248251
algorithm::JetAlgorithm.Algorithm,
249252
R::Cdouble,
250253
strategy::RecoStrategy.Strategy,
254+
recombination_scheme::RecombinationScheme.Recombine,
251255
result::Ptr{C_ClusterSequence{U}}) where {T, U}
252256
try
253257
particles_v = unsafe_wrap(Vector{T}, particles, particles_length)
254258
clusterseq = jet_reconstruct(particles_v; p = nothing, algorithm = algorithm, R = R,
255-
strategy = strategy)
259+
strategy = strategy,
260+
RecombinationMethods[recombination_scheme]...)
256261
c_clusterseq = C_ClusterSequence{U}(clusterseq)
257262
unsafe_store!(result, c_clusterseq)
258263
catch e
@@ -267,6 +272,7 @@ end
267272
algorithm::JetAlgorithm.Algorithm,
268273
R::Cdouble,
269274
strategy::RecoStrategy.Strategy,
275+
recombination_scheme::RecombinationScheme.Recombine,
270276
result::Ptr{C_ClusterSequence{PseudoJet}})::Cint
271277
272278
C-binding for `jet_reconstruct`.
@@ -277,6 +283,7 @@ C-binding for `jet_reconstruct`.
277283
- `algorithm::JetAlgorithm.Algorithm`: The algorithm to use for jet reconstruction.
278284
- `R::Cdouble`: The jet radius parameter..
279285
- `strategy::RecoStrategy.Strategy`: The jet reconstruction strategy to use.
286+
- `recombination_scheme::RecombinationScheme.Recombine`: The recombination scheme used for combining particles.
280287
- `result::Ptr{C_ClusterSequence{PseudoJet}}`: A pointer to which a cluster sequence containing the reconstructed jets and the merging history will be stored.
281288
282289
# Returns
@@ -290,8 +297,10 @@ Base.@ccallable function jetreconstruction_jet_reconstruct(particles::Ptr{Pseudo
290297
algorithm::JetAlgorithm.Algorithm,
291298
R::Cdouble,
292299
strategy::RecoStrategy.Strategy,
300+
recombination_scheme::RecombinationScheme.Recombine,
293301
result::Ptr{C_ClusterSequence{PseudoJet}})::Cint
294-
return c_jet_reconstruct(particles, particles_length, algorithm, R, strategy, result)
302+
return c_jet_reconstruct(particles, particles_length, algorithm, R, strategy,
303+
recombination_scheme, result)
295304
end
296305

297306
"""

test/test-c-interface.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function test_pseudojet()
4747
struct_approx_equal(jet, c_jet)
4848
end
4949

50-
function test_jet_reconstruct(filename; algorithm, R, strategy, power = nothing,
50+
function test_jet_reconstruct(filename; algorithm, R, strategy, recombine, power = nothing,
5151
T = PseudoJet)
5252
@testset "C-interface jet reconstruct" begin
5353
events = JetReconstruction.read_final_state_particles(filename)
@@ -64,13 +64,15 @@ function test_jet_reconstruct(filename; algorithm, R, strategy, power = nothing,
6464
algorithm,
6565
R,
6666
strategy,
67+
recombine,
6768
cluster_seq_ptr)
6869
@test C_JetReconstruction.StatusCode.T(ret) == C_JetReconstruction.StatusCode.OK
6970

7071
cluster_seq = JetReconstruction.jet_reconstruct(event; R = R,
7172
p = power,
7273
algorithm = algorithm,
73-
strategy = strategy)
74+
strategy = strategy,
75+
RecombinationMethods[recombine]...)
7476
compare_results(cluster_seq_ptr, cluster_seq)
7577
@inbounds results[ievent] = cluster_seq
7678
@inbounds c_results[ievent] = cluster_seq_ptr
@@ -136,6 +138,7 @@ end
136138

137139
@testset "C-interface JetReconstruction pp" begin
138140
test_cone_size = 0.4
141+
test_recombine_scheme = RecombinationScheme.EScheme
139142

140143
test_pseudojet()
141144

@@ -147,6 +150,7 @@ end
147150
cluster_seq_ptrs, cluster_seqs = test_jet_reconstruct(events_file_pp;
148151
algorithm = alg,
149152
strategy = stg,
153+
recombine = test_recombine_scheme,
150154
R = test_cone_size,
151155
power = power)
152156
test_inclusive_jets(cluster_seq_ptrs, cluster_seqs; ptmin = 5.0)

0 commit comments

Comments
 (0)