PandaRoot
ChiSquare.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 // ******************************************************
14 // DecayTreeFitter Package
15 // We thank the original author Wouter Hulsbergen
16 // (BaBar, LHCb) for providing the sources.
17 // http://arxiv.org/abs/physics/0503191v1 (2005)
18 // Adaptation & Development for PANDA: Ralf Kliemt (2015)
19 // ******************************************************
20 #ifndef DECAYTREEFITTER_ChiSquare_H
21 #define DECAYTREEFITTER_ChiSquare_H 1
22 #include "Rtypes.h"
23 #include "TMath.h"
24 
25 namespace DecayTreeFitter {
26 
27 class ChiSquare {
28  public:
30  ChiSquare(const double achi2, int andof) : m_chi2(achi2), m_nDoF(andof) {}
31 
33  ChiSquare() : m_chi2(0.0), m_nDoF(0) {}
34 
36  virtual ~ChiSquare() {}
37 
39  double chi2PerDoF() const { return m_nDoF > 0 ? m_chi2 / m_nDoF : 0; }
40 
42  ChiSquare &operator+=(const ChiSquare &rhs);
43 
45  ChiSquare &operator-=(const ChiSquare &rhs);
46 
48  ChiSquare operator+(const ChiSquare &rhs);
49 
51  ChiSquare operator-(const ChiSquare &rhs);
52 
54  double chi2() const { return m_chi2; }
55 
57  int nDoF() const { return m_nDoF; }
58 
60  double prob() const { return TMath::Prob(m_chi2, m_nDoF); }
61 
62  protected:
63  private:
64  double m_chi2;
65  int m_nDoF;
66  ClassDef(ChiSquare, 1)
67 
68 }; // class ChiSquare
69 
71 {
72  m_chi2 += rhs.m_chi2;
73  m_nDoF += rhs.m_nDoF;
74  return *this;
75 }
76 
78 {
79  m_chi2 -= rhs.m_chi2;
80  m_nDoF -= rhs.m_nDoF;
81  return *this;
82 }
83 
85 {
86  ChiSquare rc = *this;
87  rc += rhs;
88  return rc;
89 }
90 
92 {
93  ChiSquare rc = *this;
94  rc -= rhs;
95  return rc;
96 }
97 } // namespace DecayTreeFitter
98 
99 #endif
ChiSquare operator-(const ChiSquare &rhs)
subtraction operator
Definition: ChiSquare.h:91
ChiSquare & operator+=(const ChiSquare &rhs)
addition operator
Definition: ChiSquare.h:70
ChiSquare & operator-=(const ChiSquare &rhs)
subtraction operator
Definition: ChiSquare.h:77
ChiSquare operator+(const ChiSquare &rhs)
addition operator
Definition: ChiSquare.h:84
double chi2PerDoF() const
return chi2/ndof if ndof>0. returns zero otherwise.
Definition: ChiSquare.h:39
double prob() const
Get Cofidence level.
Definition: ChiSquare.h:60
double chi2() const
Retrieve const chi square.
Definition: ChiSquare.h:54
ChiSquare()
Default Constructor.
Definition: ChiSquare.h:33
virtual ~ChiSquare()
Default Destructor.
Definition: ChiSquare.h:36
ChiSquare(const double achi2, int andof)
Constructor.
Definition: ChiSquare.h:30
int nDoF() const
Retrieve const number of degrees of freedom.
Definition: ChiSquare.h:57