Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef __PSEUDORUNNINGMEAN_H__
0002 #define __PSEUDORUNNINGMEAN_H__
0003 
0004 /** 
0005 This is the pseudo running mean class. 
0006 
0007 In order to calculate the "real" (mathematically correct) running 
0008 mean value of a certain depth d, you will need to store the d most recent 
0009 entries to the running mean. For large values of d, this can lead to excessive
0010 amount of memory allocated.
0011 
0012 This pseudo running mean is an approximation of the running mean. It will
0013 work very well if you want to monitor values which don't vary too much, and 
0014 makes it very well-suited for gain monitoring and similar applications, where
0015 there are no dramatic changes in the values under normal conditions. It will
0016 calculate the new running mean value rn from the existing value ro as
0017 
0018 rn = ( ro * (d-1)/d + x ) /d
0019 
0020 where x is the new value in the running mean calculation. If there
0021 have been less than d readings so far, it will return the actual mean
0022 value.
0023 
0024 
0025 This class is mean to monitor lots of  values (such as all channels of a given
0026 detector) simultaneously; In the cnstructor you specify the "width" (how many channels) 
0027 and the depth of the running mean. 
0028 
0029 This class is meant to be lightweight, so there is not much in the way of bounds checking 
0030 of the input data going on. 
0031 
0032 As a simple example, let's assume that you pre-select "laser trigger" events for the EmCal, and you 
0033 want the running mean of the (144) channels calculated. You could construct a pseudoRunningMean object
0034 with 144 channels and depth 50:
0035 
0036 \begin{verbatim}
0037  pseudoRunningMean *pm = new pseudoRunningMean(144,50);
0038 \end{verbatim}
0039 
0040 and the pass your "laser" events and the pm object on to a routine that add the values:
0041 
0042 \begin{verbatim}
0043 int caculate_running_mean ( event * evt, RunningMean * rm)
0044 {
0045    int array[144];
0046    Packet *p = evt->getPacket(8002);
0047    if (p) 
0048       {
0049           // yes, we got the packet, and we ask it now to get channel 57 for us
0050       p->fillIntArray(array, 144, &nw);
0051           rm->Add(array);
0052       delete p;
0053           return 0;
0054       }
0055    return 1;
0056 }
0057 \end{verbatim}
0058 
0059 Then, outside of your routine, you could ask the pm object for the (pseudo-) running mean value 
0060 of channel i with
0061 
0062 \begin{verbatim}
0063 pm->getmean(i);
0064 \end{verbatim}
0065 
0066  
0067 
0068 */
0069 
0070 
0071 #include "runningMean.h"
0072 
0073 
0074 class pseudoRunningMean : public runningMean {
0075 
0076 public:
0077   pseudoRunningMean( const int /*NumberofChannels*/, const int /*depth*/);
0078   ~pseudoRunningMean() override;
0079 
0080  // delete copy ctor and assignment operator (cppcheck)
0081   explicit pseudoRunningMean(const pseudoRunningMean&) = delete;
0082   pseudoRunningMean& operator=(const pseudoRunningMean&) = delete;
0083 
0084   /// the getMean(i) funtion returns the current mean value of channel i 
0085   double getMean(const int /*ich*/) const override;
0086 
0087   /// Reset will reset th whole class
0088   int Reset() override;
0089 
0090   /**Add will add a new list of readings. It is your responsibility 
0091      to provide an approriate array of readings. (Typically you can get 
0092      the array of int's from the Packet object's fillIntArray function).
0093    */ 
0094   int Add (const int /*iarr*/[]) override;
0095   int Add (const float /*farr*/[]) override;
0096   int Add (const double /*darr*/[]) override;
0097 
0098 protected:
0099 
0100   int addChannel(const int /*channel*/, const double /*x*/);
0101   int depth;
0102   int current_depth;
0103   double * array;
0104 
0105 };
0106 #endif
0107 
0108