crab.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #define pi 3.14159265358979323844
  6. #define EULER 0.5772156649015328606
  7. double_complex ci(0.0,1.0);
  8. /* Prototypes */
  9. void bininit(void);
  10. void binner(int inumden,double mom,double corr,double *p1,double *p2);
  11. void printstatements(int onlyzerob);
  12. void coulset(void);
  13. void coulpar(double eta, double_complex *couly,double_complex *cfact1,
  14. double_complex *cfact2,double_complex *chype,
  15. double_complex *chype1, double_complex *chype2);
  16. double_complex coul(double mom,double r,double zk,double eta,int kk);
  17. double_complex chyper(double_complex a,double_complex b,double_complex cz,
  18. int kk);
  19. void partwaveinit(void);
  20. void diffy(int ipart);
  21. double_complex cw2_big_r(int l,double r,double eta);
  22. double_complex cw2_small_r(int l,double r,double eta);
  23. double dgamma(int mm);
  24. void phasespaceinit(int *nb,int *np1,int *np2,double *bweight_num,
  25. double *bweight1_den,double *bweight2_den,int *onlyzerob);
  26. void get_b_num(int *ib1,int *ib2,double *bweight_num);
  27. void get_b_den(int *ib1,int *ib2,double *bweight1_den,double *bweight2_den);
  28. void get_pr(int ib1,int j1,double phi1,int ib2,int j2,double phi2,
  29. double *p1,double *r1,int *iread1,
  30. double *p2,double *r2,int *iread2);
  31. void onepart_filter(int i,double *p,int *ifilter);
  32. void twopart_filter(double *p1,double *p2,int *ifilter);
  33. double get_mom(double *p1,double *p2);
  34. double corrcalc(double mom,double kdotr,double r);
  35. double bwcalc(double qred,double r);
  36. double triangle(double m0,double m1,double m2);
  37. void get_com_quantities(double *p1,double *r1,double *p2,double *r2,
  38. double *qred,double *r,double *qdotr,double *mom,
  39. int *test);
  40. void lorentz(double *u,double *q,double *qprime);
  41. double_complex cgamma(double_complex c);
  42. double get_gamow(double mom);
  43. void momentum_smear(double *p1,double *p2,double *mom,double *qred);
  44. void ranrot(double *p,double *r,double phi);
  45. void store_mixed_pair(int n_mixed_pairs,double *p1,double *pp1,double *p2,
  46. double *pp2,int iread1,int iread2,int *iiread1,
  47. int *iiread2,double corr,double *ww);
  48. void decompose(double *p1,double *p2,double vs,
  49. int long_comoving_boost,
  50. int x_along_p,int outwards_boost,
  51. double *qmag,double *qx,double *qy,double *qz);
  52. double ran2(void);
  53. void gauss(double *g1,double *g2);
  54. /* end of prototypes */
  55. /* CLASS DEFINITIONS */
  56. #define RESULTS_DIR
  57. /* ************* These are used for binning **************** */
  58. /* ********* For binning in one dimension ******************** */
  59. class onedbin_class{
  60. public:
  61. double *numerator,*denominator;
  62. int *numcounter,*dencounter;
  63. double *numrms,*denrms;
  64. int nkmax;
  65. double maxmom;
  66. char filename[80];
  67. onedbin_class(int nk,double biggest_mom, const char *fn);
  68. void bincorr(int inumden,double mom,double corr);
  69. void printcorr(int onlyzerob);
  70. };
  71. onedbin_class::onedbin_class(int nk,double biggest_mom, const char *fn){
  72. int i;
  73. nkmax=nk;
  74. maxmom=biggest_mom;
  75. #ifdef RESULTS_DIR
  76. strcpy(filename,"results/");
  77. strcat(filename,fn);
  78. #else
  79. strcpy(filename,fn);
  80. #endif
  81. numerator=new double[nkmax];
  82. denominator=new double[nkmax];
  83. numcounter=new int[nkmax];
  84. dencounter=new int[nkmax];
  85. numrms=new double[nkmax];
  86. denrms=new double[nkmax];
  87. for(i=0;i<nkmax;i++){
  88. numerator[i]=0.0;
  89. denominator[i]=0.0;
  90. numcounter[i]=0;
  91. dencounter[i]=0;
  92. numrms[i]=0.0;
  93. denrms[i]=0.0;
  94. }
  95. }
  96. void onedbin_class::bincorr(int inumden,double mom,double corr){
  97. int kk;
  98. kk=(int)floor((double)nkmax*mom/maxmom);
  99. if(kk<nkmax){
  100. if(inumden==0){
  101. numerator[kk]=numerator[kk]+corr;
  102. numcounter[kk]=numcounter[kk]+1;
  103. numrms[kk]=numrms[kk]+corr*corr;
  104. }
  105. else{
  106. denominator[kk]=denominator[kk]+corr;
  107. dencounter[kk]=dencounter[kk]+1;
  108. denrms[kk]=denrms[kk]+corr*corr;
  109. }
  110. }
  111. }
  112. void onedbin_class::printcorr(int onlyzerob){
  113. int kk,counts,no_denominator;
  114. double mom,error,corr,average_numer,average_denom;
  115. double normalization,normcount;
  116. FILE *fptr;
  117. normalization=1.0;
  118. no_denominator=onlyzerob;
  119. #ifdef MIXED_PAIRS_FOR_DENOM
  120. no_denominator=0;
  121. normalization=0.0;
  122. normcount=0;
  123. for(kk=0;kk<nkmax;kk++){
  124. normcount=normcount+dencounter[kk];
  125. normalization=normalization+denominator[kk];
  126. }
  127. if(normcount>0) normalization=normalization/(double)normcount;
  128. printf("For %s, normalization=%g \n",filename,normalization);
  129. #endif
  130. fptr=fopen(filename,"w");
  131. #ifdef REDUCED_MOM
  132. fprintf(fptr,"!As a function of reduced momentum, k=(p2-p1)/2:\n");
  133. #else
  134. fprintf(fptr,"!As a function of relative momentum, k=(p2-p1):\n");
  135. #endif
  136. fprintf(fptr,"!k(MeV/c) C(k) +/- numcounts&dencounts num den\n");
  137. for(kk=0;kk<nkmax;kk++){
  138. mom=(kk+0.5)*maxmom/(double)nkmax;
  139. float num, den;
  140. corr=-1.0;
  141. if(no_denominator==1){
  142. if(numcounter[kk]>0) {
  143. corr=numerator[kk]/numcounter[kk];
  144. num = numerator[kk];
  145. den = numcounter[kk];
  146. }
  147. }
  148. else{
  149. if(dencounter[kk]>0) {
  150. corr=numerator[kk]/denominator[kk];
  151. num = numerator[kk];
  152. den = denominator[kk];
  153. }
  154. }
  155. error=-1.0;
  156. if(numcounter[kk]!=0 && (no_denominator==1 || dencounter[kk]!=0)){
  157. average_numer=numerator[kk]/numcounter[kk];
  158. error=((numrms[kk]/numcounter[kk])
  159. -(average_numer*average_numer))/numcounter[kk];
  160. if(no_denominator!=1) error=error+corr*corr/(double)numcounter[kk];
  161. if(no_denominator!=1){
  162. average_denom=denominator[kk]/dencounter[kk];
  163. error=error+((denrms[kk]/denominator[kk])
  164. -(average_denom*average_denom))/dencounter[kk];
  165. if(no_denominator!=1) error=error+corr*corr/(double)dencounter[kk];
  166. }
  167. error=sqrt(fabs(error));
  168. }
  169. if(corr>=0.0){
  170. corr=corr*normalization;
  171. error=error*normalization;
  172. }
  173. fprintf(fptr,"%5.2f %6.3f %9g %d %d %f %f\n",
  174. mom,corr,error,numcounter[kk],dencounter[kk], num, den);
  175. }
  176. fclose(fptr);
  177. }
  178. /* ********* For binning in three dimensions ******************** */
  179. class threedbin_class{
  180. public:
  181. double *numerator,*denominator;
  182. int *numcounter,*dencounter;
  183. double *numrms,*denrms;
  184. int nkxmax,nkymax,nkzmax;
  185. double kxmax,kymax,kzmax;
  186. char filename[80];
  187. threedbin_class(int nkx,int nky,int nkz,
  188. double kxmax,double kymax,double kzmax, const char *fn);
  189. void bincorr(int inumden,double kx,double ky,double kz,double corr);
  190. void printcorr(int onlyzerob);
  191. };
  192. threedbin_class::threedbin_class(int nkx,int nky,int nkz,
  193. double biggest_kx,double biggest_ky,
  194. double biggest_kz, const char *fn){
  195. int ix,iy,iz,i,nmax;
  196. nkxmax=nkx;
  197. nkymax=nky;
  198. nkzmax=nkz;
  199. kxmax=biggest_kx;
  200. kymax=biggest_ky;
  201. kzmax=biggest_kz;
  202. nmax=nkxmax*nkymax*nkzmax;
  203. #ifdef RESULTS_DIR
  204. strcpy(filename,"results/");
  205. strcat(filename,fn);
  206. #else
  207. strcpy(filename,fn);
  208. #endif
  209. numerator=new double[nmax];
  210. denominator=new double[nmax];
  211. numcounter=new int[nmax];
  212. dencounter=new int[nmax];
  213. numrms=new double[nmax];
  214. denrms=new double[nmax];
  215. for(i=0;i<nmax;i++){
  216. numerator[i]=0.0;
  217. denominator[i]=0.0;
  218. numcounter[i]=0;
  219. dencounter[i]=0;
  220. numrms[i]=0.0;
  221. denrms[i]=0.0;
  222. }
  223. }
  224. void threedbin_class::bincorr(int inumden,double kx,double ky,double kz,
  225. double corr){
  226. int kk,ix,iy,iz;
  227. ix=(int)floor((double)nkxmax*fabs(kx)/kxmax);
  228. iy=(int)floor((double)nkymax*fabs(ky)/kymax);
  229. iz=(int)floor((double)nkzmax*fabs(kz)/kzmax);
  230. if(ix<nkxmax && iy<nkymax && iz<nkzmax){
  231. kk=ix*(nkymax*nkzmax)+iy*nkzmax+iz;
  232. if(inumden==0){
  233. numerator[kk]=numerator[kk]+corr;
  234. numcounter[kk]=numcounter[kk]+1;
  235. numrms[kk]=numrms[kk]+corr*corr;
  236. }
  237. else{
  238. denominator[kk]=denominator[kk]+corr;
  239. dencounter[kk]=dencounter[kk]+1;
  240. denrms[kk]=denrms[kk]+corr*corr;
  241. }
  242. }
  243. }
  244. void threedbin_class::printcorr(int onlyzerob){
  245. int kk,ix,iy,iz,nmax,counts,no_denominator;
  246. double kx,ky,kz,error,corr,average_numer,average_denom;
  247. double normalization,normcount;
  248. FILE *fptr;
  249. normalization=1.0;
  250. no_denominator=onlyzerob;
  251. #ifdef MIXED_PAIRS_FOR_DENOM
  252. no_denominator=0;
  253. normalization=0.0;
  254. normcount=0;
  255. nmax=nkxmax*nkymax*nkzmax;
  256. for(kk=0;kk<nmax;kk++){
  257. normcount=normcount+dencounter[kk];
  258. normalization=normalization+denominator[kk];
  259. }
  260. if(normcount>0) normalization=normalization/(double)normcount;
  261. printf("For %s, normalization=%g \n",filename,normalization);
  262. #endif
  263. fptr=fopen(filename,"w");
  264. #ifdef REDUCED_MOM
  265. fprintf(fptr,"!As a function of reduced momentum, k=(p2-p1)/2:\n");
  266. #else
  267. fprintf(fptr,"!As a function of relative momentum, k=(p2-p1):\n");
  268. #endif
  269. fprintf(fptr,"! kx ky kz C(k) +/- numcounts&dencounts norm num den\n");
  270. kk=0;
  271. for(ix=0;ix<nkxmax;ix++){
  272. kx=(ix+0.5)*kxmax/(double)nkxmax;
  273. for(iy=0;iy<nkymax;iy++){
  274. ky=(iy+0.5)*kymax/(double)nkymax;
  275. for(iz=0;iz<nkzmax;iz++){
  276. kz=(iz+0.5)*kzmax/(double)nkzmax;
  277. float num, den;
  278. corr=-1.0;
  279. if(no_denominator==1){
  280. if(numcounter[kk]>0) {
  281. corr=numerator[kk]/numcounter[kk];
  282. num = numerator[kk];
  283. den = numcounter[kk];
  284. }
  285. }
  286. else{
  287. if(dencounter[kk]>0) {
  288. corr=numerator[kk]/denominator[kk];
  289. num = numerator[kk];
  290. den = denominator[kk];
  291. }
  292. }
  293. error=-1.0;
  294. if(numcounter[kk]!=0 && (no_denominator==1 || dencounter[kk]!=0)){
  295. average_numer=numerator[kk]/numcounter[kk];
  296. error=((numrms[kk]/numcounter[kk])
  297. -(average_numer*average_numer))/numcounter[kk];
  298. if(no_denominator!=1) error=error+corr*corr/(double)numcounter[kk];
  299. if(no_denominator!=1){
  300. average_denom=denominator[kk]/dencounter[kk];
  301. error=error+((denrms[kk]/denominator[kk])
  302. -(average_denom*average_denom))/dencounter[kk];
  303. if(no_denominator!=1) error=error+corr*corr/(double)dencounter[kk];
  304. }
  305. error=sqrt(fabs(error));
  306. }
  307. if(corr>=0.0){
  308. corr=corr*normalization;
  309. error=error*normalization;
  310. }
  311. fprintf(fptr,"%5.2f %5.2f %5.2f %6.3f %9f %d %d %f %f %f\n",
  312. kx,ky,kz,corr,error,numcounter[kk],dencounter[kk], normalization, num, den);
  313. kk=kk+1;
  314. }
  315. }
  316. }
  317. fclose(fptr);
  318. }
  319. /* ************* Phasespace Info Class **************** */
  320. class phasespace_class{
  321. public:
  322. double p[4],r[4];
  323. int iread;
  324. phasespace_class(double *pp,double *rr,int iiread);
  325. /* ~phasespace_class(); */
  326. };
  327. phasespace_class::phasespace_class(double *pp,double *rr,int iiread){
  328. int alpha;
  329. for(alpha=0;alpha<4;alpha++){
  330. p[alpha]=pp[alpha];
  331. r[alpha]=rr[alpha];
  332. }
  333. iread=iiread;
  334. }
  335. /* ************************************************************ */
  336. /* The Following are used for the calculation of the strong-interaction
  337. corrections to wave functions*/
  338. class partwave_class{
  339. public:
  340. double_complex *delpsi;
  341. double_complex delpsifar;
  342. partwave_class(int nrmax);
  343. };
  344. partwave_class::partwave_class(int nrmax){
  345. delpsi=new double_complex[nrmax];
  346. }
  347. /* ************************************************************ */
  348. /* The Following are used for the calculation of Coulomb wave functions*/
  349. class coulcalc_class{
  350. public:
  351. double_complex couly;
  352. double_complex cfact1;
  353. double_complex cfact2;
  354. double_complex chype[41];
  355. double_complex chype1[6];
  356. double_complex chype2[6];
  357. };
  358. /* ************************************************************* */