static double calcwidth12(void) { int i,nsub; double width12 = 0.; double selChan=0; int first=1; long N1; err_code = 0; for(nsub=1;nsub<=nprc_int;nsub++) widths[nsub-1]=0; for(nsub=1;nsub<=nprc_int;nsub++) { double m1, m2, m3; if(strcmp(pinf_int(nsub,1,&m1,&N1),inParticle)==0) { if(first) { if(EffQmass&&Q) *Q=m1; if(calcFunc_int()>0) { messanykey(15,15,"Can not calculate constraints"); return 0; } if(GG) { if(SC) *GG=*SC; else {if(Q) *GG=sqrt(4*M_PI*alpha_2(*Q)); else *GG=sqrt(4*M_PI*alpha_2(m1));} } first=0; } pinf_int(nsub,1,&m1,NULL);pinf_int(nsub,2,&m2,NULL);pinf_int(nsub,3,&m3,NULL); if (m1 <=m2 + m3) widths[nsub-1] = 0.0; else { double md=m2-m3; double ms=m2+m3; double pRestOut=sqrt((m1*m1 - ms*ms)*(m1*m1-md*md))/(2*m1); double totcoef= pRestOut/(8. * M_PI * m1*m1); for(i=1;i<12;i++) pvect[i]=0; pvect[0]=m1; pvect[7]=pRestOut; pvect[4]=sqrt(pRestOut*pRestOut+m2*m2); pvect[11]=-pRestOut; pvect[8]=sqrt(pRestOut*pRestOut+m3*m3); widths[nsub-1] = totcoef * sqme_int(nsub,pvect,&err_code); if(err_code != 0) { errormessage(); widths[nsub-1]=0; err_code=0;} width12 += widths[nsub-1]; if(nsubSel==nsub) selChan= widths[nsub-1]; } } } if(nsubSel) { if(width12) return selChan/width12; else return 0;} return width12; }
static void writeEvent(double *x, double w) { int i,icc; double GG,qF1,qF2,qR,qS,x1,x2; REAL pvectR[4*maxNp],cb_coeff_[buffSize],*cb_coeff; double pvect[4*maxNp]; double factor_0; int cb_pow=cb_int[Nsub-1].pow; int nc=cb_int[Nsub-1].nC; mkmom(x, &factor_0,&x1,&x2,pvectR); for(i=0;i<4*(nin_int+nout_int);i++) pvect[i]=pvectR[i]; Scale(Nsub,pvect,&qR,&qF1,&qF2,&qS); if(cb_pow) { double sum=0; int err; if(buffSize<cb_pow) cb_coeff=cb_coeff_; else cb_coeff=malloc(sizeof(REAL)*buffSize); GG=sqrt(4*M_PI*alpha_2(qR)); sqme_int(Nsub,GG,pvectR,cb_coeff,&err); for(i=0;i<cb_pow;i++) sum+=fabs(cb_coeff[i]); if(nPROCSS) pthread_mutex_lock(&drandXX_key); sum*=drandXX(); if(nPROCSS) pthread_mutex_unlock(&drandXX_key); for(i=0;i<cb_pow;i++) { sum-=fabs(cb_coeff[i]); if(sum<=0) break; } if(i==cb_pow) i--; icc=i; if(cb_coeff!=cb_coeff_) free(cb_coeff); } if(nPROCSS)pthread_mutex_lock(&wrt_key); fprintf(events_,"%12.3E",w); if(nin_int==2) fprintf(events_," %17.10E %17.10E",pvect[3],pvect[7]); for(i=0;i<nout_int;i++) fprintf(events_," %17.10E %17.10E %17.10E", pvect[4*(i+nin_int)+1],pvect[4*(i+nin_int)+2],pvect[4*(i+nin_int)+3]); fprintf(events_,"| %.3E %.3E ", qS,alpha_2(qR)); if(cb_pow) { int j; fprintf(events_," "); for(j=0;j<nc;j++) { int *offset=cb_int[Nsub-1].chains +4*nc*icc+4*j; fprintf(events_,"(%d %d %d %d)",offset[0],offset[1],offset[2],offset[3]); } } fprintf(events_,"\n"); // fflush(events_); if(nPROCSS)pthread_mutex_unlock(&wrt_key); }
static void writeEvent(long cCube, int n, char * rand_state,double*pvect) { int i; int icc; double qF,qR; #ifdef PARKED fprintf(events_,"%05X|%s|%d\n",cCube,rand_state,n); #else if(*cb_pow_int) { double sum=0; for(i=0;i<*cb_pow_int;i++) sum+=fabs((*cb_coeff_int)[i]); sum*=drandXX(); for(i=0;i<*cb_pow_int;i++) { sum-=fabs((*cb_coeff_int)[i]); if(sum<=0) break; } if(i==*cb_pow_int) i--; if((*cb_coeff_int)[i]<0) n*=-1; icc=i; } fprintf(events_,"%8d ",n); if(nin_int==2) fprintf(events_," %17.10E %17.10E",pvect[3],pvect[7]); for(i=0;i<nout_int;i++) fprintf(events_," %17.10E %17.10E %17.10E", pvect[4*(i+nin_int)+1],pvect[4*(i+nin_int)+2],pvect[4*(i+nin_int)+3]); Scale(pvect,&qF,&qR); fprintf(events_,"| %.3E %.3E ", qF,alpha_2(qR)); if(*cb_pow_int) { int j; fprintf(events_," "); for(j=0;j<*cb_nc_int;j++) fprintf(events_,"(%d %d)",(*cb_chains_int)[2*(*cb_nc_int)*icc+2*j], (*cb_chains_int)[2*(*cb_nc_int)*icc+2*j+1]); } fprintf(events_,"\n"); #endif }
static double func_2(double *x, double wgt,double *pout) { double ret_val=0.; int err=0,nd,i; double factor_0; double xx0=x[0],xx1=x[1],x1,x2; double GG,qF,qR; nCall++; REAL pvectR[200]; double pvect[40]; /* get momenta */ mkmom(x, &factor_0,pvectR); if(sf_num[0]){x1=x[0]; x[0]=xx0;} if(sf_num[1]){x2=x[1]; x[1]=xx1;} nd=0; if (!factor_0) goto exi; nd=4*(nin_int+nout_int); for(i=0;i<nd;i++) pvect[i]=pvectR[i]; factor_0 *= calcCutFactor(pvect); if(nin_int>1) factor_0 *= usrFF(nin_int, nout_int,pvect,p_names,p_codes); if (!factor_0) goto exi; Scale(pvect,&qF,&qR); /* ** structure function multiplication */ if (nin_int == 2) { if(sf_num[0]) { factor_0 *= strfun_(1, x1,qF); if(factor_0==0.) {/*printf("|x1=%.2f|",x1);*/ goto exi;}} if(sf_num[1]) { factor_0 *= strfun_(2, x2,qF); if(factor_0==0.) {/*printf("|x2=%.2f|",x2);*/ goto exi;}} } if (!factor_0) { printf("strf"); goto exi;} /* ** call for 'running strong coupling constant' */ GG=sqrt(4*M_PI*alpha_2(qR)); ret_val = factor_0 * sqme_int(Nsub,GG,pvectR,&err); if(err) badPoints+= (ret_val>0 ? ret_val*wgt : - ret_val*wgt); if(ret_val<0) negPoints+=ret_val*wgt; exi: if(pout)for(i=0;i<nd;i++) pout[i]=pvect[i]; return ret_val; } /* func_ */
static double func_(double *x, double wgt) { double ret_val=0.; int err=0,nd,i; double factor_0; double x1,x2; double GG,qF1,qF2,qR,qS; REAL pvectR[100]; double pvect[100]; /* get momenta */ mkmom(x, &factor_0,&x1,&x2,pvectR); if (!factor_0) goto exi; nd=4*(nin_int+nout_int); for(i=0;i<nd;i++) pvect[i]=pvectR[i]; factor_0 *= calcCutFactor(pvect)*usrFF(nin_int,nout_int,pvect,p_names,p_codes); if (!factor_0) goto exi; Scale(Nsub,pvect,&qR,&qF1,&qF2,&qS); /* ** structure function multiplication */ if (nin_int == 2) { if(sf_num[0]) { factor_0 *= strfun_(1, x1,qF1); if(factor_0==0.) goto exi;} if(sf_num[1]) { factor_0 *= strfun_(2, x2,qF2); if(factor_0==0.) goto exi;} } if (!factor_0) { goto exi;} /* ** call for 'running strong coupling constant' */ GG=sqrt(4*M_PI*alpha_2(qR)); ret_val = factor_0 * sqme_int(Nsub,GG,pvectR,NULL,&err); if(err) badPoints+= (ret_val>0 ? ret_val*wgt : - ret_val*wgt); if(ret_val<0) negPoints+=ret_val*wgt; exi: if(hFill) { if(nPROCSS) pthread_mutex_lock(&hist_key); fillHists(ret_val*wgt,pvect); if(nPROCSS) pthread_mutex_unlock(&hist_key); } return ret_val; } /* func_ */
static void writeLesHdecays(void) { int i,nsub; int first=1; long N1,N2,N3; double S; double *widths=(double *) malloc(sizeof(double)*nprc_int); double *sum=(double *) malloc(sizeof(double)*nprc_int); double *masses=(double *) malloc(3*sizeof(double)*nprc_int); long *codes=(long *) malloc(3*sizeof(long)*nprc_int); char ** names=malloc(3*sizeof(char*)*nprc_int); int npTot=0; char f_name[50]; FILE *f; char*inP=" "; nextFileName(f_name,"decaySLHA",".txt"); f=fopen(f_name,"w"); fprintf(f,"#Masses, widths and branchings in SLHA format:\n"); fprintf(f,"BLOCK MODELPARAMETERS:\n"); for(i=1;i<=nvar_int;i++) fprintf(f,"# %8s %E\n", varName_int[i], va_int[i]); fprintf(f,"BLOCK MASS # Mass Spectrum\n"); for(nsub=1;nsub<=nprc_int;nsub++) { for(i=1;i<4;i++) { double m; long N; char * nm=pinf_int(nsub,i,&m,&N); int j; for(j=0;j<npTot;j++) if(strcmp(nm,names[j])==0 || N==codes[j] || N==-codes[j]) break; if(j==npTot) { masses[j]=m; codes[j]=N; names[j]=nm; npTot++; } } } for(i=0;i<npTot;i++) fprintf(f,"%10d %E # %s\n",codes[i],masses[i],names[i]); free(masses); free(codes); free(names); err_code = 0; for(nsub=0;nsub<nprc_int;nsub++) sum[nsub]=0; for(nsub=1;nsub<=nprc_int;nsub++) { double m1, m2, m3; char *inP_new=pinf_int(nsub,1,&m1,&N1); int Nsum; first=strcmp(inP_new,inP); if(first) { Nsum=nsub-1; inP=inP_new; if(EffQmass&&Q) *Q=m1; if(calcFunc_int()>0) { messanykey(15,15,"Can not calculate constraints"); return; } if(GG) { if(SC) *GG=*SC; else {if(Q) *GG=sqrt(4*M_PI*alpha_2(*Q)); else *GG=sqrt(4*M_PI*alpha_2(m1));} } } pinf_int(nsub,1,&m1,&N1); pinf_int(nsub,2,&m2,NULL); pinf_int(nsub,3,&m3,NULL); if (m1 <=m2 + m3) widths[nsub-1] = 0.0; else { double md=m2-m3; double ms=m2+m3; double pRestOut=sqrt((m1*m1 - ms*ms)*(m1*m1-md*md))/(2*m1); double totcoef= pRestOut/(8. * M_PI * m1*m1); for(i=1;i<12;i++) pvect[i]=0; pvect[0]=m1; pvect[7]=pRestOut; pvect[4]=sqrt(pRestOut*pRestOut+m2*m2); pvect[11]=-pRestOut; pvect[8]=sqrt(pRestOut*pRestOut+m3*m3); widths[nsub-1] = totcoef * sqme_int(nsub,pvect,&err_code); if(err_code != 0) { errormessage(); widths[nsub-1]=0; err_code=0;} sum[Nsum] += widths[nsub-1]; } } inP=" "; for(nsub=1;nsub<=nprc_int;nsub++) { char *inP_new=pinf_int(nsub,1,NULL,&N1); first=strcmp(inP_new,inP); if(first) { inP=inP_new; S=sum[nsub-1]; if(S>0) fprintf(f,"DECAY %d %E # %s width\n", N1, S, inP); } if(S>0 && widths[nsub-1]!=0) { char * inP2=pinf_int(nsub,2,NULL,&N2); char * inP3=pinf_int(nsub,3,NULL,&N3); fprintf(f," %12.4E 2 %8d %8d # Br(%-3s -> %-3s %-3s) %11.3E[Gev]\n", widths[nsub-1]/S,N2,N3,inP,inP2,inP3,widths[nsub-1]); } } fclose(f); { char mess[100]; sprintf(mess,"Output is saved in %s",f_name); messanykey( 12, 12,mess); } free(widths); free(sum); }
float* TractsToDWIImageFilter::ComputeFiberCorrelation(){ float bD = m_bD; vnl_matrix_fixed<double, 3, QBALL_ODFSIZE> bDir = *itk::PointShell<QBALL_ODFSIZE, vnl_matrix_fixed<double, 3, QBALL_ODFSIZE> >::DistributePointShell(); const int N = QBALL_ODFSIZE; vnl_matrix_fixed<double, N, N> C = bDir.transpose()*bDir; vnl_matrix_fixed<double, N, N> Q = C; for(int i=0; i<N; i++) { for(int j=0; j<N; j++) { C(i,j) = std::abs(C(i,j)); Q(i,j) = exp(-bD * C(i,j) * C(i,j)); } } vnl_matrix_fixed<double, N, N> P = Q*Q; std::vector<const double *> pointer; pointer.reserve(N*N); double * start = C.data_block(); double * end = start + N*N; for (double * iter = start; iter != end; ++iter) { pointer.push_back(iter); } std::sort(pointer.begin(), pointer.end(), LessDereference()); vnl_vector_fixed<double,N*N> alpha; vnl_vector_fixed<double,N*N> beta; for (int i=0; i<N*N; i++) { alpha(i) = *pointer[i]; beta(i) = *(P.data_block()+(pointer[i]-start)); } double nfac = sqrt(beta(N*N-1)); beta = beta / (nfac*nfac); Q = Q / nfac; double sum = 0; for(int i=0; i<N; i++) { sum += Q(0,i); } // if left to default 0 // then mean is not substracted in order to correct odf integral this->m_Meanval_sq = (sum*sum)/N; vnl_vector_fixed<double,N*N> alpha_0; vnl_vector_fixed<double,N*N> alpha_2; vnl_vector_fixed<double,N*N> alpha_4; vnl_vector_fixed<double,N*N> alpha_6; for(int i=0; i<N*N; i++) { alpha_0(i) = 1; alpha_2(i) = alpha(i)*alpha(i); alpha_4(i) = alpha_2(i)*alpha_2(i); alpha_6(i) = alpha_4(i)*alpha_2(i); } vnl_matrix_fixed<double, N*N, 4> T; T.set_column(0,alpha_0); T.set_column(1,alpha_2); T.set_column(2,alpha_4); T.set_column(3,alpha_6); vnl_vector_fixed<double,4> coeff = vnl_matrix_inverse<double>(T).pinverse()*beta; float* retval = new float[4]; retval[0] = coeff(0); retval[1] = coeff(1); retval[2] = coeff(2); retval[3] = coeff(3); return retval; }