bpmprocess/basic_stats.c

Go to the documentation of this file.
00001 
00005 #include <math.h>
00006 
00007 #include <bpm/bpm_messages.h>
00008 #include <bpm/bpm_process.h>
00009 
00026 int basic_stats( int *wf, int ns, int range, int nbits, double *offset, double *rms , 
00027                  int *max, int *min, int *unsat_sample) {
00028   
00029   double avg = 0., sqr_sum = 0.;
00030   int i;
00031 
00032   if ( ! wf || ! offset ) {
00033     bpm_error( "Invalid pointer argument in get_pedestal(...)",
00034                __FILE__, __LINE__ );
00035     return BPM_FAILURE;
00036   }
00037   
00038   if ( range == 0 || ns == 0 ) {
00039     bpm_error("Maximum range or number of samples equal zero in get_pedestal(...)",
00040               __FILE__, __LINE__ );
00041     return BPM_FAILURE;
00042   }
00043 
00044   if ( ns < range ) {
00045     bpm_warning("Number of samples < max range in get_pedestal(...)", 
00046                 __FILE__, __LINE__ );
00047     range = ns;
00048   }
00049   
00050   // find the mean and keep track of sum of squares
00051   *min = 1e6;
00052   *max = 0;
00053   for ( i = 0; i < range; i++) {
00054     avg     += (double) wf[i];
00055     sqr_sum += (double) wf[i]*wf[i];
00056     if( wf[i] > *max) *max = wf[i];
00057     if( wf[i] < *min) *min = wf[i];
00058   }
00059 
00060   *offset = avg / (double) range;
00061   if ( rms ) {
00062     *rms = sqrt( sqr_sum / (double) range - SQR( *offset ) );
00063   } else {
00064     bpm_warning( "NULL pointer given for rms in get_pedestal(...)",
00065                  __FILE__, __LINE__ );
00066   }
00067 
00068   handle_saturation( wf, ns, ns - 20, nbits, 64, unsat_sample );
00069 
00070   return BPM_SUCCESS;
00071 }

Generated on Thu Jan 10 10:18:04 2008 for libbpm by  doxygen 1.5.1