Logo ROOT   6.08/07
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 #ifndef ROOT_TObject
26 #include "TObject.h"
27 #endif
28 
29 #ifndef ROOT_TCollection
30 #include "TCollection.h"
31 #endif
32 
33 #ifndef ROOT_TMath
34 #include "TMath.h"
35 #endif
36 
37 #ifndef ROOT_TString
38 #include "TString.h"
39 #endif
40 
41 #ifndef ROOT_TROOT
42 #include "TROOT.h"
43 #endif
44 
45 class TStatistic : public TObject {
46 
47 private:
49  Long64_t fN; // Number of fills
50  Double_t fW; // Sum of weights
51  Double_t fW2; // Sum of weights**2
52  Double_t fM; // Sum of elements ( i.e. mean * sum_of_weights)
53  Double_t fM2; // Second order momentum
54 
55 public:
56 
57  TStatistic(const char *name = "") : fName(name), fN(0), fW(0.), fW2(0.), fM(0.), fM2(0.) { }
58  TStatistic(const char *name, Int_t n, const Double_t *val, const Double_t *w = 0);
60 
61  // Getters
62  const char *GetName() const { return fName; }
63  ULong_t Hash() const { return fName.Hash(); }
64 
65  inline Long64_t GetN() const { return fN; }
66  inline Long64_t GetNeff() const { return fW*fW/fW2; }
67  inline Double_t GetM2() const { return fM2; }
68  inline Double_t GetMean() const { return (fW > 0) ? fM/fW : 0; }
69  inline Double_t GetMeanErr() const { return (fW > 0.) ? TMath::Sqrt( GetVar()/ GetNeff() ) : 0; }
70  inline Double_t GetRMS() const { double var = GetVar(); return (var>0) ? TMath::Sqrt(var) : -1; }
71  inline Double_t GetVar() const { return (fW>0) ? ( (fN>1) ? (fM2 / fW)*(fN / (fN-1.)) : 0 ) : -1; }
72  inline Double_t GetW() const { return fW; }
73  inline Double_t GetW2() const { return fW2; }
74 
75  // Merging
76  Int_t Merge(TCollection *in);
77 
78  // Fill
79  void Fill(Double_t val, Double_t w = 1.);
80 
81  // Print
82  void Print(Option_t * = "") const;
83  void ls(Option_t *opt = "") const { Print(opt); }
84 
85  ClassDef(TStatistic,2) //Named statistical variable
86 };
87 
88 #endif
const char * GetName() const
Returns name of object.
Definition: TStatistic.h:62
Double_t GetRMS() const
Definition: TStatistic.h:70
Double_t GetMean() const
Definition: TStatistic.h:68
Double_t GetMeanErr() const
Definition: TStatistic.h:69
long long Long64_t
Definition: RtypesCore.h:69
Double_t fM2
Definition: TStatistic.h:53
const char Option_t
Definition: RtypesCore.h:62
Double_t fM
Definition: TStatistic.h:52
ULong_t Hash() const
Return hash value for this object.
Definition: TStatistic.h:63
Double_t GetW() const
Definition: TStatistic.h:72
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
void Print(Option_t *="") const
This method must be overridden when a class wants to print itself.
Definition: TStatistic.cxx:76
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:606
Double_t fW
Definition: TStatistic.h:50
TStatistic(const char *name="")
Definition: TStatistic.h:57
#define ClassDef(name, id)
Definition: Rtypes.h:254
TString fName
Definition: TStatistic.h:48
Statistical variable, defined by its mean and variance (RMS).
Definition: TStatistic.h:45
Long64_t fN
Definition: TStatistic.h:49
Double_t GetM2() const
Definition: TStatistic.h:67
Collection abstract base class.
Definition: TCollection.h:48
Long64_t GetNeff() const
Definition: TStatistic.h:66
double Double_t
Definition: RtypesCore.h:55
Double_t fW2
Definition: TStatistic.h:51
unsigned long ULong_t
Definition: RtypesCore.h:51
void ls(Option_t *opt="") const
The ls function lists the contents of a class on stdout.
Definition: TStatistic.h:83
void Fill(Double_t val, Double_t w=1.)
Definition: TStatistic.cxx:48
Double_t GetW2() const
Definition: TStatistic.h:73
Mother of all ROOT objects.
Definition: TObject.h:37
Double_t GetVar() const
Definition: TStatistic.h:71
Int_t Merge(TCollection *in)
Definition: TStatistic.cxx:85
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
Long64_t GetN() const
Definition: TStatistic.h:65
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109