32 #include "fastjet/Error.hh" 
   33 #include "fastjet/PseudoJet.hh" 
   34 #include "fastjet/ClusterSequence.hh" 
   35 #include "fastjet/internal/DynamicNearestNeighbours.hh" 
   44 #include "fastjet/internal/Dnn4piCylinder.hh" 
   45 #include "fastjet/internal/Dnn3piCylinder.hh" 
   46 #include "fastjet/internal/Dnn2piCylinder.hh" 
   49 FASTJET_BEGIN_NAMESPACE      
 
   60 void ClusterSequence::_delaunay_cluster () {
 
   64   vector<EtaPhi> points(n); 
 
   65   for (
int i = 0; i < n; i++) {
 
   66     points[i] = EtaPhi(_jets[i].rap(),_jets[i].phi_02pi());
 
   71   const bool verbose = 
false;
 
   72   SharedPtr<DynamicNearestNeighbours> DNN;
 
   74   bool ignore_nearest_is_mirror = (_Rparam < twopi);
 
   75   if (_strategy == NlnN4pi) {
 
   76     DNN.reset(
new Dnn4piCylinder(points,verbose));
 
   77   } 
else if (_strategy == NlnN3pi) {
 
   78     DNN.reset(
new Dnn3piCylinder(points,ignore_nearest_is_mirror,verbose));
 
   79   } 
else if (_strategy == NlnN) {
 
   80     DNN.reset(
new Dnn2piCylinder(points,ignore_nearest_is_mirror,verbose));
 
   83   if (_strategy == NlnN4pi || _strategy == NlnN3pi || _strategy == NlnN) {
 
   85     err << 
"ERROR: Requested strategy "<<strategy_string()<<
" but it is not"<<endl;
 
   86     err << 
"       supported because FastJet was compiled without CGAL"<<endl;
 
   87     throw Error(err.str());
 
  108   for (
int ii = 0; ii < n; ii++) {
 
  109     _add_ktdistance_to_map(ii, DijMap, DNN.get());
 
  115   for (
int i=0;i<n;i++) {
 
  118     TwoVertices SmallestDijPair;
 
  122     bool recombine_with_beam;
 
  124       SmallestDij = DijMap.begin()->first;
 
  125       SmallestDijPair = DijMap.begin()->second;
 
  126       jet_i = SmallestDijPair.first;
 
  127       jet_j = SmallestDijPair.second;
 
  128       if (verbose) cout << 
"CS_Delaunay found recombination candidate: " << jet_i << 
" " << jet_j << 
" " << SmallestDij << endl; 
 
  134       DijMap.erase(DijMap.begin());
 
  139       recombine_with_beam = (jet_j == BeamJet);
 
  140       if (!recombine_with_beam) {Valid2 = DNN->Valid(jet_j);} 
 
  141       else {Valid2 = 
true;}
 
  142       if (verbose) cout << 
"CS_Delaunay validities i & j: " << DNN->Valid(jet_i) << 
" " << Valid2 << endl;
 
  143     } 
while ( !DNN->Valid(jet_i) || !Valid2);
 
  149     if (! recombine_with_beam) {
 
  151       if (verbose) cout << 
"CS_Delaunay call _do_ij_recomb: " << jet_i << 
" " << jet_j << 
" " << SmallestDij << endl; 
 
  152       _do_ij_recombination_step(jet_i, jet_j, SmallestDij, nn);
 
  168       EtaPhi newpoint(_jets[nn].rap(), _jets[nn].phi_02pi());
 
  170       points.push_back(newpoint);
 
  173       if (verbose) cout << 
"CS_Delaunay call _do_iB_recomb: " << jet_i << 
" " << SmallestDij << endl; 
 
  174       _do_iB_recombination_step(jet_i, SmallestDij);
 
  181     if (i == n-1) {
break;}
 
  183     vector<int> updated_neighbours;
 
  184     if (! recombine_with_beam) {
 
  187       DNN->RemoveCombinedAddCombination(jet_i, jet_j, 
 
  188                                        points[points.size()-1], point3,
 
  193       if (
static_cast<unsigned int> (point3) != points.size()-1) {
 
  194         throw Error(
"INTERNAL ERROR: point3 != points.size()-1");}
 
  197       DNN->RemovePoint(jet_i, updated_neighbours);
 
  201     vector<int>::iterator it = updated_neighbours.begin();
 
  202     for (; it != updated_neighbours.end(); ++it) {
 
  204       _add_ktdistance_to_map(ii, DijMap, DNN.get());
 
  227 void ClusterSequence::_add_ktdistance_to_map(
 
  230                           const DynamicNearestNeighbours * DNN) {
 
  232   double yiB = jet_scale_for_algorithm(_jets[ii]);
 
  236     DijMap.insert(DijEntry(yiB,  TwoVertices(ii,-1)));
 
  238     double DeltaR2 = DNN->NearestNeighbourDistance(ii) * _invR2;
 
  249       DijMap.insert(DijEntry(yiB,  TwoVertices(ii,-1)));
 
  251       double kt2i = jet_scale_for_algorithm(_jets[ii]);
 
  252       int jj = DNN->NearestNeighbourIndex(ii);
 
  253       if (kt2i <= jet_scale_for_algorithm(_jets[jj])) {
 
  254         double dij = DeltaR2 * kt2i;
 
  255         DijMap.insert(DijEntry(dij, TwoVertices(ii,jj)));
 
  262 FASTJET_END_NAMESPACE