mEmcDefGeom.c

Go to the documentation of this file.
00001 #include "mEmcDefGeom.h"
00002 #include "emlLib.h"
00003 
00004 #include "gsl/gsl_math.h"
00005 
00006 #include <math.h>
00007 
00015 long type_of_call mEmcDefGeom_(
00016   TABLE_HEAD_ST  *dEmcGeaParams_h,  DEMCGEAPARAMS_ST    *dEmcGeaParams ,
00017   TABLE_HEAD_ST   *dEmcGeometry_h,   DEMCGEOMETRY_ST     *dEmcGeometry )
00018 {
00019 /*:>--------------------------------------------------------------------
00020 **: ROUTINE:    mEmcDefGeom_
00021 **: DESCRIPTION: Physics Analysis Module ANSI C template.
00022 **:             This is an ANSI C Physics Analysis Module template
00023 **:             automatically generated by stic from mEmcDefGeom.idl.
00024 **:             Please edit comments and code.
00025 **: ARGUMENTS:
00026 **:       IN:
00027 **:    INOUT:
00028 **:      OUT:
00029 **:      dEmcGeaParams    - PLEASE FILL IN DESCRIPTION HERE
00030 **:     dEmcGeaParams_h   - header Structure for dEmcGeaParams
00031 **:       dEmcGeometry    - PLEASE FILL IN DESCRIPTION HERE
00032 **:      dEmcGeometry_h   - header Structure for dEmcGeometry
00033 **: RETURNS:    STAF Condition Value
00034 **:>------------------------------------------------------------------*/
00035   /*              */
00036 
00037 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00038         subroutine EMC_GINI_NEW()
00039         
00040         Authour :
00041                  This routine has been converted to C on Mon Mar  2  1998 by:
00042                  
00043                  Phool Chand            phool@phenix.barc.ernet.in
00044                  Dipanwita Dutta        dipa@phenix.barc.ernet.in
00045 
00046         Modifications:
00047                  Gabor David, May 16 1998
00048         
00049 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00050 
00051 /*     Major revision: November 19, 1998, G. David
00052 
00053        All through the chain we adopt much of the PHENIX numbering scheme
00054        West arm is arm=0, East arm is arm=1
00055        West arm consists of former sectors 1-4
00056        East arm consists of former sectors 5-8, BUT IN REVERSE ORDER
00057        Former    Current
00058        5         3  (PbSc)
00059        6         2  (PbSc)
00060        7         1  (PbGl)
00061        8         0  (PbGl)
00062 
00063        Numbering of towers within a sector:
00064        Columns (z direction) are numbered 0-71 (0-95 for PbGl)
00065        Rows (y, or phi direction) are numbered 0-35 (0-47 for PbGl)
00066 
00067        HOWEVER:
00068        In the West arm column 0 is the column at the highest (positive) z,
00069 
00070        whereas
00071        in the East arm column 0 is the column at the lowest (negative) z
00072        (as before).
00073 
00074        This is done in order to be (more) conform with hardware numbering,
00075        where ALL sectors have their 0,0 element at the lower left corner
00076        WHEN VIEWED FROM BEHIND
00077 
00078        Note, that this new numbering is different from the way geometry
00079        is defined is PISA, where sectors are numbered 1-8, continuously
00080        in phi, and tower numbers start at the lowest negative z.
00081        This change effects mEmcGeaMakeRaw, too.
00082 
00083 */
00084 
00085 /********************************************************/
00086 
00087 #define max1(x,y)       ( ( int ) ( (x) > (y)  ) ? (x) : (y) )
00088 #define amax1(x,y)      ( ( (x) > (y)  ) ? (x) : (y) )
00089 #define max(x,y)        ( ( (x) > (y)  ) ? (x) : (y) )
00090 #define min(x,y)        ( ( (x) < (y)  ) ? (x) : (y) )
00091 
00092    int size;
00093 
00094    int pcons1, pcons2;
00095 
00096 /****************************************************************/
00097 
00098 #define max_chanz       96
00099 #define max_chany       48
00100 #define max_subdet      8
00101 #define max_fields      10
00102 
00103 
00104    float        ra_det[120][max_subdet];
00105 
00106 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00107         c       The number of walls (and detector types) defined can vary;
00108         c       the array I_TRANS translates the "wall,subdetector" pair
00109         c       where wall can be 1 to 8, subdetector is 1 for PbSc,
00110         c       2 for PbGl
00111         c       to a single number (1 to 8), referenced in emc_geom and
00112         c       the hit arrays
00113         c       
00114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00115 
00116    int  i_trans[8][2]   =
00117                 {
00118                 1, 0,
00119                 2, 0,
00120                 3, 0,
00121                 4, 0,
00122                 5, 0,
00123                 6, 0,
00124                 0, 7,
00125                 0, 8
00126                 };
00127 
00128    int  i_limits[16]    = { 72,36,72,36,72,36,72,36,72,36,72,36, 96,48,96,48 };
00129 
00130 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00131         c
00132         c       fields in emc_geom:
00133         c       1,z,y,det --> x position of the center of the front face
00134         c       2,z,y,det --> y position of the center of the front face
00135         c       3,z,y,det --> z position of the center of the front face
00136         c       4,z,y,det --> theta at the center of the front face
00137         c       5,z,y,det --> phi at the center of the front face
00138         c       6,z,y,det --> distance (r) at the center of the front face
00139         c       7,z,y,det --> e(x) -> unit vector for the axis of the tower
00140         c       8,z,y,det --> e(y) -> unit vector for the axis of the tower
00141         c       9,z,y,det --> e(z) -> unit vector for the axis of the tower
00142         c       
00143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00144 
00145    float        emc_geom[max_fields][max_chanz][max_chany][max_subdet];
00146    int  i,j,iz,iy,i1;
00147    int ll;
00148    float          r_work1;
00149    float          r_appx,r_appy,r_appz;
00150    float r_measthe = 0.0;
00151    float r_measphi = 0.0;
00152    
00153    float   r_sectheta,r_secphi,r_dist,r_distz,r_disty;
00154 
00155 
00156 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00157         cgd***      EXTERNAL    GFDETU
00158         c
00159         c
00160         c     MAIN GEOMETRY parameter file (phnx.par) segment
00161         c       
00162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00163 
00164    int  emc_walls       =       8;       /*      number of sectors, lately (4 in each arm)      */
00165 
00166    float        emc_cutgam      =       0.001;
00167    float        emc_cutele      =       0.001;
00168    float        emc_cutneu      =       0.001;
00169    float        emc_cuthad      =       0.001;
00170    float        emc_cutmuo      =       0.001;
00171    float        ra_sampfrac[23][2]      =
00172         {
00173         .0001, .2443, .0002, .2432, .0005, .2313, .0008, .2204, 
00174         .0010, .2054, .0012, .1981, .0015, .1889, .0018, .1809,
00175         .0020, .1760, .0022, .1717, .0025, .1650, .0028, .1607, 
00176         .0030, .1565, .0040, .1429, .0050, .1307, .0060, .1214,
00177         .0070, .1130, .0080, .1058, .0090, .0993, .0100, .0936, 
00178         .0120, .0824, .0150, .0710, .0200, .0576
00179         };
00180 
00181    float        r_cutgam,r_sampfrac;
00182    int  l_automatic_threshold   =       TRUE;   
00183    int  ind1,ind2;
00184 
00185 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00186      New calibration: three cvolu_opt(5,8)  --  AUAU, PPLO, PPHI
00187      currently four GCUTS thresholds 0.001, 0.005, 0.02, 0.1    
00188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00189 
00190    /* +++++++++++++++++++++++++++++++++++++++++++++++++++
00191 
00192       New threshold setting 'PPME' introduced to accomodate
00193       high pt photons in Pythia events - G. David, Feb. 11, 2000
00194 
00195     +++++++++++++++++++++++++++++++++++++++++++++++++++++  */
00196    float        ra_newcalib[4][4]       =
00197                         {
00198                                 0.2285, 0.1891, 0.1715, 0.1428,
00199                                 0.2285, 0.1891, 0.1715, 0.1428,
00200                                 0.1872, 0.1658, 0.1715, 0.1387,
00201                                 0.1382, 0.1593, 0.1715, 0.1295
00202                 };      
00203 
00204 
00205 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00206         c
00207         c
00208         c
00209         c
00210         c     End of Lead Scintillator (PbSc) geometry parameters
00211         c
00212         c
00213         c*******************************************************************
00214         c
00215         c     When calculating the impact position you have to add the
00216         c     depth if the insensitive material in front (but already
00217         c     inside the detector volume)
00218         c       
00219 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00220 
00221    float        rpos_plus_pbsc  =       0.0;
00222    float        rpos_plus_pbgl  =       0.0;
00223 
00224    int  istaf;
00225 
00226 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00227         c
00228         c
00229         cgd***  DATA emc_iwall_max/8/,emc_itype_max/3/,emc_i1_max/8/
00230         c
00231         c       Indices within supermodule
00232         c
00233         cgd***  DATA emc_ind1_max_sc/18/,emc_ind2_max_sc/144/
00234         cgd***  DATA emc_ind1_max_gl/192/,emc_ind2_max_gl/24/
00235         c
00236         c       Misc
00237         c
00238         cgd***  DATA emc_itrack_max/32767/,emc_spart_max/62/,
00239         cgd***     1       emc_ncycle_max/31/
00240         c
00241         c
00242         c     THIS IS HOW PARAMETERS WERE WRITTEN OUT IN emc.f
00243         c
00244         c     Defining parameters for cells and supercells for each sector
00245         c     and calorimeter type (max 8 sectors, types: Shish-Kebab, PbGlass)
00246         c
00247         c
00248         c          udetpar(1) = float(emc_walls)     ! number of walls from PHNX.PAR
00249         c          udetpar(2) = float(emc_opt)       ! EMCal option from PHNX.PAR
00250         c          udetpar(3) = float(iwall)        ! wall number (1-4)
00251         c          udetpar(4) = float(itype)        ! detector type (Sh-K,PbGl)
00252         c          udetpar(5) = angle               ! phi angle of wall center
00253         c          udetpar(6) = rpos                ! radial position of wall center
00254         c          udetpar(7) = zc_start             ! center of first cell, z coor.
00255         c          udetpar(8) = yc_start             ! center of first cell, y coor.
00256         c          udetpar(9) = lsiz                ! long. size of a cell
00257         c          udetpar(10) = tsiz               ! transverse size of a cell
00258         c          udetpar(11) = FLOAT(no_modz)     ! No. of cells in z in a supermod.
00259         c          udetpar(12) = FLOAT(no_mody)     ! No. of cells in y in a supermod.
00260         c          udetpar(13) = FLOAT(no_smodz)    ! No. of supermods. in z / wall
00261         c          udetpar(14) = FLOAT(no_smody)    ! No. of supermods. in y / wall
00262         c          udetpar(15) = 0.0                ! 
00263         c          udetpar(16) = 0.0                !
00264         c          udetpar(17) = 0.0                !
00265         c          udetpar(18) = FLOAT(scint_emc_med)  ! Shish-Kebab scint. medium
00266         c          udetpar(19) = 0.0                !
00267         c          udetpar(20) = 0.0                !
00268         c          udetpar(21) = 0.0
00269         c          udetpar(22) = FLOAT(emc_debug)
00270         c          udetpar(23) = gcuts(1)
00271         c          udetpar(24) = gcuts(2)
00272         c          udetpar(25) = gcuts(3)
00273         c          udetpar(26) = gcuts(4)
00274         c          udetpar(27) = gcuts(5)
00275         c          udetpar(28) = 0.0     !
00276         c          udetpar(29) = 0.0     !
00277         c          udetpar(30) = emc_r_min_sc ! bitp lower limit, PbSc
00278         c          udetpar(31) = emc_r_max_sc ! bitp upper limit, PbSc
00279         c          udetpar(32) = emc_r_step ! bitp stepsize, PbSc
00280         c          udetpar(33) = emc_z_min ! bitp lower limit
00281         c          udetpar(34) = emc_z_max ! bitp upper limit
00282         c          udetpar(35) = emc_z_step ! bitp stepsize
00283         c          udetpar(36) = emc_x_min_sc ! bitp lower limit, PbSc
00284         c          udetpar(37) = emc_x_max_sc ! bitp upper limit, PbSc
00285         c          udetpar(38) = emc_x_step ! bitp stepsize, PbSc
00286         c          udetpar(39) = 0.0     !
00287         c          udetpar(40) = emc_dele_max_sc ! bitp dE upper limit, PbSc
00288         c          udetpar(41) = emc_dele_step_sc ! bitp dE upper limit, PbSc
00289         c          udetpar(42) = emc_tof_min ! bitp lower limit
00290         c          udetpar(43) = emc_tof_max ! bitp upper limit
00291         c          udetpar(44) = emc_tof_step ! bitp stepsize
00292         c          udetpar(45) = 0.0     !
00293         c          udetpar(46) = 0.0     !
00294         c          udetpar(47) = 0.0     !
00295         c          udetpar(48) = 0.0     !
00296         c          udetpar(49) = 0.0     !
00297         c          udetpar(50) = FLOAT(emc_ind1_max_sc) ! bitp tower ind. 
00298         c          udetpar(51) = FLOAT(emc_ind2_max_sc) ! bitp tower ind. 
00299         c          udetpar(52) = FLOAT(emc_iwall_max) ! 
00300         c          udetpar(53) = FLOAT(emc_itype_max) ! 
00301         c          udetpar(54) = FLOAT(emc_i1_max) ! 
00302         c          udetpar(55) = 0.0     !
00303         c          udetpar(56) = 0.0     !
00304         c          udetpar(57) = 0.0     !
00305         c          udetpar(58) = 0.0     !
00306         c          udetpar(59) = 0.0     !
00307         c          udetpar(60) = FLOAT(emc_itrack_max) ! 
00308         c          udetpar(61) = FLOAT(emc_spart_max) ! 
00309         c          udetpar(62) = FLOAT(emc_ncycle_max) ! 
00310         c          udetpar(63) = 0.0     !
00311         c          udetpar(64) = 0.0     !
00312         c          udetpar(65) = emc_cutgam ! 
00313         c          udetpar(66) = emc_cutele ! 
00314         c          udetpar(67) = emc_cutneu ! 
00315         c          udetpar(68) = emc_cuthad ! 
00316         c          udetpar(69) = emc_cutmuo ! 
00317         c          udetpar(70) = 0.0     !
00318         c          udetpar(71) = 0.0     !
00319         c          udetpar(72) = 0.0     !
00320         c          udetpar(73) = 0.0     !
00321         c          udetpar(74) = 0.0     !
00322         c          udetpar(75) = 0.0     !
00323         c          udetpar(76) = 0.0     !
00324         c          udetpar(77) = 0.0     !
00325         c          udetpar(78) = 0.0     !
00326         c          udetpar(79) = 0.0     !
00327         c          udetpar(80) = 0.0     !
00328         c
00329         c     Field added to ra_det
00330         c     (eventually to be overwritten by user parameters
00331         c
00332         c          ra_det(81,j) = COSD(phi angle)
00333         c          ra_det(82,j) = SIND(phi angle)
00334         c          ra_det(83,j) = Attenuation length
00335         c          ra_det(84,j) = Speed of light (cm/ns)
00336         c
00337         c     Get the very first detector parameter set
00338         c
00339         cgd***          CALL GFDETU('EMC ','EC11',nudetpar,nw,udetpar(1))
00340         cgd***          IF(nw <= 0) THEN
00341         cgd***           CALL EMC_GINI_FILL()
00342         cgd***           GOTO 1117
00343         cgd***          ENDIF
00344         c       
00345 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00346 
00347 /*     Executable */
00348 
00349 
00350    double d_theta,d_phi,d_work,d_work0,d_work1,d_work2;
00351    double todeg,torad;
00352 
00353 
00354 
00355    torad = M_PI / 180.0;
00356    todeg = 180.0 / M_PI;
00357 
00358    /* This routine produces the default dEmcGeometry and dEmcGeaParams
00359       tables if no PISA input is present - at the request of Jeff 
00360       Mitchell, Jule 16-18 1999, G. David
00361       Eventually it should become obsolete when the same data will
00362       be fetched from the database
00363    */
00364 
00365 
00366    if(dEmcGeaParams_h->nok > 0)
00367    {
00368       return(STAFCV_OK);
00369    }
00370 
00371    /* This has been put in because of initialization problem */
00372    for (ll = 0; ll < sizeof(ra_det)/sizeof(ra_det[0][0]); ll++)
00373      {
00374        *((float *)ra_det + ll) = 0.0;
00375      }
00376    
00377    /* --------------------------------------------- */
00378    
00379    /* Put in values by hand */
00380 
00381    /* First wall */
00382 
00383    for(j=0;j<8;j++)
00384      {
00385        /* Number of sectors */
00386        ra_det[0][j] = 8.0;
00387        /* emc-opt */
00388        ra_det[1][j] = 3.0;
00389        /* Sector number */
00390        ra_det[2][j] = (float) j+1;
00391      }
00392    /* Sector type */
00393 
00394 
00395    for(j=0;j<6;j++){ ra_det[3][j]=1.0;}
00396    for(j=6;j<8;j++){ ra_det[3][j]=2.0;}
00397    /* Sector phi angle - 180 degrees!!! */
00398    ra_det[4][0] = 202.632;
00399    ra_det[4][1] = 180.000;
00400    ra_det[4][2] = 157.368;
00401    ra_det[4][3] = 134.738;
00402    ra_det[4][4] =  45.264;
00403    ra_det[4][5] =  22.632;
00404    ra_det[4][6] =   0.000;
00405    ra_det[4][7] = -22.000;
00406    /* Sector rpos */
00407    for(j=0;j<6;j++){ ra_det[5][j]= 510.0;}
00408    for(j=6;j<8;j++){ ra_det[5][j]= 552.64;}
00409    /* Sector zc_start */
00410    for(j=0;j<6;j++){ ra_det[6][j]= -196.74;}
00411    for(j=6;j<8;j++){ ra_det[6][j]= -193.23;}
00412       /* Correction following Maxim Volkov's suggestion
00413          G. David, Nov. 21, 2000 */
00414       if(j>5) {ra_det[5][j] = 543.2;}
00415 
00416    /* Sector yc_start */
00417    ra_det[7][0] = -285.771;
00418    ra_det[7][1] =  -96.985;
00419    ra_det[7][2] =  106.738;
00420    ra_det[7][3] =  294.022;
00421    ra_det[7][4] =  294.022;
00422    ra_det[7][5] =  106.738;
00423    ra_det[7][6] =  -95.598;
00424    ra_det[7][7] =  -291.674;
00425 
00426    /* Longitudinal size */
00427    for(j=0;j<6;j++){ ra_det[8][j]= 38.934;}
00428    for(j=6;j<8;j++){ ra_det[8][j]= 51.200;}
00429    /* Transverse size */
00430    for(j=0;j<6;j++){ ra_det[9][j]=  5.542;}
00431    /* Maxim Volkov discovered a discrepancy between actual size in
00432       PbGl tower size in PISA and the size passed in GeaParams.  
00433       True sizes are in z direction 4.104 cm and in y direction 4.1105 cm.
00434       Since the towers are everywhere assumed to be a square and
00435       using the z dimension in y only leaves max. 3 mm discrepancy,
00436       we use the z true z dimension for both z and y now.
00437       This has to disappear anyway a.s.a.p. when we introduce the
00438       true (survey) geometry and propagate it back to PISA.
00439       G. David, Nov. 21, 2000
00440    for(j=6;j<8;j++){ ra_det[9][j]=  4.068;}
00441    */
00442    for(j=6;j<8;j++){ ra_det[9][j]=  4.104;}
00443 
00444 
00445    /* Modules in z in supermodule */
00446    for(j=0;j<6;j++){ ra_det[10][j]=  12.0;}
00447    for(j=6;j<8;j++){ ra_det[10][j]=   6.0;}
00448    /* Modules in y in supermodule */
00449    for(j=0;j<6;j++){ ra_det[11][j]=  12.0;}
00450    for(j=6;j<8;j++){ ra_det[11][j]=   4.0;}
00451    /* Supermodules in z */
00452    for(j=0;j<6;j++){ ra_det[12][j]=   6.0;}
00453    for(j=6;j<8;j++){ ra_det[12][j]=  16.0;}
00454    /* Supermodules in y */
00455    for(j=0;j<6;j++){ ra_det[13][j]=   3.0;}
00456    for(j=6;j<8;j++){ ra_det[13][j]=  12.0;}
00457    /* Reserved fields , zero now */
00458    for(j=0;j<8;j++){ ra_det[14][j]=   0.0;}
00459    for(j=0;j<8;j++){ ra_det[15][j]=   0.0;}
00460    for(j=0;j<8;j++){ ra_det[16][j]=   0.0;}
00461    /* Scint active medium */
00462    for(j=0;j<6;j++){ ra_det[17][j]= 881.0;}
00463    for(j=6;j<8;j++){ ra_det[17][j]= 810.0;}
00464    /* Reserved fields , zero now */
00465    for(j=0;j<8;j++){ ra_det[18][j]=   0.0;}
00466    for(j=0;j<8;j++){ ra_det[19][j]=   0.0;}
00467    for(j=0;j<8;j++){ ra_det[20][j]=   0.0;}
00468    /* Emc debug option */
00469    for(j=0;j<8;j++){ ra_det[21][j]=   1.0;}
00470    /* GCUTS default values */
00471    for ( i = 0; i < 5; i++ )
00472      {
00473        ra_det[22+i][j] = 0.001;
00474      }
00475    /* Reserved fields , zero now */
00476    for(j=0;j<8;j++){ ra_det[27][j]=   0.0;}
00477    for(j=0;j<8;j++){ ra_det[28][j]=   0.0;}
00478    /* Min. radius for bitpacking */
00479    for(j=0;j<6;j++){ ra_det[29][j]= 510.0;}
00480    for(j=6;j<8;j++){ ra_det[29][j]= 535.0;}
00481    /* Max. radius for bitpacking */
00482    for(j=0;j<6;j++){ ra_det[30][j]= 580.0;}
00483    for(j=6;j<8;j++){ ra_det[30][j]= 605.0;}
00484    /* r stepsize for bitpacking */
00485    for(j=0;j<8;j++){ ra_det[31][j]=   0.07;}
00486    /* Min. z for bitpacking */
00487    for(j=0;j<8;j++){ ra_det[32][j]= -200.0;}
00488    /* Max. z for bitpacking */
00489    for(j=0;j<8;j++){ ra_det[33][j]=  200.0;}
00490    /* z stepsize for bitpacking */
00491    for(j=0;j<8;j++){ ra_det[34][j]=   0.1;}
00492    /* Min. x for bitpacking */
00493    for(j=0;j<6;j++){ ra_det[35][j]=  280.0;}
00494    for(j=6;j<8;j++){ ra_det[35][j]=  460.0;}
00495    /* Max. x for bitpacking */
00496    for(j=0;j<6;j++){ ra_det[36][j]=  560.0;}
00497    for(j=6;j<8;j++){ ra_det[36][j]=  740.0;}
00498    /* x stepsize for bitpacking */
00499    for(j=0;j<6;j++){ ra_det[37][j]=    0.07;}
00500    for(j=6;j<8;j++){ ra_det[37][j]=    0.07;}
00501    /* Reserved field , zero now */
00502    for(j=0;j<8;j++){ ra_det[38][j]=   0.0;}
00503    /* Max. E loss for bitpacking */
00504    for(j=0;j<6;j++){ ra_det[39][j]=    0.0327;}
00505    for(j=6;j<8;j++){ ra_det[39][j]=    0.256;}
00506    /* E loss stepsize for bitpacking */
00507    for(j=0;j<6;j++){ ra_det[40][j]=    1.0e-6;}
00508    for(j=6;j<8;j++){ ra_det[40][j]=    8.0e-6;}
00509    /* Tofmin for bitpacking */
00510    for(j=0;j<8;j++){ ra_det[41][j]=   17.0;}
00511    /* Tofmax for bitpacking */
00512    for(j=0;j<8;j++){ ra_det[42][j]=  345.0;}
00513    /* Tofstep for bitpacking */
00514    for(j=0;j<8;j++){ ra_det[43][j]=    0.01;}
00515    /* Reserved fields , zero now */
00516    for(j=0;j<8;j++){ ra_det[44][j]=   0.0;}
00517    for(j=0;j<8;j++){ ra_det[45][j]=   0.0;}
00518    for(j=0;j<8;j++){ ra_det[46][j]=   0.0;}
00519    for(j=0;j<8;j++){ ra_det[47][j]=   0.0;}
00520    for(j=0;j<8;j++){ ra_det[48][j]=   0.0;}
00521    /* Max. number of supermodules in sector */
00522    for(j=0;j<6;j++){ ra_det[49][j]=  18.0;}
00523    for(j=6;j<8;j++){ ra_det[49][j]= 192.0;}
00524    /* Max. number of towers in supermodule */
00525    for(j=0;j<6;j++){ ra_det[50][j]= 144.0;}
00526    for(j=6;j<8;j++){ ra_det[50][j]=  24.0;}
00527    /* Max. number of sectors for bitpacking */
00528    for(j=0;j<8;j++){ ra_det[51][j]=   8.0;}
00529    /* Max. number of sector types for bitpacking */
00530    for(j=0;j<8;j++){ ra_det[52][j]=   3.0;}
00531    /* Max. number ... for bitpacking */
00532    for(j=0;j<8;j++){ ra_det[53][j]=   8.0;}
00533    /* Reserved fields , zero now */
00534    for(j=0;j<8;j++){ ra_det[54][j]=   0.0;}
00535    for(j=0;j<8;j++){ ra_det[55][j]=   0.0;}
00536    for(j=0;j<8;j++){ ra_det[56][j]=   0.0;}
00537    for(j=0;j<8;j++){ ra_det[57][j]=   0.0;}
00538    for(j=0;j<8;j++){ ra_det[58][j]=   0.0;}
00539    /* Max. number of tracks for bitpacking */
00540    for(j=0;j<8;j++){ ra_det[59][j]= 32767.0;}
00541    /* Max. number of spart for bitpacking */
00542    for(j=0;j<8;j++){ ra_det[60][j]=    62.0;}
00543    /* Max. number of ncycle for bitpacking */
00544    for(j=0;j<8;j++){ ra_det[61][j]=    31.0;}
00545    /* Reserved fields , zero now */
00546    for(j=0;j<8;j++){ ra_det[62][j]=   0.0;}
00547    for(j=0;j<8;j++){ ra_det[63][j]=   0.0;}
00548    /* AuAu special cuts */
00549    for(j=0;j<8;j++){ ra_det[64][j]=   0.001;}
00550    for(j=0;j<8;j++){ ra_det[65][j]=   0.001;}
00551    for(j=0;j<8;j++){ ra_det[66][j]=   0.001;}
00552    for(j=0;j<8;j++){ ra_det[67][j]=   0.001;}
00553    for(j=0;j<8;j++){ ra_det[68][j]=   0.001;}
00554    for ( i = 0; i < 11; i++ )    /*      Last elements of array */
00555      {
00556        for(j=0;j<6;j++) 
00557          if(i<8)
00558            {
00559              ra_det[69+i][j] = 1.0e-4;
00560            }
00561        else
00562          {
00563          ra_det[69+i][j] = 0.0;
00564          }
00565        for(j=6;j<8;j++) ra_det[69+i][j] = 0.0;
00566 
00567      }  
00568 
00569    /* End putting in values by hand.  Now calculate derived quantities */
00570 
00571    for ( j = 0; j < emc_walls; j++ )
00572    {
00573 
00574 
00575      if( ra_det[70][0] == 0.0)
00576        {
00577          l_automatic_threshold =  FALSE;
00578        }
00579      if(l_automatic_threshold)
00580        {
00581          r_sampfrac = 0.2285;        /*  To make sure you always get something  */
00582          ind1 = 0;
00583          ind2 = 0 ;
00584          if(j < 6)
00585            {
00586              if(ra_det[70][j] >= 0.0029) ind2 = 1;
00587              if(ra_det[70][j] >= 0.0049) ind2 = 2;
00588              if(ra_det[70][j] >= 0.0099) ind2 = 3;
00589 
00590              if(ra_det[22][j] <= 0.0001) ind1 = 0;
00591              if(ra_det[22][j] > 0.0001 && ra_det[22][j] <= 0.005) ind1 = 1;
00592              if(ra_det[22][j] > 0.005 && ra_det[22][j] <= 0.02) ind1 = 2;
00593              if(ra_det[22][j] > 0.02 && ra_det[22][j] <= 0.1) ind1 = 3;
00594 
00595              r_sampfrac = ra_newcalib[ind1][ind2];
00596            }
00597        }
00598      else
00599        {
00600          r_sampfrac = .2443;
00601          r_cutgam = ra_det[22][j];
00602          if(r_cutgam <= ra_sampfrac[0][0] )
00603            {
00604              r_sampfrac = ra_sampfrac[0][1];
00605            }
00606          else
00607            {
00608              if(r_cutgam >= ra_sampfrac[22][0] )
00609                {
00610                  r_sampfrac = ra_sampfrac[22][1];
00611                }
00612              else
00613                {
00614                  
00615                  for ( i = 1; i < 22; i++)
00616                  {
00617                    if(r_cutgam == ra_sampfrac[i][0] )
00618                      {
00619                        r_sampfrac = ra_sampfrac[i][1];
00620                      }
00621                    else
00622                      {
00623                        if ( r_cutgam > ra_sampfrac[i][0] && r_cutgam < ra_sampfrac[i+1][0] )
00624                          {
00625                            r_sampfrac = ra_sampfrac[i+1][1] + 
00626                              ( ra_sampfrac[i][1] - ra_sampfrac[i+1][1] ) *
00627                              ( ra_sampfrac[i+1][0]-r_cutgam ) /
00628                              ( ra_sampfrac[i+1][0] - ra_sampfrac[i][0] );
00629                          }
00630                      }
00631                  }
00632                }
00633            }
00634        }
00635      if(r_sampfrac == 0.0) r_sampfrac = 0.2054;
00636      
00637      d_work = ra_det[4][j];
00638      d_work = torad * d_work;
00639      d_work1 = cos(d_work);
00640      d_work2 = sin(d_work);
00641      ra_det[80][j] = d_work1;
00642      ra_det[81][j] = d_work2;
00643      
00644      ra_det[82][j] = 200.0;                /*    Attenuation length     */
00645      ra_det[83][j] = 17.0;                 /*    Speed of light in medium       */
00646      ra_det[86][j] = 0.0;                  /*    Noise  */
00647      ra_det[87][j] = 1.0;                  /*    MeV/ADC (FAKE VALUE!   !       !       )       */
00648      ra_det[89][j] = 10.0;                /*     Pulse decay time (ns)  */
00649      ra_det[90][j] = 10.0;                /*     Tune for energy dependence     */
00650      ra_det[91][j] = 3.0;                 /*     Delay (?)      */
00651      ra_det[92][j] = 3.0;                 /*     tfac (?)       */
00652      
00653      ra_det[93][j] = 0.04;                 /*    TOF thresh     */
00654      
00655      ra_det[94][j] = 3.0;                 /*     Time to reach max at 1 GeV     */
00656      if(j < 6)
00657        {
00658          ra_det[84][j] = r_sampfrac;                /*   Sampling fraction      */
00659          
00660          /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00661             c ! This is for 1 MeV tracking
00662             c ! threshold
00663             c ! Correct it later with
00664             c ! proper functional form
00665             c
00666             ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00667          
00668          ra_det[84][j] = ra_det[84][j] * 0.87; /*        To correct for other losses    */
00669          ra_det[85][j] = 1500.0;              /*         Photoelectrons er GeV  */
00670        }
00671      else
00672        {
00673          ra_det[84][j] = 1.0;
00674          ra_det[85][j] = 600.0;              /*  Photoelectrons er GeV  */
00675        }
00676      if( ra_det[90][j] > 0.0)
00677        {
00678          r_work1 = ra_det[90][j] * log(2.0);
00679          ra_det[92][j] = ra_det[94][j] * r_work1 / (1.0 + r_work1);
00680        }
00681      
00682      /* Put this is STAF table  */
00683      
00684      for ( i = 0; i < 120; i++ )
00685        {
00686          dEmcGeaParams[j].detarray[i] = ra_det[i][j];
00687        }
00688    }        /*   End of loop over j = 1, emc_walls, filling ra_det      */
00689    
00690    dEmcGeaParams_h->nok = emc_walls;
00691    
00692    /*   Now fill emc_geom       */
00693    
00694    for (ll = 0; ll < sizeof(emc_geom)/sizeof(emc_geom[0][0][0][0]); ll++)
00695      {
00696        *((float *)emc_geom + ll) = 0.0;
00697      }
00698 
00699    
00700    
00701    for ( i1 = 0; i1 < emc_walls; i1++ )
00702    {
00703       for ( iz = 0; iz <  ra_det[10][i1]*ra_det[12][i1]; iz++ )  /*      Loop in z, all tow.    */
00704       {
00705          for ( iy = 0; iy <  ra_det[11][i1]*ra_det[13][i1]; iy++ ) /*    Loop in y, all tow.    */
00706          {
00707             
00708 /*      Apparent z position is the center of the first cell + ...       */
00709 
00710             r_appz = ra_det[6][i1] +   iz  * ra_det[9][i1];
00711             
00712 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00713    c Apparent y position is the center of the first cell + ...
00714    c times the COSine of the wall inclination
00715    c
00716 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00717 
00718             d_work1 = ra_det[80][i1];
00719             d_work = fabs(d_work1);
00720 
00721             r_appy = ra_det[7][i1] +   iy  * ra_det[9][i1] * d_work;
00722             
00723 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00724    c Apparent x position is
00725    c RPOS * COSine of wall inclination
00726    c - YPOSisiton in the coo.system of the wall * SINe of
00727    c wall inclination
00728 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
00729 
00730             r_appx = ra_det[5][i1] * d_work - 
00731                     (- (ra_det[11][i1]*ra_det[13][i1] - 1.0) 
00732                      * ra_det[9][i1] / 2.0
00733                      +   iy  * ra_det[9][i1]) * ra_det[81][i1];
00734 
00735             if(i1 > 3) r_appx = - r_appx;
00736             d_work1 = r_appx*r_appx + r_appy*r_appy;
00737             d_work1 = sqrt(d_work1);
00738             d_work2 = r_appz;
00739             d_work0 = r_appx;
00740             
00741             if(d_work1 > 0.0)
00742             {
00743 
00744                d_work = atan2(d_work1,d_work2);
00745                r_measthe = d_work;
00746                r_measthe = todeg * r_measthe;
00747                
00748                d_work = acos(d_work0/d_work1);
00749                r_measphi = d_work;
00750                r_measphi = todeg * r_measphi;
00751                
00752                if(r_appy < 0.0) r_measphi = 360.0 - r_measphi;
00753             }
00754 
00755 
00756             emc_geom[0][iz][iy][i1] = r_appx;
00757             emc_geom[1][iz][iy][i1] = r_appy;
00758             emc_geom[2][iz][iy][i1] = r_appz;
00759             emc_geom[3][iz][iy][i1] = r_measthe;
00760             emc_geom[4][iz][iy][i1] = r_measphi;
00761             d_work1 = r_appx*r_appx + r_appy*r_appy + r_appz*r_appz;
00762             d_work = sqrt(d_work1);
00763             r_work1 = d_work;
00764             
00765             emc_geom[5][iz][iy][i1] = r_work1;
00766             emc_geom[6][iz][iy][i1] = r_work1 / 30.0;    /*      Photon flash   */
00767 
00768             /* Write unit vector corresponding to the acis of the tower */
00769 
00770             emc_geom[7][iz][iy][i1] = ra_det[80][i1];
00771             emc_geom[8][iz][iy][i1] = ra_det[81][i1];
00772             emc_geom[9][iz][iy][i1] = 0.0;
00773             
00774             
00775                  
00776          }/*     Loop over iy   */
00777       }/*        Loop over iz   */
00778    }/*   Loop over i1   */
00779 
00780 /*      Write dEmcGeometry STAF table  
00781         the array emc_geom is indexed by sectors 1-8 at this point,
00782         but dEmcGeometry is written out according to a different
00783         numbering scheme
00784 */
00785 
00786    istaf = 0;
00787    for ( i1 = 0; i1 < emc_walls; i1++)
00788    {
00789       for ( iy = 0; iy < max_chany; iy++ )
00790       {
00791          for ( iz = 0; iz < max_chanz; iz++ )
00792          {
00793             if(emc_geom[5][iz][iy][i1] > 0.0)
00794             {
00795                dEmcGeometry[istaf].id = istaf + 1;
00796                dEmcGeometry[istaf].hwkey = 0;
00797                if(i1 < 4)
00798                {
00799                   dEmcGeometry[istaf].arm = 0;
00800                   dEmcGeometry[istaf].sector    = i1;
00801                }
00802                else
00803                {
00804                  /* Sector numbering from bottom up in East Arm */
00805                   dEmcGeometry[istaf].arm = 1;
00806                   dEmcGeometry[istaf].sector    = 7 - i1;
00807                }
00808 
00809                /*  Numbering reversed in West Arm */
00810                if(dEmcGeometry[istaf].arm == 0  && iz <= 71)
00811                  {
00812                    dEmcGeometry[istaf].ind[0]    = 71 - iz;
00813                  }
00814                else
00815                  {
00816                    dEmcGeometry[istaf].ind[0]    = iz;
00817                  }
00818 
00819                dEmcGeometry[istaf].ind[1]    = iy;
00820 
00821                dEmcGeometry[istaf].swkey = 
00822                  100000 * dEmcGeometry[istaf].arm +
00823                  10000 *  dEmcGeometry[istaf].sector +
00824                  100 *    iy+ 
00825                           iz;
00826 
00827 
00828                for (i = 0; i < 3; i++)
00829                  {
00830                    dEmcGeometry[istaf].nomxyz[i] = emc_geom[i][iz][iy][i1];
00831                    dEmcGeometry[istaf].actxyz[i] = emc_geom[i][iz][iy][i1];
00832                    dEmcGeometry[istaf].nomunitv[i] = emc_geom[7+i][iz][iy][i1];
00833                    dEmcGeometry[istaf].actunitv[i] = emc_geom[7+i][iz][iy][i1];
00834                  }
00835 
00836                dEmcGeometry[istaf].nomtheta  = emc_geom[3][iz][iy][i1];
00837                dEmcGeometry[istaf].nomphi    = emc_geom[4][iz][iy][i1];
00838                dEmcGeometry[istaf].acttheta  = emc_geom[3][iz][iy][i1];
00839                dEmcGeometry[istaf].actphi    = emc_geom[4][iz][iy][i1];
00840                dEmcGeometry[istaf].nomdist   = emc_geom[5][iz][iy][i1];
00841                dEmcGeometry[istaf].actdist   = emc_geom[5][iz][iy][i1];
00842                dEmcGeometry[istaf].nomflash  = emc_geom[6][iz][iy][i1];
00843                dEmcGeometry[istaf].actflash  = emc_geom[6][iz][iy][i1];
00844 
00845 /*      Get theta, phi within the sector (local) coordinate system) */
00846 /*      But buddy, this is c, indices are shifted by one */
00847 
00848 /*      Yes, and at some point one should check if iz,iy,i1 is correct... */
00849 /*      or it should be iz+1, etc. */
00850 
00851                r_dist = ra_det[5][i1];
00852                r_distz = (  iz
00853                           - ra_det[10][i1] * ra_det[12][i1] / 2.0)
00854                   * ra_det[9][i1];
00855                r_disty = (  iy - ra_det[11][i1] * ra_det[15][i1]
00856                           - ra_det[11][i1] * ra_det[13][i1] / 2.0)
00857                   * ra_det[9][i1];
00858 
00859                d_work1 = r_distz;
00860                d_work2 = r_disty;
00861                d_work = r_dist;
00862                d_theta = atan2(d_work1,d_work);
00863                d_phi = atan2(d_work2,d_work);
00864                d_theta = todeg * d_theta;
00865                d_phi = todeg * d_phi;
00866                r_sectheta = d_theta;
00867                r_secphi = d_phi;
00868                dEmcGeometry[istaf].sectheta = r_sectheta;
00869                dEmcGeometry[istaf].secphi = r_secphi;
00870                
00871             
00872                
00873                istaf = istaf + 1;
00874                
00875             }/*  Photon flash > 0.0, tower defined      */
00876          }/*     Loop over iz   */
00877       }/*        Loop over iy   */
00878    }/*   Loop over iz   */
00879    
00880 
00881    dEmcGeometry_h->nok = istaf;
00882    
00883    return (STAFCV_OK);
00884 }
00885 
00886