Logo ROOT  
Reference Guide
TStatistic.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: G. Ganis 2012
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TStatistic
13 #define ROOT_TStatistic
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TStatistic //
19 // //
20 // Statistical variable, defined by its mean, RMS and related errors. //
21 // Named, streamable, storable and mergeable. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #include "TObject.h"
26 
27 #include "TMath.h"
28 
29 #include "TString.h"
30 
31 class TCollection;
32 
33 class TStatistic : public TObject {
34 
35 private:
36  TString fName; ///< Name given to the TStatistic object
37  Long64_t fN; ///< Number of fills
38  Double_t fW; ///< Sum of weights
39  Double_t fW2; ///< Sum of squared weights
40  Double_t fM; ///< Sum of elements (i.e. sum of (val * weight) pairs
41  Double_t fM2; ///< Second order momentum
42  Double_t fMin; ///< Minimum value in the TStatistic object
43  Double_t fMax; ///< Maximum value in the TStatistic object
44 
45 public:
46 
47  TStatistic(const char *name = "") : fName(name), fN(0), fW(0.), fW2(0.), fM(0.), fM2(0.), fMin(TMath::Limits<Double_t>::Max()), fMax(TMath::Limits<Double_t>::Min()) { }
48  TStatistic(const char *name, Int_t n, const Double_t *val, const Double_t *w = nullptr);
49  ~TStatistic();
50 
51  // Getters
52  const char *GetName() const { return fName; }
53  ULong_t Hash() const { return fName.Hash(); }
54 
55  inline Long64_t GetN() const { return fN; }
56  inline Long64_t GetNeff() const { return fW*fW/fW2; }
57  inline Double_t GetM2() const { return fM2; }
58  inline Double_t GetMean() const { return (fW > 0) ? fM/fW : 0; }
59  inline Double_t GetMeanErr() const { return (fW > 0.) ? TMath::Sqrt( GetVar()/ GetNeff() ) : 0; }
60  inline Double_t GetRMS() const { double var = GetVar(); return (var>0) ? TMath::Sqrt(var) : -1; }
61  inline Double_t GetVar() const { return (fW>0) ? ( (fN>1) ? (fM2 / fW)*(fN / (fN-1.)) : 0 ) : -1; }
62  inline Double_t GetW() const { return fW; }
63  inline Double_t GetW2() const { return fW2; }
64  inline Double_t GetMin() const { return fMin; }
65  inline Double_t GetMax() const { return fMax; }
66 
67  // Merging
68  Int_t Merge(TCollection *in);
69 
70  // Fill
71  void Fill(Double_t val, Double_t w = 1.);
72 
73  // Print
74  void Print(Option_t * = "") const;
75  void ls(Option_t *opt = "") const { Print(opt); }
76 
77  ClassDef(TStatistic,3) // Named statistical variable
78 };
79 
80 #endif
n
const Int_t n
Definition: legend1.C:16
TStatistic::GetN
Long64_t GetN() const
Definition: TStatistic.h:55
TStatistic::fMin
Double_t fMin
Minimum value in the TStatistic object.
Definition: TStatistic.h:42
Option_t
const char Option_t
Definition: RtypesCore.h:66
TMath::Max
Short_t Max(Short_t a, Short_t b)
Definition: TMathBase.h:212
TStatistic::fM
Double_t fM
Sum of elements (i.e. sum of (val * weight) pairs.
Definition: TStatistic.h:40
TStatistic::Print
void Print(Option_t *="") const
Print the content of the object.
Definition: TStatistic.cxx:114
TStatistic::GetNeff
Long64_t GetNeff() const
Definition: TStatistic.h:56
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TMath::Sqrt
Double_t Sqrt(Double_t x)
Definition: TMath.h:691
Int_t
int Int_t
Definition: RtypesCore.h:45
TStatistic::GetMax
Double_t GetMax() const
Definition: TStatistic.h:65
TString::Hash
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:638
TStatistic::GetM2
Double_t GetM2() const
Definition: TStatistic.h:57
TStatistic::Fill
void Fill(Double_t val, Double_t w=1.)
Increment the entries in the object by one value-weight pair.
Definition: TStatistic.cxx:77
TString
Basic string class.
Definition: TString.h:136
TStatistic::GetVar
Double_t GetVar() const
Definition: TStatistic.h:61
TString.h
TStatistic::fName
TString fName
Name given to the TStatistic object.
Definition: TStatistic.h:36
TStatistic::GetW2
Double_t GetW2() const
Definition: TStatistic.h:63
TStatistic::fW
Double_t fW
Sum of weights.
Definition: TStatistic.h:38
ULong_t
unsigned long ULong_t
Definition: RtypesCore.h:55
TMath::Min
Short_t Min(Short_t a, Short_t b)
Definition: TMathBase.h:180
TStatistic::GetRMS
Double_t GetRMS() const
Definition: TStatistic.h:60
TStatistic::~TStatistic
~TStatistic()
TStatistic destructor.
Definition: TStatistic.cxx:51
Double_t
double Double_t
Definition: RtypesCore.h:59
TObject.h
TStatistic::GetMin
Double_t GetMin() const
Definition: TStatistic.h:64
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TStatistic::GetName
const char * GetName() const
Returns name of object.
Definition: TStatistic.h:52
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
TStatistic::Hash
ULong_t Hash() const
Return hash value for this object.
Definition: TStatistic.h:53
TStatistic::fMax
Double_t fMax
Maximum value in the TStatistic object.
Definition: TStatistic.h:43
TStatistic::fM2
Double_t fM2
Second order momentum.
Definition: TStatistic.h:41
TStatistic::TStatistic
TStatistic(const char *name="")
Definition: TStatistic.h:47
TCollection
Collection abstract base class.
Definition: TCollection.h:63
TStatistic::Merge
Int_t Merge(TCollection *in)
Merge implementation of TStatistic.
Definition: TStatistic.cxx:136
TStatistic::fN
Long64_t fN
Number of fills.
Definition: TStatistic.h:37
TStatistic
Statistical variable, defined by its mean and variance (RMS).
Definition: TStatistic.h:33
TStatistic::fW2
Double_t fW2
Sum of squared weights.
Definition: TStatistic.h:39
TStatistic::GetMean
Double_t GetMean() const
Definition: TStatistic.h:58
TStatistic::GetMeanErr
Double_t GetMeanErr() const
Definition: TStatistic.h:59
TMath
TMath.
Definition: TMathBase.h:35
TMath.h
TStatistic::GetW
Double_t GetW() const
Definition: TStatistic.h:62
TStatistic::ls
void ls(Option_t *opt="") const
The ls function lists the contents of a class on stdout.
Definition: TStatistic.h:75