예제 #1
0
파일: runVegas.c 프로젝트: Omer80/wimps
int readVegasGrid(FILE * f)
{
  int i,j,ndim,ndmx;
  double * x;
  
  if(veg_Ptr) {vegas_finish(veg_Ptr);veg_Ptr=NULL;}  
  fscanf(f," Vegas_grid: dim=%d  size=%d\n", &ndim, &ndmx);
  if(ndim && ndmx)
  { 
    veg_Ptr=vegas_init(ndim,ndmx);
    x=veg_Ptr->x_grid;
    for(i=0;i<ndim;i++)for(j=0;j<=ndmx;j++) fscanf(f," %lf",(x++));
    fscanf(f," Max(%ld):\n",&(veg_Ptr->nCubes));       
    if(veg_Ptr->nCubes) 
    { long l;
      veg_Ptr->fMax=malloc(sizeof(float)*veg_Ptr->nCubes);
      for(l=0;l<veg_Ptr->nCubes;l++) fscanf(f,"%f",veg_Ptr->fMax+l);
    } else veg_Ptr->fMax=NULL;
  }
  return 0;
}
예제 #2
0
파일: runVegas.c 프로젝트: restrepo/CalcHEP
int readVegasGrid(FILE * f)
{
  int i,j,ndim,ndmx;
  long nCubes;
  
  if(veg_Ptr) {vegas_finish(veg_Ptr);veg_Ptr=NULL;}  
  fscanf(f," Vegas_grid: dim=%d  size=%d\n", &ndim, &ndmx);
  if(ndim && ndmx)
  { 
    veg_Ptr=vegas_init(ndim,func_,ndmx);
    for(i=0;i<ndim;i++)for(j=0;j<=ndmx;j++) fscanf(f," %lf",&(veg_Ptr->x_grid[i][j]) );
    fscanf(f," Max(%ld):\n",&nCubes);   
    
    setEventCubes(veg_Ptr, nCubes);
    if(nCubes && veg_Ptr->evnCubes==nCubes) 
    { long l;
      veg_Ptr->fMax=malloc(sizeof(double)*veg_Ptr->evnCubes);
      for(l=0;l<veg_Ptr->evnCubes;l++) fscanf(f,"%lf",veg_Ptr->fMax+l);
    }
  }
  return 0;
}
예제 #3
0
int runVegas(void)
{
    int i;
    double sd;
    double avgi;
    char mess[25];
    FILE * iprt = NULL;
    int mode=1;
    void * pscr=NULL;
    static int n_Line=7;

    i=imkmom(inP1,inP2);
    if(veg_Ptr&&veg_Ptr->ndim!=i)clearGrid();
    if(!veg_Ptr) veg_Ptr=vegas_init(i,50);     

    if(nin_int == 2) strcpy(mess, "Cross section[pb]");
      else           strcpy(mess, "   Width[Gev]    ");
    
/* ** save current session parameters */
     w_sess__(NULL);
/* ** open protocol and resulting files */
       
    {  char fname[50];
       sprintf(fname,"%sprt_%d",outputDir,nSess);
       iprt=fopen(fname,"a");
       if(ftell(iprt)==0) 
       { fprintf(iprt,"    CalcHEP kinematics module \n The session parameters:\n");
         w_sess__(iprt);
         fprintf(iprt,"===================================\n");   
       }
    }

/* **  initkinematics */

    while(correctHistList()) editHist();
    
/* *** Main cycle */
    if(!integral.old || n_Line==7)
    { n_Line=7;
      scrcolor(Blue, BGmain);
//    printLn(iprt,&n_Line," #IT  %20s Error %%    nCall   chi**2",mess); 
      printLn(iprt,&n_Line," #IT %s Error[%%]  nCalls   Eff.  chi^2",mess);
    }

    for(;;)
    {
        static int worn=1;
        char strmen[]="\030"
         " nSess  = N2_1          "
         " nCalls = N1_1          "
         " Set  Distributions     "
         "*Start integration      "
         " Display Distributions  "
         " Clear statistic        "
         " Freeze grid        OFF " 
	 " Clear  grid            "
	 " Event Cubes NCUBE      "
	 " Generate Events        ";

        improveStr(strmen,"N1_1","%d",integral.ncall[0]);
        improveStr(strmen,"N2_1","%d",integral.itmx[0]);
        improveStr(strmen,"NCUBE","%d",EventGrid);

        if(integral.freeze) improveStr(strmen,"OFF","ON");

        menu1(54,7,"",strmen,"n_veg_*",&pscr,&mode);
        switch(mode)
        {     
        case 0:
          if(iprt) fclose(iprt);
          return 0;           
        case 1:  
          correctInt(50,12,"Enter new value ",&integral.itmx[0],1); break;
        case 2: 
          correctLong(50,12,"Enter new value ",&integral.ncall[0],1); break;
        case 3:  editHist(); break;
        case 4:
          if(veg_Ptr->fMax && !integral.freeze)
          {  if(!mess_y_n(15,15,"You have event generator prepared.\n"
             " The  answer 'Y'  will start Vegas session \nwhich destroys it."
             " To save the event generator answer 'N' \nand set "
             " ' Freeze grid' ON")) break;
             else { free(veg_Ptr->fMax); veg_Ptr->fMax=NULL; veg_Ptr->nCubes=0;}  
          }
          for (i = 1; i <= integral.itmx[0]; ++i)                                       
          { double sum;
            char  errtxt[100]="";
            int k;

            if(integral.ncall[0]==0) break;
            nCall=0;                                                                  
            negPoints=0;                                                              
            badPoints=0; 
            hFill=1;  
            if(vegas_int(veg_Ptr, integral.ncall[0],1.5*(!integral.freeze), 
                 func_, &avgi, &sd)        
              ) break;
            integral.old=1;                                              
            negPoints/=nCall;                                                         
            badPoints/=nCall;                                                         
            integral.nCallTot+=nCall;                                                          
            scrcolor(FGmain,BGmain);                                                 
            printLn(iprt,&n_Line,"%4d   %12.4E %10.2E %8d %s",                     
                 ++integral.n_it, avgi,avgi? 100*sd/(double)fabs(avgi):0.,nCall,effInfo());
                                                                   
            if(negPoints<0) sprintf(errtxt+strlen(errtxt)," Negative points %.1G%%;",                
                                      -100*negPoints/(avgi-2*negPoints));             
            if(badPoints)  sprintf(errtxt+strlen(errtxt),                             
                 "Bad Precision %.1G%%;",100*badPoints/(avgi-2*negPoints));           
                                                                                      
            if(errtxt[0])                                                             
            {                                                                         
               scrcolor(Red,BGmain);                                                  
               printLn(iprt,&n_Line,"%s",errtxt);                                     
            }
                                                                                                                                                
            integral.s0+=sd*sd;                                                                  
            integral.s1+=avgi;                                                             
            integral.s2+=avgi*avgi;                                    
          } 
          
          
          integral.In=integral.s1/integral.n_it; 
          integral.dI=sqrt(integral.s0)/integral.n_it;
          if(integral.n_it<=1 || integral.s0==0 ) integral.khi2=0; else 
          integral.khi2=(integral.s2-integral.s1*integral.s1/integral.n_it)*integral.n_it/(integral.n_it-1)/fabs(integral.s0);  
          
          scrcolor(FGmain,BGmain);

          printLn(iprt,&n_Line," < >   %12.4E %10.2E %8d %7.7s %-7.1G" ,
                      integral.In, fabs(integral.In)? 100*integral.dI/(double)fabs(integral.In):0., integral.nCallTot, 
                                                              effInfo(),  integral.khi2);
          if(histTab.strings)
          { char  fname[20];
            FILE * d;
            sprintf(fname,"distr_%d",nSess);
            d=fopen(fname,"w");  
            wrt_hist2(d,Process);
            fclose(d);
          }
                    messanykey(54,11,"Integration is over");
/*          integral.freeze=0; */
          break;

        case 5: showHist(54,10,Process); break;
        case 6: clearStatistics(-1);
                messanykey(54,13,"Old results for integral\n"
                "and distributions\nare deleted.");
                break;
        case 7: integral.freeze=!integral.freeze; break; 
        case 8: if(!integral.freeze || mess_y_n(15,15,"The information for Event Generator will be lost\n OK?"))  
                { int ndim=veg_Ptr->ndim;
                  vegas_finish(veg_Ptr);
                  veg_Ptr=vegas_init(ndim,50);
                  messanykey(57,11,"OK");
                }   
                break;
        case 9: 
           if(correctLong(50,12,"Enter new value ",&EventGrid,1))
           { if(veg_Ptr->fMax) {free(veg_Ptr->fMax); veg_Ptr->fMax=NULL;veg_Ptr->nCubes=0;}} break;
        case 10: 
           if( !veg_Ptr || !veg_Ptr->fMax)
           { char * mess="Before event generation one has to launch  Vegas session with freezed grid\n"
                                           "to prepare generator";
                if(blind) { printf("%s\n",mess); sortie(200);}  else messanykey(4,13,mess);
           }    else    runEvents(); 
       }
    }    
}
예제 #4
0
파일: runVegas.c 프로젝트: restrepo/CalcHEP
int runVegas(void)
{
    int i;
    double sd;
    double avgi;
    char mess[25];
    FILE * iprt = NULL;
    int mode=1;
    void * pscr=NULL;
    static int n_Line=0;
    
    if(blind) vegas_control=NULL; else  vegas_control=infoLine;
    i=imkmom(inP1,inP2);
    if(veg_Ptr&&veg_Ptr->dim!=i)clearGrid();
    if(!veg_Ptr) veg_Ptr=vegas_init(i,func_,50);     

    if(nin_int == 2) strcpy(mess, "Cross section[pb]");
      else           strcpy(mess, "   Width[Gev]    ");
    
/* ** save current session parameters */
     w_sess__(NULL);
/* ** open protocol and resulting files */
       
    {  char fname[50];
       sprintf(fname,"%sprt_%d",outputDir,nSess);
       iprt=fopen(fname,"a");
    }

/* **  initkinematics */

    while(correctHistList()) editHist();

    if(integral.old) { if(!n_Line)  n_Line=9;} else
    {
       w_sess__(iprt);
       n_Line=8;
    }
                           
/* *** Main cycle */

    for(;;)
    {
        int fz;
        char strmen[]="\030"
         " nSess  = N2_1          "
         " nCalls = N1_1          "
         " Set  Distributions     "
         "*Start integration      "
         " Display Distributions  "
         " Clear statistic        "
         " Freeze grid        OFF " 
	 " Clear  grid            "
	 " Event Cubes NCUBE      "
	 " Num. of events=NE      "
	 " Generate Events        ";
	 
        if(integral.freeze)
        {  fz=1;
           improveStr(strmen,"OFF","ON");
           improveStr(strmen,"NCUBE","%d",EventGrid);
        }  
        else
        {  fz=0;
           strmen[ 030*8+2]=0;
        }

        improveStr(strmen,"N1_1","%d",integral.ncall[fz]);
        improveStr(strmen,"N2_1","%d",integral.itmx[fz]);
        improveStr(strmen,"NE","%d",nEvents);
        menu1(54,7,"",strmen,"n_veg_*",&pscr,&mode);
        switch(mode)
        {     
        case 0:
           w_sess__(NULL);
          if(iprt) fclose(iprt);
          return 0;           
        case 1: correctInt(50,12,"Enter new value ", integral.itmx+fz,1);  break;
        case 2: correctLong(50,12,"Enter new value ",integral.ncall+fz,1);break;
        case 3:  editHist(); break;
        case 4:
          if(veg_Ptr->fMax && !integral.freeze) 
          {  free(veg_Ptr->fMax); veg_Ptr->fMax=NULL; veg_Ptr->evnCubes=0; }
          if(!veg_Ptr->fMax && integral.freeze)
          {  setEventCubes(veg_Ptr, EventGrid);
             EventGrid=veg_Ptr->evnCubes;
          }

          for (i = 1; i <= integral.itmx[fz]; ++i)                                       
          { char  errtxt[100]="";
            long nCall;
            if(integral.ncall[0]==0) break;                                                                  
            negPoints=0;                                                              
            badPoints=0; 
            hFill=1;   
            nCall=vegas_int(veg_Ptr, integral.ncall[fz],1.5*(!fz),nPROCSS,&avgi, &sd);
            if(nCall<0) { messanykey(10,10,"NaN in integrand"); break;}
            if(nCall==0) break;
            
            integral.old=1;                                              
            negPoints/=nCall;                                                         
            badPoints/=nCall;                                                         
            integral.nCallTot+=nCall;                                                          
            scrcolor(FGmain,BGmain);                                                 
            printLn(iprt,&n_Line,"%4d   %12.4E %10.2E %8d %s",                     
                 ++integral.n_it, avgi,avgi? 100*sd/(double)fabs(avgi):0.,nCall,effInfo());
                                                                   
            if(negPoints<0) sprintf(errtxt+strlen(errtxt)," Negative points %.1G%%;",                
                                      -100*negPoints/(avgi-2*negPoints));             
            if(badPoints)  sprintf(errtxt+strlen(errtxt),                             
                 "Bad Precision %.1G%%;",100*badPoints/(avgi-2*negPoints));           
                                                                                      
            if(errtxt[0])                                                             
            {                                                                         
               scrcolor(Red,BGmain);                                                  
               printLn(iprt,&n_Line,"%s",errtxt);                                     
            }
                                                                                                                                                
            integral.s0+=sd*sd;                                                                  
            integral.s1+=avgi;                                                             
            integral.s2+=avgi*avgi;                                    
          } 
          
          
          integral.In=integral.s1/integral.n_it; 
          integral.dI=sqrt(integral.s0)/integral.n_it;
          if(integral.n_it<=1 || integral.s0==0 ) integral.khi2=0; else 
          integral.khi2=(integral.s2-integral.s1*integral.s1/integral.n_it)*integral.n_it/(integral.n_it-1)/fabs(integral.s0);  
          
          scrcolor(FGmain,BGmain);

          printLn(iprt,&n_Line," < >   %12.4E %10.2E %8d %7.7s %-7.1G" ,
                      integral.In, fabs(integral.In)? 100*integral.dI/(double)fabs(integral.In):0., integral.nCallTot, 
                                                              effInfo(),  integral.khi2);
          if(histTab.strings)
          { char  fname[20];
            FILE * d;
            sprintf(fname,"distr_%d",nSess);
            d=fopen(fname,"w");  
            wrt_hist2(d,Process);
            fclose(d);
          }
                    messanykey(54,11,"Integration is over");
/*          integral.freeze=0; */
          break;

        case 5: showHist(54,10,Process); break;
        case 6: clearStatistics(-1);
                messanykey(54,13,"Old results for integral\n"
                "and distributions\nare deleted.");
                break;
        case 7: 
             if(veg_Ptr->fMax && integral.freeze) 
             {  if(mess_y_n(15,15,"You have event generator prepared.\n"
                " Setting the flag \"OFF\"  will destroy it."
                " Press 'Y' to confirm.")) integral.freeze=0; 
             } else  integral.freeze=!integral.freeze; 
             break; 
        case 8: if(!integral.freeze || mess_y_n(15,15,"The information for Event Generator will be lost\n OK?"))  
                { int ndim=veg_Ptr->dim;
                  vegas_finish(veg_Ptr);
                  veg_Ptr=vegas_init(ndim,func_,50);
                  messanykey(57,11,"OK");
                }   
                break;
        case 9: 
           if(correctLong(50,12,"Enter new value ",&EventGrid,1))
           { if(veg_Ptr->fMax) {free(veg_Ptr->fMax); veg_Ptr->fMax=NULL;}
             printf("EventGrid=%d\n",EventGrid);
             setEventCubes(veg_Ptr, EventGrid);
             EventGrid=veg_Ptr->evnCubes;  
           } break;
        case 10:  correctInt(50,15,"",&nEvents,1); break;
        case 11: 
           if( !veg_Ptr || !veg_Ptr->fMax)
           { char * mess="Before event generation one has to launch  Vegas session with freezed grid\n"
                                           "to prepare generator";
                if(blind) { printf("%s\n",mess); sortie(200);}  else messanykey(4,13,mess);
           } else  runEvents();
       }
    }    
}