Hi,
I have a problem when trying to plot an function after having changed the
parameters. Either the Integral nor the plot change after calling
fun->SetParameters. Although, the parameters have been really modified
beacause I have checked it with GetParameters. Could somebody please give
me some hint about what I'm doing wrong?
Thanks a lot,
Daniel
PD this is the macro I using
#include <iostream.h>
Double_t PulseShape(Double_t *x, Double_t *par)
{
Double_t arg = 0;
Double_t val = 0;
if(x[0] < par[4])
{
val = par[0];
}
else if (x[0] >= par[4] & x[0] < par[5])
{
val = par[7]*x[0]+par[8];
}
else if (x[0] >= par[5] & x[0] < par[6])
{
val = par[9]*x[0]+par[10];
}
else if (x[0] >= par[6])
{
val = par[0] + par[2]*TMath::Exp( -(x[0]-par[6])/par[3] );
}
Double_t fitval = par[0]*TMath::Exp(-0.5*arg*arg);
return val;
}
int main()
{
gROOT->Reset();
const Int_t npar = 11;
Int_t i,j;
Double_t coeff[11];
Double_t mod_coeff[11];
Double_t Amplitude;
// Amplitude
Amplitude = -225.47;
// Define function coefficients
coeff[0]=0.0;
coeff[1]= Amplitude;
coeff[2]=coeff[1]/7.1915667;
coeff[3]=703.7;
coeff[4]=51.356;
coeff[5]=55.131;
coeff[6]=63.813;
coeff[7]=-coeff[1]/(coeff[4]-coeff[5]);
coeff[8]=coeff[0]-coeff[7]*coeff[4];
coeff[9]=(coeff[1]-coeff[2])/(coeff[5]-coeff[6]) ;
coeff[10]=coeff[0]+coeff[2]-coeff[9]*coeff[6];
for (i=0; i<npar; i++)
{
printf("The value of coefficient %d is %8f\n",i+1,coeff[i]);
}
TF1 *PulseShape = new TF1("PulseShape",PulseShape,-100.,100.,11);
PulseShape->SetParameters(coeff);
PulseShape->Draw();
//Modify one coefficient
gRandom->SetSeed();
coeff[1] = Amplitude*gRandom->Gaus(1.,0.5);
printf("The amplitude of the pulse is %8f\n",coeff[1]);
//Check that the coefficient was modified
for (i=0; i<npar; i++)
{
printf("The value of coefficient %d is %8f\n",i+1,coeff[i]);
}
PulseShape->SetParameters(coeff);
//Retrieve coefficients to see if the function has adopted them
PulseShape->GetParameters(mod_coeff);
for (i=0; i<npar; i++)
{
printf("The value of new coefficient %d is %8f\n",i+1,mod_coeff[i]);
}
//Plot the new function
PulseShape->Draw("same");
return 0;
}
-------------------------------------
Daniel Cano Ott
CIEMAT
Facet Group, Dept. of Nuclear Fission
Avda. Complutense 22
28040 Madrid
SPAIN
Tel: 34-913466000 Ext 6782 9:00 AM - 5:00 PM
34-913466123 After 5:00 PM
FAX: 34-913466576
http://fachp1.ciemat.es/daniel.html
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:33 MET