# RooFit variables not recognised

**URL:** <https://root-forum.cern.ch/t/roofit-variables-not-recognised/64833>\
**Category:** Newbie\
**Created:** [May 7, 2026, 1:48pm UTC](https://root-forum.cern.ch/t/roofit-variables-not-recognised/64833 "2026-05-07T13:48:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sprock](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@sprock](https://root-forum.cern.ch/u/sprock)\
**Post date:** [May 7, 2026, 1:48pm UTC](https://root-forum.cern.ch/t/roofit-variables-not-recognised/64833/1 "2026-05-07T13:48:04Z")

</div>

* * *

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

_ROOT Version:_ root-6.38.00  
_Platform:_ FreeBSD  
_Compiler:_ FreeBSD clang version 19.1.7

* * *

Hello,

This code:

#include “TH1.h”  
#include “TMath.h”  
#include “TF1.h”  
#include “TLegend.h”  
#include “TCanvas.h”

using namespace RooFit;

void region\_1() {

std::vector\<std::vector \> values;  
std::ifstream fin(“Region\_1.csv”);  
for (std::string line; std::getline(fin, line); )  
{  
std::replace(line.begin(), line.end(), ‘,’, ’ ');  
std::istringstream in(line);  
values.push\_back(  
std::vector(std::istream\_iterator(in),  
std::istream\_iterator()));  
}

```
double xlow = values.at(0).at(0);
double xhigh = values.at(values.size()-1).at(0);

std::cout << "Read " << values.size() << " data points" << " x low: " << xlow << " xhigh: " << xhigh << "\\n";
TH1F\* hist = new TH1F("hist", "Region_1", values.size(), xlow, xhigh );
for (int i=1; i < values.size(); ++i) // setting bin contents to values
  {
hist->Fill(values.at(i).at(0), values.at(i).at(1)); // uncertainties are of course screwed up
  }
// hist->Draw("AP");

// Import into RooDataHist
RooRealVar x("x","x",xlow,xhigh);
RooDataHist data("data","dataset with x",x,hist);
RooPlot\* frame = x.frame() ;
data.plotOn(frame) ;
frame->Draw();

// Lorentzian
// A/pi ((G/2)/((x-P)^2 + (G/2)^2))
RooRealVar A("amplitude","Amplitude of Lorentzian", 0.5, 0,100);
RooRealVar P("peak", "Peak of Lorentzian", -77,-80, -70);
RooRealVar G("fwhm", "Width of lorentzian",0.1,0,2);
RooGenericPdf lorentzian{"lorentzian", "A \* ((G/2)/((x-P)^2 + (G/2)^2))", RooArgList(A,P,G)};

```

}

when invoked in cling results in this error:

```auto
root [0] .x region_1.C
Read 971 data points x low: -96.4057 xhigh: 96.2172
Fontconfig warning: using without calling FcInit()
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
input_line_37:2:73: error: use of undeclared identifier 'A'
Double_t TFormula ____ id11031697281559057077(Double_t const *x){ return {A}*(({G}/2)/(TMath::Sq((x[0]-{P}))+TMath::Sq(({G}/2)))) ; }
                                                                        ^
input_line_38:2:73: error: use of undeclared identifier 'A'
Double_t TFormula ____ id11031697281559057077(Double_t const *x){ return {A}*(({G}/2)/(TMath::Sq((x[0]-{P}))+TMath::Sq(({G}/2)))) ; }
                                                                        ^
Error in <prepareMethod>: Can't compile function TFormula ____ id11031697281559057077 prototype with arguments Double_t const*
Error in <TFormula::InputFormulaIntoCling>: Error compiling formula expression in Cling
Error in <TFormula::ProcessFormula>: "A" has not been matched in the formula expression
Error in <TFormula::ProcessFormula>: "G" has not been matched in the formula expression
Error in <TFormula::ProcessFormula>: "P" has not been matched in the formula expression
Error in <TFormula::ProcessFormula>: "G" has not been matched in the formula expression
Error in <TFormula::ProcessFormula>: Formula "A*((G/2)/(TMath::Sq((x-P))+TMath::Sq((G/2))))" is invalid !
[#0] FATAL:InputArguments -- RooFormula 'lorentzian' did not compile or is invalid.
Input:
        A * ((G/2)/((x-P)^2 + (G/2)^2))
Passed over to TFormula:
        A * ((G/2)/((x-P)^2 + (G/2)^2))
Error in <TRint::HandleTermInput()>: std::runtime_error caught: RooFormula 'lorentzian' did not compile or is invalid.
Input:
        A * ((G/2)/((x-P)^2 + (G/2)^2))
Passed over to TFormula:
        A * ((G/2)/((x-P)^2 + (G/2)^2))

```

Can someone point out what I’m doing wrong?

Thanks,

Sprock

---

<div class="post-metadata">

**Author:** ![ajomy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ajomy/32/37349_2.png) [@ajomy](https://root-forum.cern.ch/u/ajomy)\
**Post date:** [May 7, 2026, 2:12pm UTC](https://root-forum.cern.ch/t/roofit-variables-not-recognised/64833/2 "2026-05-07T14:12:18Z")

</div>

Welcome to the ROOT Forum!  
RooFit expert @jonas can help you with this question.

Aaron

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [May 7, 2026, 9:44pm UTC](https://root-forum.cern.ch/t/roofit-variables-not-recognised/64833/3 "2026-05-07T21:44:14Z")

</div>

Hi!

The mismatch is between the RooFit names of your variables and the names used in the formula string.

In RooFit, what matters in a RooGenericPdf formula is the first argument to the RooRealVar constructor (the RooFit name), not the C++ variable name. You named them:

- “amplitude” (C++ var A)
- “peak” (C++ var P)
- “fwhm” (C++ var G)

but in the formula you wrote A, P, G, which RooFit/TFormula doesn’t know about. That’s why TFormula leaves them as literal {A}, {G}, {P} placeholders and then fails to compile.

Three ways to fix it:

1. Use the RooFit names in the formula:

2. Rename the RooRealVars so their RooFit names match:

3. Use positional placeholders (`@0`, `@1`, `@2` in the order of the RooArgList):

Note that you must include x in the list too (and reference it as e.g. @3), or keep x referenced by name and the other parameters by @.

Option 1 or 2 is what most people do.

I hope that helps!  
Jonas

---

<div class="post-metadata">

**Author:** ![sprock](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@sprock](https://root-forum.cern.ch/u/sprock)\
**Post date:** [May 8, 2026, 9:51am UTC](https://root-forum.cern.ch/t/roofit-variables-not-recognised/64833/4 "2026-05-08T09:51:56Z")

</div>

Thank you Jonas, that was it.

I fear there may be more questions as I proceed with this work

sprock
