Index: external/fastjet/plugins/GridJet/GridJetPlugin.cc
===================================================================
--- external/fastjet/plugins/GridJet/GridJetPlugin.cc	(revision d7d2da362406b9e37fdf238970417c94779b54b0)
+++ external/fastjet/plugins/GridJet/GridJetPlugin.cc	(revision 49234af6f43184fff8e2bfee34c7b17846289882)
@@ -1,6 +1,6 @@
-//STARTHEADER
-// $Id$
-//
-// Copyright (c) 2011, Matteo Cacciari, Gavin Salam and Gregory Soyez
+//FJSTARTHEADER
+// $Id: GridJetPlugin.cc 2268 2011-06-20 15:12:26Z salam $
+//
+// Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
 //
 //----------------------------------------------------------------------
@@ -13,7 +13,9 @@
 //
 //  The algorithms that underlie FastJet have required considerable
-//  development and are described in hep-ph/0512210. If you use
+//  development. They are described in the original FastJet paper,
+//  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
 //  FastJet as part of work towards a scientific publication, please
-//  include a citation to the FastJet paper.
+//  quote the version you use and include a citation to the manual and
+//  optionally also to hep-ph/0512210.
 //
 //  FastJet is distributed in the hope that it will be useful,
@@ -25,5 +27,5 @@
 //  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
 //----------------------------------------------------------------------
-//ENDHEADER
+//FJENDHEADER
 
 // fastjet stuff
@@ -43,4 +45,8 @@
                               double requested_grid_spacing, 
                               const JetDefinition & post_jet_def) :
+#ifdef FASTJET_GRIDJET_USEFJGRID
+  RectangularGrid(ymax, requested_grid_spacing), _post_jet_def(post_jet_def) {
+}
+#else
   _ymin(-ymax), _ymax(ymax), 
   _requested_grid_spacing(requested_grid_spacing) ,
@@ -49,5 +55,16 @@
   setup_grid();
 }
-
+#endif
+
+#ifdef FASTJET_GRIDJET_USEFJGRID
+GridJetPlugin::GridJetPlugin (const RectangularGrid & grid,
+                              const JetDefinition & post_jet_def) : 
+  RectangularGrid(grid), _post_jet_def(post_jet_def) {
+  if (!RectangularGrid::is_initialised()) 
+    throw Error("attempt to construct GridJetPlugin with uninitialised RectangularGrid");
+}
+#endif // FASTJET_GRIDJET_USEFJGRID
+
+#ifndef FASTJET_GRIDJET_USEFJGRID
 void GridJetPlugin::setup_grid() {
   // since we've exchanged the arguments of the constructor,
@@ -69,22 +86,6 @@
 }
 
-
-//----------------------------------------------------------------------
-string GridJetPlugin::description () const {
-  ostringstream desc;
-  desc << "GridJetPlugin plugin with ymax = " << _ymax << ", dy = " << _dy << ", dphi = " << _dphi << " (requested grid spacing was " << _requested_grid_spacing << ")";
-  if (_post_jet_def.jet_algorithm() != undefined_jet_algorithm) {
-    desc << ", followed by " << _post_jet_def.description();
-  }
-  return desc.str();
-}
-
-
-//----------------------------------------------------------------------
-double GridJetPlugin::R() const {return sqrt(_dy*_dphi/pi);}
-
-
-//----------------------------------------------------------------------
-int GridJetPlugin::igrid(const PseudoJet & p) const {
+//----------------------------------------------------------------------
+int GridJetPlugin::tile_index(const PseudoJet & p) const {
   // directly taking int does not work for values between -1 and 0
   // so use floor instead
@@ -108,4 +109,25 @@
   return igrid_res;
 }
+#endif // not FASTJET_GRIDJET_USEFJGRID
+
+
+//----------------------------------------------------------------------
+string GridJetPlugin::description () const {
+  ostringstream desc;
+  desc << "GridJetPlugin plugin with ";
+#ifndef FASTJET_GRIDJET_USEFJGRID
+  desc << "ymax = " << _ymax << ", dy = " << _dy << ", dphi = " << _dphi << " (requested grid spacing was " << _requested_grid_spacing << ")";
+#else
+  desc << RectangularGrid::description();
+#endif
+  if (_post_jet_def.jet_algorithm() != undefined_jet_algorithm) {
+    desc << ", followed by " << _post_jet_def.description();
+  }
+  return desc.str();
+}
+
+
+//----------------------------------------------------------------------
+double GridJetPlugin::R() const {return sqrt(drap()*dphi()/pi);}
 
 
@@ -117,5 +139,5 @@
   //  * a number >= 0 will mean that particle indicated by the index
   //    is currently the jet on the grid
-  vector<int> grid(_ntotal, -1);
+  vector<int> grid(n_tiles(), -1);
  
   int nparticles = cs.jets().size();
@@ -126,9 +148,9 @@
   // combine particles with whatever is in the grid
   for (int i = 0; i < nparticles; i++) {
-    int igrd = igrid(cs.jets()[i]);
+    int igrd = tile_index(cs.jets()[i]);
     //cout << i << " " << cs.jets()[i].rap() << " " << cs.jets()[i].phi() 
     // 	 << " " << igrd << " " << grid.size() << " " << _ntotal << endl;
     if (igrd < 0) continue;
-    assert(igrd <= _ntotal);
+    assert(igrd <= n_tiles());
     if (grid[igrd] == -1) {
       grid[igrd] = i; // jet index of initial particle i is i
@@ -145,6 +167,6 @@
     // make the final jets via iB recombinations
     for (unsigned igrd = 0; igrd < grid.size(); igrd++) {
-      if (grid[igrd] != -1) cs.plugin_record_iB_recombination(grid[igrd], 
-							      dij_or_diB);
+      if (grid[igrd] != -1 && tile_is_good(igrd)) 
+                   cs.plugin_record_iB_recombination(grid[igrd], dij_or_diB);
     }
   } else {
