Evaluateing functions with TF1::EvalPar

Chris Jillings (chris@sno.phy.queensu.ca)
Thu, 5 Mar 1998 12:08:19 -0500 (EST)


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));

}

=================================================================
= =
= Chris Jillings =
= Department of Physics phone/voice mail: (613) 545-6000x4805 =
= Queen's University fax: (613) 545-6813 =
= Kingston, Ontario email: chris@sno.phy.queensu.ca =
= Canada, K7L 3N6 web: http://snodaq.phy.queensu.ca =
= =
=================================================================