|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2022-2024 JetReconstruction.jl authors, CERN |
| 3 | + * SPDX-License-Identifier: MIT |
| 4 | + */ |
| 5 | + |
| 6 | +#include <stddef.h> |
| 7 | + |
| 8 | +/* |
| 9 | +Enumeration representing different jet algorithms used in |
| 10 | +the JetReconstruction module. |
| 11 | +*/ |
| 12 | +typedef enum { |
| 13 | + JETRECONSTRUCTION_JETALGORITHM_ANTIKT = 0, /* The Anti-Kt algorithm. */ |
| 14 | + JETRECONSTRUCTION_JETALGORITHM_CA = 1, /* The Cambridge/Aachen algorithm. */ |
| 15 | + JETRECONSTRUCTION_JETALGORITHM_KT = 2, /* The Inclusive-Kt algorithm. */ |
| 16 | + JETRECONSTRUCTION_JETALGORITHM_GENKT = |
| 17 | + 3, /* The Generalised Kt algorithm (with arbitrary power). */ |
| 18 | + JETRECONSTRUCTION_JETALGORITHM_EEKT = |
| 19 | + 4, /* The Generalised e+e- kt algorithm. */ |
| 20 | + JETRECONSTRUCTION_JETALGORITHM_DURHAM = |
| 21 | + 5 /* The e+e- kt algorithm, aka Durham. */ |
| 22 | +} jetreconstruction_JetAlgorithm; |
| 23 | + |
| 24 | +/* |
| 25 | +Scoped enumeration (using EnumX) representing the different strategies for jet |
| 26 | +reconstruction. |
| 27 | +*/ |
| 28 | +typedef enum { |
| 29 | + JETRECONSTRUCTION_RECOSTRATEGY_BEST = 0, /* The best strategy. */ |
| 30 | + JETRECONSTRUCTION_RECOSTRATEGY_N2PLAIN = 1, /* The plain N2 strategy. */ |
| 31 | + JETRECONSTRUCTION_RECOSTRATEGY_N2TILTED = 2 /* The tiled N2 strategy. */ |
| 32 | +} jetreconstruction_RecoStrategy; |
| 33 | + |
| 34 | +/* The `PseudoJet` struct represents a pseudojet, a four-momentum object used in |
| 35 | +jet reconstruction algorithms. Additional information for the link back into the |
| 36 | +history of the clustering is stored in the `_cluster_hist_index` field. There is |
| 37 | +caching of the more expensive calculations for rapidity and azimuthal angle.*/ |
| 38 | +typedef struct { |
| 39 | + double px; /* The x-component of the momentum. */ |
| 40 | + double py; /* The y-component of the momentum. */ |
| 41 | + double pz; /* The z-component of the momentum. */ |
| 42 | + double E; /* The energy component of the momentum. */ |
| 43 | + long _cluster_hist_index; /* The index of the cluster history. */ |
| 44 | + double _pt2; /* The squared transverse momentum. */ |
| 45 | + double _inv_pt2; /* The inverse squared transverse momentum. */ |
| 46 | + double _rap; /* The rapidity. */ |
| 47 | + double _phi; /* The azimuthal angle. */ |
| 48 | +} jetreconstruction_PseudoJet; |
| 49 | + |
| 50 | +int jetreconstruction_PseudoJet_init(jetreconstruction_PseudoJet *ptr, |
| 51 | + double px, double py, double pz, double E); |
| 52 | +/* |
| 53 | +A struct holding a record of jet mergers and finalisations |
| 54 | +*/ |
| 55 | +typedef struct { |
| 56 | + long parent1; /* Index in history where first parent of this jet was |
| 57 | + created (NonexistentParent if this jet is an original |
| 58 | + particle) */ |
| 59 | + long parent2; /* Index in history where second parent of this jet was |
| 60 | + created (NonexistentParent if this jet is an original |
| 61 | + particle); BeamJet if this history entry just labels the |
| 62 | + fact that the jet has recombined with the beam */ |
| 63 | + long child; /* Index in history where the current jet is recombined with |
| 64 | + another jet to form its child. It is Invalid |
| 65 | + if this jet does not further recombine. */ |
| 66 | + long jetp_index; /* Index in the jets vector where we will find the |
| 67 | + PseudoJet object corresponding to this jet (i.e. the |
| 68 | + jet created at this entry of the history). NB: if this |
| 69 | + element of the history corresponds to a beam |
| 70 | + recombination, then `jetp_index=Invalid`. */ |
| 71 | + double dij; /* The distance corresponding to the recombination at this |
| 72 | + stage of the clustering. */ |
| 73 | + double max_dij_so_far; /* The largest recombination distance seen so far |
| 74 | + in the clustering history */ |
| 75 | +} jetreconstruction_HistoryElement; |
| 76 | + |
| 77 | +/* |
| 78 | +A struct holding the full history of a jet clustering sequence, including the |
| 79 | +final jets. |
| 80 | +*/ |
| 81 | +typedef struct { |
| 82 | + jetreconstruction_JetAlgorithm |
| 83 | + algorithm; /* The algorithm used for clustering. */ |
| 84 | + double power; /* The power value used for the clustering algorithm (note that |
| 85 | + this value is always stored as a Float64 to be |
| 86 | + type stable) */ |
| 87 | + double R; /* The R parameter used for the clustering algorithm. */ |
| 88 | + jetreconstruction_RecoStrategy |
| 89 | + strategy; /* The strategy used for clustering. */ |
| 90 | + jetreconstruction_PseudoJet |
| 91 | + *jets; /* The actual jets in the cluster sequence, which are of type `T |
| 92 | + <: FourMomentum`. */ |
| 93 | + size_t jets_length; /* Length of jets. */ |
| 94 | + long n_initial_jets; /* The initial number of particles used for exclusive |
| 95 | + jets. */ |
| 96 | + jetreconstruction_HistoryElement |
| 97 | + *history; /* The branching history of the cluster sequence. Each |
| 98 | + stage in the history indicates where to look in the |
| 99 | + jets vector to get the physical PseudoJet. */ |
| 100 | + size_t history_length; /* Length of history. */ |
| 101 | + double Qtot; /* The total energy of the event. */ |
| 102 | +} jetreconstruction_ClusterSequence; |
| 103 | + |
| 104 | +void jetreconstruction_ClusterSequence_free_members_( |
| 105 | + jetreconstruction_ClusterSequence *ptr); |
| 106 | +static inline void jetreconstruction_ClusterSequence_free_members( |
| 107 | + jetreconstruction_ClusterSequence *ptr) { |
| 108 | + jetreconstruction_ClusterSequence_free_members_(ptr); |
| 109 | + ptr->jets = NULL; |
| 110 | + ptr->jets_length = 0; |
| 111 | + ptr->history = NULL; |
| 112 | + ptr->history_length = 0; |
| 113 | +} |
| 114 | + |
| 115 | +int jetreconstruction_jet_reconstruct( |
| 116 | + const jetreconstruction_PseudoJet *particles, size_t particles_length, |
| 117 | + jetreconstruction_JetAlgorithm algorithm, double R, |
| 118 | + jetreconstruction_RecoStrategy strategy, |
| 119 | + jetreconstruction_ClusterSequence *result); |
| 120 | + |
| 121 | +typedef struct { |
| 122 | + jetreconstruction_PseudoJet *data; |
| 123 | + size_t length; |
| 124 | +} jetreconstruction_JetsResult; |
| 125 | + |
| 126 | +void jetreconstruction_JetsResult_free_members_( |
| 127 | + jetreconstruction_JetsResult *ptr); |
| 128 | +static inline void |
| 129 | +jetreconstruction_JetsResult_free_members(jetreconstruction_JetsResult *ptr) { |
| 130 | + jetreconstruction_JetsResult_free_members_(ptr); |
| 131 | + ptr->data = NULL; |
| 132 | + ptr->length = 0; |
| 133 | +} |
| 134 | + |
| 135 | +int jetreconstruction_exclusive_jets_dcut( |
| 136 | + const jetreconstruction_ClusterSequence *clustersequence, double dcut, |
| 137 | + jetreconstruction_JetsResult *result); |
| 138 | + |
| 139 | +int jetreconstruction_exclusive_jets_njets( |
| 140 | + const jetreconstruction_ClusterSequence *clustersequence, size_t njets, |
| 141 | + jetreconstruction_JetsResult *result); |
| 142 | + |
| 143 | +int jetreconstruction_inclusive_jets( |
| 144 | + const jetreconstruction_ClusterSequence *clustersequence, double ptmin, |
| 145 | + jetreconstruction_JetsResult *result); |
0 commit comments