Datao Gong,
Your problem is not the loop, but the fluxMR function:
no return statement in function returning non-void (Double_t)
result of this function is completly unpredictable, changes with
any change of the code.
Add:
return returnValue;
in fluxMR
Krzysztof
---------- Original Message -----------
From: Datao Gong <dtgong@physics.umn.edu>
To: Root Mailinglist <roottalk@cern.ch>
Sent: Wed, 22 Oct 2003 00:23:56 -0500 (CDT)
Subject: [ROOT] strange function
> Hi,Everyone,
> I just need to caculate some function values. Also it should not be hard
> to draw the funcation. But the Root always complain divided by zero.
> If i do not call the function in the loop, it is fine and get what i
> expect value. Since my code is rathen simple. i paste it here. I use
> Root 3.03 on osf1 system.
>
> #include "TH1.h"
> #include "TF1.h"
> #include "TROOT.h"
> #include "TStyle.h"
>
> Double_t f(Double_t z)
> {
>
> Double_t returnValue = (1+0.5*z)*(1+0.5*z)*TMath::log(1/z)-
> 0.5*(1-z)*(3+z);
> return returnValue;
>
> }
>
> Double_t fluxMR(Double_t beam,Double_t m)
> {
> Double_t s = 4*beam*beam;
> Double_t me = 0.511/1000.0;
> Double_t alpha = 1/137.036;
>
> Double_t returnValue;
>
> Double_t z = m*m/s;
>
> Double_t t1 = TMath::log(s/(me*me))-1;
> Double_t t2 = TMath::log(s/(m*m));
> returnValue = 3*8*alpha*alpha/(m*m*m)*
> ( f(z)*t1*t1-1/3.0*t2*t2*t2 );
>
> }
>
> Double_t flux(Double_t *beam, Double_t *par)
> {
>
> Double_t etacM = par[0];
> Double_t etacPrimeM = par[1];
> Double_t returnValue = fluxMR(beam[0],etacPrimeM)/fluxMR(beam[0],
> etacM); return returnValue;
>
> }
>
> void calcflux()
> {
> Double_t par[2];
> Double_t beam[1];
> beam[0] = 5.28;
> par[0] = 2.98;
> par[1] = 3.64;
>
> Double_t res;
> for(Int_t i = 0 ; i < 100 ; ++i){ //if do not loop, it is fine.
> beam[0] = 4.7;
> // beam[0] = 4.7+(5.5-4.7)/100.0*i;
> cout<<flux(beam,par)<<endl;
>
> }
> }
>
> Thanks
>
> Gong Datao
------- End of Original Message -------
Krzysztof Wozniak
--------------------------------------------------------------------
Email: Krzysztof.Wozniak@ifj.edu.pl phone: 48-12-662-8430
WWW: http://chall.ifj.edu.pl/~wozniak fax: 48-12-662-8458
Institute of Nuclear Physics,
ul. Radzikowskiego 152, 31-342 Krakow, Poland
--------------------------------------------------------------------
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET