[SOLVED] Compiling RooFit Macro Fails

Hi,

I’m using ROOT 5.31/01 (trunk@39516, Oct 31 2011, 12:10:00 on linux). Compilers:

g++ --version
g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1

clang++ --version
clang version 2.9 (tags/RELEASE_29/final)
Target: i386-pc-linux-gnu
Thread model: posix

I’m trying to compile a macro into a standalone program, the following is a code snippet (showing the current problem), the lines marked with * are the problem lines.

TFile * file_1 = new TFile("plot1_Run7_type2_pidopt0.root");
TH1D *  hist   = static_cast<TH1D*>(file_1->Get("dileptonmass0_mmnopid"));
hist->GetYaxis()->SetLabelSize(0.02);
RooRealVar x("dilepton mass","dilepton mass/#sqrt{s}",0.96,1.04);
RooDataHist dh("dh","dh",x,hist);

RooRealVar mean("mean", "mean", 0.99, 0.96, 1.04);
RooRealVar sigma("sigma", "sigma", 0.001,0.0, 0.1);
RooRealVar alpha("alpha", "alpha", 1.2, 0.9, 2.0);
RooRealVar n("n","n", 1, 0, 100);

RooRealVar sigma1("sigma1", "sigma1", 0.05, 0.0, 0.1);
RooGaussian gauss("gauss", "gauss", x, mean, sigma1);

RooRealVar nsig("nsig","#Upsilon (3S) events",1000,0.,100000000) ; 
RooRealVar nsig2("nsig2","#Upsilson (2S) events",400,0.,100000000) ;

RooCBShape cball("cball", "Crystal Ball Shape", x, mean, sigma, alpha, n);

RooAddPdf sum("sum", "g+cb", RooArgList(gauss,cball), RooArgList(nsig,nsig2));

sum.fitTo(dh, Range(0.96,1.04), Extended(true));

RooPlot * frame = x.frame(Name("frame"), Title("Dilepton Mass"));
frame->SetLabelSize(0.02);
frame->GetYaxis()->SetLabelSize(0.025);
frame->GetYaxis()->SetTitleSize(0.04);
dh.plotOn(frame, DataError(RooAbsData::SumW2)) ;
sum.plotOn(frame);

frame->Draw();
gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.5);
	
RooArgSet * params = sum.getParameters(x);
params->printLatex();

// Construct a histogram with the residuals of the data w.r.t. the curve
RooHist* hresid = frame->residHist() ;

// Construct a histogram with the pulls of the data w.r.t the curve
RooHist* hpull = frame->pullHist() ;

// Create a new frame to draw the residual distribution and add the distribution to the frame
RooPlot* frame2 = x.frame(Title("Residual Distribution")) ;
frame2->addPlotable(hresid) ;//*

// Create a new frame to draw the pull distribution and add the distribution to the frame
RooPlot* frame3 = x.frame(Title("Pull Distribution")) ;
frame3->addPlotable(hpull) ;//*

I use the following command to compile (and link if successful) the macro:

Where root-config --cflags --libs returns:

-pthread -m32 -I/usr/include/root -L/usr/lib/root -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic

Which gives the following error:

dilepton_mass_fitter.C: In function ‘int dilepton_mass_fitter_data_low_cb_plus_gauss()’: dilepton_mass_fitter.C:560:29: error: no matching function for call to ‘RooPlot::addPlotable(RooHist*&)’ dilepton_mass_fitter.C:560:29: note: candidate is: /usr/include/root/RooPlot.h:111:8: note: void RooPlot::addPlotable(RooPlotable*, Option_t*, Bool_t, Bool_t) /usr/include/root/RooPlot.h:111:8: note: no known conversion for argument 1 from ‘RooHist*’ to ‘RooPlotable*’ dilepton_mass_fitter.C:564:28: error: no matching function for call to ‘RooPlot::addPlotable(RooHist*&)’ dilepton_mass_fitter.C:564:28: note: candidate is: /usr/include/root/RooPlot.h:111:8: note: void RooPlot::addPlotable(RooPlotable*, Option_t*, Bool_t, Bool_t) /usr/include/root/RooPlot.h:111:8: note: no known conversion for argument 1 from ‘RooHist*’ to ‘RooPlotable*’

Similarly, using clang++ to compile gives the following error:

dilepton_mass_fitter.C:560:23: error: cannot initialize a parameter of type 'RooPlotable *' with an lvalue of type 'RooHist *' frame2->addPlotable(hresid) ; ^~~~~~ In file included from dilepton_mass_fitter.C:12: /usr/include/root/RooPlot.h:111:33: note: passing argument to parameter 'plotable' here void addPlotable(RooPlotable *plotable, Option_t *drawOptions= "", Bool_t invisible=kFALSE, Bool_t refreshNorm=kFALSE); ^ dilepton_mass_fitter.C:564:23: error: cannot initialize a parameter of type 'RooPlotable *' with an lvalue of type 'RooHist *' frame3->addPlotable(hpull) ; ^~~~~ In file included from dilepton_mass_fitter.C:12: /usr/include/root/RooPlot.h:111:33: note: passing argument to parameter 'plotable' here void addPlotable(RooPlotable *plotable, Option_t *drawOptions= "", Bool_t invisible=kFALSE, Bool_t refreshNorm=kFALSE);

However, RooPlotable is a public base class of RooHist (according to the documentation, root.cern.ch/root/html/RooHist ) - so the pointer conversion should be valid, i.e. RooHist * returned from frame->residHist() or frame->pullHist(); should be convertable to RooPlotable *, unless they are actually incomplete or malformed types.

Any idea on how to make this compile properly?

Cheers,

Greg

Found my problem, I was missing a header (RooHist.h); the problem was that RooHist is forward declared in another header (and thus will compile and link, but the actually inheritance is defined in RooHist.h).