Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 "TCollection.h"
28 
29 #include "TMath.h"
30 
31 #include "TString.h"
32 
33 #include "TROOT.h"
34 
35 class TStatistic : public TObject {
36 
37 private:
38  TString fName; ///< Name given to the TStatistic object
39  Long64_t fN; ///< Number of fills
40  Double_t fW; ///< Sum of weights
41  Double_t fW2; ///< Sum of squared weights
42  Double_t fM; ///< Sum of elements (i.e. sum of (val * weight) pairs
43  Double_t fM2; ///< Second order momentum
44  Double_t fMin; ///< Minimum value in the Tstatistic object
45  Double_t fMax; ///< Maximum value in the TStatistic object
46 
47 public:
48 
49  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()) { }
50  TStatistic(const char *name, Int_t n, const Double_t *val, const Double_t *w = 0);
51  ~TStatistic();
52 
53  // Getters
54  const char *GetName() const { return fName; }
55  ULong_t Hash() const { return fName.Hash(); }
56 
57  inline Long64_t GetN() const { return fN; }
58  inline Long64_t GetNeff() const { return fW*fW/fW2; }
59  inline Double_t GetM2() const { return fM2; }
60  inline Double_t GetMean() const { return (fW > 0) ? fM/fW : 0; }
61  inline Double_t GetMeanErr() const { return (fW > 0.) ? TMath::Sqrt( GetVar()/ GetNeff() ) : 0; }
62  inline Double_t GetRMS() const { double var = GetVar(); return (var>0) ? TMath::Sqrt(var) : -1; }
63  inline Double_t GetVar() const { return (fW>0) ? ( (fN>1) ? (fM2 / fW)*(fN / (fN-1.)) : 0 ) : -1; }
64  inline Double_t GetW() const { return fW; }
65  inline Double_t GetW2() const { return fW2; }
66  inline Double_t GetMin() const { return fMin; }
67  inline Double_t GetMax() const { return fMax; }
68 
69  // Merging
70  Int_t Merge(TCollection *in);
71 
72  // Fill
73  void Fill(Double_t val, Double_t w = 1.);
74 
75  // Print
76  void Print(Option_t * = "") const;
77  void ls(Option_t *opt = "") const { Print(opt); }
78 
79  ClassDef(TStatistic,3) // Named statistical variable
80 };
81 
82 #endif