Set parameters

Hi, I’m evaluating a function and I set the parameters with:

    fitlogpoi->SetParameters(1,1,1,1);
    fitres = fitlogpoi->Eval(bin,xbin);

but if I try to pass the parameters with a variable the evaluation is different.

  Double_t par1=1,par2=1,par3=1,par4=1;
    fitlogpoi->SetParameters(par1,par2,par3,par4);
    fitres = fitlogpoi->Eval(bin,xbin);

Hope you have some hint.

First question: How can I set the parameters with variables?
I know there must be something wrong with the way I pass the arguments.
Second question: Why it doesn’t work the way I’m using?
I used to do this with PAW.
Cheers

Could you post the shortest possible RUNNING script showing what you are doing?
In particular it is hard to understand if your function is a TF1 or TF2.
If it is a TF1, then Eval expects only one argument f(x). What do you mean by bin,xbin? there is no “bin” for a TF1

Rene

Hi, I have a TF2 function and I do not have problems evaluating it, everything works fine, here is that part of my code:

  TF2 *fitlogpoi = new TF2("fitlogpoi", logpoisson,0,0,0,0,4);
  TF1 *fitfunc = new TF1("fitfunc", myfcn4,0,0,4);

  Double_t *xbin = gr->GetX();

  Double_t fitres;
  Double_t fitlog=0;
  Double_t logsum;
  Double_t dlldp1=0,d2lldp21=0;
  Double_t dlldp2=0,d2lldp22=0;
  Double_t dlldp3=0,d2lldp23=0;
  Double_t dlldp4=0,d2lldp24=0;
  Double_t delta1;
  Double_t inifit1,inifit2,inifit3,inifit4;
  Double_t A1Bi,A1Pb,A1Ra,A1Th;
  Double_t totfit;
  Double_t bin;
  Double_t par1=1,par2=1,par3=1,par4=1;
  
  for (Int_t i=0;i<var1;i++){

    if (i==35) {xbin[i]=5;}

    //Vetoed events
    if (i==239) {xbin[i]=-1;}
    if (i==290) {xbin[i]=-1;}

    if (xbin[i] > -1){

    //log sum
    //--------------------------------
    logsum=0;
    for (Int_t j=1;j<=xbin[i];j++) {
      logsum = logsum + TMath::Log(j);
    }
    
    bin=i+1;

    //fit poisson
    //-------------------------------
    fitlogpoi->SetParameters(par1,par2,par3,par4);
    fitres[i] = fitlogpoi->Eval(bin,xbin[i]);
    fitlog = fitlog + fitres[i] - logsum;
   
 
    fitfunc->SetParameters(1,1,1,1);
    totfit[i] = fitfunc->Eval(bin);
    
   //fit one by one params
    //----------------------------------
    fitfunc->SetParameters(par1,0,0,0);
    inifit1 = fitfunc->Eval(bin);
    dlldp1 = dlldp1 + ( inifit1 * ( 1 - ( xbin[i] / totfit[i] ) ) );
    d2lldp21 = d2lldp21 + ( inifit1 * inifit1 * xbin[i] / ( totfit[i] * totfit[i] ) );
    delta1 = - dlldp1 / d2lldp21;
    
    fitfunc->SetParameters(0,par2,0,0);
    inifit2 = fitfunc->Eval(bin);
    dlldp2 = dlldp2 + ( inifit2 * ( 1 - ( xbin[i] / totfit[i] ) ) );
    d2lldp22 = d2lldp22 + ( inifit2 * inifit2 * xbin[i] / ( totfit[i] * totfit[i] ) );
    delta2 = - dlldp2 / d2lldp22;
    
    fitfunc->SetParameters(0,0,par3,0);
    inifit3 = fitfunc->Eval(bin);
    dlldp3 = dlldp3 + ( inifit3 * ( 1 - ( xbin[i] / totfit[i] ) ) );
    d2lldp23 = d2lldp23 + ( inifit3 * inifit3 * xbin[i] / ( totfit[i] * totfit[i] ) );
    delta3 = - dlldp3 / d2lldp23;

    fitfunc->SetParameters(0,0,0,par4);
    inifit4 = fitfunc->Eval(bin);
    dlldp4 = dlldp4 + ( inifit4 * ( 1 - ( xbin[i] / totfit[i] ) ) );
    d2lldp24 = d2lldp24 + ( inifit4 * inifit4 * xbin[i] / ( totfit[i] * totfit[i] ) );
    delta4 = - dlldp4 / d2lldp24;
    
    par1=par1+delta1;
    par2=par2+delta2;
    par3=par3+delta3;
    par4=par4+delta4;

   
 }
  
  }

The problems are by setting the parameters with variables instead of the numbers:

 fitlogpoi->SetParameters(1,1,1,1);

and

  Double_t par1=1,par2=1,par3=1,par4=1;
  fitlogpoi->SetParameters(par1,par2,par3,par4);

Cheers

Let me reiterate my request:

[quote]Could you post the shortest possible RUNNING script showing what you are doing?
[/quote]
Rene

Hi, sorry, I attached my anal.C analysis code.
This is the makefile:

version := v1

subj=betaalpha-$(version)
file=demolwa
read=readascii
source=calibration
anal=anal
out1=time
out2=filo
out3=tail
out4=cph
channel=5
chain=Th
hours=300

$(source)-$(out1).eps: $(anal).C $(file).root
	root -b -q '$(anal).C("$(file).root",$(channel),"$(chain)",$(hours),"$(source)-$(out4).eps")'

$(file).root: $(read).C $(file).txt
	root -b -q '$(read).C("$(file).txt","$(file).root")'

Also sorry about the mess in the code. I don’t know if it is too much important.
Again I emphasize in the set parameters part.
demolwa.txt (468 KB)
readascii.C (1.26 KB)
anal.C (9.95 KB)

Could you post the steeering script calling the function Anal ?

Rene

Hi, readascii.C and anal.C are called by Makefile.
I put the Makefile in the reply.
[/code]


version := v1

subj=betaalpha-$(version)
file=demolwa
read=readascii
source=calibration
anal=anal
out1=time
out2=filo
out3=tail
out4=cph
channel=5
chain=Th
hours=300

$(source)-$(out1).eps: $(anal).C $(file).root
   root -b -q '$(anal).C("$(file).root",$(channel),"$(chain)",$(hours),"$(source)-$(out4).eps")'

$(file).root: $(read).C $(file).txt
   root -b -q '$(read).C("$(file).txt","$(file).root")' 

You had many fatal errors in your code. I tried to repair most of them.
Check the code in attachment

Rene
anal.C (10.7 KB)

Hi, thank you for your help. I noticed about the missing declarations after I sent you the code. About the arrays, I thought I had only to declare the variable and the array was open automatically, but now I know.

The code still gives me different values:

if you run with:

    fitlogpoi->SetParameters(par1,par2,par3,par4);

the results for the output is:
-1.10698e+06

while using:

[/code]
fitlogpoi->SetParameters(1,1,1,1);


the output is:
-410.047

which is the correct result.
You can check the difference by changing the variables by numbers.

Simply add a print statement before calling SetParameters and you will see that your parameters are not equal to 1, because you keep incrementing the variables par1, etc in the loop.

Rene

I am really stupid.
You are right.
Thank you for your time.