30 #include "fastjet/ClusterSequence.hh"
31 #include "fastjet/GridJetPlugin.hh"
37 FASTJET_BEGIN_NAMESPACE
42 GridJetPlugin::GridJetPlugin (
double ymax,
43 double requested_grid_spacing,
45 _ymin(-ymax), _ymax(ymax),
46 _requested_grid_spacing(requested_grid_spacing) ,
47 _post_jet_def(post_jet_def)
52 void GridJetPlugin::setup_grid() {
56 assert(_ymax>0 && _ymax - _ymin >= _requested_grid_spacing);
58 double ny_double = (_ymax-_ymin) / _requested_grid_spacing;
59 _ny = int(ny_double+0.49999);
60 _dy = (_ymax-_ymin) / _ny;
62 _nphi = int (twopi / _requested_grid_spacing + 0.5);
63 _dphi = twopi / _nphi;
66 assert(_ny >= 1 && _nphi >= 1);
68 _ntotal = _nphi * _ny;
75 desc <<
"GridJetPlugin plugin with ymax = " << _ymax <<
", dy = " << _dy <<
", dphi = " << _dphi <<
" (requested grid spacing was " << _requested_grid_spacing <<
")";
77 desc <<
", followed by " << _post_jet_def.
description();
88 int GridJetPlugin::igrid(
const PseudoJet & p)
const {
99 int iy = int(floor( (p.
rap() - _ymin) / _dy ));
100 if (iy < 0 || iy >= _ny)
return -1;
102 int iphi = int( p.
phi()/_dphi );
103 assert(iphi >= 0 && iphi <= _nphi);
104 if (iphi == _nphi) iphi = 0;
106 int igrid_res = iy*_nphi + iphi;
107 assert (igrid_res >= 0 && igrid_res < _ny*_nphi);
119 vector<int> grid(_ntotal, -1);
121 int nparticles = cs.
jets().size();
122 double dij_or_diB = 1.0;
124 int ngrid_active = 0;
127 for (
int i = 0; i < nparticles; i++) {
128 int igrd = igrid(cs.
jets()[i]);
131 if (igrd < 0)
continue;
132 assert(igrd <= _ntotal);
133 if (grid[igrd] == -1) {
146 for (
unsigned igrd = 0; igrd < grid.size(); igrd++) {
152 vector<PseudoJet> inputs;
153 vector<int> cs_indices;
154 inputs.reserve(ngrid_active);
155 cs_indices.reserve(2*ngrid_active);
156 for (
unsigned igrd = 0; igrd < grid.size(); igrd++) {
157 if (grid[igrd] != -1) {
158 inputs.push_back(cs.
jets()[grid[igrd]]);
159 cs_indices.push_back(grid[igrd]);
163 const vector<ClusterSequence::history_element> & post_history = post_cs.
history();
164 const vector<PseudoJet> & post_jets = post_cs.
jets();
165 for (
unsigned ihist = ngrid_active; ihist < post_history.size(); ihist++) {
167 int post_ij1 = post_history[hist.parent1].
jetp_index;
168 int ij1 = cs_indices[post_ij1];
170 int post_ij2 = post_history[hist.
parent2].jetp_index;
171 int ij2 = cs_indices[post_ij2];
174 assert(
int(cs_indices.size()) == hist.
jetp_index);
175 cs_indices.push_back(k);
184 FASTJET_END_NAMESPACE