Beispiel #1
0
static void  drawgraph(void)
{
 int         n=101;
 double  f[202]; 
   
  calccoef();
  if(err_code) { messanykey(10,10,"Error in kinematics"); return; }
          
  do
  {  if (correctInt(56,8,"Number of points=",&n,1))
     {
        if (n < 3) messanykey(56,8,"Too few points");
        if (n > 201) messanykey(56,8,"Too many points");
     }
      else return;
  }  while (n < 3 || n > 201 );

           
  if( !fillseq(n,f)) 
  {  messanykey(10,10,"Error in calculation"); 
     return;
  }

  plot_1(cos1,cos2,n,f,NULL,procname,"cos(p1,p3)", "Diff. cross section [pb]");

}
Beispiel #2
0
int main(int argc,char** argv)
{  
 char   procName[100],xName[60],yName[60],buff[200];
 double xMin,xMax;
 int xDim=1;
 double yMin,yMax;
 int yDim=1;
 int ptype=-1; 
 double *f=NULL, *df=NULL;

 int i; 
 int n;
 char icon_name[STRSIZ];
 blind=0;

 strcpy(pathtocomphep,argv[0]);
 n = strlen(pathtocomphep)-1;
 while (n>=0 &&  pathtocomphep[n] != f_slash) n--;
 pathtocomphep[n-3]=0;
 sprintf(pathtohelp,"%shelp%c",pathtocomphep,f_slash);

 while(1==fscanf(stdin,"%[^\n]%*c",  buff))
 { char word[40];
   if(buff[0]!='#') break;
   if(1==sscanf(buff+1,"%s",word))
   {      if(strcmp(word,"type")==0)   sscanf(buff+1,"%*s %d",&ptype);  
     else if(strcmp(word,"type")==0)   sscanf(buff+1,"%*s %d",&ptype);  
     else if(strcmp(word,"xMin")==0)   sscanf(buff+1,"%*s %lf",&xMin);  
     else if(strcmp(word,"xMax")==0)   sscanf(buff+1,"%*s %lf",&xMax);  
     else if(strcmp(word,"yMin")==0)   sscanf(buff+1,"%*s %lf",&yMin);  
     else if(strcmp(word,"yMax")==0)   sscanf(buff+1,"%*s %lf",&yMax);  
     else if(strcmp(word,"xDim")==0)   sscanf(buff+1,"%*s %d",&xDim);  
     else if(strcmp(word,"yDim")==0)   sscanf(buff+1,"%*s %d",&yDim);    
     else if(strcmp(word,"title")==0)  
     { for(i=strlen(buff);buff[i-1]==' '; i--);
       sscanf(buff+1,"%*s %[^\n]",procName);  
     }
     else if(strcmp(word,"xName")==0) 
     { for(i=strlen(buff);buff[i-1]==' '; i--);
       sscanf(buff+1,"%*s %[^\n]",xName);  
     }   
     else if(strcmp(word,"yName")==0) 
     { for(i=strlen(buff);buff[i-1]==' '; i--);
       sscanf(buff+1,"%*s %[^\n]",yName);  
     }
   } else break;
   
 }  
  
 f=(double*)malloc(xDim*yDim*sizeof(double));   
 if(ptype)
 { 
   df=(double*)malloc(xDim*yDim*sizeof(double)); 
   sscanf(buff,"%lf  %lf",f,df);  
   for(i=1;i<xDim*yDim;i++) fscanf(stdin,"%lf  %lf",f+i,df+i);
   for(i=1;i<xDim*yDim;i++) if( !finite(f[i])|| !finite(df[i]) )
      { printf(" NAN in table %s\n",procName); return 0;}
 }
 else 
 { 
   sscanf(buff,"%lf",f);
   for(i=1;i<xDim*yDim;i++) fscanf(stdin,"%lf",f+i);
   for(i=1;i<xDim*yDim;i++) if( !finite(f[i])){ printf(" NAN in table %s\n",procName); return 0;} 
 }             
 sprintf(icon_name,"%sicon",pathtocomphep);
 start1(version,icon_name,"calchep.ini;../calchep.ini",NULL);  
 clearTypeAhead();
 if(ptype==2) plot_2(xMin,xMax,xDim,yMin,yMax,yDim,f,df,procName,xName,yName);
 else plot_1(xMin,xMax,xDim,f,df,procName, xName, yName);
 finish();
 return 0;
}
Beispiel #3
0
void  paramdependence(r_func  ff, char*  procname, char*  resultname)
{
   double      minprm, maxprm;
   int         npoints;
   double      memprm, stepprm;
   unsigned    count;
   double f[201];
   int Esc=0,mPos=1;
   double prmval; 
   char txt[100];
   char name[20];
   double *vPos;   
   if(!selectParam(54,11,"Choose parameter",NULL,nin_int==2,1,0,&vPos,name,&mPos)) return; 

   memprm=*vPos;
 
   minprm = memprm; 
   maxprm = minprm; 
    
label1:
   sprintf(txt,"'%s' min=",name); 
   if (!correctDouble(55,14,txt,&minprm,0))  return;

label2:
   sprintf(txt,"'%s' max=",name);    
   if (!correctDouble(55,15,txt,&maxprm,0)) 
   { 
      goto_xy(55,14);
      clr_eol(); 
      goto label1;
   } 
   if (maxprm <= minprm) 
   { 
      messanykey(55,17,"Range check error"); 
      goto_xy(55,15);
      clr_eol();
      goto label2;
   } 

label4: npoints = 101;
   if (correctInt(55,16,"Number of points= ",&npoints,0)) 
   { 
      if (npoints < 3) 
      { 
         messanykey(55,17,"Too few points!"); 
         goto label4;
      } 
      if (npoints > 201) 
      { 
          messanykey(55,17,"Too many points!"); 
          goto label4;
      } 
   } 
   else
   { 
      goto_xy(55,15);
      clr_eol(); 
      goto label2;
   }

   goto_xy(55,14); clr_eol();
   goto_xy(55,15); clr_eol();
   goto_xy(55,16); clr_eol();

   stepprm = (maxprm - minprm)/(npoints - 1); 

   informline(0,npoints);

   stepprm = (maxprm - minprm) / (npoints - 1); 
   prmval=minprm;
   err_code = 0; 

   for(count = 1; count <= npoints; count++)
   { 
      *vPos=prmval;
      err_code=checkParam();
      if(err_code>1) break; 

      f[count-1] = ff();
      if(err_code>1) break;
      
      Esc=informline(count,npoints);
      if(Esc) break;       
      prmval += stepprm;
   } 
 
   if(err_code) errormessage();
   strcpy(txt,name);
   if (err_code <=1 && Esc==0)  plot_1(minprm,maxprm ,npoints,f,NULL,procname,txt,resultname); 
   *vPos=memprm; 
   calcFunc_int();
} 
Beispiel #4
0
void showHist(int X, int Y)
{
   char  histStr1[STRSIZ],histStr2[STRSIZ];
   linelist ln=histTab.strings;
   char * menutxt;
   void * pscr=NULL;
   int mode =0;
   char procName[60];
   int npos=0;
   int width,width1,width2;
   int i,j;
   
   for(i=0,j=0;Process[i];i++) 
      if(Process[i]!='%') procName[j++]=Process[i];
   procName[j]=0;
   
   while(ln)
   {  npos++;
      ln=ln->next;     
   }
   if(!npos) return; 

   for(ln=histTab.strings,width1=0,width2=0; ln; ln=ln->next,npos++)
   { sscanf(ln->line,"%[^|]|%*[^|]|%*[^|]|%[^|]",histStr1,histStr2);
     trim(histStr1);
     trim(histStr2);
     { int l1=strlen(histStr1), l2=strlen(histStr2);
       if(width1<l1) width1=l1;
       if(width2<l2) width2=l2;
     }  
   }

   width=width1+width2+3;
   if(width<12) {width1=12-width2-3; width=width1+width2+3;}
   menutxt=malloc(2+width*npos);
   menutxt[0]=width;
   menutxt[1]=0;
   
   for(ln=histTab.strings; ln; ln=ln->next)
   {  
      sscanf(ln->line,"%[^|]|%*[^|]|%*[^|]|%[^|]",histStr1,histStr2);
      trim(histStr1);
      trim(histStr2);
      if(width2) sprintf(menutxt+strlen(menutxt)," %-*.*s| %-*.*s",
                   width1,width1,histStr1,width2,width2,histStr2);
      else       sprintf(menutxt+strlen(menutxt)," %-*.*s  ",
                   width1,width1,histStr1);
   }
   
   for(;;)
   {  
      menu1(X,Y,"Distributions",menutxt,"",&pscr,&mode);

      switch(mode)
      {
      case 0: free(menutxt);return;
      default: 
      {  histRec * hist=histPtr;
         int nBin1,nBin2;
         ln=histTab.strings;
         for(npos=1;npos<mode;npos++) ln=ln->next; 
         for( ;hist && hist->mother!= ln;hist=hist->next){;}
         if(hist)
         {  
            char xname[80],yname[80],units[80];                                    
                                                                                   
            if( hist->nPoints == 0) messanykey(10,10,"Distibution is empty");     
            else
            if(strcmp(hist->key[1],"0")==0)
            while(nBin1=nBinMenu(X,Y+4))                                                                   
            {  double f[300],df[300],coeff;                                        
               int i;
               coeff=nBin1/(hist->nPoints*(hist->hMax[0] - hist->hMin[0]));               

               for(i=0;i<nBin1;i++)                                                 
               {  int k;                                                           
                  f[i]=0;                                                          
                  df[i]=0;                                                         
                  for(k=0;k<300/nBin1;k++)                                          
	          {  f[i] += coeff*hist->f[i*300/nBin1+k];            
                    df[i] += coeff*coeff*hist->ff[i*300/nBin1+k];                   
                  }                                                                
                  df[i]=sqrt(fabs(df[i] - f[i]*f[i]/hist->nPoints));                      
               }                                                                                  
               if(nin_int==2) strcpy(yname,"Diff. cross section [pb");                 
               else       strcpy(yname,"Diff. width [GeV");                        
               xUnit(hist->key[0][0],units); 
               strcpy(xname,hist->title[0]);                          
               if(units[0]) { strcat(yname,"/");strcat(yname,units);}              
               strcat(yname,"]");                                                  
                                                                                   
               plot_1(hist->hMin[0],hist->hMax[0],nBin1,f,df,procName,xname,yname);       
            } else
            while(nBinMenu2(X,Y+4,&nBin1,&nBin2))                                                                   
            {  double f[900],df[900],coeff;                                        
               int i,j;                     
               coeff=nBin1*nBin2/(hist->nPoints*(hist->hMax[0]-hist->hMin[0])
                                               *(hist->hMax[1]-hist->hMin[1]));               

               for(i=0;i<nBin1;i++)  for(j=0;j<nBin2;j++)
               {  int k,l,pos;
                  pos=i*nBin2+j;                                                           
                  f[pos]=0;                                                          
                  df[pos]=0;                                                         
                  for(k=0;k<30/nBin1;k++) for(l=0;l<30/nBin2;l++)                                         
	          {  f[pos] += coeff*hist->f[30*(i*30/nBin1+k)+j*30/nBin2+l];
                    df[pos] += coeff*coeff*hist->ff[30*(i*30/nBin1+k)+j*30/nBin2+l];                   
                  }
                  df[pos]=sqrt(df[pos] - f[pos]*f[pos]/hist->nPoints);                      
               } 
                                                                                                                                
               strcpy(xname,hist->title[0]);
               strcpy(yname,hist->title[1]);
               xUnit(hist->key[0][0],units);
               if(units[0])sprintf(xname+strlen(xname),"[%s]",units);
               xUnit(hist->key[1][0],units);
               if(units[0])sprintf(yname+strlen(yname),"[%s]",units);
                                                                                    
               plot_2(hist->hMin[0],hist->hMax[0],nBin1,
                      hist->hMin[1],hist->hMax[1],nBin2,
                       f,df,procName,xname,yname);       
            }                                                                                  
         }
      }       
      }
   }
}
Beispiel #5
0
static void show_dependence(int X, int Y)
{ void *pscr1=NULL;
  int i,mPos=1; 
  REAL mem;
  int nc,ni,pos1,pos2;
  char txt[50];
  for(pos1=1;;)
  { nc=findParam(X-1,Y,0,nModelVars,nModelFunc,"Constraint",&pos1);
    if(!pos1) return;
    for(pos2=1;;)
    { double xMin,xMax;
      int nPoints=100;
      sprintf(txt,"check \"%s\" depends on",varNames[nc]); 
      ni=findParam(X-1,Y,0,0,nModelVars,txt,&pos2);
      mem=varValues[ni];
      if(ni<0) break; 
      
      xMin=varValues[ni] - fabs(varValues[ni] )/10;
      xMax=varValues[ni] + fabs(varValues[ni] )/10;
      
      for(;;)
      {  int k3=0; 
         char strmen[]="\026 "
            " x-Min = XXX          "
            " x-Max = YYY          "
            " Npoints = NNN        "
            " Display              ";

         improveStr(strmen,"XXX","%G",xMin);
         improveStr(strmen,"YYY","%G",xMax);
         improveStr(strmen,"NNN","%d",nPoints);
         sprintf(txt,"check %s(%s)",varNames[nc],varNames[ni]);        
         menu1(X,Y+2,txt,strmen,"",NULL,&k3);
         if(!k3) break;
         switch(k3)
         {  case 1: correctDouble(X,Y+12,"xMin = ",&xMin,1); break;
            case 2: correctDouble(X,Y+12,"xMax = ",&xMax,1); break;
            case 3: correctInt(X,Y+12,"nPoints = ",&nPoints,1); break;
            case 4:
            if( xMax>xMin && nPoints>=3 && nPoints<=150)
            {  double dx=(xMax-xMin)/(nPoints-1);
               double f[150];
               int i, NaN=0,Esc=0;
         
               informline(0,nPoints);               
               for(i=0;i<nPoints;i++)
               {  double x=xMin+i*dx;
                  varValues[ni]=x;
                  NaN=calcMainFunc();
                  if(NaN) 
                  {  char mess[100];
                     sprintf(mess,"Can not evaluate constraints for %s=%G",varNames[ni], x);
                     messanykey(16,5,mess);        
                     break;
                  }
                  f[i]=varValues[nc];
                  Esc=informline(i,nPoints);
                  if(Esc) break;  
               }
                  
               varValues[ni]=mem;
               calcMainFunc();

               if(!(NaN||Esc)) plot_1(xMin,xMax,nPoints,f,NULL,"Plot",
                              varNames[ni], varNames[nc]);
                               
            } else messanykey(16,5," Correct input is \n"
                                   "  xMin<xMax,\n"
                                   " 3<=nPoints<=150");
            break;
         }
       }
     }
  }
}
Beispiel #6
0
static void f7_prog(int mode)
{ int pos=1;
  void *pscr=NULL;
  if(mode>2) 
  { messanykey(10,15," Highlight the corresponding\n"
                     "structure function");
    return;
  }     

  if(!sf_num[mode-1]) return;
  
  f3_key[4]=NULL;

  for(;;)
  {  static double xMin=0.0, xMax=1.0, scale = 91.187;
     static int nPoints=100;
     double f[150];
     
     char strmen[]="\030 "
                  " x-Min = XXX            "
                  " x-Max = YYY            "
                  " Npoints = NNN          "
                  " QCD-scale= QQQ         "
                  " Display plot x*F(x)    "
                  " Display plot F(x)      ";
     
     improveStr(strmen,"XXX","%.3f",xMin);
     improveStr(strmen,"YYY","%.3f",xMax);
     improveStr(strmen,"NNN","%d",nPoints);
     improveStr(strmen,"QQQ","%.1fGeV",scale); 

     menu1(54,14,"",strmen,"n_alpha_view",&pscr,&pos);

     switch(pos)
     {  case 0: f3_key[4]=f7_prog; 
                return;
        case 1:
          correctDouble(55,18,"xMin = ",&xMin,1);                  
          break; 
        case 2:
          correctDouble(55,18,"xMax = ",&xMax,1);                  
          break; 
        case 3:
          correctInt(50,18,"nPoints = ",&nPoints,1);
          break; 
        case 4: 
          correctDouble(50,18,"QCD-scale = ",&scale,1);
          break;
        case 5: case 6:
         if(xMin>=0 && xMax>xMin && xMax<=1 
            && nPoints>=3 && nPoints<=150 && scale>0.5)
         {
           void * screen;
           double dx=(xMax-xMin)/(2*nPoints);
           double be=sf_be[mode-1];
           int i;
           get_text(1,1,maxCol(),maxRow(),&screen);
           for(i=0;i<nPoints;i++)
           {  double x=xMin+(i+0.5)*(xMax-xMin)/nPoints;
              f[i]=strfun_(mode,x,scale);
              if(pos==5) f[i]*=x;
              if(be!=1.) f[i]*=be*pow(1.-x,be-1.);
           }
           {
              char p_name[20], mess[STRSIZ];
              strcpy(p_name,pinf_int(Nsub,mode,NULL,NULL));
              if(pos==5) strcat(p_name,"(x)*x"); else strcat(p_name,"(x)");
              strFunName(mode,mess);
              trim(mess);
              sprintf(mess+strlen(mess)," [QCD-scale = %.1f GeV]",scale); 
              plot_1(xMin+dx,xMax-dx,nPoints,f,NULL,mess,"x",p_name);  
           }
           put_text(&screen);
         } else messanykey(16,5," Correct input is \n"
                                "  0<=xMin<xMax<=1,\n"
                                " QCD-scale > 0.5 GeV\n"
                                " 3<=nPoints<=150");    
         break;    
      }
   }
}