/*:>-------------------------------------------------------------------- **: FILE: mMvdClmp.c **: HISTORY: **: 00jan93-v000a-hpl- Created by stic Version **: Id: idl.y,v 1.17 1997/03/25 19:22:52 ward Exp **:<------------------------------------------------------------------*/ #include "mMvdClmp.h" void getNclmp( TABLE_HEAD_ST *bRaw_h, DMVBRAW_ST *bRaw, DMVBPAR_ST *bPar, DMVDNCLMP_ST *Nclmp, short *total); void getClmp( DMVDGEO_ST *Geo, DMVBGEO_ST *bGeo, TABLE_HEAD_ST *bRaw_h, DMVBRAW_ST *bRaw, DMVDCLMP_ST *Clmp ); void MvdMess_(char *name_of_function, short ierror, short level, char *message, ...); #define NO_ERROR 0 /* used for message output with no error */ #define LOUD 2 /* messages which are usually output */ #define QUIET 1 /* used for messages which are output at default setting */ #define SILENT 0 /* for messages which are usually not output */ long mMvdClmp_( TABLE_HEAD_ST *Geo_h, DMVDGEO_ST *Geo , TABLE_HEAD_ST *bGeo_h, DMVBGEO_ST *bGeo , TABLE_HEAD_ST *bPar_h, DMVBPAR_ST *bPar , TABLE_HEAD_ST *bRaw_h, DMVBRAW_ST *bRaw , TABLE_HEAD_ST *Clmp_h, DMVDCLMP_ST *Clmp , TABLE_HEAD_ST *Nclmp_h, DMVDNCLMP_ST *Nclmp ){ /*:>-------------------------------------------------------------------- **: ROUTINE: mMvdClmp_ **: DESCRIPTION: Physics Analysis Module ANSI C template. **: This is an ANSI C Physics Analysis Module template **: automatically generated by stic from mMvdClmp.idl. **: Please edit comments and code. **: **: AUTHOR : J.H.Park, S.S.Ryu (YonSei Univ.) (Nov 10 97) **: Translated from the original Fortran version VER_CLMP.f **: written by J.P.Sullivan **: **: HISTORY : 25-Jan-98 S.S.Ryu rewrites the code using new algorithim **: which is compact and easy to understand, because there's **: some error in the previous version. **: **: 30-Jan-98 S.S.Ryu changes "exit" to "break" inside **: a do-while loop in getNclmp and getClmp, because "exit" **: makes error on HP machine. **: **: 14-Apr-98 J.P. Sullivan replaced printf statements with **: calsl to MvdMess_ **: **: ARGUMENTS: **: IN: **: Geo - mvd geometry parameters **: Geo_h - header Structure for Geo **: bGeo - z position of barrel cell and strip **: bGeo_h - header Structure for bGeo **: bPar - mvd barrel detector dimension parameters **: bPar_h - header Structure for bPar **: bRaw - mvd barrel detector raw data **: bRaw_h - header Structure for bRaw **: INOUT: **: OUT: **: Clmp - adress,size and z-position of each clump **: on barrel detector **: Clmp_h - header Structure for Clmp **: Nclmp - no of clumps on each row of barrel detector **: Nclmp_h - header Structure for Nclmp **: RETURNS: STAF Condition Value **:>------------------------------------------------------------------*/ short i,j; short total=0; MvdMess_("mMvdClmp",NO_ERROR,LOUD,"\nmMvdClmp {"); ds2ReallocTable(&Nclmp_h,&Nclmp,2*bPar->NPHUSE); /* initialize and evaluate Nclmp array */ /* which contains # of clumps on each row */ for (i=0;i< 2;i++) for (j=0;j< bPar->NPHUSE;j++) { Nclmp[i*bPar->NPHUSE+j].num=0; Nclmp[i*bPar->NPHUSE+j].row=j; Nclmp[i*bPar->NPHUSE+j].shell=i; } MvdMess_("mMvdClmp",NO_ERROR,LOUD, "\tbRaw_h->nok=%d",bRaw_h->nok ); getNclmp( bRaw_h, bRaw, bPar, Nclmp, &total ); Nclmp_h->nok=2*bPar->NPHUSE; ds2ReallocTable(&Clmp_h,&Clmp,total); for (i=0;inok=total; MvdMess_("mMvdClmp",NO_ERROR,QUIET, "\tClmp_h->nok=%d",Clmp_h->nok); MvdMess_("mMvdClmp",NO_ERROR,LOUD,"}"); return STAFCV_OK; } void getNclmp( TABLE_HEAD_ST *bRaw_h, DMVBRAW_ST *bRaw, DMVBPAR_ST *bPar, DMVDNCLMP_ST *Nclmp, short *total ){ /* arguments ; INs : bRaw,bPar */ /* OUTs: Nclmp,total */ int i,j; short clsize; for (i=0;inok;i+=clsize){ clsize=0; j=i-1; do{ clsize++; j++; /* special treatment for the last raw data element */ if (j==bRaw_h->nok-1){ break; } } while ((bRaw[j].shell == bRaw[j+1].shell) && (bRaw[j].row == bRaw[j+1].row ) && (bRaw[j].cell == bRaw[j+1].cell ) && (bRaw[j].strip+1== bRaw[j+1].strip) ); /* clump found and evaluate # of clmps on each row */ (*total)++; Nclmp[bRaw[j].shell*bPar->NPHUSE+bRaw[j].row].num++; } } void getClmp( DMVDGEO_ST *Geo, DMVBGEO_ST *bGeo, TABLE_HEAD_ST *bRaw_h, DMVBRAW_ST *bRaw, DMVDCLMP_ST *Clmp ){ /* arguments ; INs : Geo,bGeo,bRaw */ /* OUTs : Clmp */ short clsize; short cluster; int i,j; unsigned adcsum; short strip_no; cluster=0; for (i=0;inok;i+=clsize){ clsize=0; adcsum=0; Clmp[cluster].zavg=0.; j=i-1; do { clsize++; j++; adcsum+=bRaw[j].adc; strip_no = bRaw[j].cell * Geo->nstrip + bRaw[j].strip; Clmp[cluster].zavg+= bGeo->zstrip[strip_no]*bRaw[j].adc; /* special treatment for the last raw data element */ if (j==bRaw_h->nok-1){ break; } } while ((bRaw[j].shell == bRaw[j+1].shell) && (bRaw[j].row == bRaw[j+1].row ) && (bRaw[j].cell == bRaw[j+1].cell ) && (bRaw[j].strip+1== bRaw[j+1].strip) ); /* clump found and evaluate clmp position and size */ Clmp[cluster].row =bRaw[j].row ; Clmp[cluster].shell=bRaw[j].shell; Clmp[cluster].cell =bRaw[j].cell; Clmp[cluster].clsize=clsize; /* weighted average position of hit */ Clmp[cluster].zavg= Clmp[cluster].zavg/(float)adcsum; cluster++; } }