Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrFit1DCF.cxx
1/*
2 * CorrFit1DCF.cxx
3 *
4 * Created on: 02-04-2015
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "CorrFit.h"
11
12
13#include <TAttLine.h>
14#include <TAttMarker.h>
15#include <TAxis.h>
16#include <TCanvas.h>
17#include <TF1.h>
18#include <TH1.h>
19#include <TLegend.h>
20#include <TLegendEntry.h>
21#include <TMath.h>
22#include <TNamed.h>
23#include <TString.h>
24#include <TSystem.h>
25
26#include "Array.h"
27#include "CorrFit1DCF.h"
28
29#include "CorrFit1DCFPainter.h"
30#include "CorrFitHDFunc1D.h"
31#include "CorrFitMask.h"
32#include "CorrFitMask1D.h"
33#include "Cout.h"
34#include "Femto1DCF.h"
35#include "Splines.h"
36#include "Std.h"
37#include "StdHist.h"
38#include "StdString.h"
39
40namespace Hal {
41
42 CorrFit1DCF::CorrFit1DCF(Int_t parameters) : CorrFitFunc(parameters, 1) {
43 fNormParIndex = 0;
44 if (GetParametersNo() < 2) { HalCoutDebug("1D corrfit func should contain at least 2 params"); }
45 if (GetParametersNo() > 2) { // not only radii fit also lambda
46 SetParameterName(LambdaID(), "#lambda");
47 fParameters[LambdaID()].SetRange(0, 1);
48 }
49 fBinX = 0;
52 }
53
54 Double_t CorrFit1DCF::EvalDenominator(Double_t x) const {
55 Int_t bin = fDenominatorHistogram->FindBin(x);
56 return fDenominatorHistogram->GetBinContent(bin);
57 }
58
59 void CorrFit1DCF::MakePainter(TString opt) {
61 fPainter->SetOption(opt);
62 }
63
64 void CorrFit1DCF::SetErrors(TH1* num, const TH1* /*den*/) const {
65 for (int i = 0; i <= num->GetNbinsX(); i++) {
66 Double_t e_num = num->GetBinError(i);
67 Double_t e_den = num->GetBinError(i);
68 num->SetBinError(i, TMath::Sqrt(e_num * e_num + e_den * e_den));
69 }
70 }
71
73 Prepare();
76 fNumeratorHistogram = ((DividedHisto1D*) fCF)->GetNum();
77 fCorrelationFunctionHistogram = ((DividedHisto1D*) fCF)->GetHist(kFALSE);
78 fCorrelationFunctionHistogram->SetDirectory(0);
79 fKinematics = static_cast<Femto1DCF*>(fCF)->GetFrame();
80 if (fHDMaps == nullptr) fHDMaps = new CorrFitHDFunc1D();
81 }
82
83 double CorrFit1DCF::GetChiTFD(const double* /*par*/) const {
84 Double_t f = 0.0;
85 Double_t A, B;
86 Double_t e3, chi;
87 CorrFitHDFunc1D* cf = static_cast<CorrFitHDFunc1D*>(fHDMaps);
88 Bool_t useHD = kFALSE;
89 if (fBinCalc == kExtrapolated) useHD = kTRUE;
90 for (int i = 0; i < cf->GetNbins(); i++) {
91 fBinX = cf->GetBin(i);
92 A = fNumeratorHistogram->GetBinContent(fBinX);
93 B = fDenominatorHistogram->GetBinContent(fBinX);
94 // x = fDenominatorHistogram->GetBinCenter(fBinX);
95
96 Double_t Cf, ecf;
97 Double_t Cf_theo;
98 // CalcError(A, fNumeratorHistogram->GetBinError(fBinX), B, fDenominatorHistogram->GetBinError(fBinX), Cf, ecf);
99 Cf_theo = cf->GetBinCFVal(fBinX, useHD);
100 e3 = GetNumericalError(fBinX) * Cf_theo;
101 Cf_theo = Cf_theo * B; // cf_theo * denominator
102 Cf = A; // just numerator
103 ecf = fNumeratorHistogram->GetBinError(fBinX); // just sqrt of numerator
104 chi = Cf_theo - Cf;
105 chi *= chi;
106 f += chi / (ecf * ecf + e3 * e3);
107 }
108#ifdef CF_FIT_TRACKING
109 for (int i = 0; i < GetParametersNo(); i++) {
110 std::cout << Form("%4.3f\t", par[i]);
111 }
112 std::cout << "->" << f << std::endl;
113#endif
114 return f;
115 }
116
117 double CorrFit1DCF::GetLogTFD(const double* /*par*/) const {
118 Double_t f = 0.0;
119 Double_t A, B, C;
120 CorrFitHDFunc1D* cf = static_cast<CorrFitHDFunc1D*>(fHDMaps);
121 Bool_t useHD = kFALSE;
122 if (fBinCalc == kExtrapolated) useHD = kTRUE;
123 for (int i = 0; i < cf->GetNbins(); i++) {
124 fBinX = cf->GetBin(i);
125 A = fNumeratorHistogram->GetBinContent(fBinX);
126 B = fDenominatorHistogram->GetBinContent(fBinX);
127 // x = fDenominatorHistogram->GetBinCenter(fBinX);
128 C = cf->GetBinCFVal(fBinX, useHD);
129 Double_t logA = (C * (A + B)) / (A * (C + 1.0));
130 Double_t logB = (A + B) / (B * (C + 1.0));
131 f += -(A * TMath::Log(logA) + B * TMath::Log(logB));
133 }
134#ifdef CF_FIT_TRACKING
135 for (int i = 0; i < GetParametersNo(); i++) {
136 std::cout << Form("%4.3f\t", par[i]);
137 }
138 std::cout << "->" << f << std::endl;
139#endif
140 return f;
141 }
142
143 double CorrFit1DCF::GetChiTF(const double* /*par*/) const {
144 Double_t f = 0.0;
145 Double_t C;
146 CorrFitHDFunc1D* Cf = static_cast<CorrFitHDFunc1D*>(fHDMaps);
147 Bool_t useHD = kFALSE;
148 if (fBinCalc == kExtrapolated) useHD = kTRUE;
149 for (int i = 0; i < Cf->GetNbins(); i++) {
150 fBinX = Cf->GetBin(i);
151 Double_t cf = fCorrelationFunctionHistogram->GetBinContent(fBinX);
152 // x = fDenominatorHistogram->GetBinCenter(fBinX);
153 C = Cf->GetBinCFVal(fBinX, useHD);
154 Double_t ea = fCorrelationFunctionHistogram->GetBinError(fBinX);
155 Double_t eb = GetNumericalError(fBinX);
156 ea = (ea + eb);
157 Double_t delta = C - cf;
158 f += delta * delta / (ea * ea);
159 }
160#ifdef CF_FIT_TRACKING
161 for (int i = 0; i < GetParametersNo(); i++) {
162 std::cout << Form("%4.3f\t", par[i]);
163 }
164 std::cout << "->" << f << std::endl;
165#endif
166 return f;
167 }
168
169 Double_t CorrFit1DCF::GetFunDrawable(Double_t* x, Double_t* params) const {
170 fBinX = fDenominatorHistogram->GetXaxis()->FindBin(x[0]);
171 if (params[GetParametersNo()]) { return EvalCF(x, params) / params[fNormParIndex]; }
172 return EvalCF(x, params);
173 }
174
175 Double_t CorrFit1DCF::Eval(Double_t q) const {
176 fBinX = fDenominatorHistogram->GetXaxis()->FindBin(q);
177 return CalculateCF(&q, fTempParamsEval);
178 }
179
181 fActiveBins = 0;
182 if (fMask == nullptr) {
183 fMask = new CorrFitMask1D(fDenominatorHistogram->GetNbinsX(),
184 fDenominatorHistogram->GetXaxis()->GetXmin(),
185 fDenominatorHistogram->GetXaxis()->GetXmax());
186 }
187 if (fOwnRangeMap == kTRUE) {
188 fMask->ApplyThreshold(*fDenominatorHistogram, 0);
189 } else {
190 GetMask()->Reset(false);
191 GetMask()->ApplyRange(fRange[0], fRange[1], true);
192 GetMask()->ApplyThreshold(*fNumeratorHistogram, fThreshold);
193 GetMask()->ApplyThreshold(*fDenominatorHistogram, fThreshold);
194 }
195 fMask->Init();
196 fActiveBins = GetMask()->GetActiveBins();
197 Double_t free_parameters = 0;
198 for (int i = 0; i < GetParametersNo(); i++) {
199 if (!fParameters[i].IsFixed()) free_parameters++;
200 }
201
202 Bool_t useHD = kFALSE;
203 if (fBinCalc == kExtrapolated) useHD = kTRUE;
204
206
207 fNDF = fActiveBins - free_parameters;
208 }
209
210 CorrFit1DCF::~CorrFit1DCF() {}
211
212 void CorrFit1DCF::Fit(TObject* histo) {
213 TH1* num = ((DividedHisto1D*) histo)->GetNum();
215 CorrFitFunc::Fit(histo);
216 }
217
219 TF1* draw_func = new TF1(Hal::Std::GetUniqueName("func_draw"),
220 this,
222 fRange.Get(0),
223 fRange.Get(1),
224 GetParametersNo() + 1,
225 this->ClassName(),
226 "GetFunDrawable"); // last parameter enable normalization if set to 1
227 for (int i = 0; i < GetParametersNo(); i++) {
228 draw_func->FixParameter(i, GetParameter(i));
229 draw_func->SetParName(i, GetParameterName(i));
230 }
231 draw_func->FixParameter(GetParametersNo(), 0);
232 draw_func->SetLineColor(GetLineColor());
233 draw_func->SetLineStyle(GetLineStyle());
234 draw_func->SetLineWidth(GetLineWidth());
235 return draw_func;
236 }
237
238 Double_t CorrFit1DCF::EvalCF(const Double_t* x, const Double_t* params) const {
239 if (fBinCalc == kExtrapolated) {
240 Double_t val = 0;
241 const Int_t bin0 = fBinX * 2 - 2;
242 for (int i = 0; i < 3; i++) {
243 Double_t n_temp = static_cast<CorrFitHDFunc1D*>(fHDMaps)->GetDenominatorHD()[bin0 + i];
244 val += n_temp * static_cast<CorrFitHDFunc1D*>(fHDMaps)->GetCFMapHD()[bin0 + i];
245 }
246 return val * static_cast<CorrFitHDFunc1D*>(fHDMaps)->GetDenominatorSum()[fBinX];
247 }
248 return CalculateCF(x, params);
249 }
250
251 Double_t CorrFit1DCF::EvalCFNormalized(const Double_t* x, const Double_t* params) const {
252 Double_t val = EvalCF(x, params);
253 return val / params[NormID()];
254 }
255
257 CorrFitHDFunc1D* cf = static_cast<CorrFitHDFunc1D*>(fHDMaps);
258 Double_t X[1];
259 for (int i = 0; i < cf->GetBinsHD().GetSize(); i++) {
260 Int_t hdBin = cf->GetBinsHD()[i];
261 X[0] = cf->EvalHD(hdBin);
262 fBinX = cf->HDBinToBin(hdBin);
263 Double_t p = CalculateCF(X, fTempParamsEval);
264 cf->GetCFMapHD()[hdBin] = p;
265 }
266 }
267
269 const CorrFitMask1D* mask = dynamic_cast<const CorrFitMask1D*>(&map);
270 if (mask == nullptr) return;
271 if (!mask->AreCompatible(fCF)) return;
272 if (fMask) delete fMask;
273 fMask = (CorrFitMask*) mask->Clone();
274 fOwnRangeMap = kTRUE;
275 }
276} // namespace Hal
T Get(Int_t i) const
Definition Array.h:97
Int_t LambdaID() const
virtual Double_t Eval(Double_t q) const
virtual void Fit(TObject *histo)
Int_t RadiusID() const
virtual Double_t CalculateCF(const Double_t *, const Double_t *) const
Definition CorrFit1DCF.h:93
CorrFit1DCF(Int_t parameters=3)
Double_t GetFunDrawable(Double_t *x, Double_t *params) const
Double_t EvalCFNormalized(const Double_t *x, const Double_t *params) const
void SetFittingMask(const CorrFitMask &map)
Double_t EvalCF(const Double_t *x, const Double_t *params) const
void RecalculateSmoothFunction() const
virtual void MakePainter(TString opt)
virtual TF1 * GetFunctionForDrawing() const
void SetErrors(TH1 *num, const TH1 *den) const
double GetLogTFD(const double *par) const
virtual void CalculateNumErrors(TH1 *)
Definition CorrFit1DCF.h:50
TH1 * fDenominatorHistogram
CorrFitPainter * fPainter
TH1 * fCorrelationFunctionHistogram
Int_t NormID() const
CorrFitHDFunc * fHDMaps
Femto::EKinematics fKinematics
Definition CorrFitFunc.h:69
virtual void Prepare()
Double_t fActiveBins
Definition CorrFitFunc.h:93
virtual void Fit(TObject *histo)
CorrFitMask * fMask
TH1 * fNumeratorHistogram
Array_1< Double_t > fRange
Definition CorrFitFunc.h:97
Int_t GetBin(Int_t no) const
Double_t EvalHD(Double_t hdBin) const
Double_t GetBinCFVal(Int_t bin, Bool_t extrapolated) const
virtual void SetMask(const CorrFitMask &mask, TH1 *denominator, Bool_t hd)=0
Int_t HDBinToBin(Int_t hd_bin) const
Width_t GetLineWidth() const
Definition CorrFit.h:137
Int_t fNDF
Definition CorrFit.h:95
Int_t GetParametersNo() const
Definition CorrFit.h:269
Double_t fThreshold
Definition CorrFit.h:99
ECalcOption fBinCalc
Definition CorrFit.h:87
TString GetParameterName(Int_t no) const
Definition CorrFit.h:280
Double_t GetParameter(Int_t par) const
Definition CorrFit.cxx:141
Double_t * fTempParamsEval
Definition CorrFit.h:109
Style_t GetLineStyle() const
Definition CorrFit.h:132
Color_t GetLineColor() const
Definition CorrFit.h:127
void SetParameterName(Int_t par, TString name)
Definition CorrFit.cxx:110
std::vector< FitParam > fParameters
Definition CorrFit.h:103
@ kExtrapolated
Definition CorrFit.h:79
virtual void SetOption(TString option)
Definition Painter.cxx:124