Compilation with RooFit classes

Dear experts,

I am trying to compile my macros with RooFit classes without any success.
Here’s a small test file:

  #if !defined(__CINT__) || defined(__MAKECINT__)
  #include <TStopwatch.h>
  #include <TStyle.h>
  #include <TString.h>
  #include <TCanvas.h>
  #include <TChain.h>
  #include "TH2F.h"
  #include "TH1S.h"
  #include "TH1F.h"
  #include "TFile.h"
  #include "TStyle.h"
  #include "TSystem.h"
  #include "TGrid.h"
  #include "TROOT.h"
  #include "TPaveText.h"
  #include "TGraph.h"
  #include "TGraphErrors.h"
  #include "TFitResult.h"

  #include "iostream"

  #include <math.h>
  #include <sstream>
  #include  <array>
  #include <utility>
    
  #include "RooRealVar.h"
  #include "RooDataSet.h"
  #include "RooGaussian.h"
  #include "RooPolynomial.h"
  #include "RooKeysPdf.h"
  #include "RooNDKeysPdf.h"
  #include "RooProdPdf.h"
  #include "RooPlot.h"
  #include "RooAbsPdf.h"
  #include "RooAbsArg.h"
#endif  

  using namespace RooFit;

void RFtest(){
  RooRealVar x("x","x",-10,10) ;
  RooRealVar mean("mean","Mean of Gaussian",0,-10,10) ;
  RooRealVar sigma("sigma","Width of Gaussian",3,0.1,10) ;
  RooGaussian gauss("gauss","gauss(x,mean,sigma)",x,mean,sigma) ;
  RooPlot* xframe = x.frame(Title("Time"),Bins(20)) ;

  RooDataSet* data = gauss.generate(x,10000) ;
  data->plotOn(xframe) ;  
  xframe->Draw();
  gauss.fitTo(*data, Minos(kTRUE), PrintLevel(-1)) ; 
  gauss.plotOn(xframe) ;
  xframe->Draw();
}

It works without compiling. But I get errors like this when I try to compile it:

root [0] .L RFtest.C++
Info in <TUnixSystem::ACLiC>: creating shared library /home/andrei/ppLHC18e_gf261223_work/ppLHC18e_gf_ZCopt/Separation/./RFtest_C.so
In file included from input_line_9:6:
In file included from ././RFtest.C:3:
In file included from /root/ROOT/root_install/include/TStyle.h:15:
In file included from /root/ROOT/root_install/include/TNamed.h:26:
In file included from /root/ROOT/root_install/include/TString.h:30:
In file included from /root/ROOT/root_install/include/ROOT/TypeTraits.hxx:15:
In file included from /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/memory:76:
/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/unique_ptr.h:83:16: error: invalid application of 'sizeof' to an incomplete type 'RooFitResult'
        static_assert(sizeof(_Tp)>0,
                      ^~~~~~~~~~~
/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/unique_ptr.h:361:4: note: in instantiation of member function 'std::default_delete<RooFitResult>::operator()' requested here
          get_deleter()(std::move(__ptr));
          ^
/root/ROOT/root_install/include/RooAbsPdf.h:158:38: note: in instantiation of member function 'std::unique_ptr<RooFitResult, std::default_delete<RooFitResult> >::~unique_ptr' requested here
    return RooFit::Detail::owningPtr(fitToImpl(data, *RooFit::Detail::createCmdList(&cmdArgs...)));
                                     ^
././RFtest.C:51:9: note: in instantiation of function template specialization 'RooAbsPdf::fitTo<RooCmdArg, RooCmdArg>' requested here
  gauss.fitTo(*data, Minos(kTRUE), PrintLevel(-1)) ; 
        ^
/root/ROOT/root_install/include/RooAbsArg.h:740:16: note: forward declaration of 'RooFitResult'
  friend class RooFitResult;
               ^
Error in <ACLiC>: Executing '/root/ROOT/root_install/bin/rootcling -v0 "--lib-list-prefix=/home/andrei/ppLHC18e_gf261223_work/ppLHC18e_gf_ZCopt/Separation/RFtest_C_ACLiC_map" -f "/home/andrei/ppLHC18e_gf261223_work/ppLHC18e_gf_ZCopt/Separation/RFtest_C_ACLiC_dict.cxx" -I$ROOTSYS/include -I"/root/ROOT/root_install/etc/" -I"/root/ROOT/root_install/etc//cling" -I"/root/ROOT/root_install/etc//cling/plugins/include" -I"/root/ROOT/root_install/include/" -I"/root/ROOT/root_install/include" -D__ACLIC__  "/home/andrei/ppLHC18e_gf261223_work/ppLHC18e_gf_ZCopt/Separation/./RFtest.C" "/home/andrei/ppLHC18e_gf261223_work/ppLHC18e_gf_ZCopt/Separation/RFtest_C_ACLiC_linkdef.h"' failed!

Could you help me please?

Thank you in advance.
Regards,
Andrei.

Add #include "RooFitResult.h"

1 Like

Thank you very much, Bellenot!
Now it works.

Regards,
Andrei.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.