Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:57

0001 #include "fullRunningMean.h"
0002 
0003 fullRunningMean::fullRunningMean( const int n, const int d)
0004 {
0005   int i,j;
0006   depth = d;
0007   NumberofChannels  = n;
0008   current_depth =0;
0009   array = new double *[NumberofChannels];
0010   for (i=0; i< NumberofChannels; i++) 
0011     {
0012       array[i] = new double[depth];
0013       for (j=0; j< depth; j++) array[i][j] = 0.;
0014     }
0015 }
0016 
0017 fullRunningMean::~fullRunningMean()
0018 {
0019   int i;
0020   for (i=0; i< NumberofChannels; i++) 
0021     {
0022       delete [] array[i];
0023     }
0024   delete [] array;
0025 }
0026 
0027 int fullRunningMean::Add (const int iarr[])
0028 {
0029   int i;
0030 
0031   for (i = 0; i<NumberofChannels; i++) addChannel(i, double(iarr[i]) );
0032   if ( current_depth < depth) current_depth++;
0033   return 0;
0034                           
0035 }
0036 int fullRunningMean::Add (const float farr[])
0037 {
0038   int i;
0039 
0040   for (i = 0; i<NumberofChannels; i++) addChannel(i, farr[i]);
0041   if ( current_depth < depth) current_depth++;
0042   return 0;
0043                           
0044 }
0045 int fullRunningMean::Add (const double darr[])
0046 {
0047   int i;
0048 
0049   for (i = 0; i<NumberofChannels; i++) addChannel(i, darr[i]);
0050   if ( current_depth < depth) current_depth++;
0051   return 0;
0052 }
0053 
0054 
0055 int fullRunningMean::Reset()
0056 {
0057   int i,j;
0058   for (i=0; i< NumberofChannels; i++) 
0059     {
0060       for (j=0; j< depth; j++) array[i][j] = 0.;
0061     }
0062   return 0;
0063 }
0064 
0065 double fullRunningMean::getMean(const int ich) const
0066 {
0067   int j;
0068   double x = 0.;
0069 
0070   if (current_depth == 0) return 0.;
0071 
0072   for (j=0; j<current_depth; j++) x += array[ich][j];
0073   return  x / double(current_depth);
0074 }
0075 
0076 
0077 int fullRunningMean::addChannel(const int channel, const double k)
0078 {
0079   int j;
0080   if ( current_depth < depth)
0081     {
0082        array[channel][current_depth] = k;
0083     }
0084   else
0085     {
0086       for (j=1; j<depth; j++) array[channel][j-1] = array[channel][j];
0087       array[channel][depth-1] = k;
0088     }
0089   return 0;
0090 }
0091