bpmprocess/get_pedestal.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 
00022 int get_pedestal( int *wf, int ns, int range, double *offset, double *rms ) {
00023   
00024 
00025   double avg = 0., sqr_sum = 0.;
00026   int i;
00027 
00028   if ( ! wf || ! offset ) {
00029     bpm_error( "Invalid pointer argument in get_pedestal(...)",
00030                __FILE__, __LINE__ );
00031     return BPM_FAILURE;
00032   }
00033   
00034   if ( range == 0 || ns == 0 ) {
00035     bpm_error("Maximum range or number of samples equal zero in get_pedestal(...)",
00036               __FILE__, __LINE__ );
00037     return BPM_FAILURE;
00038   }
00039 
00040   if ( ns < range ) {
00041     bpm_warning("Number of samples < max range in get_pedestal(...)", 
00042                 __FILE__, __LINE__ );
00043     range = ns;
00044   }
00045   
00046   // find the mean and keep track of sum of squares
00047   for ( i = 0; i < range; i++) {
00048     avg     += (double) wf[i];
00049     sqr_sum += (double) wf[i]*wf[i];
00050   }
00051 
00052   *offset = avg / (double) range;
00053   if ( rms ) {
00054     *rms = sqrt( sqr_sum / (double) range - SQR( *offset ) );
00055   } else {
00056     bpm_warning( "NULL pointer given for rms in get_pedestal(...)",
00057                  __FILE__, __LINE__ );
00058   }
00059 
00060   return BPM_SUCCESS;
00061 }

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