9#include "FluctuationMath.h"
15 FluctuationMath::FluctuationMath() :
29 void FluctuationMath::GetVals(Double_t& min, Double_t& max, Double_t val, Double_t error) {
30 min = val - TMath::Abs(error);
31 max = val + TMath::Abs(error);
34 void FluctuationMath::SetHistoTH1D(TH1D* h, TString opt) {
42 void FluctuationMath::Calc(TH1D* h) {
43 fN = fM[2] = fM[3] = fM[4] = 0.0;
44 Double_t entries = h->GetEntries();
46 for (
int i = 1; i <= h->GetNbinsX(); i++) {
47 Double_t pN = ((Double_t) h->GetBinContent(i));
48 Double_t N = (Double_t) h->GetBinCenter(i);
52 for (
int i = 1; i <= h->GetNbinsX(); i++) {
53 Double_t pN = ((Double_t) h->GetBinContent(i));
54 Double_t N = (Double_t) h->GetBinCenter(i);
55 for (
int j = 2; j <= 4; j++) {
56 fM[j] += TMath::Power(N - fN, j) * pN;
59 for (
int j = 2; j <= 4; j++) {
60 fM[j] = fM[j] / entries;
62 fOmega = GetCentralMoment(2) / fN;
63 fSSigma = GetCentralMoment(3) / GetCentralMoment(2);
64 fKappaSigma = GetCentralMoment(4) / GetCentralMoment(2) - 3.0 * GetCentralMoment(2);
67 Double_t FluctuationMath::GetCentralMoment(Int_t i)
const {
69 std::cout <<
"wrong mu index" << std::endl;
76 void FluctuationMath::CalcError(TH1D* h) {
77 TH1D* hh = (TH1D*) h->Clone(
"temp_boostrap");
78 FluctuationMath* stat =
new FluctuationMath();
79 Double_t range_min[4], range_max[4];
80 GetVals(range_min[0], range_max[0], GetMean(), GetMean() * 2.5);
81 GetVals(range_min[1], range_max[1], GetOmega(), GetOmega() * 2.5);
82 GetVals(range_min[2], range_max[2], GetSSigma(), GetSSigma() * 2.5);
83 GetVals(range_min[3], range_max[3], GetKappaSigma(), GetKappaSigma() * 2.5);
84 Bool_t stat_ok = kFALSE;
86 TH1D* mean =
new TH1D(
"mean",
"mean", 1000, range_min[0], range_max[0]);
87 TH1D* omega =
new TH1D(
"omega",
"omega", 1000, range_min[1], range_max[1]);
88 TH1D* sigma =
new TH1D(
"sigma",
"sigma", 1000, range_min[2], range_max[2]);
89 TH1D* kappa =
new TH1D(
"kapa",
"kappa", 1000, range_min[3], range_max[3]);
90 for (
int i = 0; i < fNSample; i++) {
92 for (
int j = 0; j < h->GetEntries(); j++) {
93 hh->Fill(h->GetRandom());
96 omega->Fill(stat->GetOmega());
97 sigma->Fill(stat->GetSSigma());
98 kappa->Fill(stat->GetKappaSigma());
99 mean->Fill(stat->GetMean());
101 fOmegaError = omega->GetRMS();
102 fSigmaError = sigma->GetRMS();
103 fKappaError = kappa->GetRMS();
104 fNError = mean->GetRMS();
106 if (fNError > (1.0 / fTollerance) * TMath::Abs(range_min[0] - range_max[0])) {
108 std::cout <<
" need to recalcuate because of mean" << std::endl;
109 Double_t step = TMath::Abs(range_min[0] - range_max[0]);
110 std::cout << Form(
" used range %4.3f - %4.3f [%4.3f ] calculated error "
117 GetVals(range_min[0], range_max[0], GetMean(), GetMeanError() * fTollerance * 2.0);
118 step = TMath::Abs(range_min[0] - range_max[0]);
119 std::cout << Form(
" new range %4.3f - %4.3f [%4.3f ] ", range_min[0], range_max[0], step) << std::endl;
121 if (fOmegaError > (1.0 / fTollerance) * TMath::Abs(range_min[1] - range_max[1])) {
123 std::cout <<
" need to recalcuate because of omega" << std::endl;
124 Double_t step = TMath::Abs(range_min[1] - range_max[1]);
125 std::cout << Form(
" used range %4.3f - %4.3f [%4.3f ] calculated error "
132 GetVals(range_min[1], range_max[1], GetOmega(), GetOmegaError() * fTollerance * 2.0);
133 step = TMath::Abs(range_min[1] - range_max[1]);
134 std::cout << Form(
" new range %4.3f - %4.3f [%4.3f ] ", range_min[1], range_max[1], step) << std::endl;
136 if (fSigmaError > (1.0 / fTollerance) * TMath::Abs(range_min[2] - range_max[2])) {
138 std::cout <<
" need to recalcuate because of sigma" << std::endl;
139 Double_t step = TMath::Abs(range_min[2] - range_max[2]);
140 std::cout << Form(
" used range %4.3f - %4.3f [%4.3f ] calculated error "
147 step = TMath::Abs(range_min[2] - range_max[2]);
148 GetVals(range_min[2], range_max[2], GetSSigma(), GetSSigmaError() * fTollerance * 2.0);
149 std::cout << Form(
" new range %4.3f - %4.3f [%4.3f ] ", range_min[2], range_max[2], step) << std::endl;
151 if (fKappaError > (1.0 / fTollerance) * TMath::Abs(range_min[3] - range_max[3])) {
153 std::cout <<
" need to recalcuate because of kappa" << std::endl;
154 Double_t step = TMath::Abs(range_min[3] - range_max[3]);
155 std::cout << Form(
" used range %4.3f - %4.3f [%4.3f ] calculated error "
162 GetVals(range_min[3], range_max[3], GetKappaSigma(), GetKappaSigmaError() * fTollerance * 2.0);
163 step = TMath::Abs(range_min[3] - range_max[3]);
164 std::cout << Form(
" new range %4.3f - %4.3f [%4.3f ] ", range_min[3], range_max[3], step) << std::endl;
175 void FluctuationMath::CalcErrorMagic(TH1D* h) {
176 TH1D* hh = (TH1D*) h->Clone(
"temp_boostrap");
177 FluctuationMath* stat =
new FluctuationMath();
178 Double_t range_min[4], range_max[4];
179 GetVals(range_min[0], range_max[0], GetMean(), GetMean() * 2.5);
180 GetVals(range_min[1], range_max[1], GetOmega(), GetOmega() * 2.5);
181 GetVals(range_min[2], range_max[2], GetSSigma(), GetSSigma() * 2.5);
182 GetVals(range_min[3], range_max[3], GetKappaSigma(), GetKappaSigma() * 2.5);
183 Bool_t stat_ok = kFALSE;
185 TH1D* mean =
new TH1D(
"mean",
"mean", 1000, range_min[0], range_max[0]);
186 TH1D* omega =
new TH1D(
"omega",
"omega", 1000, range_min[1], range_max[1]);
187 TH1D* sigma =
new TH1D(
"sigma",
"sigma", 1000, range_min[2], range_max[2]);
188 TH1D* kappa =
new TH1D(
"kapa",
"kappa", 1000, range_min[3], range_max[3]);
189 for (
int i = 0; i < h->GetNbinsX(); i++) {
191 Double_t scale = h->GetEntries();
192 Double_t bin_cont = h->GetBinContent(i);
193 scale = scale / (scale - bin_cont);
194 for (
int j = 0; j <= h->GetNbinsX(); j++) {
195 hh->SetBinContent(j, h->GetBinContent(j) * scale);
197 hh->SetBinContent(i, 0);
199 omega->Fill(stat->GetOmega(), bin_cont);
200 sigma->Fill(stat->GetSSigma(), bin_cont);
201 kappa->Fill(stat->GetKappaSigma(), bin_cont);
202 mean->Fill(stat->GetMean(), bin_cont);
204 fOmegaError = omega->GetRMS();
205 fSigmaError = sigma->GetRMS();
206 fKappaError = kappa->GetRMS();
207 fNError = mean->GetRMS();
209 if (fNError > (1.0 / fTollerance) * TMath::Abs(range_min[0] - range_max[0])) {
211 std::cout <<
" need to recalcuate because of mean" << std::endl;
212 Double_t step = TMath::Abs(range_min[0] - range_max[0]);
213 std::cout << Form(
" used range %4.3f - %4.3f [%4.3f ] calculated error "
220 GetVals(range_min[0], range_max[0], GetMean(), GetMeanError() * fTollerance * 2.0);
221 step = TMath::Abs(range_min[0] - range_max[0]);
222 std::cout << Form(
" new range %4.3f - %4.3f [%4.3f ] ", range_min[0], range_max[0], step) << std::endl;
224 if (fOmegaError > (1.0 / fTollerance) * TMath::Abs(range_min[1] - range_max[1])) {
226 std::cout <<
" need to recalcuate because of omega" << std::endl;
227 Double_t step = TMath::Abs(range_min[1] - range_max[1]);
228 std::cout << Form(
" used range %4.3f - %4.3f [%4.3f ] calculated error "
235 GetVals(range_min[1], range_max[1], GetOmega(), GetOmegaError() * fTollerance * 2.0);
236 step = TMath::Abs(range_min[1] - range_max[1]);
237 std::cout << Form(
" new range %4.3f - %4.3f [%4.3f ] ", range_min[1], range_max[1], step) << std::endl;
239 if (fSigmaError > (1.0 / fTollerance) * TMath::Abs(range_min[2] - range_max[2])) {
241 std::cout <<
" need to recalcuate because of sigma" << std::endl;
242 Double_t step = TMath::Abs(range_min[2] - range_max[2]);
243 std::cout << Form(
" used range %4.3f - %4.3f [%4.3f ] calculated error "
250 step = TMath::Abs(range_min[2] - range_max[2]);
251 GetVals(range_min[2], range_max[2], GetSSigma(), GetSSigmaError() * fTollerance * 2.0);
252 std::cout << Form(
" new range %4.3f - %4.3f [%4.3f ] ", range_min[2], range_max[2], step) << std::endl;
254 if (fKappaError > (1.0 / fTollerance) * TMath::Abs(range_min[3] - range_max[3])) {
256 std::cout <<
" need to recalcuate because of kappa" << std::endl;
257 Double_t step = TMath::Abs(range_min[3] - range_max[3]);
258 std::cout << Form(
" used range %4.3f - %4.3f [%4.3f ] calculated error "
265 GetVals(range_min[3], range_max[3], GetKappaSigma(), GetKappaSigmaError() * fTollerance * 2.0);
266 step = TMath::Abs(range_min[3] - range_max[3]);
267 std::cout << Form(
" new range %4.3f - %4.3f [%4.3f ] ", range_min[3], range_max[3], step) << std::endl;
278 FluctuationMath::~FluctuationMath() {