From 9db67ba9a20feef3477507aa00ff3cdcbfd5e8c8 Mon Sep 17 00:00:00 2001
From: Sasha Glazov <glazov@mail.desy.de>
Date: Mon, 25 Dec 2017 13:57:15 +0100
Subject: [PATCH 01/26] Uval steerable sum-rule and example of it

---
 src/sumrules.f | 18 +++++++++++++++++-
 steering.txt   |  4 ++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/sumrules.f b/src/sumrules.f
index 49c1ee87d..d9767f87d 100644
--- a/src/sumrules.f
+++ b/src/sumrules.f
@@ -38,7 +38,23 @@
 *add for mixed CTEQHERA
       double precision SumRuleCTEQ, SumRuleCTEQhera
 
+      double precision uvalSumRule
+      data uvalSumRule/2.0/
+      namelist/sumrule/uvalSumRule 
+      logical lfirst
+      data lfirst /.true./
 C-----------------------------------------
+
+      if (lfirst) then
+         lfirst = .false.
+         open (51,file='steering.txt',status='old')
+         read(51, nml=sumrule, end=1717)
+ 1717    continue
+
+         close(51)
+      endif
+
+      
       kflag=0
       zero = 1d-10
 
@@ -94,7 +110,7 @@ C**********************************************************
 C*     -- sum rule : U - Ubar = 2   :  gives AUval
 C*
          if (paruval(1).eq.0) then
-            paruval(1) = 2.0D0/CalcIntPdf(paruval)
+            paruval(1) = uvalSumRule/CalcIntPdf(paruval)
          else
             uv_sum = paruval(1)*CalcIntPdf(paruval)/2.
          endif
diff --git a/steering.txt b/steering.txt
index ab852d87c..a1695a5eb 100644
--- a/steering.txt
+++ b/steering.txt
@@ -45,6 +45,10 @@
   useBlas = .false.
 &End
 
+&sumrule
+  uvalSumRule = 1.
+&end
+
 &CovarToNuisance
    ! Global switch for using nuisance param representation for covariance mat.
   LConvertCovToNui = .False.
-- 
GitLab


From 5d1e859e9b1be20c570e9bd3bbf818006a1e4f7c Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Tue, 13 Feb 2018 20:00:03 +0300
Subject: [PATCH 02/26] Work on exporting sum rules to steering

---
 src/sumrules.f | 21 +++++++++++----------
 steering.txt   |  6 ++++--
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/sumrules.f b/src/sumrules.f
index d9767f87d..f4ff322d9 100644
--- a/src/sumrules.f
+++ b/src/sumrules.f
@@ -38,19 +38,19 @@
 *add for mixed CTEQHERA
       double precision SumRuleCTEQ, SumRuleCTEQhera
 
-      double precision uvalSumRule
-      data uvalSumRule/2.0/
-      namelist/sumrule/uvalSumRule 
+      double precision::uvalSum=2D0
+      double precision::dvalSum=1D0
+      double precision::svalSum=0D0
+      namelist/sumrule_sums/uvalSum,dvalSum,svalSum
       logical lfirst
       data lfirst /.true./
 C-----------------------------------------
 
-      if (lfirst) then
-         lfirst = .false.
+      if(lfirst)then
+         lfirst=.false.
          open (51,file='steering.txt',status='old')
-         read(51, nml=sumrule, end=1717)
+         read(51,nml=sumrule_sums,end=1717)
  1717    continue
-
          close(51)
       endif
 
@@ -101,19 +101,20 @@ C*     -- sum rule : D - Dbar = 1   :  gives ADval
 C*
 
          if (pardval(1).eq.0) then
-            pardval(1) = 1.0d0/CalcIntPdf(pardval)
+            pardval(1)=dvalSum/CalcIntPdf(pardval)
          else
-            dv_sum = pardval(1)*CalcIntPdf(pardval)
+            dv_sum = pardval(1)*CalcIntPdf(pardval)!Why? --ivnoviko
          endif
             
 C**********************************************************
 C*     -- sum rule : U - Ubar = 2   :  gives AUval
 C*
          if (paruval(1).eq.0) then
-            paruval(1) = uvalSumRule/CalcIntPdf(paruval)
+            paruval(1) = uvalSum/CalcIntPdf(paruval)
          else
             uv_sum = paruval(1)*CalcIntPdf(paruval)/2.
          endif
+C*     --TODO: cvalSum sumrule here? 
             
 C Also integrate momenta, for momentum sum rule:
          tUv = paruval(1)*CalcIntXpdf(paruval)
diff --git a/steering.txt b/steering.txt
index a1695a5eb..69d29b6cc 100644
--- a/steering.txt
+++ b/steering.txt
@@ -45,8 +45,10 @@
   useBlas = .false.
 &End
 
-&sumrule
-  uvalSumRule = 1.
+&sumrule_sums
+  uvalSum=2.
+  dvalSum=1.
+  svalSum=0.
 &end
 
 &CovarToNuisance
-- 
GitLab


From dee397cc3c74b030eab85485d89bbe659219f399 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Sun, 8 Jul 2018 20:04:34 +0300
Subject: [PATCH 03/26] Add sumrules to read_steer

---
 include/pdfparam.inc |  4 ++++
 src/read_steer.f     | 24 +++++++++++++++++++++---
 src/sumrules.f       | 33 ++++++++-------------------------
 steering.txt         |  3 ++-
 4 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/include/pdfparam.inc b/include/pdfparam.inc
index d83015dc0..f4b077271 100644
--- a/include/pdfparam.inc
+++ b/include/pdfparam.inc
@@ -1,6 +1,10 @@
  !> PDF parameterisations
 
 
+C !> Common parameters for sumrules
+      double precision::uvalSum
+      double precision::dvalSum
+      common/sumrule_sums_common/uvalSum,dvalSum
 C !> Standard parameterisation
 
        double precision paruval(1:10), pardval(1:10)
diff --git a/src/read_steer.f b/src/read_steer.f
index 975597e10..5fd43a00d 100644
--- a/src/read_steer.f
+++ b/src/read_steer.f
@@ -28,7 +28,7 @@ C Special branch for rotation
          call hf_stop
       endif
 
-      call read_infilesnml   ! Read data file names THIRD
+      call read_infilesnml  ! Read data file names THIRD
       call read_ewparsnml   ! electroweak parameters
       call read_outputnml   ! output options
       call read_outdirnml   ! output dir 
@@ -46,6 +46,7 @@ C
          call SetPDFStyle
       endif   ! Itheory < 100
 
+      call read_sumrules
       call read_mcerrorsnml  ! MC uncertainties
       call read_chebnml      ! chebyshev parameterisation extra pars
       call read_polynml
@@ -124,8 +125,10 @@ C------------------------------------------------------
 
       iDH_MOD = 0  ! no Dieter Heidt modifications to stat. errros.
 
-      PDFStyle  = 'HERAPDF'
+      PDFStyle = 'HERAPDF'
       PDFType  = 'proton'
+      uvalSum  = 2D0
+      dvalSum  = 1D0
 
       H1QCDFUNC= .False.
 C=================================================
@@ -647,7 +650,22 @@ C---
       call HF_stop
 
       end
-
+C
+!> Read number of valence up and down quarks for sum rules
+C-------------------------------------------------------
+      subroutine read_sumrules
+        implicit none
+#include "pdfparam.inc"
+        namelist/sumrule_sums/uvalSum,dvalSum
+        open(51,file='steering.txt',status='old')
+        read(51,nml=sumrule_sums,ERR=1718,end=1717)
+ 1717   continue
+        close(51)
+        return
+ 1718   continue
+        print '(''Error reading namelist &sumrule_sums, STOP'')'
+        call HF_stop
+      end
 C
 !> Read MC errors namelist
 C-------------------------------------------------------
diff --git a/src/sumrules.f b/src/sumrules.f
index f4ff322d9..6cee0f0f5 100644
--- a/src/sumrules.f
+++ b/src/sumrules.f
@@ -37,23 +37,7 @@
       double precision tstr,tNoGlue,tPho
 *add for mixed CTEQHERA
       double precision SumRuleCTEQ, SumRuleCTEQhera
-
-      double precision::uvalSum=2D0
-      double precision::dvalSum=1D0
-      double precision::svalSum=0D0
-      namelist/sumrule_sums/uvalSum,dvalSum,svalSum
-      logical lfirst
-      data lfirst /.true./
 C-----------------------------------------
-
-      if(lfirst)then
-         lfirst=.false.
-         open (51,file='steering.txt',status='old')
-         read(51,nml=sumrule_sums,end=1717)
- 1717    continue
-         close(51)
-      endif
-
       
       kflag=0
       zero = 1d-10
@@ -103,14 +87,14 @@ C*
          if (pardval(1).eq.0) then
             pardval(1)=dvalSum/CalcIntPdf(pardval)
          else
-            dv_sum = pardval(1)*CalcIntPdf(pardval)!Why? --ivnoviko
+            dv_sum = pardval(1)*CalcIntPdf(pardval)
          endif
             
 C**********************************************************
 C*     -- sum rule : U - Ubar = 2   :  gives AUval
 C*
          if (paruval(1).eq.0) then
-            paruval(1) = uvalSum/CalcIntPdf(paruval)
+            paruval(1)=uvalSum/CalcIntPdf(paruval)
          else
             uv_sum = paruval(1)*CalcIntPdf(paruval)/2.
          endif
@@ -951,11 +935,11 @@ C---------------------------------------------------------------
 
 C Counting sum-rule for uv:
       sumUv = SumRuleASpar(-1,asuval)
-      asuval(1) = 2.0D0 / sumUv
+      asuval(1) = uvalSum / sumUv
 
 C Counting sum-rule for dv:
       sumDv = SumRuleASpar(-1,asdval)
-      asdval(1) = 1.0D0 / sumDv
+      asdval(1) = dvalSum / sumDv
 
 C Momentum sum rule:
       sumMom = 2.D0*asubar(1)*SumRuleASpar(0,asubar) +
@@ -1167,11 +1151,11 @@ C---------------------------------------------------------------
 
 C Counting sum-rule for uv:
       sumUv = SumRuleCTEQ(-1,ctuval)
-      ctuval(1) = 2.0D0 / sumUv
+      ctuval(1) = uvalSum / sumUv
 
 C Counting sum-rule for dv:
       sumDv = SumRuleCTEQ(-1,ctdval)
-      ctdval(1) = 1.0D0 / sumDv
+      ctdval(1) = dvalSum / sumDv
 
 C Momentum sum rule:
 C----------------
@@ -1184,7 +1168,6 @@ C Sea:
          tStr = 0               ! Strange already included in Dbar
       endif
 
-
       sumMom = 2.D0*ctubar(1)*SumRuleCTEQ(0,ctubar) +
      $     2.D0*ctdbar(1)*SumRuleCTEQ(0,ctdbar) +
      $     ctuval(1)*SumRuleCTEQ(0,ctuval) +
@@ -1245,11 +1228,11 @@ C---------------------------------------------------------------
 
 C Counting sum-rule for uv:
       sumUv = SumRuleCTEQhera(-1,ctuval)
-      ctuval(1) = 2.0D0 / sumUv
+      ctuval(1) = uvalSum / sumUv
 
 C Counting sum-rule for dv:
       sumDv = SumRuleCTEQhera(-1,ctdval)
-      ctdval(1) = 1.0D0 / sumDv
+      ctdval(1) = dvalSum / sumDv
 
 C Momentum sum rule:
 C----------------
diff --git a/steering.txt b/steering.txt
index 69d29b6cc..c2df3a7d1 100644
--- a/steering.txt
+++ b/steering.txt
@@ -46,9 +46,10 @@
 &End
 
 &sumrule_sums
+	! Constant number of valence u- and d- quarks to be used in sum rules
+	! Change for hadrons other than proton
   uvalSum=2.
   dvalSum=1.
-  svalSum=0.
 &end
 
 &CovarToNuisance
-- 
GitLab


From 47da01d47ac1e5a46f78a369e53648cdafc58ae9 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novikovi@naf-atlas11.desy.de>
Date: Mon, 23 Jul 2018 17:03:07 +0200
Subject: [PATCH 04/26] Check for mismatch in APPLgrid grid size and number of
 datapoints

---
 reactions/APPLgrid/src/ReactionAPPLgrid.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/reactions/APPLgrid/src/ReactionAPPLgrid.cc b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
index b3ef002af..5dabd9595 100644
--- a/reactions/APPLgrid/src/ReactionAPPLgrid.cc
+++ b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
@@ -142,7 +142,7 @@ void ReactionAPPLgrid::setDatasetParamters(int dataSetID, map<string,string> par
  // Main function to compute results at an iteration
 int ReactionAPPLgrid::compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err) {
   // iterate over grids
-  int pos = 0;
+  unsigned int pos = 0;
   for(unsigned int g = 0; g < _grids[dataSetID].size(); g++)
   {
     auto grid = _grids[dataSetID][g];
@@ -177,5 +177,10 @@ int ReactionAPPLgrid::compute(int dataSetID, valarray<double> &val, map<string,
     std::copy_n(gridVals.begin(), gridVals.size(), &val[pos]);
     pos += grid->Nobs();
   }
+  if(val.size()!=pos){
+    std::ostringstream s;
+    s<<"F: Number of data points ("<<val.size()<<") in dataset (ID="<<dataSetID<<") does not match total grid size ("<<pos<<")";
+    hf_errlog(18072311,s.str().c_str());
+  }
   return 0;
 }
-- 
GitLab


From 7ff18b8bf425a941333a344577faec3a27a64492 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novikovi@naf-atlas14.desy.de>
Date: Thu, 2 Aug 2018 14:30:04 +0200
Subject: [PATCH 05/26] APPLgrid reaction module: set target PDF from LHAPDF

---
 include/ReactionTheory.h                      |  4 +-
 reactions/APPLgrid/include/ReactionAPPLgrid.h | 16 +++--
 reactions/APPLgrid/src/Makefile.am            |  9 ++-
 reactions/APPLgrid/src/ReactionAPPLgrid.cc    | 65 +++++++++++++++----
 .../BaseDISCC/include/ReactionBaseDISCC.h     |  2 +-
 reactions/BaseDISCC/src/ReactionBaseDISCC.cc  |  2 +-
 .../BaseDISNC/include/ReactionBaseDISNC.h     |  2 +-
 reactions/BaseDISNC/src/ReactionBaseDISNC.cc  |  2 +-
 .../BaseHVQMNR/include/ReactionBaseHVQMNR.h   |  2 +-
 .../BaseHVQMNR/src/ReactionBaseHVQMNR.cc      |  2 +-
 .../FFABM_DISCC/include/ReactionFFABM_DISCC.h |  2 +-
 .../FFABM_DISCC/src/ReactionFFABM_DISCC.cc    |  4 +-
 .../FFABM_DISNC/include/ReactionFFABM_DISNC.h |  2 +-
 .../FFABM_DISNC/src/ReactionFFABM_DISNC.cc    |  4 +-
 .../src/ReactionHVQMNR_LHCb_7TeV_beauty.cc    |  2 +-
 .../src/ReactionHVQMNR_LHCb_7TeV_charm.cc     |  2 +-
 reactions/Hathor/include/ReactionHathor.h     |  2 +-
 reactions/Hathor/src/ReactionHathor.cc        |  2 +-
 reactions/KFactor/include/ReactionKFactor.h   |  2 +-
 reactions/KFactor/src/ReactionKFactor.cc      |  2 +-
 reactions/RT_DISNC/include/ReactionRT_DISNC.h |  2 +-
 reactions/RT_DISNC/src/ReactionRT_DISNC.cc    |  4 +-
 reactions/fastNLO/include/ReactionfastNLO.h   |  2 +-
 reactions/fastNLO/src/ReactionfastNLO.cc      |  2 +-
 src/TheorEval.cc                              |  2 +-
 src/main.f                                    |  2 +-
 steering.txt                                  | 65 +++++++++----------
 27 files changed, 127 insertions(+), 82 deletions(-)

diff --git a/include/ReactionTheory.h b/include/ReactionTheory.h
index 7ebe0c0b7..0236f3cac 100644
--- a/include/ReactionTheory.h
+++ b/include/ReactionTheory.h
@@ -24,7 +24,7 @@ typedef double (*pTwoParFunc)(const double&, const double& );
 typedef void   (*pThreeParSub)(const double& , const double&, const double&);  
 
 // Function to emulate LHAPDF xfx behavior:
-typedef void   (*pXFXlike)(const double&, const double&, double*);
+typedef void   (*pXFXlike)(const double&x,const double&Q,double*results);
 
 //using pZeroParFunc = std::function< double() >;
 //using pOneParFunc  = std::function< double(const double&) >;
@@ -87,7 +87,7 @@ class ReactionTheory
   virtual void errorBandAction(int ivector) {};
 
   //! Set dataset @param dataSetID parameters which can be term- and dataset-specific
-  virtual void setDatasetParamters( int dataSetID, map<string,string> parsReaction,  map<string,double> parsDataset) {} ;
+  virtual void setDatasetParameters( int dataSetID, map<string,string> parsReaction,  map<string,double> parsDataset) {} ;
 
   //! Main function to compute predictions for @param dataSetID 
   virtual int compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err) = 0;  
diff --git a/reactions/APPLgrid/include/ReactionAPPLgrid.h b/reactions/APPLgrid/include/ReactionAPPLgrid.h
index 3e3cbfd07..a06cc2fd3 100644
--- a/reactions/APPLgrid/include/ReactionAPPLgrid.h
+++ b/reactions/APPLgrid/include/ReactionAPPLgrid.h
@@ -5,6 +5,10 @@
 #include "appl_grid/appl_grid.h"
 #include <memory>
 
+#ifdef LHAPDF_ENABLED
+#include<LHAPDF/LHAPDF.h>
+#endif
+
 /**
   @class' ReactionAPPLgrid
 
@@ -19,22 +23,21 @@
 class ReactionAPPLgrid : public ReactionTheory
 {
   public:
-    ReactionAPPLgrid(){};
-
-//    ~ReactionAPPLgrid(){};
+    ReactionAPPLgrid();
+    ~ReactionAPPLgrid();
 //    ~ReactionAPPLgrid(const ReactionAPPLgrid &){};
 //    ReactionAPPLgrid & operator =(const ReactionAAPPLgrid &r){return *(new ReactionAPPLgrid(r));};
 
  public:
     virtual string getReactionName() const { return  "APPLgrid" ;};
     int initAtStart(const string &); 
-    virtual void setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
+    virtual void setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
     virtual int compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err);
  protected:
     virtual int parseOptions(){ return 0;};    
 
  private:
-    enum class collision { pp, ppbar, pn};
+    enum class collision {pp,ppbar,pn,LHAPDF};
     map<int, collision> _collType;
     map<int, std::vector<std::shared_ptr<appl::grid> > > _grids;
     map<int, int> _order;
@@ -43,5 +46,8 @@ class ReactionAPPLgrid : public ReactionTheory
     map<int, bool> _flagUseReferece; // !> if true, prediction will be calculated from reference histogram (for tests and grids validation)
     map<int, std::vector<TH1D*> > _references;
     map<int, std::vector<double> > _eScale; // !> CMS energy
+#ifdef LHAPDF_ENABLED
+		map<int,LHAPDF::PDF*>lhapdf_pdf;
+#endif
 };
 
diff --git a/reactions/APPLgrid/src/Makefile.am b/reactions/APPLgrid/src/Makefile.am
index 8f5227962..b1147bed7 100644
--- a/reactions/APPLgrid/src/Makefile.am
+++ b/reactions/APPLgrid/src/Makefile.am
@@ -6,10 +6,13 @@ if ENABLE_APPLGRID
   lib_LTLIBRARIES = libapplgrid_xfitter.la
   libapplgrid_xfitter_la_SOURCES = ReactionAPPLgrid.cc
 
-# libapplgrid_xfitter_la_LDFLAGS = place_if_needed  
+  libapplgrid_xfitter_la_LDFLAGS:=
   libapplgrid_xfitter_la_CPPFLAGS = $(APPLGRID_CPPFLAGS) $(ROOT_CFLAGS)
-
-
+if ENABLE_LHAPDF
+  AM_CXXFLAGS+=$(LHAPDF_CPPFLAGS)
+  libapplgrid_xfitter_la_CPPFLAGS+=$(LHAPDF_CPPFLAGS)
+  libapplgrid_xfitter_la_LDFLAGS+=$(LHAPDF_LDFLAGS)
+endif
 endif
 
 datadir = ${prefix}/yaml/reactions/APPLgrid
diff --git a/reactions/APPLgrid/src/ReactionAPPLgrid.cc b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
index 5dabd9595..922585eaf 100644
--- a/reactions/APPLgrid/src/ReactionAPPLgrid.cc
+++ b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
@@ -8,20 +8,38 @@
 #include "ReactionAPPLgrid.h"
 #include "TFile.h"
 
+#ifdef LHAPDF_ENABLED
+LHAPDF::PDF*active_pdf;
+void xfxLHAPDF_wrapper(const double&x,const double&Q,double*results){
+	vector<double>rtn;
+	active_pdf->xfxQ(x,Q,rtn);
+	std::copy(rtn.begin(),rtn.end(),results);
+}
+#endif
+
  // the class factories
 extern "C" ReactionAPPLgrid* create() {
   return new ReactionAPPLgrid();
 }
-
+ReactionAPPLgrid::ReactionAPPLgrid(){}
+ReactionAPPLgrid::~ReactionAPPLgrid(){
+#ifdef LHAPDF_ENABLED
+	for(auto it=lhapdf_pdf.begin();it!=lhapdf_pdf.end();++it){
+		LHAPDF::PDF*p=it->second;
+		if(p)delete p;
+	}
+#endif
+}
  // Initialize at the start of the computation
 int ReactionAPPLgrid::initAtStart(const string &s )
 {
    return 0;
 }
 
- // Initialisze for a given dataset:
-void ReactionAPPLgrid::setDatasetParamters(int dataSetID, map<string,string> pars, map<string, double> parsDataset) {
-// Get grid name:
+ // Initialize for a given dataset:
+void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pars, map<string, double> parsDataset) {
+	map<string,string>::iterator it;
+	// Get grid name:
    if ( pars.find("GridName") != pars.end() )  {
      try {
        std::istringstream ss(pars["GridName"]);
@@ -51,6 +69,24 @@ void ReactionAPPLgrid::setDatasetParamters(int dataSetID, map<string,string> par
      hf_errlog_(17032801,text.c_str(),text.size());
    }
 
+	it=pars.find("LHAPDF_SetName");
+	if(it!=pars.end()){
+#ifdef LHAPDF_ENABLED
+		//To be used when PDF of second particle is static and of LHAPDF
+		//Make sure to set collision=LHAPDF
+		//std::cout<<"DEBUG LHAPDF_SetName="<<it->second<<std::endl;
+		LHAPDF::PDF*p=LHAPDF::mkPDF(it->second,0);
+		if(!p){
+			std::ostringstream s;
+			s<<"F:LHAPDF failed to load PDF set \""<<it->second<<"\" for use with APPLgrid; dataSetID="<<dataSetID;
+			hf_errlog(28071810,s.str().c_str());
+		}
+		lhapdf_pdf[dataSetID]=p;
+#else
+		hf_errlog(25071812,"F:LHAPDF Set specified for APPLgrid reaction, but xFitter has been compiled without LHAPDF. Use --enable-lhapdf at configure to enable.")
+#endif
+	}
+
 // Determine order
    int order = OrderMap( GetParamS("Order"));  // Global order
    if (pars.find("Order") != pars.end() ) { // Local order
@@ -75,15 +111,16 @@ void ReactionAPPLgrid::setDatasetParamters(int dataSetID, map<string,string> par
     _collType[dataSetID] = collision::pn;
   }
   // check if collision settings are provided in the new format key=value
-  map<string,string>::iterator it = pars.find("collision");
+  it=pars.find("collision");
   if (it != pars.end() )
   {
-    if(it->second == "pp")
-      _collType[dataSetID] = collision::pp;
-    else if(it->second == "ppbar")
-      _collType[dataSetID] = collision::ppbar;
-    else if(it->second == "pn")
-      _collType[dataSetID] = collision::pn;
+    if     (it->second=="pp")    _collType[dataSetID]=collision::pp;
+    else if(it->second=="ppbar") _collType[dataSetID]=collision::ppbar;
+    else if(it->second=="pn")    _collType[dataSetID]=collision::pn;
+		else if(it->second=="LHAPDF"){
+			_collType[dataSetID]=collision::LHAPDF;
+			if(lhapdf_pdf.find(dataSetID)==lhapdf_pdf.end())hf_errlog(24071810,"F: collision type=LHAPDF but no LHAPDF set was loaded");
+		}
     else
       hf_errlog(17102101, "F: unrecognised collision type = " + it->second);
   }
@@ -161,6 +198,12 @@ int ReactionAPPLgrid::compute(int dataSetID, valarray<double> &val, map<string,
         case collision::pn :
           gridVals =  grid->vconvolute( getXFX(), getXFX("n"), getAlphaS(), _order[dataSetID]-1, _muR[dataSetID], _muF[dataSetID], _eScale[dataSetID][g] );
           break;
+#ifdef LHAPDF_ENABLED
+        case collision::LHAPDF:
+					active_pdf=lhapdf_pdf.find(dataSetID)->second;
+          gridVals=grid->vconvolute(getXFX(),xfxLHAPDF_wrapper,getAlphaS(),_order[dataSetID]-1, _muR[dataSetID], _muF[dataSetID], _eScale[dataSetID][g] );
+          break;
+#endif
       }
     }
     else
diff --git a/reactions/BaseDISCC/include/ReactionBaseDISCC.h b/reactions/BaseDISCC/include/ReactionBaseDISCC.h
index ceb5f7ea6..4bb3e75d8 100644
--- a/reactions/BaseDISCC/include/ReactionBaseDISCC.h
+++ b/reactions/BaseDISCC/include/ReactionBaseDISCC.h
@@ -29,7 +29,7 @@ class ReactionBaseDISCC : public ReactionTheory
   public:
     virtual string getReactionName() const { return  "BaseDISCC" ;};
     int initAtStart(const string &); 
-    virtual void setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
+    virtual void setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
     virtual void initAtIteration() override;
     
     virtual int compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err);
diff --git a/reactions/BaseDISCC/src/ReactionBaseDISCC.cc b/reactions/BaseDISCC/src/ReactionBaseDISCC.cc
index f755dbe31..22861d6de 100644
--- a/reactions/BaseDISCC/src/ReactionBaseDISCC.cc
+++ b/reactions/BaseDISCC/src/ReactionBaseDISCC.cc
@@ -98,7 +98,7 @@ void ReactionBaseDISCC::initAtIteration() {
 }
 
 // 
-void  ReactionBaseDISCC::setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) 
+void  ReactionBaseDISCC::setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) 
 {
   auto *q2p  = GetBinValues(dataSetID,"Q2"), *xp  = GetBinValues(dataSetID,"x"), *yp  = GetBinValues(dataSetID,"y");  
   if (q2p == nullptr || xp == nullptr || yp == nullptr ) {
diff --git a/reactions/BaseDISNC/include/ReactionBaseDISNC.h b/reactions/BaseDISNC/include/ReactionBaseDISNC.h
index 2bec73abb..b19136cc8 100644
--- a/reactions/BaseDISNC/include/ReactionBaseDISNC.h
+++ b/reactions/BaseDISNC/include/ReactionBaseDISNC.h
@@ -23,7 +23,7 @@ class ReactionBaseDISNC : public ReactionTheory
  public:
     virtual string getReactionName() const { return  "BaseDISNC" ;};
     int initAtStart(const string &); 
-    virtual void setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
+    virtual void setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
 
     //!< Initialize all EWK couplings here:
     virtual void initAtIteration() override; 
diff --git a/reactions/BaseDISNC/src/ReactionBaseDISNC.cc b/reactions/BaseDISNC/src/ReactionBaseDISNC.cc
index 82199fb3f..701b6be2b 100644
--- a/reactions/BaseDISNC/src/ReactionBaseDISNC.cc
+++ b/reactions/BaseDISNC/src/ReactionBaseDISNC.cc
@@ -91,7 +91,7 @@ void ReactionBaseDISNC::initAtIteration() {
 }
 
 // 
-void  ReactionBaseDISNC::setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) 
+void  ReactionBaseDISNC::setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) 
 {
   auto *q2p  = GetBinValues(dataSetID,"Q2"), *xp  = GetBinValues(dataSetID,"x"), *yp  = GetBinValues(dataSetID,"y");  
   if (q2p == nullptr || xp == nullptr || yp == nullptr ) {
diff --git a/reactions/BaseHVQMNR/include/ReactionBaseHVQMNR.h b/reactions/BaseHVQMNR/include/ReactionBaseHVQMNR.h
index a1ba24dc1..b0550a4dc 100644
--- a/reactions/BaseHVQMNR/include/ReactionBaseHVQMNR.h
+++ b/reactions/BaseHVQMNR/include/ReactionBaseHVQMNR.h
@@ -35,7 +35,7 @@ class ReactionBaseHVQMNR : public ReactionTheory
     virtual int initAtStart(const string &) = 0; 
     virtual int compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err) = 0;
     virtual void initAtIteration() = 0;
-    virtual void setDatasetParamters(int dataSetID, map<string,string> pars, map<string,double> dsPars) override;
+    virtual void setDatasetParameters(int dataSetID, map<string,string> pars, map<string,double> dsPars) override;
   protected:
     virtual int parseOptions(){ return 0;};
     
diff --git a/reactions/BaseHVQMNR/src/ReactionBaseHVQMNR.cc b/reactions/BaseHVQMNR/src/ReactionBaseHVQMNR.cc
index 41a02fa39..ece984d0e 100644
--- a/reactions/BaseHVQMNR/src/ReactionBaseHVQMNR.cc
+++ b/reactions/BaseHVQMNR/src/ReactionBaseHVQMNR.cc
@@ -43,7 +43,7 @@ ReactionBaseHVQMNR::~ReactionBaseHVQMNR()
 }
 
 
-void ReactionBaseHVQMNR::setDatasetParamters(int dataSetID, map<string,string> pars, map<string,double> dsPars)
+void ReactionBaseHVQMNR::setDatasetParameters(int dataSetID, map<string,string> pars, map<string,double> dsPars)
 {
   // add new dataset
   DataSet dataSet;
diff --git a/reactions/FFABM_DISCC/include/ReactionFFABM_DISCC.h b/reactions/FFABM_DISCC/include/ReactionFFABM_DISCC.h
index a9e91674e..b0888e4e3 100644
--- a/reactions/FFABM_DISCC/include/ReactionFFABM_DISCC.h
+++ b/reactions/FFABM_DISCC/include/ReactionFFABM_DISCC.h
@@ -22,7 +22,7 @@ class ReactionFFABM_DISCC : public ReactionBaseDISCC
     ReactionFFABM_DISCC(){};
     virtual string getReactionName() const { return  "FFABM_DISCC" ;};
     int initAtStart(const string &); 
-    virtual void setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
+    virtual void setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
     virtual void initAtIteration() override;
 
   protected:
diff --git a/reactions/FFABM_DISCC/src/ReactionFFABM_DISCC.cc b/reactions/FFABM_DISCC/src/ReactionFFABM_DISCC.cc
index 52c588c96..faf2708a7 100644
--- a/reactions/FFABM_DISCC/src/ReactionFFABM_DISCC.cc
+++ b/reactions/FFABM_DISCC/src/ReactionFFABM_DISCC.cc
@@ -100,8 +100,8 @@ int ReactionFFABM_DISCC::initAtStart(const string &s)
   return isout;
 }
 
-void ReactionFFABM_DISCC::setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) {
-  Super::setDatasetParamters(dataSetID, pars, parsDataset);
+void ReactionFFABM_DISCC::setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) {
+  Super::setDatasetParameters(dataSetID, pars, parsDataset);
   // Allocate internal arrays:
   _f2abm[dataSetID].resize(GetNpoint(dataSetID));
   _flabm[dataSetID].resize(GetNpoint(dataSetID));
diff --git a/reactions/FFABM_DISNC/include/ReactionFFABM_DISNC.h b/reactions/FFABM_DISNC/include/ReactionFFABM_DISNC.h
index e7fa9e9bc..c81ded02c 100644
--- a/reactions/FFABM_DISNC/include/ReactionFFABM_DISNC.h
+++ b/reactions/FFABM_DISNC/include/ReactionFFABM_DISNC.h
@@ -23,7 +23,7 @@ class ReactionFFABM_DISNC : public ReactionBaseDISNC
   public:
     virtual string getReactionName() const { return  "FFABM_DISNC" ;};
     int initAtStart(const string &);
-    virtual void setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
+    virtual void setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
     virtual void initAtIteration() override;
 
   protected:
diff --git a/reactions/FFABM_DISNC/src/ReactionFFABM_DISNC.cc b/reactions/FFABM_DISNC/src/ReactionFFABM_DISNC.cc
index b114d328d..6c8210104 100644
--- a/reactions/FFABM_DISNC/src/ReactionFFABM_DISNC.cc
+++ b/reactions/FFABM_DISNC/src/ReactionFFABM_DISNC.cc
@@ -97,8 +97,8 @@ int ReactionFFABM_DISNC::initAtStart(const string &s)
   return isout;
 }
 
-void ReactionFFABM_DISNC::setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) {
-  Super::setDatasetParamters(dataSetID, pars, parsDataset);
+void ReactionFFABM_DISNC::setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) {
+  Super::setDatasetParameters(dataSetID, pars, parsDataset);
   // Allocate internal arrays:
   _f2abm[dataSetID].resize(GetNpoint(dataSetID));
   _flabm[dataSetID].resize(GetNpoint(dataSetID));
diff --git a/reactions/HVQMNR_LHCb_7TeV_beauty/src/ReactionHVQMNR_LHCb_7TeV_beauty.cc b/reactions/HVQMNR_LHCb_7TeV_beauty/src/ReactionHVQMNR_LHCb_7TeV_beauty.cc
index f3b207467..9c2bfaad8 100644
--- a/reactions/HVQMNR_LHCb_7TeV_beauty/src/ReactionHVQMNR_LHCb_7TeV_beauty.cc
+++ b/reactions/HVQMNR_LHCb_7TeV_beauty/src/ReactionHVQMNR_LHCb_7TeV_beauty.cc
@@ -26,7 +26,7 @@ extern "C" ReactionHVQMNR_LHCb_7TeV_beauty* create() {
 int ReactionHVQMNR_LHCb_7TeV_beauty::initAtStart(const string &s)
 {
   // ignore provided terminfo (s): all needed information has been set already 
-  // via setDatasetParamters(int dataSetID, map<string,string> pars)
+  // via setDatasetParameters(int dataSetID, map<string,string> pars)
   
   // ******************************************************************
   // perform initialisation and pre-calculation
diff --git a/reactions/HVQMNR_LHCb_7TeV_charm/src/ReactionHVQMNR_LHCb_7TeV_charm.cc b/reactions/HVQMNR_LHCb_7TeV_charm/src/ReactionHVQMNR_LHCb_7TeV_charm.cc
index 62fc456ba..88288808d 100644
--- a/reactions/HVQMNR_LHCb_7TeV_charm/src/ReactionHVQMNR_LHCb_7TeV_charm.cc
+++ b/reactions/HVQMNR_LHCb_7TeV_charm/src/ReactionHVQMNR_LHCb_7TeV_charm.cc
@@ -26,7 +26,7 @@ extern "C" ReactionHVQMNR_LHCb_7TeV_charm* create() {
 int ReactionHVQMNR_LHCb_7TeV_charm::initAtStart(const string &s)
 {
   // ignore provided terminfo (s): all needed information has been set already 
-  // via setDatasetParamters(int dataSetID, map<string,string> pars)
+  // via setDatasetParameters(int dataSetID, map<string,string> pars)
   
   // ******************************************************************
   // perform initialisation and pre-calculation
diff --git a/reactions/Hathor/include/ReactionHathor.h b/reactions/Hathor/include/ReactionHathor.h
index 07d2da6c7..ec872bec8 100644
--- a/reactions/Hathor/include/ReactionHathor.h
+++ b/reactions/Hathor/include/ReactionHathor.h
@@ -31,7 +31,7 @@ class ReactionHathor : public ReactionTheory
   public:
     virtual string getReactionName() const { return  "Hathor" ;};
     virtual int initAtStart(const string &);
-    virtual void setDatasetParamters(int dataSetID, map<string,string> pars, map<string,double> dsPars) override;
+    virtual void setDatasetParameters(int dataSetID, map<string,string> pars, map<string,double> dsPars) override;
     virtual int compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err);
   protected:
     virtual int parseOptions(){ return 0;};
diff --git a/reactions/Hathor/src/ReactionHathor.cc b/reactions/Hathor/src/ReactionHathor.cc
index 3c789d5ac..f12eb6df7 100644
--- a/reactions/Hathor/src/ReactionHathor.cc
+++ b/reactions/Hathor/src/ReactionHathor.cc
@@ -105,7 +105,7 @@ int ReactionHathor::initAtStart(const string &s)
   return 0;
 }
 
-void ReactionHathor::setDatasetParamters(int dataSetID, map<std::string, std::string> pars, map<std::string, double> dsPars)
+void ReactionHathor::setDatasetParameters(int dataSetID, map<std::string, std::string> pars, map<std::string, double> dsPars)
 {
   // check if dataset with provided ID already exists
   if(_hathorArray.find(dataSetID) != _hathorArray.end())
diff --git a/reactions/KFactor/include/ReactionKFactor.h b/reactions/KFactor/include/ReactionKFactor.h
index 05ec53eee..bf5b5122e 100644
--- a/reactions/KFactor/include/ReactionKFactor.h
+++ b/reactions/KFactor/include/ReactionKFactor.h
@@ -26,7 +26,7 @@ class ReactionKFactor : public ReactionTheory
   public:
     virtual string getReactionName() const { return  "KFactor" ;};
     int initAtStart(const string &);
-    virtual void setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
+    virtual void setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
     virtual int compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err);
   protected:
     virtual int parseOptions(){ return 0;};
diff --git a/reactions/KFactor/src/ReactionKFactor.cc b/reactions/KFactor/src/ReactionKFactor.cc
index c3f3f692c..34266df08 100644
--- a/reactions/KFactor/src/ReactionKFactor.cc
+++ b/reactions/KFactor/src/ReactionKFactor.cc
@@ -25,7 +25,7 @@ int ReactionKFactor::initAtStart(const string &s)
 }
 
 // Initialisze for a given dataset:
-void ReactionKFactor::setDatasetParamters(int dataSetID, map<string,string> pars, map<string, double> parsDataset)
+void ReactionKFactor::setDatasetParameters(int dataSetID, map<string,string> pars, map<string, double> parsDataset)
 {
   // check if kfactors should be read from separate file
   if (pars.find("FileName") != pars.end())
diff --git a/reactions/RT_DISNC/include/ReactionRT_DISNC.h b/reactions/RT_DISNC/include/ReactionRT_DISNC.h
index e8b2f242f..30c6930c1 100644
--- a/reactions/RT_DISNC/include/ReactionRT_DISNC.h
+++ b/reactions/RT_DISNC/include/ReactionRT_DISNC.h
@@ -23,7 +23,7 @@ class ReactionRT_DISNC : public ReactionBaseDISNC
  public:
   virtual string getReactionName() const { return  "RT_DISNC" ;};
   int initAtStart(const string &); 
-  virtual void setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
+  virtual void setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
   virtual void initAtIteration() override; 
 
  protected:
diff --git a/reactions/RT_DISNC/src/ReactionRT_DISNC.cc b/reactions/RT_DISNC/src/ReactionRT_DISNC.cc
index b959a5e1d..3f1097b4d 100644
--- a/reactions/RT_DISNC/src/ReactionRT_DISNC.cc
+++ b/reactions/RT_DISNC/src/ReactionRT_DISNC.cc
@@ -37,8 +37,8 @@ int ReactionRT_DISNC::initAtStart(const string &s)
   return isout;
 }
 
-void ReactionRT_DISNC::setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) {
-  Super::setDatasetParamters(dataSetID, pars, parsDataset);
+void ReactionRT_DISNC::setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) {
+  Super::setDatasetParameters(dataSetID, pars, parsDataset);
   // Allocate internal arrays:
   _f2rt[dataSetID].resize(GetNpoint(dataSetID));
   _flrt[dataSetID].resize(GetNpoint(dataSetID));
diff --git a/reactions/fastNLO/include/ReactionfastNLO.h b/reactions/fastNLO/include/ReactionfastNLO.h
index ac6cdab26..68b10e69e 100644
--- a/reactions/fastNLO/include/ReactionfastNLO.h
+++ b/reactions/fastNLO/include/ReactionfastNLO.h
@@ -43,7 +43,7 @@ public:
 public:
    virtual string getReactionName() const { return  "fastNLO" ;};
    int  initAtStart(const string &) { return 0; } //< nothing todo
-   virtual void setDatasetParamters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
+   virtual void setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
    virtual int compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err);
 protected:
    virtual int parseOptions(){ return 0;};
diff --git a/reactions/fastNLO/src/ReactionfastNLO.cc b/reactions/fastNLO/src/ReactionfastNLO.cc
index 4b9905f47..b6dfe30a0 100644
--- a/reactions/fastNLO/src/ReactionfastNLO.cc
+++ b/reactions/fastNLO/src/ReactionfastNLO.cc
@@ -18,7 +18,7 @@ extern "C" ReactionfastNLO* create() {
 
 //______________________________________________________________________________
 // Initialise for a given dataset:
-void ReactionfastNLO::setDatasetParamters(int ID, map<string,string> pars, map<string, double> parsDataset) {
+void ReactionfastNLO::setDatasetParameters(int ID, map<string,string> pars, map<string, double> parsDataset) {
    // ID=dataSetID
    if ( pars.count("Filename") ) {
       // --- Read file and instantiate fastNLO
diff --git a/src/TheorEval.cc b/src/TheorEval.cc
index 0a118e964..092d72433 100644
--- a/src/TheorEval.cc
+++ b/src/TheorEval.cc
@@ -463,7 +463,7 @@ TheorEval::initReactionTerm(int iterm, valarray<double> *val)
   map<string, string> pars = SplitTermInfo(term_info);
 
   // and transfer to the module
-  rt->setDatasetParamters(_dsId*1000+iterm, pars, _dsPars);
+  rt->setDatasetParameters(_dsId*1000+iterm, pars, _dsPars);
 
   _mapReactionToken[ std::pair<ReactionTheory*,int>(rt,iterm) ] = val;
 }
diff --git a/src/main.f b/src/main.f
index 46386b266..1786e736c 100644
--- a/src/main.f
+++ b/src/main.f
@@ -32,7 +32,7 @@ C-----------------------------------------------------
 *     ------------------------------------------------
 *     Print HFitter banner
 *     ------------------------------------------------
-      call hfbanner
+*     call hfbanner
 
       narg = command_argument_count()
       if (narg.gt.0) then
diff --git a/steering.txt b/steering.txt
index c2df3a7d1..7e0a11140 100644
--- a/steering.txt
+++ b/steering.txt
@@ -1,37 +1,33 @@
-*  Namelist to control input data
-*
-
 &InFiles
   ! Number of intput files
-    NInputFiles = 7
- 
+    NInputFiles = 18
   ! Input files:
-
-     InputFileNames = 
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_920-thexp.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_820-thexp.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_575-thexp.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_460-thexp.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCem-thexp.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_CCep-thexp.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_CCem-thexp.dat',
-
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_920.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_820.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_575.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_460.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCem.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_CCep.dat',
-     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_CCem.dat',
+    InputFileNames = 
+			'datafiles/E615/thexp-0.dat',
+			'datafiles/E615/thexp-1.dat',
+			'datafiles/E615/thexp-2.dat',
+			'datafiles/E615/thexp-3.dat',
+			'datafiles/E615/thexp-4.dat',
+			'datafiles/E615/thexp-5.dat',
+			'datafiles/E615/thexp-6.dat',
+			'datafiles/E615/thexp-7.dat',
+			'datafiles/E615/thexp-8.dat',
+			'datafiles/E615/thexp-9.dat',
+			'datafiles/E615/thexp-10.dat',
+			'datafiles/E615/thexp-11.dat',
+			'datafiles/E615/thexp-12.dat',
+			'datafiles/E615/thexp-13.dat',
+			'datafiles/E615/thexp-14.dat',
+			'datafiles/E615/thexp-15.dat',
+			'datafiles/E615/thexp-16.dat',
+			'datafiles/E615/thexp-17.dat',
     ! 'Z0_applgrid_nnlo_reaction.dat', 'D0_Wel_pt25_asymmetry.dat'
     ! 'datafiles/lhc/atlas/wzProduction/1203.4051/Z0_applgrid_nnlo.dat',
-
 &End
 
 &InCorr
   ! Number of correlation (statistical, systematical or full) files
     NCorrFiles = 0
- 
   ! Correlation files:
   !  CorrFileNames(1) = 'datafiles/hera/h1/jets/0904.3870/H1_NormInclJets_HighQ2_99-07___H1_NormInclJets_HighQ2_99-07.corr'
 &End
@@ -46,22 +42,18 @@
 &End
 
 &sumrule_sums
-	! Constant number of valence u- and d- quarks to be used in sum rules
-	! Change for hadrons other than proton
-  uvalSum=2.
+  uvalSum=-1.
   dvalSum=1.
+  !svalSum=0.!not implemented
 &end
 
 &CovarToNuisance
    ! Global switch for using nuisance param representation for covariance mat.
   LConvertCovToNui = .False.
-
    ! Tolerance -- zero means exact transformation
   Tolerance = 0.0
-
    ! (Optional) -- try to subtract diagonal stat. uncertainties from total covariance when determining uncorrelated uncertainites
   LSubtractStat = .false.
-
    ! The following lines allow to adjust error scaling properties (default: :M)
   DataName     = 'CMS electon Asymmetry rapidity', 'CMS W muon asymmetry'
   DataSystType = ':A', ':A'
@@ -125,9 +117,9 @@
                                 !uPDF4 fit calculating kernel on fly, grid of sigma_hat
 
 
-  Order  = 'NNLO'       ! 'LO', 'NLO' or 'NNLO', used for DGLAP evolution.
+  Order  = 'LO'       ! 'LO', 'NLO' or 'NNLO', used for DGLAP evolution.
 
-  Q02     = 1.9 ! Evolution starting scale
+  Q02     = 0.4 ! Evolution starting scale
 
  ! --- Scheme for heavy flavors 
  ! ---  HF_SCHEME = 'ZMVFNS'           : ZM-VFNS (massless) from QCDNUM,
@@ -178,7 +170,7 @@
  !  'DDIS'        -- use Diffractive DIS 
  !  'BiLog'       -- bi-lognormal parametrisation 
 
-  PDFStyle = 'HERAPDF'
+  PDFStyle='HERAPDF'
 
  ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  !
@@ -200,7 +192,8 @@
  !  'ExtraSystRescale'      : additional re-scaling of stat. uncertainty to account for syst. shifts.
 
    CHI2SettingsName = 'StatScale', 'UncorSysScale', 'CorSysScale', 'UncorChi2Type', 'CorChi2Type'
-   Chi2Settings     = 'Poisson'  , 'Linear',        'Linear'     , 'Diagonal'     , 'Hessian'
+ ! Chi2Settings     = 'Poisson'  , 'Linear',        'Linear'     , 'Diagonal'     , 'Hessian'
+   Chi2Settings     = 'NoRescale'  , 'NoRescale',        'NoRescale'     , 'Diagonal'     , 'Hessian'
    Chi2ExtraParam = 'PoissonCorr'
 
  ! Flag to define if native APPLgrid CKM values should be kept.
@@ -397,10 +390,10 @@
 &End
 
 *
-* (Optional) LHAPDF sttering card
+* (Optional) LHAPDF steering card
 *
 &lhapdf
-  LHAPDFSET  = 'CT10nlo'               ! LHAPDF grid file 
+  LHAPDFSET='GRVPI0'                  ! LHAPDF grid file 
   ILHAPDFSET = 0                       ! Set a PDF member of the PDF set (use together with LHAPDFPROFILE = False)
   ! LHAPDFVARSET = 'HERAPDF20_NLO_VAR' ! Add a PDF set with model and parametrisation uncertainties
   ! NPARVAR = 3                        ! Number of parametrisation uncertainties in the LHAPDFVARSET set
-- 
GitLab


From a93fab45525f00257f733a2929b3a26db3397424 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Mon, 6 Aug 2018 13:45:52 +0200
Subject: [PATCH 06/26] APPLgrid reaction module: option to select memberID of
 LHAPDF set via datafile

---
 reactions/APPLgrid/src/ReactionAPPLgrid.cc | 36 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/reactions/APPLgrid/src/ReactionAPPLgrid.cc b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
index 922585eaf..d5b7c0de8 100644
--- a/reactions/APPLgrid/src/ReactionAPPLgrid.cc
+++ b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
@@ -69,23 +69,47 @@ void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pa
      hf_errlog_(17032801,text.c_str(),text.size());
    }
 
+//Initialize for LHAPDF
+//To be used when PDF of second particle is static and of LHAPDF
+//Parameters are passed via TermInfo in theory expression in datafile:
+//*LHAPDF_SetName
+//*LHAPDF_MemberID --- defaults to 0
+#ifdef LHAPDF_ENABLED
+	{
 	it=pars.find("LHAPDF_SetName");
+	auto itMemberID=pars.find("LHAPDF_MemberID");
 	if(it!=pars.end()){
-#ifdef LHAPDF_ENABLED
-		//To be used when PDF of second particle is static and of LHAPDF
+		int member_id=0;
+		try{
+			if(itMemberID!=pars.end())member_id=std::stoi(itMemberID->second);
+		}catch(const std::exception&ex){
+			std::ostringstream s;
+			s<<"F:Failed to read PDF memberID for LHAPDF set \""<<it->second<<"\" for use with APPLgrid; dataSetID="<<dataSetID;
+			s<<"; Exception:"<<ex.what();
+			hf_errlog(3081810,s.str().c_str());
+		}
 		//Make sure to set collision=LHAPDF
 		//std::cout<<"DEBUG LHAPDF_SetName="<<it->second<<std::endl;
-		LHAPDF::PDF*p=LHAPDF::mkPDF(it->second,0);
+		LHAPDF::PDF*p=LHAPDF::mkPDF(it->second,member_id);
 		if(!p){
 			std::ostringstream s;
 			s<<"F:LHAPDF failed to load PDF set \""<<it->second<<"\" for use with APPLgrid; dataSetID="<<dataSetID;
 			hf_errlog(28071810,s.str().c_str());
 		}
 		lhapdf_pdf[dataSetID]=p;
+	}else{
+		if(itMemberID!=pars.end()){
+			std::ostringstream s;
+			s<<"W: In APPLgrid reaction parameters (dataSetID="<<dataSetID<<") memberID="<<itMemberID->second<<" is given, but set itself is not";
+			hf_errlog(3081811,s.str().c_str());
+		}
+	}
+	}
 #else
-		hf_errlog(25071812,"F:LHAPDF Set specified for APPLgrid reaction, but xFitter has been compiled without LHAPDF. Use --enable-lhapdf at configure to enable.")
-#endif
+	if(pars.find("LHAPDF_SetName")!=pars.end()||pars.find("LHAPDF_MemberID")!=pars.end()){
+		hf_errlog(25071812,"F:LHAPDF parameter specified for APPLgrid reaction, but xFitter has been compiled without LHAPDF. Use --enable-lhapdf at configure to enable.")
 	}
+#endif
 
 // Determine order
    int order = OrderMap( GetParamS("Order"));  // Global order
@@ -119,7 +143,7 @@ void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pa
     else if(it->second=="pn")    _collType[dataSetID]=collision::pn;
 		else if(it->second=="LHAPDF"){
 			_collType[dataSetID]=collision::LHAPDF;
-			if(lhapdf_pdf.find(dataSetID)==lhapdf_pdf.end())hf_errlog(24071810,"F: collision type=LHAPDF but no LHAPDF set was loaded");
+			if(lhapdf_pdf.find(dataSetID)==lhapdf_pdf.end())hf_errlog(24071810,"W: collision type=LHAPDF but no LHAPDF set was loaded");
 		}
     else
       hf_errlog(17102101, "F: unrecognised collision type = " + it->second);
-- 
GitLab


From b6af3e8e02ee29909a4b3b857a8272ffa0d0967d Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Thu, 16 Aug 2018 13:36:51 +0200
Subject: [PATCH 07/26] Fix build errors and bugs in GRV_PionPdfDecomposition

---
 Makefile.am                                   | 21 ++++-----
 Reactions.txt                                 |  2 +-
 configure.ac                                  |  1 +
 doxygen.cfg                                   |  6 ++-
 .../include/GRV_PionPdfDecomposition.h        |  1 +
 .../src/GRV_PionPdfDecomposition.cc           | 44 +++++--------------
 .../GRV_PionPdfDecomposition/src/Makefile.am  |  8 +++-
 pdfparams/BasePdfParam/include/BasePdfParam.h |  2 +-
 8 files changed, 36 insertions(+), 49 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 5592d1506..9754c60b0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,32 +1,33 @@
 ACLOCAL_AMFLAGS=-I m4
 AUTOMAKE_OPTIONS = foreign
 SUBDIRS = minuit/src interfaces/src DY/src DIPOLE/src RT/src EW/src common common/linalg \
-	common/num_utils pdf2yaml tools/process  \
-	tools/draw tools/MakeLHAPDF FastNLO/src DiffDIS/src ACOT/src SACOT/src ABM/src FONLL/src Cascade/src \
-	genetic/mixmax_r004 genetic/src QEDevol/src \
-	include interfaces/include FastNLO/include FastNLO/include/fastnlotk DiffDIS/include \
-	DY/include tools/draw/include \
-	reactions/KFactor/src \
+        common/num_utils pdf2yaml tools/process  \
+        tools/draw tools/MakeLHAPDF FastNLO/src DiffDIS/src ACOT/src SACOT/src ABM/src FONLL/src Cascade/src \
+        genetic/mixmax_r004 genetic/src QEDevol/src \
+        include interfaces/include FastNLO/include FastNLO/include/fastnlotk DiffDIS/include \
+        DY/include tools/draw/include \
+        reactions/KFactor/src \
         reactions/Fractal_DISNC/src \
         reactions/BaseDISCC/src \
         reactions/Hathor/src \
         reactions/BaseDISNC/src \
-	reactions/RT_DISNC/src \
+        reactions/RT_DISNC/src \
         reactions/FFABM_DISNC/src \
         reactions/FFABM_DISCC/src \
         reactions/APPLgrid/src \
         reactions/BaseHVQMNR/src \
-	reactions/HVQMNR_LHCb_7TeV_beauty/src \
+        reactions/HVQMNR_LHCb_7TeV_beauty/src \
         reactions/HVQMNR_LHCb_7TeV_charm/src \
         reactions/testZMVFNS/src \
         reactions/fastNLO/src/ \
-	reactions/FONLL_DISCC/src \
+        reactions/FONLL_DISCC/src \
         reactions/FONLL_DISNC/src \
         pdfparams/BasePdfParam/src \
-	pdfparams/HERAPDF_PdfParam/src \
+        pdfparams/HERAPDF_PdfParam/src \
         pdfdecompositions/BasePdfDecomposition/src \
         pdfdecompositions/LHAPDFDecomposition/src \
         pdfdecompositions/UvDvUbarDbarS/src \
+        pdfdecompositions/GRV_PionPdfDecomposition/src \
         evolutions/BaseEvolution/src \
         evolutions/APFELxx/src \
         minimizers/BaseMinimizer/src
diff --git a/Reactions.txt b/Reactions.txt
index a3de58155..0cba80323 100644
--- a/Reactions.txt
+++ b/Reactions.txt
@@ -17,4 +17,4 @@ FONLL_DISCC libfonll_discc_xfitter.so
 BaseEvolution libbaseevolution_xfitter.so
 APFELxx libapfelxx_xfitter.so
 UvDvubardbars libuvdvubardbars_xfitter.so
-GRV_PionPdfDecomposition libgrv_pionpdfdecomposition_xfitter.so
+GRV_PionPdfDecomposition libGRV_PionPdfDecomposition_xfitter.so
diff --git a/configure.ac b/configure.ac
index b874f4e3e..129f939a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -583,6 +583,7 @@ AC_CONFIG_FILES([include/Makefile
 		 pdfparams/HERAPDF_PdfParam/src/Makefile
 		 pdfdecompositions/LHAPDFDecomposition/src/Makefile
 		 pdfdecompositions/UvDvUbarDbarS/src/Makefile
+		 pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile
 		 pdfdecompositions/BasePdfDecomposition/src/Makefile
 		 reactions/KFactor/src/Makefile
 		 reactions/BaseDISCC/src/Makefile
diff --git a/doxygen.cfg b/doxygen.cfg
index b103591a1..d94a742d7 100644
--- a/doxygen.cfg
+++ b/doxygen.cfg
@@ -583,8 +583,10 @@ INPUT                  = include src \
                          reactions/HVQMNR_LHCb_7TeV_beauty/include \
                          reactions/HVQMNR_LHCb_7TeV_beauty/src \
 			 pdfparams/BasePdfParam/include  pdfparams/HERAPDF_PdfParam/include \
-			 pdfdecompositions/BasePdfDecomposition/include  pdfdecompositions/LHAPDFDecomposition/include \
-			 pdfdecompositions/UvDvUbarDbarS/include
+			 pdfdecompositions/BasePdfDecomposition/include \
+			 pdfdecompositions/LHAPDFDecomposition/include \
+			 pdfdecompositions/UvDvUbarDbarS/include \
+			 pdfdecompositions/GRV_PionPdfDecomposition/include
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
 # also the default input encoding. Doxygen uses libiconv (or the iconv built
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h b/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
index 465644ff1..2e6f84449 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
@@ -32,6 +32,7 @@ class GRV_PionPdfDecomposition:public BasePdfDecomposition{
 		GRV_PionPdfDecomposition(const std::string& inName);
 		~GRV_PionPdfDecomposition();
 		virtual void initAtStart(const std::string & pars) override final;
+		virtual void initAtIteration()override final;
 		virtual std::function<std::map<int,double>(const double& x)>f0()const override final; 
 	private:
 		BasePdfParam*par_v,*par_qbar,*par_g;
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc b/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
index 8cad3faa5..2b6557507 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
@@ -5,16 +5,10 @@
    Created by  AddPdfDecomposition.py on GRV_Pion
 */
 #include"GRV_PionPdfDecomposition.h"
+#include"HERAPDF_PdfParam.h" //This is for hacks, remove later
+#include"xfitter_pars.h"
 using uint=unsigned int;
 using namespace std;
-void initParameterisation(BasePdfParam*prm,const string&decompositionName){
-	const uint N=prm->getNPar();
-	prm->pars=new double*[N];
-	const string prefix=decompositionName+"_"+prm->getName()+"_p";
-	for(uint i=0;i<N;++i){
-		prm->pars[i]=XFITTER_PARS::gParameters[prefix+to_string(i)];
-	}
-}
 namespace xfitter{
 //For dynamic loading:
 extern "C" GRV_PionPdfDecomposition*create(){
@@ -34,35 +28,19 @@ GRV_PionPdfDecomposition::~GRV_PionPdfDecomposition(){
 // Init at start:
 void GRV_PionPdfDecomposition::initAtStart(const std::string & pars){
 	//HARDCODE copied from UvDvUbarDbarS, then modified
-	//TO BE REPLACED LATER
+	//The following is not very nice: Decomposition should not create or initialize parameterisations
+	//Create and initialize paramterisations
 	for(const auto&node:XFITTER_PARS::gParametersY.at("GRV_PionPdfDecomposition")["HERAPDF_pdfparam"]){
 		const string prmzName=node.first.as<string>();//Name of parameterisation
 		BasePdfParam*pParam=new HERAPDF_PdfParam(prmzName);
-		double*parValues=pParam->initFromYaml(node.second);//Parameters of the parameterisation
-		//Register parameters of this parameterisation in the global parameter map
-		for(int i=0;i<pParam->getNPar();i++){
-			double val     =parValues[i];
-			double step    =std::fabs(val)/100.;       /// if 0, parameter is fixed !!! 
-			double minv    =0;//0 means no bounds for minuit
-			double maxv    =0;
-			double priorVal=0;
-			double priorUnc=0;
-			int    add     =true;
-			std::ostringstream ss;
-			ss<<getName()<<'_'<<prmzName<<"_p"<<i;
-			const sring pnam=ss.str();
-			std::cout<<"INFO[GRV_PionPdfDecomposition]: Registering parameter "<<ss<<"="<<val<<std::endl;
-			/// Here it goes to minuit:
-			addexternalparam_(pnam.c_str(),val,step,minv,maxv,priorVal,priorUnc,add,&XFITTER_PARS::gParameters,pnam.size() );
-		}
-    addParameterisation(pdfName,pParam);
-  }
-//The following is not very nice: Decomposition should not create or initialize parameterisations
-	par_v   =initParameterisation(getPdfParam("v   "),getName());
-	par_qbar=initParameterisation(getPdfParam("qbar"),getName());
-	par_g   =initParameterisation(getPdfParam("g   "),getName());
+		pParam->initFromYaml(node.second);
+		addParameterisation(prmzName,pParam);
+	}
+	par_v   =getPdfParam("v");
+	par_qbar=getPdfParam("qbar");
+	par_g   =getPdfParam("g");
 }
-void GRV_PionPdfDecomposition:initAtIteration() {
+void GRV_PionPdfDecomposition::initAtIteration() {
 	//Enforce sum rules
 	//Valence sum
 	par_v->setMoment(-1,2);
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am b/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am
index 49ee9e52a..730590db5 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am
@@ -1,12 +1,16 @@
 
 # Created by AddPdfDecomposition.py on 2018-08-07
 
-AM_CXXFLAGS = -I$(srcdir)/../include  -I$(srcdir)/../../../include  -I$(srcdir)/../../../pdfparams/BasePdfParam/include/   -I$(srcdir)/../../BasePdfDecomposition/include -Wall -fPIC -Wno-deprecated 
+AM_CXXFLAGS = -I$(srcdir)/../include  -I$(srcdir)/../../../include -I$(srcdir)/../../../pdfparams/BasePdfParam/include/   -I$(srcdir)/../../BasePdfDecomposition/include -Wall -fPIC -Wno-deprecated \
+              -I$(srcdir)/../../../pdfparams/HERAPDF_PdfParam/include/ #Hacks - remove later
 
-lib_LTLIBRARIES = libGRV_PionPdfDecomposition_xfitter.la
+lib_LTLIBRARIES=libGRV_PionPdfDecomposition_xfitter.la
 libGRV_PionPdfDecomposition_xfitter_la_SOURCES = GRV_PionPdfDecomposition.cc
 
 datadir = ${prefix}/yaml/pdfdecompositions/GRV_Pion
 data_DATA = ../yaml/parameters.yaml
 
 dist_noinst_HEADERS = ../include ../yaml
+
+# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx  HERAPDF is temporary 
+libGRV_PionPdfDecomposition_xfitter_la_LDFLAGS=-lHERAPDF_PdfParam_xfitter -lBasePdfParam_xfitter -L$(libdir)
diff --git a/pdfparams/BasePdfParam/include/BasePdfParam.h b/pdfparams/BasePdfParam/include/BasePdfParam.h
index fa279bfdc..cc24d5d67 100644
--- a/pdfparams/BasePdfParam/include/BasePdfParam.h
+++ b/pdfparams/BasePdfParam/include/BasePdfParam.h
@@ -27,7 +27,7 @@
 class BasePdfParam{
 public:
   BasePdfParam(const std::string&instance_name):_name(instance_name),pars{nullptr},Npars(0){}
-  ~BasePdfParam(){if(pars)delete[]pars;}
+  virtual~BasePdfParam(){if(pars)delete[]pars;}
   void               setNPar(unsigned int N){Npars=N;}
   const unsigned int getNPar()const{return Npars;}
   //!Evaluate xf(x) at given x with current parameters, pure virtual
-- 
GitLab


From d0a43e29143066a900896388b9cf24c6c1c362bc Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Fri, 17 Aug 2018 15:18:10 +0200
Subject: [PATCH 08/26] Analytical expressions for moments for HERAPDF_PdfParam
 and a new parameterisation PolySqrtPdfParam

---
 Makefile.am                                   |  1 +
 configure.ac                                  |  1 +
 doxygen.cfg                                   |  4 +-
 .../include/HERAPDF_PdfParam.h                |  1 +
 .../HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc  | 36 +++++++---
 .../include/PolySqrtPdfParam.h                | 34 ++++++++++
 pdfparams/PolySqrtPdfParam/src/Makefile.am    | 12 ++++
 .../PolySqrtPdfParam/src/PolySqrtPdfParam.cc  | 66 +++++++++++++++++++
 8 files changed, 146 insertions(+), 9 deletions(-)
 create mode 100644 pdfparams/PolySqrtPdfParam/include/PolySqrtPdfParam.h
 create mode 100644 pdfparams/PolySqrtPdfParam/src/Makefile.am
 create mode 100644 pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc

diff --git a/Makefile.am b/Makefile.am
index 13c7868a3..43a6b17af 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,7 @@ SUBDIRS = minuit/src interfaces/src DY/src DIPOLE/src RT/src EW/src common commo
         reactions/FONLL_DISNC/src \
         pdfparams/BasePdfParam/src \
         pdfparams/HERAPDF_PdfParam/src \
+        pdfparams/PolySqrtPdfParam/src \
         pdfdecompositions/BasePdfDecomposition/src \
         pdfdecompositions/LHAPDFDecomposition/src \
         pdfdecompositions/UvDvUbarDbarS/src \
diff --git a/configure.ac b/configure.ac
index 104cd36d3..671921a4d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -584,6 +584,7 @@ AC_CONFIG_FILES([include/Makefile
 		 evolutions/QCDNUM/src/Makefile
 		 pdfparams/BasePdfParam/src/Makefile
 		 pdfparams/HERAPDF_PdfParam/src/Makefile
+		 pdfparams/PolySqrtPdfParam/src/Makefile
 		 pdfdecompositions/LHAPDFDecomposition/src/Makefile
 		 pdfdecompositions/UvDvUbarDbarS/src/Makefile
 		 pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile
diff --git a/doxygen.cfg b/doxygen.cfg
index 2539ac092..4cb5c60aa 100644
--- a/doxygen.cfg
+++ b/doxygen.cfg
@@ -582,7 +582,9 @@ INPUT                  = include src \
                          reactions/BaseHVQMNR/src 
                          reactions/HVQMNR_LHCb_7TeV_beauty/include \
                          reactions/HVQMNR_LHCb_7TeV_beauty/src \
-			 pdfparams/BasePdfParam/include  pdfparams/HERAPDF_PdfParam/include \
+			 pdfparams/BasePdfParam/include \
+			 pdfparams/HERAPDF_PdfParam/include \
+			 pdfparams/PolySqrtPdfParam/include \
 			 pdfdecompositions/BasePdfDecomposition/include \
 			 pdfdecompositions/LHAPDFDecomposition/include \
 			 pdfdecompositions/UvDvUbarDbarS/include \
diff --git a/pdfparams/HERAPDF_PdfParam/include/HERAPDF_PdfParam.h b/pdfparams/HERAPDF_PdfParam/include/HERAPDF_PdfParam.h
index f16ce7f9e..68aede0ed 100644
--- a/pdfparams/HERAPDF_PdfParam/include/HERAPDF_PdfParam.h
+++ b/pdfparams/HERAPDF_PdfParam/include/HERAPDF_PdfParam.h
@@ -25,4 +25,5 @@ class HERAPDF_PdfParam:public BasePdfParam{
   public:
     HERAPDF_PdfParam(const std::string&inName):BasePdfParam(inName){}
     virtual double operator()(double x)const override final;
+    virtual double moment(int nMoment=-1)const override final;
 };
diff --git a/pdfparams/HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc b/pdfparams/HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc
index dd9336dd1..13b97110f 100644
--- a/pdfparams/HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc
+++ b/pdfparams/HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc
@@ -23,11 +23,31 @@ double HERAPDF_PdfParam::operator()(double x)const{
   }
   return power*poly;
 }
-
-// Optional function to compute integrals:
-
-// double HERAPDF_PdfParam::moment( double const* pars, int const iMoment)
-// {
-//   return 0
-// }
-
+double HERAPDF_PdfParam::moment(int n)const{
+  //Integral of HERAPDF-style function is expressed in terms of Euler beta function:
+  //beta(x,y)=int_0^1 t^(x-1)*(1-t)^(y-1) dx=gamma(x)*gamma(y)/gamma(x+y)
+  //moment(n)=int_0^1 P[0]*x^(P[1]+n)*(1-x)^P[2]*(1+sum_{i=3}^N{P[i]*x^(i-2)})
+  //Let A:=P[0], B:=P[1]+n+1, C:=P[2]+1, then
+  //moment=int_0^1 A*x^(B-1)*(1-x)^(C-1)*(1+sum_{i=3}^N{P[i]*x^(i-2)})
+  //=A*(beta(B,C)+sum_{i=3}^N{P[i]*beta(B+i-2,C)})
+  //beta(B+1,C)=B/(B+C)
+  //=> beta(B+n,C)=beta(B,C)*product_{k=0}^{n-1}{(B+k)/(B+C+k)}
+  //=> beta(B+i-2,C)=beta(B,C)*product_{k=0}^{i-3}{(B+k)/(B+C+k)}
+  //=> moment=A*beta(B,C)*(1+sum_{i=3}^N{P[i]*product_{k=0}^{i-3}{(B+k)/(B+C+k)}})=
+  //=> moment=A*beta(B,C)*(1+P[3]*B/(B+C)+P[4]*B/(B+C)*(B+1)/(B+C+1)+...)
+  //beta(B,C)=exp(lgamma(B)+lgamma(C)-lgamma(B+C))
+  using uint=unsigned int;
+  const double B=(*pars[1])+(n+1),C=(*pars[2])+1;
+  const uint N=getNPar();
+  double sum=1;
+  double prod=1;
+  double a=B;
+  double b=B+C;
+  for(uint i=3;i<N;++i){
+    prod=prod*a/b;
+    sum+=(*pars[i])*prod;
+    a++;
+    b++;
+  }
+  return (*pars[0])*exp(lgamma(B)+lgamma(C)-lgamma(B+C))*sum;
+}
diff --git a/pdfparams/PolySqrtPdfParam/include/PolySqrtPdfParam.h b/pdfparams/PolySqrtPdfParam/include/PolySqrtPdfParam.h
new file mode 100644
index 000000000..eeb2a880c
--- /dev/null
+++ b/pdfparams/PolySqrtPdfParam/include/PolySqrtPdfParam.h
@@ -0,0 +1,34 @@
+
+#pragma once
+
+#include "BasePdfParam.h"
+
+/**
+  @class PolySqrtPdfParam 
+
+  @brief A class for PolySqrt pdf parameterisation
+
+  xf(x)=A*x^B*(1-x)^C*(1+P(sqrt(x)))
+  where P(sqrt(x)) is a polynomial of sqrt(x) with other parameters as coefficients:
+  P(sqrt(x))=D*sqrt(x)+E*x+F*x*sqrt(x)+...
+
+  Number of parameters may vary, but at least 3, corresponding to A,B,C
+
+  In terms of indexed parameters:
+  xf(x)=par_0*x^par_1*(1-x)^par_2*(1+sum_{i=3}^{N}{par_i*x^(i/2-1)})
+
+  @version 0.1
+  @date 2018-08-16
+  */
+
+class PolySqrtPdfParam:public BasePdfParam{
+  public:
+    PolySqrtPdfParam(const std::string&inName):BasePdfParam(inName){}
+    virtual double operator()(double x)const override final;
+    virtual double moment(int nMoment=-1)const override final;
+    // (Optional) set moments:
+    // virtual void setMoment(int nMoment,double value)override final;
+    // (Optional)
+    //Initialize from a yaml node. Uses node[getName] as the basis
+    // virtual void initFromYaml(YAML::Node value)override final;
+};
diff --git a/pdfparams/PolySqrtPdfParam/src/Makefile.am b/pdfparams/PolySqrtPdfParam/src/Makefile.am
new file mode 100644
index 000000000..6cf1672ff
--- /dev/null
+++ b/pdfparams/PolySqrtPdfParam/src/Makefile.am
@@ -0,0 +1,12 @@
+
+# Created by AddPdfParam.py on 2018-08-16
+
+AM_CXXFLAGS = -I$(srcdir)/../include  -I$(srcdir)/../../../include  -I$(srcdir)/../../BasePdfParam/include -Wall -fPIC -Wno-deprecated 
+
+lib_LTLIBRARIES = libPolySqrtPdfParam_xfitter.la
+libPolySqrtPdfParam_xfitter_la_SOURCES = PolySqrtPdfParam.cc
+
+datadir = ${prefix}/yaml/pdfparams/PolySqrt
+data_DATA = ../yaml/parameters.yaml
+
+dist_noinst_HEADERS = ../include ../yaml
diff --git a/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc b/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc
new file mode 100644
index 000000000..b4c69985d
--- /dev/null
+++ b/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc
@@ -0,0 +1,66 @@
+ 
+/*
+   @file PolySqrtPdfParam.cc
+   @date 2018-08-16
+   @author AddPdfParam.py
+   Created by AddPdfParam.py on 2018-08-16
+*/
+
+#include"PolySqrtPdfParam.h"
+#include<cmath>
+using namespace std;
+using uint=unsigned int;
+double PolySqrtPdfParam::operator()(double x)const{
+	const uint N=getNPar();
+	double pol=1;
+	double mulx=1;
+	double sqrtx=sqrt(x);
+	for(uint i=3;i<N;++i){
+		mulx*=sqrtx;
+		pol+=(*pars[i])*mulx;
+	}
+	return(*pars[0])*pow(x,(*pars[1]))*pow((1-x),(*pars[2]))*pol;
+}
+double PolySqrtPdfParam::moment(int n)const{
+  //Integral of PolySqrtPdfParam-style function is expressed in terms of Euler beta function:
+  //beta(x,y)=int_0^1 t^(x-1)*(1-t)^(y-1) dx=gamma(x)*gamma(y)/gamma(x+y)
+  //beta(B,C)=exp(lgamma(B)+lgamma(C)-lgamma(B+C))
+  //moment(n)=int_0^1 P[0]*x^(P[1]+n)*(1-x)^P[2]*(1+sum_{i=3}^N{P[i]*x^(i/2-1)})
+  //Let A:=P[0], B:=P[1]+n+1, C:=P[2]+1, then
+  //moment=int_0^1 A*x^(B-1)*(1-x)^(C-1)*(1+sum_{i=3}^N{P[i]*x^(i/2-1)})
+  //=A*(beta(B,C)+sum_{i=3}^N{P[i]*beta(B+i/2-1,C)})=
+  //=A*(beta(B,C)+sum(i=3;i<=N;i+=2){P[i]*beta(B+i/2-1,C)}+sum(i=4;i<=N;i+=2){P[i]*beta(B+i/2-1,C)})
+  //=A*(beta(B,C)+sum(k=0;3+2k<=N;k++){P[3+2k]*beta(B+k+1/2,C)}+sum(k=1;2+2k<=N;k++){P[2+2k]*beta(B+k,C)})
+  //beta(B+1,C)=B/(B+C)
+  //=> beta(B+k,C)=beta(B,C)*product_{i=0}^{k-1}{(B+i)/(B+C+i)}
+  //=> beta(B+k+1/2,C)=beta(B+1/2,C)*product_{i=0}^{k-1}{(B+1/2+i)/(B+C+1/2+i)}
+  //=> moment=A*(beta(B,C)*(1+sum(k=1;2+2k<=N;k++){P[2+2k]*product_{i=0}^{k-1}{(B+i)/(B+C+i)}})+beta(B+1/2,C)*sum(k=0;3+2k<=N;k++){P[3+2k]*product_{i=0}^{k-1}{(B+1/2+i)/(B+C+1/2+i)}})
+  using uint=unsigned int;
+  const double B=(*pars[1])+(n+1),C=(*pars[2])+1;
+  const uint N=getNPar();
+  double sum=1;
+  double prod=1;
+  double a=B;
+  double b=B+C;
+  for(uint i=4;i<N;i+=2){
+    prod=prod*a/b;
+    sum+=(*pars[i])*prod;
+    a++;
+    b++;
+  }
+	double lgammaC=lgamma(C);
+	double ret=exp(lgamma(B)+lgammaC-lgamma(B+C))*sum;
+	sum=0;
+	prod=1;
+	a=B+0.5;
+	b=a+C;
+  for(uint i=3;i<N;i+=2){
+    sum+=(*pars[i])*prod;
+    prod=prod*a/b;
+    a++;
+    b++;
+  }
+	ret+=exp(lgamma(B+0.5)+lgammaC-lgamma(B+C+0.5))*sum;
+	ret*=(*pars[0]);
+  return ret;
+}
-- 
GitLab


From cf0129f22344fe2fcbd27b0f1bfe8d24983ea301 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Sat, 18 Aug 2018 18:21:54 +0200
Subject: [PATCH 09/26] Fix incorrect definition of qbar in GRV_Pion
 decomposition

---
 .../include/GRV_PionPdfDecomposition.h               | 10 +++++-----
 .../src/GRV_PionPdfDecomposition.cc                  | 12 ++++++------
 .../GRV_PionPdfDecomposition/src/Makefile.am         |  6 +++---
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h b/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
index 2e6f84449..ed122cbd2 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
@@ -11,17 +11,17 @@
     dbar=u
     s=sbar=0
   Parametrised distributions are:
-    v   := dval-uval
-    qbar:=(ubar+dbar)/2
+    v   := dval-uval=2*(d-u)
+    qbar:=(u+dbar)/2=u
     g
   Therefore, transformations to physical basis:
-    u=dbar=qbar-v/4
-    d=ubar=qbar+v/4
+    u=dbar=qbar
+    d=ubar=qbar+v/2
     g=g
     others=0
   And sum rules for pi- are:
     \int_0^1 v dx=2
-    \int_0^1 x*(4*qbar+g) dx=1
+    \int_0^1 x*(4*qbar+v+g) dx=1
   @version 0.2
   @date 2018-08-14
   */
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc b/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
index 2b6557507..3729ce656 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
@@ -5,7 +5,7 @@
    Created by  AddPdfDecomposition.py on GRV_Pion
 */
 #include"GRV_PionPdfDecomposition.h"
-#include"HERAPDF_PdfParam.h" //This is for hacks, remove later
+#include"PolySqrtPdfParam.h" //This is for hacks, remove later
 #include"xfitter_pars.h"
 using uint=unsigned int;
 using namespace std;
@@ -30,9 +30,9 @@ void GRV_PionPdfDecomposition::initAtStart(const std::string & pars){
 	//HARDCODE copied from UvDvUbarDbarS, then modified
 	//The following is not very nice: Decomposition should not create or initialize parameterisations
 	//Create and initialize paramterisations
-	for(const auto&node:XFITTER_PARS::gParametersY.at("GRV_PionPdfDecomposition")["HERAPDF_pdfparam"]){
+	for(const auto&node:XFITTER_PARS::gParametersY.at("GRV_PionPdfDecomposition")["HARDWIRED_PolySqrt"]){
 		const string prmzName=node.first.as<string>();//Name of parameterisation
-		BasePdfParam*pParam=new HERAPDF_PdfParam(prmzName);
+		BasePdfParam*pParam=new PolySqrtPdfParam(prmzName);
 		pParam->initFromYaml(node.second);
 		addParameterisation(prmzName,pParam);
 	}
@@ -45,7 +45,7 @@ void GRV_PionPdfDecomposition::initAtIteration() {
 	//Valence sum
 	par_v->setMoment(-1,2);
 	//Momentum sum
-	par_g->setMoment(0,1-4*par_qbar->moment(0));
+	par_g->setMoment(0,1-4*par_qbar->moment(0)-par_v->moment(0));
 }
 // Returns a LHAPDF-style function, that returns PDFs in a physical basis for given x
 std::function<std::map<int,double>(const double& x)>GRV_PionPdfDecomposition::f0()const{
@@ -53,8 +53,8 @@ std::function<std::map<int,double>(const double& x)>GRV_PionPdfDecomposition::f0
 		double v   =(*par_v)(x);
 		double qbar=(*par_qbar)(x);
 		double g   =(*par_g)(x);
-		double u=qbar-v/4;
-		double d=qbar+v/4;
+		double u=qbar;
+		double d=qbar+v/2;
 		std::map<int,double>res_={
 			{-6,0},
 			{-5,0},
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am b/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am
index 730590db5..e385b63dc 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am
@@ -2,7 +2,7 @@
 # Created by AddPdfDecomposition.py on 2018-08-07
 
 AM_CXXFLAGS = -I$(srcdir)/../include  -I$(srcdir)/../../../include -I$(srcdir)/../../../pdfparams/BasePdfParam/include/   -I$(srcdir)/../../BasePdfDecomposition/include -Wall -fPIC -Wno-deprecated \
-              -I$(srcdir)/../../../pdfparams/HERAPDF_PdfParam/include/ #Hacks - remove later
+              -I$(srcdir)/../../../pdfparams/PolySqrtPdfParam/include/ #Hacks - remove later
 
 lib_LTLIBRARIES=libGRV_PionPdfDecomposition_xfitter.la
 libGRV_PionPdfDecomposition_xfitter_la_SOURCES = GRV_PionPdfDecomposition.cc
@@ -12,5 +12,5 @@ data_DATA = ../yaml/parameters.yaml
 
 dist_noinst_HEADERS = ../include ../yaml
 
-# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx  HERAPDF is temporary 
-libGRV_PionPdfDecomposition_xfitter_la_LDFLAGS=-lHERAPDF_PdfParam_xfitter -lBasePdfParam_xfitter -L$(libdir)
+# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx These hacks are temporary 
+libGRV_PionPdfDecomposition_xfitter_la_LDFLAGS=-lPolySqrtPdfParam_xfitter -lBasePdfParam_xfitter -L$(libdir)
-- 
GitLab


From 332e39ecbaa94f841f7f967d564094e1d7de516d Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Mon, 20 Aug 2018 16:15:40 +0200
Subject: [PATCH 10/26] Change GRV_Pion decomposition to use fs --- strange
 fraction

---
 .../include/GRV_PionPdfDecomposition.h        | 12 +++++++++--
 .../src/GRV_PionPdfDecomposition.cc           |  9 ++++++---
 tools/AddPdfParam.py                          | 20 +++++++++----------
 3 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h b/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
index ed122cbd2..075f9fee6 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
@@ -4,12 +4,19 @@
   @class GRV_PionPdfDecomposition 
 
   @brief A class for GRV_Pion pdf decomposition
+HACKS for s fraction
 
   Used for pi-
   Assumes that at starting scale:
     ubar=d
     dbar=u
-    s=sbar=0
+    s=sbar
+		u_sea=u   =f_u*sea
+		d_sea=dbar=f_d*sea
+		s_sea=s   =f_s*sea
+		f_u=f_d
+		f_u+f_d+f_s=1
+		=> s=2*f_s/(1-f_s)*u
   Parametrised distributions are:
     v   := dval-uval=2*(d-u)
     qbar:=(u+dbar)/2=u
@@ -18,10 +25,11 @@
     u=dbar=qbar
     d=ubar=qbar+v/2
     g=g
+    s=sbar=qbar*2f_s/(1-f_s)
     others=0
   And sum rules for pi- are:
     \int_0^1 v dx=2
-    \int_0^1 x*(4*qbar+v+g) dx=1
+    \int_0^1 x*(4*qbar/(1-f_s)+v+g) dx=1
   @version 0.2
   @date 2018-08-14
   */
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc b/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
index 3729ce656..b93caf6d0 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
@@ -42,29 +42,32 @@ void GRV_PionPdfDecomposition::initAtStart(const std::string & pars){
 }
 void GRV_PionPdfDecomposition::initAtIteration() {
 	//Enforce sum rules
+	double fs=*XFITTER_PARS::gParameters.at("fs");
 	//Valence sum
 	par_v->setMoment(-1,2);
 	//Momentum sum
-	par_g->setMoment(0,1-4*par_qbar->moment(0)-par_v->moment(0));
+	par_g->setMoment(0,1-4*par_qbar->moment(0)/(1-fs)-par_v->moment(0));
 }
 // Returns a LHAPDF-style function, that returns PDFs in a physical basis for given x
 std::function<std::map<int,double>(const double& x)>GRV_PionPdfDecomposition::f0()const{
 	return [=](double const& x)->std::map<int, double>{
+		double fs=*XFITTER_PARS::gParameters.at("fs");
 		double v   =(*par_v)(x);
 		double qbar=(*par_qbar)(x);
 		double g   =(*par_g)(x);
 		double u=qbar;
 		double d=qbar+v/2;
+		double s=2*fs/(1-fs)*qbar;
 		std::map<int,double>res_={
 			{-6,0},
 			{-5,0},
 			{-4,0},
-			{-3,0},
+			{-3,s},//sbar
 			{-2,d},//ubar
 			{-1,u},//dbar
 			{ 1,d},
 			{ 2,u},
-			{ 3,0},
+			{ 3,s},
 			{ 4,0},
 			{ 5,0},
 			{ 6,0},
diff --git a/tools/AddPdfParam.py b/tools/AddPdfParam.py
index 227e9684f..a6f4239b3 100644
--- a/tools/AddPdfParam.py
+++ b/tools/AddPdfParam.py
@@ -45,16 +45,16 @@ with open(hFile,"w+") as f:
 
 class {name:s}PdfParam:public BasePdfParam{{
   public:
-     {name:s}PdfParam(const std::string&inName):BasePdfParam(inName){{}}
-     //Evaluate xf(x) at given x with current parameters
-     virtual double operator()(double x)const override final;
-     // (Optional) compute moments:
-     // virtual double  moment(int nMoment=-1)const override final;
-     // (Optional) set moments:
-     // virtual void setMoment(int nMoment,double value)override final;
-     // (Optional)
-     //Initialize from a yaml node. Uses node[getName] as the basis
-     // virtual void initFromYaml(YAML::Node value)override final;
+    {name:s}PdfParam(const std::string&inName):BasePdfParam(inName){{}}
+    //Evaluate xf(x) at given x with current parameters
+    virtual double operator()(double x)const override final;
+    // (Optional) compute moments:
+    // virtual double  moment(int nMoment=-1)const override final;
+    // (Optional) set moments:
+    // virtual void setMoment(int nMoment,double value)override final;
+    // (Optional)
+    //Initialize from a yaml node. Uses node[getName] as the basis
+    // virtual void initFromYaml(YAML::Node value)override final;
 }};
 '''.format(name=name,date=datetime.date.today().isoformat())
 )
-- 
GitLab


From 6b3c2bef2154c2fa735d3a271d8ad1619d11e21d Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Wed, 22 Aug 2018 15:53:02 +0200
Subject: [PATCH 11/26] Minor updates

---
 .gitignore      |  16 ++++
 configure.ac    |   2 +-
 parameters.yaml | 211 ++++++++++++++++--------------------------------
 steering.txt    |  55 +++++--------
 4 files changed, 107 insertions(+), 177 deletions(-)

diff --git a/.gitignore b/.gitignore
index f71e36d0e..c89da91b5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,22 @@ unpolarised.wgt
 zmstf.wgt
 SACOT/src/mdispac.mod
 doc/html/
+WHATIDID
+bak/
+constants.yaml
+datafiles/E615/
+deps/
+install.log
+install_yam.log
+make.log
+myconfigure.sh
+output*
+setup.sh
+tmp.sh
+version
+xfitter-master/
+yaml/
+plots/
 
 # vim swap file
 *.swp
diff --git a/configure.ac b/configure.ac
index 93671a243..98ac36b47 100644
--- a/configure.ac
+++ b/configure.ac
@@ -293,7 +293,7 @@ if test $enable_ceres; then
     AC_MSG_ERROR([Unable to find CERES_DIR])
   else
     CERES_CPPFLAGS="-I${CERES_DIR}/include/  -I/usr/include/eigen3"
-    CERES_LDFLAGS="-L${CERES_DIR}/lib  -lceres -lglog -lgflags -lpthread -lspqr -lcholmod -lccolamd -lcamd -lcolamd -lamd -llapack -lblas -lsuitesparseconfig -lrt -lcxsparse -lrt -lcxsparse -lgomp"
+    CERES_LDFLAGS="-L${CERES_DIR}/lib -lceres -lpthread -llapack -lblas -lrt -lgomp"
     AC_SUBST(CERES_CPPFLAGS)
     AC_SUBST(CERES_LDFLAGS)
     AC_DEFINE([CERES_ENABLED],[1],[Define if APFEL++ is enabled])    
diff --git a/parameters.yaml b/parameters.yaml
index 0b229d7c6..1532de0c5 100644
--- a/parameters.yaml
+++ b/parameters.yaml
@@ -1,159 +1,86 @@
-# File to store parameters for theory modules. Overwrites
-# fortran-based ewparam.txt.
-
-#
-# default minimizer:
-#
-Minimizer :  CERES # MINUIT
+Minimizer: MINUIT
+
+PDFDecomposition: GRV_PionPdfDecomposition
+GRV_PionPdfDecomposition:
+  HARDWIRED_PolySqrt: #=A*x^B*(1-x)^C*(1+D*sqrt(x)+E*x)
+    v   : [0    ,0.67881,0.97958, 0.,0.]
+    qbar: [0    ,0.     ,0] # 13.143 ]
+    g   : [0    ,0.     ,5.56   ]
+#    v   : [0    ,0.6561,0.9690, 0.,0.]
+#    qbar: [0.417,0.   , 9    ] #,-2.466,3.855]
+#    g   : [0    ,0.   , 5.56 ] #,-2.074] #,1.824]
+
+Q0: 1.378404875209022   #=sqrt(1.9)
+alphas: 0.118 #0.100
+fs:     0.3333333333333
 
 MINUIT :
   Commands : |
-    fix 103 106 107 109 111 112 113 114 115 116 117 118 119 120 122
-    minimize 
+    fix 111
+    minimize
+    hesse
     call fcn 3
-
-#
-# default evolution:
-#
-Evolution :   QCDNUM
-
-#
-# default PDF decomposition 
-#
-PDFDecomposition : UvDvubardbars
-include : "yaml/pdfdecompositions/UvDvUbarDbarS/parameters.yaml"
-
-
-#
-# Initial scale
-#---------------------------
-Q0 : 1.378404875209
-
-#
-# EW parameters
-#---------------------------
-Mz : 91.1876
-Mw : 80.385
-Mh : 125.9
+#    fix 103 106 107 109 111 112 113 114 115 116 117 118 119 120 122
+
+Evolution: QCDNUM
+QCDNUM:
+  xGrid   :   [9.9e-7, 0.01, 0.1, 0.4, 0.7]
+  xGridW  :   [1,       2,     4,   8,  16]
+  Q2Grid  :   [1.,  2.05e8 ]
+  Q2GridW :   [1.,     1.]  
+  NQ2bins :   120
+  NXbins  :   200
+  Read_QCDNUM_Tables : 1
+  SplineOrder : 2
+  ICheck  :   0
+
+APPLgrid:  # APPLgrid specific
+  muF: 1.0
+  muR: 1.0
+  Order: NLO   # APPLgrids are at max. NLO for now
+
+Mz: 91.1876
+Mw: 80.385
+Mh: 125.9
 
 Wz : 2.4952
 Ww : 2.085
 Wh : 1d-3
-Wtp : 2.0d0
-
-gf : 1.16638e-5
-convFac : 0.389379338e9
-alphaem : 7.29735e-3
-
-sin2thW :  0.23127
-Vud : 0.97427
-Vus : 0.2254
-Vub : 0.00358
-Vcd : 0.22520
-Vcs : 0.97344 
-Vcb : 0.04156
-Vtd : 0.00872
-Vts : 0.04076
-Vtb : 0.999133
+Wtp: 2.0d0
+
+gf: 1.16638e-5
+convFac: 0.389379338e9
+alphaem: 7.29735e-3
+
+sin2thW:  0.23127
+Vud: 0.97427
+Vus: 0.2254
+Vub: 0.00358
+Vcd: 0.22520
+Vcs: 0.97344 
+Vcb: 0.04156
+Vtd: 0.00872
+Vts: 0.04076
+Vtb: 0.999133
 
-#
 # lepton masses:
-#---------------------------
-men : 1e-10
-mel : 0.510998928e-3
-mmn : 1e-10
-mmo : 0.1056583715
-mtn : 1e-10
-mta : 1.77682
+men: 1e-10
+mel: 0.510998928e-3
+mmn: 1e-10
+mmo: 0.1056583715
+mtn: 1e-10
+mta: 1.77682
 
-#
 # Light quark masses:
-#---------------------------
-mup : 0.06983
-mdn : 0.06983
-mst : 0.150
+mup: 0.06983
+mdn: 0.06983
+mst: 0.150
 
-#
 # Heavy quark masses:
-#---------------------------
-mch : 1.43 
-mbt : 4.50
-mtp : 173.0
+mch: 1.43 
+mbt: 4.50
+mtp: 173.0
 
-#
 # QCD parameters
-#---------------------------
-Order : NNLO
+Order : NLO
 NFlavour : 5
-
-#
-# AlphaS, incuding options to fit it:
-#---------------------------
-alphas : 0.118
-#  value: 0.118
-#  step:  0.01
-#  prior: 0.118
-#  priorUnc: 0.1
-#  min: 0.1
-#  max: 0.3
-
-# Strange and charm fractions:
-#---------------------------
-fs: 0.4
-fcharm: 0.
-
-#
-# RT DIS scheme settings:
-#---------------------------
-include : yaml/reactions/RT_DISNC/parameters.yaml
-
-#
-# FONLL scheme settings:
-#---------------------------
-include : yaml/reactions/FONLL_DISNC/parameters.yaml
-include : yaml/reactions/FONLL_DISCC/parameters.yaml
-
-# FF ABM scheme settings:
-#---------------------------
-include : yaml/reactions/FFABM_DISNC/parameters.yaml
-include : yaml/reactions/FFABM_DISCC/parameters.yaml
-
-#
-# APPLgrid settings:
-#---------------------------
-include : yaml/reactions/APPLgrid/parameters.yaml
-
-#
-# (optional) Fractal module settings:
-#---------------------------
-# include : yaml/reactions/Fractal_DISNC/parameters.yaml
-
-#
-# Speficify HF scheme used for DIS NC processes:
-#---------------------------
-hf_scheme_DISNC :
-#  defaultValue : 'BaseDISNC'       # global specification
-  defaultValue : 'RT_DISNC'        # global specification
-#  defaultValue : 'FONLL_DISNC'     # global specification
-#  defaultValue : 'FFABM_DISNC'
-#  'HERA1+2 NCep 920' : 'BaseDISNC' # datafile specific (based on name)
-#  1 : BaseDISNC
-#  'HERA1+2 NCep 920' : 'Fractal_DISNC'  # Fractal model. Add parameters file if you want to try it (see above)
-
-#
-# Speficify HF scheme used for DIS CC processes:
-#---------------------------
-hf_scheme_DISCC :
-  defaultValue : 'BaseDISCC'       # global specification
-#  defaultValue : 'FONLL_DISCC'     # global specification
-#  defaultValue : 'FFABM_DISCC'     # global specification
-
-#
-# Load APFEL++
-#---------------------------
-include : yaml/evolutions/APFELxx/parameters.yaml
-
-#
-# Load QCDNUM
-#---------------------------
-include : yaml/evolutions/QCDNUM/parameters.yaml
diff --git a/steering.txt b/steering.txt
index 3bbf665b3..cd4e9c396 100644
--- a/steering.txt
+++ b/steering.txt
@@ -1,43 +1,32 @@
 &InFiles
   ! Number of intput files
-    NInputFiles = 18
+    NInputFiles = 15
   ! Input files:
     InputFileNames = 
-			'datafiles/E615/thexp-0.dat',
-			'datafiles/E615/thexp-1.dat',
-			'datafiles/E615/thexp-2.dat',
-			'datafiles/E615/thexp-3.dat',
-			'datafiles/E615/thexp-4.dat',
-			'datafiles/E615/thexp-5.dat',
-			'datafiles/E615/thexp-6.dat',
-			'datafiles/E615/thexp-7.dat',
-			'datafiles/E615/thexp-8.dat',
-			'datafiles/E615/thexp-9.dat',
-			'datafiles/E615/thexp-10.dat',
-			'datafiles/E615/thexp-11.dat',
-			'datafiles/E615/thexp-12.dat',
-			'datafiles/E615/thexp-13.dat',
-			'datafiles/E615/thexp-14.dat',
-			'datafiles/E615/thexp-15.dat',
-			'datafiles/E615/thexp-16.dat',
-			'datafiles/E615/thexp-17.dat',
-    ! 'Z0_applgrid_nnlo_reaction.dat', 'D0_Wel_pt25_asymmetry.dat'
-    ! 'datafiles/lhc/atlas/wzProduction/1203.4051/Z0_applgrid_nnlo.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-0.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-1.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-2.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-3.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-4.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-5.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-6.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-7.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-8.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-9.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-13.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-14.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-15.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-16.dat',
+			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-17.dat',
 &End
 
 &InCorr
-  ! Number of correlation (statistical, systematical or full) files
     NCorrFiles = 0
-  ! Correlation files:
-  !  CorrFileNames(1) = 'datafiles/hera/h1/jets/0904.3870/H1_NormInclJets_HighQ2_99-07___H1_NormInclJets_HighQ2_99-07.corr'
 &End
 
 &ReduceSyst
-    ! even with tolerance =0 the following flag may speed up calculations
   do_reduce = .false.  ! turn-on to simplify/speedup chi2 calculation.
-    ! tolerance = 0.0 for exact calculation, > 0.0 for improved speed.
   tolerance = 0.0
-    ! depending on blas library, toggling the following flag may improve chi2 computation speed:
   useBlas = .false.
 &End
 
@@ -48,13 +37,9 @@
 &end
 
 &CovarToNuisance
-   ! Global switch for using nuisance param representation for covariance mat.
   LConvertCovToNui = .False.
-   ! Tolerance -- zero means exact transformation
   Tolerance = 0.0
-   ! (Optional) -- try to subtract diagonal stat. uncertainties from total covariance when determining uncorrelated uncertainites
   LSubtractStat = .false.
-   ! The following lines allow to adjust error scaling properties (default: :M)
   DataName     = 'CMS electon Asymmetry rapidity', 'CMS W muon asymmetry'
   DataSystType = ':A', ':A'
 &End
@@ -192,8 +177,10 @@
  !  'ExtraSystRescale'      : additional re-scaling of stat. uncertainty to account for syst. shifts.
 
    CHI2SettingsName = 'StatScale', 'UncorSysScale', 'CorSysScale', 'UncorChi2Type', 'CorChi2Type'
-   Chi2Settings     = 'Poisson'  , 'Linear',        'Linear'     , 'Diagonal'     , 'Hessian'
- !  Chi2ExtraParam = 'PoissonCorr'
+ !  Chi2Settings     = 'Poisson' , 'Linear',  'Linear'  , 'Diagonal' , 'Hessian'
+    Chi2Settings     = 'Poisson' , 'Poisson',  'Linear'  , 'Diagonal' , 'Hessian'
+ !  Chi2Settings     = 'NoRescale'  , 'NoRescale',        'NoRescale'     , 'Diagonal'     , 'Hessian'
+    Chi2ExtraParam = 'PoissonCorr'
 
  ! Flag to define if native APPLgrid CKM values should be kept.
  LUseAPPLgridCKM = True
@@ -216,7 +203,7 @@
   DoBandsSym = False     ! symmetric bands ( HESSE )
 
   ! -- Q2 values at which the pdfs & errors are done (up to 20)
-  Q2VAL = 1.9, 3.0, 4.0, 5., 10., 100., 6464, 8317 
+  Q2VAL = 0.4,1.9, 3.0, 4.0, 5., 10.
 !  Q2VAL = 1.9, 4., 10., 100., 6464, 8317 
 
   ! How many x points to write (standard = 101)
-- 
GitLab


From 8ef3e7bed4336b815f9ef733382f922fd248615c Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Tue, 28 Aug 2018 15:59:29 +0200
Subject: [PATCH 12/26] Change decomposition for pion

---
 parameters.yaml | 76 -------------------------------------------------
 1 file changed, 76 deletions(-)

diff --git a/parameters.yaml b/parameters.yaml
index 087b87432..1532de0c5 100644
--- a/parameters.yaml
+++ b/parameters.yaml
@@ -15,7 +15,6 @@ alphas: 0.118 #0.100
 fs:     0.3333333333333
 
 MINUIT :
-  doErrors : Pumplin # Hesse # None
   Commands : |
     fix 111
     minimize
@@ -85,78 +84,3 @@ mtp: 173.0
 # QCD parameters
 Order : NLO
 NFlavour : 5
-<<<<<<< HEAD
-=======
-
-#
-# AlphaS, incuding options to fit it:
-#---------------------------
-alphas : 0.118
-#  value: 0.118
-#  step:  0.01
-#  prior: 0.118
-#  priorUnc: 0.1
-#  min: 0.1
-#  max: 0.3
-
-# Strange and charm fractions:
-#---------------------------
-fs: 0.4
-fcharm: 0.
-
-#
-# RT DIS scheme settings:
-#---------------------------
-include : yaml/reactions/RT_DISNC/parameters.yaml
-
-#
-# FONLL scheme settings:
-#---------------------------
-include : yaml/reactions/FONLL_DISNC/parameters.yaml
-include : yaml/reactions/FONLL_DISCC/parameters.yaml
-
-# FF ABM scheme settings:
-#---------------------------
-include : yaml/reactions/FFABM_DISNC/parameters.yaml
-include : yaml/reactions/FFABM_DISCC/parameters.yaml
-
-#
-# APPLgrid settings:
-#---------------------------
-include : yaml/reactions/APPLgrid/parameters.yaml
-
-#
-# (optional) Fractal module settings:
-#---------------------------
-# include : yaml/reactions/Fractal_DISNC/parameters.yaml
-
-#
-# Speficify HF scheme used for DIS NC processes:
-#---------------------------
-hf_scheme_DISNC :
-  defaultValue : 'BaseDISNC'       # global specification
-#  defaultValue : 'RT_DISNC'        # global specification
-#  defaultValue : 'FONLL_DISNC'     # global specification
-#  defaultValue : 'FFABM_DISNC'
-#  'HERA1+2 NCep 920' : 'BaseDISNC' # datafile specific (based on name)
-#  1 : BaseDISNC
-#  'HERA1+2 NCep 920' : 'Fractal_DISNC'  # Fractal model. Add parameters file if you want to try it (see above)
-
-#
-# Speficify HF scheme used for DIS CC processes:
-#---------------------------
-hf_scheme_DISCC :
-  defaultValue : 'BaseDISCC'       # global specification
-#  defaultValue : 'FONLL_DISCC'     # global specification
-#  defaultValue : 'FFABM_DISCC'     # global specification
-
-#
-# Load APFEL++
-#---------------------------
-include : yaml/evolutions/APFELxx/parameters.yaml
-
-#
-# Load QCDNUM
-#---------------------------
-include : yaml/evolutions/QCDNUM/parameters.yaml
->>>>>>> test_ceres
-- 
GitLab


From 00d569cc2010f652d8713b52a97de744e8e6c826 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Tue, 28 Aug 2018 16:14:41 +0200
Subject: [PATCH 13/26] Redefine GRV-decomposition

---
 parameters.yaml                               |  48 ++---
 .../include/GRV_PionPdfDecomposition.h        |  25 +--
 .../src/GRV_PionPdfDecomposition.cc           |  44 ++---
 src/main.f                                    |   6 +-
 steering.txt                                  |   5 +-
 tools/draw/src/xfitter-draw.cc                | 182 +++++++++---------
 6 files changed, 152 insertions(+), 158 deletions(-)

diff --git a/parameters.yaml b/parameters.yaml
index 192e74bbd..1de4bf455 100644
--- a/parameters.yaml
+++ b/parameters.yaml
@@ -3,23 +3,23 @@ Minimizer: MINUIT
 PDFDecomposition: GRV_PionPdfDecomposition
 GRV_PionPdfDecomposition:
   HARDWIRED_PolySqrt: #=A*x^B*(1-x)^C*(1+D*sqrt(x)+E*x)
-    v   : [0    ,0.67881,0.97958]
-    qbar: [0    ,0.     ,0]
-    g   : [0    ,0.     ,5.56   ]
+    v: [0.    , 0.6817,0.9794]
+    S: [0.0818,-0.2 ,8]
+    g: [0.    , 0   ,9]
 
 Q0: 1.378404875209022   #=sqrt(1.9)
 alphas: 0.118 #0.100
-fs:     0.3333333333333
 
-MINUIT :
-  Commands : |
-    fix 111
-    minimize
-    hesse
+MINUIT:
+  doErrors: None #Pumplin #Hesse
+  Commands: |
+    fix 106 107 108 109
     call fcn 3
-#    fix 103 106 107 109 111 112 113 114 115 116 117 118 119 120 122
+    #minimize
+    #hesse
+    #fix 103 106 107 109 111 112 113 114 115 116 117 118 119 120 122
 
-Evolution: QCDNUM
+Evolution: QCDNUM #QCDNUM LHAPDF
 QCDNUM:
   xGrid   :   [9.9e-7, 0.01, 0.1, 0.4, 0.7]
   xGridW  :   [1,       2,     4,   8,  16]
@@ -30,21 +30,25 @@ QCDNUM:
   Read_QCDNUM_Tables : 1
   SplineOrder : 2
   ICheck  :   0
-LHAPDF :
-  set : "CT10"
-  member : 0
+LHAPDF:
+  set: "GRVPI0"
+  member: 0
 
 APPLgrid:  # APPLgrid specific
+  #LHAPDF_SetName: nCTEQ15FullNuc_184_74
+  #LHAPDF_MemberID: '0'
   muF: 1.0
   muR: 1.0
-  Order: NLO   # APPLgrids are at max. NLO for now
+  Order: NLO
+
+fs: 0.333333333333333
 
 Profiler:
-   alphas : [ 0.118, 0.119, 0.117 ]
-   evolutions :
-     proton :
-       sets :    [  NNPDF31_nnlo_as_0118, CT10  ]
-       members : [ [ 0, 1, end ], [0, 1, end] ]
+  alphas: [ 0.118, 0.119, 0.117 ]
+  evolutions:
+    proton:
+      sets:    [  NNPDF31_nnlo_as_0118, CT10  ]
+      members: [ [ 0, 1, end ], [0, 1, end] ]
 
 Mz: 91.1876
 Mw: 80.385
@@ -89,5 +93,5 @@ mbt: 4.50
 mtp: 173.0
 
 # QCD parameters
-Order : NLO
-NFlavour : 5
+Order: NLO
+NFlavour: 5
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h b/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
index 075f9fee6..a7b5f254d 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
@@ -4,32 +4,23 @@
   @class GRV_PionPdfDecomposition 
 
   @brief A class for GRV_Pion pdf decomposition
-HACKS for s fraction
 
   Used for pi-
   Assumes that at starting scale:
     ubar=d
-    dbar=u
-    s=sbar
-		u_sea=u   =f_u*sea
-		d_sea=dbar=f_d*sea
-		s_sea=s   =f_s*sea
-		f_u=f_d
-		f_u+f_d+f_s=1
-		=> s=2*f_s/(1-f_s)*u
+    dbar=u=s=sbar
   Parametrised distributions are:
-    v   := dval-uval=2*(d-u)
-    qbar:=(u+dbar)/2=u
+    v:=(dval-uval)/2=d-u
+    S:=(u   +dbar)/2=u
     g
   Therefore, transformations to physical basis:
-    u=dbar=qbar
-    d=ubar=qbar+v/2
+    d=ubar=v+S
+    u=dbar=s=sbar=S
     g=g
-    s=sbar=qbar*2f_s/(1-f_s)
     others=0
   And sum rules for pi- are:
-    \int_0^1 v dx=2
-    \int_0^1 x*(4*qbar/(1-f_s)+v+g) dx=1
+    \int_0^1 v dx=1
+    \int_0^1 x*(6S+2v+g) dx=1
   @version 0.2
   @date 2018-08-14
   */
@@ -43,6 +34,6 @@ class GRV_PionPdfDecomposition:public BasePdfDecomposition{
 		virtual void initAtIteration()override final;
 		virtual std::function<std::map<int,double>(const double& x)>f0()const override final; 
 	private:
-		BasePdfParam*par_v,*par_qbar,*par_g;
+		BasePdfParam*par_v,*par_S,*par_g;
 	};
 }
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc b/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
index b93caf6d0..83479261f 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
+++ b/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
@@ -15,15 +15,15 @@ extern "C" GRV_PionPdfDecomposition*create(){
 	return new GRV_PionPdfDecomposition();
 }
 GRV_PionPdfDecomposition::GRV_PionPdfDecomposition():BasePdfDecomposition("GRV_Pion"){
-	par_v   =nullptr;
-	par_qbar=nullptr;
-	par_g   =nullptr;
+	par_v=nullptr;
+	par_S=nullptr;
+	par_g=nullptr;
 }
 GRV_PionPdfDecomposition::GRV_PionPdfDecomposition(const std::string& inName):BasePdfDecomposition(inName){}
 GRV_PionPdfDecomposition::~GRV_PionPdfDecomposition(){
-	if(par_v   )delete par_v;
-	if(par_qbar)delete par_qbar;
-	if(par_g   )delete par_g;
+	if(par_v)delete par_v;
+	if(par_S)delete par_S;
+	if(par_g)delete par_g;
 }
 // Init at start:
 void GRV_PionPdfDecomposition::initAtStart(const std::string & pars){
@@ -36,38 +36,34 @@ void GRV_PionPdfDecomposition::initAtStart(const std::string & pars){
 		pParam->initFromYaml(node.second);
 		addParameterisation(prmzName,pParam);
 	}
-	par_v   =getPdfParam("v");
-	par_qbar=getPdfParam("qbar");
-	par_g   =getPdfParam("g");
+	par_v=getPdfParam("v");
+	par_S=getPdfParam("S");
+	par_g=getPdfParam("g");
 }
 void GRV_PionPdfDecomposition::initAtIteration() {
 	//Enforce sum rules
-	double fs=*XFITTER_PARS::gParameters.at("fs");
 	//Valence sum
-	par_v->setMoment(-1,2);
+	par_v->setMoment(-1,1);
 	//Momentum sum
-	par_g->setMoment(0,1-4*par_qbar->moment(0)/(1-fs)-par_v->moment(0));
+	par_g->setMoment(0,1-6*par_S->moment(0)-2*par_v->moment(0));
 }
 // Returns a LHAPDF-style function, that returns PDFs in a physical basis for given x
 std::function<std::map<int,double>(const double& x)>GRV_PionPdfDecomposition::f0()const{
 	return [=](double const& x)->std::map<int, double>{
-		double fs=*XFITTER_PARS::gParameters.at("fs");
-		double v   =(*par_v)(x);
-		double qbar=(*par_qbar)(x);
-		double g   =(*par_g)(x);
-		double u=qbar;
-		double d=qbar+v/2;
-		double s=2*fs/(1-fs)*qbar;
+		double v=(*par_v)(x);
+		double S=(*par_S)(x);
+		double g=(*par_g)(x);
+		double d=S+v;
 		std::map<int,double>res_={
 			{-6,0},
 			{-5,0},
 			{-4,0},
-			{-3,s},//sbar
+			{-3,S},//sbar
 			{-2,d},//ubar
-			{-1,u},//dbar
-			{ 1,d},
-			{ 2,u},
-			{ 3,s},
+			{-1,S},//dbar
+			{ 1,d},//d
+			{ 2,S},//u
+			{ 3,S},//s
 			{ 4,0},
 			{ 5,0},
 			{ 6,0},
diff --git a/src/main.f b/src/main.f
index 97a1339a9..f47716856 100644
--- a/src/main.f
+++ b/src/main.f
@@ -225,16 +225,16 @@ C-----------------------------------------------------
 #include "steering.inc"
       double precision fmin, fedm, errdef
       integer npari, nparx, istat
-C----------------------------------------------------------      
+C----------------------------------------------------------
       call MNSTAT(fmin, fedm, errdef, npari, nparx, istat)
       if (istat.eq.0) then
          call hf_errlog(16042801,'I: No minimization has run')
       else if (istat.eq.3) then
          call hf_errlog(16042802,'I: Successful run')
       else if (istat.eq.1) then
-         call hf_errlog(16042803,'E: Error matrix not accurate')         
+         call hf_errlog(16042803,'E: Error matrix not accurate')
       else if (istat.eq.2) then
-         call hf_errlog(16042804,'E: Error matrix forced positive')         
+         call hf_errlog(16042804,'E: Error matrix forced positive')
       endif
 C Save in output file
       open (51,file=Trim(OutDirName)//'/Status.out',status='unknown')
diff --git a/steering.txt b/steering.txt
index cd4e9c396..00cd38e83 100644
--- a/steering.txt
+++ b/steering.txt
@@ -18,6 +18,9 @@
 			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-15.dat',
 			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-16.dat',
 			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-17.dat',
+!		  '/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-10.dat',
+!		  '/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-11.dat',
+!		  '/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-12.dat',
 &End
 
 &InCorr
@@ -203,7 +206,7 @@
   DoBandsSym = False     ! symmetric bands ( HESSE )
 
   ! -- Q2 values at which the pdfs & errors are done (up to 20)
-  Q2VAL = 0.4,1.9, 3.0, 4.0, 5., 10.
+  Q2VAL = 1.9, 3.0, 4.0, 5., 10.
 !  Q2VAL = 1.9, 4., 10., 100., 6464, 8317 
 
   ! How many x points to write (standard = 101)
diff --git a/tools/draw/src/xfitter-draw.cc b/tools/draw/src/xfitter-draw.cc
index c98b62004..ea5d5cef9 100644
--- a/tools/draw/src/xfitter-draw.cc
+++ b/tools/draw/src/xfitter-draw.cc
@@ -35,13 +35,13 @@ int main(int argc, char **argv)
   for (vector<string>::iterator it1 = opts.labels.begin(); it1 != opts.labels.end(); it1++)
     for (vector<string>::iterator it2 = it1+1; it2 != opts.labels.end(); it2++)
       if (*it1 == *it2)
-	{
-	  cout << endl;
-	  cout << "Error: label (or directory) " << *it1 << " can appear only once in labels list" << endl;
-	  cout << "Specify different labels" << endl;
-	  cout << endl;
-	  exit(-1);
-	}
+        {
+          cout << endl;
+          cout << "Error: label (or directory) " << *it1 << " can appear only once in labels list" << endl;
+          cout << "Specify different labels" << endl;
+          cout << endl;
+          exit(-1);
+        }
 
   //Associate colors and styles to labels
   for (vector<string>::iterator itl = opts.labels.begin(); itl != opts.labels.end(); itl++)
@@ -67,19 +67,19 @@ int main(int argc, char **argv)
       //loop on Q2 bins
       vector <float> ql = q2list();
       for (vector<float>::iterator qit = ql.begin(); qit != ql.end(); qit++)
-	{
-	  //loop on pdf types
-	  for (vector <pdftype>::iterator pit = pdfs.begin(); pit != pdfs.end(); pit++)
-	    {
-	      vector <TCanvas*> pdfcnv = PdfsPainter(*qit, *pit);
-	      pdfscanvaslist.push_back(pdfcnv[0]);
-	      if (pdfcnv.size() > 1)
-		pdfscanvasratiolist.push_back(pdfcnv[1]);
-	    }
-
-	  if (!opts.q2all)
-	    break;
-	}
+        {
+          //loop on pdf types
+          for (vector <pdftype>::iterator pit = pdfs.begin(); pit != pdfs.end(); pit++)
+            {
+              vector <TCanvas*> pdfcnv = PdfsPainter(*qit, *pit);
+              pdfscanvaslist.push_back(pdfcnv[0]);
+              if (pdfcnv.size() > 1)
+                pdfscanvasratiolist.push_back(pdfcnv[1]);
+            }
+
+          if (!opts.q2all)
+            break;
+        }
     }
   
   //--------------------------------------------------
@@ -91,14 +91,14 @@ int main(int argc, char **argv)
       //loop on datasets
       vector <int> dl = datalist();
       for (vector<int>::iterator dit = dl.begin(); dit != dl.end(); dit++)
-	{
-	  //extract dataset index and subplot index
-	  int dataindex = (int)(*dit) / 100;
-	  int subplotindex = *dit - dataindex * 100;
-	  TCanvas *dataplot = DataPainter(dataindex, subplotindex);
-	  if (dataplot != 0)
-	    datapullscanvaslist.push_back(dataplot);
-	}
+        {
+          //extract dataset index and subplot index
+          int dataindex = (int)(*dit) / 100;
+          int subplotindex = *dit - dataindex * 100;
+          TCanvas *dataplot = DataPainter(dataindex, subplotindex);
+          if (dataplot != 0)
+            datapullscanvaslist.push_back(dataplot);
+        }
     }
 
   //--------------------------------------------------
@@ -141,11 +141,11 @@ int main(int argc, char **argv)
       TCanvas * pagecnv = new TCanvas(numb, "", 0, 0, opts.resolution * opts.plotsperpage, opts.resolution * opts.plotsperpage);
       pagecnv->Divide(opts.plotsperpage, opts.plotsperpage);
       for (int i = 1; i <= opts.plotsperpage*opts.plotsperpage && it != pdfscanvaslist.end(); i++)
-	{
-	  pagecnv->cd(i);
-	  (*it)->DrawClonePad();
-	  it++;
-	}
+        {
+          pagecnv->cd(i);
+          (*it)->DrawClonePad();
+          it++;
+        }
 
       pgn++;
       sprintf(pgnum, "%d", pgn);
@@ -158,11 +158,11 @@ int main(int argc, char **argv)
       TCanvas * pagecnv = new TCanvas(numb, "", 0, 0, opts.resolution *opts.plotsperpage, opts.resolution * opts.plotsperpage);
       pagecnv->Divide(opts.plotsperpage, opts.plotsperpage);
       for (int i = 1; i <= opts.plotsperpage*opts.plotsperpage && it != pdfscanvasratiolist.end(); i++)
-	{
-	  pagecnv->cd(i);
-	  (*it)->DrawClonePad();
-	  it++;
-	}
+        {
+          pagecnv->cd(i);
+          (*it)->DrawClonePad();
+          it++;
+        }
       pgn++;
       sprintf(pgnum, "%d", pgn);
       pagecnv->Print((opts.outdir + "plots_" + pgnum + ".eps").c_str());
@@ -179,29 +179,29 @@ int main(int argc, char **argv)
       sprintf(numb, "data_%d", it - datapullscanvaslist.begin());
       TCanvas * pagecnv;
       if (opts.twopanels || opts.threepanels)
-	{
-	  pagecnv = new TCanvas(numb, "", 0, 0, opts.resolution * 2, opts.resolution * 2);
-	  pagecnv->Divide(1, 2);
-	  for (int i = 1; i <= 2; i++)
-	    if (it != datapullscanvaslist.end())
-	      {
-		pagecnv->cd(i);
-		(*it)->DrawClonePad();
-		it++;
-	      }
-	}
+        {
+          pagecnv = new TCanvas(numb, "", 0, 0, opts.resolution * 2, opts.resolution * 2);
+          pagecnv->Divide(1, 2);
+          for (int i = 1; i <= 2; i++)
+            if (it != datapullscanvaslist.end())
+              {
+                pagecnv->cd(i);
+                (*it)->DrawClonePad();
+                it++;
+              }
+        }
       else
-	{
-	  pagecnv = new TCanvas(numb, "", 0, 0, opts.resolution * 2, opts.resolution * 2);
-	  pagecnv->Divide(opts.plotsperpage, opts.plotsperpage);
-	  for (int i = 1; i <= opts.plotsperpage*opts.plotsperpage; i++)
-	    if (it != datapullscanvaslist.end())
-	      {
-		pagecnv->cd(i);
-		(*it)->DrawClonePad();
-		it++;
-	      }
-	}
+        {
+          pagecnv = new TCanvas(numb, "", 0, 0, opts.resolution * 2, opts.resolution * 2);
+          pagecnv->Divide(opts.plotsperpage, opts.plotsperpage);
+          for (int i = 1; i <= opts.plotsperpage*opts.plotsperpage; i++)
+            if (it != datapullscanvaslist.end())
+              {
+                pagecnv->cd(i);
+                (*it)->DrawClonePad();
+                it++;
+              }
+        }
       pgn++;
       sprintf(pgnum, "%d", pgn);
       pagecnv->Print((opts.outdir + "plots_" + pgnum + ".eps").c_str());
@@ -230,12 +230,12 @@ int main(int argc, char **argv)
       pagecnv = new TCanvas(numb, "", 0, 0, opts.resolution * 2, opts.resolution * 2);
       pagecnv->Divide(2, 2);
       for (int i = 1; i <= 4; i++)
-	if (it != chi2scancanvaslist.end())
-	  {
-	    pagecnv->cd(i);
-	    (*it)->DrawClonePad();
-	    it++;
-	  }
+        if (it != chi2scancanvaslist.end())
+          {
+            pagecnv->cd(i);
+            (*it)->DrawClonePad();
+            it++;
+          }
       pgn++;
       sprintf(pgnum, "%d", pgn);
       pagecnv->Print((opts.outdir + "plots_" + pgnum + ".eps").c_str());
@@ -245,36 +245,36 @@ int main(int argc, char **argv)
     {
       string ext = opts.ext;
       if (opts.ext == "pdf")
-	ext = "eps";
+        ext = "eps";
 
       gStyle->SetPaperSize(opts.pagewidth / 2., opts.pagewidth / 2.);
       for (vector <TCanvas*>::iterator it = pdfscanvaslist.begin(); it != pdfscanvaslist.end(); it++)
-	(*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
+        (*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
       for (vector <TCanvas*>::iterator it = pdfscanvasratiolist.begin(); it != pdfscanvasratiolist.end(); it++)
-	(*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
+        (*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
       if (opts.twopanels || opts.threepanels)
-	gStyle->SetPaperSize(opts.pagewidth, opts.pagewidth / 2.);
+        gStyle->SetPaperSize(opts.pagewidth, opts.pagewidth / 2.);
       for (vector <TCanvas*>::iterator it = datapullscanvaslist.begin(); it != datapullscanvaslist.end(); it++)
-	(*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
+        (*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
       gStyle->SetPaperSize(opts.pagewidth, opts.pagewidth);
       for (vector <TCanvas*>::iterator it = shiftcanvaslist.begin(); it != shiftcanvaslist.end(); it++)
-	(*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
+        (*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
       for (vector <TCanvas*>::iterator it = chi2scancanvaslist.begin(); it != chi2scancanvaslist.end(); it++)
-	(*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
+        (*it)->Print((opts.outdir + (*it)->GetName() + "." + ext).c_str());
 
       if (opts.ext == "pdf")
-	{
-	  for (vector <TCanvas*>::iterator it = pdfscanvaslist.begin(); it != pdfscanvaslist.end(); it++)
-	    system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
-	  for (vector <TCanvas*>::iterator it = pdfscanvasratiolist.begin(); it != pdfscanvasratiolist.end(); it++)
-	    system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
-	  for (vector <TCanvas*>::iterator it = datapullscanvaslist.begin(); it != datapullscanvaslist.end(); it++)
-	    system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
-	  for (vector <TCanvas*>::iterator it = shiftcanvaslist.begin(); it != shiftcanvaslist.end(); it++)
-	    system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
-	  for (vector <TCanvas*>::iterator it = chi2scancanvaslist.begin(); it != chi2scancanvaslist.end(); it++)
-	    system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
-	}
+        {
+          for (vector <TCanvas*>::iterator it = pdfscanvaslist.begin(); it != pdfscanvaslist.end(); it++)
+            system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
+          for (vector <TCanvas*>::iterator it = pdfscanvasratiolist.begin(); it != pdfscanvasratiolist.end(); it++)
+            system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
+          for (vector <TCanvas*>::iterator it = datapullscanvaslist.begin(); it != datapullscanvaslist.end(); it++)
+            system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
+          for (vector <TCanvas*>::iterator it = shiftcanvaslist.begin(); it != shiftcanvaslist.end(); it++)
+            system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
+          for (vector <TCanvas*>::iterator it = chi2scancanvaslist.begin(); it != chi2scancanvaslist.end(); it++)
+            system(((string)"ps2pdf -dEPSCrop " + opts.outdir + (*it)->GetName() + ".eps " + opts.outdir + (*it)->GetName() + ".pdf").c_str());
+        }
       cout << "Multiple " << opts.ext << " plots saved in: " << (opts.outdir + "*." + opts.ext) << endl;
     }
 
@@ -285,21 +285,21 @@ int main(int argc, char **argv)
       f->mkdir("Canvas");
       f->cd("Canvas");
       for (vector <TCanvas*>::iterator it = pdfscanvaslist.begin(); it != pdfscanvaslist.end(); it++)
-	(*it)->Write();
+        (*it)->Write();
       for (vector <TCanvas*>::iterator it = pdfscanvasratiolist.begin(); it != pdfscanvasratiolist.end(); it++)
-	(*it)->Write();
+        (*it)->Write();
       for (vector <TCanvas*>::iterator it = datapullscanvaslist.begin(); it != datapullscanvaslist.end(); it++)
-	(*it)->Write();
+        (*it)->Write();
       for (vector <TCanvas*>::iterator it = shiftcanvaslist.begin(); it != shiftcanvaslist.end(); it++)
-	(*it)->Write();
+        (*it)->Write();
       for (vector <TCanvas*>::iterator it = chi2scancanvaslist.begin(); it != chi2scancanvaslist.end(); it++)
-	(*it)->Write();
+        (*it)->Write();
 
       f->cd("");
       f->mkdir("Graphs");
       f->cd("Graphs");
       for (vector <TGraphAsymmErrors*>::iterator git = allgraphs.begin(); git != allgraphs.end(); git++)
-	(*git)->Write();
+        (*git)->Write();
 
       f->Close();
       cout << "TCanvas saved in: " << (opts.outdir + "plots.root") << endl;
-- 
GitLab


From b552e3fa7778c7f6c4f9a7d369cb7d7502ec34e5 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Fri, 31 Aug 2018 12:59:30 +0200
Subject: [PATCH 14/26] Rename decomposition GRV to SU3

---
 Makefile.am                                   |  2 +-
 Reactions.txt                                 |  2 +-
 configure.ac                                  |  2 +-
 parameters.yaml                               | 18 +++++++-------
 .../yaml/parameters.yaml                      |  0
 .../include/SU3_PionPdfDecomposition.h}       | 12 +++++-----
 .../src/Makefile.am                           |  8 +++----
 .../src/SU3_PionPdfDecomposition.cc}          | 24 +++++++++----------
 8 files changed, 34 insertions(+), 34 deletions(-)
 delete mode 100644 pdfdecompositions/GRV_PionPdfDecomposition/yaml/parameters.yaml
 rename pdfdecompositions/{GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h => SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h} (71%)
 rename pdfdecompositions/{GRV_PionPdfDecomposition => SU3_PionPdfDecomposition}/src/Makefile.am (69%)
 rename pdfdecompositions/{GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc => SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc} (70%)

diff --git a/Makefile.am b/Makefile.am
index 013e39e8f..480f0e462 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -29,7 +29,7 @@ SUBDIRS = minuit/src interfaces/src DY/src DIPOLE/src RT/src EW/src common commo
         pdfdecompositions/BasePdfDecomposition/src \
         pdfdecompositions/LHAPDFDecomposition/src \
         pdfdecompositions/UvDvUbarDbarS/src \
-        pdfdecompositions/GRV_PionPdfDecomposition/src \
+        pdfdecompositions/SU3_PionPdfDecomposition/src \
         evolutions/BaseEvolution/src \
         evolutions/APFELxx/src \
         minimizers/BaseMinimizer/src minimizers/CERESMinimizer/src minimizers/MINUITMinimizer/src
diff --git a/Reactions.txt b/Reactions.txt
index 29076463d..bd7678f04 100644
--- a/Reactions.txt
+++ b/Reactions.txt
@@ -18,7 +18,7 @@ BaseEvolution libbaseevolution_xfitter.so
 APFELxx libapfelxx_xfitter.so
 QCDNUM libqcdnum_xfitter.so
 UvDvubardbars libuvdvubardbars_xfitter.so
-GRV_PionPdfDecomposition libGRV_PionPdfDecomposition_xfitter.so
+SU3_PionPdfDecomposition libSU3_PionPdfDecomposition_xfitter.so
 MINUIT libMINUITMinimizer_xfitter.so
 CERES libCERESMinimizer_xfitter.so
 LHAPDF liblhapdf_xfitter.so
diff --git a/configure.ac b/configure.ac
index 98ac36b47..ae1ef735c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -608,7 +608,7 @@ AC_CONFIG_FILES([include/Makefile
 		 pdfparams/PolySqrtPdfParam/src/Makefile
 		 pdfdecompositions/LHAPDFDecomposition/src/Makefile
 		 pdfdecompositions/UvDvUbarDbarS/src/Makefile
-		 pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile
+		 pdfdecompositions/SU3_PionPdfDecomposition/src/Makefile
 		 pdfdecompositions/BasePdfDecomposition/src/Makefile
 		 reactions/KFactor/src/Makefile
 		 reactions/BaseDISCC/src/Makefile
diff --git a/parameters.yaml b/parameters.yaml
index 1de4bf455..d086394b5 100644
--- a/parameters.yaml
+++ b/parameters.yaml
@@ -1,7 +1,7 @@
 Minimizer: MINUIT
 
-PDFDecomposition: GRV_PionPdfDecomposition
-GRV_PionPdfDecomposition:
+PDFDecomposition: SU3_PionPdfDecomposition
+SU3_PionPdfDecomposition:
   HARDWIRED_PolySqrt: #=A*x^B*(1-x)^C*(1+D*sqrt(x)+E*x)
     v: [0.    , 0.6817,0.9794]
     S: [0.0818,-0.2 ,8]
@@ -19,7 +19,7 @@ MINUIT:
     #hesse
     #fix 103 106 107 109 111 112 113 114 115 116 117 118 119 120 122
 
-Evolution: QCDNUM #QCDNUM LHAPDF
+Evolution: LHAPDF #QCDNUM LHAPDF
 QCDNUM:
   xGrid   :   [9.9e-7, 0.01, 0.1, 0.4, 0.7]
   xGridW  :   [1,       2,     4,   8,  16]
@@ -43,12 +43,12 @@ APPLgrid:  # APPLgrid specific
 
 fs: 0.333333333333333
 
-Profiler:
-  alphas: [ 0.118, 0.119, 0.117 ]
-  evolutions:
-    proton:
-      sets:    [  NNPDF31_nnlo_as_0118, CT10  ]
-      members: [ [ 0, 1, end ], [0, 1, end] ]
+#Profiler:
+#  alphas: [ 0.118, 0.119, 0.117 ]
+#  evolutions:
+#    proton:
+#      sets:    [  NNPDF31_nnlo_as_0118, CT10  ]
+#      members: [ [ 0, 1, end ], [0, 1, end] ]
 
 Mz: 91.1876
 Mw: 80.385
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/yaml/parameters.yaml b/pdfdecompositions/GRV_PionPdfDecomposition/yaml/parameters.yaml
deleted file mode 100644
index e69de29bb..000000000
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h b/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h
similarity index 71%
rename from pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
rename to pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h
index a7b5f254d..7c9cd253f 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/include/GRV_PionPdfDecomposition.h
+++ b/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h
@@ -1,9 +1,9 @@
 #pragma once
 #include "BasePdfDecomposition.h"
 /**
-  @class GRV_PionPdfDecomposition 
+  @class SU3_PionPdfDecomposition 
 
-  @brief A class for GRV_Pion pdf decomposition
+  @brief A class for pdf decomposition for the pion with SU3-symmetric sea
 
   Used for pi-
   Assumes that at starting scale:
@@ -25,11 +25,11 @@
   @date 2018-08-14
   */
 namespace xfitter{
-class GRV_PionPdfDecomposition:public BasePdfDecomposition{
+class SU3_PionPdfDecomposition:public BasePdfDecomposition{
 	public:
-		GRV_PionPdfDecomposition();
-		GRV_PionPdfDecomposition(const std::string& inName);
-		~GRV_PionPdfDecomposition();
+		SU3_PionPdfDecomposition();
+		SU3_PionPdfDecomposition(const std::string& inName);
+		~SU3_PionPdfDecomposition();
 		virtual void initAtStart(const std::string & pars) override final;
 		virtual void initAtIteration()override final;
 		virtual std::function<std::map<int,double>(const double& x)>f0()const override final; 
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am b/pdfdecompositions/SU3_PionPdfDecomposition/src/Makefile.am
similarity index 69%
rename from pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am
rename to pdfdecompositions/SU3_PionPdfDecomposition/src/Makefile.am
index e385b63dc..fb7bcd83c 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/src/Makefile.am
+++ b/pdfdecompositions/SU3_PionPdfDecomposition/src/Makefile.am
@@ -4,13 +4,13 @@
 AM_CXXFLAGS = -I$(srcdir)/../include  -I$(srcdir)/../../../include -I$(srcdir)/../../../pdfparams/BasePdfParam/include/   -I$(srcdir)/../../BasePdfDecomposition/include -Wall -fPIC -Wno-deprecated \
               -I$(srcdir)/../../../pdfparams/PolySqrtPdfParam/include/ #Hacks - remove later
 
-lib_LTLIBRARIES=libGRV_PionPdfDecomposition_xfitter.la
-libGRV_PionPdfDecomposition_xfitter_la_SOURCES = GRV_PionPdfDecomposition.cc
+lib_LTLIBRARIES=libSU3_PionPdfDecomposition_xfitter.la
+libSU3_PionPdfDecomposition_xfitter_la_SOURCES = SU3_PionPdfDecomposition.cc
 
-datadir = ${prefix}/yaml/pdfdecompositions/GRV_Pion
+datadir = ${prefix}/yaml/pdfdecompositions/SU3_Pion
 data_DATA = ../yaml/parameters.yaml
 
 dist_noinst_HEADERS = ../include ../yaml
 
 # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx These hacks are temporary 
-libGRV_PionPdfDecomposition_xfitter_la_LDFLAGS=-lPolySqrtPdfParam_xfitter -lBasePdfParam_xfitter -L$(libdir)
+libSU3_PionPdfDecomposition_xfitter_la_LDFLAGS=-lPolySqrtPdfParam_xfitter -lBasePdfParam_xfitter -L$(libdir)
diff --git a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc b/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc
similarity index 70%
rename from pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
rename to pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc
index 83479261f..2c15b0cef 100644
--- a/pdfdecompositions/GRV_PionPdfDecomposition/src/GRV_PionPdfDecomposition.cc
+++ b/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc
@@ -1,36 +1,36 @@
 /*
-   @file GRV_PionPdfDecomposition.cc
+   @file SU3_PionPdfDecomposition.cc
    @date 2018-08-07
    @author  AddPdfDecomposition.py
-   Created by  AddPdfDecomposition.py on GRV_Pion
+   Created by  AddPdfDecomposition.py on SU3_Pion
 */
-#include"GRV_PionPdfDecomposition.h"
+#include"SU3_PionPdfDecomposition.h"
 #include"PolySqrtPdfParam.h" //This is for hacks, remove later
 #include"xfitter_pars.h"
 using uint=unsigned int;
 using namespace std;
 namespace xfitter{
 //For dynamic loading:
-extern "C" GRV_PionPdfDecomposition*create(){
-	return new GRV_PionPdfDecomposition();
+extern "C" SU3_PionPdfDecomposition*create(){
+	return new SU3_PionPdfDecomposition();
 }
-GRV_PionPdfDecomposition::GRV_PionPdfDecomposition():BasePdfDecomposition("GRV_Pion"){
+SU3_PionPdfDecomposition::SU3_PionPdfDecomposition():BasePdfDecomposition("SU3_Pion"){
 	par_v=nullptr;
 	par_S=nullptr;
 	par_g=nullptr;
 }
-GRV_PionPdfDecomposition::GRV_PionPdfDecomposition(const std::string& inName):BasePdfDecomposition(inName){}
-GRV_PionPdfDecomposition::~GRV_PionPdfDecomposition(){
+SU3_PionPdfDecomposition::SU3_PionPdfDecomposition(const std::string& inName):BasePdfDecomposition(inName){}
+SU3_PionPdfDecomposition::~SU3_PionPdfDecomposition(){
 	if(par_v)delete par_v;
 	if(par_S)delete par_S;
 	if(par_g)delete par_g;
 }
 // Init at start:
-void GRV_PionPdfDecomposition::initAtStart(const std::string & pars){
+void SU3_PionPdfDecomposition::initAtStart(const std::string & pars){
 	//HARDCODE copied from UvDvUbarDbarS, then modified
 	//The following is not very nice: Decomposition should not create or initialize parameterisations
 	//Create and initialize paramterisations
-	for(const auto&node:XFITTER_PARS::gParametersY.at("GRV_PionPdfDecomposition")["HARDWIRED_PolySqrt"]){
+	for(const auto&node:XFITTER_PARS::gParametersY.at("SU3_PionPdfDecomposition")["HARDWIRED_PolySqrt"]){
 		const string prmzName=node.first.as<string>();//Name of parameterisation
 		BasePdfParam*pParam=new PolySqrtPdfParam(prmzName);
 		pParam->initFromYaml(node.second);
@@ -40,7 +40,7 @@ void GRV_PionPdfDecomposition::initAtStart(const std::string & pars){
 	par_S=getPdfParam("S");
 	par_g=getPdfParam("g");
 }
-void GRV_PionPdfDecomposition::initAtIteration() {
+void SU3_PionPdfDecomposition::initAtIteration() {
 	//Enforce sum rules
 	//Valence sum
 	par_v->setMoment(-1,1);
@@ -48,7 +48,7 @@ void GRV_PionPdfDecomposition::initAtIteration() {
 	par_g->setMoment(0,1-6*par_S->moment(0)-2*par_v->moment(0));
 }
 // Returns a LHAPDF-style function, that returns PDFs in a physical basis for given x
-std::function<std::map<int,double>(const double& x)>GRV_PionPdfDecomposition::f0()const{
+std::function<std::map<int,double>(const double& x)>SU3_PionPdfDecomposition::f0()const{
 	return [=](double const& x)->std::map<int, double>{
 		double v=(*par_v)(x);
 		double S=(*par_S)(x);
-- 
GitLab


From a37c1e12990eed65b0e73064cab7cbacfca122e4 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Fri, 31 Aug 2018 13:02:25 +0200
Subject: [PATCH 15/26] New interfaces for evolutions and APPLgrid reaction

---
 .gitignore                                    |   6 +-
 evolutions/APFELxx/include/EvolutionAPFELxx.h |  13 +-
 evolutions/APFELxx/src/EvolutionAPFELxx.cc    |  13 +-
 .../BaseEvolution/include/BaseEvolution.h     |  43 +--
 evolutions/BaseEvolution/src/BaseEvolution.cc |   1 +
 evolutions/LHAPDF/include/EvolutionLHAPDF.h   |  11 +-
 evolutions/LHAPDF/src/EvolutionLHAPDF.cc      |  27 +-
 evolutions/QCDNUM/include/EvolutionQCDNUM.h   |  17 +-
 evolutions/QCDNUM/src/EvolutionQCDNUM.cc      |  41 ++-
 include/xfitter_pars.h                        |  22 +-
 .../CERESMinimizer/src/CERESMinimizer.cc      |   4 +-
 parameters.yaml                               |  46 ++-
 pdfparams/BasePdfParam/src/BasePdfParam.cc    |   6 +-
 reactions/APPLgrid/include/ReactionAPPLgrid.h |  14 +-
 reactions/APPLgrid/src/Makefile.am            |   9 +-
 reactions/APPLgrid/src/ReactionAPPLgrid.cc    | 161 +++------
 src/Profiler.cc                               | 328 +++++++++---------
 src/TheorEval.cc                              |  26 +-
 src/ftheor_eval.cc                            |  13 +-
 src/xfitter_pars.cc                           |  58 +++-
 src/xfitter_steer.cc                          |  98 +++---
 steering.txt                                  |   4 +-
 22 files changed, 466 insertions(+), 495 deletions(-)

diff --git a/.gitignore b/.gitignore
index c89da91b5..3f1542069 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,7 +21,6 @@ aclocal.m4
 autom4te.cache/
 *.m4
 config.guess
-config.log
 config.status
 config.sub
 configure
@@ -40,9 +39,6 @@ bak/
 constants.yaml
 datafiles/E615/
 deps/
-install.log
-install_yam.log
-make.log
 myconfigure.sh
 output*
 setup.sh
@@ -51,6 +47,8 @@ version
 xfitter-master/
 yaml/
 plots/
+outs/
+*.log
 
 # vim swap file
 *.swp
diff --git a/evolutions/APFELxx/include/EvolutionAPFELxx.h b/evolutions/APFELxx/include/EvolutionAPFELxx.h
index f5e311421..99f8ee2aa 100644
--- a/evolutions/APFELxx/include/EvolutionAPFELxx.h
+++ b/evolutions/APFELxx/include/EvolutionAPFELxx.h
@@ -18,22 +18,18 @@ namespace xfitter
 
      @brief Derived class of BaseEvolution for using APFEL++ as an evolution code.
 
-     @version 0.1
-     @date 2018-07-11
+     @version 0.2
+     @date 2018-09-29
   */
   class EvolutionAPFELxx: public BaseEvolution
   {
   public:
-    /// Empty constructor (needed for the dynamic loading)
-    EvolutionAPFELxx():  BaseEvolution{"APFELxx",nullptr} {}
-
-    /// Constructor wit PDF decomposition
-    EvolutionAPFELxx(std::function<std::map<int,double>(double const& x)> const& inPDFs): BaseEvolution{"APFELxx", inPDFs} {}
+    EvolutionAPFELxx(const char*name):BaseEvolution{name}{}
 
     /**
      * @brief Function that initialises the evolution in APFEL++.
      */
-    void initAtStart();
+    void initFromYaml(const YAML::Node);
 
     /**
      * @brief Function that updates the relevant parameters of the
@@ -76,6 +72,7 @@ namespace xfitter
     ///@}
 
   private:
+		std::function<std::map<int,double>(const double& x)>                    _inPDFs;
     std::vector<double>                                                     _Masses;
     std::vector<double>                                                     _Thresholds;
     std::unique_ptr<const apfel::Grid>                                      _Grid;
diff --git a/evolutions/APFELxx/src/EvolutionAPFELxx.cc b/evolutions/APFELxx/src/EvolutionAPFELxx.cc
index 6acaf7d1f..72f8f5885 100644
--- a/evolutions/APFELxx/src/EvolutionAPFELxx.cc
+++ b/evolutions/APFELxx/src/EvolutionAPFELxx.cc
@@ -10,22 +10,23 @@
 namespace xfitter
 {
   // the class factories
-  extern "C" EvolutionAPFELxx* create() {
-    return new EvolutionAPFELxx();
+  extern "C" EvolutionAPFELxx*create(const char*name){
+    return new EvolutionAPFELxx(name);
   }
 
 
   //_________________________________________________________________________________
-  void EvolutionAPFELxx::initAtStart()
+  void EvolutionAPFELxx::initFromYaml(const YAML::Node yamlNode)
   {
     // APFEL++ banner
     apfel::Banner();
 
+		_inPDFs=XFITTER_PARS::getInputFunctionFromYaml(yamlNode);
     // Retrieve parameters needed to initialize APFEL++.
     const double* MCharm   = XFITTER_PARS::gParameters.at("mch");
     const double* MBottom  = XFITTER_PARS::gParameters.at("mbt");
     const double* MTop     = XFITTER_PARS::gParameters.at("mtp");
-    const YAML::Node xGrid = XFITTER_PARS::gParametersY.at("APFELxx")["xGrid"];
+    const YAML::Node xGrid = yamlNode["xGrid"];
 
     vector<apfel::SubGrid> sgv;
     for(auto const& sg : xGrid)
@@ -51,6 +52,10 @@ namespace xfitter
     const double* Q0         = XFITTER_PARS::gParameters.at("Q0");
     const double* Q_ref      = XFITTER_PARS::gParameters.at("Mz");
     const double* Alphas_ref = XFITTER_PARS::gParameters.at("alphas");
+		//XXX HACKS XXX
+		//I do not understand how QGrid is supposed to change between iterations --Ivan
+		//This will not work with the new parameters.yaml syntax
+		//TODO
     const YAML::Node QGrid   = XFITTER_PARS::gParametersY.at("APFELxx")["QGrid"];
 
     // Reinitialise and tabulate the running coupling at every
diff --git a/evolutions/BaseEvolution/include/BaseEvolution.h b/evolutions/BaseEvolution/include/BaseEvolution.h
index a5c7c5ebf..29045e9cb 100644
--- a/evolutions/BaseEvolution/include/BaseEvolution.h
+++ b/evolutions/BaseEvolution/include/BaseEvolution.h
@@ -3,41 +3,37 @@
 #include <string>
 #include <map>
 #include <functional>
+#include <yaml-cpp/yaml.h>
 
 namespace xfitter
 {
   /**
      @class BaseEvolution
 
-     @brief Base class for the evolving quantities
+     @brief Base class for the evolved PDFs and other evolved quantities
 
      Contains methods to compute the evolution of PDFs, alpha_s, and
      other possible evolving quantites.
 
-     @version 0.1
-     @date 2018-07-11
+     @version 0.2
+     @date 2018-09-29
   */
-
-
-      
-
   class BaseEvolution
   {
   public:
+		/// Unique name of instance
+		const std::string _name;
     /**
      * @brief The BaseEvolution default constructor.
      * @param name: the name assignet to the instance
      */
-    BaseEvolution(const std::string& name, std::function<std::map<int,double>(double const& x)> const& inPDFs): _name(name), _inPDFs(inPDFs) { }
-
-    /// Explicitly set PDF decomposition
-    void SetPdfDecomposition(  std::function<std::map<int,double>(double const& x)> const& inPDFs) { _inPDFs = inPDFs;}
+    BaseEvolution(const char*name):_name(name){}
     
     /**
      * @brief Function to be called at the begining to initialise the
      * evolution code.
      */
-    virtual void initAtStart() = 0;
+    virtual void initFromYaml(const YAML::Node) = 0;
 
     /**
      * @brief Function to be call at each iteration to update the
@@ -45,37 +41,26 @@ namespace xfitter
      */
     virtual void initAtIteration() = 0;
 
-    /**
-     * @name Setters
-     */
-    ///@{
-    /**
-     * @brief Function to set the PdfDecomposition object to be used
-     * as initial scale distributions.
-     */
-    void SetInitialPDFs(std::function<std::map<int,double>(double const& x)> const& inPDFs) { _inPDFs = inPDFs; }
-    ///@}
-
     /**
      * @name Getters
      */
     ///@{
     /**
-     * @brief Function that returns a std::function that in turns
+     * @brief Function that returns a std::function that in turn
      * returns a map<int, double> as a function of x and Q.
      * @return map<int, double>-valued function of x and Q.
      */
     virtual std::function<std::map<int,double>(double const& x, double const& Q)> xfxQMap() = 0;
 
     /**
-     * @brief Function that returns a std::function that in turns
+     * @brief Function that returns a std::function that in turn
      * returns a double as a function of the pdf index i, x and Q.
      * @return double-valued function of i, x and Q.
      */
     virtual std::function<double(int const& i, double const& x, double const& Q)> xfxQDouble() = 0;
 
     /**
-     * @brief Function that returns a std::function that in turns
+     * @brief Function that returns a std::function that in turn
      * returns a void as a function of the pdf index x, Q, and pdfs,
      * where pdfs is the array of PDFs.
      * @return void-valued function of x, Q and pdfs.
@@ -89,9 +74,6 @@ namespace xfitter
      */
     virtual std::function<double(double const& Q)> AlphaQCD() = 0;
 
-    /// Get name 
-    const std::string getName() const { return _name; }
-
     /// Get generic property of the evolution
     virtual std::string getPropertyS(std::string const& propertyName ) const { return "" ; }
 
@@ -105,11 +87,10 @@ namespace xfitter
    
     
   protected:
-    const std::string                                    _name;
     std::function<std::map<int,double>(double const& x)> _inPDFs;
   };
 
   /// For dynamic loader
-  typedef BaseEvolution* create_evolution();
+  typedef BaseEvolution*create_evolution(const char*name);
 }
 
diff --git a/evolutions/BaseEvolution/src/BaseEvolution.cc b/evolutions/BaseEvolution/src/BaseEvolution.cc
index f3443f6f0..0081c72b2 100644
--- a/evolutions/BaseEvolution/src/BaseEvolution.cc
+++ b/evolutions/BaseEvolution/src/BaseEvolution.cc
@@ -1 +1,2 @@
 #include "BaseEvolution.h"
+//Why is this here???
diff --git a/evolutions/LHAPDF/include/EvolutionLHAPDF.h b/evolutions/LHAPDF/include/EvolutionLHAPDF.h
index 59bdaa597..c13b73d77 100644
--- a/evolutions/LHAPDF/include/EvolutionLHAPDF.h
+++ b/evolutions/LHAPDF/include/EvolutionLHAPDF.h
@@ -11,7 +11,12 @@
   */
 
 #include "BaseEvolution.h"
+//Try to suppress unused-local-typedef warning from boost 1.53.0 for gcc
+//Apparently these warnings have been fixed in later versions of boost
+#pragma GCC diagnostic push 
+#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
 #include "LHAPDF/LHAPDF.h"
+#pragma GCC diagnostic pop
 
 namespace xfitter 
 {
@@ -20,13 +25,11 @@ class EvolutionLHAPDF : BaseEvolution
 {
   public:
     /// Empty constructor (needed for the dynamic loading)
-    EvolutionLHAPDF():  BaseEvolution("LHAPDF",nullptr) {};
+    EvolutionLHAPDF(const char*name):BaseEvolution(name){};
 
   public:
-  /// Constructor setting the name
-    virtual std::string getEvolutionName() const { return  "LHAPDF" ;};
   /// Global initialization
-    virtual void initAtStart() override final;
+    virtual void initFromYaml(const YAML::Node) override final;
   /// Init at each iteration
     virtual void initAtIteration() override final;  
 
diff --git a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
index bf8c57a4d..e9300b687 100644
--- a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
+++ b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
@@ -15,21 +15,24 @@ namespace xfitter
 {
 
 // the class factories
-extern "C" EvolutionLHAPDF* create() {
-  return new EvolutionLHAPDF();
+extern "C" EvolutionLHAPDF*create(const char*name){
+  return new EvolutionLHAPDF(name);
 }
 
     
 /// Global initialization
-  void EvolutionLHAPDF::initAtStart() {
-
-    // Initialize LHAPDF XXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxx
-    auto pars = XFITTER_PARS::gParametersY["LHAPDF"];
-
-    _set_name = pars["set"].as<std::string>();
+  void EvolutionLHAPDF::initFromYaml(const YAML::Node pars) {
+    try{
+      _set_name = pars["set"].as<std::string>();
+    }catch(YAML::TypedBadConversion<std::string>&ex){
+      hf_errlog(18090310,"F: In EvolutionLHAPDF::initFromYaml: failed to convert YAML node \"set\" to string; printing node to stderr");
+      std::cerr<<pars<<std::endl;
+    }
 
     // check if exists first
     CheckForPDF(_set_name.c_str());
+    _member   = pars["member"].as<int>();
+    _pdf      = LHAPDF::mkPDF(_set_name,_member);//Doesn't one need to delete _pdf then later? --Ivan
     return ;
  };
     
@@ -37,12 +40,12 @@ extern "C" EvolutionLHAPDF* create() {
   void EvolutionLHAPDF::initAtIteration() {
 
     // Initialize LHAPDF XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-    auto pars = XFITTER_PARS::gParametersY["LHAPDF"];
+    //auto pars = XFITTER_PARS::gParametersY["LHAPDF"];
 
-    _set_name = pars["set"].as<std::string>();
-    _member   = pars["member"].as<int>();
+    //_set_name = pars["set"].as<std::string>();
+    //_member   = pars["member"].as<int>();
 
-    _pdf      = LHAPDF::mkPDF(_set_name,_member);
+    //_pdf      = LHAPDF::mkPDF(_set_name,_member);//Doesn't one need to delete _pdf then later? --Ivan
 
     return ;
   };
diff --git a/evolutions/QCDNUM/include/EvolutionQCDNUM.h b/evolutions/QCDNUM/include/EvolutionQCDNUM.h
index 44d9cfefe..669dcfb63 100644
--- a/evolutions/QCDNUM/include/EvolutionQCDNUM.h
+++ b/evolutions/QCDNUM/include/EvolutionQCDNUM.h
@@ -13,8 +13,8 @@
 
   @brief A wrapper class for QCDNUM evolution 
 
-  @version 0.1
-  @date 2018-08-14
+  @version 0.2
+  @date 2018-09-29
   */
 
 namespace xfitter
@@ -23,19 +23,16 @@ namespace xfitter
   class EvolutionQCDNUM: public BaseEvolution
   {
   public:
-    /// Empty constructor (needed for the dynamic loading)
-    EvolutionQCDNUM():  BaseEvolution{"QCDNUM",nullptr}{};
-    
-  public:
-    virtual std::string getEvolutionName() const { return  "QCDNUM" ;};
-    virtual void initAtStart() override final;
+    EvolutionQCDNUM(const char*name):BaseEvolution{name}{};
+
+    virtual void initFromYaml(const YAML::Node) override final;
     virtual void initAtIteration() override final;
     virtual std::function<std::map<int,double>(double const& x, double const& Q)> xfxQMap()  override final;
     virtual std::function<void(double const& x, double const& Q, double* pdfs)> xfxQArray() override final;
     virtual std::function<double(int const& i, double const& x, double const& Q)> xfxQDouble() override final;
     virtual std::function<double(double const& Q)> AlphaQCD() override final;
-  protected:
-    virtual int parseOptions(){ return 0;};
+//  protected:
+//    virtual int parseOptions(){ return 0;};
   private:
     /// PDFs called outside boundaries check:
     int _icheck{0};
diff --git a/evolutions/QCDNUM/src/EvolutionQCDNUM.cc b/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
index 055ce7b49..091649815 100644
--- a/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
+++ b/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
@@ -23,8 +23,11 @@ double funcPDF(int *ipdf, double *x) {
 
 // helper to parse yaml sequences of uniform type
 template <class T>
-vector<T> getSeq(std::string name) {
-  const  YAML::Node node   = XFITTER_PARS::gParametersY.at("QCDNUM")[name];
+vector<T> getSeq(const YAML::Node node) {
+	if(!node.IsSequence()){
+		std::cerr<<"[DEBUG]getSeq: node=\n"<<node<<std::endl;
+    hf_errlog(180829150,"F: In QCDNUM in function getSeq: wrong node type, expected sequence");
+	}
   size_t len = node.size();
   vector<T> v(len);
   for (size_t i=0; i<len; i++) {
@@ -55,14 +58,12 @@ namespace xfitter
 {
 
 // the class factories
-  extern "C" EvolutionQCDNUM* create() {
-    return new EvolutionQCDNUM();
+  extern "C" EvolutionQCDNUM* create(const char*name) {
+    return new EvolutionQCDNUM(name);
   }
 
-
-
   // Initialize at the start of the computation
-  void EvolutionQCDNUM::initAtStart()
+  void EvolutionQCDNUM::initFromYaml(const YAML::Node yQCDNUM)
   {
     QCDNUM::qcinit(6," ");
 
@@ -81,9 +82,9 @@ namespace xfitter
       QCDNUM::getint(memT[i].c_str(),itest);
 
       if (itest < siz[i]) {
-	std::string mess = "F: QCDNUM memory allocation insufficient. Recompile QCDNUM with at least "+memT[i] + " = " + std::to_string(siz[i]) + " in qcdnum.inc.";
-	hf_errlog(231020152,mess.c_str());
-      }      
+        std::string mess = "F: QCDNUM memory allocation insufficient. Recompile QCDNUM with at least "+memT[i] + " = " + std::to_string(siz[i]) + " in qcdnum.inc.";
+        hf_errlog(231020152,mess.c_str());
+      }
     }
 
     // Evolution order:
@@ -100,17 +101,15 @@ namespace xfitter
 
     //  const double* mtp     = XFITTER_PARS::gParameters.at("mtp");   // no top PDF treatment yet XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     
-    const YAML::Node yQCDNUM =  XFITTER_PARS::gParametersY.at("QCDNUM");
-
     _icheck      = yQCDNUM["ICheck"].as<int>();
     _splineOrder = yQCDNUM["SplineOrder"].as<int>();
     _readTables  = yQCDNUM["Read_QCDNUM_Tables"].as<int>();
 
     // Get grids
-    vector<double> xGrid   = getSeq<double>("xGrid");
-    vector<int>    xGridW  = getSeq<int>("xGridW");
-    vector<double> Q2Grid  = getSeq<double>("Q2Grid");
-    vector<double> Q2GridW = getSeq<double>("Q2GridW");
+    vector<double> xGrid   = getSeq<double>(yQCDNUM["xGrid"]);
+    vector<int>    xGridW  = getSeq<int>   (yQCDNUM["xGridW"]);
+    vector<double> Q2Grid  = getSeq<double>(yQCDNUM["Q2Grid"]);
+    vector<double> Q2GridW = getSeq<double>(yQCDNUM["Q2GridW"]);
 
     int nxgrid             = yQCDNUM["NXbins"].as<int>();
     int nxout = 0;
@@ -177,13 +176,14 @@ namespace xfitter
       QCDNUM::dmpwgt(1,22,"unpolarised.wgt");
     }
        
-    return ;
+		//Evolution gets its decomposition from YAML
+    gPdfDecomp=XFITTER_PARS::getInputFunctionFromYaml(yQCDNUM);
   }
 
   // Initialize at 
   void EvolutionQCDNUM::initAtIteration()
   {
-    gPdfDecomp = _inPDFs;
+		//TODO: reload decompositions?? --Ivan
     // XXXXXXXXXXXXXX
     const double* q0 = XFITTER_PARS::gParameters.at("Q0");
     int iq0  = QCDNUM::iqfrmq( (*q0) * (*q0) );
@@ -195,7 +195,6 @@ namespace xfitter
 
     QCDNUM::setalf(*alphas,(*Mz)*(*Mz));
     QCDNUM::evolfg(_itype,funcPDF,qcdnumDef,iq0,epsi);
-    return ;
   }
 
   std::function<std::map<int,double>(double const& x, double const& Q)> EvolutionQCDNUM::xfxQMap() {
@@ -203,8 +202,8 @@ namespace xfitter
     const auto _f0 =  [=] (double const& x, double const& Q) -> std::map<int, double> {
       std::map<int, double> res;
       for (int ipdf =-6; ipdf<7; ipdf++) {
-	int ii = ( ipdf == 0 ) ? 21 : ipdf ;
-	res[ii] = QCDNUM::fvalxq(_itype,ipdf,x,Q*Q,_icheck);
+        int ii = ( ipdf == 0 ) ? 21 : ipdf ;
+        res[ii] = QCDNUM::fvalxq(_itype,ipdf,x,Q*Q,_icheck);
       }
       return res;
     };
diff --git a/include/xfitter_pars.h b/include/xfitter_pars.h
index 73f9a56e2..ab6576e2b 100644
--- a/include/xfitter_pars.h
+++ b/include/xfitter_pars.h
@@ -22,11 +22,13 @@ using std::vector;
 
 namespace xfitter{
   // to be defined in evolutions/
-  class  BaseEvolution;
+  class BaseEvolution;
   // to be defined in pdfdecompositions/
-  class  BasePdfDecomposition;
+  class BasePdfDecomposition;
   // to be defined in minimizers/
   class BaseMinimizer;
+	using InitialPDFfunction=std::function<std::map<int,double>(const double&x)>;
+	using EvolvedPDFfunction=std::function<void(double const&x,double const&Q,double*pdfs)>;
 }
 
 namespace XFITTER_PARS {
@@ -49,16 +51,28 @@ namespace XFITTER_PARS {
   extern map<string,YAML::Node> gParametersY;
 
   /// Global map of PDF functions produced by evolutions. 
-  extern map<string,std::function<void(double const& x, double const& Q, double* pdfs)> > gXfxQArrays;
+  extern map<string,xfitter::EvolvedPDFfunction> gXfxQArrays;
 
   /// Global map to store evolutions
   extern map<string,xfitter::BaseEvolution*> gEvolutions;
 
-  /// Global map to store evolutions
+  /// Global map to store decompositions
   extern map<string,xfitter::BasePdfDecomposition*> gPdfDecompositions;
+	/// Helper function to get input function from a yaml node
+	///
+  /// It finds a "decomposition" subnode in given node, extracts a decomposition name from it, finds this decomposition and returns its output function
+  /// This function will either return a valid function, or issue a fatal error and never return
+  /// This is used in evolution initialization
+  xfitter::InitialPDFfunction getInputFunctionFromYaml(const YAML::Node&);
+  /// Helper function to get a yaml node corresponding to an evolution, by this evolutions's instance name
+	YAML::Node getEvolutionNode(const std::string&name="");
 
   /// Helper function to get string parameters
   std::string getParameterS(std::string name);
+
+  /// Helper functions
+	string getDefaultEvolutionName();
+	string getDefaultDecompositionName();
   
   /// Parse yaml file @param name
   void parse_file(const std::string& name);
diff --git a/minimizers/CERESMinimizer/src/CERESMinimizer.cc b/minimizers/CERESMinimizer/src/CERESMinimizer.cc
index d4b23521c..b9bef0b90 100644
--- a/minimizers/CERESMinimizer/src/CERESMinimizer.cc
+++ b/minimizers/CERESMinimizer/src/CERESMinimizer.cc
@@ -82,7 +82,9 @@ CERESMinimizer::CERESMinimizer(const std::string& inName) : BaseMinimizer(inName
 
 // Init at start:
 void CERESMinimizer::initAtStart() {
-  google::InitGoogleLogging("");
+	//There's a suppressed warning here
+	//warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
+  google::InitGoogleLogging((char*)"");
   return;
 }
 
diff --git a/parameters.yaml b/parameters.yaml
index d086394b5..047a129cf 100644
--- a/parameters.yaml
+++ b/parameters.yaml
@@ -1,6 +1,5 @@
 Minimizer: MINUIT
 
-PDFDecomposition: SU3_PionPdfDecomposition
 SU3_PionPdfDecomposition:
   HARDWIRED_PolySqrt: #=A*x^B*(1-x)^C*(1+D*sqrt(x)+E*x)
     v: [0.    , 0.6817,0.9794]
@@ -19,24 +18,35 @@ MINUIT:
     #hesse
     #fix 103 106 107 109 111 112 113 114 115 116 117 118 119 120 122
 
-Evolution: LHAPDF #QCDNUM LHAPDF
-QCDNUM:
-  xGrid   :   [9.9e-7, 0.01, 0.1, 0.4, 0.7]
-  xGridW  :   [1,       2,     4,   8,  16]
-  Q2Grid  :   [1.,  2.05e8 ]
-  Q2GridW :   [1.,     1.]  
-  NQ2bins :   120
-  NXbins  :   200
-  Read_QCDNUM_Tables : 1
-  SplineOrder : 2
-  ICheck  :   0
-LHAPDF:
-  set: "GRVPI0"
-  member: 0
+#New syntax
+#DefaultDecomposition: SU3_PionPdfDecomposition
+DefaultEvolution: pion #if this is not set, default evolution's name is "default"
 
-APPLgrid:  # APPLgrid specific
-  #LHAPDF_SetName: nCTEQ15FullNuc_184_74
-  #LHAPDF_MemberID: '0'
+Evolutions:
+  pion:
+    class: QCDNUM
+    decomposition: SU3_PionPdfDecomposition #this could be omitted, as the default decomposition is set
+    xGrid   :   [9.9e-7, 0.01, 0.1, 0.4, 0.7]
+    xGridW  :   [1,       2,     4,   8,  16]
+    Q2Grid  :   [1.,  2.05e8 ]
+    Q2GridW :   [1.,     1.]  
+    NQ2bins :   120
+    NXbins  :   200
+    Read_QCDNUM_Tables : 1
+    SplineOrder : 2
+    ICheck  :   0
+  tungsten_target:
+    class: LHAPDF
+    set:   nCTEQ15FullNuc_184_74
+    member: 0
+  reference_pion:
+    class: LHAPDF
+    set:   GRVPI0
+    member: 0
+APPLgrid:
+#Error: these parameters are not read yet
+  evolution1: pion #this can be overwritten in the datafile
+  evolution2: tungsten_target
   muF: 1.0
   muR: 1.0
   Order: NLO
diff --git a/pdfparams/BasePdfParam/src/BasePdfParam.cc b/pdfparams/BasePdfParam/src/BasePdfParam.cc
index ec680c177..992ec5926 100644
--- a/pdfparams/BasePdfParam/src/BasePdfParam.cc
+++ b/pdfparams/BasePdfParam/src/BasePdfParam.cc
@@ -60,10 +60,10 @@ void BasePdfParam::initFromYaml(YAML::Node value) {
   //TODO rewrite this for a different, new YAML format
   using namespace std;
   using uint=unsigned int;
-  cout<<"DEBUG["<<_name<<"]: initFromYaml: value="<<value<<endl;
+  //cout<<"DEBUG["<<_name<<"]: initFromYaml: value="<<value<<endl;
   if(value.IsSequence()){
     Npars=value.size();
-    cout<<Npars<<endl;
+    //cout<<Npars<<endl;
     pars=new double*[Npars];
     // HARDWIRE old-way for now:  XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     for(uint i=0;i<Npars;++i){
@@ -82,7 +82,7 @@ void BasePdfParam::initFromYaml(YAML::Node value) {
       minimizer->addParameter(val,pnam,step,nullptr,nullptr);
       
       pars[i]=XFITTER_PARS::gParameters.at(pnam);
-      cout<<pnam<<"="<<(*pars[i])<<endl;
+      //cout<<pnam<<"="<<(*pars[i])<<endl;
     }
   }else{
     cout<<"ERROR["<<_name<<"]: initFromYaml: parameter is not a sequence!"<<endl;
diff --git a/reactions/APPLgrid/include/ReactionAPPLgrid.h b/reactions/APPLgrid/include/ReactionAPPLgrid.h
index 76d6a2e0e..608e814f7 100644
--- a/reactions/APPLgrid/include/ReactionAPPLgrid.h
+++ b/reactions/APPLgrid/include/ReactionAPPLgrid.h
@@ -4,10 +4,7 @@
 #include "ReactionTheory.h"
 #include "appl_grid/appl_grid.h"
 #include <memory>
-
-#ifdef LHAPDF_ENABLED
-#include<LHAPDF/LHAPDF.h>
-#endif
+#include "BaseEvolution.h"
 
 /**
   @class' ReactionAPPLgrid
@@ -37,8 +34,9 @@ class ReactionAPPLgrid : public ReactionTheory
     virtual int parseOptions(){ return 0;};    
 
  private:
-    enum class collision {pp,ppbar,pn,LHAPDF};
-    map<int, collision> _collType;
+    enum class collision {pp,ppbar,pn,LHAPDF};//TODO: deprecated, remove this
+    //TODO: make this into a data structure
+    map<int, collision> _collType;//TODO:deprecated
     map<int, std::vector<std::shared_ptr<appl::grid> > > _grids;
     map<int, int> _order;
     map<int, double> _muR, _muF; // !> renormalisation and factorisation scales
@@ -46,8 +44,6 @@ class ReactionAPPLgrid : public ReactionTheory
     map<int, bool> _flagUseReference; // !> if true, prediction will be calculated from reference histogram (for tests and grids validation)
     map<int, std::vector<TH1D*> > _references;
     map<int, std::vector<double> > _eScale; // !> CMS energy
-#ifdef LHAPDF_ENABLED
-		map<int,LHAPDF::PDF*>lhapdf_pdf;
-#endif
+    xfitter::BaseEvolution*evolutions[2];//TODO these per dataset
 };
 
diff --git a/reactions/APPLgrid/src/Makefile.am b/reactions/APPLgrid/src/Makefile.am
index 37be56e3e..7b7764136 100644
--- a/reactions/APPLgrid/src/Makefile.am
+++ b/reactions/APPLgrid/src/Makefile.am
@@ -1,17 +1,10 @@
-# Created by AddReaction.py on 2017-03-28
-
 if ENABLE_APPLGRID
-  AM_CXXFLAGS = -I$(srcdir)/../include  -I$(srcdir)/../../../include  -I$(srcdir)/../../../interfaces/include -Wall -fPIC -Wno-deprecated 
+  AM_CXXFLAGS = -I$(srcdir)/../include  -I$(srcdir)/../../../include  -I$(srcdir)/../../../interfaces/include -I$(srcdir)/../../../evolutions/BaseEvolution/include -Wall -fPIC -Wno-deprecated 
 
   lib_LTLIBRARIES = libapplgrid_xfitter.la
   libapplgrid_xfitter_la_SOURCES = ReactionAPPLgrid.cc
 
   libapplgrid_xfitter_la_CPPFLAGS = $(APPLGRID_CPPFLAGS) $(ROOT_CFLAGS)
-if ENABLE_LHAPDF
-  AM_CXXFLAGS+=$(LHAPDF_CPPFLAGS)
-  libapplgrid_xfitter_la_CPPFLAGS+= $(LHAPDF_CPPFLAGS)
-  libapplgrid_xfitter_la_LDFLAGS  = $(LHAPDF_LDFLAGS)
-endif
 endif
 
 datadir = ${prefix}/yaml/reactions/APPLgrid
diff --git a/reactions/APPLgrid/src/ReactionAPPLgrid.cc b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
index 91cc82954..3b3fd4e90 100644
--- a/reactions/APPLgrid/src/ReactionAPPLgrid.cc
+++ b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
@@ -5,44 +5,48 @@
   Created by  AddReaction.py on 2017-03-28
 */
 
-#include "ReactionAPPLgrid.h"
-#include "TFile.h"
-
-#ifdef LHAPDF_ENABLED
-LHAPDF::PDF*active_pdf;
-void xfxLHAPDF_wrapper(const double&x,const double&Q,double*results){
-	vector<double>rtn;
-	active_pdf->xfxQ(x,Q,rtn);
-	std::copy(rtn.begin(),rtn.end(),results);
-}
-#endif
-
+#include"ReactionAPPLgrid.h"
+#include"TFile.h"
+#include"xfitter_pars.h"
+#include"xfitter_steer.h"
+using namespace std;
+using namespace xfitter;
  // the class factories
 extern "C" ReactionAPPLgrid* create() {
   return new ReactionAPPLgrid();
 }
-ReactionAPPLgrid::ReactionAPPLgrid(){}
-ReactionAPPLgrid::~ReactionAPPLgrid(){
-#ifdef LHAPDF_ENABLED
-	for(auto it=lhapdf_pdf.begin();it!=lhapdf_pdf.end();++it){
-		LHAPDF::PDF*p=it->second;
-		if(p)delete p;
-	}
-#endif
+function<void(double const&x,double const&Q,double*pdfs)>active_xfxQ_functions[2];
+void xfxWrapper0(const double&x,const double&Q,double*results){active_xfxQ_functions[0](x,Q,results);}
+void xfxWrapper1(const double&x,const double&Q,double*results){active_xfxQ_functions[1](x,Q,results);}
+ReactionAPPLgrid::ReactionAPPLgrid(){
+  evolutions[0]=nullptr;
+  evolutions[1]=nullptr;
 }
+ReactionAPPLgrid::~ReactionAPPLgrid(){}
  // Initialize at the start of the computation
-int ReactionAPPLgrid::initAtStart(const string &s )
-{
-   return 0;
-}
+int ReactionAPPLgrid::initAtStart(const string &s){return 0;}
 
  // Initialize for a given dataset:
 void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pars, map<string, double> parsDataset) {
+  //<DEBUG
+  cerr<<"[DEBUG]ReactionAPPLgrid::setDatasetParameters(dataSetID="<<dataSetID<<",pars,parsDataset):\n"
+      <<"pars={\n";
+  for(map<string,string>::const_iterator it=pars.begin();it!=pars.end();++it){
+    cerr<<"  \""<<it->first<<"\":\""<<it->second<<"\"\n";
+  }
+  cerr<<"}"<<endl;
+  cerr<<"parsDataset={\n";
+  for(map<string,double>::const_iterator it=parsDataset.begin();it!=parsDataset.end();++it){
+    cerr<<"  \""<<it->first<<"\":"<<it->second<<'\n';
+  }
+  cerr<<"}"<<endl;
+  //DEBUG>
 	map<string,string>::iterator it;
 	// Get grid name:
-   if ( pars.find("GridName") != pars.end() )  {
-     try {
-       std::istringstream ss(pars["GridName"]);
+  it=pars.find("GridName");
+  if(it!=pars.end()){
+    try{
+      std::istringstream ss(it->second);
        //std::cout << pars["GridName"] << '\n';
        std::string token;
        while(std::getline(ss, token, ','))
@@ -68,49 +72,14 @@ void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pa
      std::string text = "F:GridName must be specified for the Reaction APPLgrid";
      hf_errlog_(17032801,text.c_str(),text.size());
    }
-
-//Initialize for LHAPDF
-//To be used when PDF of second particle is static and of LHAPDF
-//Parameters are passed via TermInfo in theory expression in datafile:
-//*LHAPDF_SetName
-//*LHAPDF_MemberID --- defaults to 0
-#ifdef LHAPDF_ENABLED
-	{
-	it=pars.find("LHAPDF_SetName");
-	auto itMemberID=pars.find("LHAPDF_MemberID");
-	if(it!=pars.end()){
-		int member_id=0;
-		try{
-			if(itMemberID!=pars.end())member_id=std::stoi(itMemberID->second);
-		}catch(const std::exception&ex){
-			std::ostringstream s;
-			s<<"F:Failed to read PDF memberID for LHAPDF set \""<<it->second<<"\" for use with APPLgrid; dataSetID="<<dataSetID;
-			s<<"; Exception:"<<ex.what();
-			hf_errlog(3081810,s.str().c_str());
-		}
-		//Make sure to set collision=LHAPDF
-		//std::cout<<"DEBUG LHAPDF_SetName="<<it->second<<std::endl;
-		LHAPDF::PDF*p=LHAPDF::mkPDF(it->second,member_id);
-		if(!p){
-			std::ostringstream s;
-			s<<"F:LHAPDF failed to load PDF set \""<<it->second<<"\" for use with APPLgrid; dataSetID="<<dataSetID;
-			hf_errlog(28071810,s.str().c_str());
-		}
-		lhapdf_pdf[dataSetID]=p;
-	}else{
-		if(itMemberID!=pars.end()){
-			std::ostringstream s;
-			s<<"W: In APPLgrid reaction parameters (dataSetID="<<dataSetID<<") memberID="<<itMemberID->second<<" is given, but set itself is not";
-			hf_errlog(3081811,s.str().c_str());
-		}
-	}
-	}
-#else
-	if(pars.find("LHAPDF_SetName")!=pars.end()||pars.find("LHAPDF_MemberID")!=pars.end()){
-		hf_errlog(25071812,"F:LHAPDF parameter specified for APPLgrid reaction, but xFitter has been compiled without LHAPDF. Use --enable-lhapdf at configure to enable.")
-	}
-#endif
-
+// Get pointers to evolutions
+  for(int i=0;i<2;++i){
+    string evolutionName="";
+    it=pars.find("evolution"+to_string(i+1));
+    if(it!=pars.end())evolutionName=it->second;//else default evolution name will be used
+    cerr<<"[DEBUG]APPLgrid: use evolution \""<<evolutionName<<'\"'<<endl;
+    evolutions[i]=get_evolution(evolutionName);
+  }
 // Determine order
    int order = OrderMap( GetParamS("Order"));  // Global order
    if (pars.find("Order") != pars.end() ) { // Local order
@@ -125,29 +94,6 @@ void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pa
 
   if (_muR[dataSetID] == 0) _muR[dataSetID] = 1.0; 
   if (_muF[dataSetID] == 0) _muF[dataSetID] = 1.0;
-
-// Determine if pp or ppbar
-  _collType[dataSetID] = collision::pp;
-  if (parsDataset.find("ppbar") != parsDataset.end() ) {
-    _collType[dataSetID] = collision::ppbar;
-  }
-  if (parsDataset.find("pn") != parsDataset.end() ) {
-    _collType[dataSetID] = collision::pn;
-  }
-  // check if collision settings are provided in the new format key=value
-  it=pars.find("collision");
-  if (it != pars.end() )
-  {
-    if     (it->second=="pp")    _collType[dataSetID]=collision::pp;
-    else if(it->second=="ppbar") _collType[dataSetID]=collision::ppbar;
-    else if(it->second=="pn")    _collType[dataSetID]=collision::pn;
-		else if(it->second=="LHAPDF"){
-			_collType[dataSetID]=collision::LHAPDF;
-			if(lhapdf_pdf.find(dataSetID)==lhapdf_pdf.end())hf_errlog(24071810,"W: collision type=LHAPDF but no LHAPDF set was loaded");
-		}
-    else
-      hf_errlog(17102101, "F: unrecognised collision type = " + it->second);
-  }
   // bin width normalisation (by default no rescaling)
   _flagNorm[dataSetID] = false;
   it = pars.find("norm");
@@ -202,35 +148,18 @@ void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pa
 
  // Main function to compute results at an iteration
 int ReactionAPPLgrid::compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err) {
-  //
-
   // iterate over grids
   unsigned int pos = 0;
   for(unsigned int g = 0; g < _grids[dataSetID].size(); g++)
   {
     auto grid = _grids[dataSetID][g];
     std::vector<double> gridVals(grid->Nobs());
-    if(!_flagUseReference[dataSetID])
-    {
-      // Convolute the grid:
-      switch (_collType[dataSetID])
-      {
-        case collision::pp :
-          gridVals =  grid->vconvolute( getXFX(), getAlphaS(), _order[dataSetID]-1, _muR[dataSetID], _muF[dataSetID], _eScale[dataSetID][g] );
-          break;
-        case collision::ppbar :
-          gridVals =  grid->vconvolute( getXFX(), getXFX("pbar"), getAlphaS(), _order[dataSetID]-1, _muR[dataSetID], _muF[dataSetID], _eScale[dataSetID][g] );
-          break;
-        case collision::pn :
-          gridVals =  grid->vconvolute( getXFX(), getXFX("n"), getAlphaS(), _order[dataSetID]-1, _muR[dataSetID], _muF[dataSetID], _eScale[dataSetID][g] );
-          break;
-#ifdef LHAPDF_ENABLED
-        case collision::LHAPDF:
-					active_pdf=lhapdf_pdf.find(dataSetID)->second;
-          gridVals=grid->vconvolute(getXFX(),xfxLHAPDF_wrapper,getAlphaS(),_order[dataSetID]-1, _muR[dataSetID], _muF[dataSetID], _eScale[dataSetID][g] );
-          break;
-#endif
-      }
+    if(!_flagUseReference[dataSetID]){
+      //For some reason we do not take alphaS from evolutions?
+      active_xfxQ_functions[0]=evolutions[0]->xfxQArray();
+      active_xfxQ_functions[1]=evolutions[1]->xfxQArray();
+      gridVals=grid->vconvolute(xfxWrapper0,xfxWrapper1,getAlphaS(),_order[dataSetID]-1,_muR[dataSetID],_muF[dataSetID],_eScale[dataSetID][g]);
+      //TODO: call specialized vconvolute when the two evolutions are the same
     }
     else
     {
diff --git a/src/Profiler.cc b/src/Profiler.cc
index 42619453f..7b86b54ba 100644
--- a/src/Profiler.cc
+++ b/src/Profiler.cc
@@ -75,20 +75,20 @@ namespace xfitter
 
     if ( node )  {
       for ( auto const& term : node ) {
-	std::string name = term.first.as<string>();
-	// check if present on the global list
-	if ( XFITTER_PARS::gParameters.find(name) != XFITTER_PARS::gParameters.end() ) {
-	  profileParameter(name, term.second);
-	}
-	
-	else if ( name == "evolutions") {
-	  for ( auto const& evol : term.second ) {
-	    std::string const name = term.first.as<string>();
-	    // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-	    profilePDF("",evol.second );
-	  }
-	}
-	
+        std::string name = term.first.as<string>();
+        // check if present on the global list
+        if ( XFITTER_PARS::gParameters.find(name) != XFITTER_PARS::gParameters.end() ) {
+          profileParameter(name, term.second);
+        }
+        
+        else if ( name == "evolutions") {
+          for ( auto const& evol : term.second ) {
+            std::string const name = term.first.as<string>();
+            // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+            profilePDF("",evol.second );
+          }
+        }
+        
       };
     }      
     return;
@@ -99,7 +99,7 @@ namespace xfitter
     if ( node.IsSequence() ) {
       size_t len = node.size();
       if ( (len != 2) && (len != 3)  ) {
-	hf_errlog( 2018082301,"S: Expected 2 or 3 parameters for a profiled variable. Check variable "+name);
+        hf_errlog( 2018082301,"S: Expected 2 or 3 parameters for a profiled variable. Check variable "+name);
       }
 
       // Evaluate varied predictions:
@@ -108,18 +108,18 @@ namespace xfitter
 
       double save = *ppar;
       for ( size_t i=0; i<len; i++) {
-	double val = node[i].as<double>();
-	*ppar = val;
-	preds.push_back( evaluatePredictions() );	
+        double val = node[i].as<double>();
+        *ppar = val;
+        preds.push_back( evaluatePredictions() );       
       }
       *ppar = save;
 
       // Add to systematics list:
       if ( len == 2) {
-	addSystematics(name+":T",(preds[1]-preds[0])/preds[0]);
+        addSystematics(name+":T",(preds[1]-preds[0])/preds[0]);
       }
       else {
-	addSystematics(name+":T",(preds[1]-preds[0])/preds[0], (preds[2]-preds[0])/preds[0]);
+        addSystematics(name+":T",(preds[1]-preds[0])/preds[0], (preds[2]-preds[0])/preds[0]);
       }
     }
   }
@@ -127,150 +127,146 @@ namespace xfitter
   void Profiler::profilePDF( std::string const& evolName, YAML::Node const& node) {
     // get evolution
 
-    
+
     auto *evol = get_evolution(evolName);
     // get corresponding yaml node:
-    std::string eName = evol->getName();
-    YAML::Node *gNode = & XFITTER_PARS::gParametersY[eName];
+    YAML::Node gNode=XFITTER_PARS::getEvolutionNode(evolName);
 
-    //std::cout << "DEBUG: " << eName << "\n" << (*gNode) << std::endl;
+    //std::cout << "DEBUG: " << evolName << "\n" << (*gNode) << std::endl;
     //std::cout << "DEBUG3: " << node << std::endl;
 
     
     YAML::Node const sets = node["sets"];
     YAML::Node const members = node["members"];
+    //Sanity checks
     if ( !sets || !members  ) {
-      hf_errlog(2018082401,"S: Profiler: missing set or member parameters for evolution "+eName);  // XXXXXXXXXXXXXXXX
+      hf_errlog(2018082401,"S: Profiler: missing set or member parameters for evolution "+evolName);  // XXXXXXXXXXXXXXXX
+    }
+    if(!sets.IsSequence()||!members.IsSequence()){
+      hf_errlog(2018082402,"S: Profiler: sets and members must be sequence");  // XXXXXXXXXXXXXXXX
+    }
+    if(sets.size()!=members.size()){
+      hf_errlog(2018082403,"S: Profiler: sets and members must be the same length");  // XXXXXXXXXXXXXXXX
     }
 
-    
-    if ( sets.IsSequence() && members.IsSequence() ) {
-      if ( sets.size() == members.size() ) {
-	size_t endi = sets.size();
-	for (size_t i=0; i< endi; i++) {
-	  std::string pName = sets[i].as<string>();
-	  
-	  if ( members[i].IsSequence() ) {
-	    int msize = members[i].size();
-
-	    if ( msize != 3) {
-	      hf_errlog(2018082404,"S: Profiler: sets must be sequence of length 3");  // XXXXXXXXXXXXXXXX
-	    }
-
-	    int central = members[i][0].as<int>();
-	    int first   = members[i][1].as<int>();
-	    int last = 0;
-
-	    try {
-	      last =  members[i][2].as<int>();
-	    }
-	    catch (...) {
-	      last = 0; /// auto-decodez
-	    }
-	      
-	    // save original
-	    auto oSet    = (*gNode)["set"] ;
-	    auto oMember = (*gNode)["member"] ;
-	    
-	    if ( ! oSet  || ! oMember ) {
-	      hf_errlog(2018082410,"S: No set or member variables for evolution : "+eName);
-	    }
-
-	    // all predictions
-	    std::vector< std::valarray<double> > preds;      
-	   
-	    // Set central PDF and init 
-	    (*gNode)["set"] = pName;
-	    (*gNode)["member"] = central;
-	    preds.push_back(evaluatePredictions() );
-
-	    
-	    // now we can get set properties: is it hessia asymmetric, MC or symmetric hessian
-	    std::string errorType = evol->getPropertyS("ErrorType");
-	    std::cout << errorType << std::endl;
-
-	    if ( last == 0) {
-	      // auto determine XXXXXXXXXXXXXXXX
-	      last = evol->getPropertyI("NumMembers")-1;
-	    }
-	    
-	    if ( last > evol->getPropertyI("NumMembers") ) {
-	      hf_errlog(2018082431,"W: Profller: too many members requested, use max instead");
-	    };
-
-	    if (errorType == "hessian") {
-	      if ( (last - first + 1) % 2 != 0 ) {
-		hf_errlog(2018082431,"S: Profller: hessian sets need even number of members. Check your inputs");
-	      }
-	      if ( first % 2 == 0 ) {
-		hf_errlog(2018082432,"S: Profller: hessian error members should start from odd number. Check your inputs");
-	      }
-	    }
-	    	    
-	    // loop over all
-	    for (int imember = first; imember<=last; imember++) {
-	      (*gNode)["member"] = imember;
-	      preds.push_back( evaluatePredictions() );
-	      //	      for ( double th : preds[imember] ) {
-	      //std::cout << th << std::endl;
-	      //}
-	      //std::cout << imember << std::endl;
-	    }
-
-	    // Restore original
-	    
-	    (*gNode)["set"] = oSet ;
-	    (*gNode)["member"]  = oMember;
-
-	    
-	    // Depending on error type, do nuisance parameters addition
-	    if ( errorType == "symmhessian" ) {
-	      for (int imember = first; imember<=last; imember++) {
-		addSystematics("PDF_nuisance_param_"+std::to_string( ++_ipdf )+":T",(preds[imember]-preds[0])/preds[0]);
-	      }
-	    }
-	    else if ( errorType == "hessian") {
-	      for (int imember = first; imember<=last; imember += 2) {
-		addSystematics("PDF_nuisance_param_"+std::to_string( ++_ipdf )+":T"
-			       ,(preds[imember]-preds[0])/preds[0]
-			       ,(preds[imember+1]-preds[0])/preds[0]);
-	      }
-	    }
-	    else if ( errorType == "replicas") {
-	      // construct average 
-	      for (size_t i=0; i<preds[0].size(); i++) {
-		preds[0][i] = 0;
-	      }
-	      for ( int i=first; i<=last; i++) {
-		preds[0] += preds[i];
-	      }
-	      preds[0] /= (last-first+1);
-	      
-	      // convert replicas to deviations from average:
-	      for ( int i=first; i<=last; i++) {
-		preds[i] -= preds[0];
-	      }
-
-	      // convert to eigenvectors, add to list of systematics
-	      addReplicas(pName,preds);
-	    }
-	    else {
-	      hf_errlog(2018082441,"S: Profiler Unsupported PDF error type : "+errorType);
-	    }
-	    
-	  }
-	  else {
-	    hf_errlog(2018082404,"S: Profiler: sets must be sequence of length 3");  // XXXXXXXXXXXXXXXX
-	  }
-	}
+
+    size_t endi = sets.size();
+    for (size_t i=0; i< endi; i++) {
+      std::string pName = sets[i].as<string>();
+
+      if ( members[i].IsSequence() ) {
+        int msize = members[i].size();
+
+        if ( msize != 3) {
+          hf_errlog(2018082404,"S: Profiler: sets must be sequence of length 3");  // XXXXXXXXXXXXXXXX
+        }
+
+        int central = members[i][0].as<int>();
+        int first   = members[i][1].as<int>();
+        int last = 0;
+
+        try {
+          last =  members[i][2].as<int>();
+        }
+        catch (...) {
+          last = 0; /// auto-decodez
+        }
+          
+        // save original
+        auto oSet   =gNode["set"];
+        auto oMember=gNode["member"];
+
+        if ( ! oSet  || ! oMember ) {
+          hf_errlog(2018082410,"S: No set or member variables for evolution : "+evolName);
+        }
+
+        // all predictions
+        std::vector< std::valarray<double> > preds;
+
+        // Set central PDF and init 
+        gNode["set"]   =pName;
+        gNode["member"]=central;
+        preds.push_back(evaluatePredictions() );
+
+
+        // now we can get set properties: is it hessian asymmetric, MC or symmetric hessian
+        std::string errorType = evol->getPropertyS("ErrorType");
+        std::cout << errorType << std::endl;
+
+        if ( last == 0) {
+          // auto determine XXXXXXXXXXXXXXXX
+          last = evol->getPropertyI("NumMembers")-1;
+        }
+        
+        if ( last > evol->getPropertyI("NumMembers") ) {
+          hf_errlog(2018082431,"W: Profiler: too many members requested, use max instead");
+        };
+
+        if (errorType == "hessian") {
+          if ( (last - first + 1) % 2 != 0 ) {
+            hf_errlog(2018082431,"S: Profiler: hessian sets need even number of members. Check your inputs");
+          }
+          if ( first % 2 == 0 ) {
+            hf_errlog(2018082432,"S: Profiler: hessian error members should start from odd number. Check your inputs");
+          }
+        }
+                
+        // loop over all
+        for (int imember = first; imember<=last; imember++) {
+          gNode["member"] = imember;
+          preds.push_back( evaluatePredictions() );
+          //              for ( double th : preds[imember] ) {
+          //std::cout << th << std::endl;
+          //}
+          //std::cout << imember << std::endl;
+        }
+
+        // Restore original
+
+        gNode["set"]   =oSet;
+        gNode["member"]=oMember;
+
+
+        // Depending on error type, do nuisance parameters addition
+        if ( errorType == "symmhessian" ) {
+          for (int imember = first; imember<=last; imember++) {
+            addSystematics("PDF_nuisance_param_"+std::to_string( ++_ipdf )+":T",(preds[imember]-preds[0])/preds[0]);
+          }
+        }
+        else if ( errorType == "hessian") {
+          for (int imember = first; imember<=last; imember += 2) {
+            addSystematics("PDF_nuisance_param_"+std::to_string( ++_ipdf )+":T"
+                           ,(preds[imember]-preds[0])/preds[0]
+                           ,(preds[imember+1]-preds[0])/preds[0]);
+          }
+        }
+        else if ( errorType == "replicas") {
+          // construct average 
+          for (size_t i=0; i<preds[0].size(); i++) {
+            preds[0][i] = 0;
+          }
+          for ( int i=first; i<=last; i++) {
+            preds[0] += preds[i];
+          }
+          preds[0] /= (last-first+1);
+          
+          // convert replicas to deviations from average:
+          for ( int i=first; i<=last; i++) {
+            preds[i] -= preds[0];
+          }
+
+          // convert to eigenvectors, add to list of systematics
+          addReplicas(pName,preds);
+        }
+        else {
+          hf_errlog(2018082441,"S: Profiler Unsupported PDF error type : "+errorType);
+        }
+        
       }
       else {
-	hf_errlog(2018082403,"S: Profiler: sets and members must be the same length");  // XXXXXXXXXXXXXXXX
+        hf_errlog(2018082404,"S: Profiler: sets must be sequence of length 3");  // XXXXXXXXXXXXXXXX
       }
     }
-    else {
-      hf_errlog(2018082402,"S: Profiler: sets and members must be sequence");  // XXXXXXXXXXXXXXXX
-    }    
   }
   
   void Profiler::addReplicas(std::string const& pdfName,  std::vector< std::valarray<double> > const& uncertainties) {
@@ -284,35 +280,35 @@ namespace xfitter
     
     for ( int i=0; i<ndata; i++) {
       for ( int j=i; j<ndata; j++) {
-	int id = i*ndata + j;
-	covar[id] = 0;
-
-	for ( int k=1; k<=nrep; k++) {
-	  covar[id] += uncertainties[k][i]*uncertainties[k][j] ;
-	}
-
-	covar[id] /= nrep;
-	
-	if ( i != j ) {
-	  int id2 = j*ndata + i;
-	  covar[id2] = covar[id];
-	}	
+        int id = i*ndata + j;
+        covar[id] = 0;
+
+        for ( int k=1; k<=nrep; k++) {
+          covar[id] += uncertainties[k][i]*uncertainties[k][j] ;
+        }
+
+        covar[id] /= nrep;
+        
+        if ( i != j ) {
+          int id2 = j*ndata + i;
+          covar[id2] = covar[id];
+        }       
       }
     }
     double *beta = new double[ndata*ndata];
     double alpha[ndata];
     int ncorr = 0;
     getnuisancefromcovar_(ndata,ndata,ndata,
-			    covar,beta,0,
-			    ncorr,alpha,0);
+                            covar,beta,0,
+                            ncorr,alpha,0);
     //    std::cout << "NCorr = " << beta[0] << " " << ncorr << std::endl;
     // ready to add systematic sources
 
     for ( int i=0; i<ncorr; i++) {
       valarray<double> unc(ndata);
       for ( int j=0; j<ndata; j++) {
-	unc[j] = beta[ndata*j + i];
-	//	std::cout << unc[j] << std::endl;
+        unc[j] = beta[ndata*j + i];
+        //      std::cout << unc[j] << std::endl;
       }
       addSystematics("PDF_nuisance_param_"+std::to_string(++_ipdf)+":T", unc/uncertainties[0] );
     }
diff --git a/src/TheorEval.cc b/src/TheorEval.cc
index 5c72815ea..4278d9725 100644
--- a/src/TheorEval.cc
+++ b/src/TheorEval.cc
@@ -265,7 +265,28 @@ TheorEval::initTerm(int iterm, valarray<double> *val)
   }
 }
 
-
+void LoadParametersFromYAML(std::map<std::string,std::string>&pars,const std::string&reactionName){
+  using std::string;
+  //add to pars all parameters given in YAML file, but do not overwrite any parameters already in pars
+  auto it=XFITTER_PARS::gParametersY.find(reactionName);
+  if(it==XFITTER_PARS::gParametersY.end()){
+    hf_errlog(18090300,"W: No parameters for reaction \""+reactionName+"\" found in YAML steering file");
+    return;
+  }
+  YAML::Node&reactionNode=it->second;
+  try{
+    for(YAML::const_iterator it=reactionNode.begin();it!=reactionNode.end();++it){
+      string key=it->first.as<string>();
+      auto pit=pars.find(key);
+      if(pit==pars.end())pars[key]=it->second.as<string>();
+    }
+  }catch(YAML::TypedBadConversion<string>ex){
+    cerr<<"[ERROR] In LoadParametersFromYAML(pars,reactionName="<<reactionName<<"):\n"
+        <<"  YAML failed to convert to string while parsing node:\n"
+        <<reactionNode<<"\n[/ERROR]"<<endl;
+    hf_errlog(18090301,"F: YAML error in LoadParametersFromYAML, details written to stderr");
+  }
+}
 int
 TheorEval::initReactionTerm(int iterm, valarray<double> *val)
 {
@@ -327,8 +348,8 @@ TheorEval::initReactionTerm(int iterm, valarray<double> *val)
       rt->resetParameters(XFITTER_PARS::gParametersY[term_source]);
     }
 
+    std::string evoName =XFITTER_PARS::getDefaultEvolutionName();
     // Set the evolution:
-    std::string evoName = XFITTER_PARS::gParametersS.at("Evolution"); 
     rt->setEvolution(evoName);
 
     //Retrieve evolution
@@ -363,6 +384,7 @@ TheorEval::initReactionTerm(int iterm, valarray<double> *val)
   
   // split term_info into map<string, string> according to key1=value1:key2=value2:key=value3...
   map<string, string> pars = SplitTermInfo(term_info);
+  LoadParametersFromYAML(pars,rt->getReactionName());
 
   // and transfer to the module
   rt->setDatasetParameters(_dsId*1000+iterm, pars, _dsPars);
diff --git a/src/ftheor_eval.cc b/src/ftheor_eval.cc
index 240f08e2b..947146360 100644
--- a/src/ftheor_eval.cc
+++ b/src/ftheor_eval.cc
@@ -315,15 +315,18 @@ void init_at_iteration_() {
   }
 
   
-  for ( auto evolution : XFITTER_PARS::gEvolutions) {
-    evolution.second->initAtIteration();
+  for(auto it:XFITTER_PARS::gEvolutions) {
+		xfitter::BaseEvolution*evolution=it.second;
+    evolution->initAtIteration();
 
     // register updated PDF XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-    const auto f = evolution.second->xfxQDouble();
+		//Wait, do they get updated between iterations? Is this here even necessary? --Ivan
+
+    //const auto f = it.second->xfxQDouble();
     //    std::cout << "Gluon(1) = " << f(0, 0.00001, 100) << std::endl;
-    const std::string evolName = evolution.second->getName() +":p";
+    const std::string evolName=evolution->_name+":p"; //Not sure why we need ":p" here --Ivan
     
-    XFITTER_PARS::registerXfxQArray(evolName,evolution.second->xfxQArray());
+    XFITTER_PARS::registerXfxQArray(evolName,evolution->xfxQArray());
   }
 
 
diff --git a/src/xfitter_pars.cc b/src/xfitter_pars.cc
index 7e0e63ae3..0cbc12656 100644
--- a/src/xfitter_pars.cc
+++ b/src/xfitter_pars.cc
@@ -8,6 +8,7 @@
  */
 
 #include "xfitter_pars.h"
+#include "xfitter_steer.h"
 #include "xfitter_cpp.h"
 #include "xfitter_cpp_base.h"
 #include <fstream>
@@ -51,7 +52,36 @@ namespace XFITTER_PARS {
   map<string,xfitter::BaseEvolution*> gEvolutions;
   // Also keep list of loaded evolutions here:
   map<string,xfitter::BasePdfDecomposition*> gPdfDecompositions;
-  
+
+  using namespace xfitter;
+  xfitter::InitialPDFfunction getInputFunctionFromYaml(const YAML::Node&rootNode){
+    YAML::Node node=rootNode["decomposition"];
+    string name;
+    try{
+      name=node.as<string>();
+    }catch(YAML::TypedBadConversion<string>ex){
+      ostringstream s;s<<"W: YAML exception: "<<ex.what()<<"; while trying to extract decomposition name from node: "<<node<<"; using default decomposition name";
+      hf_errlog(18082930,s.str().c_str()); 
+      name=getDefaultDecompositionName();
+    }
+    return xfitter::get_pdfDecomposition(name)->f0();
+  }
+	YAML::Node getEvolutionNode(const std::string&name){
+    auto it=gParametersY.find("Evolutions");
+    if(it==gParametersY.end()){
+      hf_errlog(18082900,"F:Failed to get evolution "+name+": Evolutions node not found in parameters.yaml");
+    }
+    YAML::Node instanceNode=it->second[name];
+    if(!instanceNode.IsMap()){
+			std::ostringstream s;
+			s<<"F:Failed to get evolution \""<<name<<"\": ";
+      if(!instanceNode)s<<"no subnode with this name under the node Evolutions";
+      else s<<"corresponding subnode is not of type Map";
+			hf_errlog(18082901,s.str().c_str());
+    }
+		return instanceNode;
+	}
+
   std::string getParameterS(std::string name) {
     auto search = gParametersS.find(name);
     if ( search != gParametersS.end() ) {
@@ -62,7 +92,17 @@ namespace XFITTER_PARS {
       return ""; // not found
     }
   }
-  
+
+  string getDefaultEvolutionName(){
+    auto it=gParametersS.find("DefaultEvolution");
+    if(it!=gParametersS.end()) return it->second;
+    return "default";
+  }
+  string getDefaultDecompositionName(){
+    auto it=gParametersS.find("DefaultDecomposition");
+    if(it!=gParametersS.end())return it->second;
+    return "default";
+  }
 // Helper function
   bool is_file_exist(const char *fileName)
   {
@@ -74,8 +114,8 @@ namespace XFITTER_PARS {
   {
     try {
       if ( ! std::ifstream(name).good()) {
-	string text = "F: Problems opening parameters file " + name;
-	hf_errlog_(18032001,text.c_str(), text.size());
+        string text = "F: Problems opening parameters file " + name;
+        hf_errlog_(18032001,text.c_str(), text.size());
       }
       YAML::Node node = YAML::LoadFile(name);
       parse_node(node, gParameters, gParametersI, gParametersS, gParametersV, gParametersY);
@@ -93,11 +133,11 @@ namespace XFITTER_PARS {
 
   // Parse @param node and return maps
   void parse_node(const YAML::Node& node, 
-		  std::map<string,double*>& dMap, 
-		  std::map<string,int>& iMap, 
-		  std::map<string,string>& sMap, 
-		  std::map<string,vector<double> >& vMap,
-		  std::map<string,YAML::Node> & yMap )
+                  std::map<string,double*>& dMap, 
+                  std::map<string,int>& iMap, 
+                  std::map<string,string>& sMap, 
+                  std::map<string,vector<double> >& vMap,
+                  std::map<string,YAML::Node> & yMap )
   {
     for ( YAML::const_iterator it = node.begin(); it != node.end(); ++it) {
       YAML::Node key = it->first;
diff --git a/src/xfitter_steer.cc b/src/xfitter_steer.cc
index 2bb75cca4..a34da7f79 100644
--- a/src/xfitter_steer.cc
+++ b/src/xfitter_steer.cc
@@ -9,82 +9,63 @@
 #include <iostream>
 #include <yaml-cpp/yaml.h>
 #include <Profiler.h>
+using std::string;
 
 extern std::map<string,string> gReactionLibs;
 
 namespace xfitter {
 
-  BaseEvolution* get_evolution(std::string name) {
-    if (name == "") {
-      // get the name from the map
-      name = XFITTER_PARS::getParameterS("Evolution");
-    }
-    
+  BaseEvolution*get_evolution(string name){
+    if(name=="")name=XFITTER_PARS::getDefaultEvolutionName();
     // Check if already present
-    if (XFITTER_PARS::gEvolutions.count(name) == 1) {
-      return XFITTER_PARS::gEvolutions[name];  //already loaded
+    if(XFITTER_PARS::gEvolutions.count(name)==1){
+      return XFITTER_PARS::gEvolutions.at(name);
     }
-
-
-    // Load corresponding shared library:
-    string libname = gReactionLibs[name];
-    if ( libname == "") {
-      hf_errlog(18071302,"F: Shared library for evolution "+name+" not found");
+    // Else create a new instance of evolution
+    YAML::Node instanceNode=XFITTER_PARS::getEvolutionNode(name);
+    YAML::Node classnameNode=instanceNode["class"];
+    if(!classnameNode.IsScalar()){
+      std::ostringstream s;
+      s<<"F:Failed to get evolution \""<<name<<"\": evolution must have a node \"class\" with the class name as a string";
+      hf_errlog(18082902,s.str().c_str());
+    }
+    string classname=classnameNode.as<string>();
+    string libname;
+    {auto it=gReactionLibs.find(classname);
+    if(it==gReactionLibs.end()){
+      std::ostringstream s;
+      s<<"F: Failed to get evolution \""<<name<<"\": unknown evolution class name \""<<classname<<"\"";
+      hf_errlog(18082903,s.str().c_str());
+    }
+    libname=it->second;
     }
-
     // load the library:
-    void *evolution_handler = dlopen((PREFIX+string("/lib/")+libname).c_str(), RTLD_NOW);
-    if (evolution_handler == NULL)  { 
-      std::cout  << dlerror() << std::endl;      
+    //dlopen may be called multiple times for the same library and should return the same handle each time
+    void*shared_library=dlopen((PREFIX+string("/lib/")+libname).c_str(),RTLD_NOW);
+    //By the way, do we ever call dlclose? I don't think so... Maybe we should call it eventually. --Ivan Novikov
+    if(shared_library==NULL){ 
+      std::cout<<dlerror()<<std::endl;      
       hf_errlog(18071303,"F: Evolution shared library ./lib/"  + libname  +  " not present for evolution" + name + ". Check Reactions.txt file");
     }
-
-     // reset errors
+    // reset errors
     dlerror();
 
-    create_evolution *dispatch_ev = (create_evolution*) dlsym(evolution_handler, "create");   
-    BaseEvolution *evolution = dispatch_ev();
-
-    // Now we attach corresponding PDFdecomposition. First try specific, next: global
-    std::string pdfDecomp =  XFITTER_PARS::getParameterS("PDFDecomposition");
-
-    // XXXXXXXXXXXXXXXXXXXXXXXX
-    if ( XFITTER_PARS::gParametersY.count(name) > 0 ) {
-      auto evolNode = XFITTER_PARS::gParametersY[name];
-      if ( evolNode["PDFDecomposition"] ) {
-	pdfDecomp = evolNode["PDFDecomposition"].as<std::string>();
-	std::cout << " here here \n";
-      }
-      else {
-	std::cout << " ho here \n";	
-      }
-    }
+    BaseEvolution*evolution=((create_evolution*)dlsym(shared_library,"create"))(name.c_str());
 
-    std::cout << "PDF decomp=" << pdfDecomp << "\n";
+    //Note that unlike in the pervious version of this function, we do not set decompositions for evolutions
+    //Evolution objects are expected to get their decomposition themselves based on YAML parameters, during initFromYaml
 
-    // Get corresponding PDF decomposition:
-    BasePdfDecomposition* pdfD = get_pdfDecomposition(pdfDecomp);
-    evolution->SetPdfDecomposition( pdfD->f0() );
-
-    // Init it:
-    evolution->initAtStart();
-    
-    // Store on the map
+    evolution->initFromYaml(instanceNode);
+    // Store the newly created evolution on the global map
     XFITTER_PARS::gEvolutions[name] = evolution;
     return evolution;
   }
-
-  BasePdfDecomposition* get_pdfDecomposition(std::string name) {
-    if (name == "") {
-      // get the name from the map
-      name = XFITTER_PARS::getParameterS("PDFDecomposition");
-    }
-    // Check if already present
-    if (XFITTER_PARS::gPdfDecompositions.count(name) == 1) {
-      return  XFITTER_PARS::gPdfDecompositions[name];  //already loaded
-    }
-    
+  BasePdfDecomposition*get_pdfDecomposition(string name){
+    if(name=="")name=XFITTER_PARS::getDefaultDecompositionName();
+    auto it=XFITTER_PARS::gPdfDecompositions.find(name);
+    if(it!=XFITTER_PARS::gPdfDecompositions.end())return it->second;
     // Load corresponding shared library:
+    //Note: apparently we store all shared lib names in the map gReactionLibs, whether the libs are for reaction or whatever else. This naming is misleading.
     string libname = gReactionLibs[name];
     if ( libname == "") {
       hf_errlog(18072302,"F: Shared library for pdf decomposition "+name+" not found");
@@ -157,7 +138,8 @@ extern "C" {
 }
 
 void init_evolution_() {
-  auto evol = xfitter::get_evolution();
+  //TODO: reimplement for new interface with multiple evolutions
+  //auto evol = xfitter::get_evolution();
 }
 
 void init_minimizer_() {
diff --git a/steering.txt b/steering.txt
index 00cd38e83..69cf2374f 100644
--- a/steering.txt
+++ b/steering.txt
@@ -216,10 +216,10 @@
   OUTXRANGE = 1E-4, 0.9999
 
   ! Do not write out LHAPDF6 output
-  ! WriteLHAPDF6 = false
+   WriteLHAPDF6 = false
 
   ! Write out LHAPDF5 output
-  ! WriteLHAPDF5 = false
+   WriteLHAPDF5 = false
 &End
 
 
-- 
GitLab


From 0604742213cfbf9c9b94708a9eab365bee541428 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Mon, 3 Sep 2018 17:06:49 +0200
Subject: [PATCH 16/26] Revert unnecessary changes

---
 .gitignore                                    | 18 +---
 configure.ac                                  |  2 +-
 .../PolySqrtPdfParam/src/PolySqrtPdfParam.cc  | 34 ++++----
 src/main.f                                    |  2 +-
 steering.txt                                  | 87 +++++++++++--------
 5 files changed, 69 insertions(+), 74 deletions(-)

diff --git a/.gitignore b/.gitignore
index 3f1542069..3ee433a61 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,6 +21,7 @@ aclocal.m4
 autom4te.cache/
 *.m4
 config.guess
+config.log
 config.status
 config.sub
 configure
@@ -32,23 +33,6 @@ libtool
 ltmain.sh
 unpolarised.wgt
 zmstf.wgt
-SACOT/src/mdispac.mod
-doc/html/
-WHATIDID
-bak/
-constants.yaml
-datafiles/E615/
-deps/
-myconfigure.sh
-output*
-setup.sh
-tmp.sh
-version
-xfitter-master/
-yaml/
-plots/
-outs/
-*.log
 
 # vim swap file
 *.swp
diff --git a/configure.ac b/configure.ac
index ae1ef735c..00f7f37ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -293,7 +293,7 @@ if test $enable_ceres; then
     AC_MSG_ERROR([Unable to find CERES_DIR])
   else
     CERES_CPPFLAGS="-I${CERES_DIR}/include/  -I/usr/include/eigen3"
-    CERES_LDFLAGS="-L${CERES_DIR}/lib -lceres -lpthread -llapack -lblas -lrt -lgomp"
+    CERES_LDFLAGS="-L${CERES_DIR}/lib  -lceres -lglog -lgflags -lpthread -lspqr -lcholmod -lccolamd -lcamd -lcolamd -lamd -llapack -lblas -lsuitesparseconfig -lrt -lcxsparse -lrt -lcxsparse -lgomp"
     AC_SUBST(CERES_CPPFLAGS)
     AC_SUBST(CERES_LDFLAGS)
     AC_DEFINE([CERES_ENABLED],[1],[Define if APFEL++ is enabled])    
diff --git a/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc b/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc
index b4c69985d..6799ed524 100644
--- a/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc
+++ b/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc
@@ -11,15 +11,15 @@
 using namespace std;
 using uint=unsigned int;
 double PolySqrtPdfParam::operator()(double x)const{
-	const uint N=getNPar();
-	double pol=1;
-	double mulx=1;
-	double sqrtx=sqrt(x);
-	for(uint i=3;i<N;++i){
-		mulx*=sqrtx;
-		pol+=(*pars[i])*mulx;
-	}
-	return(*pars[0])*pow(x,(*pars[1]))*pow((1-x),(*pars[2]))*pol;
+  const uint N=getNPar();
+  double pol=1;
+  double mulx=1;
+  double sqrtx=sqrt(x);
+  for(uint i=3;i<N;++i){
+    mulx*=sqrtx;
+    pol+=(*pars[i])*mulx;
+  }
+  return(*pars[0])*pow(x,(*pars[1]))*pow((1-x),(*pars[2]))*pol;
 }
 double PolySqrtPdfParam::moment(int n)const{
   //Integral of PolySqrtPdfParam-style function is expressed in terms of Euler beta function:
@@ -48,19 +48,19 @@ double PolySqrtPdfParam::moment(int n)const{
     a++;
     b++;
   }
-	double lgammaC=lgamma(C);
-	double ret=exp(lgamma(B)+lgammaC-lgamma(B+C))*sum;
-	sum=0;
-	prod=1;
-	a=B+0.5;
-	b=a+C;
+  double lgammaC=lgamma(C);
+  double ret=exp(lgamma(B)+lgammaC-lgamma(B+C))*sum;
+  sum=0;
+  prod=1;
+  a=B+0.5;
+  b=a+C;
   for(uint i=3;i<N;i+=2){
     sum+=(*pars[i])*prod;
     prod=prod*a/b;
     a++;
     b++;
   }
-	ret+=exp(lgamma(B+0.5)+lgammaC-lgamma(B+C+0.5))*sum;
-	ret*=(*pars[0]);
+  ret+=exp(lgamma(B+0.5)+lgammaC-lgamma(B+C+0.5))*sum;
+  ret*=(*pars[0]);
   return ret;
 }
diff --git a/src/main.f b/src/main.f
index f47716856..426d32d65 100644
--- a/src/main.f
+++ b/src/main.f
@@ -32,7 +32,7 @@ C-----------------------------------------------------
 *     ------------------------------------------------
 *     Print HFitter banner
 *     ------------------------------------------------
-*     call hfbanner
+      call hfbanner
 
       narg = command_argument_count()
       if (narg.gt.0) then
diff --git a/steering.txt b/steering.txt
index 69cf2374f..580cc1d21 100644
--- a/steering.txt
+++ b/steering.txt
@@ -1,48 +1,61 @@
+*  Namelist to control input data
+*
+
 &InFiles
   ! Number of intput files
-    NInputFiles = 15
+    NInputFiles = 7
+ 
   ! Input files:
-    InputFileNames = 
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-0.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-1.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-2.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-3.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-4.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-5.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-6.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-7.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-8.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-9.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-13.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-14.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-15.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-16.dat',
-			'/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-17.dat',
-!		  '/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-10.dat',
-!		  '/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-11.dat',
-!		  '/afs/desy.de/user/n/novikovi/xfitter/datafiles/E615/thexp-12.dat',
+
+     InputFileNames = 
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_920-thexp.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_820-thexp.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_575-thexp.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_460-thexp.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCem-thexp.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_CCep-thexp.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_CCem-thexp.dat',
+
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_920.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_820.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_575.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCep_460.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_NCem.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_CCep.dat',
+     'datafiles/hera/h1zeusCombined/inclusiveDis/1506.06042/HERA1+2_CCem.dat',
+    ! 'Z0_applgrid_nnlo_reaction.dat', 'D0_Wel_pt25_asymmetry.dat'
+    ! 'datafiles/lhc/atlas/wzProduction/1203.4051/Z0_applgrid_nnlo.dat',
+
 &End
 
 &InCorr
+  ! Number of correlation (statistical, systematical or full) files
     NCorrFiles = 0
+ 
+  ! Correlation files:
+  !  CorrFileNames(1) = 'datafiles/hera/h1/jets/0904.3870/H1_NormInclJets_HighQ2_99-07___H1_NormInclJets_HighQ2_99-07.corr'
 &End
 
 &ReduceSyst
+    ! even with tolerance =0 the following flag may speed up calculations
   do_reduce = .false.  ! turn-on to simplify/speedup chi2 calculation.
+    ! tolerance = 0.0 for exact calculation, > 0.0 for improved speed.
   tolerance = 0.0
+    ! depending on blas library, toggling the following flag may improve chi2 computation speed:
   useBlas = .false.
 &End
 
-&sumrule_sums
-  uvalSum=-1.
-  dvalSum=1.
-  !svalSum=0.!not implemented
-&end
-
 &CovarToNuisance
+   ! Global switch for using nuisance param representation for covariance mat.
   LConvertCovToNui = .False.
+
+   ! Tolerance -- zero means exact transformation
   Tolerance = 0.0
+
+   ! (Optional) -- try to subtract diagonal stat. uncertainties from total covariance when determining uncorrelated uncertainites
   LSubtractStat = .false.
+
+   ! The following lines allow to adjust error scaling properties (default: :M)
   DataName     = 'CMS electon Asymmetry rapidity', 'CMS W muon asymmetry'
   DataSystType = ':A', ':A'
 &End
@@ -105,9 +118,9 @@
                                 !uPDF4 fit calculating kernel on fly, grid of sigma_hat
 
 
-  Order  = 'LO'       ! 'LO', 'NLO' or 'NNLO', used for DGLAP evolution.
+  Order  = 'NNLO'       ! 'LO', 'NLO' or 'NNLO', used for DGLAP evolution.
 
-  Q02     = 0.4 ! Evolution starting scale
+  Q02     = 1.9 ! Evolution starting scale
 
  ! --- Scheme for heavy flavors 
  ! ---  HF_SCHEME = 'ZMVFNS'           : ZM-VFNS (massless) from QCDNUM,
@@ -158,7 +171,7 @@
  !  'DDIS'        -- use Diffractive DIS 
  !  'BiLog'       -- bi-lognormal parametrisation 
 
-  PDFStyle='HERAPDF'
+  PDFStyle = 'HERAPDF'
 
  ! XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  !
@@ -180,10 +193,8 @@
  !  'ExtraSystRescale'      : additional re-scaling of stat. uncertainty to account for syst. shifts.
 
    CHI2SettingsName = 'StatScale', 'UncorSysScale', 'CorSysScale', 'UncorChi2Type', 'CorChi2Type'
- !  Chi2Settings     = 'Poisson' , 'Linear',  'Linear'  , 'Diagonal' , 'Hessian'
-    Chi2Settings     = 'Poisson' , 'Poisson',  'Linear'  , 'Diagonal' , 'Hessian'
- !  Chi2Settings     = 'NoRescale'  , 'NoRescale',        'NoRescale'     , 'Diagonal'     , 'Hessian'
-    Chi2ExtraParam = 'PoissonCorr'
+   Chi2Settings     = 'Poisson'  , 'Linear',        'Linear'     , 'Diagonal'     , 'Hessian'
+   Chi2ExtraParam = 'PoissonCorr'
 
  ! Flag to define if native APPLgrid CKM values should be kept.
  LUseAPPLgridCKM = True
@@ -206,7 +217,7 @@
   DoBandsSym = False     ! symmetric bands ( HESSE )
 
   ! -- Q2 values at which the pdfs & errors are done (up to 20)
-  Q2VAL = 1.9, 3.0, 4.0, 5., 10.
+  Q2VAL = 1.9, 3.0, 4.0, 5., 10., 100., 6464, 8317 
 !  Q2VAL = 1.9, 4., 10., 100., 6464, 8317 
 
   ! How many x points to write (standard = 101)
@@ -216,10 +227,10 @@
   OUTXRANGE = 1E-4, 0.9999
 
   ! Do not write out LHAPDF6 output
-   WriteLHAPDF6 = false
+  ! WriteLHAPDF6 = false
 
   ! Write out LHAPDF5 output
-   WriteLHAPDF5 = false
+  ! WriteLHAPDF5 = false
 &End
 
 
@@ -368,10 +379,10 @@
 &End
 
 *
-* (Optional) LHAPDF steering card
+* (Optional) LHAPDF sttering card
 *
 &lhapdf
-  LHAPDFSET='GRVPI0'                  ! LHAPDF grid file 
+  LHAPDFSET  = 'CT10nlo'               ! LHAPDF grid file 
   ILHAPDFSET = 0                       ! Set a PDF member of the PDF set (use together with LHAPDFPROFILE = False)
   ! LHAPDFVARSET = 'HERAPDF20_NLO_VAR' ! Add a PDF set with model and parametrisation uncertainties
   ! NPARVAR = 3                        ! Number of parametrisation uncertainties in the LHAPDFVARSET set
-- 
GitLab


From d3f6889f9b62ab0a34268719ecf7604a5d4f3802 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Mon, 3 Sep 2018 17:21:04 +0200
Subject: [PATCH 17/26] Fix .gitignore

---
 .gitignore | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.gitignore b/.gitignore
index 3ee433a61..bac320883 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,6 +33,9 @@ libtool
 ltmain.sh
 unpolarised.wgt
 zmstf.wgt
+SACOT/src/mdispac.mod
+doc/html/
+
 
 # vim swap file
 *.swp
-- 
GitLab


From 65d3678c8e165aad75ec793753af55c0b97ff68f Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Mon, 3 Sep 2018 17:23:34 +0200
Subject: [PATCH 18/26] Fix .gitignore, for real this time

---
 .gitignore | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index bac320883..f71e36d0e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,6 +36,5 @@ zmstf.wgt
 SACOT/src/mdispac.mod
 doc/html/
 
-
 # vim swap file
 *.swp
-- 
GitLab


From 9442e9769fdbb6bca9af02ea8c0c8a3a77d221e2 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Mon, 3 Sep 2018 18:43:09 +0200
Subject: [PATCH 19/26] Three different initializations methods for evolutions

---
 evolutions/APFELxx/include/EvolutionAPFELxx.h |  9 ++-----
 evolutions/APFELxx/src/EvolutionAPFELxx.cc    | 27 +++++++++----------
 .../BaseEvolution/include/BaseEvolution.h     | 16 +++++++----
 evolutions/LHAPDF/include/EvolutionLHAPDF.h   |  8 +++---
 evolutions/LHAPDF/src/EvolutionLHAPDF.cc      | 24 ++++++++++-------
 evolutions/QCDNUM/include/EvolutionQCDNUM.h   |  5 ++--
 evolutions/QCDNUM/src/EvolutionQCDNUM.cc      | 17 ++++++------
 src/xfitter_steer.cc                          |  4 +--
 8 files changed, 58 insertions(+), 52 deletions(-)

diff --git a/evolutions/APFELxx/include/EvolutionAPFELxx.h b/evolutions/APFELxx/include/EvolutionAPFELxx.h
index 99f8ee2aa..0a63a1184 100644
--- a/evolutions/APFELxx/include/EvolutionAPFELxx.h
+++ b/evolutions/APFELxx/include/EvolutionAPFELxx.h
@@ -29,13 +29,8 @@ namespace xfitter
     /**
      * @brief Function that initialises the evolution in APFEL++.
      */
-    void initFromYaml(const YAML::Node);
-
-    /**
-     * @brief Function that updates the relevant parameters of the
-     * evolution at each iteration of the fitting procedure.
-     */
-    void initAtIteration();
+    void initAtStart();
+    void initAtParameterChange();
 
     /**
      * @name Getters
diff --git a/evolutions/APFELxx/src/EvolutionAPFELxx.cc b/evolutions/APFELxx/src/EvolutionAPFELxx.cc
index 72f8f5885..4e33493c7 100644
--- a/evolutions/APFELxx/src/EvolutionAPFELxx.cc
+++ b/evolutions/APFELxx/src/EvolutionAPFELxx.cc
@@ -16,12 +16,13 @@ namespace xfitter
 
 
   //_________________________________________________________________________________
-  void EvolutionAPFELxx::initFromYaml(const YAML::Node yamlNode)
+  void EvolutionAPFELxx::initAtStart()
   {
     // APFEL++ banner
     apfel::Banner();
 
-		_inPDFs=XFITTER_PARS::getInputFunctionFromYaml(yamlNode);
+    const YAML::Node yamlNode=XFITTER_PARS::getEvolutionNode(_name);
+    _inPDFs=XFITTER_PARS::getInputFunctionFromYaml(yamlNode);
     // Retrieve parameters needed to initialize APFEL++.
     const double* MCharm   = XFITTER_PARS::gParameters.at("mch");
     const double* MBottom  = XFITTER_PARS::gParameters.at("mbt");
@@ -42,21 +43,19 @@ namespace xfitter
 
     // Initialize QCD evolution objects
     _DglapObj = apfel::InitializeDglapObjectsQCD(*_Grid, _Masses, _Thresholds);
+    initAtParameterChange();
   }
 
   //_________________________________________________________________________________
-  void EvolutionAPFELxx::initAtIteration()
+  void EvolutionAPFELxx::initAtParameterChange()
   {
+    const YAML::Node yamlNode=XFITTER_PARS::getEvolutionNode(_name);
     // Retrieve the relevant parameters needed to compute the evolutions
     const int     PtOrder    = OrderMap(XFITTER_PARS::gParametersS.at("Order")) - 1;
     const double* Q0         = XFITTER_PARS::gParameters.at("Q0");
     const double* Q_ref      = XFITTER_PARS::gParameters.at("Mz");
     const double* Alphas_ref = XFITTER_PARS::gParameters.at("alphas");
-		//XXX HACKS XXX
-		//I do not understand how QGrid is supposed to change between iterations --Ivan
-		//This will not work with the new parameters.yaml syntax
-		//TODO
-    const YAML::Node QGrid   = XFITTER_PARS::gParametersY.at("APFELxx")["QGrid"];
+    const YAML::Node QGrid   = yamlNode["QGrid"];
 
     // Reinitialise and tabulate the running coupling at every
     // iteration. This is fast enough and allows for the reference
@@ -67,17 +66,17 @@ namespace xfitter
 
     // Construct the DGLAP objects
     const auto Dglap = BuildDglap(_DglapObj,
-				  [=] (double const& x, double const&)->std::map<int,double>{ return apfel::PhysToQCDEv(this->_inPDFs(x)); },
-				  *Q0, PtOrder, _AlphaQCD);
+                                  [=] (double const& x, double const&)->std::map<int,double>{ return apfel::PhysToQCDEv(this->_inPDFs(x)); },
+                                  *Q0, PtOrder, _AlphaQCD);
 
     // Tabulate PDFs (ideally the parameters of the tabulation should
     // be read from parameters.yaml).
     _TabulatedPDFs = std::unique_ptr<apfel::TabulateObject<apfel::Set<apfel::Distribution>>>
       (new apfel::TabulateObject<apfel::Set<apfel::Distribution>>{*Dglap,
-	  QGrid[0].as<int>(),
-	  QGrid[1].as<double>(),
-	  QGrid[2].as<double>(),
-	  QGrid[3].as<int>()});
+          QGrid[0].as<int>(),
+          QGrid[1].as<double>(),
+          QGrid[2].as<double>(),
+          QGrid[3].as<int>()});
   }
 
   //_________________________________________________________________________________
diff --git a/evolutions/BaseEvolution/include/BaseEvolution.h b/evolutions/BaseEvolution/include/BaseEvolution.h
index 29045e9cb..9477bf800 100644
--- a/evolutions/BaseEvolution/include/BaseEvolution.h
+++ b/evolutions/BaseEvolution/include/BaseEvolution.h
@@ -31,15 +31,21 @@ namespace xfitter
     
     /**
      * @brief Function to be called at the begining to initialise the
-     * evolution code.
+     * evolution code based on its YAML node
+     *
+     * This function is called only once
      */
-    virtual void initFromYaml(const YAML::Node) = 0;
+    virtual void initAtStart(){};
 
     /**
-     * @brief Function to be call at each iteration to update the
-     * relevant evolution parameters.
+     * @brief Function to be called at each iteration
      */
-    virtual void initAtIteration() = 0;
+    virtual void initAtIteration(){};
+
+    /**
+     * @brief This function should be called when at least one parameter in the YAML node of given evolution changes
+     */
+    virtual void initAtParameterChange(){};
 
     /**
      * @name Getters
diff --git a/evolutions/LHAPDF/include/EvolutionLHAPDF.h b/evolutions/LHAPDF/include/EvolutionLHAPDF.h
index c13b73d77..0f0e0aa55 100644
--- a/evolutions/LHAPDF/include/EvolutionLHAPDF.h
+++ b/evolutions/LHAPDF/include/EvolutionLHAPDF.h
@@ -25,13 +25,13 @@ class EvolutionLHAPDF : BaseEvolution
 {
   public:
     /// Empty constructor (needed for the dynamic loading)
-    EvolutionLHAPDF(const char*name):BaseEvolution(name){};
+    EvolutionLHAPDF(const char*name);
 
   public:
   /// Global initialization
-    virtual void initFromYaml(const YAML::Node) override final;
-  /// Init at each iteration
-    virtual void initAtIteration() override final;  
+    virtual void initAtStart() override final;
+  /// Init at each change of at least one parameter
+    virtual void initAtParameterChange() override final;  
 
   /// Return PDFs as a map <int,double> where int is PDF ID (-6, ... 6, 21)   
     virtual std::function<std::map<int,double>(double const& x, double const& Q)> xfxQMap() override final;
diff --git a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
index e9300b687..5762f9578 100644
--- a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
+++ b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
@@ -18,10 +18,14 @@ namespace xfitter
 extern "C" EvolutionLHAPDF*create(const char*name){
   return new EvolutionLHAPDF(name);
 }
+EvolutionLHAPDF::EvolutionLHAPDF(const char*name):BaseEvolution(name){
+  _pdf=nullptr;
+}
 
     
 /// Global initialization
-  void EvolutionLHAPDF::initFromYaml(const YAML::Node pars) {
+  void EvolutionLHAPDF::initAtStart() {
+    YAML::Node pars=XFITTER_PARS::getEvolutionNode(_name);
     try{
       _set_name = pars["set"].as<std::string>();
     }catch(YAML::TypedBadConversion<std::string>&ex){
@@ -32,20 +36,20 @@ extern "C" EvolutionLHAPDF*create(const char*name){
     // check if exists first
     CheckForPDF(_set_name.c_str());
     _member   = pars["member"].as<int>();
-    _pdf      = LHAPDF::mkPDF(_set_name,_member);//Doesn't one need to delete _pdf then later? --Ivan
+    if(_pdf)delete _pdf;
+    _pdf      = LHAPDF::mkPDF(_set_name,_member);
     return ;
  };
     
   /// Init at each iteration
-  void EvolutionLHAPDF::initAtIteration() {
-
-    // Initialize LHAPDF XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-    //auto pars = XFITTER_PARS::gParametersY["LHAPDF"];
-
-    //_set_name = pars["set"].as<std::string>();
-    //_member   = pars["member"].as<int>();
+  void EvolutionLHAPDF::initAtParameterChange() {
+    YAML::Node pars=XFITTER_PARS::getEvolutionNode(_name);
+    //TODO: check for errors while parsing YAML
+    _set_name = pars["set"].as<std::string>();
+    _member   = pars["member"].as<int>();
 
-    //_pdf      = LHAPDF::mkPDF(_set_name,_member);//Doesn't one need to delete _pdf then later? --Ivan
+    if(_pdf)delete _pdf;
+    _pdf=LHAPDF::mkPDF(_set_name,_member);
 
     return ;
   };
diff --git a/evolutions/QCDNUM/include/EvolutionQCDNUM.h b/evolutions/QCDNUM/include/EvolutionQCDNUM.h
index 669dcfb63..3013d9141 100644
--- a/evolutions/QCDNUM/include/EvolutionQCDNUM.h
+++ b/evolutions/QCDNUM/include/EvolutionQCDNUM.h
@@ -25,8 +25,9 @@ namespace xfitter
   public:
     EvolutionQCDNUM(const char*name):BaseEvolution{name}{};
 
-    virtual void initFromYaml(const YAML::Node) override final;
-    virtual void initAtIteration() override final;
+    virtual void initAtStart()override final;
+    virtual void initAtIteration()override final;
+    virtual void initAtParameterChange()override final;
     virtual std::function<std::map<int,double>(double const& x, double const& Q)> xfxQMap()  override final;
     virtual std::function<void(double const& x, double const& Q, double* pdfs)> xfxQArray() override final;
     virtual std::function<double(int const& i, double const& x, double const& Q)> xfxQDouble() override final;
diff --git a/evolutions/QCDNUM/src/EvolutionQCDNUM.cc b/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
index 091649815..3ac138cce 100644
--- a/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
+++ b/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
@@ -63,7 +63,7 @@ namespace xfitter
   }
 
   // Initialize at the start of the computation
-  void EvolutionQCDNUM::initFromYaml(const YAML::Node yQCDNUM)
+  void EvolutionQCDNUM::initAtStart()
   {
     QCDNUM::qcinit(6," ");
 
@@ -101,6 +101,7 @@ namespace xfitter
 
     //  const double* mtp     = XFITTER_PARS::gParameters.at("mtp");   // no top PDF treatment yet XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     
+    YAML::Node yQCDNUM=XFITTER_PARS::getEvolutionNode(_name);
     _icheck      = yQCDNUM["ICheck"].as<int>();
     _splineOrder = yQCDNUM["SplineOrder"].as<int>();
     _readTables  = yQCDNUM["Read_QCDNUM_Tables"].as<int>();
@@ -178,22 +179,22 @@ namespace xfitter
        
 		//Evolution gets its decomposition from YAML
     gPdfDecomp=XFITTER_PARS::getInputFunctionFromYaml(yQCDNUM);
+    initAtParameterChange();
   }
 
-  // Initialize at 
-  void EvolutionQCDNUM::initAtIteration()
+  void EvolutionQCDNUM::initAtParameterChange()
   {
-		//TODO: reload decompositions?? --Ivan
     // XXXXXXXXXXXXXX
-    const double* q0 = XFITTER_PARS::gParameters.at("Q0");
-    int iq0  = QCDNUM::iqfrmq( (*q0) * (*q0) );
 
     const double* Mz      = XFITTER_PARS::gParameters.at("Mz");
     const double* alphas  = XFITTER_PARS::gParameters.at("alphas");
     
-    double epsi = 0;
-
     QCDNUM::setalf(*alphas,(*Mz)*(*Mz));
+  }
+  void EvolutionQCDNUM::initAtIteration(){
+    const double* q0 = XFITTER_PARS::gParameters.at("Q0");
+    int iq0  = QCDNUM::iqfrmq( (*q0) * (*q0) );
+    double epsi = 0;
     QCDNUM::evolfg(_itype,funcPDF,qcdnumDef,iq0,epsi);
   }
 
diff --git a/src/xfitter_steer.cc b/src/xfitter_steer.cc
index a34da7f79..b0885a2a1 100644
--- a/src/xfitter_steer.cc
+++ b/src/xfitter_steer.cc
@@ -53,9 +53,9 @@ namespace xfitter {
     BaseEvolution*evolution=((create_evolution*)dlsym(shared_library,"create"))(name.c_str());
 
     //Note that unlike in the pervious version of this function, we do not set decompositions for evolutions
-    //Evolution objects are expected to get their decomposition themselves based on YAML parameters, during initFromYaml
+    //Evolution objects are expected to get their decomposition themselves based on YAML parameters, during initAtStart
 
-    evolution->initFromYaml(instanceNode);
+    evolution->initAtStart();
     // Store the newly created evolution on the global map
     XFITTER_PARS::gEvolutions[name] = evolution;
     return evolution;
-- 
GitLab


From 17d86c53694ecdef469335e3f940a740517e5694 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Tue, 4 Sep 2018 13:59:43 +0200
Subject: [PATCH 20/26] Allow each dataset to specify its own pair of
 evolutions for reaction APPLgrid

---
 reactions/APPLgrid/include/ReactionAPPLgrid.h |  34 ++---
 reactions/APPLgrid/src/ReactionAPPLgrid.cc    | 141 +++++++++---------
 2 files changed, 88 insertions(+), 87 deletions(-)

diff --git a/reactions/APPLgrid/include/ReactionAPPLgrid.h b/reactions/APPLgrid/include/ReactionAPPLgrid.h
index 608e814f7..6645d3aeb 100644
--- a/reactions/APPLgrid/include/ReactionAPPLgrid.h
+++ b/reactions/APPLgrid/include/ReactionAPPLgrid.h
@@ -16,34 +16,28 @@
   @version 0.1
   @date 2017-03-28
   */
-
+struct DatasetData{
+  std::vector<std::shared_ptr<appl::grid> >grids;
+  int order;
+  double muR,muF; // !> renormalisation and factorisation scales
+  bool flagNorm; // !> if true, multiply by bin width
+  bool flagUseReference; // !> if true, prediction will be calculated from reference histogram (for tests and grids validation)
+  std::vector<TH1D*>  references;
+  std::vector<double> eScale; // !> CMS energy
+  xfitter::BaseEvolution*evolutions[2];
+};
 class ReactionAPPLgrid : public ReactionTheory
 {
   public:
     ReactionAPPLgrid();
     ~ReactionAPPLgrid();
-//    ~ReactionAPPLgrid(const ReactionAPPLgrid &){};
-//    ReactionAPPLgrid & operator =(const ReactionAAPPLgrid &r){return *(new ReactionAPPLgrid(r));};
-
- public:
     virtual string getReactionName() const { return  "APPLgrid" ;};
     int initAtStart(const string &); 
     virtual void setDatasetParameters( int dataSetID, map<string,string> pars, map<string,double> parsDataset) override ;
     virtual int compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err);
- protected:
-    virtual int parseOptions(){ return 0;};    
-
- private:
-    enum class collision {pp,ppbar,pn,LHAPDF};//TODO: deprecated, remove this
-    //TODO: make this into a data structure
-    map<int, collision> _collType;//TODO:deprecated
-    map<int, std::vector<std::shared_ptr<appl::grid> > > _grids;
-    map<int, int> _order;
-    map<int, double> _muR, _muF; // !> renormalisation and factorisation scales
-    map<int, bool> _flagNorm; // !> if true, multiply by bin width
-    map<int, bool> _flagUseReference; // !> if true, prediction will be calculated from reference histogram (for tests and grids validation)
-    map<int, std::vector<TH1D*> > _references;
-    map<int, std::vector<double> > _eScale; // !> CMS energy
-    xfitter::BaseEvolution*evolutions[2];//TODO these per dataset
+  protected:
+    virtual int parseOptions(){ return 0;};
+  private:
+    map<int,DatasetData>dataset_data;
 };
 
diff --git a/reactions/APPLgrid/src/ReactionAPPLgrid.cc b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
index 3b3fd4e90..55ed4cefd 100644
--- a/reactions/APPLgrid/src/ReactionAPPLgrid.cc
+++ b/reactions/APPLgrid/src/ReactionAPPLgrid.cc
@@ -18,17 +18,14 @@ extern "C" ReactionAPPLgrid* create() {
 function<void(double const&x,double const&Q,double*pdfs)>active_xfxQ_functions[2];
 void xfxWrapper0(const double&x,const double&Q,double*results){active_xfxQ_functions[0](x,Q,results);}
 void xfxWrapper1(const double&x,const double&Q,double*results){active_xfxQ_functions[1](x,Q,results);}
-ReactionAPPLgrid::ReactionAPPLgrid(){
-  evolutions[0]=nullptr;
-  evolutions[1]=nullptr;
-}
+ReactionAPPLgrid::ReactionAPPLgrid(){}
 ReactionAPPLgrid::~ReactionAPPLgrid(){}
  // Initialize at the start of the computation
 int ReactionAPPLgrid::initAtStart(const string &s){return 0;}
 
  // Initialize for a given dataset:
 void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pars, map<string, double> parsDataset) {
-  //<DEBUG
+  /*DEBUG
   cerr<<"[DEBUG]ReactionAPPLgrid::setDatasetParameters(dataSetID="<<dataSetID<<",pars,parsDataset):\n"
       <<"pars={\n";
   for(map<string,string>::const_iterator it=pars.begin();it!=pars.end();++it){
@@ -40,69 +37,68 @@ void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pa
     cerr<<"  \""<<it->first<<"\":"<<it->second<<'\n';
   }
   cerr<<"}"<<endl;
-  //DEBUG>
-	map<string,string>::iterator it;
-	// Get grid name:
+  DEBUG*/
+  DatasetData&data=dataset_data[dataSetID];
+  vector<TH1D*>&references=data.references;
+  BaseEvolution*(&evolutions)[2]=data.evolutions;
+  map<string,string>::iterator it;
+  // Get grid name:
   it=pars.find("GridName");
   if(it!=pars.end()){
     try{
       std::istringstream ss(it->second);
-       //std::cout << pars["GridName"] << '\n';
-       std::string token;
-       while(std::getline(ss, token, ','))
-       {
-         //std::cout << token << '\n';
-         std::shared_ptr<appl::grid>  g(new appl::grid(token));
-         g->trim();
-         _grids[dataSetID].push_back(g);
-         TFile file(token.c_str());
-         _references[dataSetID].push_back((TH1D*)file.Get("grid/reference"));
-         if(!_references[dataSetID].back())
-           hf_errlog(17033000, "W: no reference histogram grid/reference in " + token);
-         else
-           _references[dataSetID].back()->SetDirectory(0);
-       }
-     }
-     catch ( const std::exception& e ) {
-        std::string text = "F:Failed to read APPLgrid file(s) "+pars["GridName"];
-        hf_errlog_(17032802,text.c_str(),text.size());
-     }
-   }
-   else {
-     std::string text = "F:GridName must be specified for the Reaction APPLgrid";
-     hf_errlog_(17032801,text.c_str(),text.size());
-   }
+      std::string token;
+      while(std::getline(ss, token, ',')){
+        std::shared_ptr<appl::grid> g(new appl::grid(token));
+        g->trim();
+        data.grids.push_back(g);
+        TFile file(token.c_str());
+        references.push_back((TH1D*)file.Get("grid/reference"));
+        if(!references.back())
+          hf_errlog(17033000, "W: no reference histogram grid/reference in " + token);
+        else
+          references.back()->SetDirectory(0);
+      }
+    }
+    catch ( const std::exception& e ) {
+      std::string text = "F:Failed to read APPLgrid file(s) "+pars["GridName"];
+      hf_errlog_(17032802,text.c_str(),text.size());
+    }
+  }
+  else {
+    std::string text = "F:GridName must be specified for the Reaction APPLgrid";
+    hf_errlog_(17032801,text.c_str(),text.size());
+  }
 // Get pointers to evolutions
   for(int i=0;i<2;++i){
     string evolutionName="";
     it=pars.find("evolution"+to_string(i+1));
     if(it!=pars.end())evolutionName=it->second;//else default evolution name will be used
-    cerr<<"[DEBUG]APPLgrid: use evolution \""<<evolutionName<<'\"'<<endl;
+    //cerr<<"[DEBUG]APPLgrid: use evolution \""<<evolutionName<<'\"'<<endl;
     evolutions[i]=get_evolution(evolutionName);
   }
 // Determine order
-   int order = OrderMap( GetParamS("Order"));  // Global order
-   if (pars.find("Order") != pars.end() ) { // Local order
-       int localOrder = OrderMap( pars["Order"] );
-       order = localOrder>order ? order : localOrder;
-   }
-
-   _order[dataSetID] = order;
+  int order = OrderMap( GetParamS("Order"));  // Global order
+  if (pars.find("Order") != pars.end() ) { // Local order
+      int localOrder = OrderMap( pars["Order"] );
+      order = localOrder>order ? order : localOrder;
+  }
+  data.order=order;
 // Determine MuR and MuF.  Use default 
-  _muR[dataSetID] =  pars.find("muR") == pars.end() ? GetParam("muR") : stod(pars["muR"]);
-  _muF[dataSetID] =  pars.find("muF") == pars.end() ? GetParam("muF") : stod(pars["muF"]);
+  data.muR=pars.find("muR") == pars.end() ? GetParam("muR") : stod(pars["muR"]);
+  data.muF=pars.find("muF") == pars.end() ? GetParam("muF") : stod(pars["muF"]);
 
-  if (_muR[dataSetID] == 0) _muR[dataSetID] = 1.0; 
-  if (_muF[dataSetID] == 0) _muF[dataSetID] = 1.0;
+  if(data.muR==0)data.muR=1.0; 
+  if(data.muF==0)data.muF=1.0;
   // bin width normalisation (by default no rescaling)
-  _flagNorm[dataSetID] = false;
+  data.flagNorm=false;
   it = pars.find("norm");
   if (it != pars.end() )
   {
     if(stoi(it->second) == 0)
-      _flagNorm[dataSetID] = false;
+      data.flagNorm=false;
     else if(stoi(it->second) == 1)
-      _flagNorm[dataSetID] = true;
+      data.flagNorm=true;
     else
       hf_errlog(17102102, "F: unrecognised norm = " + it->second);
   }
@@ -111,13 +107,14 @@ void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pa
   if (it != pars.end() )
   {
     if(stoi(it->second) == 0)
-      _flagUseReference[dataSetID] = false;
+      data.flagUseReference=false;
     else if(stoi(it->second) == 1)
     {
-      _flagUseReference[dataSetID] = true;
+      data.flagUseReference=true;
       // check that reference histogram is available
-      for(std::size_t i=0; i<_references[dataSetID].size(); i++)
-        if(!_references[dataSetID][i])
+      size_t endi=data.references.size();
+      for(size_t i=0;i<endi;++i)
+        if(!data.references[i])
           hf_errlog(17033000, "W: no reference histogram is available");
     }
     else
@@ -125,23 +122,24 @@ void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pa
   }
   // CMS energy (by default the one used to create the grid is used)
   it = pars.find("energy");
-  for(unsigned int i = 0; i < _grids[dataSetID].size(); i++)
+  unsigned int endi=data.grids.size();
+  for(unsigned int i=0;i<endi;++i)
   {
     double eScale = 1.0;
     if (it != pars.end())
     {
-      if(_flagUseReference[dataSetID])
+      if(data.flagUseReference)
         hf_errlog(17110300, "W: can not apply energy scaling when using predictions from reference histogram");
       else
       {
-        double eStored = _grids[dataSetID][i]->getCMSScale();
+        double eStored=data.grids[i]->getCMSScale();
         if(eStored < 1e-3)
           hf_errlog(17110301, "W: can not apply energy scaling because stored getCMSScale = 0");
         else
-          eScale = _grids[dataSetID][i]->getCMSScale() / stof(it->second);
+          eScale = eStored/ stof(it->second);
       }
     }
-    _eScale[dataSetID].push_back(eScale);
+    data.eScale.push_back(eScale);
   }
 }
 
@@ -149,26 +147,35 @@ void ReactionAPPLgrid::setDatasetParameters(int dataSetID, map<string,string> pa
  // Main function to compute results at an iteration
 int ReactionAPPLgrid::compute(int dataSetID, valarray<double> &val, map<string, valarray<double> > &err) {
   // iterate over grids
+  DatasetData&data=dataset_data.at(dataSetID);
+  const int order=data.order;
+  const double muR=data.muR;
+  const double muF=data.muF;
+  BaseEvolution*(&evolutions)[2]=data.evolutions;
   unsigned int pos = 0;
-  for(unsigned int g = 0; g < _grids[dataSetID].size(); g++)
+  for(unsigned int g=0;g<data.grids.size();g++)
   {
-    auto grid = _grids[dataSetID][g];
+    auto grid=data.grids[g];
+    double eScale=data.eScale[g];
     std::vector<double> gridVals(grid->Nobs());
-    if(!_flagUseReference[dataSetID]){
+    if(!data.flagUseReference){
       //For some reason we do not take alphaS from evolutions?
       active_xfxQ_functions[0]=evolutions[0]->xfxQArray();
-      active_xfxQ_functions[1]=evolutions[1]->xfxQArray();
-      gridVals=grid->vconvolute(xfxWrapper0,xfxWrapper1,getAlphaS(),_order[dataSetID]-1,_muR[dataSetID],_muF[dataSetID],_eScale[dataSetID][g]);
-      //TODO: call specialized vconvolute when the two evolutions are the same
+      if(evolutions[0]==evolutions[1]){
+        gridVals=grid->vconvolute(xfxWrapper0,getAlphaS(),order-1,muR,muF,eScale);
+      }else{
+        active_xfxQ_functions[1]=evolutions[1]->xfxQArray();
+        gridVals=grid->vconvolute(xfxWrapper0,xfxWrapper1,getAlphaS(),order-1,muR,muF,eScale);
+      }
     }
     else
     {
       // use reference histogram
       for(std::size_t i=0; i<gridVals.size(); i++)
-        gridVals[i] = _references[dataSetID][g]->GetBinContent(i + 1);
+        gridVals[i]=data.references[g]->GetBinContent(i + 1);
     }
     // scale by bin width if requested
-    if(_flagNorm[dataSetID])
+    if(data.flagNorm)
       for (std::size_t i=0; i<gridVals.size(); i++)
         gridVals[i] *= grid->deltaobs(i);
 
@@ -177,9 +184,9 @@ int ReactionAPPLgrid::compute(int dataSetID, valarray<double> &val, map<string,
     std::copy_n(gridVals.begin(), gridVals.size(), &val[pos]);
     pos += grid->Nobs();
   }
-  if(val.size()!=pos){
+  if(val.size()!=pos){//TODO: number of data points actually doesn't have to match grid size in some cases, so this check should be replaced by something else
     std::ostringstream s;
-    s<<"F: Number of data points ("<<val.size()<<") in dataset (ID="<<dataSetID<<") does not match total grid size ("<<pos<<")";
+    s<<"F: ReactionAPPLgrid: Number of data points ("<<val.size()<<") in dataset (ID="<<dataSetID<<") does not match total grid size ("<<pos<<")";
     hf_errlog(18072311,s.str().c_str());
   }
   return 0;
-- 
GitLab


From 27591a1b31932527f5330904b0f04855c8754784 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Tue, 4 Sep 2018 14:05:23 +0200
Subject: [PATCH 21/26] Add missing parameters.yaml files

---
 pdfdecompositions/SU3_PionPdfDecomposition/yaml/parameters.yaml | 0
 pdfparams/PolySqrtPdfParam/yaml/parameters.yaml                 | 0
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 pdfdecompositions/SU3_PionPdfDecomposition/yaml/parameters.yaml
 create mode 100644 pdfparams/PolySqrtPdfParam/yaml/parameters.yaml

diff --git a/pdfdecompositions/SU3_PionPdfDecomposition/yaml/parameters.yaml b/pdfdecompositions/SU3_PionPdfDecomposition/yaml/parameters.yaml
new file mode 100644
index 000000000..e69de29bb
diff --git a/pdfparams/PolySqrtPdfParam/yaml/parameters.yaml b/pdfparams/PolySqrtPdfParam/yaml/parameters.yaml
new file mode 100644
index 000000000..e69de29bb
-- 
GitLab


From 4d15d475c2fb7109be87b9745b9a5e63a93ca20e Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Tue, 4 Sep 2018 15:26:08 +0200
Subject: [PATCH 22/26] Add getClassName() method to evolutions

---
 evolutions/APFELxx/include/EvolutionAPFELxx.h    | 5 +++--
 evolutions/APFELxx/src/EvolutionAPFELxx.cc       | 1 +
 evolutions/BaseEvolution/include/BaseEvolution.h | 2 ++
 evolutions/LHAPDF/include/EvolutionLHAPDF.h      | 1 +
 evolutions/LHAPDF/src/EvolutionLHAPDF.cc         | 1 +
 evolutions/QCDNUM/include/EvolutionQCDNUM.h      | 1 +
 evolutions/QCDNUM/src/EvolutionQCDNUM.cc         | 9 +++++----
 7 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/evolutions/APFELxx/include/EvolutionAPFELxx.h b/evolutions/APFELxx/include/EvolutionAPFELxx.h
index 0a63a1184..03a54fd12 100644
--- a/evolutions/APFELxx/include/EvolutionAPFELxx.h
+++ b/evolutions/APFELxx/include/EvolutionAPFELxx.h
@@ -25,12 +25,13 @@ namespace xfitter
   {
   public:
     EvolutionAPFELxx(const char*name):BaseEvolution{name}{}
+    virtual const char*getClassName()const final override;
 
     /**
      * @brief Function that initialises the evolution in APFEL++.
      */
-    void initAtStart();
-    void initAtParameterChange();
+    virtual void initAtStart()override final;
+    virtual void initAtParameterChange()override final;
 
     /**
      * @name Getters
diff --git a/evolutions/APFELxx/src/EvolutionAPFELxx.cc b/evolutions/APFELxx/src/EvolutionAPFELxx.cc
index 4e33493c7..25d120b7f 100644
--- a/evolutions/APFELxx/src/EvolutionAPFELxx.cc
+++ b/evolutions/APFELxx/src/EvolutionAPFELxx.cc
@@ -13,6 +13,7 @@ namespace xfitter
   extern "C" EvolutionAPFELxx*create(const char*name){
     return new EvolutionAPFELxx(name);
   }
+  const char*EvolutionAPFELxx::getClassName()const{return "APFELxx";}
 
 
   //_________________________________________________________________________________
diff --git a/evolutions/BaseEvolution/include/BaseEvolution.h b/evolutions/BaseEvolution/include/BaseEvolution.h
index 9477bf800..368976152 100644
--- a/evolutions/BaseEvolution/include/BaseEvolution.h
+++ b/evolutions/BaseEvolution/include/BaseEvolution.h
@@ -89,6 +89,8 @@ namespace xfitter
     /// Get generic property of the evolution
     virtual double  getPropertyD(std::string const& propertyName ) const { return 0.; }
     
+    /// Get class name, can be used to verify that the correct concrete class is being used
+    virtual const char*getClassName()const=0;
     ///@}
    
     
diff --git a/evolutions/LHAPDF/include/EvolutionLHAPDF.h b/evolutions/LHAPDF/include/EvolutionLHAPDF.h
index 0f0e0aa55..cd52acac5 100644
--- a/evolutions/LHAPDF/include/EvolutionLHAPDF.h
+++ b/evolutions/LHAPDF/include/EvolutionLHAPDF.h
@@ -26,6 +26,7 @@ class EvolutionLHAPDF : BaseEvolution
   public:
     /// Empty constructor (needed for the dynamic loading)
     EvolutionLHAPDF(const char*name);
+    virtual const char*getClassName()const override final;
 
   public:
   /// Global initialization
diff --git a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
index 5762f9578..4f6a4b0a2 100644
--- a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
+++ b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
@@ -21,6 +21,7 @@ extern "C" EvolutionLHAPDF*create(const char*name){
 EvolutionLHAPDF::EvolutionLHAPDF(const char*name):BaseEvolution(name){
   _pdf=nullptr;
 }
+const char*EvolutionLHAPDF::getClassName()const{return "LHAPDF";}
 
     
 /// Global initialization
diff --git a/evolutions/QCDNUM/include/EvolutionQCDNUM.h b/evolutions/QCDNUM/include/EvolutionQCDNUM.h
index 3013d9141..6d4d84479 100644
--- a/evolutions/QCDNUM/include/EvolutionQCDNUM.h
+++ b/evolutions/QCDNUM/include/EvolutionQCDNUM.h
@@ -25,6 +25,7 @@ namespace xfitter
   public:
     EvolutionQCDNUM(const char*name):BaseEvolution{name}{};
 
+    virtual const char*getClassName()const override final;
     virtual void initAtStart()override final;
     virtual void initAtIteration()override final;
     virtual void initAtParameterChange()override final;
diff --git a/evolutions/QCDNUM/src/EvolutionQCDNUM.cc b/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
index 3ac138cce..21ea5693b 100644
--- a/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
+++ b/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
@@ -24,10 +24,10 @@ double funcPDF(int *ipdf, double *x) {
 // helper to parse yaml sequences of uniform type
 template <class T>
 vector<T> getSeq(const YAML::Node node) {
-	if(!node.IsSequence()){
-		std::cerr<<"[DEBUG]getSeq: node=\n"<<node<<std::endl;
+  if(!node.IsSequence()){
+    std::cerr<<"[ERROR]getSeq: node=\n"<<node<<std::endl;
     hf_errlog(180829150,"F: In QCDNUM in function getSeq: wrong node type, expected sequence");
-	}
+  }
   size_t len = node.size();
   vector<T> v(len);
   for (size_t i=0; i<len; i++) {
@@ -61,6 +61,7 @@ namespace xfitter
   extern "C" EvolutionQCDNUM* create(const char*name) {
     return new EvolutionQCDNUM(name);
   }
+  const char*EvolutionQCDNUM::getClassName()const{return "QCDNUM";}
 
   // Initialize at the start of the computation
   void EvolutionQCDNUM::initAtStart()
@@ -177,7 +178,7 @@ namespace xfitter
       QCDNUM::dmpwgt(1,22,"unpolarised.wgt");
     }
        
-		//Evolution gets its decomposition from YAML
+    //Evolution gets its decomposition from YAML
     gPdfDecomp=XFITTER_PARS::getInputFunctionFromYaml(yQCDNUM);
     initAtParameterChange();
   }
-- 
GitLab


From ee0d7a0c5460a573e22b267f4859a8911bb8d4bf Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Mon, 17 Sep 2018 08:36:51 +0200
Subject: [PATCH 23/26] Read reaction-specific parameters from "byReaction"
 YAML node

Only string-typed parameters for now
parameters.yaml may overwrite parameters in datafile, but in that case a warning is issued
---
 include/ReactionTheory.h |  2 +-
 src/ReactionTheory.cc    | 25 +++++++++++++++++--------
 src/TheorEval.cc         | 30 ++++++++++++++++++++----------
 src/ftheor_eval.cc       |  8 ++------
 4 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/include/ReactionTheory.h b/include/ReactionTheory.h
index bc7c25cc2..394b7e7a2 100644
--- a/include/ReactionTheory.h
+++ b/include/ReactionTheory.h
@@ -128,7 +128,7 @@ class ReactionTheory
   /// Set evolution name
   void setEvolution(std::string& evolution) { _evolution = evolution; }
 
-  /// Retrieve evolition
+  /// Retrieve evolution name //A better name would be "getEvolutionName" -- Ivan
   const std::string  getEvolution() const { return _evolution; }  
   
  protected:
diff --git a/src/ReactionTheory.cc b/src/ReactionTheory.cc
index 53b7c8e49..de598b91d 100644
--- a/src/ReactionTheory.cc
+++ b/src/ReactionTheory.cc
@@ -17,7 +17,7 @@ using std::string;
 
 // Global variable to hold current function
 
-std::function<void(double const& x, double const& Q, double* pdfs)> gProtonPdf;
+std::function<void(double const& x, double const& Q, double* pdfs)> gProtonPdf; //The name is misleading, this doesn't actually have to be a proton
 
 void protonPDF(double const& x, double const& Q, double* pdfs) {
   gProtonPdf(x,Q,pdfs);
@@ -52,16 +52,25 @@ ReactionTheory::operator=(const ReactionTheory &rt)
 }
 
 void ReactionTheory::initAtIteration() {
-  // do some magic
-  std::string evolName = getEvolution();
-  gProtonPdf = XFITTER_PARS::retrieveXfxQArray(evolName+":p");
+  try{
+    gProtonPdf = XFITTER_PARS::retrieveXfxQArray(_evolution);
+  }catch(std::out_of_range&ex){
+    std::cerr<<"Exception in "<<__func__<<": index \""<<_evolution<<"\" not present in gXfxQArrays map\n";
+    std::cerr<<ex.what();
+    hf_errlog(18091400,"F: Exception in retrieveXfxQArray, details written to stderr");
+  }
 }
 
 const pXFXlike  ReactionTheory::getXFX(const string& type) {
-
-  // XXXXXXXXXXXXXXXXXXXXXX  default evolution
-  std::string evName = XFITTER_PARS::getParameterS("Evolution");
-  gProtonPdf = XFITTER_PARS::retrieveXfxQArray(evName+":p");
+  //How is this different from initAtIteration?
+
+  try{
+    gProtonPdf = XFITTER_PARS::retrieveXfxQArray(_evolution);
+  }catch(std::out_of_range&ex){
+    std::cerr<<"Exception in "<<__func__<<": index \""<<_evolution<<"\" not present in gXfxQArrays map\n";
+    std::cerr<<ex.what();
+    hf_errlog(18091400,"F: Exception in retrieveXfxQArray, details written to stderr");
+  }
 
   // return _xfx[type];
   //  double dd[13];
diff --git a/src/TheorEval.cc b/src/TheorEval.cc
index 4278d9725..04563b804 100644
--- a/src/TheorEval.cc
+++ b/src/TheorEval.cc
@@ -265,26 +265,36 @@ TheorEval::initTerm(int iterm, valarray<double> *val)
   }
 }
 
+//Temporary solution, for string parameters only, pending discussion
+//Allows to provide dataset-specific reaction parameters in addition to dataset-provided reaction parameters
+//using byReaction node in parameters.yaml
+//When a parameters is given both in parameters.yaml and datafile, parameters.yaml has priority and a warning iss issued
 void LoadParametersFromYAML(std::map<std::string,std::string>&pars,const std::string&reactionName){
   using std::string;
-  //add to pars all parameters given in YAML file, but do not overwrite any parameters already in pars
-  auto it=XFITTER_PARS::gParametersY.find(reactionName);
-  if(it==XFITTER_PARS::gParametersY.end()){
-    hf_errlog(18090300,"W: No parameters for reaction \""+reactionName+"\" found in YAML steering file");
-    return;
+  const char*BY_REACTION="byReaction";
+  auto it=XFITTER_PARS::gParametersY.find(BY_REACTION);
+  if(it==XFITTER_PARS::gParametersY.end())return;//No overwrites given, nothing to do
+  YAML::Node&overwritesNode=it->second;
+  YAML::Node reactionNode=overwritesNode[reactionName];
+  if(reactionNode.IsNull())return;//No overwrite for this reaction, nothing to do
+  if(!reactionNode.IsMap()){
+    cerr<<"[ERROR] In "<<__func__<<"(pars,reactionName="<<reactionName<<"): expected reaction node to be a YAML Map:\n"
+        <<reactionNode<<"\n[/ERROR]"<<endl;
+    hf_errlog(18090301,"F: YAML error while loading reaction parameters, details written to stderr");
   }
-  YAML::Node&reactionNode=it->second;
   try{
     for(YAML::const_iterator it=reactionNode.begin();it!=reactionNode.end();++it){
       string key=it->first.as<string>();
       auto pit=pars.find(key);
-      if(pit==pars.end())pars[key]=it->second.as<string>();
+      if(pit!=pars.end()){
+        hf_errlog(18091700,"W: Reaction parameter in parameters.yaml overwrites dataset parameter");
+      }
+      pars[key]=it->second.as<string>();
     }
   }catch(YAML::TypedBadConversion<string>ex){
-    cerr<<"[ERROR] In LoadParametersFromYAML(pars,reactionName="<<reactionName<<"):\n"
-        <<"  YAML failed to convert to string while parsing node:\n"
+    cerr<<"[ERROR] In "<<__func__<<"(pars,reactionName="<<reactionName<<"): YAML failed to convert to string while parsing node:\n"
         <<reactionNode<<"\n[/ERROR]"<<endl;
-    hf_errlog(18090301,"F: YAML error in LoadParametersFromYAML, details written to stderr");
+    hf_errlog(18090301,"F: YAML error while loading reaction parameters, details written to stderr");
   }
 }
 int
diff --git a/src/ftheor_eval.cc b/src/ftheor_eval.cc
index 947146360..cbd74af77 100644
--- a/src/ftheor_eval.cc
+++ b/src/ftheor_eval.cc
@@ -320,13 +320,9 @@ void init_at_iteration_() {
     evolution->initAtIteration();
 
     // register updated PDF XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-		//Wait, do they get updated between iterations? Is this here even necessary? --Ivan
-
-    //const auto f = it.second->xfxQDouble();
-    //    std::cout << "Gluon(1) = " << f(0, 0.00001, 100) << std::endl;
-    const std::string evolName=evolution->_name+":p"; //Not sure why we need ":p" here --Ivan
+		//Wait, do they even get updated between iterations? Is this here even necessary? --Ivan
     
-    XFITTER_PARS::registerXfxQArray(evolName,evolution->xfxQArray());
+    XFITTER_PARS::registerXfxQArray(evolution->_name,evolution->xfxQArray());
   }
 
 
-- 
GitLab


From 5876d53213b20b683b4cfcde5b8581dddf35c385 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Mon, 24 Sep 2018 16:47:21 +0200
Subject: [PATCH 24/26] New interface for parameters, parameterisations and
 decompositions

---
 Reactions.txt                                 |   4 +-
 .../BaseEvolution/include/BaseEvolution.h     |   2 +-
 evolutions/LHAPDF/src/EvolutionLHAPDF.cc      |   3 +-
 include/CheckForPDF.h                         |   2 +-
 include/xfitter_pars.h                        |  11 +-
 include/xfitter_steer.h                       |   2 +
 .../include/BasePdfDecomposition.h            |  40 +--
 .../src/BasePdfDecomposition.cc               |   2 -
 .../include/LHAPDFDecomposition.h             |  19 +-
 .../src/LHAPDFDecomposition.cc                |  41 ++-
 .../include/SU3_PionPdfDecomposition.h        |  19 +-
 .../src/SU3_PionPdfDecomposition.cc           | 108 +++---
 .../UvDvUbarDbarS/include/UvDvUbarDbarS.h     |  37 +-
 .../UvDvUbarDbarS/src/UvDvUbarDbarS.cc        | 153 +++-----
 pdfparams/BasePdfParam/include/BasePdfParam.h |  16 +-
 pdfparams/BasePdfParam/src/BasePdfParam.cc    |  40 ++-
 .../include/HERAPDF_PdfParam.h                |   2 +
 .../HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc  |   6 +
 pdfparams/HERAPDF_PdfParam/src/Makefile.am    |   1 +
 .../include/PolySqrtPdfParam.h                |   2 +
 pdfparams/PolySqrtPdfParam/src/Makefile.am    |   1 +
 .../PolySqrtPdfParam/src/PolySqrtPdfParam.cc  |   6 +
 src/main.f                                    |   9 +-
 src/xfitter_pars.cc                           | 336 +++++++++++++-----
 src/xfitter_steer.cc                          | 141 +++++---
 25 files changed, 592 insertions(+), 411 deletions(-)

diff --git a/Reactions.txt b/Reactions.txt
index bd7678f04..a87355f2e 100644
--- a/Reactions.txt
+++ b/Reactions.txt
@@ -18,7 +18,9 @@ BaseEvolution libbaseevolution_xfitter.so
 APFELxx libapfelxx_xfitter.so
 QCDNUM libqcdnum_xfitter.so
 UvDvubardbars libuvdvubardbars_xfitter.so
-SU3_PionPdfDecomposition libSU3_PionPdfDecomposition_xfitter.so
+SU3_Pion libSU3_PionPdfDecomposition_xfitter.so
 MINUIT libMINUITMinimizer_xfitter.so
 CERES libCERESMinimizer_xfitter.so
 LHAPDF liblhapdf_xfitter.so
+HERAPDF libHERAPDF_PdfParam_xfitter.so
+PolySqrt libPolySqrtPdfParam_xfitter.so
diff --git a/evolutions/BaseEvolution/include/BaseEvolution.h b/evolutions/BaseEvolution/include/BaseEvolution.h
index 368976152..b9180d17b 100644
--- a/evolutions/BaseEvolution/include/BaseEvolution.h
+++ b/evolutions/BaseEvolution/include/BaseEvolution.h
@@ -25,7 +25,7 @@ namespace xfitter
 		const std::string _name;
     /**
      * @brief The BaseEvolution default constructor.
-     * @param name: the name assignet to the instance
+     * @param name: the unique name used to identify the instance
      */
     BaseEvolution(const char*name):_name(name){}
     
diff --git a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
index 4f6a4b0a2..118d78440 100644
--- a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
+++ b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
@@ -30,7 +30,7 @@ const char*EvolutionLHAPDF::getClassName()const{return "LHAPDF";}
     try{
       _set_name = pars["set"].as<std::string>();
     }catch(YAML::TypedBadConversion<std::string>&ex){
-      hf_errlog(18090310,"F: In EvolutionLHAPDF::initFromYaml: failed to convert YAML node \"set\" to string; printing node to stderr");
+      hf_errlog(18090310,"F: In EvolutionLHAPDF::initAtStart: failed to convert YAML node \"set\" to string; printing node to stderr");
       std::cerr<<pars<<std::endl;
     }
 
@@ -39,7 +39,6 @@ const char*EvolutionLHAPDF::getClassName()const{return "LHAPDF";}
     _member   = pars["member"].as<int>();
     if(_pdf)delete _pdf;
     _pdf      = LHAPDF::mkPDF(_set_name,_member);
-    return ;
  };
     
   /// Init at each iteration
diff --git a/include/CheckForPDF.h b/include/CheckForPDF.h
index b741706a3..d7ce9c740 100644
--- a/include/CheckForPDF.h
+++ b/include/CheckForPDF.h
@@ -1,7 +1,7 @@
 #ifndef __CHECKFORPDF_H
 #define __CHECKFORPDF_H
 
-/// for Fortran calling, check presense of PDF file.
+/// for Fortran calling, check presence of PDF file.
 void CheckForPDF(char const*pdfname);
 
 
diff --git a/include/xfitter_pars.h b/include/xfitter_pars.h
index ab6576e2b..baba52b57 100644
--- a/include/xfitter_pars.h
+++ b/include/xfitter_pars.h
@@ -25,6 +25,8 @@ namespace xfitter{
   class BaseEvolution;
   // to be defined in pdfdecompositions/
   class BasePdfDecomposition;
+  // to be defined in pdfparams/
+  class BasePdfParam;
   // to be defined in minimizers/
   class BaseMinimizer;
 	using InitialPDFfunction=std::function<std::map<int,double>(const double&x)>;
@@ -35,6 +37,8 @@ namespace XFITTER_PARS {
   /// Global pointer to the mimimizer
   extern xfitter::BaseMinimizer* gMinimizer;
   
+  /// Globally available YAML node pointing to root of YAML parameters tree, read from parameters.yaml. Might be modified during runtime
+  extern YAML::Node rootNode;
   /// Global map of double parameters. They can be used by the minimizer. Initialized based on parameters.yaml
   extern map<string,double*> gParameters;
 
@@ -55,9 +59,10 @@ namespace XFITTER_PARS {
 
   /// Global map to store evolutions
   extern map<string,xfitter::BaseEvolution*> gEvolutions;
-
   /// Global map to store decompositions
   extern map<string,xfitter::BasePdfDecomposition*> gPdfDecompositions;
+  /// Global map to store parameterisations
+  extern map<string,xfitter::BasePdfParam*>gParameterisations;
 	/// Helper function to get input function from a yaml node
 	///
   /// It finds a "decomposition" subnode in given node, extracts a decomposition name from it, finds this decomposition and returns its output function
@@ -66,6 +71,10 @@ namespace XFITTER_PARS {
   xfitter::InitialPDFfunction getInputFunctionFromYaml(const YAML::Node&);
   /// Helper function to get a yaml node corresponding to an evolution, by this evolutions's instance name
 	YAML::Node getEvolutionNode(const std::string&name="");
+  /// Helper function to get a yaml node corresponding to a decomposition, by this decomposition's instance name
+	YAML::Node getDecompositionNode(const std::string&name="");
+  /// Helper function to get a yaml node corresponding to a parameterisation, by this parameterisation's instance name
+	YAML::Node getParameterisationNode(const std::string&name="");
 
   /// Helper function to get string parameters
   std::string getParameterS(std::string name);
diff --git a/include/xfitter_steer.h b/include/xfitter_steer.h
index 28b7d49b7..387ea8eb3 100644
--- a/include/xfitter_steer.h
+++ b/include/xfitter_steer.h
@@ -14,12 +14,14 @@ namespace xfitter
 {
   class BaseEvolution;
   class BasePdfDecomposition;
+  class BasePdfParam;
   class BaseMinimizer;
 
   /// Load named evolution code.  
   BaseEvolution* get_evolution(std::string name="");  
   /// Load named pdfDecomposition code.  
   BasePdfDecomposition* get_pdfDecomposition(std::string name="");
+  BasePdfParam*getParameterisation(const std::string&name="");
   /// Load the minimizer
   BaseMinimizer* get_minimizer();
 }
diff --git a/pdfdecompositions/BasePdfDecomposition/include/BasePdfDecomposition.h b/pdfdecompositions/BasePdfDecomposition/include/BasePdfDecomposition.h
index 94f3141a7..298b31454 100644
--- a/pdfdecompositions/BasePdfDecomposition/include/BasePdfDecomposition.h
+++ b/pdfdecompositions/BasePdfDecomposition/include/BasePdfDecomposition.h
@@ -21,45 +21,35 @@ namespace xfitter
 {
   class BasePdfDecomposition {
   public:
+		const std::string _name;//Unique name used to identify this decomposition instance
 
-    /// Default constructor. Name is the PDF name
-  BasePdfDecomposition(const std::string& inName): _name(inName)  { };
-    virtual ~BasePdfDecomposition() {};
+    /// Default constructor. 
+    BasePdfDecomposition(const char*name):_name(name){}
+    virtual ~BasePdfDecomposition(){}
     
     /// Initialization at the first call
-    virtual void initAtStart(const std::string& pars) = 0;
-
+    virtual void initAtStart(){}
     /// Optional initialization at each iteration. Can be used to compute sum-rules
-    virtual void initAtIteration() {}
+    virtual void initAtIteration(){}
+    /// This function should be called when at least one parameter in the YAML node of given decomposition changes
+    virtual void initAtParameterChange(){}
 
     /// Print pdf parameters
-    virtual void printParams() {}
-    
+    //This shouldn't be here, printing parameters should be just a global function --Ivan
+    virtual void printParams(){}
+
     /// Returns a LHAPDF-style function, that returns PDFs in a physical basis for given x
     virtual std::function<std::map<int,double>(const double& x)> f0() const = 0;
-
-    void addParameterisation(const std::string& pname, BasePdfParam* pdfParam) {
-      _pdfParams[pname] = pdfParam;
-    }
-    
-    BasePdfParam* getPdfParam(std::string const& name) const {
-      return _pdfParams.at(name);
-    }
-
-    const std::string& getName() const { return _name; }
+    /// Get class name, can be used to verify that the correct concrete class is being used
+    virtual const char*getClassName()const=0;
     
   protected:
     /// PDF parameterisations
+    //Not really needed in this form --Ivan
       std::map<std::string,BasePdfParam*> _pdfParams;
-
-    
-    
-  private:
-    /// Name of PDF decomposition 
-    std::string _name;
-
   };
 
   /// For dynamic loader
+  //Wait, is this even used anywhere? --Ivan
   typedef BasePdfDecomposition* create_pdfDecomposition();
 }
diff --git a/pdfdecompositions/BasePdfDecomposition/src/BasePdfDecomposition.cc b/pdfdecompositions/BasePdfDecomposition/src/BasePdfDecomposition.cc
index 4f9c53666..b835543f8 100644
--- a/pdfdecompositions/BasePdfDecomposition/src/BasePdfDecomposition.cc
+++ b/pdfdecompositions/BasePdfDecomposition/src/BasePdfDecomposition.cc
@@ -1,3 +1 @@
 #include "BasePdfDecomposition.h"
-
-
diff --git a/pdfdecompositions/LHAPDFDecomposition/include/LHAPDFDecomposition.h b/pdfdecompositions/LHAPDFDecomposition/include/LHAPDFDecomposition.h
index 83c2d2bec..b95df4abf 100644
--- a/pdfdecompositions/LHAPDFDecomposition/include/LHAPDFDecomposition.h
+++ b/pdfdecompositions/LHAPDFDecomposition/include/LHAPDFDecomposition.h
@@ -2,8 +2,13 @@
 #pragma once
 
 #include "BasePdfDecomposition.h"
-
+//Try to suppress unused-local-typedef warning from boost 1.53.0 for gcc
+//Apparently these warnings have been fixed in later versions of boost
+#pragma GCC diagnostic push 
+#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
 #include "LHAPDF/LHAPDF.h"
+#pragma GCC diagnostic pop
+
 
 /**
   @class LHAPDFDecomposition
@@ -19,17 +24,17 @@ namespace xfitter
   class LHAPDFDecomposition : public BasePdfDecomposition
   {
   public:
-    /// Default constructor. Name is the PDF name
-    LHAPDFDecomposition(const std::string& PDFset, const int& mem = 0);
+    LHAPDFDecomposition(const char*name);
+    ~LHAPDFDecomposition();
+    virtual const char*getClassName()const override final;
 
     /// Optional initialization at the first call
-    virtual void initAtStart(const std::string& pars) override final;
+    virtual void initAtStart()override final;
 
-    /// Compute PDF in a physical base in LHAPDF format at the initial scale
+    /// Compute PDF in a physical basis in LHAPDF format at the initial scale
     virtual std::function<std::map<int,double>(const double& x)> f0() const override final;
 
   private:
-    const int                 _mem;
-    std::vector<LHAPDF::PDF*> _dist;
+    LHAPDF::PDF*_pdf{nullptr};
   };
 }
diff --git a/pdfdecompositions/LHAPDFDecomposition/src/LHAPDFDecomposition.cc b/pdfdecompositions/LHAPDFDecomposition/src/LHAPDFDecomposition.cc
index 00ceaac85..fe09f9b42 100644
--- a/pdfdecompositions/LHAPDFDecomposition/src/LHAPDFDecomposition.cc
+++ b/pdfdecompositions/LHAPDFDecomposition/src/LHAPDFDecomposition.cc
@@ -6,23 +6,36 @@
    Created by  AddPdfDecomposition.py on 2018-07-12
 */
 
-#include "LHAPDFDecomposition.h"
-#include "xfitter_pars.h"
+#include"LHAPDFDecomposition.h"
+#include"xfitter_pars.h"
+#include"xfitter_cpp_base.h"
+#include"CheckForPDF.h"
 
-namespace xfitter
-{
+namespace xfitter {
+  //For dynamic loading:
+  extern "C" LHAPDFDecomposition*create(const char*name){
+    return new LHAPDFDecomposition(name);
+  }
   //_________________________________________________________________________________
-  LHAPDFDecomposition::LHAPDFDecomposition(const std::string& PDFset, const int& mem):
-    BasePdfDecomposition{"LHAPDF"},
-    _mem(mem)
-    {
-      // Upload PDF set from LHAPDF
-      _dist = LHAPDF::mkPDFs(PDFset);
+  LHAPDFDecomposition::LHAPDFDecomposition(const char*name):BasePdfDecomposition{name}{}
+  LHAPDFDecomposition::~LHAPDFDecomposition(){if(_pdf)delete _pdf;}
+  const char*LHAPDFDecomposition::getClassName()const{return"LHAPDF";}
+  void LHAPDFDecomposition::initAtStart(){
+    YAML::Node pars=XFITTER_PARS::getDecompositionNode(_name);
+    string setName;
+    int member;
+    try{
+      setName=pars["set"].as<std::string>();
+    }catch(YAML::TypedBadConversion<std::string>&ex){
+      hf_errlog(18090310,"F: In LHAPDFDecomposition::initAtStart: failed to convert YAML node \"set\" to string; printing node to stderr");
+      std::cerr<<pars<<std::endl;
     }
 
-  //_________________________________________________________________________________
-  void LHAPDFDecomposition::initAtStart(const std::string & pars) 
-  {
+    // check if exists first
+    CheckForPDF(setName.c_str());
+    member=pars["member"].as<int>();
+    if(_pdf)delete _pdf;
+    _pdf=LHAPDF::mkPDF(setName,member);
   }
 
   //_________________________________________________________________________________
@@ -30,7 +43,7 @@ namespace xfitter
   {
     return [=] (const double& x)->std::map<int,double>
       {
-	return _dist[_mem]->xfxQ(x, *(XFITTER_PARS::gParameters.at("Q0")));
+        return _pdf->xfxQ(x, *(XFITTER_PARS::gParameters.at("Q0")));
       };
   }
 }
diff --git a/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h b/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h
index 7c9cd253f..d678078d0 100644
--- a/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h
+++ b/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h
@@ -26,14 +26,13 @@
   */
 namespace xfitter{
 class SU3_PionPdfDecomposition:public BasePdfDecomposition{
-	public:
-		SU3_PionPdfDecomposition();
-		SU3_PionPdfDecomposition(const std::string& inName);
-		~SU3_PionPdfDecomposition();
-		virtual void initAtStart(const std::string & pars) override final;
-		virtual void initAtIteration()override final;
-		virtual std::function<std::map<int,double>(const double& x)>f0()const override final; 
-	private:
-		BasePdfParam*par_v,*par_S,*par_g;
-	};
+  public:
+    SU3_PionPdfDecomposition(const char*name);
+    virtual const char*getClassName()const override final;
+    virtual void initAtStart()override final;
+    virtual void initAtIteration()override final;
+    virtual std::function<std::map<int,double>(const double& x)>f0()const override final;
+  private:
+    BasePdfParam*par_v{nullptr},*par_S{nullptr},*par_g{nullptr};
+  };
 }
diff --git a/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc b/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc
index 2c15b0cef..d7bab883d 100644
--- a/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc
+++ b/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc
@@ -4,72 +4,72 @@
    @author  AddPdfDecomposition.py
    Created by  AddPdfDecomposition.py on SU3_Pion
 */
+#include"xfitter_cpp_base.h"
+#include<iostream>
 #include"SU3_PionPdfDecomposition.h"
-#include"PolySqrtPdfParam.h" //This is for hacks, remove later
 #include"xfitter_pars.h"
+#include"xfitter_steer.h"
 using uint=unsigned int;
 using namespace std;
-namespace xfitter{
 //For dynamic loading:
-extern "C" SU3_PionPdfDecomposition*create(){
-	return new SU3_PionPdfDecomposition();
-}
-SU3_PionPdfDecomposition::SU3_PionPdfDecomposition():BasePdfDecomposition("SU3_Pion"){
-	par_v=nullptr;
-	par_S=nullptr;
-	par_g=nullptr;
+namespace xfitter{
+extern "C" SU3_PionPdfDecomposition*create(const char*name){
+  return new SU3_PionPdfDecomposition(name);
 }
-SU3_PionPdfDecomposition::SU3_PionPdfDecomposition(const std::string& inName):BasePdfDecomposition(inName){}
-SU3_PionPdfDecomposition::~SU3_PionPdfDecomposition(){
-	if(par_v)delete par_v;
-	if(par_S)delete par_S;
-	if(par_g)delete par_g;
+SU3_PionPdfDecomposition::SU3_PionPdfDecomposition(const char*name):BasePdfDecomposition{name}{}
+const char*SU3_PionPdfDecomposition::getClassName()const{return"SU3_Pion";}
+BasePdfParam*getParam(const BasePdfDecomposition*self,const YAML::Node&node,const char*s){
+  try{
+    return getParameterisation(node[s].as<string>());
+  }catch(const YAML::InvalidNode&ex){
+    if(node[s].IsNull()){
+      cerr<<"[ERROR] No \""<<s<<"\" parameterisation given for decomposition \""<<self->_name<<"\""<<endl;
+      hf_errlog(18092410,"F: Error in decomposition parameters, details written to stderr");
+    }else throw ex;
+  }catch(const YAML::BadConversion&ex){
+    cerr<<"[ERROR] Bad parameter \""<<s<<"\" given for decomposition \""<<self->_name<<"\""<<endl;
+    hf_errlog(18092410,"F: Error in decomposition parameters, details written to stderr");
+  }
+  return nullptr;//unreachable, suppress warning
 }
 // Init at start:
-void SU3_PionPdfDecomposition::initAtStart(const std::string & pars){
-	//HARDCODE copied from UvDvUbarDbarS, then modified
-	//The following is not very nice: Decomposition should not create or initialize parameterisations
-	//Create and initialize paramterisations
-	for(const auto&node:XFITTER_PARS::gParametersY.at("SU3_PionPdfDecomposition")["HARDWIRED_PolySqrt"]){
-		const string prmzName=node.first.as<string>();//Name of parameterisation
-		BasePdfParam*pParam=new PolySqrtPdfParam(prmzName);
-		pParam->initFromYaml(node.second);
-		addParameterisation(prmzName,pParam);
-	}
-	par_v=getPdfParam("v");
-	par_S=getPdfParam("S");
-	par_g=getPdfParam("g");
+void SU3_PionPdfDecomposition::initAtStart(){
+  const YAML::Node node=XFITTER_PARS::getDecompositionNode(_name);
+  //get parameterisation usually doesn't throw
+  par_v=getParam(this,node,"valence");
+  par_S=getParam(this,node,"sea");
+  par_g=getParam(this,node,"gluon");
 }
 void SU3_PionPdfDecomposition::initAtIteration() {
-	//Enforce sum rules
-	//Valence sum
-	par_v->setMoment(-1,1);
-	//Momentum sum
-	par_g->setMoment(0,1-6*par_S->moment(0)-2*par_v->moment(0));
+  //Enforce sum rules
+  //Valence sum
+  par_v->setMoment(-1,1);
+  //Momentum sum
+  par_g->setMoment(0,1-6*par_S->moment(0)-2*par_v->moment(0));
 }
 // Returns a LHAPDF-style function, that returns PDFs in a physical basis for given x
 std::function<std::map<int,double>(const double& x)>SU3_PionPdfDecomposition::f0()const{
-	return [=](double const& x)->std::map<int, double>{
-		double v=(*par_v)(x);
-		double S=(*par_S)(x);
-		double g=(*par_g)(x);
-		double d=S+v;
-		std::map<int,double>res_={
-			{-6,0},
-			{-5,0},
-			{-4,0},
-			{-3,S},//sbar
-			{-2,d},//ubar
-			{-1,S},//dbar
-			{ 1,d},//d
-			{ 2,S},//u
-			{ 3,S},//s
-			{ 4,0},
-			{ 5,0},
-			{ 6,0},
-			{21,g}
-		};
-		return res_;
-	};
+  return [=](double const& x)->std::map<int, double>{
+    double v=(*par_v)(x);
+    double S=(*par_S)(x);
+    double g=(*par_g)(x);
+    double d=S+v;
+    std::map<int,double>res_={
+      {-6,0},
+      {-5,0},
+      {-4,0},
+      {-3,S},//sbar
+      {-2,d},//ubar
+      {-1,S},//dbar
+      { 1,d},//d
+      { 2,S},//u
+      { 3,S},//s
+      { 4,0},
+      { 5,0},
+      { 6,0},
+      {21,g}
+    };
+    return res_;
+  };
 }
 }
diff --git a/pdfdecompositions/UvDvUbarDbarS/include/UvDvUbarDbarS.h b/pdfdecompositions/UvDvUbarDbarS/include/UvDvUbarDbarS.h
index 74e06bcc2..bda3db877 100644
--- a/pdfdecompositions/UvDvUbarDbarS/include/UvDvUbarDbarS.h
+++ b/pdfdecompositions/UvDvUbarDbarS/include/UvDvUbarDbarS.h
@@ -20,10 +20,11 @@ namespace xfitter
   {
   public:
     /// Default constructor. Name is the PDF name
-    UvDvUbarDbarS();
+    UvDvUbarDbarS(const char*name);
+    virtual const char*getClassName()const override final;
 
     /// Optional initialization at the first call
-    virtual void initAtStart(const std::string& pars) override final;
+    virtual void initAtStart()override final;
 
     /// Compute sum-rules
     virtual void initAtIteration() override final;
@@ -36,31 +37,11 @@ namespace xfitter
 
 
   private:
-    /// Get parameter values from the minimizer
-    std::unique_ptr<double[]> getParValues(BasePdfParam const* param) const;
-
-    /// Get valence
-    double valence(double x,const std::string&name)const;
-
-    /// Get sea
-    double sea(double x, std::string const& name) const;
-    
-    /// Get uv, apply sum-rule
-    double uv(double x) const;
-
-    /// Get dv, apply sum-rule
-    double dv(double x) const;    
-
-    /// Get dbar
-    double dbar(double x) const;
-
-    /// Get ubar
-    double ubar(double x) const;
-
-    /// Get s
-    double s(double x) const;
-
-    /// Get g
-    double g(double x) const;
+    BasePdfParam*par_xuv{nullptr},
+                *par_xdv{nullptr},
+                *par_xubar{nullptr},
+                *par_xdbar{nullptr},
+                *par_xs{nullptr},
+                *par_xg{nullptr};
   };
 }
diff --git a/pdfdecompositions/UvDvUbarDbarS/src/UvDvUbarDbarS.cc b/pdfdecompositions/UvDvUbarDbarS/src/UvDvUbarDbarS.cc
index 6ca48015e..b784102f2 100644
--- a/pdfdecompositions/UvDvUbarDbarS/src/UvDvUbarDbarS.cc
+++ b/pdfdecompositions/UvDvUbarDbarS/src/UvDvUbarDbarS.cc
@@ -7,8 +7,8 @@
 */
 
 #include "UvDvUbarDbarS.h"
-#include "HERAPDF_PdfParam.h"
 #include "xfitter_pars.h"
+#include "xfitter_steer.h"
 #include <iostream>
 #include <iomanip>
 #include <cmath>
@@ -16,135 +16,98 @@
 namespace xfitter
 {
   /// the class factories
-  extern "C" UvDvUbarDbarS* create() {
-    return new UvDvUbarDbarS();
+  extern "C" UvDvUbarDbarS*create(const char*name){
+    return new UvDvUbarDbarS(name);
   }
 
   
   //_________________________________________________________________________________
-  UvDvUbarDbarS::UvDvUbarDbarS(): BasePdfDecomposition{"UvDvUbarDbarS"} { }
+  UvDvUbarDbarS::UvDvUbarDbarS(const char*name):BasePdfDecomposition{name}{}
+  const char*UvDvUbarDbarS::getClassName()const{return"UvDvUbarDbarS";}
 
   //_________________________________________________________________________________
-  void UvDvUbarDbarS::initAtStart(const std::string & pars){
-    // HARDWIRE A BIT FOR NOW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-    // Currently we create and initialise parameterisations
-    // This is not great, it is not Decomposition's job, they should be created globally
-    const YAML::Node pdfs    = XFITTER_PARS::gParametersY.at("UvDvubardbars")["HERAPDF_pdfparam"];
-
-    for (const auto& pdf : pdfs) {
-      const string pdfName = pdf.first.as<string>();
-      BasePdfParam* pParam = new HERAPDF_PdfParam(pdfName);
-      pParam->initFromYaml(pdf.second);
-			addParameterisation(pdfName,pParam);
-    }
+  void UvDvUbarDbarS::initAtStart(){
+    const YAML::Node node=XFITTER_PARS::getDecompositionNode(_name);
+    //TODO: handle errors
+    par_xuv  =getParameterisation(node["xuv"].as<string>());
+    par_xdv  =getParameterisation(node["xdv"].as<string>());
+    par_xubar=getParameterisation(node["xubar"].as<string>());
+    par_xdbar=getParameterisation(node["xdbar"].as<string>());
+    par_xs   =getParameterisation(node["xs"].as<string>());
+    par_xg   =getParameterisation(node["xg"].as<string>());
   }
 
   void UvDvUbarDbarS::initAtIteration() {
     //Enforce sum rules
     // counting sum-rules for uv and dv
-    getPdfParam("xuv")->setMoment(-1,2.0);
-    getPdfParam("xdv")->setMoment(-1,1.0);
+    par_xuv->setMoment(-1,2.0);
+    par_xdv->setMoment(-1,1.0);
     // momentum sum-rule
     // quark part
     double xsumq=0;
-    xsumq+=  getPdfParam("xuv"  )->moment(0);
-    xsumq+=  getPdfParam("xdv"  )->moment(0);
-    xsumq+=2*getPdfParam("xubar")->moment(0);
-    xsumq+=2*getPdfParam("xdbar")->moment(0);
-    xsumq+=2*getPdfParam("xs"   )->moment(0);
+    xsumq+=  par_xuv  ->moment(0);
+    xsumq+=  par_xdv  ->moment(0);
+    xsumq+=2*par_xubar->moment(0);
+    xsumq+=2*par_xdbar->moment(0);
+    xsumq+=2*par_xs   ->moment(0);
     // gluon part
-    getPdfParam("xg")->setMoment(0,1-xsumq);
+    par_xg->setMoment(0,1-xsumq);
 
     printParams();
   }
 
   void UvDvUbarDbarS::printParams() {
-    std::cout << "\n" << std::left<< std::setw(8) << " Name " << std::right;
-    for ( int i =0 ; i<6; i++) {
-      std::cout << std::setw(12) << " par"+std::to_string(i) ;
-    }
-    std::cout << "\n";
-    for ( auto p : _pdfParams) {
-      auto pdfParam = p.second;
-      auto name = p.first;
-      auto pars = getParValues(pdfParam);
-      int  npar = pdfParam->getNPar();
-
-      //      std::cout << "name :" << name << " npar: " << npar << "\n";
-      std::cout << std::left<< std::setw(8) << name << std::right;
-      for ( int i =0 ; i<npar; i++) {
-        std::cout << std::setw(12) << pars[i];
-      }
-      std::cout << "\n";
-    }
-    std::cout << "\n";
-  }
-  
-  std::unique_ptr<double[]> UvDvUbarDbarS::getParValues(BasePdfParam const* param) const {
-    std::unique_ptr<double[]> pars( new double[param->getNPar()] );
-    for (unsigned int i=0; i<param->getNPar(); i++) {
-      const std::string pnam=param->getName()+ "_p" +  std::to_string(i) ;
-      pars[i] = *XFITTER_PARS::gParameters.at(pnam);
-    }
-    return pars;
-  }
-  
-  double UvDvUbarDbarS::valence(double x, const std::string&name) const {
-    return(*getPdfParam(name))(x);
-  }
-
-  double UvDvUbarDbarS::sea(double x,const std::string&name)const{
-    return(*getPdfParam(name))(x);
-  }
-
-  double UvDvUbarDbarS::uv(double x) const {
-    return valence(x,"xuv"); 
-  }
-
-  double UvDvUbarDbarS::dv(double x) const {
-    return valence(x,"xdv"); 
-  }
-
-  double UvDvUbarDbarS::ubar(double x) const {
-    return sea(x,"xubar");
+  //Sorry, I broke this during a rewrite
+  //This should be a global function anyway
+  //--Ivan
+    //std::cout << "\n" << std::left<< std::setw(8) << " Name " << std::right;
+    //for ( int i =0 ; i<6; i++) {
+      //std::cout << std::setw(12) << " par"+std::to_string(i) ;
+    //}
+    //std::cout << "\n";
+    //for ( auto p : _pdfParams) {
+      //auto pdfParam = p.second;
+      //auto name = p.first;
+      //auto pars = getParValues(pdfParam);
+      //int  npar = pdfParam->getNPar();
+
+      ////      std::cout << "name :" << name << " npar: " << npar << "\n";
+      //std::cout << std::left<< std::setw(8) << name << std::right;
+      //for ( int i =0 ; i<npar; i++) {
+        //std::cout << std::setw(12) << pars[i];
+      //}
+      //std::cout << "\n";
+    //}
+    //std::cout << "\n";
   }
-
-  double UvDvUbarDbarS::dbar(double x) const {
-    return sea(x,"xdbar"); // XXXXXXXXXXXXX HARDWIRE
-  }
-  
-  double UvDvUbarDbarS::s(double x) const {
-    return sea(x,"xs");
-  }
-
-  double UvDvUbarDbarS::g(double x)const{
-    return (*getPdfParam("xg"))(x);
-  }
-
-  
   //_________________________________________________________________________________
   std::function<std::map<int,double>(const double& x)> UvDvUbarDbarS::f0() const
   {
     // lambda function
-    const auto _f0 = [=] (double const& x)->std::map<int, double> {
+    return [=] (double const& x)->std::map<int, double> {
+      double ubar=(*par_xubar)(x);
+      double dbar=(*par_xdbar)(x);
+      double u=(*par_xuv)(x)+ubar;
+      double d=(*par_xdv)(x)+dbar;
+      double s=(*par_xs)(x);
+      double g=(*par_xg)(x);
       std::map<int, double> res  = {
         {-6,0},
         {-5,0},
         {-4,0},
-        {-3,s(x)},
-        {-2,ubar(x)},
-        {-1,dbar(x)},
-        { 1,dbar(x)+dv(x)},
-        { 2,ubar(x)+uv(x)},
-        { 3,s(x)},
+        {-3,s},
+        {-2,ubar},
+        {-1,dbar},
+        { 1,d},
+        { 2,u},
+        { 3,s},
         { 4,0},
         { 5,0},
         { 6,0},
-        {21,g(x)}
+        {21,g}
       };
       return res;
     };
-    return _f0;
   }
 }
 
diff --git a/pdfparams/BasePdfParam/include/BasePdfParam.h b/pdfparams/BasePdfParam/include/BasePdfParam.h
index cc24d5d67..343711a13 100644
--- a/pdfparams/BasePdfParam/include/BasePdfParam.h
+++ b/pdfparams/BasePdfParam/include/BasePdfParam.h
@@ -24,10 +24,11 @@
   @date 2018-08-13
   */
 
+namespace xfitter{
 class BasePdfParam{
 public:
-  BasePdfParam(const std::string&instance_name):_name(instance_name),pars{nullptr},Npars(0){}
-  virtual~BasePdfParam(){if(pars)delete[]pars;}
+  BasePdfParam(const std::string&instance_name):_name(instance_name){}
+  virtual~BasePdfParam();
   void               setNPar(unsigned int N){Npars=N;}
   const unsigned int getNPar()const{return Npars;}
   //!Evaluate xf(x) at given x with current parameters, pure virtual
@@ -41,14 +42,13 @@ public:
   virtual void setMoment(int nMoment,double value);
   //!Get name of the instance
   const std::string getName()const{return _name;} 
-  //!Initialize from a yaml node. Uses node[getName] as the basis
-  virtual void initFromYaml(YAML::Node value);
+  virtual void initAtStart();
 protected:
   //!Unique name of instance
-  std::string _name;
+  const std::string _name;
   //!Array of pointers to some global locations where minimization parameters are stored
-  //TODO: Implement proper pars initialization from YAML
-  double**pars;
+  double**pars{nullptr};
   //!Number of parameters, which is also the size of the array **parameters defined above
-  unsigned int Npars;
+  unsigned int Npars{0};
 };
+}
diff --git a/pdfparams/BasePdfParam/src/BasePdfParam.cc b/pdfparams/BasePdfParam/src/BasePdfParam.cc
index 992ec5926..63d0de5bd 100644
--- a/pdfparams/BasePdfParam/src/BasePdfParam.cc
+++ b/pdfparams/BasePdfParam/src/BasePdfParam.cc
@@ -2,6 +2,7 @@
 #include"BaseMinimizer.h"
 #include"xfitter_pars.h"
 #include"xfitter_steer.h"
+#include"xfitter_cpp_base.h"
 #include<cmath>
 #include<memory>
 #include<iostream>
@@ -17,7 +18,9 @@ extern "C" {
                          map<std::string,double*> *map,
                          int len);
 }
+namespace xfitter{
 /// Implement numeric integration
+BasePdfParam::~BasePdfParam(){if(pars)delete[]pars;}
 double BasePdfParam::moment(int iMoment)const{
   /// Simple rule, split log/lin spacing at xsplit=0.1
 
@@ -55,10 +58,32 @@ void BasePdfParam::setMoment(int nMoment,double value){
   *pars[0]=1;
   *pars[0]=value/moment(nMoment);
 }
-void BasePdfParam::initFromYaml(YAML::Node value) {
-  // HARDWIRE A BIT FOR NOW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-  //TODO rewrite this for a different, new YAML format
+void BasePdfParam::initAtStart(){
   using namespace std;
+  YAML::Node node=XFITTER_PARS::getParameterisationNode(_name);
+  YAML::Node parsNode=node["parameters"];
+  if(!parsNode.IsSequence()){
+    cerr<<"[ERROR] Bad \"parameters\" for parameterisation \""<<_name<<"\", expected sequence"<<endl;
+    hf_errlog(18092420,"F: Bad parameters in parameterisation, see stderr");
+  }
+  Npars=parsNode.size();
+  pars=new double*[Npars];
+  //TODO: destructor
+  for(unsigned int i=0;i<Npars;++i){
+    try{
+      pars[i]=XFITTER_PARS::gParameters.at(parsNode[i].as<string>());
+    }catch(const YAML::BadConversion&ex){
+      cerr<<"[ERROR] Bad name of parameter "<<i<<" for parameterisation \""<<_name<<"\": "<<ex.what()<<endl;
+      hf_errlog(18092421,"F: Bad parameter name in parameterisation definition, see stderr");
+    }catch(const out_of_range&ex){
+      string parname=parsNode[i].as<string>();
+      if(XFITTER_PARS::gParameters.count(parname)==0){
+        cerr<<"[ERROR] Unknown parameter \""<<parname<<"\" in parameterisation \""<<_name<<"\""<<endl;
+        hf_errlog(18092422,"F: Unknown parameter in parameterisation definition, see stderr");
+      }
+    }
+  }
+  /*
   using uint=unsigned int;
   //cout<<"DEBUG["<<_name<<"]: initFromYaml: value="<<value<<endl;
   if(value.IsSequence()){
@@ -78,15 +103,10 @@ void BasePdfParam::initFromYaml(YAML::Node value) {
       //int add = true;
       //      addexternalparam_(pnam.c_str(),val,step,minv,maxv,priorVal,priorUnc,add,&XFITTER_PARS::gParameters,pnam.size());
 
-      xfitter::BaseMinimizer* minimizer = xfitter::get_minimizer();
-      minimizer->addParameter(val,pnam,step,nullptr,nullptr);
-      
-      pars[i]=XFITTER_PARS::gParameters.at(pnam);
-      //cout<<pnam<<"="<<(*pars[i])<<endl;
     }
   }else{
     cout<<"ERROR["<<_name<<"]: initFromYaml: parameter is not a sequence!"<<endl;
   }
-  //TODO: Handle possible errors
+  */
+}
 }
-
diff --git a/pdfparams/HERAPDF_PdfParam/include/HERAPDF_PdfParam.h b/pdfparams/HERAPDF_PdfParam/include/HERAPDF_PdfParam.h
index 68aede0ed..b406f9bdd 100644
--- a/pdfparams/HERAPDF_PdfParam/include/HERAPDF_PdfParam.h
+++ b/pdfparams/HERAPDF_PdfParam/include/HERAPDF_PdfParam.h
@@ -21,9 +21,11 @@
   @date 2018-08-14
   */
 
+namespace xfitter{
 class HERAPDF_PdfParam:public BasePdfParam{
   public:
     HERAPDF_PdfParam(const std::string&inName):BasePdfParam(inName){}
     virtual double operator()(double x)const override final;
     virtual double moment(int nMoment=-1)const override final;
 };
+}
diff --git a/pdfparams/HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc b/pdfparams/HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc
index 13b97110f..44ea567e6 100644
--- a/pdfparams/HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc
+++ b/pdfparams/HERAPDF_PdfParam/src/HERAPDF_PdfParam.cc
@@ -8,6 +8,11 @@
 #include "HERAPDF_PdfParam.h"
 #include <cmath>
 
+namespace xfitter{
+//for dynamic loading
+extern"C" HERAPDF_PdfParam*create(const char*name){
+  return new HERAPDF_PdfParam(name);
+}
 // Main function to compute PDF
 double HERAPDF_PdfParam::operator()(double x)const{
   const int npar = getNPar();
@@ -51,3 +56,4 @@ double HERAPDF_PdfParam::moment(int n)const{
   }
   return (*pars[0])*exp(lgamma(B)+lgamma(C)-lgamma(B+C))*sum;
 }
+}
diff --git a/pdfparams/HERAPDF_PdfParam/src/Makefile.am b/pdfparams/HERAPDF_PdfParam/src/Makefile.am
index 7d0f21450..2913dd712 100644
--- a/pdfparams/HERAPDF_PdfParam/src/Makefile.am
+++ b/pdfparams/HERAPDF_PdfParam/src/Makefile.am
@@ -10,3 +10,4 @@ datadir = ${prefix}/yaml/pdfparams/HERAPDF_PdfParam
 data_DATA = ../yaml/parameters.yaml
 
 dist_noinst_HEADERS = ../include ../yaml
+libHERAPDF_PdfParam_xfitter_la_LDFLAGS=-lBasePdfParam_xfitter -L$(libdir)
diff --git a/pdfparams/PolySqrtPdfParam/include/PolySqrtPdfParam.h b/pdfparams/PolySqrtPdfParam/include/PolySqrtPdfParam.h
index eeb2a880c..c8073b1ab 100644
--- a/pdfparams/PolySqrtPdfParam/include/PolySqrtPdfParam.h
+++ b/pdfparams/PolySqrtPdfParam/include/PolySqrtPdfParam.h
@@ -21,6 +21,7 @@
   @date 2018-08-16
   */
 
+namespace xfitter{
 class PolySqrtPdfParam:public BasePdfParam{
   public:
     PolySqrtPdfParam(const std::string&inName):BasePdfParam(inName){}
@@ -32,3 +33,4 @@ class PolySqrtPdfParam:public BasePdfParam{
     //Initialize from a yaml node. Uses node[getName] as the basis
     // virtual void initFromYaml(YAML::Node value)override final;
 };
+}
diff --git a/pdfparams/PolySqrtPdfParam/src/Makefile.am b/pdfparams/PolySqrtPdfParam/src/Makefile.am
index 6cf1672ff..6a51b542c 100644
--- a/pdfparams/PolySqrtPdfParam/src/Makefile.am
+++ b/pdfparams/PolySqrtPdfParam/src/Makefile.am
@@ -10,3 +10,4 @@ datadir = ${prefix}/yaml/pdfparams/PolySqrt
 data_DATA = ../yaml/parameters.yaml
 
 dist_noinst_HEADERS = ../include ../yaml
+libPolySqrtPdfParam_xfitter_la_LDFLAGS=-lBasePdfParam_xfitter -L$(libdir)
diff --git a/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc b/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc
index 6799ed524..e1258bd7c 100644
--- a/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc
+++ b/pdfparams/PolySqrtPdfParam/src/PolySqrtPdfParam.cc
@@ -10,6 +10,11 @@
 #include<cmath>
 using namespace std;
 using uint=unsigned int;
+namespace xfitter{
+//for dynamic loading
+extern"C" PolySqrtPdfParam*create(const char*name){
+  return new PolySqrtPdfParam(name);
+}
 double PolySqrtPdfParam::operator()(double x)const{
   const uint N=getNPar();
   double pol=1;
@@ -64,3 +69,4 @@ double PolySqrtPdfParam::moment(int n)const{
   ret*=(*pars[0]);
   return ret;
 }
+}
diff --git a/src/main.f b/src/main.f
index 426d32d65..444ee8fd7 100644
--- a/src/main.f
+++ b/src/main.f
@@ -65,12 +65,11 @@ C-----------------------------------------------------
 *
 *  Read parameters:
 *
-      call parse_params() 
-
-*     ------------------------------------------------
-*     Init new theory modules
-*     ------------------------------------------------
+*Read the list of dynamically loaded objects from Reactions.txt
+*Confusingly, this is used not only for reactions, but also for
+*minimizers, decompositions, parameterisations and evolutions
       call read_reactions()
+      call parse_params() !read parameters.yaml
 
 *
 *     Init evolution
diff --git a/src/xfitter_pars.cc b/src/xfitter_pars.cc
index 0cbc12656..5985e3221 100644
--- a/src/xfitter_pars.cc
+++ b/src/xfitter_pars.cc
@@ -13,6 +13,7 @@
 #include "xfitter_cpp_base.h"
 #include <fstream>
 #include <string.h>
+#include <cmath>
 #include "BaseEvolution.h"
 #include "BasePdfDecomposition.h"
 #include "BaseMinimizer.h"
@@ -22,12 +23,12 @@ extern "C" {
   void parse_params_();  //!< Fortran callable parsing
   /// Interface to minuit parameters
   void addexternalparam_(const char name[],  const double &val, 
-			 const double  &step,
-			 const double &min, const double &max, 
-			 const double &prior, const double &priorUnc,
-			 const int &add, 
-			 map<std::string,double*> *map,
-			 int len);
+       const double  &step,
+       const double &min, const double &max, 
+       const double &prior, const double &priorUnc,
+       const int &add, 
+       map<std::string,double*> *map,
+       int len);
   void add_to_param_map_(map<std::string,double*>* map,double &value, int& global, char *name, int len);
   // Get parameters in fortran, for backward compatibility:
   double getparamd_(const char* name, int len);
@@ -40,6 +41,7 @@ namespace XFITTER_PARS {
 
   // Global vars:
   xfitter::BaseMinimizer* gMinimizer(nullptr);
+  YAML::Node rootNode;
   map <string, double*> gParameters;
   map <string, int>    gParametersI;
   map <string, string> gParametersS;
@@ -50,8 +52,10 @@ namespace XFITTER_PARS {
 
   // Also keep list of loaded evolutions here:
   map<string,xfitter::BaseEvolution*> gEvolutions;
-  // Also keep list of loaded evolutions here:
+  // Also keep list of loaded decompositions here:
   map<string,xfitter::BasePdfDecomposition*> gPdfDecompositions;
+  // Also keep list of loaded parameterisations here:
+  map<string,xfitter::BasePdfParam*> gParameterisations;
 
   using namespace xfitter;
   xfitter::InitialPDFfunction getInputFunctionFromYaml(const YAML::Node&rootNode){
@@ -61,26 +65,56 @@ namespace XFITTER_PARS {
       name=node.as<string>();
     }catch(YAML::TypedBadConversion<string>ex){
       ostringstream s;s<<"W: YAML exception: "<<ex.what()<<"; while trying to extract decomposition name from node: "<<node<<"; using default decomposition name";
-      hf_errlog(18082930,s.str().c_str()); 
+      hf_errlog(18082930,s.str()); 
       name=getDefaultDecompositionName();
     }
     return xfitter::get_pdfDecomposition(name)->f0();
   }
-	YAML::Node getEvolutionNode(const std::string&name){
+  YAML::Node getEvolutionNode(const std::string&name){
     auto it=gParametersY.find("Evolutions");
     if(it==gParametersY.end()){
       hf_errlog(18082900,"F:Failed to get evolution "+name+": Evolutions node not found in parameters.yaml");
     }
     YAML::Node instanceNode=it->second[name];
     if(!instanceNode.IsMap()){
-			std::ostringstream s;
-			s<<"F:Failed to get evolution \""<<name<<"\": ";
+      std::ostringstream s;
+      s<<"F:Failed to get evolution \""<<name<<"\": ";
       if(!instanceNode)s<<"no subnode with this name under the node Evolutions";
       else s<<"corresponding subnode is not of type Map";
-			hf_errlog(18082901,s.str().c_str());
+      hf_errlog(18082901,s.str().c_str());
+    }
+    return instanceNode;
+  }
+  YAML::Node getDecompositionNode(const std::string&name){
+    auto it=gParametersY.find("Decompositions");
+    if(it==gParametersY.end()){
+      hf_errlog(18082902,"F:Failed to get decomposition "+name+": \"Decompositions\" node not found");
+    }
+    YAML::Node instanceNode=it->second[name];
+    if(!instanceNode.IsMap()){
+      std::ostringstream s;
+      s<<"F:Failed to get decomposition \""<<name<<"\": ";
+      if(!instanceNode)s<<"no subnode with this name under the node Decompositions";
+      else s<<"corresponding subnode is not of type Map";
+      hf_errlog(18082903,s.str().c_str());
+    }
+    return instanceNode;
+  }
+  YAML::Node getParameterisationNode(const std::string&name){
+    auto it=gParametersY.find("Parameterisations");
+    if(it==gParametersY.end()){
+      hf_errlog(18082904,"F:Failed to get parameterisation "+name+": \"Parameterisations\" node not found");
     }
-		return instanceNode;
-	}
+    YAML::Node instanceNode=it->second[name];
+    if(!instanceNode.IsMap()){
+      std::ostringstream s;
+      s<<"F:Failed to get parameterisation \""<<name<<"\": ";
+      if(!instanceNode)s<<"no subnode with this name under the node Parameterisations";
+      else s<<"corresponding subnode is not of type Map";
+      hf_errlog(18082905,s.str().c_str());
+    }
+    return instanceNode;
+  }
 
   std::string getParameterS(std::string name) {
     auto search = gParametersS.find(name);
@@ -119,6 +153,8 @@ namespace XFITTER_PARS {
       }
       YAML::Node node = YAML::LoadFile(name);
       parse_node(node, gParameters, gParametersI, gParametersS, gParametersV, gParametersY);
+      //HACKY way to get rootNode, pending include rewrite
+      if(rootNode.IsNull())rootNode=node;
     }
     catch (const std::exception& e) {
       std::cout << e.what() << std::endl;
@@ -148,95 +184,95 @@ namespace XFITTER_PARS {
     
       //  Check if asked to read another file:
       if ( p_name == "include" ) {
-	auto fileName =  value.as<string>();
-	if (is_file_exist(fileName.c_str())) {
-	  parse_file( fileName );
-	}
-	else {
-	  // Now try default location:
-	  if (is_file_exist((PREFIX +string("/")+fileName).c_str())) {
-	    parse_file( PREFIX +string("/")+fileName );
-	  }
-	  else {
-	    string msg = "F: Include Yaml parameters file "+fileName+" not found";
-	    hf_errlog_(17041601,msg.c_str(), msg.size());
-	  }
-	}
+  auto fileName =  value.as<string>();
+  if (is_file_exist(fileName.c_str())) {
+    parse_file( fileName );
+  }
+  else {
+    // Now try default location:
+    if (is_file_exist((PREFIX +string("/")+fileName).c_str())) {
+      parse_file( PREFIX +string("/")+fileName );
+    }
+    else {
+      string msg = "F: Include Yaml parameters file "+fileName+" not found";
+      hf_errlog_(17041601,msg.c_str(), msg.size());
+    }
+  }
       }
       
       if (value.IsScalar()) {
-	// Alright, store directly
-	// Try to read as int, float, string:
-	try {
-	  int i = value.as<int>();
-	  iMap[p_name] = i;
-	  continue;
-	}
-	catch (const std::exception& e) {
-	}
-	
-	try {
-	  double f = value.as<double>();
-	  dMap[p_name] = new double(f);
-	  continue;
-	}
-	catch (const std::exception& e) {
-	}
-	
-	try {
-	  std::string s = value.as<std::string>();
-	  sMap[p_name] = s;
-	  continue;
-	}
-	catch (const std::exception& e) {
-	}      
+  // Alright, store directly
+  // Try to read as int, float, string:
+  try {
+    int i = value.as<int>();
+    iMap[p_name] = i;
+    continue;
+  }
+  catch (const std::exception& e) {
+  }
+  
+  try {
+    double f = value.as<double>();
+    dMap[p_name] = new double(f);
+    continue;
+  }
+  catch (const std::exception& e) {
+  }
+  
+  try {
+    std::string s = value.as<std::string>();
+    sMap[p_name] = s;
+    continue;
+  }
+  catch (const std::exception& e) {
+  }      
       }
       else { // Potentially this may go to minuit, if step is not zero.
-	
-	if (value.IsMap()) {
+  
+  if (value.IsMap()) {
 
-	  // Check if this is a minimisation block, true if step is present
-	  if (value["step"] || value["value"]) {  
-	    // Defaults
-	    double val = 0;
-	    double step = 0;
-	    double minv  = 0;
-	    double maxv  = 0;
-	    double priorVal = 0;
-	    double priorUnc = 0;
-	    int add = true;
-	    
-	    if (value["value"]) {
-	      val = value["value"].as<double>();
-	    }
-	    else {
-	      string text = "F: missing value field for parameter " + p_name;
-	      hf_errlog_(17032401,text.c_str(),text.size());       
-	    }
-	    if (value["step"]) step = value["step"].as<double>();
-	    if (value["prior"]) priorVal = value["prior"].as<double>();
-	    if (value["priorUnc"]) priorUnc = value["priorUnc"].as<double>();
-	    if (value["min"]) minv = value["min"].as<double>();
-	    if (value["max"]) maxv = value["max"].as<double>();
-	    // Goes to fortran
-	    addexternalparam_(p_name.c_str(),  val, step, minv, maxv,
-			      priorVal, priorUnc, add, &dMap, p_name.size());
-	  }
-	  else {
-	    // no step or value, store as it is as a yaml node:
-	    yMap[p_name] = value;
-	  }
-	}
-	
-	else if (value.IsSequence() ) {
-	  size_t len = value.size();
-	  vector<double> v(len);
-	  for (size_t i=0; i<len; i++) {
-	    v[i] = value[i].as<double>();
-	  }
-	  vMap[p_name] = v;
-	}
-      }	  
+    // Check if this is a minimisation block, true if step is present
+    if (value["step"] || value["value"]) {  
+      // Defaults
+      double val = 0;
+      double step = 0;
+      double minv  = 0;
+      double maxv  = 0;
+      double priorVal = 0;
+      double priorUnc = 0;
+      int add = true;
+      
+      if (value["value"]) {
+        val = value["value"].as<double>();
+      }
+      else {
+        string text = "F: missing value field for parameter " + p_name;
+        hf_errlog_(17032401,text.c_str(),text.size());       
+      }
+      if (value["step"]) step = value["step"].as<double>();
+      if (value["prior"]) priorVal = value["prior"].as<double>();
+      if (value["priorUnc"]) priorUnc = value["priorUnc"].as<double>();
+      if (value["min"]) minv = value["min"].as<double>();
+      if (value["max"]) maxv = value["max"].as<double>();
+      // Goes to fortran
+      addexternalparam_(p_name.c_str(),  val, step, minv, maxv,
+            priorVal, priorUnc, add, &dMap, p_name.size());
+    }
+    else {
+      // no step or value, store as it is as a yaml node:
+      yMap[p_name] = value;
+    }
+  }
+  
+  else if (value.IsSequence() ) {
+    size_t len = value.size();
+    vector<double> v(len);
+    for (size_t i=0; i<len; i++) {
+      v[i] = value[i].as<double>();
+    }
+    vMap[p_name] = v;
+  }
+      }   
     }
   }
 
@@ -304,10 +340,116 @@ namespace XFITTER_PARS {
   const std::function<void(double const& x, double const& Q, double* pdfs)>  retrieveXfxQArray(const std::string& name) {
     return gXfxQArrays.at(name);
   }
+  void createParameters(){
+    using namespace std;
+    try{
+      YAML::Node parsNode=rootNode["Parameters"];
+      if(!parsNode.IsMap()){
+        hf_errlog(18091710,"F: Failed to create parameters: bad \"Parameters\" YAML node");
+      }
+      xfitter::BaseMinimizer*minimizer=xfitter::get_minimizer();
+      for(YAML::const_iterator it=parsNode.begin();it!=parsNode.end();++it){
+        string parameterName=it->first.as<string>();
+        double value=nan("");
+        double step=nan("");
+        double min=nan("");
+        double max=nan("");
+        double pr_mean=nan("");
+        double pr_sigma=nan("");
+        //TODO: bounds and priors
+        YAML::Node pNode=it->second;
+        switch(pNode.Type()){
+          case YAML::NodeType::Scalar:{//Should be a special string DEPENDENT
+            string key=pNode.as<string>();
+            if(key=="DEPENDENT"){
+              value=1;
+              step=0;//This means that this parameter will be calculated using sum rules
+            }
+            else hf_errlog(18091712,"F: Bad parameter definition");
+            break;}
+          case YAML::NodeType::Sequence:{// interpret sequence as [value,step,min,max]
+            int size=pNode.size();
+            if(size>0)value=pNode[0].as<double>();
+            else break;
+            if(size>1)step=pNode[1].as<double>();
+            else break;
+            if(size>2)min=pNode[2].as<double>();
+            else break;
+            if(size>3)max=pNode[3].as<double>();
+            else break;
+            if(size>4)pr_mean=pNode[4].as<double>();
+            else break;
+            if(size>5)pr_sigma=pNode[5].as<double>();
+            else break;
+            if(size>6){
+              cerr<<"[ERROR] Too many arguments("<<size<<") in definition of parameter "<<parameterName<<"; expected at most 6"<<endl;
+              hf_errlog(18091716,"F: Too many arguments in parameter definition, see stderr");
+            }
+            break;}
+          case YAML::NodeType::Map:{
+            for(YAML::const_iterator it=pNode.begin();it!=pNode.end();++it){
+              string key=it->first.as<string>();
+              if   (key=="value")value=it->second.as<double>();
+              else if(key=="step")step=it->second.as<double>();
+              else if(key=="min")min=it->second.as<double>();
+              else if(key=="max")max=it->second.as<double>();
+              else if(key=="pr_mean")pr_mean=it->second.as<double>();
+              else if(key=="pr_sigma")pr_sigma=it->second.as<double>();
+              else{
+                cerr<<"[ERROR] Unknown key "<<key<<" in definition of parameter "<<parameterName<<endl;
+                hf_errlog(18091711,"F: Unknown key in parameter definition, see stderr");
+              }
+            }
+            break;}
+          default:
+            hf_errlog(18091710,"F: Failed to parse parameters definition node, expected Sequence or Map");
+        }
+        if(std::isnan(value)){
+          value=1;
+          hf_errlog(18091713,"W: Initial value not given for a parameter, assuming 1.0");
+        }
+        if(std::isnan(step)||step<0){
+          step=fabs(value)*0.01;
+          hf_errlog(18091714,"W: Step not given for a parameter, assuming 1%");
+        }
+        if(std::isnan(min)^std::isnan(max)){
+          cerr<<"[ERROR] Only one of two bounds ("<<(std::isnan(min)?"upper":"lower")<<") is given for parameter "<<parameterName<<endl;
+          hf_errlog(18091715,"F: Only one of two bounds is given for one of parameters, see stderr");
+        }
+        if(std::isnan(pr_mean)^std::isnan(pr_sigma)){
+          if(std::isnan(pr_sigma)){
+            pr_sigma=1;
+            hf_errlog(18091716,"W: Prior mean value, but not sigma given for a parameter, assuming sigma=1.0");
+          }else{
+            cerr<<"[ERROR] Prior sigma value, but not prior mean fiven for parameter "<<parameterName<<endl;
+            hf_errlog(18091717,"F: Prior sigma value, but not mean given for a parameter, see stderr");
+          }
+        }
+        //Note that if we allocate memory here, it will never be freed
+        double*bounds=nullptr;
+        double*priors=nullptr;
+        if(!std::isnan(min)){
+          bounds=new double[2];
+          bounds[0]=min;
+          bounds[1]=max;
+        }
+        if(!std::isnan(pr_mean)){
+          priors=new double[2];
+          priors[0]=pr_mean;
+          priors[1]=pr_sigma;
+        }
+        minimizer->addParameter(value,parameterName,step,bounds,priors);
+      }
+    }catch(YAML::Exception&ex){
+      cerr<<"[ERROR] YAML exception:\n"<<ex.what()<<"\n[/ERROR]"<<endl;
+      hf_errlog(18091713,"F: YAML exception while creating parameters, details written to stderr");
+    }
+  }
 }
 
 void parse_params_(){
   XFITTER_PARS::parse_file("parameters.yaml");
+  XFITTER_PARS::createParameters();
   XFITTER_PARS::ParsToFortran();
 }
 
diff --git a/src/xfitter_steer.cc b/src/xfitter_steer.cc
index b0885a2a1..37a9bef06 100644
--- a/src/xfitter_steer.cc
+++ b/src/xfitter_steer.cc
@@ -13,8 +13,39 @@ using std::string;
 
 extern std::map<string,string> gReactionLibs;
 
-namespace xfitter {
+void*createDynamicObject(const string&classname,const string&instanceName){
+  //instantiate an object from a shared library
+  //Used to create evolution, decomposition, parameterisation, could be used to create minimizer
+  string libpath;
+  try{
+    libpath=PREFIX+string("/lib/")+gReactionLibs.at(classname);
+  }catch(const std::out_of_range&ex){
+    std::cerr<<"[ERROR] out_of_range in function "<<__func__<<":\n"<<ex.what()<<"\n[/ERROR]\n";
+    std::ostringstream s;
+    if(gReactionLibs.count(classname)==0){
+      s<<"F: Unknown dynamically loaded class \""<<classname<<"\"";
+      hf_errlog(18091901,s.str().c_str());
+    }
+    s<<"F: Unknown out_of_range exception in "<<__func__;
+    hf_errlog(18091902,s.str().c_str());
+  }
+  void*shared_library=dlopen(libpath.c_str(),RTLD_NOW);
+  //By the way, do we ever call dlclose? I don't think so... Maybe we should call it eventually. --Ivan Novikov
+  if(shared_library==NULL){
+    std::cerr<<"[ERROR] dlopen() error while trying to open shared library for class \""<<classname<<"\":\n"<<dlerror()<<"\n[/ERROR]"<<std::endl;
+    hf_errlog(18091900,"F:dlopen() error, see stderr");
+  }
+  //reset errors
+  dlerror();
+  void*create=dlsym(shared_library,"create");
+  if(create==NULL){
+    std::cerr<<"[ERROR] dlsym() failed to find \"create\" function for class \""<<classname<<"\":\n"<<dlerror()<<"\n[/ERROR]"<<std::endl;
+    hf_errlog(18091902,"F:dlsym() error, see stderr");
+  }
+  return((void*(*)(const char*))create)(instanceName.c_str());
+}
 
+namespace xfitter {
   BaseEvolution*get_evolution(string name){
     if(name=="")name=XFITTER_PARS::getDefaultEvolutionName();
     // Check if already present
@@ -30,65 +61,75 @@ namespace xfitter {
       hf_errlog(18082902,s.str().c_str());
     }
     string classname=classnameNode.as<string>();
-    string libname;
-    {auto it=gReactionLibs.find(classname);
-    if(it==gReactionLibs.end()){
-      std::ostringstream s;
-      s<<"F: Failed to get evolution \""<<name<<"\": unknown evolution class name \""<<classname<<"\"";
-      hf_errlog(18082903,s.str().c_str());
-    }
-    libname=it->second;
-    }
-    // load the library:
-    //dlopen may be called multiple times for the same library and should return the same handle each time
-    void*shared_library=dlopen((PREFIX+string("/lib/")+libname).c_str(),RTLD_NOW);
-    //By the way, do we ever call dlclose? I don't think so... Maybe we should call it eventually. --Ivan Novikov
-    if(shared_library==NULL){ 
-      std::cout<<dlerror()<<std::endl;      
-      hf_errlog(18071303,"F: Evolution shared library ./lib/"  + libname  +  " not present for evolution" + name + ". Check Reactions.txt file");
-    }
-    // reset errors
-    dlerror();
-
-    BaseEvolution*evolution=((create_evolution*)dlsym(shared_library,"create"))(name.c_str());
-
+    BaseEvolution*evolution=(BaseEvolution*)createDynamicObject(classname,name);
     //Note that unlike in the pervious version of this function, we do not set decompositions for evolutions
     //Evolution objects are expected to get their decomposition themselves based on YAML parameters, during initAtStart
-
     evolution->initAtStart();
     // Store the newly created evolution on the global map
     XFITTER_PARS::gEvolutions[name] = evolution;
     return evolution;
   }
   BasePdfDecomposition*get_pdfDecomposition(string name){
-    if(name=="")name=XFITTER_PARS::getDefaultDecompositionName();
-    auto it=XFITTER_PARS::gPdfDecompositions.find(name);
-    if(it!=XFITTER_PARS::gPdfDecompositions.end())return it->second;
-    // Load corresponding shared library:
-    //Note: apparently we store all shared lib names in the map gReactionLibs, whether the libs are for reaction or whatever else. This naming is misleading.
-    string libname = gReactionLibs[name];
-    if ( libname == "") {
-      hf_errlog(18072302,"F: Shared library for pdf decomposition "+name+" not found");
+    try{
+      if(name=="")name=XFITTER_PARS::getDefaultDecompositionName();
+      auto it=XFITTER_PARS::gPdfDecompositions.find(name);
+      if(it!=XFITTER_PARS::gPdfDecompositions.end())return it->second;
+      string classname=XFITTER_PARS::getDecompositionNode(name)["class"].as<string>();
+      BasePdfDecomposition*ret=(BasePdfDecomposition*)createDynamicObject(classname,name);
+      ret->initAtStart();
+      XFITTER_PARS::gPdfDecompositions[name]=ret;
+      return ret;
+    }catch(YAML::InvalidNode&ex){
+      const int errcode=18092401;
+      const char*errmsg="F: YAML::InvalidNode exception while creating decomposition, details written to stderr";
+      using namespace std;
+      cerr<<"[ERROR]"<<__func__<<'('<<name<<')'<<endl;
+      YAML::Node node=XFITTER_PARS::getDecompositionNode(name);
+      if(!node.IsMap()){
+        cerr<<"Invalid node Decompositions/"<<name<<"\nnode is not a map\n[/ERROR]"<<endl;
+        hf_errlog(errcode,errmsg);
+      }
+      YAML::Node node_class=node["class"];
+      if(!node_class.IsScalar()){
+        if(node_class.IsNull())cerr<<"Missing node Decompositions/"<<name<<"/class";
+        else cerr<<"Invalid node Decompositions/"<<name<<"/class\nnode is not a scalar";
+        cerr<<"\n[/ERROR]"<<endl;
+        hf_errlog(errcode,errmsg);
+      }
+      cerr<<"Unexpected YAML exception\nNode:\n"<<node<<"\n[/ERROR]"<<endl;
+      hf_errlog(errcode,errmsg);
     }
-
-    // load the library:
-    void *pdfDecomposition_handler = dlopen((PREFIX+string("/lib/")+libname).c_str(), RTLD_NOW);
-    if (pdfDecomposition_handler == NULL)  { 
-      std::cout  << dlerror() << std::endl;      
-      hf_errlog(18072303,"F: PdfDecomposition shared library ./lib/"  + libname  +  " not present for pdfDecomposition" + name + ". Check Reactions.txt file");
+  }
+  BasePdfParam*getParameterisation(const string&name){
+    try{
+      auto it=XFITTER_PARS::gParameterisations.find(name);
+      if(it!=XFITTER_PARS::gParameterisations.end())return it->second;
+      //Else create a new instance
+      string classname=XFITTER_PARS::getParameterisationNode(name)["class"].as<string>();
+      BasePdfParam*ret=(BasePdfParam*)createDynamicObject(classname,name);
+      ret->initAtStart();
+      XFITTER_PARS::gParameterisations[name]=ret;
+      return ret;
+    }catch(YAML::InvalidNode&ex){
+      const int errcode=18092400;
+      const char*errmsg="F: YAML::InvalidNode exception while creating parameterisation, details written to stderr";
+      using namespace std;
+      cerr<<"[ERROR]"<<__func__<<'('<<name<<')'<<endl;
+      YAML::Node node=XFITTER_PARS::getParameterisationNode(name);
+      if(!node.IsMap()){
+        cerr<<"Invalid node Parameterisations/"<<name<<"\nnode is not a map\n[/ERROR]"<<endl;
+        hf_errlog(errcode,errmsg);
+      }
+      YAML::Node node_class=node["class"];
+      if(!node_class.IsScalar()){
+        if(node_class.IsNull())cerr<<"Missing node Parameterisations/"<<name<<"/class";
+        else cerr<<"Invalid node Parameterisations/"<<name<<"/class\nnode is not a scalar";
+        cerr<<"\n[/ERROR]"<<endl;
+        hf_errlog(errcode,errmsg);
+      }
+      cerr<<"Unexpected YAML exception\nNode:\n"<<node<<"\n[/ERROR]"<<endl;
+      hf_errlog(errcode,errmsg);
     }
-
-         // reset errors
-    dlerror();
-
-    create_pdfDecomposition *dispatch_decomp = (create_pdfDecomposition*) dlsym(pdfDecomposition_handler, "create");
-    BasePdfDecomposition *pdfDecomp = dispatch_decomp();
-    pdfDecomp->initAtStart("");
-
-    // store on the map
-    XFITTER_PARS::gPdfDecompositions[name] = pdfDecomp;
-
-    return pdfDecomp;
   }
 
 
-- 
GitLab


From 84ef8b37e023c0687ea6ea651a11e8e8cebeebf5 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Tue, 25 Sep 2018 15:31:23 +0200
Subject: [PATCH 25/26] Parameters.yaml for HERA data as an example

---
 parameters.yaml     | 266 +++++++++++++++++++++++++++++++-------------
 src/xfitter_pars.cc |   2 +-
 2 files changed, 190 insertions(+), 78 deletions(-)

diff --git a/parameters.yaml b/parameters.yaml
index 047a129cf..28adb9bf5 100644
--- a/parameters.yaml
+++ b/parameters.yaml
@@ -1,31 +1,75 @@
-Minimizer: MINUIT
-
-SU3_PionPdfDecomposition:
-  HARDWIRED_PolySqrt: #=A*x^B*(1-x)^C*(1+D*sqrt(x)+E*x)
-    v: [0.    , 0.6817,0.9794]
-    S: [0.0818,-0.2 ,8]
-    g: [0.    , 0   ,9]
-
-Q0: 1.378404875209022   #=sqrt(1.9)
-alphas: 0.118 #0.100
-
+Minimizer: MINUIT # CERES
 MINUIT:
-  doErrors: None #Pumplin #Hesse
   Commands: |
-    fix 106 107 108 109
+    fix 6 7 9 11 12 13 14 15 16 17 18 19 20 22 
     call fcn 3
-    #minimize
-    #hesse
-    #fix 103 106 107 109 111 112 113 114 115 116 117 118 119 120 122
+#  doErrors :  Hesse # None
+ #value    step    min     max       priors
+Parameters:
+  Ag   :  DEPENDENT
+  Bg   : [-0.061953]
+  Cg   : [ 5.562367,  0.55]
+  Auv  :  DEPENDENT
+  Buv  : [ 0.810476]
+  Cuv  : [ 4.823512]
+  Duv  : [    0    ]
+  Euv  : [ 9.921366]
+  Adv  :  DEPENDENT
+  Bdv  : [ 1.029995]
+  Cdv  : [ 4.846279]
+  Aubar: [ 0.27    ]
+  Bubar: [-0.13    ]
+  Cubar: [ 7.059694]
+  Dubar: [ 1.548098]
+  Adbar: [ 0.27    ]
+  Bdbar: [-0.13    ]
+  Cdbar:
+    value: 9.586246
+    step: 1.2345
+    #min
+    #max
+    #pr_mean
+    #pr_sigma
+  As   : [ 0.13    ]
+  Bs   : [ 0       ]
+  Cs   : [10.0     ]
 
-#New syntax
-#DefaultDecomposition: SU3_PionPdfDecomposition
-DefaultEvolution: pion #if this is not set, default evolution's name is "default"
+Parameterisations:
+  par_uv:
+    class: HERAPDF
+    parameters: [Auv,Buv,Cuv,Duv,Euv]
+  par_dv:
+    class: HERAPDF
+    parameters: [Adv,Bdv,Cdv]
+  par_ubar:
+    class: HERAPDF
+    parameters: [Aubar,Bubar,Cubar,Dubar]
+  par_dbar:
+    class: HERAPDF
+    parameters: [Adbar,Bdbar,Cdbar]
+  par_s:
+    class: HERAPDF
+    parameters: [As,Bs,Cs]
+  par_g:
+    class: HERAPDF
+    parameters: [Ag,Bg,Cg]
 
+DefaultDecomposition: proton
+Decompositions:
+  proton:
+    class: UvDvubardbars
+    xuv: par_uv
+    xdv: par_dv
+    xubar: par_ubar
+    xdbar: par_dbar
+    xs: par_s
+    xg: par_g
+
+DefaultEvolution: proton-QCDNUM
 Evolutions:
-  pion:
+  proton-QCDNUM:
     class: QCDNUM
-    decomposition: SU3_PionPdfDecomposition #this could be omitted, as the default decomposition is set
+    decomposition: proton #this could be omitted, as the default decomposition is set
     xGrid   :   [9.9e-7, 0.01, 0.1, 0.4, 0.7]
     xGridW  :   [1,       2,     4,   8,  16]
     Q2Grid  :   [1.,  2.05e8 ]
@@ -35,73 +79,141 @@ Evolutions:
     Read_QCDNUM_Tables : 1
     SplineOrder : 2
     ICheck  :   0
-  tungsten_target:
-    class: LHAPDF
-    set:   nCTEQ15FullNuc_184_74
-    member: 0
-  reference_pion:
+  proton-LHAPDF:
     class: LHAPDF
-    set:   GRVPI0
+    set: "CT10"
     member: 0
-APPLgrid:
-#Error: these parameters are not read yet
-  evolution1: pion #this can be overwritten in the datafile
-  evolution2: tungsten_target
-  muF: 1.0
-  muR: 1.0
-  Order: NLO
-
-fs: 0.333333333333333
-
-#Profiler:
-#  alphas: [ 0.118, 0.119, 0.117 ]
-#  evolutions:
-#    proton:
-#      sets:    [  NNPDF31_nnlo_as_0118, CT10  ]
-#      members: [ [ 0, 1, end ], [0, 1, end] ]
-
-Mz: 91.1876
-Mw: 80.385
-Mh: 125.9
+
+#
+# Initial scale
+#---------------------------
+Q0 : 1.378404875209
+
+#
+# EW parameters
+#---------------------------
+Mz : 91.1876
+Mw : 80.385
+Mh : 125.9
 
 Wz : 2.4952
 Ww : 2.085
 Wh : 1d-3
-Wtp: 2.0d0
-
-gf: 1.16638e-5
-convFac: 0.389379338e9
-alphaem: 7.29735e-3
-
-sin2thW:  0.23127
-Vud: 0.97427
-Vus: 0.2254
-Vub: 0.00358
-Vcd: 0.22520
-Vcs: 0.97344 
-Vcb: 0.04156
-Vtd: 0.00872
-Vts: 0.04076
-Vtb: 0.999133
+Wtp : 2.0d0
+
+gf : 1.16638e-5
+convFac : 0.389379338e9
+alphaem : 7.29735e-3
+
+sin2thW :  0.23127
+Vud : 0.97427
+Vus : 0.2254
+Vub : 0.00358
+Vcd : 0.22520
+Vcs : 0.97344 
+Vcb : 0.04156
+Vtd : 0.00872
+Vts : 0.04076
+Vtb : 0.999133
 
+#
 # lepton masses:
-men: 1e-10
-mel: 0.510998928e-3
-mmn: 1e-10
-mmo: 0.1056583715
-mtn: 1e-10
-mta: 1.77682
+#---------------------------
+men : 1e-10
+mel : 0.510998928e-3
+mmn : 1e-10
+mmo : 0.1056583715
+mtn : 1e-10
+mta : 1.77682
 
+#
 # Light quark masses:
-mup: 0.06983
-mdn: 0.06983
-mst: 0.150
+#---------------------------
+mup : 0.06983
+mdn : 0.06983
+mst : 0.150
 
+#
 # Heavy quark masses:
-mch: 1.43 
-mbt: 4.50
-mtp: 173.0
+#---------------------------
+mch : 1.43 
+mbt : 4.50
+mtp : 173.0
 
+#
 # QCD parameters
-Order: NLO
-NFlavour: 5
+#---------------------------
+Order :   NNLO
+NFlavour : 5
+
+#
+# AlphaS, incuding options to fit it:
+#---------------------------
+alphas : 0.118
+#  value: 0.118
+#  step:  0.01
+#  prior: 0.118
+#  priorUnc: 0.1
+#  min: 0.1
+#  max: 0.3
+
+# Strange and charm fractions:
+#---------------------------
+fs: 0.4
+fcharm: 0.
+
+#
+# RT DIS scheme settings:
+#---------------------------
+include : yaml/reactions/RT_DISNC/parameters.yaml
+#
+# FONLL scheme settings:
+#---------------------------
+include : yaml/reactions/FONLL_DISNC/parameters.yaml
+include : yaml/reactions/FONLL_DISCC/parameters.yaml
+
+#
+# FF ABM scheme settings:
+#---------------------------
+include : yaml/reactions/FFABM_DISNC/parameters.yaml
+include : yaml/reactions/FFABM_DISCC/parameters.yaml
+
+#
+# APPLgrid settings:
+#---------------------------
+include : yaml/reactions/APPLgrid/parameters.yaml
+
+#
+# (optional) Fractal module settings:
+#---------------------------
+# include : yaml/reactions/Fractal_DISNC/parameters.yaml
+
+#
+# Speficify HF scheme used for DIS NC processes:
+#---------------------------
+hf_scheme_DISNC :
+#  defaultValue : 'BaseDISNC'       # global specification
+  defaultValue : 'RT_DISNC'        # global specification
+#  defaultValue : 'FONLL_DISNC'     # global specification
+#  defaultValue : 'FFABM_DISNC'
+#  'HERA1+2 NCep 920' : 'BaseDISNC' # datafile specific (based on name)
+#  1 : BaseDISNC
+#  'HERA1+2 NCep 920' : 'Fractal_DISNC'  # Fractal model. Add parameters file if you want to try it (see above)
+
+#
+# Speficify HF scheme used for DIS CC processes:
+#---------------------------
+hf_scheme_DISCC :
+  defaultValue : 'BaseDISCC'       # global specification
+#  defaultValue : 'FONLL_DISCC'     # global specification
+#  defaultValue : 'FFABM_DISCC'     # global specification
+
+#
+# Load APFEL++
+#---------------------------
+include : yaml/evolutions/APFELxx/parameters.yaml
+
+#
+# Load QCDNUM
+#---------------------------
+include : yaml/evolutions/QCDNUM/parameters.yaml
diff --git a/src/xfitter_pars.cc b/src/xfitter_pars.cc
index 5985e3221..bfcf0765d 100644
--- a/src/xfitter_pars.cc
+++ b/src/xfitter_pars.cc
@@ -343,7 +343,7 @@ namespace XFITTER_PARS {
   void createParameters(){
     using namespace std;
     try{
-      YAML::Node parsNode=rootNode["Parameters"];
+      YAML::Node parsNode=gParametersY["Parameters"];
       if(!parsNode.IsMap()){
         hf_errlog(18091710,"F: Failed to create parameters: bad \"Parameters\" YAML node");
       }
-- 
GitLab


From 3a46a3a89ec573df91a61dbd03faa1ab0cb5d995 Mon Sep 17 00:00:00 2001
From: Ivan Novikov <novivanya@yandex.ru>
Date: Wed, 26 Sep 2018 08:43:34 +0200
Subject: [PATCH 26/26] Rename initialization methods

---
 evolutions/APFELxx/include/EvolutionAPFELxx.h        |  4 ++--
 evolutions/APFELxx/src/EvolutionAPFELxx.cc           |  6 +++---
 evolutions/BaseEvolution/include/BaseEvolution.h     |  6 +++---
 evolutions/LHAPDF/include/EvolutionLHAPDF.h          |  4 ++--
 evolutions/LHAPDF/src/EvolutionLHAPDF.cc             |  6 +++---
 evolutions/QCDNUM/include/EvolutionQCDNUM.h          |  6 +++---
 evolutions/QCDNUM/src/EvolutionQCDNUM.cc             |  8 ++++----
 include/ReactionTheory.h                             |  2 ++
 minimizers/BaseMinimizer/include/BaseMinimizer.h     |  4 ++--
 minimizers/CERESMinimizer/include/CERESMinimizer.h   |  2 +-
 minimizers/CERESMinimizer/src/CERESMinimizer.cc      |  2 +-
 minimizers/MINUITMinimizer/include/MINUITMinimizer.h |  2 +-
 minimizers/MINUITMinimizer/src/MINUITMinimizer.cc    |  2 +-
 .../include/BasePdfDecomposition.h                   |  6 +++---
 .../include/LHAPDFDecomposition.h                    |  2 +-
 .../LHAPDFDecomposition/src/LHAPDFDecomposition.cc   |  4 ++--
 .../include/SU3_PionPdfDecomposition.h               |  4 ++--
 .../src/SU3_PionPdfDecomposition.cc                  |  4 ++--
 .../UvDvUbarDbarS/include/UvDvUbarDbarS.h            |  4 ++--
 pdfdecompositions/UvDvUbarDbarS/src/UvDvUbarDbarS.cc |  4 ++--
 pdfparams/BasePdfParam/include/BasePdfParam.h        |  2 +-
 pdfparams/BasePdfParam/src/BasePdfParam.cc           |  2 +-
 src/ReactionTheory.cc                                |  2 +-
 src/ftheor_eval.cc                                   |  4 ++--
 src/xfitter_steer.cc                                 | 12 ++++++------
 25 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/evolutions/APFELxx/include/EvolutionAPFELxx.h b/evolutions/APFELxx/include/EvolutionAPFELxx.h
index 03a54fd12..563866dce 100644
--- a/evolutions/APFELxx/include/EvolutionAPFELxx.h
+++ b/evolutions/APFELxx/include/EvolutionAPFELxx.h
@@ -30,8 +30,8 @@ namespace xfitter
     /**
      * @brief Function that initialises the evolution in APFEL++.
      */
-    virtual void initAtStart()override final;
-    virtual void initAtParameterChange()override final;
+    virtual void atStart()override final;
+    virtual void atConfigurationChange()override final;
 
     /**
      * @name Getters
diff --git a/evolutions/APFELxx/src/EvolutionAPFELxx.cc b/evolutions/APFELxx/src/EvolutionAPFELxx.cc
index 25d120b7f..bdc18aea1 100644
--- a/evolutions/APFELxx/src/EvolutionAPFELxx.cc
+++ b/evolutions/APFELxx/src/EvolutionAPFELxx.cc
@@ -17,7 +17,7 @@ namespace xfitter
 
 
   //_________________________________________________________________________________
-  void EvolutionAPFELxx::initAtStart()
+  void EvolutionAPFELxx::atStart()
   {
     // APFEL++ banner
     apfel::Banner();
@@ -44,11 +44,11 @@ namespace xfitter
 
     // Initialize QCD evolution objects
     _DglapObj = apfel::InitializeDglapObjectsQCD(*_Grid, _Masses, _Thresholds);
-    initAtParameterChange();
+    atConfigurationChange();
   }
 
   //_________________________________________________________________________________
-  void EvolutionAPFELxx::initAtParameterChange()
+  void EvolutionAPFELxx::atConfigurationChange()
   {
     const YAML::Node yamlNode=XFITTER_PARS::getEvolutionNode(_name);
     // Retrieve the relevant parameters needed to compute the evolutions
diff --git a/evolutions/BaseEvolution/include/BaseEvolution.h b/evolutions/BaseEvolution/include/BaseEvolution.h
index b9180d17b..a1feedfe3 100644
--- a/evolutions/BaseEvolution/include/BaseEvolution.h
+++ b/evolutions/BaseEvolution/include/BaseEvolution.h
@@ -35,17 +35,17 @@ namespace xfitter
      *
      * This function is called only once
      */
-    virtual void initAtStart(){};
+    virtual void atStart(){};
 
     /**
      * @brief Function to be called at each iteration
      */
-    virtual void initAtIteration(){};
+    virtual void atIteration(){};
 
     /**
      * @brief This function should be called when at least one parameter in the YAML node of given evolution changes
      */
-    virtual void initAtParameterChange(){};
+    virtual void atConfigurationChange(){};
 
     /**
      * @name Getters
diff --git a/evolutions/LHAPDF/include/EvolutionLHAPDF.h b/evolutions/LHAPDF/include/EvolutionLHAPDF.h
index cd52acac5..89c093587 100644
--- a/evolutions/LHAPDF/include/EvolutionLHAPDF.h
+++ b/evolutions/LHAPDF/include/EvolutionLHAPDF.h
@@ -30,9 +30,9 @@ class EvolutionLHAPDF : BaseEvolution
 
   public:
   /// Global initialization
-    virtual void initAtStart() override final;
+    virtual void atStart() override final;
   /// Init at each change of at least one parameter
-    virtual void initAtParameterChange() override final;  
+    virtual void atConfigurationChange() override final;  
 
   /// Return PDFs as a map <int,double> where int is PDF ID (-6, ... 6, 21)   
     virtual std::function<std::map<int,double>(double const& x, double const& Q)> xfxQMap() override final;
diff --git a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
index 118d78440..e9c613c04 100644
--- a/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
+++ b/evolutions/LHAPDF/src/EvolutionLHAPDF.cc
@@ -25,12 +25,12 @@ const char*EvolutionLHAPDF::getClassName()const{return "LHAPDF";}
 
     
 /// Global initialization
-  void EvolutionLHAPDF::initAtStart() {
+  void EvolutionLHAPDF::atStart() {
     YAML::Node pars=XFITTER_PARS::getEvolutionNode(_name);
     try{
       _set_name = pars["set"].as<std::string>();
     }catch(YAML::TypedBadConversion<std::string>&ex){
-      hf_errlog(18090310,"F: In EvolutionLHAPDF::initAtStart: failed to convert YAML node \"set\" to string; printing node to stderr");
+      hf_errlog(18090310,"F: In EvolutionLHAPDF::atStart: failed to convert YAML node \"set\" to string; printing node to stderr");
       std::cerr<<pars<<std::endl;
     }
 
@@ -42,7 +42,7 @@ const char*EvolutionLHAPDF::getClassName()const{return "LHAPDF";}
  };
     
   /// Init at each iteration
-  void EvolutionLHAPDF::initAtParameterChange() {
+  void EvolutionLHAPDF::atConfigurationChange() {
     YAML::Node pars=XFITTER_PARS::getEvolutionNode(_name);
     //TODO: check for errors while parsing YAML
     _set_name = pars["set"].as<std::string>();
diff --git a/evolutions/QCDNUM/include/EvolutionQCDNUM.h b/evolutions/QCDNUM/include/EvolutionQCDNUM.h
index 6d4d84479..646d09af4 100644
--- a/evolutions/QCDNUM/include/EvolutionQCDNUM.h
+++ b/evolutions/QCDNUM/include/EvolutionQCDNUM.h
@@ -26,9 +26,9 @@ namespace xfitter
     EvolutionQCDNUM(const char*name):BaseEvolution{name}{};
 
     virtual const char*getClassName()const override final;
-    virtual void initAtStart()override final;
-    virtual void initAtIteration()override final;
-    virtual void initAtParameterChange()override final;
+    virtual void atStart()override final;
+    virtual void atIteration()override final;
+    virtual void atConfigurationChange()override final;
     virtual std::function<std::map<int,double>(double const& x, double const& Q)> xfxQMap()  override final;
     virtual std::function<void(double const& x, double const& Q, double* pdfs)> xfxQArray() override final;
     virtual std::function<double(int const& i, double const& x, double const& Q)> xfxQDouble() override final;
diff --git a/evolutions/QCDNUM/src/EvolutionQCDNUM.cc b/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
index 21ea5693b..3855a334d 100644
--- a/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
+++ b/evolutions/QCDNUM/src/EvolutionQCDNUM.cc
@@ -64,7 +64,7 @@ namespace xfitter
   const char*EvolutionQCDNUM::getClassName()const{return "QCDNUM";}
 
   // Initialize at the start of the computation
-  void EvolutionQCDNUM::initAtStart()
+  void EvolutionQCDNUM::atStart()
   {
     QCDNUM::qcinit(6," ");
 
@@ -180,10 +180,10 @@ namespace xfitter
        
     //Evolution gets its decomposition from YAML
     gPdfDecomp=XFITTER_PARS::getInputFunctionFromYaml(yQCDNUM);
-    initAtParameterChange();
+    atConfigurationChange();
   }
 
-  void EvolutionQCDNUM::initAtParameterChange()
+  void EvolutionQCDNUM::atConfigurationChange()
   {
     // XXXXXXXXXXXXXX
 
@@ -192,7 +192,7 @@ namespace xfitter
     
     QCDNUM::setalf(*alphas,(*Mz)*(*Mz));
   }
-  void EvolutionQCDNUM::initAtIteration(){
+  void EvolutionQCDNUM::atIteration(){
     const double* q0 = XFITTER_PARS::gParameters.at("Q0");
     int iq0  = QCDNUM::iqfrmq( (*q0) * (*q0) );
     double epsi = 0;
diff --git a/include/ReactionTheory.h b/include/ReactionTheory.h
index 394b7e7a2..01facec83 100644
--- a/include/ReactionTheory.h
+++ b/include/ReactionTheory.h
@@ -60,6 +60,7 @@ class ReactionTheory
   using super = ReactionTheory;
   
   virtual string getReactionName() const =0;  ///< Should return expected reaction name. Normally generated automatically by AddReaction.py
+  //A better name would be atStart
   virtual int  initAtStart(const string &) =0; ///< Initialization first time ReactionTheory implementation is called
 
   virtual void setxFitterParameters(map<string,double*> &xfitter_pars) {_xfitter_pars = xfitter_pars; }; ///< Set environment map for doubles
@@ -81,6 +82,7 @@ class ReactionTheory
 
 
   /// Perform optional re-initialization for a given iteration. Interface for old-style pdf functions 
+  //A better name would be atIteration
   virtual void initAtIteration(); 
 
   //! Perform optional action when minuit fcn 3 is called (normally after fit)
diff --git a/minimizers/BaseMinimizer/include/BaseMinimizer.h b/minimizers/BaseMinimizer/include/BaseMinimizer.h
index 5002a47f0..f76069a31 100644
--- a/minimizers/BaseMinimizer/include/BaseMinimizer.h
+++ b/minimizers/BaseMinimizer/include/BaseMinimizer.h
@@ -25,7 +25,7 @@ namespace xfitter
 	{}
 
     /// Initialization
-    virtual void initAtStart() = 0;
+    virtual void atStart() = 0;
 
     /// Provide some information
     virtual void printInfo(){};
@@ -41,7 +41,7 @@ namespace xfitter
     virtual void addParameter(double par, std::string const &name, double step = 0.01, double const* bounds = nullptr, double  const* priors = nullptr );
     
     /// Action at each iteration
-    virtual void initAtIteration(){};
+    virtual void atIteration(){};
 
     /// Miniminzation loop
     virtual void doMimimization() = 0;
diff --git a/minimizers/CERESMinimizer/include/CERESMinimizer.h b/minimizers/CERESMinimizer/include/CERESMinimizer.h
index bb16c1695..fe95f48cf 100644
--- a/minimizers/CERESMinimizer/include/CERESMinimizer.h
+++ b/minimizers/CERESMinimizer/include/CERESMinimizer.h
@@ -25,7 +25,7 @@ namespace xfitter {
     CERESMinimizer (const std::string& inName);
     
     /// Optional initialization at the first call
-    virtual void initAtStart() override final;
+    virtual void atStart() override final;
 
     /// Miniminzation loop
     virtual void doMimimization() override final;
diff --git a/minimizers/CERESMinimizer/src/CERESMinimizer.cc b/minimizers/CERESMinimizer/src/CERESMinimizer.cc
index b9bef0b90..7ae82228b 100644
--- a/minimizers/CERESMinimizer/src/CERESMinimizer.cc
+++ b/minimizers/CERESMinimizer/src/CERESMinimizer.cc
@@ -81,7 +81,7 @@ CERESMinimizer::CERESMinimizer(const std::string& inName) : BaseMinimizer(inName
 }
 
 // Init at start:
-void CERESMinimizer::initAtStart() {
+void CERESMinimizer::atStart() {
 	//There's a suppressed warning here
 	//warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   google::InitGoogleLogging((char*)"");
diff --git a/minimizers/MINUITMinimizer/include/MINUITMinimizer.h b/minimizers/MINUITMinimizer/include/MINUITMinimizer.h
index 32057c9ec..d34c06f82 100644
--- a/minimizers/MINUITMinimizer/include/MINUITMinimizer.h
+++ b/minimizers/MINUITMinimizer/include/MINUITMinimizer.h
@@ -24,7 +24,7 @@ class MINUITMinimizer : public BaseMinimizer
     MINUITMinimizer (const std::string& inName);
 
     /// Optional initialization at the first call
-    virtual void initAtStart() override final;
+    virtual void atStart() override final;
 
     /// Miniminzation loop
     virtual void doMimimization() override final;
diff --git a/minimizers/MINUITMinimizer/src/MINUITMinimizer.cc b/minimizers/MINUITMinimizer/src/MINUITMinimizer.cc
index 53c8c42f9..60bd9928b 100644
--- a/minimizers/MINUITMinimizer/src/MINUITMinimizer.cc
+++ b/minimizers/MINUITMinimizer/src/MINUITMinimizer.cc
@@ -91,7 +91,7 @@ MINUITMinimizer::MINUITMinimizer(const std::string& inName) : BaseMinimizer(inNa
 }
 
 // Init at start:
-void MINUITMinimizer::initAtStart() {
+void MINUITMinimizer::atStart() {
   // Call fortran interface
   generate_io_filenames_();
   minuit_ini_();
diff --git a/pdfdecompositions/BasePdfDecomposition/include/BasePdfDecomposition.h b/pdfdecompositions/BasePdfDecomposition/include/BasePdfDecomposition.h
index 298b31454..7b99701bc 100644
--- a/pdfdecompositions/BasePdfDecomposition/include/BasePdfDecomposition.h
+++ b/pdfdecompositions/BasePdfDecomposition/include/BasePdfDecomposition.h
@@ -28,11 +28,11 @@ namespace xfitter
     virtual ~BasePdfDecomposition(){}
     
     /// Initialization at the first call
-    virtual void initAtStart(){}
+    virtual void atStart(){}
     /// Optional initialization at each iteration. Can be used to compute sum-rules
-    virtual void initAtIteration(){}
+    virtual void atIteration(){}
     /// This function should be called when at least one parameter in the YAML node of given decomposition changes
-    virtual void initAtParameterChange(){}
+    virtual void atConfigurationChange(){}
 
     /// Print pdf parameters
     //This shouldn't be here, printing parameters should be just a global function --Ivan
diff --git a/pdfdecompositions/LHAPDFDecomposition/include/LHAPDFDecomposition.h b/pdfdecompositions/LHAPDFDecomposition/include/LHAPDFDecomposition.h
index b95df4abf..0700d5d96 100644
--- a/pdfdecompositions/LHAPDFDecomposition/include/LHAPDFDecomposition.h
+++ b/pdfdecompositions/LHAPDFDecomposition/include/LHAPDFDecomposition.h
@@ -29,7 +29,7 @@ namespace xfitter
     virtual const char*getClassName()const override final;
 
     /// Optional initialization at the first call
-    virtual void initAtStart()override final;
+    virtual void atStart()override final;
 
     /// Compute PDF in a physical basis in LHAPDF format at the initial scale
     virtual std::function<std::map<int,double>(const double& x)> f0() const override final;
diff --git a/pdfdecompositions/LHAPDFDecomposition/src/LHAPDFDecomposition.cc b/pdfdecompositions/LHAPDFDecomposition/src/LHAPDFDecomposition.cc
index fe09f9b42..946385d1a 100644
--- a/pdfdecompositions/LHAPDFDecomposition/src/LHAPDFDecomposition.cc
+++ b/pdfdecompositions/LHAPDFDecomposition/src/LHAPDFDecomposition.cc
@@ -20,14 +20,14 @@ namespace xfitter {
   LHAPDFDecomposition::LHAPDFDecomposition(const char*name):BasePdfDecomposition{name}{}
   LHAPDFDecomposition::~LHAPDFDecomposition(){if(_pdf)delete _pdf;}
   const char*LHAPDFDecomposition::getClassName()const{return"LHAPDF";}
-  void LHAPDFDecomposition::initAtStart(){
+  void LHAPDFDecomposition::atStart(){
     YAML::Node pars=XFITTER_PARS::getDecompositionNode(_name);
     string setName;
     int member;
     try{
       setName=pars["set"].as<std::string>();
     }catch(YAML::TypedBadConversion<std::string>&ex){
-      hf_errlog(18090310,"F: In LHAPDFDecomposition::initAtStart: failed to convert YAML node \"set\" to string; printing node to stderr");
+      hf_errlog(18090310,"F: In LHAPDFDecomposition::atStart: failed to convert YAML node \"set\" to string; printing node to stderr");
       std::cerr<<pars<<std::endl;
     }
 
diff --git a/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h b/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h
index d678078d0..010ba1c4e 100644
--- a/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h
+++ b/pdfdecompositions/SU3_PionPdfDecomposition/include/SU3_PionPdfDecomposition.h
@@ -29,8 +29,8 @@ class SU3_PionPdfDecomposition:public BasePdfDecomposition{
   public:
     SU3_PionPdfDecomposition(const char*name);
     virtual const char*getClassName()const override final;
-    virtual void initAtStart()override final;
-    virtual void initAtIteration()override final;
+    virtual void atStart()override final;
+    virtual void atIteration()override final;
     virtual std::function<std::map<int,double>(const double& x)>f0()const override final;
   private:
     BasePdfParam*par_v{nullptr},*par_S{nullptr},*par_g{nullptr};
diff --git a/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc b/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc
index d7bab883d..389d0de25 100644
--- a/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc
+++ b/pdfdecompositions/SU3_PionPdfDecomposition/src/SU3_PionPdfDecomposition.cc
@@ -33,14 +33,14 @@ BasePdfParam*getParam(const BasePdfDecomposition*self,const YAML::Node&node,cons
   return nullptr;//unreachable, suppress warning
 }
 // Init at start:
-void SU3_PionPdfDecomposition::initAtStart(){
+void SU3_PionPdfDecomposition::atStart(){
   const YAML::Node node=XFITTER_PARS::getDecompositionNode(_name);
   //get parameterisation usually doesn't throw
   par_v=getParam(this,node,"valence");
   par_S=getParam(this,node,"sea");
   par_g=getParam(this,node,"gluon");
 }
-void SU3_PionPdfDecomposition::initAtIteration() {
+void SU3_PionPdfDecomposition::atIteration() {
   //Enforce sum rules
   //Valence sum
   par_v->setMoment(-1,1);
diff --git a/pdfdecompositions/UvDvUbarDbarS/include/UvDvUbarDbarS.h b/pdfdecompositions/UvDvUbarDbarS/include/UvDvUbarDbarS.h
index bda3db877..ae93e7c95 100644
--- a/pdfdecompositions/UvDvUbarDbarS/include/UvDvUbarDbarS.h
+++ b/pdfdecompositions/UvDvUbarDbarS/include/UvDvUbarDbarS.h
@@ -24,10 +24,10 @@ namespace xfitter
     virtual const char*getClassName()const override final;
 
     /// Optional initialization at the first call
-    virtual void initAtStart()override final;
+    virtual void atStart()override final;
 
     /// Compute sum-rules
-    virtual void initAtIteration() override final;
+    virtual void atIteration() override final;
 
     /// print parameters
     virtual void printParams() override final;
diff --git a/pdfdecompositions/UvDvUbarDbarS/src/UvDvUbarDbarS.cc b/pdfdecompositions/UvDvUbarDbarS/src/UvDvUbarDbarS.cc
index b784102f2..630f3aed2 100644
--- a/pdfdecompositions/UvDvUbarDbarS/src/UvDvUbarDbarS.cc
+++ b/pdfdecompositions/UvDvUbarDbarS/src/UvDvUbarDbarS.cc
@@ -26,7 +26,7 @@ namespace xfitter
   const char*UvDvUbarDbarS::getClassName()const{return"UvDvUbarDbarS";}
 
   //_________________________________________________________________________________
-  void UvDvUbarDbarS::initAtStart(){
+  void UvDvUbarDbarS::atStart(){
     const YAML::Node node=XFITTER_PARS::getDecompositionNode(_name);
     //TODO: handle errors
     par_xuv  =getParameterisation(node["xuv"].as<string>());
@@ -37,7 +37,7 @@ namespace xfitter
     par_xg   =getParameterisation(node["xg"].as<string>());
   }
 
-  void UvDvUbarDbarS::initAtIteration() {
+  void UvDvUbarDbarS::atIteration() {
     //Enforce sum rules
     // counting sum-rules for uv and dv
     par_xuv->setMoment(-1,2.0);
diff --git a/pdfparams/BasePdfParam/include/BasePdfParam.h b/pdfparams/BasePdfParam/include/BasePdfParam.h
index 343711a13..2d4a82170 100644
--- a/pdfparams/BasePdfParam/include/BasePdfParam.h
+++ b/pdfparams/BasePdfParam/include/BasePdfParam.h
@@ -42,7 +42,7 @@ public:
   virtual void setMoment(int nMoment,double value);
   //!Get name of the instance
   const std::string getName()const{return _name;} 
-  virtual void initAtStart();
+  virtual void atStart();
 protected:
   //!Unique name of instance
   const std::string _name;
diff --git a/pdfparams/BasePdfParam/src/BasePdfParam.cc b/pdfparams/BasePdfParam/src/BasePdfParam.cc
index 63d0de5bd..468cf3883 100644
--- a/pdfparams/BasePdfParam/src/BasePdfParam.cc
+++ b/pdfparams/BasePdfParam/src/BasePdfParam.cc
@@ -58,7 +58,7 @@ void BasePdfParam::setMoment(int nMoment,double value){
   *pars[0]=1;
   *pars[0]=value/moment(nMoment);
 }
-void BasePdfParam::initAtStart(){
+void BasePdfParam::atStart(){
   using namespace std;
   YAML::Node node=XFITTER_PARS::getParameterisationNode(_name);
   YAML::Node parsNode=node["parameters"];
diff --git a/src/ReactionTheory.cc b/src/ReactionTheory.cc
index de598b91d..25ecd397d 100644
--- a/src/ReactionTheory.cc
+++ b/src/ReactionTheory.cc
@@ -62,7 +62,7 @@ void ReactionTheory::initAtIteration() {
 }
 
 const pXFXlike  ReactionTheory::getXFX(const string& type) {
-  //How is this different from initAtIteration?
+  //How is this different from atIteration?
 
   try{
     gProtonPdf = XFITTER_PARS::retrieveXfxQArray(_evolution);
diff --git a/src/ftheor_eval.cc b/src/ftheor_eval.cc
index cbd74af77..cf9a26679 100644
--- a/src/ftheor_eval.cc
+++ b/src/ftheor_eval.cc
@@ -311,13 +311,13 @@ void init_func_map_() {
 void init_at_iteration_() {
   
   for ( auto pdfdecomposition : XFITTER_PARS::gPdfDecompositions) {
-    pdfdecomposition.second->initAtIteration();
+    pdfdecomposition.second->atIteration();
   }
 
   
   for(auto it:XFITTER_PARS::gEvolutions) {
 		xfitter::BaseEvolution*evolution=it.second;
-    evolution->initAtIteration();
+    evolution->atIteration();
 
     // register updated PDF XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 		//Wait, do they even get updated between iterations? Is this here even necessary? --Ivan
diff --git a/src/xfitter_steer.cc b/src/xfitter_steer.cc
index 37a9bef06..22892010b 100644
--- a/src/xfitter_steer.cc
+++ b/src/xfitter_steer.cc
@@ -63,8 +63,8 @@ namespace xfitter {
     string classname=classnameNode.as<string>();
     BaseEvolution*evolution=(BaseEvolution*)createDynamicObject(classname,name);
     //Note that unlike in the pervious version of this function, we do not set decompositions for evolutions
-    //Evolution objects are expected to get their decomposition themselves based on YAML parameters, during initAtStart
-    evolution->initAtStart();
+    //Evolution objects are expected to get their decomposition themselves based on YAML parameters, during atStart
+    evolution->atStart();
     // Store the newly created evolution on the global map
     XFITTER_PARS::gEvolutions[name] = evolution;
     return evolution;
@@ -76,7 +76,7 @@ namespace xfitter {
       if(it!=XFITTER_PARS::gPdfDecompositions.end())return it->second;
       string classname=XFITTER_PARS::getDecompositionNode(name)["class"].as<string>();
       BasePdfDecomposition*ret=(BasePdfDecomposition*)createDynamicObject(classname,name);
-      ret->initAtStart();
+      ret->atStart();
       XFITTER_PARS::gPdfDecompositions[name]=ret;
       return ret;
     }catch(YAML::InvalidNode&ex){
@@ -107,7 +107,7 @@ namespace xfitter {
       //Else create a new instance
       string classname=XFITTER_PARS::getParameterisationNode(name)["class"].as<string>();
       BasePdfParam*ret=(BasePdfParam*)createDynamicObject(classname,name);
-      ret->initAtStart();
+      ret->atStart();
       XFITTER_PARS::gParameterisations[name]=ret;
       return ret;
     }catch(YAML::InvalidNode&ex){
@@ -159,7 +159,7 @@ namespace xfitter {
 
     create_minimizer *dispatch_minimizer = (create_minimizer*) dlsym(lib_handler, "create");
     BaseMinimizer *minimizer = dispatch_minimizer();
-    minimizer->initAtStart();
+    minimizer->atStart();
 
     // store on the map
     XFITTER_PARS::gMinimizer = minimizer;
@@ -184,7 +184,7 @@ void init_evolution_() {
 }
 
 void init_minimizer_() {
-  /// initAtStart is called inside
+  /// atStart is called inside
   auto mini = xfitter::get_minimizer();
 }
 
-- 
GitLab