11using Statistics
22
33"""
4- mutable struct SoftKiller
4+ struct SoftKiller
55
66Implements the SoftKiller pileup mitigation algorithm, inspired by the FastJet contrib package.
77
@@ -21,14 +21,14 @@ are removed from the event.
2121- `_ymin::Float64`: Minimum rapidity of the grid.
2222- `_requested_drap::Float64`: Requested grid spacing in rapidity.
2323- `_requested_dphi::Float64`: Requested grid spacing in phi.
24- - `_ntotal::Int64 `: Total number of tiles.
24+ - `_ntotal::Int `: Total number of tiles.
2525- `_dy::Float64`: Actual grid spacing in rapidity.
2626- `_dphi::Float64`: Actual grid spacing in phi.
2727- `_cell_area::Float64`: Area of a single tile.
2828- `_inverse_dy::Float64`: Inverse of rapidity grid spacing.
2929- `_inverse_dphi::Float64`: Inverse of phi grid spacing.
30- - `_ny::Int64 `: Number of tiles in rapidity.
31- - `_nphi::Int64 `: Number of tiles in phi.
30+ - `_ny::Int `: Number of tiles in rapidity.
31+ - `_nphi::Int `: Number of tiles in phi.
3232
3333# Constructors
3434- `SoftKiller(rapmin::Float64, rapmax::Float64, drap::Float64, dphi::Float64)`:
@@ -37,19 +37,19 @@ are removed from the event.
3737 Construct a square grid from `-rapmax` to `rapmax` in rapidity, with tile size `grid_size`.
3838
3939"""
40- mutable struct SoftKiller
41- _ymax:: Float64
40+ struct SoftKiller
4241 _ymin:: Float64
42+ _ymax:: Float64
4343 _requested_drap:: Float64
4444 _requested_dphi:: Float64
45- _ntotal:: Int64
45+ _ntotal:: Int
4646 _dy:: Float64
4747 _dphi:: Float64
4848 _cell_area:: Float64
4949 _inverse_dy:: Float64
5050 _inverse_dphi:: Float64
51- _ny:: Int64
52- _nphi:: Int64
51+ _ny:: Int
52+ _nphi:: Int
5353
5454 """
5555 SoftKiller(rapmin::Float64, rapmax::Float64, drap::Float64, dphi::Float64)
@@ -58,9 +58,26 @@ mutable struct SoftKiller
5858 """
5959
6060 function SoftKiller (rapmin:: Float64 , rapmax:: Float64 , drap:: Float64 , dphi:: Float64 )
61- grid = new (rapmax, rapmin, drap, dphi, 0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0 , 0 )
62- _setup_grid! (grid)
63- grid
61+ @assert rapmax > rapmin
62+ @assert drap > 0
63+ @assert dphi > 0
64+
65+ ny_double = (rapmax - rapmin) / drap
66+ ny = max (round (Int, ny_double + 0.5 ), 1 )
67+ dy = (rapmax - rapmin) / ny
68+ inverse_dy = ny / (rapmax - rapmin)
69+
70+ nphi = round (Int, (2 * π) / dphi + 0.5 )
71+ dphi_final = (2 * π) / nphi
72+ inverse_dphi = nphi / (2 * π)
73+
74+ @assert ny >= 1 && nphi >= 1
75+
76+ ntotal = nphi * ny
77+ cell_area = dy * dphi_final
78+
79+ new (rapmin, rapmax, drap, dphi, ntotal, dy, dphi_final, cell_area,
80+ inverse_dy, inverse_dphi, ny, nphi)
6481 end
6582
6683 """
@@ -69,10 +86,7 @@ mutable struct SoftKiller
6986 Construct a square SoftKiller grid from `-rapmax` to `rapmax` in rapidity, with tile size `grid_size`.
7087 """
7188 function SoftKiller (rapmax:: Float64 , grid_size:: Float64 )
72- grid = new (rapmax, - rapmax, grid_size, grid_size, 0 , 0.0 , 0.0 , 0.0 , 0.0 , 0.0 , 0 ,
73- 0 )
74- _setup_grid! (grid)
75- grid
89+ return SoftKiller (- rapmax, rapmax, grid_size, grid_size)
7690 end
7791end
7892
@@ -88,46 +102,21 @@ function tile_index(sk::SoftKiller, p::PseudoJet)
88102 return - 1
89103 end
90104
91- iy = round (Int64 , y_minus_ymin * sk. _inverse_dy)
105+ iy = round (Int , y_minus_ymin * sk. _inverse_dy)
92106 if iy >= sk. _ny
93107 return - 1
94108 end
95109
96- iphi = round (Int64 , phi (p) * sk. _inverse_dphi)
110+ iphi = round (Int , phi (p) * sk. _inverse_dphi)
97111 if iphi == sk. _nphi
98112 iphi = 0
99113 end
100114
101- res = round (Int64 , iy * sk. _nphi + iphi)
115+ res = round (Int , iy * sk. _nphi + iphi)
102116
103117 res + 1
104118end
105119
106- """
107- _setup_grid!(sk::SoftKiller)
108-
109- Internal function to initialize the grid parameters for a `SoftKiller` instance.
110- """
111- function _setup_grid! (sk:: SoftKiller )
112- @assert sk. _ymax > sk. _ymin
113- @assert sk. _requested_drap > 0
114- @assert sk. _requested_dphi > 0
115-
116- ny_double = (sk. _ymax - sk. _ymin) / sk. _requested_drap
117- sk. _ny = max (round (Int64, ny_double + 0.5 ), 1 )
118- sk. _dy = (sk. _ymax - sk. _ymin) / sk. _ny
119- sk. _inverse_dy = sk. _ny / (sk. _ymax - sk. _ymin)
120-
121- sk. _nphi = round (Int64, (2 * π) / sk. _requested_dphi + 0.5 )
122- sk. _dphi = (2 * π) / sk. _nphi
123- sk. _inverse_dphi = sk. _nphi / (2 * π)
124-
125- @assert sk. _ny>= 1 and sk. _nphi>= 1
126-
127- sk. _ntotal = sk. _nphi * sk. _ny
128- sk. _cell_area = sk. _dy * sk. _dphi
129- end
130-
131120import Base: show
132121
133122"""
0 commit comments