NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
Count.h
Go to the documentation of this file.
1//***************************************************************************************
4//***************************************************************************************
5
6#pragma once
7
8#include "NAGASH/Global.h"
9#include "NAGASH/Result.h"
10
11namespace NAGASH
12{
19 {
20 public:
21 void Add(const CountBase &);
22 void Add(double x = 1, double w = 1);
23 double GetSum() const;
24 double GetSum2() const;
25 double GetSumW() const;
26 double GetSumW2() const;
27 double GetSumStatUnc() const;
28 double GetMean() const;
29 double GetMeanStatUnc() const;
30 double GetVar() const;
31 double GetStdVar() const;
32 double Chi2(const CountBase &) const;
33 void Clear();
34
35 protected:
36 double SumW = 0;
37 double SumW2 = 0;
38 double SumX = 0;
39 double SumX2 = 0;
40 };
41
44 inline void CountBase::Add(const CountBase &subCountBase)
45 {
46 SumW += subCountBase.SumW;
47 SumW2 += subCountBase.SumW2;
48 SumX += subCountBase.SumX;
49 SumX2 += subCountBase.SumX2;
50 }
51
55 inline void CountBase::Add(double x, double w)
56 {
57 SumW += w;
58 SumW2 += w * w;
59 SumX += x * w;
60 SumX2 += x * x * w;
61 }
62
66 inline double CountBase::Chi2(const CountBase &count) const
67 {
68 return pow(this->GetMean() - count.GetMean(), 2) / (pow(this->GetMeanStatUnc(), 2) + pow(count.GetMeanStatUnc(), 2));
69 }
70
72 inline void CountBase::Clear()
73 {
74 SumW = 0;
75 SumW2 = 0;
76 SumX = 0;
77 SumX2 = 0;
78 }
79
80 inline double CountBase::GetSum() const { return SumX; }
81 inline double CountBase::GetSum2() const { return SumX2; }
82 inline double CountBase::GetSumW() const { return SumW; }
83 inline double CountBase::GetSumW2() const { return SumW2; }
84 inline double CountBase::GetSumStatUnc() const { return GetMean() * sqrt(SumW2); }
85 inline double CountBase::GetMean() const { return SumW != 0 ? SumX / SumW : 0; }
86
88 inline double CountBase::GetMeanStatUnc() const { return SumW != 0 ? GetStdVar() * sqrt(SumW2) / SumW : 0; }
90 inline double CountBase::GetVar() const { return SumW != 0 ? (SumX2 / SumW - (SumX / SumW) * (SumX / SumW)) : 0; }
92 inline double CountBase::GetStdVar() const { return sqrt(fabs(GetVar())); }
93
97 class Count : public Result, public CountBase
98 {
99 public:
100 Count(std::shared_ptr<MSGTool> MSG, std::shared_ptr<ConfigTool> c, const TString &rname, const TString &fname = "") : Result(MSG, c, rname, fname), CountBase(){};
101 ~Count() = default;
102 void Combine(std::shared_ptr<Result> result);
103 };
104
107 inline void Count::Combine(std::shared_ptr<Result> result)
108 {
109 auto subCount = std::dynamic_pointer_cast<std::remove_pointer<decltype(this)>::type>(result);
110 if (subCount != nullptr)
111 {
112 SumW += subCount->SumW;
113 SumW2 += subCount->SumW2;
114 SumX += subCount->SumX;
115 SumX2 += subCount->SumX2;
116 }
117 }
118} // namespace NAGASH
Some global definitions.
Base class for Count. This class provide a base class for Count. You can also use it if you don't nee...
Definition Count.h:19
double SumW
Definition Count.h:36
double SumX
Definition Count.h:38
double GetSumW() const
Get the sum of the weights .
Definition Count.h:82
double GetVar() const
Get the variance .
Definition Count.h:90
double GetMean() const
Get the mean .
Definition Count.h:85
double Chi2(const CountBase &) const
Calculate the with this and another CountBase object.
Definition Count.h:66
void Add(const CountBase &)
Add another CountBase object to this one.
Definition Count.h:44
double GetSumW2() const
Get the sum of the weights squared .
Definition Count.h:83
double GetMeanStatUnc() const
Get the statistical uncertainty of the mean .
Definition Count.h:88
double SumW2
Definition Count.h:37
double SumX2
Definition Count.h:39
double GetSum() const
Get the sum of the values .
Definition Count.h:80
double GetStdVar() const
Get the standard variance .
Definition Count.h:92
double GetSumStatUnc() const
Get the statistical uncertainty of the sum .
Definition Count.h:84
void Clear()
Clear this CountBase object.
Definition Count.h:72
double GetSum2() const
Get the sum of the values squared .
Definition Count.h:81
Use CountBase with the interface of provided by NAGASH::Result.
Definition Count.h:98
~Count()=default
Count(std::shared_ptr< MSGTool > MSG, std::shared_ptr< ConfigTool > c, const TString &rname, const TString &fname="")
Definition Count.h:100
void Combine(std::shared_ptr< Result > result)
Combine with another Count object, interface provided by NAGASH::Result.
Definition Count.h:107
Provide virtual interface to manipulate all the results inside NAGASH.
Definition Result.h:68