1 /**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
5 * Permission to use, copy, modify and distribute this software and its *
6 * documentation strictly for non-commercial purposes is hereby granted *
7 * without fee, provided that the above copyright notice appears in all *
8 * copies and that both the copyright notice and this permission notice *
9 * appear in the supporting documentation. The authors make no claims *
10 * about the suitability of this software for any purpose. It is *
11 * provided "as is" without express or implied warranty. *
12 **************************************************************************/
14 //-------------------------------------------------------------------------
16 // This class include into LRC library for Long-Range Correlation analysis
17 // it makes fit of the 1d histogramm
18 // calculates ax+b coefficients with error and hi square
19 // Origin: Petr Naumenko, SPbSU-CERN, Petr.Naoumenko@cern.ch
20 //-------------------------------------------------------------------------
24 #include "AliLRCFit.h"
30 AliLRCFit::AliLRCFit():fN (0), fTrueN(0), fNmin (0), fNmax(0), fS1(.0), fSz(.0), fSfz(.0), fSf(.0), fSf2(.0), fhi2(.0), fw(.0), fz(.0), f(.0), fnum(.0), fdf(.0), fdelta(.0), fa(.0), fb(.0), fda(.0), fdb(.0), fda1(.0), fdb1(.0), fxmin(.0), fxmax(.0){
34 AliLRCFit::AliLRCFit(TH1D* h):fN (0), fTrueN(0), fNmin (0), fNmax(0), fS1(.0), fSz(.0), fSfz(.0), fSf(.0), fSf2(.0), fhi2(.0), fw(.0), fz(.0), f(.0), fnum(.0), fdf(.0), fdelta(.0), fa(.0), fb(.0), fda(.0), fdb(.0), fda1(.0), fdb1(.0), fxmin(.0), fxmax(.0){
35 //Constructor make fit of 1d histogramm
36 fxmin = h->GetXaxis()->GetXmin();
37 fxmax = h->GetXaxis()->GetXmax();
41 fnum = h->GetXaxis()->GetXmin();
42 fdf = (h->GetXaxis()->GetXmax()-fnum)/fN;
43 for(int i=1; i<=fN; i++){
45 fw = h->GetBinError(i);
47 fz = h->GetBinContent(i);
48 fS1 = fS1 + 1/(fw*fw);
49 fSz = fSz + fz/(fw*fw);
50 fSfz = fSfz + f*fz/(fw*fw);
51 fSf = fSf + f/(fw*fw);
52 fSf2 = fSf2 + (f*f)/(fw*fw);
55 fdelta = fS1*fSf2 - fSf*fSf;
56 fb = (fS1*fSfz - fSf*fSz)/fdelta;
57 fa = ((fSf2-fSf)*fSz - (fSf-fS1)*fSfz)/fdelta;
58 fda = sqrt((fS1+fSf2-2*fSf)/fdelta);
59 fdb = sqrt(fS1/fdelta);
62 f = h->GetXaxis()->GetXmin();
63 for(int i=1; i<=fN; i++){
65 fw = h->GetBinError(i);
67 fz = h->GetBinContent(i);
68 fdb1 = fdb1 + ((fS1*f - fSf)*(fS1*f - fSf)/(fw*fw)) * ((fz-fa-fb*(f-1))*(fz-fa-fb*(f-1))/(fw*fw));
69 fda1 = fda1 + (((fSf2-fSf)-(fSf-fS1)*f)*((fSf2-fSf)-(fSf-fS1)*f)/(fw*fw)) * ((fz-fa+fb-fb*f)*(fz-fa+fb-fb*f)/(fw*fw));
70 fhi2 = fhi2 + ((fz-(fa-fb)-fb*f) * (fz-(fa-fb)-fb*f)) / (fw*fw);
74 fdb1 = sqrt(fdb1/(fdelta*fdelta));
75 fda1 = sqrt(fda1/(fdelta*fdelta));
76 fhi2 = fhi2 / (fTrueN-2);
79 AliLRCFit::AliLRCFit(TH1D *h, double xmin, double xmax):fN (0), fTrueN(0), fNmin (0), fNmax(0), fS1(.0), fSz(.0), fSfz(.0), fSf(.0), fSf2(.0), fhi2(.0), fw(.0), fz(.0), f(.0), fnum(.0), fdf(.0), fdelta(.0), fa(.0), fb(.0), fda(.0), fdb(.0), fda1(.0), fdb1(.0), fxmin(.0), fxmax(.0){
80 //Constructor make fit of 1d histogramm between xmin and xmax
84 fnum = h->GetXaxis()->GetXmin();
85 fdf = (h->GetXaxis()->GetXmax()-fnum)/fN;
86 fNmin=int((xmin-f)/fdf)+1;
87 fNmax=int((xmax-f)/fdf)+1;
88 for(int i=fNmin; i<=fNmax; i++){
90 fw = h->GetBinError(i);
92 fz = h->GetBinContent(i);
93 fS1 = fS1 + 1/(fw*fw);
94 fSz = fSz + fz/(fw*fw);
95 fSfz = fSfz + f*fz/(fw*fw);
96 fSf = fSf + f/(fw*fw);
97 fSf2 = fSf2 + (f*f)/(fw*fw);
100 fdelta = fS1*fSf2 - fSf*fSf;
101 fb = (fS1*fSfz - fSf*fSz)/fdelta;
102 fa = ((fSf2-fSf)*fSz - (fSf-fS1)*fSfz)/fdelta;
103 fda = sqrt((fS1+fSf2-2*fSf)/fdelta);
104 fdb = sqrt(fS1/fdelta);
107 for(int i=fNmin; i<=fNmax; i++){
109 fw = h->GetBinError(i);
111 fz = h->GetBinContent(i);
112 fdb1 = fdb1 + ((fS1*f - fSf)*(fS1*f - fSf)/(fw*fw)) * ((fz-fa-fb*(f-1))*(fz-fa-fb*(f-1))/(fw*fw));
113 fda1 = fda1 + (((fSf2-fSf)-(fSf-fS1)*f)*((fSf2-fSf)-(fSf-fS1)*f)/(fw*fw)) * ((fz-fa+fb-fb*f)*(fz-fa+fb-fb*f)/(fw*fw));
114 fhi2 = fhi2 + ((fz-(fa-fb)-fb*f) * (fz-(fa-fb)-fb*f)) / (fw*fw);
118 fdb1 = sqrt(fdb1/(fdelta*fdelta));
119 fda1 = sqrt(fda1/(fdelta*fdelta));
120 fhi2 = fhi2 / (fTrueN-2);
123 AliLRCFit::~AliLRCFit() {
126 double AliLRCFit::Geta() const {return fa;}
127 double AliLRCFit::Getb() const {return fb;}
128 double AliLRCFit::Getda() const {return fda;}
129 double AliLRCFit::Getdb() const {return fdb;}
130 double AliLRCFit::Getda1() const {return fda1;}
131 double AliLRCFit::Getdb1() const {return fdb1;}
132 double AliLRCFit::Gethi2() const {return fhi2;}
133 double AliLRCFit::Getf() const {return f;}
134 double AliLRCFit::Getxmin() const {return fxmin;}
135 double AliLRCFit::Getxmax() const {return fxmax;}
136 int AliLRCFit::GetN() const {return fN;}