CommitLineData
39eefe19 1// -*- mode: C++ -*-
2#ifndef FLOW_STAT_H
3#define FLOW_STAT_H
4995b978 4// #include <cmath>
5#include <TMath.h>
39eefe19 6#include <TObject.h>
7
8//______________________________________________________
9/** @class AliFMDFlowStat flow/AliFMDFlowStat.h <flow/AliFMDFlowStat.h>
10 @brief Single variable statistics.
11 @ingroup u_utils
12
13 This class calculates the single variable statistics of a random
14 variable @f$x@f$.
15
16 The average @f$\bar{x}@f$ after @f$n@f$ observations is calculated as
17 @f[
18 \bar{x}^{(n)} = \left\{\begin{array}{rl}
19 x^{(n)} & n = 1\\
20 \left(1-\frac1n\right)\bar{x}^{(n-1)} + \frac{x^{(n)}}{n} & n > 1
21 \end{array}\right.
22 @f]
23 and the square variance @f$s^2@f$ after @f$n@f$ observations is
24 given by
25 @f[
26 {s^{2}}^{(n)} = \left\{\begin{array}{rl}
27 0 & n = 1\\
28 \left(1-\frac1n\right){s^{2}}^{(n-1)} +
29 \frac{\left(x^{(n)}-\bar{x}^{(n)}\right)^2}{n-1} & n > 1
30 \end{array}\right.
31 @f]
32*/
824e71c1 33class AliFMDFlowStat : public TObject
39eefe19 34{
35public:
36 /** Constructor */
37 AliFMDFlowStat() : fAverage(0), fSqVar(0), fN(0) {}
38 /** Destructor */
39 virtual ~AliFMDFlowStat() {}
40 /** Reset */
824e71c1 41 void Clear(Option_t* option="");
39eefe19 42 /** Add another data point */
44 /** Get the average */
45 Double_t Average() const { return fAverage; }
46 /** Get the square variance */
47 Double_t SqVar() const { return fSqVar; }
48 /** Get the number of data points */
49 ULong_t N() const { return fN; }
50protected:
51 /** Average */
52 Double_t fAverage;
53 /** Square variance */
54 Double_t fSqVar;
55 /** Number of data points */
56 ULong_t fN;
57 /** Define for ROOT I/O */
58 ClassDef(AliFMDFlowStat,1);
59};
60
824e71c1 61//__________________________________________________________________
62inline void
63AliFMDFlowStat::Clear(Option_t*)
64{
65 fAverage = fSqVar = 0;
66 fN = 0;
67}
68
39eefe19 69//__________________________________________________________________
70inline void
72{
4995b978 73 if (TMath::IsNaN(x) || !TMath::Finite(x)) return;
39eefe19 74 fN++;
75 if (fN == 1) {
76 fAverage = x;
77 fSqVar = 0;
78 return;
79 }
80 Double_t c = (1. - 1. / fN);
81 fAverage *= c;
82 fAverage += x / fN;
83 fSqVar *= c;
4995b978 84 fSqVar += TMath::Power(x - fAverage, 2) / (fN - 1);
39eefe19 85}
86
87
88#endif
89//
90// EOF
91//