title: Applgrid makefile (undefined reference)
body: <p>I've a question that could be naive for the experienced users, but I'm kinda stuck. I'm trying to get ApplGrid code working (<a href="https://applgrid.hepforge.org/index.htm" rel="nofollow">https://applgrid.hepforge.org/index.htm</a>), so I wish to run the provided examples.</p>
  
  <p>As far as I've understood, the dependencies are ROOT (root.cern.ch) and LHAPDF libraries (lhapdf.hepforge.org/index.html), which work well on my machine.
  The aforementioned examples were build to work with an older version of LHAPDF, so I had to change the name of an invoked method.
  When I try to make, I get an error regarding the undefined reference of that function, but if I isolate that instruction and execute with</p>
  
  <pre><code>g++ extract.cxx `lhapdf-config --cflags --ldflags`
  </code></pre>
  
  <p>it works like a charm.</p>
  
  <p>The output of the config command is:</p>
  
  <blockquote>
    <p>-I/home/matteo/software/gcc-4.7/lhapdf/install/include -I/home/matteo/software/gcc-4.7/boost/install/include -L/home/matteo/software/gcc-4.7/lhapdf/install/lib -lLHAPDF</p>
  </blockquote>
  
  <p>If I remove the "LHAPDF-related commands" from the original cxx file I can run "make" without any problem.</p>
  
  <p>As a final test, I've tried to isolate the "applgrid related code" and try to compile with:</p>
  
  <pre><code>g++ extract_2.cxx `applgrid-config --cxxflags --ldfflags`
  </code></pre>
  
  <p>but I get an undefined reference error.</p>
  
  <p>The output of the config command is:</p>
  
  <blockquote>
    <p>-I/home/matteo/software/gcc-4.7/applgrid/install/include -pthread -m64 -I/home/matteo/software/gcc-4.7/root/install/include -L/home/matteo/software/gcc-4.7/applgrid/install/lib -lfAPPLgrid -lAPPLgrid -m64 -L/home/matteo/software/gcc-4.7/root/install/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -L/home/matteo/software/gcc-4.7/hoppet/install/lib -lhoppet_v1</p>
  </blockquote>
  
  <p>the content of the makefile is the following:</p>
  
  <pre><code>CXX = g++
  F77 = gfortran
  
  FFLAGS   += -O3 -fPIC
  CXXFLAGS += -O3 -fPIC
  
  # root
  ROOTINCS = $(shell root-config --cflags)
  ROOTLIBS = $(shell root-config --glibs)
  ROOTARCH = $(findstring -m64, $(ROOTINCS) )
  
  #LHAPDF
  LHAPDFINCS = $(shell lhapdf-config --cflags)
  LHAPDFDIR  = $(shell lhapdf-config --libdir)
  LHAPDFLIBS = $(shell lhapdf-config --libs)
  
  # applgrid
  APPLCXXFLAGS = $(shell applgrid-config --cxxflags)
  APPLCLIBS    = $(shell applgrid-config --ldcflags)
  APPLFLIBS    = $(shell applgrid-config --ldflags)
  
  # hoppet
  HOPPETLIBS =  $(shell hoppet-config --libs)
  
  # get the fotran runtime library for linking fortran
  
  FRTLLIB = $(shell gfortran $(CXXFLAGS) -print-file-name=libgfortran.a)
  FRTLIB  = -L$(subst /libgfortran.a, ,$(FRTLLIB) ) -lgfortran
  
  # now set up the compile and link flags and libs
  CXXFLAGS += $(ROOTARCH) $(ROOTINCS) $(APPLCXXFLAGS) $(LHAPDFINCS)
  LDFLAGS  += $(ROOTARCH)
  FFLAGS   += $(ROOTARCH)
  
  CLIBS += $(ROOTLIBS) $(LHAPDFLIBS) $(HOPPETLIBS) $(APPLCLIBS)
  FLIBS += $(ROOTLIBS) $(LHAPDFLIBS) $(HOPPETLIBS) $(APPLFLIBS) $(APPLCLIBS) $(FRTLIB)
  
  install : all
  all : stand fnlo fstand getdata
  
  stand: stand.o
          $(CXX) $(LDFLAGS) -o $@ $&lt; $(CLIBS)
  
  
  fstand: fstand.o fmain.o
          $(CXX) $(LDFLAGS) -o $@ fstand.o fmain.o $(FLIBS)
  
  
  % : %.o
          $(CXX) $(LDFLAGS) -o $@ $&lt; $(CLIBS)
  
  fnlo: fnmain.o
          $(CXX) $(LDFLAGS) -o $@  $&lt;  $(CLIBS)
  
  
  .SUFFIXES : .cxx .o .f .c
  
  .f.o :
          $(F77) $(FFLAGS)   -c $&lt;
  
  .cxx.o:  
          $(CXX) $(CXXFLAGS) -c $&lt;
  
  
  #########################################################
  #  just type make getdata and it will download all
  #  the required data for these examples
  #########################################################
  
  .PRECIOUS : fnlodata appldata
  
  getdata : getfnlodata getappldata
  
  getfnlodata: fnl0004.tab
  fnl0004.tab:
          @ echo "\n************************\ndownloading fastnlo data\n************************\n"
          (curl http://fastnlo.hepforge.org/code/src/fnl0004.tab.gz | gunzip &gt; fnl0004.tab )
  
  getappldata: atlas-incljets-arxiv-1009.5908v2
  atlas-incljets-arxiv-1009.5908v2:
          @ echo "\n*************************************\n downloading atlas inclusive jet data\n***********************************\n"
          (curl http://www.hepforge.org/archive/applgrid/atlas-incljets-arxiv-1009.5908v2.tgz | tar -xzf - )
  
  clean:
          rm -rf ./.libs ./.obj *.lo *.o *.la stand fnlo fstand *~
  </code></pre>
  
  <p>while the other files in the directory are the following:</p>
  
  <p>fmain.cxx</p>
  
  <pre><code>extern "C" void fstand_();
  
  int main() { 
    fstand_();
    return 0
  </code></pre>
  
  <p>fnmain.cxx</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  #include "appl_grid/fastnlo.h"
  
  #include "TFile.h"
  #include "TH1D.h"
  
  
  // lhapdf routines
  #include "LHAPDF/LHAPDF.h"
  extern "C" void evolvepdf_(const double&amp; , const double&amp; , double* );
  extern "C" double alphaspdf_(const double&amp; Q);
  
  
  
  int main(int argc, char** argv) { 
  
    if ( argc&lt;2 ) { 
      std::cerr &lt;&lt; "usage: fnlo fastnlogrid.tab" &lt;&lt; std::endl;
      return -1;
    }
  
    std::cout &lt;&lt; "set up lhapdf..." &lt;&lt; std::endl;
  
    const std::string _pdfname = "cteq6mE.LHgrid";  
    int iset = 0;
    LHAPDF::initPDFSet( _pdfname, iset );
  
    // don't need to hard code, can use a runtime parameter...
    std::string gridname = argv[1];
    // std::string gridname = "fnt1007midp.tab";
    // std::string gridname = "fnt1008midp.tab";
    // std::string gridname = "fnt2004.tab";
    // std::string gridname = "fnl2004.tab";
  
    fastnlo f( gridname );
  
    std::vector&lt;appl::grid*&gt; g = f.grids(); 
  
    //  g.push_back( new appl::grid("atlas-incljets04-eta1.root") );
  
    /// histograms and file for seeing the results
    std::vector&lt;TH1D*&gt; hc(g.size());
    std::string foutname = "appl.root";
    TFile fout( foutname.c_str(),"recreate");
  
    for ( int i=0 ; i&lt;g.size() ; i++ ) { 
  
      // trim the grids (not actually needed, done in 
      // the fastnlo constructor
      g[i]-&gt;trim();
  
      char hname[64];
      sprintf(hname, "hist%02d", i);
  
      /// optionally print out the grid documentation  
      std::cout &lt;&lt; "\n" &lt;&lt; g[i]-&gt;getDocumentation() &lt;&lt; std::endl;
  
      /// perform the convolution
      hc[i] = g[i]-&gt;convolute( evolvepdf_, alphaspdf_ );
      hc[i]-&gt;SetName(hname);
      hc[i]-&gt;SetDirectory(&amp;fout);
      hc[i]-&gt;Write();
  
      /// print out the results
      for ( int j=1 ; j&lt;=hc[i]-&gt;GetNbinsX() ; j++ ) { 
        std::cout &lt;&lt; "xsec(" &lt;&lt; j-1 &lt;&lt; ")=" &lt;&lt; hc[i]-&gt;GetBinContent(j) &lt;&lt; std::endl;
      }
  
    }
  
    std::cout &lt;&lt; "writing file " &lt;&lt; foutname &lt;&lt; std::endl; 
    fout.Close();
  
    return 0;
  }
  
  }
  </code></pre>
  
  <p>fstand.f</p>
  
  <pre><code>C----------------------------------------------------------
  C     dummy routines that call  the pdf and alphas routines
  C     this example, they just call the lhapdf routine
  C     for apdf fit, call your own routines 
  C----------------------------------------------------------
        double precision function fnalphas(Q)
        double precision Q      
        double precision alphaspdf
        fnalphas = alphaspdf(Q)
        return
        end
  
        subroutine fnpdf(x, Q, xf)
        double precision x, Q      
        double precision xf(13)
        call evolvePDF(x, Q, xf)
        return
        end
  C----------------------------------------------------------
  </code></pre>
  
  <p>stand.cxx</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  #include "appl_grid/appl_grid.h"
  #include "appl_grid/appl_timer.h"
  
  #include "TH1D.h"
  #include "TPad.h"
  
  
  // lhapdf routines
  #include "LHAPDF/LHAPDF.h"
  extern "C" void evolvepdf_(const double&amp; , const double&amp; , double* ); 
  extern "C" double alphaspdf_(const double&amp; Q);
  
  
  
  int main(int argc, char** argv) { 
  
  
  
    // use a default atlas inclusive grid
    std::string gridname = "atlas-incljets04-eta1.root";
  
    if ( argc&gt;1 ) gridname = argv[1];
  
    std::cout &lt;&lt; "reading grid " &lt;&lt; gridname &lt;&lt; std::endl; 
  
    // get name of grid from user and create from grid file
    appl::grid g(gridname);
  
    g.trim(); // trim away uneeded memory
  
    /// print the grid documentation     
    std::cout &lt;&lt; g.getDocumentation() &lt;&lt; std::endl; 
  
  
  
  
  
  
  
    // initialise lhapdf
  
    std::cout &lt;&lt; "setting up lhapdf" &lt;&lt; std::endl; 
  
    // const std::string _pdfname = "cteq6mE.LHgrid";  
    const std::string _pdfname = "CT10.LHgrid";      
    int iset = 0;
  
    LHAPDF::initPDFSet( _pdfname, iset );
    // initpdfset_(_pdfname.c_str());
    // initpdf_( iset );
  
  
  
  
  
  
    // do the convolution into a vector
    std::cout &lt;&lt; "doing standalone convolution" &lt;&lt; std::endl; 
  
    //  struct timeval atimer = appl_timer_start(); 
  
    std::vector&lt;double&gt;  xsec = g.vconvolute( evolvepdf_, alphaspdf_ ); 
  
    //  double atime = appl_timer_stop(atimer); 
    //  std::cout &lt;&lt; "time " &lt;&lt; atime &lt;&lt; " ms" &lt;&lt; std::endl;
  
    for ( int i=0 ; i&lt;xsec.size() ; i++ ) std::cout &lt;&lt; "xsec[" &lt;&lt; i &lt;&lt; "]\t= " &lt;&lt; xsec[i] &lt;&lt; std::endl;  
  
  
  
  
  
    // do the convolution into a TH1D
  
    //  atimer = appl_timer_start(); 
    TH1D*  hxsec = g.convolute( evolvepdf_, alphaspdf_ ); 
    //  atime = appl_timer_stop(atimer); 
    //  std::cout &lt;&lt; "time " &lt;&lt; atime &lt;&lt; " ms" &lt;&lt; std::endl;
  
    hxsec-&gt;SetLineColor(kRed);
    hxsec-&gt;SetMarkerColor(kRed);
    hxsec-&gt;SetMarkerStyle(20);
    hxsec-&gt;DrawCopy();
    gPad-&gt;SetLogy(true);
  
    gPad-&gt;Print("xsec.pdf");
  
  
  
    return 0;
  }
  </code></pre>
  
  <p>stand-full.cxx</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  #include "appl_grid/appl_grid.h"
  #include "appl_grid/appl_timer.h"
  
  #include "TH1D.h"
  #include "TPad.h"
  
  
  // lhapdf routines
  #include "LHAPDF/LHAPDF.h"
  extern "C" void evolvepdf_(const double&amp; , const double&amp; , double* ); 
  extern "C" double alphaspdf_(const double&amp; Q);
  
  
  
  int main(int argc, char** argv) { 
  
    // use a default atlas inclusive grid
    std::string gridname = "atlas-incljets04-eta1.root";
  
    if ( argc&gt;1 ) gridname = argv[1];
  
    std::cout &lt;&lt; "reading grid " &lt;&lt; gridname &lt;&lt; std::endl; 
  
    // get name of grid from user and create from grid file
    appl::grid g(gridname);
  
    g.trim(); // trim away uneeded memory
  
    std::cout &lt;&lt; "setting up lhapdf" &lt;&lt; std::endl; 
  
    // initialise lhapdf
  
    //  const std::string _pdfname = "cteq6mE.LHgrid";  
    const std::string _pdfname = "CT10.LHgrid";  
    int iset = 0;
  
    LHAPDF::initPDFSet( _pdfname, iset );
    // initpdfset_(_pdfname.c_str());
    // initpdf_( iset );
  
    // do the convolution into a vector
    std::cout &lt;&lt; "doing standalone convolution" &lt;&lt; std::endl; 
    std::cout &lt;&lt; g.getDocumentation() &lt;&lt; std::endl; 
  
  
    struct timeval atimer = appl_timer_start(); 
  
    std::vector&lt;double&gt;  xsec = g.vconvolute( evolvepdf_, alphaspdf_ ); 
  
    double atime = appl_timer_stop(atimer); 
  
    const int Nsubproc = g.subProcesses();
  
    std::cout &lt;&lt; "time : " &lt;&lt; atime &lt;&lt; " ms\tNsubproc : " &lt;&lt; Nsubproc &lt;&lt; std::endl;
  
    std::vector&lt;std::vector&lt;double&gt; &gt;  xsb(Nsubproc);
  
    for ( int i=0 ; i&lt;Nsubproc ; i++ ) { 
      xsb[i] = g.vconvolute( i, evolvepdf_, alphaspdf_ ); 
    }
  
  
    // print results
    for ( int i=0 ; i&lt;xsec.size() ; i++ ) { 
      std::cout &lt;&lt; "xsec(" &lt;&lt; i &lt;&lt; ")=" &lt;&lt; xsec[i] &lt;&lt; std::endl;
    }
  
    for ( int i=0 ; i&lt;Nsubproc ; i++ ) { 
      std::cout &lt;&lt; "subproc: " &lt;&lt; i &lt;&lt; std::endl;
      for ( int j=0 ; j&lt;xsec.size() ; j++ ) { 
        std::cout &lt;&lt; "xsec(" &lt;&lt; i &lt;&lt; ")=" &lt;&lt; xsb[i][j] &lt;&lt; std::endl;
      } 
    }
  
  
  
  
  
    TH1D*  hxsec = g.convolute( evolvepdf_, alphaspdf_ ); 
  
    std::vector&lt;TH1D*&gt;  hxsb(Nsubproc);
  
    for ( int i=0 ; i&lt;Nsubproc ; i++ ) { 
      hxsb[i] = g.convolute( i, evolvepdf_, alphaspdf_ ); 
    }
  
  
    hxsec-&gt;SetLineColor(kRed);
    hxsec-&gt;SetMarkerColor(kRed);
    hxsec-&gt;SetMarkerStyle(20);
    hxsec-&gt;SetMinimum(0.000001);
    hxsec-&gt;DrawCopy();
    gPad-&gt;SetLogy(true);
    for ( int i=0 ; i&lt;Nsubproc ; i++ ) { 
      hxsb[i]-&gt;SetLineColor(kRed+i%5);
      hxsb[i]-&gt;SetMarkerColor(kRed+i%5);
      hxsb[i]-&gt;SetLineStyle(1+i%5);
      hxsb[i]-&gt;SetMarkerStyle(20+i%5);
      hxsb[i]-&gt;DrawCopy("same");
    }
  
  
    gPad-&gt;Print("xsec.pdf");
  
  
    double escale = 7e3/8e3;
    TH1D*  hxsec8 = g.convolute( escale, evolvepdf_, alphaspdf_ ); 
  
    escale = 7e3/2.76e3;
    TH1D*  hxsec276 = g.convolute( escale, evolvepdf_, alphaspdf_ ); 
  
  
    hxsec-&gt;DrawCopy();
    hxsec8-&gt;SetLineColor(kRed+1);
    hxsec8-&gt;SetLineStyle(2);
    hxsec8-&gt;DrawCopy("same");
  
    gPad-&gt;Print("xsec8.pdf");
  
    hxsec276-&gt;SetLineColor(kRed+2);
    hxsec276-&gt;SetLineStyle(3);
    hxsec276-&gt;DrawCopy("same");
  
    gPad-&gt;Print("xsec276.pdf");
  
    //  or get into a histogram
    //  TH1D* hxsec = g.convolute( evolvepdf_, alphaspdf_ ); 
    //  hxsec-&gt;SetName("xsec");
  
    return 0;
  }
  </code></pre>
  
  <p>stand-save.cxx</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  #include "appl_grid/appl_grid.h"
  #include "appl_grid/appl_timer.h"
  
  #include "TH1D.h"
  #include "TPad.h"
  
  
  // lhapdf routines
  #include "LHAPDF/LHAPDF.h"
  extern "C" void evolvepdf_(const double&amp; , const double&amp; , double* ); 
  extern "C" double alphaspdf_(const double&amp; Q);
  
  
  
  int main(int argc, char** argv) {    
  
    // use a default atlas inclusive grid
    std::string gridname = "atlas-incljets04-eta1.root";
  
    if ( argc&gt;1 ) gridname = argv[1];
  
    std::cout &lt;&lt; "reading grid " &lt;&lt; gridname &lt;&lt; std::endl; 
  
    // get name of grid from user and create from grid file
    appl::grid g(gridname);
  
    g.trim(); // trim away uneeded memory
  
    /// print the grid documentation 
    std::cout &lt;&lt; g.getDocumentation() &lt;&lt; std::endl;      
  
    // initialise lhapdf
  
    std::cout &lt;&lt; "setting up lhapdf" &lt;&lt; std::endl; 
  
    // const string _pdfname = "cteq6mE.LHgrid";  
    const string _pdfname = "CT10.LHgrid";  
    int iset = 0;
  
    LHAPDF::initPDFSet( _pdfname, iset );
    // initpdfset_(_pdfname.c_str());
    // initpdf_( iset );
  
    // do the convolution into a vector
    std::cout &lt;&lt; "doing standalone convolution" &lt;&lt; std::endl; 
  
    //  struct timeval atimer = appl_timer_start(); 
  
    std::vector&lt;double&gt;  xsec = g.vconvolute( evolvepdf_, alphaspdf_ ); 
  
    //  double atime = appl_timer_stop(atimer); 
    //  std::cout &lt;&lt; "time " &lt;&lt; atime &lt;&lt; " ms" &lt;&lt; std::endl;
  
    for ( int i=0 ; i&lt;xsec.size() ; i++ ) std::cout &lt;&lt; "xsec[" &lt;&lt; i &lt;&lt; "]\t= " &lt;&lt; xsec[i] &lt;&lt; std::endl;  
  
    // do the convolution into a TH1D
  
    //  atimer = appl_timer_start(); 
    TH1D*  hxsec = g.convolute( evolvepdf_, alphaspdf_ ); 
    //  atime = appl_timer_stop(atimer); 
    //  std::cout &lt;&lt; "time " &lt;&lt; atime &lt;&lt; " ms" &lt;&lt; std::endl;
  
    hxsec-&gt;SetLineColor(kRed);
    hxsec-&gt;SetMarkerColor(kRed);
    hxsec-&gt;SetMarkerStyle(20);
    hxsec-&gt;DrawCopy();
    gPad-&gt;SetLogy(true);
  
    gPad-&gt;Print("xsec.pdf");
  
  
  
    return 0;
  }
  </code></pre>
  
  <p>stand-tutorial.cxx</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  #include "appl_grid/appl_grid.h"
  
  
  #include "appl_grid/appl_timer.h"
  
  #include "TH1D.h"
  #include "TLatex.h"
  #include "TFile.h"
  #include "TH2D.h"
  #include "TStyle.h"
  #include "TCanvas.h"
  #include "TPad.h"
  #include "TStyle.h"
  #include "TColor.h"
  #include "TPaveStats.h"
  
  
  // lhapdf routines
  #include "LHAPDF/LHAPDF.h"
  extern "C" void evolvepdf_(const double&amp; x, const double&amp; Q, double* xf); 
  extern "C" double alphaspdf_(const double&amp; Q);
  
  
  void setpalette()
  {
      const Int_t NRGBs = 7;
      const Int_t NCont = 98;
  
      Double_t stops[NRGBs] = { 0.00, 0.20, 0.40, 0.60, 0.70, 0.90, 1.00 };
  
      Double_t red[NRGBs]   = { 0.00, 0.00, 0.00, 0.60, 0.90, 1.00, 0.50 };
      Double_t green[NRGBs] = { 0.00, 0.00, 0.40, 0.95, 1.00, 0.20, 0.00 };
      Double_t blue[NRGBs]  = { 0.00, 1.00, 1.00, 0.10, 0.00, 0.00, 0.00 };
  
      TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
      gStyle-&gt;SetNumberContours(NCont);
  }
  
  
  
  
  
  TH2D* smooth(TH2D* h) { 
  
    int Nnbins = 10;
  
    TH2D* hi = new TH2D("h2","", 
                h-&gt;GetXaxis()-&gt;GetNbins()*Nnbins, 
                h-&gt;GetXaxis()-&gt;GetBinLowEdge(1), 
                h-&gt;GetXaxis()-&gt;GetBinLowEdge(h-&gt;GetXaxis()-&gt;GetNbins()+1), 
  
                h-&gt;GetYaxis()-&gt;GetNbins()*Nnbins, 
                h-&gt;GetYaxis()-&gt;GetBinLowEdge(1), 
                h-&gt;GetYaxis()-&gt;GetBinLowEdge(h-&gt;GetYaxis()-&gt;GetNbins()+1) );
  
    hi-&gt;GetXaxis()-&gt;SetTitle( h-&gt;GetXaxis()-&gt;GetTitle() );
    hi-&gt;GetYaxis()-&gt;SetTitle( h-&gt;GetYaxis()-&gt;GetTitle() );
    hi-&gt;GetYaxis()-&gt;SetTitleOffset(1.1);
  
  
    for ( int i=1 ; i&lt;=h-&gt;GetXaxis()-&gt;GetNbins() ; i++ ) { 
      for ( int j=1 ; j&lt;=h-&gt;GetYaxis()-&gt;GetNbins() ; j++ ) {
  
        double z1 = h-&gt;GetBinContent(i,j);
        double z2 = h-&gt;GetBinContent(i+1,j);
        double z3 = h-&gt;GetBinContent(i,j+1);
        double z4 = h-&gt;GetBinContent(i+1,j+1);
  
  
        if ( z2==0 ) z2 = z1;
        if ( z3==0 ) z3 = z1;
        if ( z4==0 ) z4 = z3;
  
        for ( int ii=0 ; ii&lt;Nnbins ; ii++ ) { 
  
      double fx = 1.0*ii/Nnbins;
  
      for ( int jj=0 ; jj&lt;Nnbins ; jj++ ) { 
  
        double fy = 1.0*jj/Nnbins;
  
        double z = ( (z4-z3-z2+z1)*fx + z3 - z1 )*fy + (z2-z1)*fx + z1;
  
        //      std::cout &lt;&lt; (i-1)*Nnbins+ii+1 &lt;&lt; " " &lt;&lt; (j-1)*Nnbins+jj+1 &lt;&lt; "\t z : "  &lt;&lt; z &lt;&lt; "\tz1-4: " &lt;&lt; z1 &lt;&lt; " " &lt;&lt; z2 &lt;&lt; " " &lt;&lt; z3 &lt;&lt; " " &lt;&lt; z4 &lt;&lt; std::endl; 
  
        hi-&gt;SetBinContent( (i-1)*Nnbins+ii+1, (j-1)*Nnbins+jj+1, z); 
        // hi-&gt;SetBinContent( (i-1)*Nnbins+ii+1, (j-1)*Nnbins+jj+1, h-&gt;GetBinContent(i,j) ); 
  
      }
  
        } 
      }
  
    }
  
    return hi;
  
  }
  
  
  
  
  
  
  
  
  
  int main(int argc, char** argv) { 
  
    gStyle-&gt;SetOptStat(0);
  
    setpalette();
  
    // use a default atlas inclusive grid
    std::string gridname = "atlas-incljets-arxiv-1009.5908v2/r04/atlas-incljets-eta1.root";
  
    if ( argc&gt;1 ) gridname = argv[1];
  
    std::cout &lt;&lt; "reading grid " &lt;&lt; gridname &lt;&lt; std::endl; 
  
    appl::grid g(gridname);
    //  g.trim(); // trim away uneeded memory
  
    /// print the grid documentation 
    std::cout &lt;&lt; g.getDocumentation() &lt;&lt; std::endl; 
  
  
    // initialise lhapdf
  
    std::cout &lt;&lt; "setting up lhapdf" &lt;&lt; std::endl; 
  
    //  const std::string _pdfname = "cteq6mE.LHgrid";  
    const std::string _pdfname = "CT10.LHgrid";  
    int iset = 0;
  
    LHAPDF::initPDFSet( _pdfname, iset );
    // initpdfset_(_pdfname.c_str());
    // initpdf_( iset );
  
  
  
    ///  ----------------- example 1 -------------------- 
  
    if ( true ) { 
  
      // do the convolution into a vector
      std::cout &lt;&lt; "example 1: standalone convolution" &lt;&lt; std::endl; 
  
      struct timeval atimer = appl_timer_start(); 
  
      std::vector&lt;double&gt;  xsec = g.vconvolute( evolvepdf_, alphaspdf_ ); 
  
      double atime = appl_timer_stop(atimer); 
  
      std::cout &lt;&lt; "time : " &lt;&lt; atime &lt;&lt; " ms" &lt;&lt; std::endl;
  
      for ( int i=0 ; i&lt;xsec.size() ; i++ ) std::cout &lt;&lt; "xsec[" &lt;&lt; i &lt;&lt; "]\t= " &lt;&lt; xsec[i] &lt;&lt; std::endl;  
  
      TH1D*  hxsec = g.convolute( evolvepdf_, alphaspdf_ ); 
  
      hxsec-&gt;SetTitle("");
      hxsec-&gt;DrawCopy();
  
      gPad-&gt;SetLogy(true);
      gPad-&gt;Print("example-1.pdf");
  
    }
  
  
    ///  ----------------- example 2 (corrections) -------------------- 
  
    if ( false ) { 
  
      std::cout &lt;&lt; "example 2: multiplicative corrections" &lt;&lt; std::endl; 
  
      std::cout &lt;&lt; g.getApplyCorrections() &lt;&lt; std::endl;
  
      g.setApplyCorrections(false);
      TH1D*  huncor = g.convolute( evolvepdf_, alphaspdf_ ); 
  
      g.setApplyCorrections(true);
      TH1D*  hcor = g.convolute( evolvepdf_, alphaspdf_ ); 
  
      huncor-&gt;SetLineStyle(2);
      huncor-&gt;SetTitle("");
  
      huncor-&gt;DrawCopy();
      hcor-&gt;DrawCopy("same");
  
      gPad-&gt;Print("example-2.pdf");
  
    }
  
    ///  ----------------- example 3 (cms scaling) -------------------- 
  
    if ( false ) { 
  
      std::cout &lt;&lt; "example 3: centre-of-mass energy scaling " &lt;&lt; std::endl;
  
      TH1D* h7 = g.convolute( evolvepdf_, alphaspdf_ ); 
  
      double Escale = 7/2.46;
  
      TH1D* h246 = g.convolute( Escale, evolvepdf_, alphaspdf_ ); 
  
      std::cout &lt;&lt; "cms scale " &lt;&lt; g.getCMSScale() &lt;&lt; std::endl;
  
      h7-&gt;SetTitle("");
      h7-&gt;SetMinimum(0.001);
  
      gStyle-&gt;SetOptStat(0);
  
      h7-&gt;DrawCopy();
      h246-&gt;SetLineColor(kRed);
      h246-&gt;DrawCopy("same");
  
      gPad-&gt;SetLogy(true);
      gPad-&gt;Print("example-3.pdf");
  
    }
  
  
  
  
  
    ///  ------------------ example 4 (scale variation) -----------------
  
    if ( false ) {
  
      std::cout &lt;&lt; "example 4: scale variation " &lt;&lt; std::endl;
  
      int nloops = 1; // loop order
  
      int Nbins = 30;
      TH2D* hscale = new TH2D("scale", "", Nbins, 0.45, 2.05,  Nbins, 0.45, 2.05 );
  
      struct timeval atimer = appl_timer_start(); 
  
      for ( int i=1 ; i&lt;=hscale-&gt;GetNbinsX() ; i++ ) { 
        double fscale = hscale-&gt;GetXaxis()-&gt;GetBinCenter(i); 
  
        for ( int j=1 ; j&lt;=hscale-&gt;GetNbinsY() ; j++ ) { 
      double rscale = hscale-&gt;GetYaxis()-&gt;GetBinCenter(j);
  
      std::vector&lt;double&gt; xs = g.vconvolute( evolvepdf_, alphaspdf_, nloops, rscale, fscale );
  
      double total = 0;
      for ( int k=xs.size() ; k-- ; ) total += xs[k];
  
      hscale-&gt;Fill( fscale, rscale, total );
  
        }
      }  
  
      double atime = appl_timer_stop(atimer);
  
      std::cout &lt;&lt; "time " &lt;&lt; atime &lt;&lt; " ms" &lt;&lt; std::endl;
  
  
      /// plot ....
  
  
      gStyle-&gt;SetPalette(52);
      gStyle-&gt;SetPadRightMargin(0.17);
  
  
      TCanvas* tc = new TCanvas( "","", 650, 600 );
  
      hscale-&gt;GetXaxis()-&gt;SetTitle("factorisation scale factor");
      hscale-&gt;GetYaxis()-&gt;SetTitle("renormalisation scale factor");
      hscale-&gt;GetYaxis()-&gt;SetTitleOffset(1.1);
  
      TH2D* _hscale = smooth(hscale);
  
      _hscale-&gt;DrawCopy("colz");
  
      gPad-&gt;Print("example-4.png");
  
  
      TFile fs("scale.root","recreate");
      fs.cd();
      hscale-&gt;Write();
      fs.Write();
      fs.Close();
  
    }
  
  
  
    ///  ------------------ example 5 (subprocesses) -----------------
  
    if ( false ) {
  
      std::cout &lt;&lt; "example 4: subprocess contributions " &lt;&lt; std::endl;
  
      std::vector&lt;double&gt; xsec = g.vconvolute( evolvepdf_, alphaspdf_);
  
      std::vector&lt;TH1D*&gt; xsec_sub(g.subProcesses());
  
      for ( int i=0 ; i&lt;g.subProcesses() ; i++ ) {
        xsec_sub[i] = g.convolute_subproc( i, evolvepdf_, alphaspdf_);
  
        for ( int j=0 ; j&lt;xsec_sub[i]-&gt;GetNbinsX() ; j++ ) { 
      xsec_sub[i]-&gt;SetBinContent( j+1,  xsec_sub[i]-&gt;GetBinContent(j+1)/xsec[j] );
        }
      }
  
  
      /// plot ...
  
      int col[7] = { kRed, kBlue, kMagenta, kCyan, kGreen, kBlack, kViolet };
  
      xsec_sub[0]-&gt;SetMaximum(0.6);
      xsec_sub[0]-&gt;SetMinimum(0);
      xsec_sub[0]-&gt;GetXaxis()-&gt;SetTitle("P_{T} [GeV]");
      xsec_sub[0]-&gt;GetYaxis()-&gt;SetTitle("subprocess fraction");
      xsec_sub[0]-&gt;SetTitle("");
  
  
      xsec_sub[0]-&gt;DrawCopy();
  
  
      for ( int i=0 ; i&lt;g.subProcesses() ; i++ ) {
        xsec_sub[i]-&gt;SetLineColor(col[i]);
        xsec_sub[i]-&gt;DrawCopy("same");
  
        TLatex* tl = new TLatex(0,0,"");
        tl-&gt;SetTextColor(col[i]);
        tl-&gt;SetTextSize(0.04);
  
        char label[64];
        sprintf(label, "subprocess %d", i);
  
        tl-&gt;DrawLatex(430, 0.55-0.035*i, label );
      }
  
      gPad-&gt;SetLogy(false);
  
      gPad-&gt;Print("example-5.pdf");
  
    }
  
  
  
  
    ///   -------------------- example 6 (pdf sets) -----------------------
  
    if ( false ) {
  
      // const std::string _pdfname = "cteq6mE.LHgrid";  
      const std::string _pdfname = "CT10.LHgrid";  
      int iset = 0;
  
      LHAPDF::initPDFSet( _pdfname, iset );
      std::vector&lt;double&gt; _xs = g.vconvolute( evolvepdf_, alphaspdf_ );
  
      int Nset = LHAPDF::numberPDF();
  
      std::vector&lt;TH1D*&gt; xs(Nset); 
  
      for ( int i=0 ; i&lt;Nset ; i++ ) {
        struct timeval atimer = appl_timer_start();
        LHAPDF::initPDFSet( _pdfname, i );
        double atime = appl_timer_stop(atimer);
        std::cout &lt;&lt; "set " &lt;&lt; i &lt;&lt; "\tinitPDF time " &lt;&lt; atime &lt;&lt; " ms" &lt;&lt; std::endl;
  
        atimer = appl_timer_start();
        xs[i] = g.convolute( evolvepdf_, alphaspdf_ );
        atime = appl_timer_stop(atimer);
  
        std::cout &lt;&lt; "convolution time " &lt;&lt; atime &lt;&lt; " ms" &lt;&lt; std::endl;
  
        for ( int j=_xs.size() ; j-- ; ) xs[i]-&gt;SetBinContent( j+1, xs[i]-&gt;GetBinContent(j+1)/_xs[j]);   
      }
  
      xs[0]-&gt;SetMaximum(1.1);
      xs[0]-&gt;SetMinimum(0.9);
      gPad-&gt;SetLogy(false);
      gPad-&gt;SetLogx(true);
  
      xs[0]-&gt;DrawCopy("l");
      for ( int i=0 ; i&lt;Nset ; i++ ) xs[i]-&gt;DrawCopy("lsame");
  
      gPad-&gt;Print("example-6.pdf");
      gPad-&gt;SetLogx(false);
    }
  
  
    /// ------------------- example 7 (timers) ---------------------
  
    if ( false ) {
  
      gStyle-&gt;SetOptStat(2220);
  
      std::cout &lt;&lt; "example 7 : timings" &lt;&lt; std::endl;
  
      TH1D* htrim   = new TH1D("htrim",   "", 100, 38, 45);
      // TH1D* htrim2  = new TH1D("htrim2",  "", 100, 37, 45);
      TH1D* huntrim = new TH1D("huntrim", "", 100, 38, 45);
  
  
      g.trim();
  
      std::cout &lt;&lt; "grid size : " &lt;&lt; g.size() &lt;&lt; std::endl;
  
      for ( int i=400 ; i-- ; ) { 
        struct timeval atimer = appl_timer_start();
        std::vector&lt;double&gt; xsec = g.vconvolute( evolvepdf_, alphaspdf_ );
        double atime = appl_timer_stop( atimer );
        htrim-&gt;Fill(atime);
      }
  
       g.untrim();
  
      std::cout &lt;&lt; "grid size : " &lt;&lt; g.size() &lt;&lt; std::endl;
  
      for ( int i=400 ; i-- ; ) { 
        struct timeval atimer = appl_timer_start();
        std::vector&lt;double&gt; xsec = g.vconvolute( evolvepdf_, alphaspdf_ );
        double atime = appl_timer_stop( atimer );
        huntrim-&gt;Fill(atime);
      }
  
  
      if ( huntrim-&gt;GetMaximum()&lt;htrim-&gt;GetMaximum() ) huntrim-&gt;SetMaximum(1.1*htrim-&gt;GetMaximum());
      else                                             htrim-&gt;SetMaximum(1.1*huntrim-&gt;GetMaximum());
      huntrim-&gt;SetLineStyle(2);
      huntrim-&gt;SetLineColor(kRed);
      htrim-&gt;GetXaxis()-&gt;SetTitle("time [ms]");
      huntrim-&gt;GetXaxis()-&gt;SetTitle("time [ms]");
  
      huntrim-&gt;Draw();
      htrim-&gt;Draw("same");
      //  htrim2-&gt;DrawCopy("same");
      huntrim-&gt;Draw("same");
      htrim-&gt;Draw("sames+");
      huntrim-&gt;Draw("sames+");
  
      gPad-&gt;Update();
  
      TPaveStats* tp1 = (TPaveStats*)htrim-&gt;GetListOfFunctions()-&gt;FindObject("stats");
      TPaveStats* tp2 = (TPaveStats*)huntrim-&gt;GetListOfFunctions()-&gt;FindObject("stats");
  
      std::cout &lt;&lt; tp1 &lt;&lt; " " &lt;&lt; tp2 &lt;&lt; std::endl;
  
      tp2-&gt;SetTextColor(kRed);
  
  
      tp1-&gt;SetY1NDC(0.93-0.15);
      tp1-&gt;SetY2NDC(0.93);
  
      tp2-&gt;SetY1NDC(0.93-0.16-0.15);
      tp2-&gt;SetY2NDC(0.93-0.16);
  
      tp1-&gt;Draw();
      tp2-&gt;Draw();
  
      gPad-&gt;Update();
  
      gPad-&gt;Print("example-7.pdf");
  
    }
  
    return 0;
  }
  </code></pre>
  
  <p>any help will be greatly appreciated, thank you.</p>