22 templateClassImp(TStatistic);
32 TStatistic::TStatistic(
const char *name, Int_t n,
const Double_t *val,
const Double_t *w)
33 : fName(name), fN(0), fW(0.), fW2(0.), fM(0.), fM2(0.), fMin(TMath::Limits<Double_t>::Max()), fMax(TMath::Limits<Double_t>::Min())
36 for (Int_t i = 0; i < n; i++) {
48 TStatistic::~TStatistic()
51 ROOT::CallRecursiveRemoveIfNeeded(*
this);
74 void TStatistic::Fill(Double_t val, Double_t w) {
88 fMin = (val < fMin) ? val : fMin;
89 fMax = (val > fMax) ? val : fMax;
93 Warning(
"Fill",
"Sum of weights is zero - ignore current data point");
99 Double_t rr = ( tW * val - fM);
100 fM2 += w * rr * rr / (tW * fW);
111 void TStatistic::Print(Option_t *)
const {
112 TROOT::IndentLevel();
113 Printf(
" OBJ: TStatistic\t %s \t Mean = %.5g +- %.4g \t RMS = %.5g \t Count = %lld \t Min = %.5g \t Max = %.5g",
114 fName.Data(), GetMean(), GetMeanErr(), GetRMS(), GetN(), GetMin(), GetMax());
133 Int_t TStatistic::Merge(TCollection *in) {
136 std::vector<TStatistic*> statPtrs;
137 if (this->fN != 0LL) statPtrs.push_back(
this);
140 if ((statPtr = dynamic_cast<TStatistic *>(o)) && statPtr->fN != 0LL) {
141 statPtrs.push_back(statPtr);
146 const auto nStatsPtrs = statPtrs.size();
149 if (nStatsPtrs == 0)
return 0;
153 auto firstStatPtr = statPtrs[0];
154 auto N = firstStatPtr->fN;
155 auto M = firstStatPtr->fM;
156 auto M2 = firstStatPtr->fM2;
157 auto W = firstStatPtr->fW;
158 auto W2 = firstStatPtr->fW2;
159 auto Min = firstStatPtr->fMin;
160 auto Max = firstStatPtr->fMax;
161 for (
auto i = 1U; i < nStatsPtrs; ++i) {
162 auto c = statPtrs[i];
163 double temp = (c->fW) / (W)*M - c->fM;
164 M2 += c->fM2 + W / (c->fW * (c->fW + W)) * temp * temp;
169 Min = (c->fMin < Min) ? c->fMin : Min;
170 Max = (c->fMax > Max) ? c->fMax : Max;