]>
Commit | Line | Data |
---|---|---|
fabf4d8e | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | ///////////////////////////////////////////////////////////// | |
17 | // | |
18 | // AliHFMassFitter for the fit of invariant mass distribution | |
19 | // of charmed mesons | |
20 | // | |
21 | // Author: C.Bianchin, chiara.bianchin@pd.infn.it | |
22 | ///////////////////////////////////////////////////////////// | |
23 | ||
24 | #include <TCanvas.h> | |
25 | ||
26 | #include "AliHFMassFitter.h" | |
27 | ||
28 | ||
29 | ClassImp(AliHFMassFitter) | |
30 | ||
56cbeefb | 31 | //************** constructors |
2f328d65 | 32 | AliHFMassFitter::AliHFMassFitter() : |
33 | TNamed(), | |
fabf4d8e | 34 | fhistoInvMass(0), |
35 | fminMass(0), | |
36 | fmaxMass(0), | |
37 | fNbin(1), | |
2f328d65 | 38 | fParsSize(1), |
39 | fFitPars(0), | |
fabf4d8e | 40 | fWithBkg(0), |
41 | ftypeOfFit4Bkg(0), | |
42 | ftypeOfFit4Sgn(0), | |
43 | ffactor(1), | |
44 | fntuParam(0), | |
45 | fMass(1.85), | |
46 | fSigmaSgn(0.012), | |
56cbeefb | 47 | fSideBands(0), |
48 | fcounter(0) | |
fabf4d8e | 49 | { |
50 | // default constructor | |
51 | ||
52 | cout<<"Default constructor"<<endl; | |
53 | } | |
54 | ||
55 | //___________________________________________________________________________ | |
56 | ||
57 | AliHFMassFitter::AliHFMassFitter (TH1F *histoToFit, Double_t minvalue, Double_t maxvalue, Int_t rebin,Int_t fittypeb,Int_t fittypes): | |
58 | TNamed(), | |
59 | fhistoInvMass(0), | |
60 | fminMass(0), | |
61 | fmaxMass(0), | |
62 | fNbin(1), | |
2f328d65 | 63 | fParsSize(1), |
64 | fFitPars(0), | |
fabf4d8e | 65 | fWithBkg(0), |
66 | ftypeOfFit4Bkg(0), | |
67 | ftypeOfFit4Sgn(0), | |
68 | ffactor(1), | |
69 | fntuParam(0), | |
70 | fMass(1.85), | |
71 | fSigmaSgn(0.012), | |
56cbeefb | 72 | fSideBands(0), |
73 | fcounter(0) | |
fabf4d8e | 74 | { |
75 | // standard constructor | |
76 | ||
56cbeefb | 77 | fhistoInvMass= (TH1F*)histoToFit->Clone("fhistoInvMass"); |
fabf4d8e | 78 | fminMass=minvalue; |
79 | fmaxMass=maxvalue; | |
80 | if(rebin!=1) RebinMass(rebin); | |
81 | else fNbin=(Int_t)fhistoInvMass->GetNbinsX(); | |
82 | ftypeOfFit4Bkg=fittypeb; | |
83 | ftypeOfFit4Sgn=fittypes; | |
84 | if(ftypeOfFit4Bkg!=0 && ftypeOfFit4Bkg!=1 && ftypeOfFit4Bkg!=2) fWithBkg=kFALSE; | |
85 | else fWithBkg=kTRUE; | |
86 | if (!fWithBkg) cout<<"Fit Histogram of Signal only"<<endl; | |
87 | else cout<<"Type of fit For Background = "<<ftypeOfFit4Bkg<<endl; | |
2f328d65 | 88 | |
89 | ComputeParSize(); | |
90 | fFitPars=new Float_t[fParsSize]; | |
fabf4d8e | 91 | } |
92 | ||
74179930 | 93 | |
94 | AliHFMassFitter::AliHFMassFitter(const AliHFMassFitter &mfit): | |
95 | TNamed(), | |
96 | fhistoInvMass(mfit.fhistoInvMass), | |
97 | fminMass(mfit.fminMass), | |
98 | fmaxMass(mfit.fmaxMass), | |
99 | fNbin(mfit.fNbin), | |
2f328d65 | 100 | fParsSize(mfit.fParsSize), |
101 | fFitPars(0), | |
74179930 | 102 | fWithBkg(mfit.fWithBkg), |
103 | ftypeOfFit4Bkg(mfit.ftypeOfFit4Bkg), | |
104 | ftypeOfFit4Sgn(mfit.ftypeOfFit4Sgn), | |
105 | ffactor(mfit.ffactor), | |
106 | fntuParam(mfit.fntuParam), | |
107 | fMass(mfit.fMass), | |
108 | fSigmaSgn(mfit.fSigmaSgn), | |
56cbeefb | 109 | fSideBands(mfit.fSideBands), |
110 | fcounter(mfit.fcounter) | |
74179930 | 111 | |
112 | { | |
113 | //copy constructor | |
2f328d65 | 114 | |
115 | if(mfit.fParsSize > 0){ | |
116 | fFitPars=new Float_t[fParsSize]; | |
117 | memcpy(fFitPars,mfit.fFitPars,mfit.fParsSize*sizeof(Float_t)); | |
118 | } | |
119 | //for(Int_t i=0;i<fParsSize;i++) fFitPars[i]=mfit.fFitPars[i]; | |
120 | } | |
121 | ||
122 | //_________________________________________________________________________ | |
123 | ||
124 | AliHFMassFitter::~AliHFMassFitter() { | |
56cbeefb | 125 | cout<<"AliHFMassFitter destructor called"<<endl; |
2f328d65 | 126 | if(fhistoInvMass) delete fhistoInvMass; |
127 | if(fntuParam) delete fntuParam; | |
128 | if(fFitPars) delete[] fFitPars; | |
56cbeefb | 129 | fcounter = 0; |
74179930 | 130 | } |
131 | ||
132 | //_________________________________________________________________________ | |
133 | ||
134 | AliHFMassFitter& AliHFMassFitter::operator=(const AliHFMassFitter &mfit){ | |
135 | ||
136 | //assignment operator | |
137 | ||
138 | if(&mfit == this) return *this; | |
139 | fhistoInvMass= mfit.fhistoInvMass; | |
140 | fminMass= mfit.fminMass; | |
141 | fmaxMass= mfit.fmaxMass; | |
142 | fNbin= mfit.fNbin; | |
2f328d65 | 143 | fParsSize= mfit.fParsSize; |
74179930 | 144 | fWithBkg= mfit.fWithBkg; |
145 | ftypeOfFit4Bkg= mfit.ftypeOfFit4Bkg; | |
146 | ftypeOfFit4Sgn= mfit.ftypeOfFit4Sgn; | |
147 | ffactor= mfit.ffactor; | |
148 | fntuParam= mfit.fntuParam; | |
149 | fMass= mfit.fMass; | |
150 | fSigmaSgn= mfit.fSigmaSgn; | |
151 | fSideBands= mfit.fSideBands; | |
56cbeefb | 152 | fcounter= mfit.fcounter; |
2f328d65 | 153 | if(mfit.fParsSize > 0){ |
154 | if(fFitPars) delete[] fFitPars; | |
155 | fFitPars=new Float_t[fParsSize]; | |
156 | memcpy(fFitPars,mfit.fFitPars,mfit.fParsSize*sizeof(Float_t)); | |
157 | } | |
158 | // fFitPars=new Float_t[fParsSize]; | |
159 | // for(Int_t i=0;i<fParsSize;i++) fFitPars[i]=mfit.fFitPars[i]; | |
74179930 | 160 | |
161 | return *this; | |
162 | } | |
56cbeefb | 163 | |
164 | //************ tools & settings | |
165 | ||
2f328d65 | 166 | //__________________________________________________________________________ |
167 | ||
168 | void AliHFMassFitter::ComputeParSize() { | |
169 | switch (ftypeOfFit4Bkg) {//npar backround func | |
170 | case 0: | |
171 | fParsSize = 2*3; | |
172 | break; | |
173 | case 1: | |
174 | fParsSize = 2*3; | |
175 | break; | |
176 | case 2: | |
177 | fParsSize = 3*3; | |
178 | break; | |
179 | case 3: | |
56cbeefb | 180 | fParsSize = 1*3; |
2f328d65 | 181 | break; |
182 | default: | |
56cbeefb | 183 | cout<<"Error in computing fParsSize: check ftypeOfFit4Bkg"<<endl; |
2f328d65 | 184 | break; |
185 | } | |
186 | ||
56cbeefb | 187 | fParsSize += 3; // npar refl |
188 | fParsSize += 3; // npar signal gaus | |
2f328d65 | 189 | |
56cbeefb | 190 | fParsSize*=2; // add errors |
2f328d65 | 191 | cout<<"Parameters array size "<<fParsSize<<endl; |
192 | } | |
193 | ||
56cbeefb | 194 | //___________________________________________________________________________ |
195 | void AliHFMassFitter::SetHisto(TH1F *histoToFit){ | |
196 | fhistoInvMass = (TH1F*)histoToFit->Clone(); | |
197 | } | |
198 | ||
2f328d65 | 199 | //___________________________________________________________________________ |
200 | ||
201 | void AliHFMassFitter::SetType(Int_t fittypeb, Int_t fittypes) { | |
202 | ftypeOfFit4Bkg = fittypeb; | |
203 | ftypeOfFit4Sgn = fittypes; | |
204 | ComputeParSize(); | |
205 | fFitPars = new Float_t[fParsSize]; | |
206 | ||
207 | } | |
74179930 | 208 | |
fabf4d8e | 209 | //___________________________________________________________________________ |
210 | ||
56cbeefb | 211 | void AliHFMassFitter::Reset() { |
212 | delete fhistoInvMass; | |
213 | } | |
214 | ||
215 | //_________________________________________________________________________ | |
216 | ||
217 | void AliHFMassFitter::InitNtuParam(char *ntuname) { | |
218 | // Create ntuple to keep fit parameters | |
219 | fntuParam=0; | |
220 | fntuParam=new TNtuple(ntuname,"Contains fit parameters","intbkg1:slope1:conc1:intGB:meanGB:sigmaGB:intbkg2:slope2:conc2:inttot:slope3:conc3:intsgn:meansgn:sigmasgn:intbkg1Err:slope1Err:conc1Err:intGBErr:meanGBErr:sigmaGBErr:intbkg2Err:slope2Err:conc2Err:inttotErr:slope3Err:conc3Err:intsgnErr:meansgnErr:sigmasgnErr"); | |
221 | ||
222 | } | |
223 | ||
224 | //_________________________________________________________________________ | |
225 | ||
226 | void AliHFMassFitter::FillNtuParam() { | |
227 | // Fill ntuple with fit parameters | |
228 | ||
229 | Float_t nothing=0.; | |
230 | ||
231 | if (ftypeOfFit4Bkg==2) { | |
232 | fntuParam->SetBranchAddress("intbkg1",&fFitPars[0]); | |
233 | fntuParam->SetBranchAddress("slope1",&fFitPars[1]); | |
234 | fntuParam->SetBranchAddress("conc1",&fFitPars[2]); | |
235 | fntuParam->SetBranchAddress("intGB",&fFitPars[3]); | |
236 | fntuParam->SetBranchAddress("meanGB",&fFitPars[4]); | |
237 | fntuParam->SetBranchAddress("sigmaGB",&fFitPars[5]); | |
238 | fntuParam->SetBranchAddress("intbkg2",&fFitPars[6]); | |
239 | fntuParam->SetBranchAddress("slope2",&fFitPars[7]); | |
240 | fntuParam->SetBranchAddress("conc2",&fFitPars[8]); | |
241 | fntuParam->SetBranchAddress("inttot",&fFitPars[9]); | |
242 | fntuParam->SetBranchAddress("slope3",&fFitPars[10]); | |
243 | fntuParam->SetBranchAddress("conc3",&fFitPars[11]); | |
244 | fntuParam->SetBranchAddress("intsgn",&fFitPars[12]); | |
245 | fntuParam->SetBranchAddress("meansgn",&fFitPars[13]); | |
246 | fntuParam->SetBranchAddress("sigmasgn",&fFitPars[14]); | |
247 | ||
248 | fntuParam->SetBranchAddress("intbkg1Err",&fFitPars[15]); | |
249 | fntuParam->SetBranchAddress("slope1Err",&fFitPars[16]); | |
250 | fntuParam->SetBranchAddress("conc1Err",&fFitPars[17]); | |
251 | fntuParam->SetBranchAddress("intGBErr",&fFitPars[18]); | |
252 | fntuParam->SetBranchAddress("meanGBErr",&fFitPars[19]); | |
253 | fntuParam->SetBranchAddress("sigmaGBErr",&fFitPars[20]); | |
254 | fntuParam->SetBranchAddress("intbkg2Err",&fFitPars[21]); | |
255 | fntuParam->SetBranchAddress("slope2Err",&fFitPars[22]); | |
256 | fntuParam->SetBranchAddress("conc2Err",&fFitPars[23]); | |
257 | fntuParam->SetBranchAddress("inttotErr",&fFitPars[24]); | |
258 | fntuParam->SetBranchAddress("slope3Err",&fFitPars[25]); | |
259 | fntuParam->SetBranchAddress("conc3Err",&fFitPars[26]); | |
260 | fntuParam->SetBranchAddress("intsgnErr",&fFitPars[27]); | |
261 | fntuParam->SetBranchAddress("meansgnErr",&fFitPars[28]); | |
262 | fntuParam->SetBranchAddress("sigmasgnErr",&fFitPars[29]); | |
263 | ||
264 | } else { | |
265 | ||
266 | if(ftypeOfFit4Bkg==3){ | |
267 | fntuParam->SetBranchAddress("intbkg1",&fFitPars[0]); | |
268 | fntuParam->SetBranchAddress("slope1",¬hing); | |
269 | fntuParam->SetBranchAddress("conc1",¬hing); | |
270 | fntuParam->SetBranchAddress("intGB",&fFitPars[1]); | |
271 | fntuParam->SetBranchAddress("meanGB",&fFitPars[2]); | |
272 | fntuParam->SetBranchAddress("sigmaGB",&fFitPars[3]); | |
273 | fntuParam->SetBranchAddress("intbkg2",&fFitPars[4]); | |
274 | fntuParam->SetBranchAddress("slope2",¬hing); | |
275 | fntuParam->SetBranchAddress("conc2",¬hing); | |
276 | fntuParam->SetBranchAddress("inttot",&fFitPars[6]); | |
277 | fntuParam->SetBranchAddress("slope3",¬hing); | |
278 | fntuParam->SetBranchAddress("conc3",¬hing); | |
279 | fntuParam->SetBranchAddress("intsgn",&fFitPars[6]); | |
280 | fntuParam->SetBranchAddress("meansgn",&fFitPars[7]); | |
281 | fntuParam->SetBranchAddress("sigmasgn",&fFitPars[8]); | |
282 | ||
283 | fntuParam->SetBranchAddress("intbkg1Err",&fFitPars[9]); | |
284 | fntuParam->SetBranchAddress("slope1Err",¬hing); | |
285 | fntuParam->SetBranchAddress("conc1Err",¬hing); | |
286 | fntuParam->SetBranchAddress("intGBErr",&fFitPars[10]); | |
287 | fntuParam->SetBranchAddress("meanGBErr",&fFitPars[11]); | |
288 | fntuParam->SetBranchAddress("sigmaGBErr",&fFitPars[12]); | |
289 | fntuParam->SetBranchAddress("intbkg2Err",&fFitPars[13]); | |
290 | fntuParam->SetBranchAddress("slope2Err",¬hing); | |
291 | fntuParam->SetBranchAddress("conc2Err",¬hing); | |
292 | fntuParam->SetBranchAddress("inttotErr",&fFitPars[15]); | |
293 | fntuParam->SetBranchAddress("slope3Err",¬hing); | |
294 | fntuParam->SetBranchAddress("conc3Err",¬hing); | |
295 | fntuParam->SetBranchAddress("intsgnErr",&fFitPars[15]); | |
296 | fntuParam->SetBranchAddress("meansgnErr",&fFitPars[16]); | |
297 | fntuParam->SetBranchAddress("sigmasgnErr",&fFitPars[17]); | |
298 | ||
299 | } | |
300 | else{ | |
301 | fntuParam->SetBranchAddress("intbkg1",&fFitPars[0]); | |
302 | fntuParam->SetBranchAddress("slope1",&fFitPars[1]); | |
303 | fntuParam->SetBranchAddress("conc1",¬hing); | |
304 | fntuParam->SetBranchAddress("intGB",&fFitPars[2]); | |
305 | fntuParam->SetBranchAddress("meanGB",&fFitPars[3]); | |
306 | fntuParam->SetBranchAddress("sigmaGB",&fFitPars[4]); | |
307 | fntuParam->SetBranchAddress("intbkg2",&fFitPars[5]); | |
308 | fntuParam->SetBranchAddress("slope2",&fFitPars[6]); | |
309 | fntuParam->SetBranchAddress("conc2",¬hing); | |
310 | fntuParam->SetBranchAddress("inttot",&fFitPars[7]); | |
311 | fntuParam->SetBranchAddress("slope3",&fFitPars[8]); | |
312 | fntuParam->SetBranchAddress("conc3",¬hing); | |
313 | fntuParam->SetBranchAddress("intsgn",&fFitPars[9]); | |
314 | fntuParam->SetBranchAddress("meansgn",&fFitPars[10]); | |
315 | fntuParam->SetBranchAddress("sigmasgn",&fFitPars[11]); | |
316 | ||
317 | fntuParam->SetBranchAddress("intbkg1Err",&fFitPars[12]); | |
318 | fntuParam->SetBranchAddress("slope1Err",&fFitPars[13]); | |
319 | fntuParam->SetBranchAddress("conc1Err",¬hing); | |
320 | fntuParam->SetBranchAddress("intGBErr",&fFitPars[14]); | |
321 | fntuParam->SetBranchAddress("meanGBErr",&fFitPars[15]); | |
322 | fntuParam->SetBranchAddress("sigmaGBErr",&fFitPars[16]); | |
323 | fntuParam->SetBranchAddress("intbkg2Err",&fFitPars[17]); | |
324 | fntuParam->SetBranchAddress("slope2Err",&fFitPars[18]); | |
325 | fntuParam->SetBranchAddress("conc2Err",¬hing); | |
326 | fntuParam->SetBranchAddress("inttotErr",&fFitPars[19]); | |
327 | fntuParam->SetBranchAddress("slope3Err",&fFitPars[20]); | |
328 | fntuParam->SetBranchAddress("conc3Err",¬hing); | |
329 | fntuParam->SetBranchAddress("intsgnErr",&fFitPars[21]); | |
330 | fntuParam->SetBranchAddress("meansgnErr",&fFitPars[22]); | |
331 | fntuParam->SetBranchAddress("sigmasgnErr",&fFitPars[23]); | |
332 | } | |
333 | ||
334 | } | |
335 | fntuParam->TTree::Fill(); | |
336 | } | |
337 | ||
338 | //_________________________________________________________________________ | |
339 | ||
340 | TNtuple* AliHFMassFitter::NtuParamOneShot(char *ntuname){ | |
341 | // Create, fill and return ntuple with fit parameters | |
342 | ||
343 | InitNtuParam(ntuname); | |
344 | FillNtuParam(); | |
345 | return fntuParam; | |
346 | } | |
347 | //_________________________________________________________________________ | |
348 | ||
349 | void AliHFMassFitter::RebinMass(Int_t bingroup){ | |
350 | // Rebin invariant mass histogram | |
351 | ||
352 | if(bingroup<1){ | |
353 | cout<<"Error! Cannot group "<<bingroup<<" bins\n"; | |
354 | fNbin=fhistoInvMass->GetNbinsX(); | |
355 | cout<<"Kept original number of bins: "<<fNbin<<endl; | |
356 | } else{ | |
357 | fhistoInvMass->Rebin(bingroup); | |
358 | fNbin = fhistoInvMass->GetNbinsX(); | |
359 | cout<<"New number of bins: "<<fNbin<<endl; | |
360 | } | |
361 | ||
362 | ||
363 | } | |
364 | ||
365 | //************* fit | |
366 | ||
367 | //___________________________________________________________________________ | |
368 | ||
fabf4d8e | 369 | Double_t AliHFMassFitter::FitFunction4MassDistr (Double_t *x, Double_t *par){ |
370 | // Fit function for signal+background | |
371 | ||
372 | ||
373 | //exponential or linear fit | |
374 | // | |
375 | // par[0] = tot integral | |
376 | // par[1] = slope | |
377 | // par[2] = gaussian integral | |
378 | // par[3] = gaussian mean | |
379 | // par[4] = gaussian sigma | |
380 | ||
381 | Double_t total,bkg=0,sgn=0; | |
382 | ||
383 | if (ftypeOfFit4Bkg==0 || ftypeOfFit4Bkg==1) { | |
384 | if(ftypeOfFit4Sgn == 0) { | |
385 | ||
386 | Double_t parbkg[2] = {par[0]-par[2], par[1]}; | |
387 | bkg = FitFunction4Bkg(x,parbkg); | |
388 | } | |
389 | if(ftypeOfFit4Sgn == 1) { | |
390 | Double_t parbkg[5] = {par[2],par[3],ffactor*par[4],par[0]-2*par[2], par[1]}; | |
391 | bkg = FitFunction4Bkg(x,parbkg); | |
392 | } | |
393 | ||
394 | sgn = FitFunction4Sgn(x,&par[2]); | |
395 | ||
396 | } | |
397 | ||
398 | //polynomial fit | |
399 | ||
400 | // par[0] = tot integral | |
401 | // par[1] = coef1 | |
402 | // par[2] = coef2 | |
403 | // par[3] = gaussian integral | |
404 | // par[4] = gaussian mean | |
405 | // par[5] = gaussian sigma | |
406 | ||
407 | if (ftypeOfFit4Bkg==2) { | |
408 | ||
409 | if(ftypeOfFit4Sgn == 0) { | |
56cbeefb | 410 | |
fabf4d8e | 411 | Double_t parbkg[3] = {par[0]-par[3], par[1], par[2]}; |
412 | bkg = FitFunction4Bkg(x,parbkg); | |
413 | } | |
414 | if(ftypeOfFit4Sgn == 1) { | |
56cbeefb | 415 | |
fabf4d8e | 416 | Double_t parbkg[6] = {par[3],par[4],ffactor*par[5],par[0]-2*par[3], par[1], par[2]}; |
417 | bkg = FitFunction4Bkg(x,parbkg); | |
418 | } | |
419 | ||
420 | sgn = FitFunction4Sgn(x,&par[3]); | |
421 | } | |
422 | ||
423 | if (ftypeOfFit4Bkg==3) { | |
424 | ||
425 | if(ftypeOfFit4Sgn == 0) { | |
426 | bkg=FitFunction4Bkg(x,par); | |
427 | sgn=FitFunction4Sgn(x,&par[1]); | |
428 | } | |
429 | if(ftypeOfFit4Sgn == 1) { | |
430 | Double_t parbkg[4]={par[1],par[2],ffactor*par[3],par[0]}; | |
431 | bkg=FitFunction4Bkg(x,parbkg); | |
432 | sgn=FitFunction4Sgn(x,&par[1]); | |
433 | } | |
434 | } | |
435 | ||
436 | total = bkg + sgn; | |
437 | ||
438 | return total; | |
439 | } | |
440 | ||
441 | //_________________________________________________________________________ | |
442 | Double_t AliHFMassFitter::FitFunction4Sgn (Double_t *x, Double_t *par){ | |
443 | // Fit function for the signal | |
444 | ||
445 | //gaussian = A/(sigma*sqrt(2*pi))*exp(-(x-mean)^2/2/sigma^2) | |
446 | //Par: | |
447 | // * [0] = integralSgn | |
448 | // * [1] = mean | |
449 | // * [2] = sigma | |
450 | //gaussian = [0]/TMath::Sqrt(2.*TMath::Pi())/[2]*exp[-(x-[1])*(x-[1])/(2*[2]*[2])] | |
451 | ||
452 | return par[0]/TMath::Sqrt(2.*TMath::Pi())/par[2]*TMath::Exp(-(x[0]-par[1])*(x[0]-par[1])/2./par[2]/par[2]); | |
453 | ||
454 | } | |
455 | ||
456 | //__________________________________________________________________________ | |
457 | ||
458 | Double_t AliHFMassFitter::FitFunction4Bkg (Double_t *x, Double_t *par){ | |
459 | // Fit function for the background | |
460 | ||
461 | Double_t maxDeltaM = 4.*fSigmaSgn; | |
462 | if(fSideBands && TMath::Abs(x[0]-fMass) < maxDeltaM) { | |
463 | TF1::RejectPoint(); | |
464 | return 0; | |
465 | } | |
466 | Int_t firstPar=0; | |
467 | Double_t gaus2=0,total=-1; | |
468 | if(ftypeOfFit4Sgn == 1){ | |
469 | firstPar=3; | |
470 | //gaussian = A/(sigma*sqrt(2*pi))*exp(-(x-mean)^2/2/sigma^2) | |
471 | //Par: | |
472 | // * [0] = integralSgn | |
473 | // * [1] = mean | |
474 | // * [2] = sigma | |
475 | //gaussian = [0]/TMath::Sqrt(2.*TMath::Pi())/[2]*exp[-(x-[1])*(x-[1])/(2*[2]*[2])] | |
476 | gaus2 = FitFunction4Sgn(x,par); | |
477 | } | |
478 | ||
479 | switch (ftypeOfFit4Bkg){ | |
480 | case 0: | |
481 | //exponential | |
482 | //exponential = A*exp(B*x) -> integral(exponential)=A/B*exp(B*x)](min,max) | |
483 | //-> A = B*integral/(exp(B*max)-exp(B*min)) where integral can be written | |
484 | //as integralTot- integralGaus (=par [2]) | |
485 | //Par: | |
486 | // * [0] = integralBkg; | |
487 | // * [1] = B; | |
488 | //exponential = [1]*[0]/(exp([1]*max)-exp([1]*min))*exp([1]*x) | |
489 | total = par[0+firstPar]*par[1+firstPar]/(TMath::Exp(par[1+firstPar]*fmaxMass)-TMath::Exp(par[1+firstPar]*fminMass))*TMath::Exp(par[1+firstPar]*x[0]); | |
490 | break; | |
491 | case 1: | |
492 | //linear | |
493 | //y=a+b*x -> integral = a(max-min)+1/2*b*(max^2-min^2) -> a = (integral-1/2*b*(max^2-min^2))/(max-min)=integral/(max-min)-1/2*b*(max+min) | |
494 | // * [0] = integralBkg; | |
495 | // * [1] = b; | |
496 | total= par[0+firstPar]/(fmaxMass-fminMass)+par[1+firstPar]*(x[0]-0.5*(fmaxMass+fminMass)); | |
497 | break; | |
498 | case 2: | |
499 | //polynomial | |
500 | //y=a+b*x+c*x**2 -> integral = a(max-min) + 1/2*b*(max^2-min^2) + | |
501 | //+ 1/3*c*(max^3-min^3) -> | |
502 | //a = (integral-1/2*b*(max^2-min^2)-1/3*c*(max^3-min^3))/(max-min) | |
503 | // * [0] = integralBkg; | |
504 | // * [1] = b; | |
505 | // * [2] = c; | |
506 | total = par[0+firstPar]/(fmaxMass-fminMass)+par[1]*(x[0]-0.5*(fmaxMass+fminMass))+par[2+firstPar]*(x[0]*x[0]-1/3.*(fmaxMass*fmaxMass*fmaxMass-fminMass*fminMass*fminMass)/(fmaxMass-fminMass)); | |
507 | break; | |
508 | case 3: | |
509 | total=par[0+firstPar]; | |
510 | break; | |
511 | // default: | |
512 | // Types of Fit Functions for Background: | |
513 | // * 0 = exponential; | |
514 | // * 1 = linear; | |
515 | // * 2 = polynomial 2nd order | |
516 | // * 3 = no background"<<endl; | |
517 | ||
518 | } | |
519 | return total+gaus2; | |
520 | } | |
521 | ||
522 | //__________________________________________________________________________ | |
523 | ||
524 | void AliHFMassFitter::MassFitter(Bool_t draw){ | |
525 | // Main method of the class: performs the fit of the histogram | |
526 | ||
527 | Int_t nFitPars=0; //total function's number of parameters | |
528 | switch (ftypeOfFit4Bkg){ | |
529 | case 0: | |
530 | nFitPars=5; //3+2 | |
531 | break; | |
532 | case 1: | |
533 | nFitPars=5; //3+2 | |
534 | break; | |
535 | case 2: | |
536 | nFitPars=6; //3+3 | |
537 | break; | |
538 | case 3: | |
539 | nFitPars=4; //3+1 | |
540 | break; | |
541 | } | |
542 | ||
543 | Int_t bkgPar = nFitPars-3; //background function's number of parameters | |
544 | ||
545 | cout<<"nFitPars = "<<nFitPars<<"\tbkgPar = "<<bkgPar<<endl; | |
546 | ||
56cbeefb | 547 | //function names |
548 | TString bkgname="funcbkg"; | |
549 | TString bkg1name="funcbkg1"; | |
550 | TString massname="funcmass"; | |
551 | ||
fabf4d8e | 552 | //Total integral |
553 | Double_t totInt = fhistoInvMass->Integral("width"); | |
554 | ||
555 | fSideBands = kTRUE; | |
556 | Double_t width; | |
557 | Int_t binleft,binright; | |
558 | fNbin=fhistoInvMass->GetNbinsX(); | |
559 | width=fhistoInvMass->GetBinWidth(8); | |
560 | //width=(fmaxMass-fminMass)/(Double_t)fNbin; | |
561 | binleft=(Int_t)((fMass-4.*fSigmaSgn-fminMass)/width); | |
562 | binright=(Int_t)((fMass+4.*fSigmaSgn-fminMass)/width); | |
563 | ||
564 | //sidebands integral - first approx (from histo) | |
565 | Double_t sideBandsInt=(Double_t)fhistoInvMass->Integral(1,binleft,"width") + (Double_t)fhistoInvMass->Integral(binright,fNbin,"width"); | |
566 | cout<<"------nbin = "<<fNbin<<"\twidth = "<<width<<"\tbinleft = "<<binleft<<"\tbinright = "<<binright<<endl; | |
567 | cout<<"------sideBandsInt - first approx = "<<sideBandsInt<<endl; | |
568 | ||
569 | /*Fit Bkg*/ | |
570 | ||
56cbeefb | 571 | TF1 *funcbkg = new TF1(bkgname.Data(),this,&AliHFMassFitter::FitFunction4Bkg,fminMass,fmaxMass,bkgPar,"AliHFMassFitter","FitFunction4Bkg"); |
572 | cout<<"Function name = "<<funcbkg->GetName()<<endl<<endl; | |
fabf4d8e | 573 | |
574 | funcbkg->SetLineColor(2); //red | |
575 | ||
576 | //first fit for bkg: approx bkgint | |
577 | ||
578 | switch (ftypeOfFit4Bkg) { | |
579 | case 0: //gaus+expo | |
580 | funcbkg->SetParNames("BkgInt","Slope"); | |
581 | funcbkg->SetParameters(sideBandsInt,-2.); | |
582 | break; | |
583 | case 1: | |
584 | funcbkg->SetParNames("BkgInt","Slope"); | |
585 | funcbkg->SetParameters(sideBandsInt,-100.); | |
586 | break; | |
587 | case 2: | |
588 | funcbkg->SetParNames("BkgInt","Coef1","Coef2"); | |
589 | funcbkg->SetParameters(sideBandsInt,-10.,5); | |
590 | break; | |
591 | case 3: | |
592 | if(ftypeOfFit4Sgn==0){ | |
fabf4d8e | 593 | funcbkg->SetParNames("Const"); |
594 | funcbkg->SetParameter(0,0.); | |
595 | funcbkg->FixParameter(0,0.); | |
596 | } | |
597 | break; | |
598 | default: | |
599 | cout<<"Wrong choise of ftypeOfFit4Bkg ("<<ftypeOfFit4Bkg<<")"<<endl; | |
600 | return; | |
601 | break; | |
602 | } | |
603 | cout<<"\nBACKGROUND FIT - only combinatorial"<<endl; | |
604 | Int_t ftypeOfFit4SgnBkp=ftypeOfFit4Sgn; | |
605 | ||
606 | Double_t intbkg1=0,slope1=0,conc1=0; | |
56cbeefb | 607 | //if only signal and reflection: skip |
fabf4d8e | 608 | if (!(ftypeOfFit4Bkg==3 && ftypeOfFit4Sgn==1)) { |
609 | ftypeOfFit4Sgn=0; | |
56cbeefb | 610 | fhistoInvMass->Fit(bkgname.Data(),"R,L,E,0"); |
fabf4d8e | 611 | |
612 | for(Int_t i=0;i<bkgPar;i++){ | |
613 | fFitPars[i]=funcbkg->GetParameter(i); | |
614 | //cout<<i<<"\t"<<funcbkg->GetParameter(i)<<"\t"; | |
615 | fFitPars[nFitPars+2*bkgPar+3+i]= funcbkg->GetParError(i); | |
616 | //cout<<nFitPars+2*bkgPar+3+i<<"\t"<< funcbkg->GetParError(i)<<endl; | |
617 | } | |
618 | ||
619 | intbkg1 = funcbkg->GetParameter(0); | |
620 | if(ftypeOfFit4Bkg!=3) slope1 = funcbkg->GetParameter(1); | |
621 | if(ftypeOfFit4Bkg==2) conc1 = funcbkg->GetParameter(2); | |
622 | cout<<"Primo fit: \nintbkg1 = "<<intbkg1<<"\nslope1= "<<slope1<<"\nconc1 = "<<conc1<<endl; | |
56cbeefb | 623 | } |
624 | else cout<<"\t\t//"<<endl; | |
fabf4d8e | 625 | |
626 | ftypeOfFit4Sgn=ftypeOfFit4SgnBkp; | |
627 | TF1 *funcbkg1=0; | |
628 | if (ftypeOfFit4Sgn == 1) { | |
629 | cout<<"\nBACKGROUND FIT WITH REFLECTION"<<endl; | |
630 | bkgPar+=3; | |
631 | ||
56cbeefb | 632 | cout<<"nFitPars = "<<nFitPars<<"\tbkgPar = "<<bkgPar<<endl; |
633 | ||
634 | funcbkg1 = new TF1(bkg1name.Data(),this,&AliHFMassFitter::FitFunction4Bkg,fminMass,fmaxMass,bkgPar,"AliHFMassFitter","FitFunction4Bkg"); | |
635 | cout<<"Function name = "<<funcbkg1->GetName()<<endl; | |
636 | ||
fabf4d8e | 637 | funcbkg1->SetLineColor(2); //red |
638 | ||
639 | if(ftypeOfFit4Bkg==2){ | |
640 | cout<<"*** Polynomial Fit ***"<<endl; | |
641 | funcbkg1->SetParNames("IntGB","MeanGB","SigmaGB","BkgInt","Coef1","Coef2"); | |
642 | funcbkg1->SetParameters(0.5*(totInt-intbkg1),fMass,ffactor*fSigmaSgn,intbkg1,slope1,conc1); | |
643 | // cout<<"Parameters set to: "<<0.5*(totInt-intbkg1)<<"\t"<<fMass<<"\t"<<ffactor*fSigmaSgn<<"\t"<<intbkg1<<"\t"<<slope1<<"\t"<<conc1<<"\t"<<endl; | |
644 | // cout<<"Limits: ("<<fminMass<<","<<fmaxMass<<")\tnPar = "<<bkgPar<<"\tgsidebands = "<<fSideBands<<endl; | |
645 | } else{ | |
646 | if(ftypeOfFit4Bkg==3) //no background: gaus sign+ gaus broadened | |
647 | { | |
648 | cout<<"*** No background Fit ***"<<endl; | |
649 | funcbkg1->SetParNames("IntGB","MeanGB","SigmaGB","Const"); | |
650 | funcbkg1->SetParameters(0.5*totInt,fMass,ffactor*fSigmaSgn,0.); | |
651 | funcbkg1->FixParameter(3,0.); | |
652 | } else{ //expo or linear | |
653 | if(ftypeOfFit4Bkg==0) cout<<"*** Exponential Fit ***"<<endl; | |
654 | if(ftypeOfFit4Bkg==1) cout<<"*** Linear Fit ***"<<endl; | |
655 | funcbkg1->SetParNames("IntGB","MeanGB","SigmaGB","BkgInt","Slope"); | |
656 | funcbkg1->SetParameters(0.5*(totInt-intbkg1),fMass,ffactor*fSigmaSgn,intbkg1,slope1); | |
657 | } | |
658 | } | |
56cbeefb | 659 | fhistoInvMass->Fit(bkg1name.Data(),"R,L,E,+,0"); |
fabf4d8e | 660 | |
661 | for(Int_t i=0;i<bkgPar;i++){ | |
662 | fFitPars[bkgPar-3+i]=funcbkg1->GetParameter(i); | |
663 | //cout<<bkgPar-3+i<<"\t"<<funcbkg1->GetParameter(i); | |
664 | fFitPars[nFitPars+3*bkgPar-6+i]= funcbkg1->GetParError(i); | |
56cbeefb | 665 | //cout<<"\t"<<nFitPars+3*bkgPar-6+i<<"\t"<<funcbkg1->GetParError(i)<<endl; |
fabf4d8e | 666 | } |
667 | ||
668 | intbkg1=funcbkg1->GetParameter(3); | |
669 | if(ftypeOfFit4Bkg!=3) slope1 = funcbkg1->GetParameter(4); | |
670 | if(ftypeOfFit4Bkg==2) conc1 = funcbkg1->GetParameter(5); | |
671 | ||
672 | } else { | |
673 | bkgPar+=3; | |
674 | ||
675 | for(Int_t i=0;i<3;i++){ | |
676 | fFitPars[bkgPar-3+i]=0.; | |
56cbeefb | 677 | cout<<bkgPar-3+i<<"\t"<<0.<<"\t"; |
fabf4d8e | 678 | fFitPars[nFitPars+3*bkgPar-6+i]= 0.; |
56cbeefb | 679 | cout<<nFitPars+3*bkgPar-6+i<<"\t"<<0.<<endl; |
fabf4d8e | 680 | } |
681 | ||
682 | for(Int_t i=0;i<bkgPar-3;i++){ | |
683 | fFitPars[bkgPar+i]=funcbkg->GetParameter(i); | |
56cbeefb | 684 | cout<<bkgPar+i<<"\t"<<funcbkg->GetParameter(i)<<"\t"; |
fabf4d8e | 685 | fFitPars[nFitPars+3*bkgPar-3+i]= funcbkg->GetParError(i); |
56cbeefb | 686 | cout<<nFitPars+3*bkgPar-3+i<<"\t"<< funcbkg->GetParError(i)<<endl; |
fabf4d8e | 687 | } |
688 | ||
689 | ||
690 | } | |
691 | ||
692 | //sidebands integral - second approx (from fit) | |
693 | fSideBands = kFALSE; | |
694 | Double_t bkgInt; | |
695 | ||
696 | if(ftypeOfFit4Sgn == 1) bkgInt=funcbkg1->Integral(fminMass,fmaxMass); | |
697 | else bkgInt=funcbkg->Integral(fminMass,fmaxMass); | |
698 | cout<<"------BkgInt(Fit) = "<<bkgInt<<endl; | |
699 | ||
700 | //Signal integral - first approx | |
701 | Double_t sgnInt; | |
702 | sgnInt = totInt-bkgInt; | |
703 | cout<<"------TotInt = "<<totInt<<"\tsgnInt = "<<sgnInt<<endl; | |
704 | ||
705 | /*Fit All Mass distribution with exponential + gaussian (+gaussiam braodened) */ | |
56cbeefb | 706 | TF1 *funcmass = new TF1(massname.Data(),this,&AliHFMassFitter::FitFunction4MassDistr,fminMass,fmaxMass,nFitPars,"AliHFMassFitter","FitFunction4MassDistr"); |
707 | cout<<"Function name = "<<funcmass->GetName()<<endl<<endl; | |
fabf4d8e | 708 | funcmass->SetLineColor(4); //blue |
709 | ||
710 | //Set parameters | |
711 | cout<<"\nTOTAL FIT"<<endl; | |
712 | ||
713 | if(nFitPars==5){ | |
714 | funcmass->SetParNames("TotInt","Slope","SgnInt","Mean","Sigma"); | |
715 | funcmass->SetParameters(totInt,slope1,sgnInt,fMass,fSigmaSgn); | |
56cbeefb | 716 | //cout<<"Parameters set to: "<<totInt<<"\t"<<slope1<<"\t"<<sgnInt<<"\t"<<fMass<<"\t"<<fSigmaSgn<<"\t"<<endl; |
fabf4d8e | 717 | // cout<<"Limits: ("<<fminMass<<","<<fmaxMass<<")\tnPar = "<<nFitPars<<"\tgsidebands = "<<fSideBands<<endl; |
718 | funcmass->FixParameter(0,totInt); | |
719 | } | |
720 | if (nFitPars==6){ | |
721 | funcmass->SetParNames("TotInt","Coef1","Coef2","SgnInt","Mean","Sigma"); | |
722 | funcmass->SetParameters(totInt,slope1,conc1,sgnInt,fMass,fSigmaSgn); | |
723 | // cout<<"Parameters set to: "<<totInt<<"\t"<<slope1<<"\t"<<conc1<<"\t"<<sgnInt<<"\t"<<fMass<<"\t"<<fSigmaSgn<<"\t"<<endl; | |
724 | // cout<<"Limits: ("<<fminMass<<","<<fmaxMass<<")\tnPar = "<<nFitPars<<"\tgsidebands = "<<fSideBands<<endl; | |
725 | funcmass->FixParameter(0,totInt); | |
726 | } | |
727 | if(nFitPars==4){ | |
728 | funcmass->SetParNames("Const","SgnInt","Mean","Sigma"); | |
56cbeefb | 729 | if(ftypeOfFit4Sgn == 1) funcmass->SetParameters(0.,0.5*totInt,fMass,fSigmaSgn); |
730 | else funcmass->SetParameters(0.,totInt,fMass,fSigmaSgn); | |
fabf4d8e | 731 | funcmass->FixParameter(0,0.); |
732 | //cout<<"Parameters set to: "<<0.5*totInt<<"\t"<<fMass<<"\t"<<fSigmaSgn<<"\t"<<endl; | |
733 | //cout<<"Limits: ("<<fminMass<<","<<fmaxMass<<")\tnPar = "<<nFitPars<<"\tgsidebands = "<<fSideBands<<endl; | |
734 | ||
735 | } | |
56cbeefb | 736 | |
737 | fhistoInvMass->Fit(massname.Data(),"R,L,E,+,0"); | |
fabf4d8e | 738 | cout<<"fit done"<<endl; |
739 | ||
740 | for(Int_t i=0;i<nFitPars;i++){ | |
741 | fFitPars[i+2*bkgPar-3]=funcmass->GetParameter(i); | |
742 | fFitPars[nFitPars+4*bkgPar-6+i]= funcmass->GetParError(i); | |
56cbeefb | 743 | //cout<<i+2*bkgPar-3<<"\t"<<funcmass->GetParameter(i)<<"\t\t"<<nFitPars+4*bkgPar-6+i<<"\t"<<funcmass->GetParError(i)<<endl; |
fabf4d8e | 744 | } |
745 | /* | |
746 | //check: cout parameters | |
747 | for(Int_t i=0;i<2*(nFitPars+2*bkgPar-3);i++){ | |
748 | cout<<i<<"\t"<<fFitPars[i]<<endl; | |
749 | } | |
750 | */ | |
74179930 | 751 | |
fabf4d8e | 752 | if(draw){ |
56cbeefb | 753 | TCanvas *canvas=new TCanvas(fhistoInvMass->GetName(),fhistoInvMass->GetName()); |
fabf4d8e | 754 | TH1F *fhistocopy=new TH1F(*fhistoInvMass); |
755 | canvas->cd(); | |
56cbeefb | 756 | fhistocopy->DrawClone(); |
757 | if(ftypeOfFit4Sgn == 1) funcbkg1->DrawClone("sames"); | |
758 | else funcbkg->DrawClone("sames"); | |
759 | funcmass->DrawClone("sames"); | |
2f328d65 | 760 | cout<<"Drawn"<<endl; |
fabf4d8e | 761 | } |
56cbeefb | 762 | |
763 | //increase counter of number of fits done | |
764 | fcounter++; | |
765 | ||
766 | if (ftypeOfFit4Sgn == 1) delete funcbkg1; | |
767 | delete funcbkg; | |
768 | delete funcmass; | |
74179930 | 769 | |
fabf4d8e | 770 | } |
771 | ||
56cbeefb | 772 | |
773 | //*********output | |
774 | ||
fabf4d8e | 775 | //_________________________________________________________________________ |
2f328d65 | 776 | void AliHFMassFitter::GetFitPars(Float_t *vector) const { |
fabf4d8e | 777 | // Return fit parameters |
778 | ||
2f328d65 | 779 | for(Int_t i=0;i<fParsSize;i++){ |
780 | vector[i]=fFitPars[i]; | |
fabf4d8e | 781 | } |
782 | } | |
fabf4d8e | 783 | //_________________________________________________________________________ |
784 | ||
56cbeefb | 785 | TH1F* AliHFMassFitter::GetHistoClone() const{ |
786 | TH1F* hout=(TH1F*)fhistoInvMass->Clone(fhistoInvMass->GetName()); | |
787 | return hout; | |
fabf4d8e | 788 | } |
fabf4d8e | 789 | //_________________________________________________________________________ |
790 | ||
56cbeefb | 791 | void AliHFMassFitter::WriteHisto(TString path) { |
792 | TH1F* hget=(TH1F*)fhistoInvMass->Clone(); | |
fabf4d8e | 793 | |
56cbeefb | 794 | TString bkgname = "funcbkg"; |
ab0fa301 | 795 | Int_t np=-99; |
56cbeefb | 796 | switch (ftypeOfFit4Bkg){ |
797 | case 0: | |
798 | np=2; | |
799 | break; | |
800 | case 1: | |
801 | np=2; | |
802 | break; | |
803 | case 2: | |
804 | np=3; | |
805 | break; | |
806 | case 3: | |
807 | np=1; | |
808 | break; | |
809 | } | |
810 | if (ftypeOfFit4Sgn == 1) { | |
811 | bkgname += 1; | |
812 | np+=3; | |
813 | } | |
814 | TF1 *b=(TF1*)hget->GetFunction(bkgname.Data()); | |
815 | //cout<<"WRITEHISTO np = "<<np<<"\n"<<bkgname<<endl; | |
816 | bkgname += "FullRange"; | |
817 | TF1 *bwrite=new TF1(bkgname.Data(),this,&AliHFMassFitter::FitFunction4Bkg,fminMass,fmaxMass,np,"AliHFMassFitter","FitFunction4Bkg"); | |
818 | for(Int_t i=0;i<np;i++){ | |
819 | bwrite->SetParameter(i,b->GetParameter(i)); | |
820 | } | |
821 | TList *hlist=hget->GetListOfFunctions(); | |
822 | hlist->Add(bwrite); | |
fabf4d8e | 823 | |
56cbeefb | 824 | path += "HFMassFitterOutput.root"; |
825 | TFile *output; | |
826 | if (fcounter == 1) output = new TFile(path.Data(),"recreate"); | |
827 | else output = new TFile(path.Data(),"update"); | |
828 | output->cd(); | |
829 | hget->Write(); | |
830 | output->Close(); | |
fabf4d8e | 831 | |
56cbeefb | 832 | cout<<fcounter<<" "<<hget->GetName()<<" written in "<<path<<endl; |
fabf4d8e | 833 | |
56cbeefb | 834 | delete bwrite; |
835 | delete output; | |
fabf4d8e | 836 | |
fabf4d8e | 837 | } |
838 | ||
839 | //_________________________________________________________________________ | |
840 | ||
56cbeefb | 841 | void AliHFMassFitter::WriteNtuple(TString path) const{ |
842 | TNtuple* nget=(TNtuple*)fntuParam->Clone(); | |
843 | path += "HFMassFitterOutput.root"; | |
844 | TFile *output = new TFile(path.Data(),"update"); | |
845 | output->cd(); | |
846 | nget->Write(); | |
847 | output->Close(); | |
848 | cout<<nget->GetName()<<" written in "<<path<<endl; | |
849 | delete nget; | |
850 | delete output; | |
fabf4d8e | 851 | } |
fabf4d8e | 852 | |
fabf4d8e | 853 | |
56cbeefb | 854 | //************ significance |
fabf4d8e | 855 | |
856 | //_________________________________________________________________________ | |
857 | ||
858 | void AliHFMassFitter::Signal(Double_t nOfSigma,Double_t &signal,Double_t &errsignal) const { | |
859 | // Return signal integral in mean+- n sigma | |
860 | ||
56cbeefb | 861 | |
862 | //functions names | |
863 | TString bkgname="funcbkg"; | |
864 | TString bkg1name="funcbkg1"; | |
865 | TString massname="funcmass"; | |
866 | ||
867 | TF1 *funcmass=fhistoInvMass->GetFunction(massname.Data()); | |
fabf4d8e | 868 | Double_t mean=0,sigma=1; |
869 | Double_t intS,intSerr; | |
870 | ||
871 | if(ftypeOfFit4Bkg == 2) { //polynomial | |
872 | mean=funcmass->GetParameter(4); //mean | |
873 | sigma=funcmass->GetParameter(5); //sigma | |
874 | intS=fFitPars[12]; | |
875 | intSerr=fFitPars[27]; | |
876 | } else if(ftypeOfFit4Bkg == 3){ //no background | |
877 | mean=funcmass->GetParameter(2); //mean | |
878 | sigma=funcmass->GetParameter(3); //sigma | |
879 | intS=fFitPars[6]; | |
880 | intSerr=fFitPars[15]; | |
881 | } else { //expo or linear | |
882 | mean=funcmass->GetParameter(3); //mean | |
883 | sigma=funcmass->GetParameter(4); //sigma | |
884 | intS=fFitPars[9]; | |
885 | intSerr=fFitPars[21]; | |
886 | } | |
887 | ||
888 | TF1 *funcbkg=0; | |
56cbeefb | 889 | if(ftypeOfFit4Sgn == 0) funcbkg=fhistoInvMass->GetFunction(bkgname.Data()); |
890 | else funcbkg=fhistoInvMass->GetFunction(bkg1name.Data()); | |
fabf4d8e | 891 | Double_t min=mean-nOfSigma*sigma; |
892 | Double_t max=mean+nOfSigma*sigma; | |
2f328d65 | 893 | signal=(funcmass->Integral(min,max)-funcbkg->Integral(min,max))/(Double_t)fhistoInvMass->GetBinWidth(2); |
fabf4d8e | 894 | errsignal=intSerr/intS*signal; // assume relative error is the same as for total integral |
895 | ||
896 | return; | |
897 | } | |
898 | //_________________________________________________________________________ | |
899 | ||
900 | void AliHFMassFitter::Background(Double_t nOfSigma,Double_t &background,Double_t &errbackground) const { | |
901 | // Return background integral in mean+- n sigma | |
56cbeefb | 902 | |
903 | //functions names | |
904 | TString bkgname="funcbkg"; | |
905 | TString bkg1name="funcbkg1"; | |
906 | TString massname="funcmass"; | |
fabf4d8e | 907 | |
56cbeefb | 908 | TF1 *funcmass=fhistoInvMass->GetFunction(massname.Data()); |
fabf4d8e | 909 | Double_t mean=0,sigma=1; |
910 | Double_t intB,intBerr,err; | |
911 | ||
912 | if(ftypeOfFit4Bkg == 2) { //polynomial | |
913 | mean=funcmass->GetParameter(4); //mean | |
914 | sigma=funcmass->GetParameter(5); //sigma | |
915 | intB=fFitPars[9]-fFitPars[12]; | |
916 | intBerr=fFitPars[27]; | |
917 | } else if(ftypeOfFit4Bkg == 3){ //no background | |
918 | mean=funcmass->GetParameter(2); //mean | |
919 | sigma=funcmass->GetParameter(3); //sigma | |
920 | if (ftypeOfFit4Sgn == 1){ //reflection | |
921 | intB=fFitPars[1]; | |
922 | intBerr=fFitPars[9]; | |
923 | } else { | |
924 | intB=-1;intBerr=-1; | |
925 | err=0; | |
926 | } | |
927 | } else { //expo or linear | |
928 | mean=funcmass->GetParameter(3); //mean | |
929 | sigma=funcmass->GetParameter(4); //sigma | |
930 | intB=fFitPars[7]-fFitPars[9]; | |
931 | intBerr=fFitPars[21]; | |
932 | } | |
933 | ||
934 | TF1 *funcbkg=0; | |
56cbeefb | 935 | |
936 | if(ftypeOfFit4Sgn == 0) funcbkg=fhistoInvMass->GetFunction(bkgname.Data()); | |
937 | else funcbkg=fhistoInvMass->GetFunction(bkg1name.Data()); | |
fabf4d8e | 938 | Double_t min=mean-nOfSigma*sigma; |
939 | Double_t max=mean+nOfSigma*sigma; | |
2f328d65 | 940 | background=funcbkg->Integral(min,max)/(Double_t)fhistoInvMass->GetBinWidth(2); |
fabf4d8e | 941 | errbackground=intBerr/intB*background; |
942 | ||
943 | return; | |
944 | ||
945 | } | |
946 | ||
947 | //__________________________________________________________________________ | |
948 | ||
949 | void AliHFMassFitter::Significance(Double_t nOfSigma,Double_t &significance,Double_t &errsignificance) const { | |
950 | // Return significance in mean+- n sigma | |
951 | ||
952 | Double_t signal,errsignal,background,errbackground; | |
953 | Signal(nOfSigma,signal,errsignal); | |
954 | Background(nOfSigma,background,errbackground); | |
955 | ||
956 | significance = signal/TMath::Sqrt(signal+background); | |
957 | errsignificance = TMath::Sqrt(significance*significance/(signal+background)/(signal+background)*(1/4.*errsignal*errsignal+errbackground*errbackground)+significance*significance/signal/signal*errsignal*errsignal); | |
958 | ||
959 | return; | |
960 | } | |
961 | ||
962 | //__________________________________________________________________________ | |
74179930 | 963 |