Xytest cprog

From Tauwiki

Jump to: navigation, search
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main (){

    FILE *fout=NULL,*fin=NULL,*fres=NULL;
    float c1,c2,x1,y1,w,s,z,maxs;
    int x,y,s1,s2,xres[500],yres[500],i=0,j=0;
    char line[100];
   
    fres = fopen("xyres","r");
    while((fgets(line,sizeof(line),fres))!=NULL) {
         sscanf(line,"%d%d",&xres[j],&yres[j]);
         j++;
    }

// fclose(fres);

    fin = fopen("xyin","r");
    fout = fopen("xytest","w");


    fprintf(fout,"Comparison of x,y calculation: index is different, since T1 gets 1st event, etc.\n");
    while((fgets(line,sizeof(line),fin))!=NULL) {
          sscanf(line,"%d%d",&s1,&s2);
          if(i%3 !=0 ) {
              i++;
              continue; 
          }
         c1=(float) s1/s2;
         c2=((float) (2048-s1) ) /s2 -1;

//sort pxelisation/c1,pixelisation/c2 right=floor(minimum) =maxS //1024/c1,1024/c2

         if(1024/c1 < 1024/c2) {
               maxs=1024/c1;
         }
         else {
               maxs=1024/c2;
         }

// maxs=ceil(maxs);

         s=maxs-1;
         w=c1*s;
         z=c2*s;
//       printf("1024/c1=%.1f,1024/c2=%.1f",1024/c1,1024/c2);
// 	  printf("\nc1=%.3f,c2=%.3f ",c1,c2);
// 	  printf("\nw=%0.2f,s= %0.2f,z= %0.2f", w,s,z); 
// 	  fprintf(fout,%0.1f %0.1f %0.1f", w,s,z); 
// 	  w=(int)w, z=(int)z, s=(int)s;
// 	  printf("round::  w=%0.2f,s= %0.2f,z= %0.2f", w,s,z); 
        x1=2048.0*w/(w+s+z);
        y1=2048.0*s/(w+s+z);
       
        fprintf(fout,"\n    x_sim[%d] =%d, y_sim[%d] =%d :: ",i,s1,i,s2); 
        fprintf(fout,"x_eqn[%d]=%.0f,y_eqn[%d]=%.0f",i,x1,i,y1);   
        if((s1!=xres[i/3])||(s2!=yres[i/3])) {
               fprintf(fout," :::::: Difference");		
        }
        fprintf(fout,"\n   x_fits[%d] =%d, y_fits[%d]=%d \n",i/3,xres[i/3],i/3,yres[i/3]); 
        i++;
   }
   return 0;
}
//         w = (short)(W / create_level0_data.wgain);
//         s = (short)(S / create_level0_data.sgain);
//         z = (short)(Z / create_level0_data.zgain);
//         W = (short)(Math.round((C[0] * S)));
//         Z = (short)(Math.round((C[1] * S)));
//        float leftlimit[]={1.0f,1/C[0],1/C[1]};
//         java.util.Arrays.sort(leftlimit);
//        float rightlimit[]={create_level0_data.pixelization,
//         create_level0_data.pixelization/C[0], create_level0_data.pixelization/C[1]};
//         java.util.Arrays.sort(rightlimit);
//         //take the maximum of the left limit array i.e the last element in the array
//         //this is the minimum value of S-round it so that it is slightly greater
//         //than the actual min value
//         int minS = (Math.round(leftlimit[2]));
//         //take the minimum of the right limit array i.e the first element in the array
//         //this is the maximum value of S-take only the int part so that it is
//         //slightly lesser than max value
//         int maxS = (int)rightlimit[0];
// //        System.out.println("minS = " + minS + " maxS = " + maxS);
// 
 // 
// 
//            Calculate C1,C2:
//           =================
//        float C1 = 0, C2 = 0;
//         C1 = (float)(x)/(float)(y);
//         C2 = (((2 * create_level0_data.pixelization) - x) /(float)(y)) - 1;
// //        System.out.println("x = " + x + " y = " + y + "C1 = " + C1 + "C2 = " + C2);
//         if(C1 < 0){
//             System.out.println("C1 is negative");
//         }
//         if(C2 < 0){
//             System.out.println("C2 is negative");
//         }
//         float C[] = {C1, C2};
CSS 2.1 Xhtml 1.0 Last Modified: February 22, 2007 GooglePagerank