Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
runningMean.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file runningMean.cc
1 #include "runningMean.h"
2 
4 {
5  refArray = nullptr;
6 }
7 
9 {
10  if (refArray) delete [] refArray;
11 }
12 
13 int runningMean::setRefArray(const double darr[])
14 {
15  int i;
16  if (refArray ==nullptr)
17  {
18  refArray = new double[getNumberofChannels()];
19  }
20 
21  for (i=0; i< getNumberofChannels(); i++) refArray[i] = darr[i];
22 
23  return 0;
24 }
25 
26 int runningMean::setRefChannel(const int channel, const double refvalue)
27 {
28  int i;
29  if (refArray ==nullptr)
30  {
31  refArray = new double[getNumberofChannels()];
32  for (i=0; i< getNumberofChannels(); i++) refArray[i] = 0;
33  }
34 
35  if (channel < 0 || channel >= getNumberofChannels() ) return -1;
36  refArray[channel] = refvalue;
37 
38  return 0;
39 }
40 
42 {
43  int i;
44  if (refArray ==nullptr)
45  {
46  refArray = new double[getNumberofChannels()];
47  }
48  for (i=0; i< getNumberofChannels(); i++) refArray[i] = getMean(i);
49  return 0;
50 }
51 
52 double runningMean::getReference(const int channel) const
53 {
54  if (refArray ==nullptr) return 0;
55 
56  if (channel < 0 || channel >= getNumberofChannels() ) return 0;
57  return refArray[channel];
58 }
59 
61 {
62  if (refArray ==nullptr) return 0;
63 
64  if (channel < 0 || channel >= getNumberofChannels() ) return 0;
65 
66  if (getReference(channel) == 0.) return 0.;
67  return ( 100.* ( getMean(channel) - getReference(channel) ) / getReference(channel) );
68 }
69