Re: Evaluateing functions with TF1::EvalPar

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Mar 06 1998 - 09:07:05 MET


I have modified the body of your macro below.
You were using TF1::EvalPar. This function requires a prior
initialisation of the parameters via TF1::InitArgs before calling it
in the case where the function is an interpreted function.
This feature is unfortunately not documented. I have put the info
in the new version of EvalPar. Thanks for reporting this anomaly.

Rene Brun


> {
  gROOT->Reset();
  gStyle->SetOptFit(1);
  gStyle->SetStatX(0.45);
  gStyle->SetStatY(0.85);


  TCanvas* c1 = new TCanvas("c1","Ntuple Plots",1); // create canvas
  c1->SetFillColor(kWhite);

  TFile* f1 = new TFile("cjj_g10.root","READ");
  TH1F* hi1 = new TH1F("hi1","Angular Resolution: Gamma Energy = 10 MeV
",80,-1.0,1.0);
  hi1->SetXTitle("Cos`q#");
  //  h509->Draw("Angres>>hi1","Egen>4&&Rfitt<600","goff"); 
  h503->Draw("(Ue*Uf+Ve*Vf+We*Wf)>>hi1","Rfit<600","goff"); 
  c1->SetLogy(1);
  TF1* expExp = new TF1("expExp",expExp,-1,1,4);
  expExp->SetParameters(9.2,0.2,5.7,17000);
  expExp->SetParNames("1st slope","2nd Amp","2nd slope","scale fac");
  Double_t x;
  Double_t y;
  printf("Hello\n");
  for( Int_t i=0 ; i<80 ; i++) {
    x = -0.9875+i*0.025;
    y = expExp->Eval(x);
    printf("%d\t%f\t%f\t%f\n",i,hi1->GetBinContent(i),x[0],y);
  }
  expExp->Draw();
  /*  expExp->SetParLimits(0,9.2,9.3);
  expExp->SetParLimits(1,0.2,0.21);
  expExp->SetParLimits(2,5.7,5.8);
  expExp->SetParLimits(3,17000.0,17100.0);

  TPostScript ps("cjj_g10.eps",114);
  hi1->Fit("expExp","RB");
  //  expExp->Draw();
  //  hi1->Draw("same");
  c1->Update();
  ps.Close();
  */

} 

>Chris Jillings wrote:
> Hi,
>    The follwing macro fails to calculate
> y = expExp->EvalPar(x,a);
> 
> At the prompt I type
> .L expExp.C
> .x cjj_g10.C
> 
> All values printed to screen for y are 0. Everything is printed
> correctly. Any ideas? Also, is it possible to subtract a function from a
> histgram to get the residuals of a fit, say. This feature would be very
> nice if it is not currently in place.
> 
> I am running 1.03/09 on a linux box.
> 
> Thanks,
> 
> Chris
> 
> The complete macro follows
> 
> {
>   gROOT->Reset();
>   gStyle->SetOptFit(1);
>   gStyle->SetStatX(0.45);
>   gStyle->SetStatY(0.85);
> 
>   TCanvas* c1 = new TCanvas("c1","Ntuple Plots",1); // create canvas
>   c1->SetFillColor(kWhite);
> 
>   TFile* f1 = new TFile("cjj_g10.root","READ");
>   TH1F* hi1 = new TH1F("hi1","Angular Resolution: Gamma Energy = 10 MeV ",80,-1.0,1.0);
>   hi1->SetXTitle("Cos`q#");
>   //  h509->Draw("Angres>>hi1","Egen>4&&Rfitt<600","goff");
>   h503->Draw("(Ue*Uf+Ve*Vf+We*Wf)>>hi1","Rfit<600","goff");
>   c1->SetLogy(1);
>   TF1* expExp = new TF1("expExp",expExp,-1,1,4);
>   expExp->SetParameters(9.2,0.2,5.7,17000);
>   expExp->SetParNames("1st slope","2nd Amp","2nd slope","scale fac");
>   Double_t x[1];
>   Double_t a[4];
>   a[0] = 9.2;
>   a[1] = 0.2;
>   a[2] = 5.7;
>   a[3] = 17000.0;
>   Double_t y;
>   printf("Hello\n");
>   for( Int_t i=0 ; i<80 ; i++) {
>     x[0] = -0.9875+i*0.025;
>     y = expExp->EvalPar(x,a);
>     printf("%d\t%f\t%f\t%f\n",i,hi1->GetBinContent(i),x[0],y);
>   }
>   expExp->Draw();
>   /*  expExp->SetParLimits(0,9.2,9.3);
>   expExp->SetParLimits(1,0.2,0.21);
>   expExp->SetParLimits(2,5.7,5.8);
>   expExp->SetParLimits(3,17000.0,17100.0);
> 
>   TPostScript ps("cjj_g10.eps",114);
>   hi1->Fit("expExp","RB");
>   //  expExp->Draw();
>   //  hi1->Draw("same");
>   c1->Update();
>   ps.Close();
>   */
> 
> }
> 
> The function expExp is ...
> 
> Double_t  expExp(Double_t* x, Double_t* par) {
>   Double_t expPart1 = exp(par[0]*(x[0]-1));
>   Double_t expPart2  = exp(par[2]*(x[0]-1));
> 
>   return (par[3]* (expPart1 + par[1]*expPart2));
>



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:30 MET