How to fit the data by integral function

Dear rooter,

I have a question about the fitting by ROOT.
I have several Au+Au collision data and I have to fit these data by the function.
The function is integral [from 0.0, to 13.0] (func)
(func) function includes I0 and K1 (modified Bessel functions).

[code]example…
.
.
.
Double_t bwfitfunc(Double_t *x, Double_t *par)
{
// *x is Pt in this case.
// par[0] = alpha;
// par[1] = Tf;
// par[2] = beta;

Double_t arg = 0.0;
Double_t out;

Double_t mass = 0.1395679;
Double_t mt = x[0] + mass;  
Double_t con = 1023.0; 

Double_t rho = TMath::ATanH(par[2]*pow(x[0]/13.0, par[0]));
Double_t pt = sqrt(mt*mt - mass*mass);

// Double_t temp = param[5];

out = con * x[0]
		* TMath::BesselI0(pt * TMath::SinH(rho)/par[1])
		* TMath::BesselK1(mt * TMath::CosH(rho)/par[1]);
return out;

}

I could fit by bwfitfunc, but I need the integral of this bwfitfunc and fit it!
So, I created this function, integralfunc() including bwfitfunc().
.
.
Double_t integralfunc()
{
Double_t integral;
Double_t radius = 13.0; // radius = 13.0 fm (Rmax)

TF1 *funcx = new TF1("funcx", bwfitfunc, 0.0, radius+2.0, 3);
integral = funcx->Integral(0.0, radius);

return integral;

}

After that how to fit the data by this integralfunc()???


func->SetParameter(2, 0.75); // beta
func->SetParameter(1, 0.118); // temp.
func->SetParameter(0, 0.398); // alpha

//Need parameter limits. Otherwise I end up with negative Bessel
//functions.
func->SetParLimits(2, 0.2, 0.95);	//	beta
func->SetParLimits(1, 0.01, 0.2);	//	temp.

// func->SetParLimits(0, 0.398, 0.398); // alpha
func->SetParLimits(0, 0.390, 0.400); // alpha

gr->Fit("bwfitfunc");

// gr->Fit(“integralfunc”);
gr->Draw(“same”);
…[/code]

works, but

gr->Fit("integralfunc"); does not work. I think I am missing TF1 *func commands or other implementations. Would you help me by showing simple examples how to fit the function by integral functions?

Thank you!

1 Like

Hi,

you need to create an instance of the TF1 class using the integral of your original function.
An example to do that is in the tutorial exampleFunctor.C,

see

root.cern.ch/viewvc/trunk/tutori … iew=markup

Regards

Lorenzo

Hi,

Thank you for the message. But I am not familiar about “instance”.

you need to create an instance of the TF1 class using the integral of your original function.
What does it mean?

from your reference,

// function class with a member function
struct MyIntegFunc {
MyIntegFunc(TF1 * f): fFunc(f) {}

Do I need this MyIntegFunc(TF1 *f)… sentences?
MyIntegFunc(TF1 * f): fFunc(f) {}

Thank you!

Hi,

in order to fit your data with the integral of bwfitfunc, you need to create a new TF1 object (or instance) which when is evaluated computes this integral.
If your original function, bwfitfunc is represented by a TF1 object, you can construct the integral function using the pointer to that object.

I more detail if you have your original funciton (integrand) defined as

Double_t bwfitfunc(Double_t *x, Double_t *par) 
{ 
   ...............
}

You can define a class (or structure) representing the integral of that function as follows

// structure representing the integral of a function  between 0 and radius 
struct MyIntegFunc() { 

   // constructor using the TF1 pointer
   MyIntegFunc(TF1 * f): 
      fFunc(f) {}

   // evaluate the function (is it independent of x ???)
   double operator() (double * /*x */, double *p) const { 
      double radius = 13.0;   //   radius = 13.0 fm (Rmax)
      return fFunc->Integral(a, radius, p);
   }

   TF1 * fFunc; // pointer to the integrand function
};

// integrand function
TF1 *funcx = new TF1("funcx", bwfitfunc, 0.0, radius+2.0, 3);
// integral function of funcx

TF1 * ifuncx = new TF1("ifuncx", new MyIntegFunc(funcx), 0.0, radius +2.,3, "MyIntegFunc"); 

and then use directly ifuncx for fitting your data

Best Regards

Lorenzo

Hi,

Thank you for the message and I implimented the code such as MyIntegFunc(){…}.
But, I see error message,

Error: Symbol MyIntegFunc is not defined in current scope bwfit02.C:255:

What is the meaning?
I created

struct MyIntegFunc()
{

(as you mention)

};

TF1 *funcx = new … ;
TF1 *ifuncx = new … ;

and

gr->Fit(“ifuncx”); // for fitting

Do I need extra TF1 *MyIntegFunc()… statement?
Thank you!

You need to put the definition of MyIntegFunc.
Please attach the code so I can tell you how to fix it,

Lorenzo

Hi,

I attached the code. Would you check the code for me?

In addition, would you explain how to use “gMINUIT” package?
I am trying and having error the package as you see in the code.

Thnak you so much!
bwfit02.C (10.3 KB)

There were few C++ errors in the code. Attached is the updated one, it should run, I would need the data file to test it.
However, I don’t understand your integral fitting funcition. It seems to me it has not any dependency on x. This is equivalent to fit your data to a constant line, I don’t think what you want to fit.

For performing a fit using directly MINUIT, you can see the tutorial example
tutorials/fit/Ifit.C :

root.cern.ch/root/html/examples/Ifit.C.html

Regards

Lorenzo
bwfit02.C (10.6 KB)

Thank you for the reply. It does not run, however.

The error message is same as before,

***** command line screen message *****
[tsuchiya@kunuc8 minuit]$ root -l
root [0] .L bwfit03.C
root [1] fitexample();

    Number of data
    index = 17

    0.25    277.15          0       6.27
    0.35    190.05          0       2.72
    0.45    112.2           0       1.36
    0.55    70.24           0       0.75
    0.65    45.53           0       0.46
    0.75    29.16           0       0.32
    0.85    19.09           0       0.23
    0.95    12.84           0       0.17
    1.05    8.54            0       0.13
    1.15    5.73            0       0.1
    1.25    3.99            0       0.08
    1.35    2.76            0       0.06
    1.45    1.84            0       0.05
    1.55    1.23            0       0.04
    1.65    0.92            0       0.03
    1.75    0.66            0       0.03
    1.85    0.48            0       0.02

TCanvas::MakeDefCanvas: created default TCanvas with name c1
Error: Symbol MyIntegFunc is not defined in current scope bwfit03.C:159:
Error: Symbol MyIntegFunc is not defined in current scope bwfit03.C:159:
Error: type MyIntegFunc not defined FILE:/home/tsuchiya/analysis/blastwave/minuit/./bwfit03.C LINE:159
Warning: Automatic variable MyIntegFuncinteg is allocated bwfit03.C:159:
Error: Undeclared variable MyIntegFunc
integ bwfit03.C:159:
*** Interpreter error recovered ***
root [2] .q

***** end of the message *****

I attached “bwfit03.C” and “piplus.txt” sample data file with this message.
Please check it!
I need to define “MyIntegFunc” as a function or TF1 not only structure, “struct”, but how?
piplus.txt (409 Bytes)
bwfit03.C (5.82 KB)

I attached the other file which mentions blastwave fuction and I want to fit the data by this integral function.
Yes, you are right. I want to integral by R(Rmax) and not fixed integral.
So, in your code

struct MyIntegFunc
{


double operator() (double *x, double *p) const


}

How can I modify this code?

Thank you!
blastwavefunc.doc (28 KB)
blastwavefunc.doc (28 KB)

I attached same file twice, sorry!

Hi,
there are still some compilation errors in your macro. You should compile it with ACLIC:

root> .L bwfit03.C+

You should start from the one I attached before.

Anyway I think your definition of the integrand function is incorrect. What exactly is the x variable of the graph, the pt ?
You should define the integrand function in term of r (with is the double *x variable of TF1) and make pt one parameter and then the fitted function, a function of pt.

Best Regards

Lorenzo

Hi,

I compiled the code you attached before, but I cannot compile it.
See the message below:

[tsuchiya@kunuc8 minuit]$ root -l
root [0] .L bwfit02_2.C+
Info in TUnixSystem::ACLiC: creating shared library /home/tsuchiya/analysis/blastwave/minuit/./bwfit02_2_C.so
In file included from /home/tsuchiya/analysis/blastwave/minuit/fileF5oEnR.h:32,
from /home/tsuchiya/analysis/blastwave/minuit/fileF5oEnR.cxx:16:
/home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C: In function Double_t bwfitfunc(Double_t*, Double_t*)': /home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C:95: warning: unused variableDouble_t arg’
In file included from /home/tsuchiya/analysis/blastwave/minuit/fileF5oEnR.h:32,
from /home/tsuchiya/analysis/blastwave/minuit/fileF5oEnR.cxx:16:
/home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C: In function void fitexample()': /home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C:341: warning: unused variableDouble_t parameter’
/home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C:341: warning: unused
variable Double_t erro' /home/tsuchiya/analysis/blastwave/minuit/fileF5oEnR.cxx: In functionint
G__fileF5oEnR__0_1096(G__value*, const char*, G__param*, int)’:
/home/tsuchiya/analysis/blastwave/minuit/fileF5oEnR.cxx:235: aggregate value
used where an integer was expected
g++: /home/tsuchiya/analysis/blastwave/minuit/./fileF5oEnR.o: No such file or directory
Error in : Compilation failed!
root [1]

The warning are fine, but I don’t understand the error messages.
Would you tell me how to fix them?
Thank you for your many replys.

Remove the line of code:

        gROOT -> Reset();

It is not needed for a named macro

Lorenzo

Hi,

just to clarify: it MUST NOT BE USED in a named macro! As soon as you have one single function in the file it must not contain gROOT->Reset().

Cheers, Axel.

Thank you for all of you,

I could compile this, but would you tell me how to use it after compiling?
I see “bwfit02_2_C.so” file.
What is “bwfit02_2_C.d” file?

In addition,

just to clarify: it MUST NOT BE USED in a named macro!
What does it mean? Would you explain about it to use the example?

to compile:

root >.L bwfit02.C+

to run just call the main function defined in bwfit02.C

root > fitexample()

Or you can renamed your macro as fitexample.C and simply do for compiling and running at the same time

root >.x fitexample.C+

Lorenzo

Hi,

Thank you for your answer, however, I see the error messages.

root [0] .L bwfit02_2.C+
Info in TUnixSystem::ACLiC: creating shared library /home/tsuchiya/analysis/blastwave/minuit/./bwfit02_2_C.so
In file included from /home/tsuchiya/analysis/blastwave/minuit/fileB9K84W.h:32,
from /home/tsuchiya/analysis/blastwave/minuit/fileB9K84W.cxx:16:
/home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C: In function Double_t bwfitfunc(Double_t*, Double_t*)': /home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C:95: warning: unused variable Double_t arg’
In file included from /home/tsuchiya/analysis/blastwave/minuit/fileB9K84W.h:32,
from /home/tsuchiya/analysis/blastwave/minuit/fileB9K84W.cxx:16:
/home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C: In function void fitexample()': /home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C:341: warning: unused variable Double_t parameter’
/home/tsuchiya/analysis/blastwave/minuit/bwfit02_2.C:341: warning: unused
variable `Double_t erro’
root [1] fitexample();

*** Break *** segmentation violation
Attaching to program: /proc/21571/exe, process 21571
[New Thread 1087239328 (LWP 21571)]
0xffffe002 in ?? ()
Thread 1 (Thread 1087239328 (LWP 21571)):
#0 0xffffe002 in ?? ()
#1 0x4203f864 in do_system () from /lib/tls/libc.so.6
#2 0x40cad6ef in system () from /lib/tls/libpthread.so.0
#3 0x401c8757 in TUnixSystem::Exec(char const*) () from /usr/local/root/lib/libCore.so
#4 0x401c8b3c in TUnixSystem::StackTrace() () from /usr/local/root/lib/libCore.so
#5 0x401c698d in TUnixSystem::DispatchSignals(ESignals) () from /usr/local/root/lib/libCore.so
#6 0x401c4ad9 in SigHandler(ESignals) () from /usr/local/root/lib/libCore.so
#7 0x401cb2f5 in sighandler(int) () from /usr/local/root/lib/libCore.so
#8
#9 0x40c507ed in void std::__convert_to_v(char const*, double&, std::_Ios_Iostate&, __locale_struct* const&, int) () from /usr/lib/libstdc++.so.5
#10 0x40c20280 in std::num_get<char, std::istreambuf_iterator<char, std::char_traits > >::do_get(std::istreambuf_iterator<char, std::char_traits

, std::istreambuf_iterator<char, std::char_traits >, std::ios_base&, std::_Ios_Iostate&, double&) const () from /usr/lib/libstdc++.so.5
#11 0x40c0f738 in std::istream::operator>>(double&) () from /usr/lib/libstdc++.so.5
#12 0x415c7321 in readfile() () from /home/tsuchiya/analysis/blastwave/minuit/./bwfit02_2_C.so
#13 0x415c794e in fitexample() () from /home/tsuchiya/analysis/blastwave/minuit/./bwfit02_2_C.so
#14 0x415c854e in G__fileB9K84W__0_1099(G__value*, char const*, G__param*, int) () from /home/tsuchiya/analysis/blastwave/minuit/./bwfit02_2_C.so
#15 0x4068ade7 in Cint::G__ExceptionWrapper(int ()(G__value, char const*, G__param*, int), G__value*, char*, G__param*, int) ()
from /usr/local/root/lib/libCint.so
#16 0x4072bea5 in G__call_cppfunc () from /usr/local/root/lib/libCint.so
#17 0x4071b2bf in G__interpret_func () from /usr/local/root/lib/libCint.so
#18 0x40707c5d in G__getfunction () from /usr/local/root/lib/libCint.so
#19 0x406fdf0e in G__getitem () from /usr/local/root/lib/libCint.so
#20 0x406f3e9b in G__getexpr () from /usr/local/root/lib/libCint.so
#21 0x4074574f in G__exec_function () from /usr/local/root/lib/libCint.so
#22 0x4074c8b1 in G__exec_statement () from /usr/local/root/lib/libCint.so
#23 0x406e308a in G__exec_tempfile_core () from /usr/local/root/lib/libCint.so
#24 0x406e32ac in G__exec_tempfile_fp () from /usr/local/root/lib/libCint.so
#25 0x40753ce4 in G__process_cmd () from /usr/local/root/lib/libCint.so
#26 0x4019c54e in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /usr/local/root/lib/libCore.so
#27 0x40116fe7 in TApplication::ProcessLine(char const*, bool, int*) () from /usr/local/root/lib/libCore.so
#28 0x40b95e8a in TRint::HandleTermInput() () from /usr/local/root/lib/libRint.so
#29 0x40b947c4 in TTermInputHandler::Notify() () from /usr/local/root/lib/libRint.so
#30 0x40b96972 in TTermInputHandler::ReadNotify() () from /usr/local/root/lib/libRint.so
#31 0x401c6d9b in TUnixSystem::CheckDescriptors() () from /usr/local/root/lib/libCore.so
#32 0x401c60b0 in TUnixSystem::DispatchOneEvent(bool) () from /usr/local/root/lib/libCore.so
#33 0x40167af4 in TSystem::InnerLoop() () from /usr/local/root/lib/libCore.so
#34 0x40167a98 in TSystem::Run() () from /usr/local/root/lib/libCore.so
#35 0x40117d6a in TApplication::Run(bool) () from /usr/local/root/lib/libCore.so
#36 0x40b9586e in TRint::Run(bool) () from /usr/local/root/lib/libRint.so
#37 0x0804884a in main ()
#38 0x42015704 in __libc_start_main () from /lib/tls/libc.so.6
#0 0xffffe002 in ?? ()
Root >
root [2]

What should I fix for these problems?
I think it should be simple problem such as removing “gROOT->Reset():” line.

I attached the code which is same as previous your code bwfit02.C withoug “gROOT->Reset()” statement.
bwfit02_2.C (10.6 KB)

It seems to me you are having a problem reading the data file.
However I cannot reproduce your error on my computer

Hi,

I input the data in the code directory since you mentioned about a problem reading the data file. See the attached file.
I could compile the code, but it does not RUN and I see error messages.


[tsuchiya@kunuc8 minuit]$ root -l
root [0] .L bwfit02_3.C+
Info in TUnixSystem::ACLiC: creating shared library /home/tsuchiya/analysis/blastwave/minuit/./bwfit02_3_C.so
In file included from /home/tsuchiya/analysis/blastwave/minuit/fileyUiT9o.h:32,
from /home/tsuchiya/analysis/blastwave/minuit/fileyUiT9o.cxx:16:
/home/tsuchiya/analysis/blastwave/minuit/bwfit02_3.C: In function Double_t bwfitfunc(Double_t*, Double_t*)': /home/tsuchiya/analysis/blastwave/minuit/bwfit02_3.C:126: warning: unused variableDouble_t arg’
In file included from /home/tsuchiya/analysis/blastwave/minuit/fileyUiT9o.h:32,
from /home/tsuchiya/analysis/blastwave/minuit/fileyUiT9o.cxx:16:
/home/tsuchiya/analysis/blastwave/minuit/bwfit02_3.C: In function void fitexample()': /home/tsuchiya/analysis/blastwave/minuit/bwfit02_3.C:372: warning: unused variableDouble_t parameter’
/home/tsuchiya/analysis/blastwave/minuit/bwfit02_3.C:372: warning: unused
variable `Double_t erro’
root [1] fitexample();

    Number of data
    index = 17
                                                                                                                                                         
    0.25    277.15          0       6.27
    0.35    190.05          0       2.72
    0.45    112.2           0       1.36
    0.55    70.24           0       0.75
    0.65    45.53           0       0.46
    0.75    29.16           0       0.32
    0.85    19.09           0       0.23
    0.95    12.84           0       0.17
    1.05    8.54            0       0.13
    1.15    5.73            0       0.1
    1.25    3.99            0       0.08
    1.35    2.76            0       0.06
    1.45    1.84            0       0.05
    1.55    1.23            0       0.04
    1.65    0.92            0       0.03
    1.75    0.66            0       0.03
    1.85    0.48            0       0.02

TCanvas::MakeDefCanvas: created default TCanvas with name c1


** 5 **MIGRAD 5000 0


MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
MIGRAD MINIMIZATION HAS CONVERGED.
FCN=6.24419e-06 FROM MIGRAD STATUS=CONVERGED 88 CALLS 89 TOTAL
EDM=8.61689e-09 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 12.1 per cent
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 3.90335e-01 6.07997e-03 3.84620e-06 -5.57301e-09
2 p1 2.30260e-02 1.43273e-01 -2.23792e-01 2.21857e-04
3 p2 6.44994e-01 5.86487e-01 -4.58544e-04 3.82303e-07
FCN=6.24419e-06 FROM MIGRAD STATUS=CONVERGED 88 CALLS 89 TOTAL
EDM=8.61689e-09 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 12.1 per cent
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 3.90335e-01 6.07997e-03 3.84620e-06 -5.57301e-09
2 p1 2.30260e-02 1.43273e-01 -2.23792e-01 2.21857e-04
3 p2 6.44994e-01 5.86487e-01 -4.58544e-04 3.82303e-07

*** Break *** segmentation violation
Attaching to program: /proc/22166/exe, process 22166
[New Thread 1087239328 (LWP 22166)]
0xffffe002 in ?? ()
Thread 1 (Thread 1087239328 (LWP 22166)):
#0 0xffffe002 in ?? ()
#1 0x4203f864 in do_system () from /lib/tls/libc.so.6
#2 0x40cad6ef in system () from /lib/tls/libpthread.so.0
#3 0x401c8757 in TUnixSystem::Exec(char const*) () from /usr/local/root/lib/libCore.so
#4 0x401c8b3c in TUnixSystem::StackTrace() () from /usr/local/root/lib/libCore.so
#5 0x401c698d in TUnixSystem::DispatchSignals(ESignals) () from /usr/local/root/lib/libCore.so
#6 0x401c4ad9 in SigHandler(ESignals) () from /usr/local/root/lib/libCore.so
#7 0x401cb2f5 in sighandler(int) () from /usr/local/root/lib/libCore.so
#8
#9 0x415c7456 in fitexample() () from /home/tsuchiya/analysis/blastwave/minuit/./bwfit02_3_C.so
#10 0x415c7c02 in G__fileyUiT9o__0_1099(G__value*, char const*, G__param*, int) () from /home/tsuchiya/analysis/blastwave/minuit/./bwfit02_3_C.so
#11 0x4068ade7 in Cint::G__ExceptionWrapper(int ()(G__value, char const*, G__param*, int), G__value*, char*, G__param*, int) ()
from /usr/local/root/lib/libCint.so
#12 0x4072bea5 in G__call_cppfunc () from /usr/local/root/lib/libCint.so
#13 0x4071b2bf in G__interpret_func () from /usr/local/root/lib/libCint.so
#14 0x40707c5d in G__getfunction () from /usr/local/root/lib/libCint.so
#15 0x406fdf0e in G__getitem () from /usr/local/root/lib/libCint.so
#16 0x406f3e9b in G__getexpr () from /usr/local/root/lib/libCint.so
#17 0x4074574f in G__exec_function () from /usr/local/root/lib/libCint.so
#18 0x4074c8b1 in G__exec_statement () from /usr/local/root/lib/libCint.so
#19 0x406e308a in G__exec_tempfile_core () from /usr/local/root/lib/libCint.so
#20 0x406e32ac in G__exec_tempfile_fp () from /usr/local/root/lib/libCint.so
#21 0x40753ce4 in G__process_cmd () from /usr/local/root/lib/libCint.so
#22 0x4019c54e in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /usr/local/root/lib/libCore.so
#23 0x40116fe7 in TApplication::ProcessLine(char const*, bool, int*) () from /usr/local/root/lib/libCore.so
#24 0x40b95e8a in TRint::HandleTermInput() () from /usr/local/root/lib/libRint.so
#25 0x40b947c4 in TTermInputHandler::Notify() () from /usr/local/root/lib/libRint.so
#26 0x40b96972 in TTermInputHandler::ReadNotify() () from /usr/local/root/lib/libRint.so
#27 0x401c6d9b in TUnixSystem::CheckDescriptors() () from /usr/local/root/lib/libCore.so
#28 0x401c60b0 in TUnixSystem::DispatchOneEvent(bool) () from /usr/local/root/lib/libCore.so
#29 0x40167af4 in TSystem::InnerLoop() () from /usr/local/root/lib/libCore.so
#30 0x40167a98 in TSystem::Run() () from /usr/local/root/lib/libCore.so
#31 0x40117d6a in TApplication::Run(bool) () from /usr/local/root/lib/libCore.so
#32 0x40b9586e in TRint::Run(bool) () from /usr/local/root/lib/libRint.so
#33 0x0804884a in main ()
#34 0x42015704 in __libc_start_main () from /lib/tls/libc.so.6
#0 0xffffe002 in ?? ()
Root >
root [2]

How can I fix these problems?
bwfit02_3.C (11.6 KB)