Index: classes/DelphesFormula.cc
===================================================================
--- classes/DelphesFormula.cc	(revision 2b3ef28c545a94f999f62ef4cfde37b0dfdb710d)
+++ classes/DelphesFormula.cc	(revision f53a4d29acc13d296285ecd9b0a986c73a2c0efb)
@@ -23,5 +23,4 @@
 
 #include <stdexcept>
-#include <string>
 
 using namespace std;
@@ -51,12 +50,16 @@
 Int_t DelphesFormula::Compile(const char *expression)
 {
-  string buffer;
+  TString buffer;
   const char *it;
   for(it = expression; *it; ++it)
   {
     if(*it == ' ' || *it == '\t' || *it == '\r' || *it == '\n' || *it == '\\' ) continue;
-    buffer.push_back(*it);
+    buffer.Append(*it);
   }
-  if(TFormula::Compile(buffer.c_str()) != 0)
+  buffer.ReplaceAll("pt", "x");
+  buffer.ReplaceAll("eta", "y");
+  buffer.ReplaceAll("phi", "z");
+  buffer.ReplaceAll("energy", "t");
+  if(TFormula::Compile(buffer) != 0)
   {
     throw runtime_error("Invalid formula.");
@@ -74,30 +77,2 @@
 
 //------------------------------------------------------------------------------
-
-Int_t DelphesFormula::DefinedVariable(TString &chaine, Int_t &action)
-{
-  action = kVariable;
-  if(chaine == "pt")
-  {
-    if(fNdim < 1) fNdim = 1;
-    return 0;
-  }
-  else if(chaine == "eta")
-  {
-    if(fNdim < 2) fNdim = 2;
-    return 1;
-  }
-  else if(chaine == "phi")
-  {
-    if(fNdim < 3) fNdim = 3;
-    return 2;
-  }
-  else if(chaine == "energy")
-  {
-    if(fNdim < 4) fNdim = 4;
-    return 3;
-  }
-  return -1;
-}
-
-//------------------------------------------------------------------------------
Index: classes/DelphesFormula.h
===================================================================
--- classes/DelphesFormula.h	(revision 2b3ef28c545a94f999f62ef4cfde37b0dfdb710d)
+++ classes/DelphesFormula.h	(revision f53a4d29acc13d296285ecd9b0a986c73a2c0efb)
@@ -35,6 +35,4 @@
 
   Double_t Eval(Double_t pt, Double_t eta = 0, Double_t phi = 0, Double_t energy = 0);
-
-  Int_t DefinedVariable(TString &variable, Int_t &action);
 };
 
Index: classes/DelphesTF2.cc
===================================================================
--- classes/DelphesTF2.cc	(revision 2b3ef28c545a94f999f62ef4cfde37b0dfdb710d)
+++ classes/DelphesTF2.cc	(revision f53a4d29acc13d296285ecd9b0a986c73a2c0efb)
@@ -18,7 +18,9 @@
 
 #include "classes/DelphesTF2.h"
+
+#include "RVersion.h"
 #include "TString.h"
+
 #include <stdexcept>
-#include <string>
 
 using namespace std;
@@ -34,5 +36,5 @@
 
 DelphesTF2::DelphesTF2(const char *name, const char *expression) :
-  TF2(name,expression)
+  TF2(name, expression)
 {
 }
@@ -46,18 +48,24 @@
 //------------------------------------------------------------------------------
 
-Int_t DelphesTF2::DefinedVariable(TString &chaine, Int_t &action)
+Int_t DelphesTF2::Compile(const char *expression)
 {
-  action = kVariable;
-  if(chaine == "z")
+  TString buffer;
+  const char *it;
+  for(it = expression; *it; ++it)
   {
-    if(fNdim < 1) fNdim = 1;
-    return 0;
+    if(*it == ' ' || *it == '\t' || *it == '\r' || *it == '\n' || *it == '\\' ) continue;
+    buffer.Append(*it);
   }
-  else if(chaine == "t")
+  buffer.ReplaceAll("z", "x");
+  buffer.ReplaceAll("t", "y");
+#if  ROOT_VERSION_CODE < ROOT_VERSION(6,04,00)
+  if(TF2::Compile(buffer) != 0)
+#else
+  if(TF2::GetFormula()->Compile(buffer) != 0)
+#endif
   {
-    if(fNdim < 2) fNdim = 2;
-    return 1;
+    throw runtime_error("Invalid formula.");
   }
-  return -1;
+  return 0;
 }
 
Index: classes/DelphesTF2.h
===================================================================
--- classes/DelphesTF2.h	(revision 2b3ef28c545a94f999f62ef4cfde37b0dfdb710d)
+++ classes/DelphesTF2.h	(revision f53a4d29acc13d296285ecd9b0a986c73a2c0efb)
@@ -21,7 +21,4 @@
 
 #include "TF2.h"
-#include "TFormula.h"
-
-#include <string>
 
 class DelphesTF2: public TF2
@@ -35,8 +32,6 @@
   ~DelphesTF2();
 
-  Int_t DefinedVariable(TString &variable, Int_t &action);
-
+  Int_t Compile(const char *expression);
 };
 
 #endif /* DelphesTF2_h */
-
