static void generateEvents( vegasGrid * vegPtr, char *fname, FILE * iprt) { long nGenerated=0; double eff; int nmax,mult,neg; char mess[200]; long cEvent; long fileEnd; double sumW,sumW2; event_stat stat; events_= fopen(fname,"a"); if(ftell(events_)==0) write_event_cap(); fileEnd=ftell(events_); fflush(events_); cEvent= vegas_events(vegPtr,nEvents,max,writeEvent,regenEvents,nPROCSS,&stat); // &eff,&nmax,&mult,&neg); eff=stat.eff; neg=stat.neg; mult=stat.lmax; fclose(events_); if(cEvent>0) { int l; sprintf(mess,"Statistic\n Events generated: %ld\n efficiency: %.1E\n" "<weight^2>/<weight>^2-1: %.1E \nNegative weight events: %d \n", cEvent, eff, cEvent*stat.sumW2/stat.sumW/stat.sumW-1., neg); l=strlen(mess); strcat(mess,"---------------\n Accept events? "); if(mess_y_n(25,15,mess)) { long nEvPos=0,nWpos=0; integral.old=1; mess[l]=0; events_=fopen(fname,"r+"); while(nEvPos==0 || nWpos==0) { char ch; char word[100]; do fscanf(events_,"%c",&ch); while(ch !='#'); fscanf(events_,"%s",word); if(strcmp(word,"Number_of_events")==0) nEvPos=ftell(events_); if(strcmp(word,"Sum_of_weights")==0) nWpos=ftell(events_); } fseek(events_,nEvPos,SEEK_SET); fscanf(events_,"%ld",&nGenerated); nGenerated+=cEvent; fseek(events_,nEvPos,SEEK_SET); fprintf(events_," %10ld",nGenerated); fseek(events_,nWpos,SEEK_SET); fscanf(events_,"%lf %lf",&sumW,&sumW2); sumW+=stat.sumW; sumW2+=stat.sumW2; fseek(events_,nWpos,SEEK_SET); fprintf(events_," %12.4E %12.4E",sumW,sumW2); fclose(events_); fprintf(iprt," %ld events are stored in '%s'\n",nGenerated,fname); fprintf(iprt,"%s\n",mess); fflush(iprt); } else truncate(fname,fileEnd); } }
static void generateEvents( vegasGrid * vegPtr, double (*func)(double *,double,double*), char *fname, FILE * iprt) { int mode=1; void * pscr=NULL; static int regen=1; // if(!vegPtr->fMax)improveEvents(vegPtr,func); for(mode=1;;) { char strmen[]="\032" " Number of events=N1 " " Launch generator " " Allow weighted events OFF"; if(!regen) improveStr(strmen,"OFF","%s","ON"); improveStr(strmen,"N1","%d",nEvents); menu1(53,10,"",strmen,"n_gen_*",&pscr,&mode); switch(mode) { case 0: return; case 1: correctLong(50,15,"",&nEvents,1); break; case 2: { long nGenerated=0; double eff; int nmax,mult,neg; char mess[200]; long cEvent; long fileEnd; if(!vegPtr->fMax) { messanykey(15,15,"Generator is not ready."); break;} events_= fopen(fname,"a"); if(ftell(events_)==0) write_event_cap(); fileEnd=ftell(events_); build_cb_int(Nsub); cEvent= vegas_events(vegPtr,nEvents,max,func,writeEvent,regen,&eff,&nmax,&mult,&neg); fclose(events_); if(cEvent>0) { int l; sprintf(mess,"Statistic\n Events generated: %ld\n efficiency: %.1E\nMax event multiplicity: %d\n" "Multiple events(total): %d \nNegative weight events: %d \n", cEvent, eff,nmax,mult, neg); l=strlen(mess); strcat(mess,"---------------\n Accept events? "); if(mess_y_n(25,15,mess)) { long nEvPos=0; integral.old=1; mess[l]=0; events_=fopen(fname,"r+"); while(nEvPos==0) { char ch; char word[100]; do fscanf(events_,"%c",&ch); while(ch !='#'); fscanf(events_,"%s",word); if(strcmp(word,"Number_of_events")==0) nEvPos=ftell(events_); } fscanf(events_,"%ld",&nGenerated); nGenerated+=cEvent; fseek(events_,nEvPos,SEEK_SET); fprintf(events_," %10ld",nGenerated); fclose(events_); fprintf(iprt," %ld events are stored in '%s'\n",nGenerated,fname); fprintf(iprt,"%s\n",mess); fflush(iprt); } else truncate(fname,fileEnd); } destroy_cb_int(); } break; // case 3: improveEvents(vegPtr,func); put_text(&pscr); break; case 3: regen=!regen; // goto ret; } } }