225 Start(seed,cnt1,cnt2,ts);
288 if (seed>921350143) seed=53310452;
298 ts->
GetJD(jd,sec,ns);
306 Int_t sec100=ns/10000000;
307 seed=10000*sec+100*sec100+jd100;
336 for (Int_t ii=0; ii<97; ii++)
341 for (Int_t jj=1; jj<=24; jj++)
343 m=(((i*j)%179)*k)%179;
348 if ((l*m)%64 >= 32) s+=t;
355 fC=362436./16777216.;
356 fCd=7654321./16777216.;
357 fCm=16777213./16777216.;
364 for (Int_t n=1; n<=cnt2; n++)
406 if ((seed >= 0) && (seed <= 921350143))
409 Int_t imin2=idum/(176*176*169);
410 idum=idum%(176*176*169);
411 Int_t jmin2=idum/(176*169);
413 Int_t kmin2=idum/169;
422 cout <<
" *NcRandom::unpack()* Unallowed seed value encountered."
423 <<
" seed = " << seed << endl;
424 cout <<
" Seed will be set to default value." << endl;
472 cout <<
" *NcRandom* seed = " <<
fSeed
473 <<
" cnt1 = " <<
fCnt1 <<
" cnt2 = " <<
fCnt2 << endl;
495 if (unirnu < 0) unirnu+=1.;
506 if (unirnu < 0.) unirnu+=1.;
521 if (unirnu <= 0.) unirnu=
Uniform();
538 rndm=rmin+fabs(rndm*(a-b));
571 for (Int_t jvec=0; jvec<n; jvec++)
575 if (unirnu < 0) unirnu+=1.;
586 if (unirnu < 0.) unirnu+=1.;
601 if (unirnu <= 0.) unirnu=
Uniform();
604 vec[jvec]=rmin+fabs(unirnu*(a-b));
609 cout <<
" *NcRandom::Uniform* Invalid value n = " << n << endl;
654 for (Int_t jvec=0; jvec<n; jvec++)
658 if (unirnu < 0) unirnu+=1.;
669 if (unirnu < 0.) unirnu+=1.;
687 cout <<
" *NcRandom::Uniform* Invalid value n = " << n << endl;
722 Float_t pi=acos(-1.);
723 Float_t unirng=mean+cos(2.*pi*q2)*sigma*sqrt(-2.*log(q1));
758 Float_t* q=
new Float_t[m];
762 Float_t pi=acos(-1.);
764 for (Int_t jvec=0; jvec<n; jvec++)
768 vec[jvec]=mean+cos(2.*pi*q2)*sigma*sqrt(-2.*log(q1));
774 cout <<
" *NcRandom::Gauss* Invalid value n = " << n << endl;
814 cout <<
" *NcRandom::Poisson* Invalid value mean = " << mean
815 <<
" Should be positive." << endl;
821 Float_t grndm=
Gauss();
822 Float_t rpois=mean+grndm*sqrt(mean);
823 Int_t npois=int(rpois);
824 if ((rpois-
float(npois)) > 0.5) npois++;
830 Float_t expxm=exp(-mean);
832 while (poitst > expxm)
867 cout <<
" *NcRandom::Poisson* Invalid value n = " << n << endl;
873 cout <<
" *NcRandom::Poisson* Invalid value mean = " << mean
874 <<
" Should be positive." << endl;
880 Float_t* grndm=
new Float_t[n];
884 for (Int_t jvec=0; jvec<n; jvec++)
886 rpois=mean+grndm[jvec]*sqrt(mean);
888 if ((rpois-
float(npois)) > 0.5) npois++;
889 vec[jvec]=float(npois);
895 Float_t expxm=exp(-mean);
898 for (Int_t jvec=0; jvec<n; jvec++)
902 while (poitst > expxm)
908 vec[jvec]=float(npois);
935 Float_t step=fabs(a-b)/float(n);
939 for (Int_t i=0; i<
fNa; i++)
941 x=xmin+float(i)*step;
944 if (i > 0)
fYa[i]+=
fYa[i-1];
945 if (fabs(
fYa[i]) > extreme) extreme=fabs(
fYa[i]);
949 for (Int_t j=0; j<
fNa; j++)
978 for (Int_t i=1; i<
fNa; i++)
980 for (Int_t j=0; j<i; j++)
984 for (Int_t k=i; k>=j; k--)
1002 for (Int_t l=0; l<
fNa; l++)
1004 if (l > 0)
fYa[l]+=
fYa[l-1];
1005 if (fabs(
fYa[l]) > extreme) extreme=fabs(
fYa[l]);
1009 for (Int_t m=0; m<
fNa; m++)
1039 for (Int_t i=0; i<
fNa; i++)
1041 dist=fabs(ra-
fYa[i]);
1045 if (dist < dmin) ncand=1;
1052 if (ncand == 1) jbin=
fIbins[0];
1056 Float_t cand=
Uniform(1.,
float(ncand));
1057 Int_t jcand=int(cand);
1058 if ((cand-
float(jcand)) > 0.5) jcand++;
1064 Float_t xlow=
fXa[jbin-1];
1065 if (jbin > 1) xlow=
fXa[jbin-2];
1066 Float_t xup=
fXa[jbin-1];
1067 if (jbin <
fNa-1) xup=
fXa[jbin];
1071 if (ncand == 0) cout <<
" *NcRandom::User* No candidate found." << endl;
1096 Float_t unirnf,ra,dmin,dist;
1098 for (Int_t jvec=0; jvec<n; jvec++)
1104 for (Int_t i=0; i<
fNa; i++)
1106 dist=fabs(ra-
fYa[i]);
1110 if (dist < dmin) ncand=1;
1117 if (ncand == 1) jbin=
fIbins[0];
1121 Float_t cand=
Uniform(1.,
float(ncand));
1122 Int_t jcand=int(cand);
1123 if ((cand-
float(jcand)) > 0.5) jcand++;
1129 Float_t xlow=
fXa[jbin-1];
1130 if (jbin > 1) xlow=
fXa[jbin-2];
1131 Float_t xup=
fXa[jbin-1];
1132 if (jbin <
fNa-1) xup=
fXa[jbin];
1136 if (ncand == 0) cout <<
" *NcRandom::User* No candidate found." << endl;
1143Double_t
NcRandom::RanBm(Double_t nr,Double_t n,Int_t m,Double_t* p,Double_t* na,Double_t* psia,Double_t psi0,Int_t f,TH1* psih,Int_t ncut,Double_t* nrx)
1249 if (nr<0 || fabs(n)<1 || m<1 || nr>1e19 || fabs(n)>1e19)
return -1;
1250 if (n<0 && !na)
return -1;
1257 Double_t pk=1./double(m);
1259 Double_t* nk=
new Double_t[m];
1264 ULong64_t nrep=ULong64_t(nr);
1269 nrep=ULong64_t(1.e19);
1277 ULong64_t ntrial=ULong64_t(fabs(n));
1278 ULong64_t jrep,jtrial;
1284 nsig=
new Double_t[m];
1286 for (jm=0; jm<m; jm++)
1289 if (na[jm]>0) isig=ULong64_t(na[jm]);
1295 for (jrep=0; jrep<nrep; jrep++)
1297 if (psia) psia[jrep]=-1;
1298 for (jm=0; jm<m; jm++)
1301 if (na && jrep==0) na[jm]=0;
1304 for (jtrial=0; jtrial<ntrial; jtrial++)
1309 for (jm=0; jm<m; jm++)
1327 for (jm=0; jm<m; jm++)
1336 if (psi<psimin || psimin<0) psimin=psi;
1337 if (psi0>=0 && psi>=psi0) npsi+=1;
1338 if (psia) psia[jrep]=psi;
1339 if (psih) psih->Fill(psi);
1342 if (!ncut)
continue;
1343 if (npsi>=ncut)
break;
1347 if (nrep==1) retval=psi;
1348 if (nrep>1 && psi0<0) retval=psimin;
1349 if (nrep>1 && psi0>=0) retval=npsi;
1354 if (jrep<nrep) *nrx=jrep+1;
1357 if (nk)
delete [] nk;
1358 if (nsig)
delete [] nsig;
Various mathematical tools for scientific analysis.
Double_t PsiValue(Int_t m, Int_t *n, Double_t *p=0, Int_t f=0) const
Generate universal random numbers and sequences on all common machines.
Float_t fYamax
! The min. and max. y values of the area function
void Unpack(Int_t seed, Int_t &i, Int_t &j, Int_t &k, Int_t &l)
Float_t * fXa
! The binned x values of the area function
Double_t RanBm(Double_t nr, Double_t n, Int_t m, Double_t *p=0, Double_t *na=0, Double_t *psia=0, Double_t psi0=-1, Int_t f=0, TH1 *psih=0, Int_t ncut=0, Double_t *nrx=0)
void Start(Int_t seed, Int_t cnt1, Int_t cnt2, NcTimestamp *ts)
Float_t * fYa
! The corresponding y values of the area function
void SetUser(Float_t a, Float_t b, Int_t n, Float_t(*f)(Float_t))
Int_t * fIbins
! The bin numbers of the random x candidates
Float_t Poisson(Float_t mean)
Int_t fNa
! The number of bins of the area function
Handling of timestamps for (astro)particle physics research.
Double_t GetJD(Int_t y, Int_t m, Int_t d, Int_t hh, Int_t mm, Int_t ss, Int_t ns) const