Please read tips for efficient and successful posting and posting code
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:
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