Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:26

0001 // @(#)root/mathcore:$Id$
0002 // Author: G. Ganis 2012
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TStatistic
0013 #define ROOT_TStatistic
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TStatistic                                                           //
0019 //                                                                      //
0020 // Statistical variable, defined by its mean, RMS and related errors.   //
0021 // Named, streamable, storable and mergeable.                           //
0022 //                                                                      //
0023 //////////////////////////////////////////////////////////////////////////
0024 
0025 #include "TObject.h"
0026 
0027 #include "TMath.h"
0028 
0029 #include "TString.h"
0030 
0031 class TCollection;
0032 
0033 class TStatistic : public TObject {
0034 
0035 private:
0036    TString     fName;    ///< Name given to the TStatistic object
0037    Long64_t    fN;       ///< Number of fills
0038    Double_t    fW;       ///< Sum of weights
0039    Double_t    fW2;      ///< Sum of squared weights
0040    Double_t    fM;       ///< Sum of elements (i.e. sum of (val * weight) pairs
0041    Double_t    fM2;      ///< Second order momentum
0042    Double_t    fMin;     ///< Minimum value in the TStatistic object
0043    Double_t    fMax;     ///< Maximum value in the TStatistic object
0044 
0045 public:
0046 
0047    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>::Max()) { }
0048    TStatistic(const char *name, Int_t n, const Double_t *val, const Double_t *w = nullptr);
0049    ~TStatistic() override;
0050 
0051    // Getters
0052    const char    *GetName() const override { return fName; }
0053    ULong_t        Hash() const override { return fName.Hash(); }
0054 
0055    inline       Long64_t GetN() const { return fN; }
0056    inline       Long64_t GetNeff() const { return fW*fW/fW2; }
0057    inline       Double_t GetM2() const { return fM2; }
0058    inline       Double_t GetMean() const { return (fW > 0) ? fM/fW : 0; }
0059    inline       Double_t GetMeanErr() const { return  (fW > 0.) ?  TMath::Sqrt( GetVar()/ GetNeff() ) : 0; }
0060    inline       Double_t GetRMS() const { double var = GetVar(); return (var>0) ? TMath::Sqrt(var) : -1; }
0061    inline       Double_t GetVar() const { return (fW>0) ? ( (fN>1) ? (fM2 / fW)*(fN / (fN-1.)) : 0 ) : -1; }
0062    inline       Double_t GetW() const { return fW; }
0063    inline       Double_t GetW2() const { return fW2; }
0064    inline       Double_t GetMin() const { return fMin; }
0065    inline       Double_t GetMax() const { return fMax; }
0066 
0067    // Merging
0068    Int_t Merge(TCollection *in);
0069 
0070    // Fill
0071    void Fill(Double_t val, Double_t w = 1.);
0072 
0073    // Print
0074    void Print(Option_t * = "") const override;
0075    void ls(Option_t *opt = "") const override { Print(opt); }
0076 
0077    ClassDefOverride(TStatistic,3)  // Named statistical variable
0078 };
0079 
0080 #endif