#include #include #include #include #include #include #include #ifdef SINGLE #define double float #define cos cosf #define sin sinf #define log logf #define sqrt sqrtf #define ceil ceilf #define floor floorf #define round roundf #endif #define XACCL namespace ppc{ using namespace std; #ifdef SINGLE struct setprc{ short store; setprc(){ short byte=127, end; __asm__("fstcw %0\nfldcw %1\nfstcw %2"::"m" (store), "m" (byte), "m" (end)); // cerr< strs; #ifdef XACCL static const int ncel=10; vector cells[ncel][ncel]; double rl[3], rh[3], rst[2]; #endif static const double OVR=5; static const double R=OVR*0.16510; static const double zoff=-1948.07; struct DOM{ double r[3]; }; map doms; #ifndef ICETRAY void load(){ ifstream inFile; inFile.open((dir+"geo-f2k").c_str(), ifstream::in); if(!inFile.fail()){ KEY key; DOM dom; string id; unsigned long long domid; while(inFile>>id>>hex>>domid>>dec>>dom.r[0]>>dom.r[1]>>dom.r[2]>>key.str>>key.om) #else double angsens(double x){ // hole ice double s[11]={0.32752, 0.66696, 0.35389, -1.4107, -1.7738, 4.3302, 5.7151, -5.5262, -7.9000, 2.0155, 3.3965}; double sum=s[0], y=1; for(int i=1; i<11; i++){ y*=x; sum+=s[i]*y; } return sum; } int hitnum=0; pair mcpids; I3MCHitSeriesMapPtr mchits(new I3MCHitSeriesMap); void load(const I3GeometryConstPtr& geo){ strs=map(); doms=map(); KEY key; DOM dom; for(I3OMGeoMap::const_iterator it=geo->omgeo.begin(); it!=geo->omgeo.end(); ++it){ OMKey omkey=it->first; key.str=omkey.GetString(); key.om=omkey.GetOM(); const I3Position& pos = (it->second).position; dom.r[0]=pos.GetX()/I3Units::m; dom.r[1]=pos.GetY()/I3Units::m; dom.r[2]=pos.GetZ()/I3Units::m+zoff; #endif if(key.str>0 && key.om>=1 && key.om<=60){ doms[key]=dom; STR & s=strs[key.str]; if(s.sp<0){ s.l=key.om; s.h=key.om; for(int i=0; i<3; i++){ s.rl[i]=dom.r[i]; s.rh[i]=dom.r[i]; } s.sp=0; } else{ if(key.oms.h) s.h=key.om; for(int i=0; i<3; i++){ if(dom.r[i]s.rh[i]) s.rh[i]=dom.r[i]; } s.sp++; } } #ifndef ICETRAY inFile.close(); #endif } for(map::iterator str=strs.begin(); str!=strs.end(); str++){ STR & s=str->second; s.zl=s.rl[2]; s.zh=s.rh[2]; s.st=(s.h-s.l)/(s.zh-s.zl); for(int i=0; i<3; i++){ s.rl[i]-=R; s.rh[i]+=R; } } for(map::iterator s=doms.begin(); s!=doms.end(); s++){ STR & str=strs[s->first.str]; double dz=s->second.r[2]-(str.zl+(str.h-s->first.om)/str.st); if(str.zf){ str.zn=dz; str.zx=dz; str.zf=false; } else{ if(dzstr.zx) str.zx=dz; } } for(map::iterator str=strs.begin(); str!=strs.end(); str++){ STR & s=str->second; s.zn-=R; s.zx+=R; } #ifdef XACCL bool first=true; for(map::const_iterator str=strs.begin(); str!=strs.end(); str++){ const STR & s=str->second; if(first){ for(int i=0; i<3; i++){ rl[i]=s.rl[i]; rh[i]=s.rh[i]; } first=false; } else{ for(int i=0; i<3; i++){ if(rl[i]>s.rl[i]) rl[i]=s.rl[i]; if(rh[i]::const_iterator str=strs.begin(); str!=strs.end(); str++){ const STR & s=str->second; int xl[2], xh[2]; for(int i=0; i<2; i++){ xl[i]=(int) floor((s.rl[i]-rl[i])*rst[i]); xh[i]=(int) floor((s.rh[i]-rl[i])*rst[i]); } for(int i=xl[0]; i<=xh[0]; i++) for(int j=xl[1]; j<=xh[1]; j++) cells[i][j].push_back(str->first); } if(false){ for(int i=0; i<3; i++) cout<::const_iterator s=cells[i][j].begin(); s!=cells[i][j].end(); s++) cout<<" "<<*s; cout< x, y; double xa, ya, xo=0, yo=0; int num=0; bool flag=true; while(inFile>>xa>>ya){ if(( xa<0 || 10 && ( xa<=xo || ya<=yo )){ flag=false; break; } x.push_back(xa); y.push_back(ya); xo=xa; yo=ya; num++; } if(xo!=1 || x.size()<2) flag=false; inFile.close(); if(flag){ size=x.size(); rx = new double[size]; wv = new double[size]; for(int i=0; i0){ delete rx; delete wv; } } double next(){ double l=0.405; double xi=xrnd(); if(size>1){ int i=1; for(; i::iterator s=doms.begin(); s!=doms.end(); s++) if(s->first.str==str && s->first.om==om){ for(int i=0; i<3; i++) r[i]=s->second.r[i]; doms.erase(s); break; } m.init(0.405); } void flasher(){ static const double rms=9.2*sqrt(3)*M_PI/180; double xi=xrnd(); xi=rms*(2*xi-1); double nz=sin(xi), np=cos(xi); xi=xrnd(); xi*=2*M_PI; n[0]=np*cos(xi); n[1]=np*sin(xi); n[2]=nz; } } x; struct photon{ #ifdef ROTASM volatile double t __attribute__ (( aligned(16) )), r[3] __attribute__ ((packed)); volatile double q __attribute__ (( aligned(16) )), n[3] __attribute__ ((packed)); #else double t, r[3], n[3]; #endif double xx; photon(){ t=x.t; #ifdef ROTASM q=0; #endif for(int i=0; i<3; i++){ r[i]=x.r[i]; n[i]=x.n[i]; } if(x.type==1) rotate(m.coschr, m.sinchr); xx=1.e-5; } void rotate(double cs, double si){ double zi=xrnd(); zi*=2*M_PI; double px=cos(zi), py=sin(zi); #ifdef ROTASM volatile __attribute__ (( aligned(16) )) float xcos[2]={px, py}, zcos[2]={cs, si}; __asm__(" movaps %0,%%xmm0 \n" " movlps %1,%%xmm1 \n" " movlps %2,%%xmm5 \n" ".intel_syntax noprefix \n" " movaps xmm7,xmm0 \n" " mulps xmm7,xmm7 \n" " movaps xmm2,xmm7 \n" " shufps xmm2,xmm2,0xe5 \n" " movaps xmm3,xmm7 \n" " shufps xmm3,xmm3,0xe6 \n" " movaps xmm4,xmm7 \n" " shufps xmm4,xmm4,0xe7 \n" " comiss xmm2,xmm3 \n" " jc 1f \n" " comiss xmm2,xmm4 \n" " jc 5f \n" " jmp 3f \n" "1: \n" " comiss xmm3,xmm4 \n" " jc 5f \n" " jmp 4f \n" "3: \n" " movaps xmm7,xmm2 \n" " shufps xmm7,xmm7,0x4e \n" " addps xmm7,xmm2 \n" " rsqrtps xmm7,xmm7 \n" " movaps xmm3,xmm0 \n" " shufps xmm3,xmm3,0x10 \n" " movaps xmm4,xmm0 \n" " shufps xmm4,xmm4,0x08 \n" " subps xmm3,xmm4 \n" " movaps xmm6,xmm7 \n" " shufps xmm6,xmm6,0x00 \n" " mulps xmm6,xmm3 \n" " movaps xmm3,xmm0 \n" " shufps xmm3,xmm3,0x40 \n" " movaps xmm4,xmm0 \n" " shufps xmm4,xmm4,0x0c \n" " subps xmm3,xmm4 \n" " shufps xmm7,xmm7,0x55 \n" " mulps xmm7,xmm3 \n" " jmp 2f \n" "4: \n" " movaps xmm7,xmm3 \n" " shufps xmm7,xmm7,0x1b \n" " addps xmm7,xmm3 \n" " rsqrtps xmm7,xmm7 \n" " movaps xmm4,xmm0 \n" " shufps xmm4,xmm4,0x80 \n" " movaps xmm2,xmm0 \n" " shufps xmm2,xmm2,0x30 \n" " subps xmm4,xmm2 \n" " movaps xmm6,xmm7 \n" " shufps xmm6,xmm6,0x00 \n" " mulps xmm6,xmm4 \n" " movaps xmm4,xmm0 \n" " shufps xmm4,xmm4,0x08 \n" " movaps xmm2,xmm0 \n" " shufps xmm2,xmm2,0x10 \n" " subps xmm4,xmm2 \n" " shufps xmm7,xmm7,0x55 \n" " mulps xmm7,xmm4 \n" " jmp 2f \n" "5: \n" " movaps xmm7,xmm4 \n" " shufps xmm7,xmm7,0x4e \n" " addps xmm7,xmm4 \n" " rsqrtps xmm7,xmm7 \n" " movaps xmm2,xmm0 \n" " shufps xmm2,xmm2,0x0c \n" " movaps xmm3,xmm0 \n" " shufps xmm3,xmm3,0x40 \n" " subps xmm2,xmm3 \n" " movaps xmm6,xmm7 \n" " shufps xmm6,xmm6,0x55 \n" " mulps xmm6,xmm2 \n" " movaps xmm2,xmm0 \n" " shufps xmm2,xmm2,0x30 \n" " movaps xmm3,xmm0 \n" " shufps xmm3,xmm3,0x80 \n" " subps xmm2,xmm3 \n" " shufps xmm7,xmm7,0x00 \n" " mulps xmm7,xmm2 \n" "2: \n" " movaps xmm3,xmm6 \n" " subps xmm3,xmm7 \n" " addps xmm7,xmm6 \n" " movaps xmm4,xmm3 \n" " mulps xmm4,xmm4 \n" " movaps xmm6,xmm7 \n" " mulps xmm6,xmm6 \n" " movaps xmm2,xmm4 \n" " shufps xmm2,xmm6,0x11 \n" " shufps xmm4,xmm6,0xee \n" " addps xmm4,xmm2 \n" " movaps xmm2,xmm4 \n" " shufps xmm2,xmm2,0xb1 \n" " addps xmm4,xmm2 \n" " rsqrtps xmm4,xmm4 \n" " movaps xmm6,xmm4 \n" " shufps xmm4,xmm4,0x00 \n" " shufps xmm6,xmm6,0xaa \n" " mulps xmm3,xmm4 \n" " mulps xmm7,xmm6 \n" "" " movaps xmm6,xmm1 \n" " shufps xmm6,xmm6,0x00 \n" " shufps xmm1,xmm1,0x55 \n" " mulps xmm6,xmm3 \n" " mulps xmm1,xmm7 \n" " addps xmm1,xmm6 \n" "" " movaps xmm3,xmm5 \n" " shufps xmm3,xmm3,0x00 \n" " shufps xmm5,xmm5,0x55 \n" " mulps xmm1,xmm5 \n" " mulps xmm0,xmm3 \n" " addps xmm0,xmm1 \n" " movaps xmm7,xmm0 \n" " mulps xmm7,xmm7 \n" " shufps xmm7,xmm7,0x39 \n" " movss xmm5,xmm7 \n" " shufps xmm7,xmm7,0x39 \n" " movss xmm3,xmm7 \n" " shufps xmm7,xmm7,0x39 \n" " movss xmm1,xmm7 \n" " addss xmm5,xmm3 \n" " addss xmm5,xmm1 \n" " rsqrtss xmm5,xmm5 \n" " shufps xmm5,xmm5,0x00 \n" " mulps xmm0,xmm5 \n" ".att_syntax prefix \n" " movaps %%xmm0,%0 \n" ""::"m" (q), "m" (xcos[0]), "m" (zcos[0]):); return; #else double u[3]; { double p1[3], p2[3]; { int i0=0; double n0=n[0]; for(int i=1; i<3; i++) if(abs(n[i])>abs(n0)){ i0=i; n0=n[i]; } int i1=(i0+1)%3, i2=(i0+2)%3; double n1=n[i1], n2=n[i2], nq=n0*n0; double r1=1/sqrt(nq+n1*n1), r2=1/sqrt(nq+n2*n2); p1[i0]=-n1*r1; p1[i1]=n0*r1; p1[i2]=0; p2[i0]=-n2*r2; p2[i1]=0; p2[i2]=n0*r2; } { double q1[3], q2[3], r1=0, r2=0; for(int i=0; i<3; i++){ double a1=p1[i]-p2[i]; q1[i]=a1; r1+=a1*a1; double a2=p1[i]+p2[i]; q2[i]=a2; r2+=a2*a2; } r1=1/sqrt(r1); r2=1/sqrt(r2); for(int i=0; i<3; i++){ p1[i]=q1[i]*r1; p2[i]=q2[i]*r2; } } for(int i=0; i<3; i++) u[i]=px*p1[i]+py*p2[i]; } { double r=0; for(int i=0; i<3; i++){ double a=n[i]*cs+u[i]*si; n[i]=a; r+=a*a; } if(abs(1-r)>xx){ r=1/sqrt(r); for(int i=0; i<3; i++) n[i]*=r; } } #endif } void rotate(){ double xi=xrnd(); xi=2*xi-1; double g=m.g; if(g!=0){ double g2=g*g; double ga=(1-g2)/(1+g*xi); xi=(1+g2-ga*ga)/(2*g); } if(xi>1) xi=1; else if(xi<-1) xi=-1; double si=sqrt(1-xi*xi); rotate(xi, si); } void advance(double a){ t+=a/m.cm; for(int i=0; i<3; i++) r[i]+=n[i]*a; } void propagate(){ double TOT=-log(xrnd()); while(true){ double tot=m.aX(TOT, r[2], n[2]); double SCA=-log(xrnd()); double sca=m.sX(SCA, r[2], n[2]); if(sca>tot) sca=tot; KEY om=sphere(sca); TOT-=m.xA(sca, r[2], n[2]); advance(sca); if(om.str>=0){ #ifndef ICETRAY cout<<"HIT "<0){ dn[i]=start; dx[i]=end; } else{ dn[i]=end; dx[i]=start; } } #ifdef XACCL int xl[2], xh[2]; for(int i=0; i<2; i++){ xl[i]=max((int) floor((dn[i]-rl[i])*rst[i]), 0); xh[i]=min((int) floor((dx[i]-rl[i])*rst[i]), ncel-1); } if(dn[2]rl[2]) for(int i=xl[0]; i<=xh[0]; i++) for(int j=xl[1]; j<=xh[1]; j++) for(vector::const_iterator c=cells[i][j].begin(); c!=cells[i][j].end(); c++){ int sn=*c; const STR & s=strs[sn]; #else for(map::const_iterator str=strs.begin(); str!=strs.end(); str++){ int sn=str->first; const STR & s=str->second; #endif bool pass=false; for(int i=0; i<3; i++) if(s.rh[i]dx[i]){ pass=true; break; } if(pass) continue; int n1=(int) ceil (s.h-(dx[2]-s.zn-s.zl)*s.st); int n2=(int) floor(s.h-(dn[2]-s.zx-s.zl)*s.st); if(n1>s.h || n20){ D=sqrt(D); h=b-D; if(h<0) h=b+D; } if(h>0 && h=0) sca=hmin; return imin; } }; void flasher(int str, int dom, unsigned long long num){ x.init_flasher(str, dom); for(unsigned long long i=0; i1) str=atoi(arg_a[1]); if(arg_c>2) dom=atoi(arg_a[2]); if(arg_c>3) num=(unsigned long long) atof(arg_a[3]); if(arg_c>4) seed=atoi(arg_a[4]); srand(1+seed); flasher(str, dom, num); } } #endif