Formula not properly initialized

Please enlighten me on this one.
This code gave an error “formula not properly initialized”.

#include "TF1.h"
#include "Math/WrappedTF1.h"
#include "Math/GaussIntegrator.h"
#include <TGraph.h>
#include <TMultiGraph.h>

void sample()
{
double E = 10.0;
double al = 0.00729927;
double k = gRandom -> Gaus(E,1);
double sth = gRandom -> Uniform(-1,1);
double v = gRandom -> Gaus(4,4);

f1 = new TF1("f1", "([0]*[0]*(1 - [1]*[1]) / (4*x*x*[1]*[1]*[1]*[1])", 0, E);
f1->SetParameter(0,al);
f1->SetParameter(1,sth);
f1->SetLineColor(kBlue+2);
f1->SetLineWidth(3);
f1->SetTitle("Title; X; Y");
f1->Draw();
}

Thanks, Jaybee

the correct program.

#include “TF1.h”
#include “Math/WrappedTF1.h”
#include “Math/GaussIntegrator.h”
#include <TGraph.h>
#include <TMultiGraph.h>

void sample()
{
double E = 10.0;
double al = 0.00729927;
double k = gRandom -> Gaus(E,1);
double sth = gRandom -> Uniform(-1,1);
double v = gRandom -> Gaus(4,4);

f1 = new TF1(“f1”, “([0]*[0]*(1 - [1]*[1]) / (4*x*x*[1]*[1]*[1]*[1])”, 0, E);
f1->SetParameter(0,al);
f1->SetParameter(1,sth);
f1->SetLineColor(kBlue+2);
f1->SetLineWidth(3);
f1->SetTitle(“Title; X; Y”);
f1->Draw();
}

the asterisks wouldn’t show in the formula.

Use three ``` not ‘’’ (see your edited posts).

thanks… i am figuring them out from a spanish keyoard :slight_smile: i’m sorry…

TF1 *f1 = new TF1("f1", "([0]*[0]*(1. - [1]*[1]) / (4.*x*x*[1]*[1]*[1]*[1]))", 0., E);
#include "TF1.h"
#include "Math/WrappedTF1.h"
#include "Math/GaussIntegrator.h"
#include <TGraph.h>
#include <TMultiGraph.h>

void sample()
{
double E = 10.0;
double al = 0.00729927;
double k = gRandom -> Gaus(E,1);
double sth = gRandom -> Uniform(-1,1);
double v = gRandom -> Gaus(4,4);

f1 = new TF1("f1", "([0]*[0]*(1 - [1]*[1]) / (4*x*x*[1]*[1]*[1]*[1])", 0, E);
f1->SetParameter(0,al);
f1->SetParameter(1,sth);
f1->SetLineColor(kBlue+2);
f1->SetLineWidth(3);
f1->SetTitle("Title; X; Y");
f1->Draw();
}

thank you Wile :slight_smile:

this is the new error message:

input_line_63:1:141: error: expected ')'
  ...return (p[0]*p[0]*(1.0-p[1]*p[1])/(4.0*x[0]*x[0]*p[1]*p[1]*p[1]*p[1]) ; }
                                                                           ^
input_line_63:1:78: note: to match this '('
  ...TFormula____id12623564732164165984(Double_t *x,Double_t *p){ return (p[0...
                                                                         ^
Error in <TFormula::Eval>: Can't find TFormula____id12623564732164165984 function prototype with arguments Double_t*,Double_t*
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
Error in <TFormula::Eval>: Formula is invalid or not properly initialized - try calling TFormula::Compile

got it… figured it out :slight_smile:

how do you make the plot to have a logarithm scale in the y-axis?
I tried f1->SetLogy(); but it did not work :slight_smile:

After drawing, execute: gPad->SetLogy(1);

thank you Wile… :slight_smile:

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