32#include "fastjet/config.h"
33#include "fastjet/Error.hh"
34#include "fastjet/PseudoJet.hh"
35#include "fastjet/ClusterSequence.hh"
36#include "fastjet/internal/DynamicNearestNeighbours.hh"
45#include "fastjet/internal/Dnn4piCylinder.hh"
46#include "fastjet/internal/Dnn3piCylinder.hh"
47#include "fastjet/internal/Dnn2piCylinder.hh"
50FASTJET_BEGIN_NAMESPACE
61void ClusterSequence::_delaunay_cluster () {
65 vector<EtaPhi> points(n);
66 for (
int i = 0; i < n; i++) {
67 points[i] = EtaPhi(_jets[i].rap(),_jets[i].phi_02pi());
72 const bool verbose =
false;
73 SharedPtr<DynamicNearestNeighbours> DNN;
75 bool ignore_nearest_is_mirror = (_Rparam < twopi);
76 if (_strategy == NlnN4pi) {
77 DNN.reset(
new Dnn4piCylinder(points,verbose));
78 }
else if (_strategy == NlnN3pi) {
79 DNN.reset(
new Dnn3piCylinder(points,ignore_nearest_is_mirror,verbose));
80 }
else if (_strategy == NlnN) {
81 DNN.reset(
new Dnn2piCylinder(points,ignore_nearest_is_mirror,verbose));
84 if (_strategy == NlnN4pi || _strategy == NlnN3pi || _strategy == NlnN) {
86 err <<
"ERROR: Requested strategy "<<strategy_string()<<
" but it is not"<<endl;
87 err <<
" supported because FastJet was compiled without CGAL"<<endl;
88 throw Error(err.str());
109 for (
int ii = 0; ii < n; ii++) {
110 _add_ktdistance_to_map(ii, DijMap, DNN.get());
116 for (
int i=0;i<n;i++) {
119 TwoVertices SmallestDijPair;
123 bool recombine_with_beam;
125 SmallestDij = DijMap.begin()->first;
126 SmallestDijPair = DijMap.begin()->second;
127 jet_i = SmallestDijPair.first;
128 jet_j = SmallestDijPair.second;
129 if (verbose) cout <<
"CS_Delaunay found recombination candidate: " << jet_i <<
" " << jet_j <<
" " << SmallestDij << endl;
135 DijMap.erase(DijMap.begin());
140 recombine_with_beam = (jet_j == BeamJet);
141 if (!recombine_with_beam) {Valid2 = DNN->Valid(jet_j);}
142 else {Valid2 =
true;}
143 if (verbose) cout <<
"CS_Delaunay validities i & j: " << DNN->Valid(jet_i) <<
" " << Valid2 << endl;
144 }
while ( !DNN->Valid(jet_i) || !Valid2);
150 if (! recombine_with_beam) {
152 if (verbose) cout <<
"CS_Delaunay call _do_ij_recomb: " << jet_i <<
" " << jet_j <<
" " << SmallestDij << endl;
153 _do_ij_recombination_step(jet_i, jet_j, SmallestDij, nn);
169 EtaPhi newpoint(_jets[nn].rap(), _jets[nn].phi_02pi());
171 points.push_back(newpoint);
174 if (verbose) cout <<
"CS_Delaunay call _do_iB_recomb: " << jet_i <<
" " << SmallestDij << endl;
175 _do_iB_recombination_step(jet_i, SmallestDij);
182 if (i == n-1) {
break;}
184 vector<int> updated_neighbours;
185 if (! recombine_with_beam) {
188 DNN->RemoveCombinedAddCombination(jet_i, jet_j,
189 points[points.size()-1], point3,
194 if (
static_cast<unsigned int> (point3) != points.size()-1) {
195 throw Error(
"INTERNAL ERROR: point3 != points.size()-1");}
198 DNN->RemovePoint(jet_i, updated_neighbours);
202 vector<int>::iterator it = updated_neighbours.begin();
203 for (; it != updated_neighbours.end(); ++it) {
205 _add_ktdistance_to_map(ii, DijMap, DNN.get());
228void ClusterSequence::_add_ktdistance_to_map(
231 const DynamicNearestNeighbours * DNN) {
233 double yiB = jet_scale_for_algorithm(_jets[ii]);
237 DijMap.insert(DijEntry(yiB, TwoVertices(ii,-1)));
239 double DeltaR2 = DNN->NearestNeighbourDistance(ii) * _invR2;
250 DijMap.insert(DijEntry(yiB, TwoVertices(ii,-1)));
252 double kt2i = jet_scale_for_algorithm(_jets[ii]);
253 int jj = DNN->NearestNeighbourIndex(ii);
254 if (kt2i <= jet_scale_for_algorithm(_jets[jj])) {
255 double dij = DeltaR2 * kt2i;
256 DijMap.insert(DijEntry(dij, TwoVertices(ii,jj)));