void NumbPadToPixel(int ich, int side, int *ipx, int *ipz) { /* ich should be 0,1,2 for PC1,2,3 */ const int wire_adjust[3]={0,-1,1}; int tempx,tempz; /* first go from padx,padz space: for one side of one sector in chamber ich PC1: (0,19)x(0,107) to wire,z pad-space (-1,58)x(-1,106) (which in fact gives cell-space correctly (0,57)x(0,105) ..) PC2/3: (0,39)x(0,107) to wire,z pad-space (-1,116)x(-1,106) (which in fact gives cell-space correctly (0,115)x(0,105) ..) */ tempz=*ipz-1; tempx = 3*(*ipx%20)+wire_adjust[(tempz+3)%3]; /* tempx,tempz are now true within all chamberhalves.. Now transform to north side coordinate system*/ if (ich==0) { /* PC1 (-1,58)x(-1,106-1+107)) = (-1,58)x(-1,212) cells: (0,57)x(0,211) */ if (side==0) { /* South */ tempx=57-tempx; tempz=105-tempz; } else tempz=tempz+106; /* North */ } if ((ich == 1) || (ich == 2)) { /* PC2,3 (-1,58-1+59)x(-1,212) = (-1,116)x(-1,212) cells: (0,115)x(0,211) */ if (*ipx>=20) tempx=tempx+58; /* 2nd module */ if (side==0) { /* South */ tempx=115-tempx; tempz=105-tempz; } else tempz=tempz+106; /* North */ } /* and the final twist: PC2 is oriented with the MB towards IP. If we flip the wire direction, it will follow the same standard as the rest: z in the z direction (..) and wire following the phi direction */ if (ich == 1) { /* PC2 */ tempx=115-tempx; } *ipx = tempx; *ipz = tempz; }
And here's the more dense version..
void NumbPadToPixel(int ich, int side, int *ipx, int *ipz) { /* ich should be 0,1,2 for PC1,2,3 */ const int wire_adjust[3] = {0,-1,1}; const int cells_along_wire = 106; /* Number of cells along wire for half a sector(PC1:subsector) */ const int cells_across_wire[3] = {58,116,116}; /* Number of cells across wire for a sector(PC1:subsector) */ int tempx,tempz; tempz=*ipz-1; tempx = 3*(*ipx%20)+wire_adjust[(tempz+3)%3] + (*ipx/20)*58; /* tempx,tempz are now true within all chamberhalves.. Now transform to north side coordinate system*/ if (side==0) { /* South */ tempx=(cells_across_wire[ich]-1)-tempx; tempz=(cells_along_wire-1)-tempz; } else tempz=tempz+cells_along_wire; /* North */ if (ich == 1) { /* PC2 */ tempx=(cells_across_wire[ich]-1)-tempx; } *ipx = tempx; *ipz = tempz; }