RooWorkspace, help please

Hi everyone,

I am compiling a small code using gcc

"#include “TFile.h”
#include “TString.h”
#include “TMath.h”
#include <stdio.h>

#include “RooGlobalFunc.h”
#include “RooDataSet.h”
#include “RooRealVar.h”
#include “RooAbsPdf.h”
#include “RooFit.h”
#include “RooFitResult.h”

#include “RooEffProd.h”
#include “RooNLLVar.h”
#include “RooWorkspace.h”
#include “RooDataHist.h”
#include “RooHistPdf.h”

double QCDEstimation(TString& file, int jets, double dR, double Electron_pt, double Muon_pt){

std::cout << dR << std::endl;

TFile f(file);
RooWorkspace* w = (RooWorkspace*)f.Get(“w”);

double factor_bin = w->function(“em_qcd_osss_binned”)->getVal();
double factor_uncert = w->function(“em_qcd_extrap_uncert”)->getVal();

double osss = factor_bin * factor_uncert;

//float osss = w->function(“em_qcd_osss_binned”).getVal()*w->funtion(“em_qcd_extrap_uncert”).getVal();
//std::cout << "OSSS Value " << osss << std::endl;

return osss;

void Test(){

TString file(“QCD/htt_scalefactors_legacy_2018.root”);
double osss = QCDEstimation(file, 0, 1.0, 100.0, 100.0);
std::cout << osss << std::endl;


I compile it using the following line:

g++ -std=gnu++0x -I${ROOTINCDIR} {fileC} {ROOTLIBS} -lX11 -o ${fileEXE}

in which fileC is my Test.C (the code attached above)

I got the following errors…

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/…/…/…/…/lib64/crt1.o: In function _start': (.text+0x20): undefined reference tomain’
/tmp/lurda/ccSWacp4.o: In function QCDEstimation(TString&, int, double, double, double)': Test.C:(.text+0xb6): undefined reference toRooWorkspace::var(char const*) const’
Test.C:(.text+0xe1): undefined reference to RooWorkspace::var(char const*) const' Test.C:(.text+0x11c): undefined reference toRooWorkspace::var(char const*) const’
Test.C:(.text+0x157): undefined reference to RooWorkspace::var(char const*) const' Test.C:(.text+0x192): undefined reference toRooWorkspace::function(char const*) const’
Test.C:(.text+0x1c3): undefined reference to RooWorkspace::function(char const*) const' /tmp/lurda/ccSWacp4.o: In functionRooAbsReal::getVal(RooArgSet const*) const’:
Test.C:(.text._ZNK10RooAbsReal6getValEPK9RooArgSet[_ZNK10RooAbsReal6getValEPK9RooArgSet]+0x22): undefined reference to `RooAbsArg::_inhibitDirty’
collect2: error: ld returned 1 exit status
Compilation done.
./cmsAnalysisRunLU: line 28: ./Test.exe: No such file or directory

Can anyone help me?..

Thank you so much in advance!


undefined reference to main means that you didn’t include the main method. You have to fix that in the source file.

The other missing symbol errors are likely because you have to mention the roofit libraries when linking. What is in your variable ROOTLIBS? It should at least have -lRooFitCore -lRooFit in addition to the core ROOT libraries.

1 Like

Thank you so much
My ROOTLIBS contained ROOTLIBS="-L/usr/lib64 $ROOTSYS/bin/root-config --glibs -lMathCore -lMinuit"

Now it works after including -lRooFitCore -lRooFit

Thank you!!

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