]>
Commit | Line | Data |
---|---|---|
d03e5de4 | 1 | /************************************************************************** |
2 | * Author: Panos Christakoglou. * | |
3 | * Contributors are mentioned in the code where appropriate. * | |
4 | * * | |
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 | **************************************************************************/ | |
13 | //------------------------------------------------------------------------- | |
14 | // Description: | |
15 | // This class include into LRC library for Long-Range Correlation analysis | |
16 | // it is base class for NN, PtN, PtPt | |
17 | // implements base methods for thees classes | |
18 | // Origin: Petr Naumenko, SPbSU-CERN, Petr.Naoumenko@cern.ch | |
19 | //------------------------------------------------------------------------- | |
20 | ||
21 | /* $Id$ */ | |
22 | ||
23 | //------------------------------------------------------------------------- | |
24 | // LRC library for Long-Range Correlation analysis | |
25 | // | |
26 | // Origin: Petr Naumenko, SPbSU-CERN, Petr.Naoumenko@cern.ch | |
27 | //------------------------------------------------------------------------- | |
28 | ||
29 | #include "AliLRCAnalysis.h" | |
30 | ||
31 | ClassImp(AliLRCAnalysis) | |
32 | ||
33 | /****************************************************** | |
34 | * AliLRCAnalysis class | |
35 | ******************************************************/ | |
36 | ||
d96e5666 | 37 | AliLRCAnalysis::AliLRCAnalysis(): fPrAbs(new TH1D()), fPrRel(new TH1D()), fPrf(new TH1D()), fPrb(new TH1D()), fileHist(new TFile()), fdptb(.0), fEntries(0), fSx((char*)" "), fSy((char*)" "), fxFitMin(.0), fxFitMax(.0), fa_rel(.0), fb_rel(.0), fXi2_rel(.0), fa_abs(.0), fb_abs(.0), fXi2_abs(.0){ |
d03e5de4 | 38 | //Empty constructor |
39 | } | |
40 | ||
d96e5666 | 41 | AliLRCAnalysis::AliLRCAnalysis(const AliLRCAnalysis& a):fPrAbs(a.fPrAbs), fPrRel(a.fPrRel), fPrf(a.fPrf), fPrb(a.fPrb), fileHist(a.fileHist), fdptb(a.fdptb), fEntries(a.fEntries), fSx(a.fSx), fSy(a.fSy), fxFitMin(a.fxFitMin), fxFitMax(a.fxFitMax), fa_rel(a.fa_rel), fb_rel(a.fb_rel), fXi2_rel(a.fXi2_rel), fa_abs(a.fa_abs), fb_abs(a.fb_abs), fXi2_abs(a.fXi2_abs){ |
d03e5de4 | 42 | //Constructor |
43 | } | |
44 | ||
45 | AliLRCAnalysis& AliLRCAnalysis::operator= (const AliLRCAnalysis& a){ | |
46 | //Operator = | |
47 | if(this!=&a){ | |
48 | fPrAbs = a.fPrAbs; | |
49 | fPrRel = a.fPrRel; | |
50 | fPrf = a.fPrf; | |
51 | fPrb = a.fPrb; | |
52 | fileHist = a.fileHist; | |
53 | fSx = a.fSx; | |
54 | fSy = a.fSy; | |
55 | fdptb = a.fdptb; | |
56 | fEntries = a.fEntries; | |
d96e5666 | 57 | fxFitMin = a.fxFitMin; |
58 | fxFitMax = a.fxFitMax; | |
59 | fa_rel = a.fa_rel; | |
60 | fb_rel = a.fb_rel; | |
61 | fXi2_rel = a.fXi2_rel; | |
62 | fa_abs = a.fa_abs; | |
63 | fb_abs = a.fb_abs; | |
64 | fXi2_abs = a.fXi2_abs; | |
d03e5de4 | 65 | } |
66 | return *this; | |
67 | } | |
68 | ||
69 | ||
70 | AliLRCAnalysis::~AliLRCAnalysis() { | |
71 | //Destructor | |
72 | delete fPrAbs; | |
73 | delete fPrRel; | |
74 | delete fileHist; | |
75 | } | |
76 | ||
77 | double AliLRCAnalysis::HI2(TH1D *h, double a, double b, double xmin, double xmax) const { | |
78 | //hi square calculation of approximation 1d hist with ax+b between xmin and xmax | |
79 | double trueN = 0; | |
80 | double fhi2=0; | |
81 | double num; | |
82 | double fN=h->GetNbinsX(); | |
83 | double f = h->GetXaxis()->GetXmin(); | |
84 | double fdf = (h->GetXaxis()->GetXmax()-f)/fN; | |
85 | int fNmin = int((xmin-f)/fdf)+1; | |
86 | int fNmax = int((xmax-f)/fdf)+1; | |
87 | for(int i=fNmin; i<=fNmax; i++) { | |
88 | double fw = h->GetBinError(i); | |
89 | if(fw!=0){ | |
90 | num = b*(i*fdf-fdf/2+f)+a-h->GetBinContent(i); | |
91 | fhi2 = fhi2 + (num*num) / (fw*fw); | |
92 | trueN++; | |
93 | } | |
94 | } | |
95 | return fhi2/(trueN-2); | |
96 | } | |
97 | ||
98 | double AliLRCAnalysis::HI2(TH1D *h, double a, double b) const { | |
99 | //hi square calculation of approximation 1d hist with ax+b | |
100 | double trueN = 0; | |
101 | double fhi2=0; | |
102 | double num; | |
103 | int fN=h->GetNbinsX(); | |
104 | double f = h->GetXaxis()->GetXmin(); | |
105 | double fdf = (h->GetXaxis()->GetXmax()-f)/fN; | |
106 | int fNmin = 1; | |
107 | int fNmax = fN; | |
108 | for(int i=fNmin; i<=fNmax; i++) { | |
109 | double fw = h->GetBinError(i); | |
110 | if(fw!=0){ | |
111 | num = b*(i*fdf-fdf/2+f)+a-h->GetBinContent(i); | |
112 | fhi2 = fhi2 + (num*num) / (fw*fw); | |
113 | trueN++; | |
114 | } | |
115 | } | |
116 | return fhi2/(trueN-2); | |
117 | } | |
118 | ||
119 | ||
120 | void AliLRCAnalysis::CreateHist(char *name, char *nameAbs, char *nameRel, char *atitleF, char *atitleB, char *rtitleF, char *rtitleB, TH2D* sourceHist) { | |
121 | //Create absolute and relation var histogramm | |
122 | TProfile* profX = (TProfile*) sourceHist->ProfileX(name, 1, sourceHist->GetNbinsY()); | |
123 | fEntries = (int) sourceHist->GetEntries(); | |
124 | fPrAbs = new TH1D(nameAbs, profX->GetTitle(), profX->GetXaxis()->GetNbins(), profX->GetXaxis()->GetXmin(), profX->GetXaxis()->GetXmax()); | |
125 | fPrAbs->SetOption("E"); | |
126 | fPrRel = new TH1D(nameRel, profX->GetTitle(), profX->GetXaxis()->GetNbins(), profX->GetXaxis()->GetXmin()/sourceHist->ProjectionX()->GetMean(), profX->GetXaxis()->GetXmax()/sourceHist->ProjectionX()->GetMean()); | |
127 | fPrRel->SetOption("E"); | |
128 | fPrAbs->GetXaxis()->SetTitle(atitleF); | |
129 | fPrAbs->GetYaxis()->SetTitle(atitleB); | |
130 | fPrRel->GetXaxis()->SetTitle(rtitleF); | |
131 | fPrRel->GetYaxis()->SetTitle(rtitleB); | |
132 | fPrf = (TH1D*) sourceHist->ProjectionX(); | |
133 | fPrb = (TH1D*) sourceHist->ProjectionY(); | |
134 | fPrf->GetXaxis()->SetTitle(atitleF); | |
135 | fPrf->GetYaxis()->SetTitle("Tracks"); | |
136 | fPrb->GetXaxis()->SetTitle(atitleB); | |
137 | fPrb->GetYaxis()->SetTitle("Tracks"); | |
138 | fSx = atitleF; | |
139 | fSy = atitleB; | |
d96e5666 | 140 | double mnf = fPrf->GetMean(); |
141 | fxFitMin = mnf-2*sqrt(mnf); | |
142 | fxFitMax = mnf+2*sqrt(mnf); | |
143 | ||
144 | } | |
145 | ||
146 | void AliLRCAnalysis::SetBinsRange(int binMin, int binMax){ | |
147 | TH1D* h=fPrf; | |
148 | double N=h->GetNbinsX(); | |
149 | fxFitMin = h->GetXaxis()->GetXmin(); | |
150 | fxFitMax = h->GetXaxis()->GetXmax(); | |
151 | double df = (fxFitMax-fxFitMin)/N; | |
152 | for(int i=1; i<=N; i++) | |
153 | if(h->GetBinContent(i) != 0){ | |
154 | fxFitMin += (i + binMin) * df; | |
155 | break; | |
156 | } | |
157 | for(int i=1; i<=N; i++) | |
158 | if(h->GetBinContent(N-i) != 0){ | |
159 | fxFitMax -= (i + binMax) * df; | |
160 | break; | |
161 | } | |
162 | } | |
163 | ||
164 | bool AliLRCAnalysis::SetFitRange(double xMin, double xMax){ | |
165 | //������������� ������� �������������. ���������� false, ���� xMin ������ xMax. ��������� �� ���������� �� ����, � ���� � ���� ��� �����.(( | |
166 | if(xMax < xMin){ | |
167 | return false; | |
168 | } | |
169 | this->fxFitMin = xMin; | |
170 | this->fxFitMax = xMax; | |
171 | return true; | |
172 | } | |
173 | ||
174 | void AliLRCAnalysis::SetXmin(double xMin){ | |
175 | fxFitMin = xMin; | |
176 | } | |
177 | ||
178 | void AliLRCAnalysis::SetXmax(double xMax){ | |
179 | fxFitMax = xMax; | |
180 | } | |
181 | ||
182 | double AliLRCAnalysis::GetArel(){ | |
183 | return fa_rel; | |
184 | } | |
185 | ||
186 | double AliLRCAnalysis::GetBrel(){ | |
187 | return fb_rel; | |
188 | } | |
189 | ||
190 | double AliLRCAnalysis::GetXi2rel(){ | |
191 | return fXi2_rel; | |
192 | } | |
193 | ||
194 | double AliLRCAnalysis::GetAabs(){ | |
195 | return fa_abs; | |
196 | } | |
197 | ||
198 | double AliLRCAnalysis::GetBabs(){ | |
199 | return fb_abs; | |
200 | } | |
201 | ||
202 | double AliLRCAnalysis::GetXi2abs(){ | |
203 | return fXi2_abs; | |
204 | } | |
205 | ||
206 | void AliLRCAnalysis::Calculate(){ | |
207 | double mnf; | |
208 | fPrAbs->SetStats(0); | |
209 | fPrAbs->Fit("pol1", "0", "", fxFitMin, fxFitMax); | |
210 | TF1 *fitt1 = fPrAbs->GetFunction("pol1"); | |
211 | fa_abs = fitt1->GetParameter(0); | |
212 | fb_abs = fitt1->GetParameter(1); | |
213 | fXi2_abs = HI2(fPrAbs, fitt1->GetParameter(0), fitt1->GetParameter(1), fxFitMin, fxFitMax); | |
214 | ||
215 | mnf = fPrf->GetMean(); | |
216 | fPrRel->SetStats(0); | |
217 | AliLRCFit *fit1 = new AliLRCFit(fPrRel, fxFitMin/mnf, fxFitMax/mnf); | |
218 | TF1 *f1 = new TF1("f1", "[0] + [1]*x", 0, fPrRel->GetXaxis()->GetXmax()); | |
219 | f1->SetParameter(0,fit1->Geta()); | |
220 | f1->SetParameter(1,fit1->Getb()); | |
221 | fPrRel->Fit("f1", "0", "", fxFitMin/mnf, fxFitMax/mnf); | |
222 | fa_rel = fit1->Geta(); | |
223 | fb_rel = fit1->Getb(); | |
224 | fXi2_rel = fit1->Gethi2(); | |
d03e5de4 | 225 | } |
226 | ||
227 | void AliLRCAnalysis::DrawAbs() { | |
228 | // Draw abs var histrogramm | |
d96e5666 | 229 | //double mnf; |
d03e5de4 | 230 | double y1, y2, x1, x2; |
231 | Int_t i, n; | |
232 | char str[50]; | |
d96e5666 | 233 | //mnf = fPrf->GetMean(); |
d03e5de4 | 234 | fPrAbs->SetStats(0); |
d96e5666 | 235 | fPrAbs->Fit("pol1", "", "", fxFitMin, fxFitMax); |
d03e5de4 | 236 | //fPrAbs->Fit("pol1"); |
237 | TF1 *fit1 = fPrAbs->GetFunction("pol1"); | |
238 | y1=fPrAbs->GetBinContent(1)-fPrAbs->GetBinError(1); | |
239 | y2=fPrAbs->GetBinContent(1)+fPrAbs->GetBinError(1); | |
240 | ||
241 | n=fPrAbs->GetNbinsX(); | |
242 | for(i=2; i<=n; i++){ | |
243 | if(fPrAbs->GetBinContent(i)-fPrAbs->GetBinError(i)<y1) | |
244 | y1=fPrAbs->GetBinContent(i)-fPrAbs->GetBinError(i); | |
245 | if(fPrAbs->GetBinContent(i)+fPrAbs->GetBinError(i)>y2) | |
246 | y2=fPrAbs->GetBinContent(i)+fPrAbs->GetBinError(i); | |
247 | } | |
248 | x1 = fPrAbs->GetXaxis()->GetXmin(); | |
249 | x2 = fPrAbs->GetXaxis()->GetXmax(); | |
250 | TPaveText *pt1 = new TPaveText(x1+(x2-x1)/4, y1+(y2-y1)/2, x2-(x2-x1)/4, y2); | |
251 | pt1->SetTextSize(0.03); | |
252 | ||
253 | sprintf(str, "Entries = %i", fEntries); | |
254 | pt1->AddText(str); | |
255 | sprintf(str, "a = %f #pm %f", fit1->GetParameter(0), fit1->GetParError(0)); | |
256 | pt1->AddText(str); | |
257 | sprintf(str, "b = %f #pm %f", fit1->GetParameter(1), fit1->GetParError(1)); | |
258 | pt1->AddText(str); | |
d96e5666 | 259 | sprintf(str, "#hat{#chi}^{2} = #chi^{2}/(n-2) = %f", HI2(fPrAbs, fit1->GetParameter(0), fit1->GetParameter(1), fxFitMin, fxFitMax)); |
d03e5de4 | 260 | pt1->AddText(str); |
261 | sprintf(str, "<%s> = %f " , fSx, fPrf->GetMean()); | |
262 | pt1->AddText(str); | |
263 | sprintf(str, "<%s> = %f", fSy, fPrb->GetMean()); | |
264 | pt1->AddText(str); | |
265 | ||
266 | sprintf(str, "<<%s>> = %f " , fSx, fPrf->GetRMS()); | |
267 | pt1->AddText(str); | |
268 | sprintf(str, "<<%s>> = %f", fSy, fPrb->GetRMS()); | |
269 | pt1->AddText(str); | |
270 | if(fdptb){ | |
271 | sprintf(str, "d%s = %f", fSy, fdptb); | |
272 | pt1->AddText(str); | |
273 | } | |
274 | ||
275 | ||
276 | pt1->SetTextAlign(12); | |
277 | pt1->SetTextFont(42); | |
278 | pt1->SetFillColor(0); | |
d96e5666 | 279 | fPrAbs->DrawCopy(); |
280 | pt1->DrawClone(); | |
d03e5de4 | 281 | } |
282 | ||
283 | void AliLRCAnalysis::DrawRel() { | |
284 | // Draw rel var histogramm | |
285 | double mnf; | |
286 | double y1, y2, x1, x2; | |
287 | Int_t i, n; | |
288 | char str[50]; | |
289 | ||
290 | mnf = fPrf->GetMean(); | |
291 | ||
292 | fPrRel->SetStats(0); | |
d96e5666 | 293 | AliLRCFit *fit1 = new AliLRCFit(fPrRel, fxFitMin/mnf, fxFitMax/mnf); |
d03e5de4 | 294 | TF1 *f1 = new TF1("f1", "[0] + [1]*x", 0, fPrRel->GetXaxis()->GetXmax()); |
295 | f1->SetParameter(0,fit1->Geta()); | |
296 | f1->SetParameter(1,fit1->Getb()); | |
d96e5666 | 297 | fPrRel->Fit("f1", "", "", fxFitMin/mnf, fxFitMax/mnf); |
d03e5de4 | 298 | y1=fPrRel->GetBinContent(1)-fPrRel->GetBinError(1); |
299 | y2=fPrRel->GetBinContent(1)+fPrRel->GetBinError(1); | |
300 | n=fPrRel->GetNbinsX(); | |
301 | for(i=2; i<=n; i++) { | |
302 | if(fPrRel->GetBinContent(i)-fPrRel->GetBinError(i)<y1) | |
303 | y1=fPrRel->GetBinContent(i)-fPrRel->GetBinError(i); | |
304 | if(fPrRel->GetBinContent(i)+fPrRel->GetBinError(i)>y2) | |
305 | y2=fPrRel->GetBinContent(i)+fPrRel->GetBinError(i); | |
306 | } | |
307 | x1 = fPrRel->GetXaxis()->GetXmin(); | |
308 | x2 = fPrRel->GetXaxis()->GetXmax(); | |
309 | TPaveText *pt1 = new TPaveText(x1+(x2-x1)/4, y1+(y2-y1)/2, x2-(x2-x1)/4, y2); | |
310 | pt1->SetTextSize(0.03); | |
311 | sprintf(str, "Entries = %i", fEntries); | |
312 | pt1->AddText(str); | |
313 | sprintf(str, "a = %f #pm %f", fit1->Geta(), fit1->Getda()); | |
314 | pt1->AddText(str); | |
315 | sprintf(str, "b = %f #pm %f", fit1->Getb(), fit1->Getdb()); | |
316 | pt1->AddText(str); | |
317 | sprintf(str, "#hat{#chi}^{2} = #chi^{2}/(n-2) = %f", fit1->Gethi2()); | |
318 | pt1->AddText(str); | |
319 | sprintf(str, "<%s> = %f " , fSx, fPrf->GetMean()); | |
320 | pt1->AddText(str); | |
321 | sprintf(str, "<%s> = %f", fSy, fPrb->GetMean()); | |
322 | pt1->AddText(str); | |
323 | sprintf(str, "<<%s>> = %f " , fSx, fPrf->GetRMS()); | |
324 | pt1->AddText(str); | |
325 | sprintf(str, "<<%s>> = %f", fSy, fPrb->GetRMS()); | |
326 | pt1->AddText(str); | |
327 | if(fdptb){ | |
328 | sprintf(str, "d%s = %f", fSy, fdptb); | |
329 | pt1->AddText(str); | |
330 | } | |
331 | pt1->SetTextAlign(12); | |
332 | pt1->SetTextFont(42); | |
333 | pt1->SetFillColor(0); | |
d96e5666 | 334 | fPrRel->DrawCopy(); |
335 | pt1->DrawClone(); | |
d03e5de4 | 336 | } |
337 | ||
338 | void AliLRCAnalysis::SetGraphics() const { | |
339 | // Set root graph style | |
340 | gStyle->SetCanvasColor(10); | |
341 | gStyle->SetFrameFillColor(10); | |
342 | gStyle->SetStatColor(0); | |
343 | gStyle->SetPadColor(0); | |
344 | } | |
345 | ||
346 | double AliLRCAnalysis::Integral(TH2D* source, Int_t nbin) const { | |
347 | // calculate the integrall for x bin and y bins of 2d histogramm | |
348 | double sum = 0; | |
349 | for(Int_t i = 1; i<=source->GetNbinsY(); i++) { | |
350 | sum += source->GetYaxis()->GetBinCenter(i)*source->GetBinContent(nbin, i); | |
351 | } | |
352 | return sum; | |
353 | } | |
354 | ||
355 | void AliLRCAnalysis::SetErrors(TH2D* source, const char *name){ | |
356 | // Calculate errors for NN | |
357 | TProfile* profX = (TProfile*) source->ProfileX(name, 1, source->GetNbinsY()); | |
358 | for(int i = 0; i < profX->GetNbinsX(); i++) | |
359 | { | |
360 | fPrAbs->SetBinContent(i, profX->GetBinContent(i)); | |
361 | if(fPrf->GetBinContent(i)!=0) | |
362 | { | |
363 | fPrAbs->SetBinError(i,sqrt(profX->GetBinContent(i)/fPrf->GetBinContent(i))); | |
364 | } | |
365 | fPrRel->SetBinContent(i, fPrAbs->GetBinContent(i)/fPrb->GetMean()); | |
366 | fPrRel->SetBinError(i,fPrAbs->GetBinError(i)/fPrb->GetMean()); | |
367 | } | |
368 | } | |
369 | ||
370 | void AliLRCAnalysis::SetErrors(TH2D* source, const char *name, double ptd, TH2D* nb){ | |
371 | //Calculate arrors for ptn and ptpt | |
372 | TProfile* profX = (TProfile*) source->ProfileX(name, 1, source->GetNbinsY()); | |
373 | fdptb = ptd; | |
374 | double pt; | |
375 | for(int i = 0; i < profX->GetNbinsX(); i++) | |
376 | { | |
377 | fPrAbs->SetBinContent(i, profX->GetBinContent(i)); | |
378 | if(fPrf->GetBinContent(i)!=0) | |
379 | { | |
380 | pt = profX->GetBinContent(i); | |
381 | fPrAbs->SetBinError(i,ptd*sqrt(Integral(nb,i))/fPrf->GetBinContent(i)); | |
382 | } | |
383 | fPrRel->SetBinContent(i, fPrAbs->GetBinContent(i)/fPrb->GetMean()); | |
384 | fPrRel->SetBinError(i,fPrAbs->GetBinError(i)/fPrb->GetMean()); | |
385 | } | |
386 | ||
387 | } | |
388 | ||
d96e5666 | 389 | void AliLRCAnalysis::SetErrors(TH2D* source, const char *name, double ptd, TProfile* nb){ |
390 | //Calculate arrors for ptn and ptpt | |
391 | TProfile* profX = (TProfile*) source->ProfileX(name, 1, source->GetNbinsY()); | |
392 | fdptb = ptd; | |
393 | double pt; | |
394 | for(int i = 0; i < profX->GetNbinsX(); i++) | |
395 | { | |
396 | fPrAbs->SetBinContent(i, profX->GetBinContent(i)); | |
397 | if(fPrf->GetBinContent(i)!=0) | |
398 | { | |
399 | pt = profX->GetBinContent(i); | |
400 | fPrAbs->SetBinError(i,ptd*sqrt(nb->GetBinContent(i)/fPrf->GetBinContent(i))); | |
401 | } | |
402 | fPrRel->SetBinContent(i, fPrAbs->GetBinContent(i)/fPrb->GetMean()); | |
403 | fPrRel->SetBinError(i,fPrAbs->GetBinError(i)/fPrb->GetMean()); | |
404 | } | |
405 | ||
406 | } | |
407 | ||
d03e5de4 | 408 |