Back to home page

sPhenix code displayed by LXR

 
 

    


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

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