mEmcCalibTower.c

Go to the documentation of this file.
00001 /*:>--------------------------------------------------------------------
00002 **: FILE:       mEmcCalibTower.c.template
00003 **: HISTORY:
00004 **:             00jan93-v000a-hpl- Created by stic Version
00005 **:  Id: idl.y,v 1.5 1999/02/02 16:03:58 lajoie Exp  
00006 **:<------------------------------------------------------------------*/
00007 
00008 #include "mEmcCalibTower.h"
00009 #include "emlLib.h"
00010 #include <math.h>
00011 
00022 long type_of_call mEmcCalibTower_(
00023   TABLE_HEAD_ST    *dEmcRawData_h,    DEMCRAWDATA_ST      *dEmcRawData ,
00024   TABLE_HEAD_ST   *dEmcGeometry_h,   DEMCGEOMETRY_ST     *dEmcGeometry ,
00025   TABLE_HEAD_ST      *dEmcEvent_h,      DEMCEVENT_ST        *dEmcEvent ,
00026   TABLE_HEAD_ST *dEmcCalibTower_h, DEMCCALIBTOWER_ST   *dEmcCalibTower )
00027 {
00028 /*:>--------------------------------------------------------------------
00029 **: ROUTINE:    mEmcCalibTower_
00030 **: DESCRIPTION: Physics Analysis Module ANSI C template.
00031 **:             This is an ANSI C Physics Analysis Module template
00032 **:             automatically generated by stic from mEmcCalibTower.idl.
00033 **:             Please edit comments and code.
00034 **: AUTHOR:     hpl - H.P. Lovecraft, hplovecraft@cthulhu.void
00035 **: ARGUMENTS:
00036 **:       IN:
00037 **:        dEmcRawData    - PLEASE FILL IN DESCRIPTION HERE
00038 **:       dEmcRawData_h   - header Structure for dEmcRawData
00039 **:    INOUT:
00040 **:       dEmcGeometry    - PLEASE FILL IN DESCRIPTION HERE
00041 **:      dEmcGeometry_h   - header Structure for dEmcGeometry
00042 **:          dEmcEvent    - PLEASE FILL IN DESCRIPTION HERE
00043 **:         dEmcEvent_h   - header Structure for dEmcEvent
00044 **:      OUT:
00045 **:     dEmcCalibTower    - PLEASE FILL IN DESCRIPTION HERE
00046 **:    dEmcCalibTower_h   - header Structure for dEmcCalibTower
00047 **: RETURNS:    STAF Condition Value
00048 **:>------------------------------------------------------------------*/
00049 
00050 
00051 
00052     long i,j;
00053     float e_lo,e_hi,tof;        /* Energy, low and high gain; TOF */
00054     float e;
00055     
00056     const float mult_lothr = 0.005;
00057     const float mult_hithr = 0.020;
00058     float mult_lo,mult_hi;      /* Multiplicity with low and high threshold */
00059     
00060     short i1,iz,iy;
00061     float sectore[8];           /* Energy in each sector */
00062     float sectoret[8];          /* Energy in each sector */
00063     float tote,totet;
00064 
00065     static int l_first = 1;
00066     double d_work,d_work1;
00067     static float torad = M_PI/180.0;
00068     
00069 
00070     long i_twrkey,iarm,isec;
00071     
00072     const float r_tdc_convfac = 0.05;
00073 
00074 
00075     static float emc_geom[8][96][48][8];
00076     /*-------------------------------------------
00077 
00078       Executable
00079 
00080       -----------------------------------------*/
00081 
00082 
00083     if( l_first == 1 )
00084       {
00085         for (i = 0;  i < dEmcGeometry_h->nok; i++ )
00086           {
00087             /* Changed indexing in dEmcGeometry Nov 20, 1998 G. David
00088             i1 = dEmcGeometry[i].sector    -       1;
00089             iz = dEmcGeometry[i].ind[0]    -       1;
00090             iy = dEmcGeometry[i].ind[1]    -       1;
00091             */
00092 
00093             iz = dEmcGeometry[i].ind[0];
00094             iy = dEmcGeometry[i].ind[1];
00095             if(dEmcGeometry[i].arm == 0)
00096               {
00097                 i1 = dEmcGeometry[i].sector;
00098               }
00099             else
00100               {
00101                 i1 = 7 - dEmcGeometry[i].sector;
00102               }
00103 
00104 
00105             /* Fix the PISA bug for PbGl sector E0 here
00106                plus add a few small corrections */
00107             /*  This FIX is taken out, since now PISA seems to be OK
00108                 Aug. 30, 1999 G. David
00109             switch(i1)
00110               {
00111               case 0:               
00112                 dEmcGeometry[i].nomxyz[0] = dEmcGeometry[i].nomxyz[0] + 1.3;
00113                 dEmcGeometry[i].nomxyz[1] = dEmcGeometry[i].nomxyz[1] - 1.0;
00114                 break;
00115               case 1:               
00116                 dEmcGeometry[i].nomxyz[0] = dEmcGeometry[i].nomxyz[0] + 1.0;
00117                 dEmcGeometry[i].nomxyz[1] = dEmcGeometry[i].nomxyz[1] - 0.2;
00118                 break;
00119               case 2:               
00120                 dEmcGeometry[i].nomxyz[0] = dEmcGeometry[i].nomxyz[0] + 1.3;
00121                 dEmcGeometry[i].nomxyz[1] = dEmcGeometry[i].nomxyz[1] + 1.0;
00122                 break;
00123               case 3:               
00124                 dEmcGeometry[i].nomxyz[0] = dEmcGeometry[i].nomxyz[0] + 1.0;
00125                 dEmcGeometry[i].nomxyz[1] = dEmcGeometry[i].nomxyz[1] + 1.3;
00126                 break;
00127               case 4:               
00128                 dEmcGeometry[i].nomxyz[0] = dEmcGeometry[i].nomxyz[0] - 2.0;
00129                 dEmcGeometry[i].nomxyz[1] = dEmcGeometry[i].nomxyz[1] + 1.6;
00130                 break;
00131               case 5:               
00132                 dEmcGeometry[i].nomxyz[0] = dEmcGeometry[i].nomxyz[0] - 2.0;
00133                 dEmcGeometry[i].nomxyz[1] = dEmcGeometry[i].nomxyz[1] - 1.2;
00134                 break;
00135               case 6:               
00136                 dEmcGeometry[i].nomxyz[0] = dEmcGeometry[i].nomxyz[0] - 11.4;
00137                 dEmcGeometry[i].nomxyz[1] = dEmcGeometry[i].nomxyz[1] + 0.1;
00138                 break;
00139               case 7:               
00140                 dEmcGeometry[i].nomxyz[0] = dEmcGeometry[i].nomxyz[0] - 24.4;
00141                 dEmcGeometry[i].nomxyz[1] = dEmcGeometry[i].nomxyz[1] - 12.8;
00142                 break;
00143               }
00144             */
00145             /*  End of geometry fixes */
00146 
00147             emc_geom[0][iz][iy][i1] = dEmcGeometry[i].nomxyz[0];
00148             emc_geom[1][iz][iy][i1] = dEmcGeometry[i].nomxyz[1];
00149             emc_geom[2][iz][iy][i1] = dEmcGeometry[i].nomxyz[2];
00150             emc_geom[3][iz][iy][i1] = dEmcGeometry[i].nomtheta;
00151             emc_geom[4][iz][iy][i1] = dEmcGeometry[i].nomphi;
00152             emc_geom[5][iz][iy][i1] = dEmcGeometry[i].nomdist;
00153             emc_geom[6][iz][iy][i1] = dEmcGeometry[i].nomflash;
00154             d_work1 = dEmcGeometry[i].nomtheta;
00155             d_work1 = torad * d_work1;
00156             d_work = sin(d_work1);
00157             emc_geom[7][iz][iy][i1] = d_work;
00158             
00159           }
00160         l_first = 0;
00161         dEmcGeometry_h->nok = i;
00162       }
00163 
00164 
00165         
00166     
00167 
00168 /* Sanity check of header for table "dEmcRawData"... */
00169     if( ( dEmcRawData_h->maxlen <= 0 ))
00170        {
00171        return STAFCV_BAD;
00172     }
00173 
00174 /* Clear sector energy array */
00175 
00176     for( i=0; i<8 ; i++)
00177     {
00178             sectore[i] = 0.0;
00179             sectoret[i] = 0.0;
00180     }
00181     
00182 /* Process event */
00183     j = 0;
00184     mult_lo = 0. ;
00185     mult_hi = 0. ;
00186     tote = 0.0;
00187     totet = 0.0;
00188     
00189     for( i=0; i < dEmcRawData_h->nok; i++ ){
00190             j = j + 1 ; 
00191             e_lo =  dEmcRawData[i].adclopost - dEmcRawData[i].adclopre ;
00192             e_hi =  dEmcRawData[i].adchipost - dEmcRawData[i].adchipre ;
00193             e_lo = e_lo * 0.001 ;
00194             e_hi = e_hi * 0.008 ;
00195             /* Instead of hardwiring use conv. factor, to be retrieved from DB 
00196                tof  = dEmcRawData[i].tdc * 0.05 ;
00197             */
00198             tof  =  dEmcRawData[i].tdc * r_tdc_convfac;
00199             /* Changed to "count down from high pedestal
00200                Nov. 30, 1999 G.D. */
00201             if(e_lo < 0.0) e_lo = - e_lo;
00202             if(e_hi < 0.0) e_hi = - e_hi;
00203             
00204                    /* Max(e_lo,i_hi) is the energy */
00205             e = (e_lo > e_hi) ? e_lo : e_hi;    
00206 
00207                    /* Count hit multiplicity */
00208             if (e > mult_lothr) mult_lo = mult_lo + 1.0 ;
00209             if (e > mult_hithr) mult_hi = mult_hi + 1.0 ;
00210 
00211                    /* Fill calibrated tower structures */
00212             dEmcCalibTower[i].id = j ; 
00213             dEmcCalibTower[i].hwkey = dEmcRawData[i].hwkey ;
00214             dEmcCalibTower[i].swkey = dEmcRawData[i].swkey ;
00215             dEmcCalibTower[i].type = dEmcRawData[i].type ;
00216 
00217             i_twrkey = dEmcRawData[i].swkey;
00218             iarm = i_twrkey / 100000;
00219             i_twrkey = i_twrkey - 100000 * iarm;
00220             isec = i_twrkey / 10000;
00221             i_twrkey = i_twrkey - 10000 * isec;
00222             iy = i_twrkey / 100;
00223             iz = i_twrkey - 100 * iy;
00224 
00225             i1 = isec;
00226             if(iarm == 1) 
00227               {
00228                 i1 = 7 - i1;
00229               }
00230             
00231             dEmcCalibTower[i].arm = iarm ;
00232             dEmcCalibTower[i].sector = isec ;
00233             dEmcCalibTower[i].ind[0] = iz ;
00234             dEmcCalibTower[i].ind[1] = iy ;
00235             dEmcCalibTower[i].ecal = e ;
00236             /* Suppress non-physical tof */
00237             if(tof > 0.0 && tof < 16.0) tof = 0.0;
00238             
00239             dEmcCalibTower[i].tof = tof ;
00240 
00241             /*
00242             i1 = dEmcRawData[i].sector    -       1;
00243             iz = dEmcRawData[i].ind[0]    -       1;
00244             iy = dEmcRawData[i].ind[1]    -       1;
00245             */
00246 
00247             totet = totet + emc_geom[7][iz][iy][i1] * e;
00248             
00249 
00250 /* Increment sector energy array */         
00251 
00252             sectore[i1] = sectore[i1] + e ;
00253             sectoret[i1] = sectoret[i1] + emc_geom[7][iz][iy][i1] * e ;
00254             tote = tote + e;
00255 
00256     }
00257 
00258     dEmcCalibTower_h->nok = j ;
00259 
00260     for( i=0; i<8; i++)
00261     {
00262             dEmcEvent[0].sece[i] = sectore[i] ;
00263             dEmcEvent[0].secet[i] = sectoret[i] ;
00264     }
00265     dEmcEvent[0].twrmultlo = mult_lo;
00266     dEmcEvent[0].twrmulthi = mult_hi;
00267     dEmcEvent[0].tote = tote;
00268     dEmcEvent[0].totet = totet;
00269 
00270 
00271    return STAFCV_OK;
00272 }