FastJet 3.4.1
LazyTiling9SeparateGhosts.hh
1#ifndef __FASTJET_LAZYTILING9SEPARATEGHOSTS_HH__
2#define __FASTJET_LAZYTILING9SEPARATEGHOSTS_HH__
3
4//FJSTARTHEADER
5// $Id$
6//
7// Copyright (c) 2005-2023, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
8//
9//----------------------------------------------------------------------
10// This file is part of FastJet.
11//
12// FastJet is free software; you can redistribute it and/or modify
13// it under the terms of the GNU General Public License as published by
14// the Free Software Foundation; either version 2 of the License, or
15// (at your option) any later version.
16//
17// The algorithms that underlie FastJet have required considerable
18// development. They are described in the original FastJet paper,
19// hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
20// FastJet as part of work towards a scientific publication, please
21// quote the version you use and include a citation to the manual and
22// optionally also to hep-ph/0512210.
23//
24// FastJet is distributed in the hope that it will be useful,
25// but WITHOUT ANY WARRANTY; without even the implied warranty of
26// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27// GNU General Public License for more details.
28//
29// You should have received a copy of the GNU General Public License
30// along with FastJet. If not, see <http://www.gnu.org/licenses/>.
31//----------------------------------------------------------------------
32//FJENDHEADER
33
34//#include "fastjet/PseudoJet.hh"
35#include "fastjet/internal/MinHeap.hh"
36#include "fastjet/ClusterSequence.hh"
37#include "fastjet/internal/LazyTiling9Alt.hh"
38
39#include "fastjet/config.h"
40
41FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
42
43class TiledJet3 {
44public:
45 double eta, phi, kt2, NN_dist;
46 TiledJet3 * NN, *previous, * next;
47 int _jets_index, tile_index;
48 bool _minheap_update_needed;
49 bool is_ghost;
50
51 // indicate whether jets need to have their minheap entries
52 // updated).
53 inline void label_minheap_update_needed() {_minheap_update_needed = true;}
54 inline void label_minheap_update_done() {_minheap_update_needed = false;}
55 inline bool minheap_update_needed() const {return _minheap_update_needed;}
56};
57
58
59class Tile3 {
60public:
61 /// pointers to neighbouring tiles, including self
62 Tile3 * begin_tiles[n_tile_neighbours];
63 /// neighbouring tiles, excluding self
64 Tile3 ** surrounding_tiles;
65 /// half of neighbouring tiles, no self
66 Tile3 ** RH_tiles;
67 /// just beyond end of tiles
68 Tile3 ** end_tiles;
69 /// start of list of BriefJets contained in this tile
70 TiledJet3 * head;
71 /// start of list of BriefJets contained in this tile
72 TiledJet3 * ghost_head;
73 /// sometimes useful to be able to tag a tile
74 bool tagged;
75 /// for all particles in the tile, this stores the largest of the
76 /// (squared) nearest-neighbour distances.
77 double max_NN_dist;
78 double eta_centre, phi_centre;
79
80 bool is_near_zero_phi(double tile_size_phi) const {
81 return phi_centre < tile_size_phi || (twopi-phi_centre) < tile_size_phi;
82 }
83};
84
85
86//----------------------------------------------------------------------
87class LazyTiling9SeparateGhosts {
88public:
89 LazyTiling9SeparateGhosts(ClusterSequence & cs);
90
91 void run();
92
93 //void get_next_clustering(int & jetA_index, int & jetB_index, double & dij);
94
95 /// this is the pt2 threshold below which particles will be
96 /// considered as ghosts.
97 ///
98 /// Note that as it stands, a user can decide to change that
99 /// value. Note however that this has to be done at the user's own
100 /// risk (this is an internal part of fastjet).In a similar spirit,
101 /// the interface to access this valus might also change in a future
102 /// release of FastJet.
103 static double ghost_pt2_threshold;
104
105protected:
106 ClusterSequence & _cs;
107 const std::vector<PseudoJet> & _jets;
108 std::vector<Tile3> _tiles;
109
110
111 double _Rparam, _R2, _invR2;
112 double _tiles_eta_min, _tiles_eta_max;
113 double _tile_size_eta, _tile_size_phi;
114 double _tile_half_size_eta, _tile_half_size_phi;
115 int _n_tiles_phi,_tiles_ieta_min,_tiles_ieta_max;
116
117 std::vector<TiledJet3 *> _jets_for_minheap;
118
119 //MinHeap _minheap;
120
121 void _initialise_tiles();
122
123 // reasonably robust return of tile index given ieta and iphi, in particular
124 // it works even if iphi is negative
125 inline int _tile_index (int ieta, int iphi) const {
126 // note that (-1)%n = -1 so that we have to add _n_tiles_phi
127 // before performing modulo operation
128 return (ieta-_tiles_ieta_min)*_n_tiles_phi
129 + (iphi+_n_tiles_phi) % _n_tiles_phi;
130 }
131
132 void _bj_remove_from_tiles(TiledJet3 * const jet);
133
134 /// returns the tile index given the eta and phi values of a jet
135 int _tile_index(const double eta, const double phi) const;
136
137 // sets up information regarding the tiling of the given jet
138 void _tj_set_jetinfo(TiledJet3 * const jet, const int _jets_index, bool is_ghost);
139
140 void _print_tiles(TiledJet3 * briefjets ) const;
141 void _add_neighbours_to_tile_union(const int tile_index,
142 std::vector<int> & tile_union, int & n_near_tiles) const;
143 void _add_untagged_neighbours_to_tile_union(const int tile_index,
144 std::vector<int> & tile_union, int & n_near_tiles);
145 void _add_untagged_neighbours_to_tile_union_using_max_info(const TiledJet3 * const jet,
146 std::vector<int> & tile_union, int & n_near_tiles);
147 double _distance_to_tile(const TiledJet3 * bj, const Tile3 *) const;
148 void _update_jetX_jetI_NN(TiledJet3 * jetX, TiledJet3 * jetI, std::vector<TiledJet3 *> & jets_for_minheap);
149
150 void _set_NN(TiledJet3 * jetI, std::vector<TiledJet3 *> & jets_for_minheap);
151
152 // return the diJ (multiplied by _R2) for this jet assuming its NN
153 // info is correct
154 template <class J> double _bj_diJ(const J * const jet) const {
155 double kt2 = jet->kt2;
156 if (jet->NN != NULL) {if (jet->NN->kt2 < kt2) {kt2 = jet->NN->kt2;}}
157 return jet->NN_dist * kt2;
158 }
159
160
161 //----------------------------------------------------------------------
162 template <class J> inline void _bj_set_jetinfo(
163 J * const jetA, const int _jets_index) const {
164 jetA->eta = _jets[_jets_index].rap();
165 jetA->phi = _jets[_jets_index].phi_02pi();
166 jetA->kt2 = _cs.jet_scale_for_algorithm(_jets[_jets_index]);
167 jetA->_jets_index = _jets_index;
168 // initialise NN info as well
169 jetA->NN_dist = _R2;
170 jetA->NN = NULL;
171 }
172
173
174 //----------------------------------------------------------------------
175 template <class J> inline double _bj_dist(
176 const J * const jetA, const J * const jetB) const {
177 double dphi = std::abs(jetA->phi - jetB->phi);
178 double deta = (jetA->eta - jetB->eta);
179 if (dphi > pi) {dphi = twopi - dphi;}
180 return dphi*dphi + deta*deta;
181 }
182
183
184 //----------------------------------------------------------------------
185 template <class J> inline double _bj_dist_not_periodic(
186 const J * const jetA, const J * const jetB) const {
187 double dphi = jetA->phi - jetB->phi;
188 double deta = (jetA->eta - jetB->eta);
189 return dphi*dphi + deta*deta;
190 }
191
192};
193
194
195FASTJET_END_NAMESPACE
196
197#endif // __FASTJET_LAZYTILING9SEPARATEGHOSTS_HH__