I want to see what the output of a certain predifined function will look (eg Erf(x) or Freq(x)).
I tried to simply just construct a function, then draw it, but that doesn’t seem to work:
MY SCRIPT #include <TF1.h> #include <TMath.h>
int Freqfit
{
Double_t Freq(Double_t x);
TF1 *f1 = new TF1(“f1”, “Freq(x)”, -10,10);
f1->Draw();
return(0);
}
I load and execute in root simply by:
[root] .x pathname/Freqfit.C
Hi,
in your first try you didn’t ever reference TMath::Freq. You defined your own Freq, but local in your method (which is invalid under C++). I don’t think TF1::TF1 will see it - and it shouldn’t. Note that you called “Freq”, not “TMath::Freq”. Those two are completely different - including TMath.h makes TMath::Freq known to the compiler, but that doesn’t mean Freq will get TMath:: prepended (for that you’d have to use “using namespace TMath;” - but that worn’t work for TF1::TF1). In your second example you did everything right - you’re calling the function with its namespace prepended, so TF1 knows what function you’re talking about.
O, and you also forgot the “()” behind your function name Freqfit, i.e. your code should be#include "TF1.h"
#include "TMath.h"
int Freqfit()
{
TF1 *f1 = new TF1("f1", "TMath::Freq(x)", -10,10);
f1->Draw();
return(0);
}Axel.
thanks for that explanation. Makes ‘sense’ I guess. Now I have another question. I was looking up the TF1 class in the Root Reference guide, and an example of a type A2 function is:
TF1 *fa2 = new TF1("fa2","TMath::DiLog(x)",0,10);
fa2->Draw();
I plotted that, but root gives me an error about DiLog being an unknown name, and how it has 0 parameters instead of 1 …
and then displays an empty histogram.
When i start root it says: Version 3.05/07 25 March 2004
If its a version problem => ? … i mean do i have to have root access to Linux or can anyone upgrade?
I also get error messages for the A3 type example now … this time when compiling it.
//my complete script
#include <TF1.h>
#include <TMath.h>
#include <TCanvas.h>
int check()
{
TCanvas *can = new TCanvas("can","predefined functions",1200,400);
can -> Divide(3,1);
//type A2 ... works
TF1 *f2 = new TF1("f2", "TMath::Erf(x)", -10, 10);
can->cd(1);
f2->Draw();
//type A2 ... compiles ok, but doesn't work: unknown function error msg and empty plot
TF1 *fa2 = new TF1("fa2","TMath::DiLog(x)",0,10);
can->cd(2);
fa2->Draw();
//type A3 ... doesn't compile: undeclared x and parse errors
Double_t myFunc(x)
{
return x+sin(x);
}
TF1 *fa3 = new TF1("fa3","myFunc(x)",-3,5);
can->cd(3);
fa3->Draw();
return(0);
}
TMath::DiLog was only implemented in ROOT 4.02/00. So this is the problem
You do not need root priviledge to compile and install a new version of ROOT.
See root.cern.ch/root/Install.html
So is the version problem also the reason why the A3 type function doesn’t work?
I followed the links to download version 4.03/03 using binary file transfer. got ftp acces, but the point after i ‘get’ the file I get a message saying ‘Entering passive mode, file not opened’.
the command i used was: (were)
get root-v4_03.03.source.tar.gz
get root-v4-03-03.source.tar.gz
… amongst others. basically, exactly how am i supposed to enter the version correctly?
[quote]So is the version problem also the reason why the A3 type function doesn’t work? [/quote]No it is not. I missed that problem.
The issue is that your function declaration is not properly located. Move it outside of the body of the function check.
I can’t reproduce your problem with downloading. I recommend that you use the CVS method (instead of ftp).
[quote=“no1else”]So is the version problem also the reason why the A3 type function doesn’t work?[/quote] No, the reason for that is defining a function (myFunc) inside a function body (check), which is ill-formed in C++.
[quote=“no1else”]I followed the links to download version 4.03/03 using binary file transfer. got ftp acces, but the point after i ‘get’ the file I get a message saying ‘Entering passive mode, file not opened’.[/quote] You use a strange FTP client, or you have a strange firewall in front of you. Try e.g. Firefox with this link: ftp://root.cern.ch/root/root_v4.03.03.source.tar.gz.
when i click on the link I get a ‘failed to change directory’ Alert from Mozilla.
Anyway, I don’t need the DiLog function … I was just trying out the examples on the TF1 constructor, so I don’t think I’ll bother with dowloading with CVS method either, Philippe.
Everything else seems to work ok… after i moved the function out of the function , and what I’m actually trying to do is write a function made up of two gaussians: gaus1 with sigma1 up until the mean, then gaus2 with sigma2 after the mean. U see I’m trying to fit a tdc spectra (time output from drift chamber) which is non uniform