mEmcGeaParams.c

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