ROOT Version: 6.26/06
Platform: MacOS 12.6.7
Compiler: g++
I am trying to make a graph of a function. This simple implementation below does not work. The function chi2_p2bm clearly exists, because I can calculate a value and print it out via the cout. But the TF1 does not recognize it. I am very confused because this looks exactly like many of the examples in the TF1 documentation.
Here is the compiler line:
% g++ -std=c++11 testgraph.cpp -o testgraph root-config --cflags --glibs
Here is the output:
% ./testgraph
0.0225
0.0256
0.0289
0.0324
input_line_8:2:65: error: use of undeclared identifier ‘chi2_p2bm’
Double_t TFormula____id4664759779193443662(Double_t *x){ return chi2_p2bm(x[0]) ; }
^
input_line_9:2:65: error: use of undeclared identifier ‘chi2_p2bm’
Double_t TFormula____id4664759779193443662(Double_t x){ return chi2_p2bm(x[0]) ; }
^
Error in : Can’t compile function TFormula____id4664759779193443662 prototype with arguments Double_t
Error in < TFormula::InputFormulaIntoCling >: Error compiling formula expression in Cling
Error in < TFormula::ProcessFormula >: Formula “chi2_p2bm(x)” is invalid !
%
Here is the code:
#include <TObject.h>
#include <TROOT.h>
#include <TClass.h>
#include <TError.h>
#include <TMath.h>
#include <TH1.h>
#include <TH2.h>
#include <TH3.h>
#include <TF1.h>
#include <TGraphErrors.h>
#include <TCanvas.h>
#include <TMinuit.h>
#include <TStyle.h>
#include <TPaveText.h>
#include <TPaveLabel.h>
#include <TLegend.h>
#include <TMatrixD.h>
#include <TFormula.h>
using namespace std;
double chi2_p2bm(double x) {
return pow(x,2);
}
int main()
{
cout << chi2_p2bm(.15) << endl;
cout << chi2_p2bm(.16) << endl;
cout << chi2_p2bm(.17) << endl;
cout << chi2_p2bm(.18) << endl;
TCanvas *c1 = new TCanvas("c1", "",1900,1100);
// c1->Divide(5,1);
// c1->cd(1);
TF1 *fp2bm = new TF1("fp2bm","chi2_p2bm(x)",0.1,0.3);
// fp2bm->Draw();
// c1->Print(“chi2.pdf”);
}