]>
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 | ||
dc262918 | 24 | #include <Riostream.h> |
25 | #include <TMath.h> | |
26 | #include <TNtuple.h> | |
27 | #include <TH1F.h> | |
28 | #include <TF1.h> | |
29 | #include <TList.h> | |
30 | #include <TFile.h> | |
fabf4d8e | 31 | #include <TCanvas.h> |
a12d80b8 | 32 | #include <TVirtualPad.h> |
ad73ca8f | 33 | #include <TGraph.h> |
34 | #include <TVirtualFitter.h> | |
dc262918 | 35 | #include <TMinuit.h> |
3c0e7d59 | 36 | #include <TStyle.h> |
37 | #include <TPaveText.h> | |
fabf4d8e | 38 | |
39 | #include "AliHFMassFitter.h" | |
40 | ||
41 | ||
dc262918 | 42 | |
fabf4d8e | 43 | ClassImp(AliHFMassFitter) |
44 | ||
56cbeefb | 45 | //************** constructors |
2f328d65 | 46 | AliHFMassFitter::AliHFMassFitter() : |
47 | TNamed(), | |
fabf4d8e | 48 | fhistoInvMass(0), |
49 | fminMass(0), | |
50 | fmaxMass(0), | |
34c79b83 | 51 | fNbin(0), |
2f328d65 | 52 | fParsSize(1), |
d22f0682 | 53 | fNFinalPars(1), |
2f328d65 | 54 | fFitPars(0), |
fabf4d8e | 55 | fWithBkg(0), |
56 | ftypeOfFit4Bkg(0), | |
57 | ftypeOfFit4Sgn(0), | |
58 | ffactor(1), | |
59 | fntuParam(0), | |
60 | fMass(1.85), | |
61 | fSigmaSgn(0.012), | |
56cbeefb | 62 | fSideBands(0), |
3c0e7d59 | 63 | fFixPar(0), |
b7d4bc49 | 64 | fSideBandl(0), |
65 | fSideBandr(0), | |
ad73ca8f | 66 | fcounter(0), |
67 | fContourGraph(0) | |
fabf4d8e | 68 | { |
69 | // default constructor | |
a12d80b8 | 70 | |
71 | cout<<"Default constructor:"<<endl; | |
72 | cout<<"Remember to set the Histo, the Type, the FixPar"<<endl; | |
ad73ca8f | 73 | |
fabf4d8e | 74 | } |
75 | ||
76 | //___________________________________________________________________________ | |
77 | ||
dc262918 | 78 | AliHFMassFitter::AliHFMassFitter (const TH1F *histoToFit, Double_t minvalue, Double_t maxvalue, Int_t rebin,Int_t fittypeb,Int_t fittypes): |
fabf4d8e | 79 | TNamed(), |
80 | fhistoInvMass(0), | |
81 | fminMass(0), | |
82 | fmaxMass(0), | |
34c79b83 | 83 | fNbin(0), |
2f328d65 | 84 | fParsSize(1), |
d22f0682 | 85 | fNFinalPars(1), |
2f328d65 | 86 | fFitPars(0), |
fabf4d8e | 87 | fWithBkg(0), |
88 | ftypeOfFit4Bkg(0), | |
89 | ftypeOfFit4Sgn(0), | |
90 | ffactor(1), | |
91 | fntuParam(0), | |
92 | fMass(1.85), | |
93 | fSigmaSgn(0.012), | |
56cbeefb | 94 | fSideBands(0), |
3c0e7d59 | 95 | fFixPar(0), |
b7d4bc49 | 96 | fSideBandl(0), |
97 | fSideBandr(0), | |
ad73ca8f | 98 | fcounter(0), |
99 | fContourGraph(0) | |
fabf4d8e | 100 | { |
101 | // standard constructor | |
102 | ||
56cbeefb | 103 | fhistoInvMass= (TH1F*)histoToFit->Clone("fhistoInvMass"); |
6321ee46 | 104 | fhistoInvMass->SetDirectory(0); |
fabf4d8e | 105 | fminMass=minvalue; |
106 | fmaxMass=maxvalue; | |
107 | if(rebin!=1) RebinMass(rebin); | |
108 | else fNbin=(Int_t)fhistoInvMass->GetNbinsX(); | |
d22f0682 | 109 | CheckRangeFit(); |
fabf4d8e | 110 | ftypeOfFit4Bkg=fittypeb; |
111 | ftypeOfFit4Sgn=fittypes; | |
112 | if(ftypeOfFit4Bkg!=0 && ftypeOfFit4Bkg!=1 && ftypeOfFit4Bkg!=2) fWithBkg=kFALSE; | |
113 | else fWithBkg=kTRUE; | |
114 | if (!fWithBkg) cout<<"Fit Histogram of Signal only"<<endl; | |
115 | else cout<<"Type of fit For Background = "<<ftypeOfFit4Bkg<<endl; | |
2f328d65 | 116 | |
117 | ComputeParSize(); | |
118 | fFitPars=new Float_t[fParsSize]; | |
d22f0682 | 119 | ComputeNFinalPars(); |
120 | fFixPar=new Bool_t[fNFinalPars]; | |
a12d80b8 | 121 | |
3c0e7d59 | 122 | fFixPar[0]=kTRUE; //default: IntTot fixed |
a12d80b8 | 123 | cout<<"Parameter 0 is fixed"<<endl; |
d22f0682 | 124 | for(Int_t i=1;i<fNFinalPars;i++){ |
3c0e7d59 | 125 | fFixPar[i]=kFALSE; |
126 | } | |
a12d80b8 | 127 | |
ad73ca8f | 128 | fContourGraph=new TList(); |
129 | fContourGraph->SetOwner(); | |
130 | ||
fabf4d8e | 131 | } |
132 | ||
74179930 | 133 | |
134 | AliHFMassFitter::AliHFMassFitter(const AliHFMassFitter &mfit): | |
135 | TNamed(), | |
136 | fhistoInvMass(mfit.fhistoInvMass), | |
137 | fminMass(mfit.fminMass), | |
138 | fmaxMass(mfit.fmaxMass), | |
139 | fNbin(mfit.fNbin), | |
2f328d65 | 140 | fParsSize(mfit.fParsSize), |
d22f0682 | 141 | fNFinalPars(mfit.fNFinalPars), |
2f328d65 | 142 | fFitPars(0), |
74179930 | 143 | fWithBkg(mfit.fWithBkg), |
144 | ftypeOfFit4Bkg(mfit.ftypeOfFit4Bkg), | |
145 | ftypeOfFit4Sgn(mfit.ftypeOfFit4Sgn), | |
146 | ffactor(mfit.ffactor), | |
147 | fntuParam(mfit.fntuParam), | |
148 | fMass(mfit.fMass), | |
149 | fSigmaSgn(mfit.fSigmaSgn), | |
56cbeefb | 150 | fSideBands(mfit.fSideBands), |
3c0e7d59 | 151 | fFixPar(0), |
b7d4bc49 | 152 | fSideBandl(mfit.fSideBandl), |
153 | fSideBandr(mfit.fSideBandr), | |
ad73ca8f | 154 | fcounter(mfit.fcounter), |
155 | fContourGraph(mfit.fContourGraph) | |
74179930 | 156 | { |
157 | //copy constructor | |
2f328d65 | 158 | |
159 | if(mfit.fParsSize > 0){ | |
160 | fFitPars=new Float_t[fParsSize]; | |
3c0e7d59 | 161 | fFixPar=new Bool_t[fParsSize]; |
2f328d65 | 162 | memcpy(fFitPars,mfit.fFitPars,mfit.fParsSize*sizeof(Float_t)); |
3c0e7d59 | 163 | memcpy(fFixPar,mfit.fFixPar,mfit.fParsSize*sizeof(Bool_t)); |
2f328d65 | 164 | } |
165 | //for(Int_t i=0;i<fParsSize;i++) fFitPars[i]=mfit.fFitPars[i]; | |
166 | } | |
167 | ||
168 | //_________________________________________________________________________ | |
169 | ||
170 | AliHFMassFitter::~AliHFMassFitter() { | |
dc262918 | 171 | |
172 | //destructor | |
173 | ||
56cbeefb | 174 | cout<<"AliHFMassFitter destructor called"<<endl; |
a60f573d | 175 | if(fhistoInvMass) { |
176 | cout<<"deleting histogram..."<<endl; | |
177 | delete fhistoInvMass; | |
178 | fhistoInvMass=NULL; | |
179 | } | |
180 | if(fntuParam){ | |
181 | cout<<"deleting ntuple..."<<endl; | |
182 | delete fntuParam; | |
183 | ||
184 | fntuParam=NULL; | |
185 | } | |
186 | ||
187 | if(fFitPars) { | |
188 | delete[] fFitPars; | |
189 | cout<<"deleting parameter array..."<<endl; | |
190 | fFitPars=NULL; | |
191 | } | |
192 | ||
3c0e7d59 | 193 | if(fFixPar) { |
194 | delete[] fFixPar; | |
195 | cout<<"deleting bool array..."<<endl; | |
196 | fFixPar=NULL; | |
197 | } | |
198 | ||
56cbeefb | 199 | fcounter = 0; |
74179930 | 200 | } |
201 | ||
202 | //_________________________________________________________________________ | |
203 | ||
204 | AliHFMassFitter& AliHFMassFitter::operator=(const AliHFMassFitter &mfit){ | |
205 | ||
206 | //assignment operator | |
207 | ||
208 | if(&mfit == this) return *this; | |
209 | fhistoInvMass= mfit.fhistoInvMass; | |
210 | fminMass= mfit.fminMass; | |
211 | fmaxMass= mfit.fmaxMass; | |
212 | fNbin= mfit.fNbin; | |
2f328d65 | 213 | fParsSize= mfit.fParsSize; |
74179930 | 214 | fWithBkg= mfit.fWithBkg; |
215 | ftypeOfFit4Bkg= mfit.ftypeOfFit4Bkg; | |
216 | ftypeOfFit4Sgn= mfit.ftypeOfFit4Sgn; | |
217 | ffactor= mfit.ffactor; | |
218 | fntuParam= mfit.fntuParam; | |
219 | fMass= mfit.fMass; | |
220 | fSigmaSgn= mfit.fSigmaSgn; | |
221 | fSideBands= mfit.fSideBands; | |
b7d4bc49 | 222 | fSideBandl= mfit.fSideBandl; |
223 | fSideBandr= mfit.fSideBandr; | |
56cbeefb | 224 | fcounter= mfit.fcounter; |
ad73ca8f | 225 | fContourGraph= mfit.fContourGraph; |
226 | ||
2f328d65 | 227 | if(mfit.fParsSize > 0){ |
a60f573d | 228 | if(fFitPars) { |
229 | delete[] fFitPars; | |
230 | fFitPars=NULL; | |
231 | } | |
2f328d65 | 232 | fFitPars=new Float_t[fParsSize]; |
233 | memcpy(fFitPars,mfit.fFitPars,mfit.fParsSize*sizeof(Float_t)); | |
3c0e7d59 | 234 | |
235 | if(fFixPar) { | |
236 | delete[] fFixPar; | |
237 | fFixPar=NULL; | |
238 | } | |
d22f0682 | 239 | fFixPar=new Bool_t[fNFinalPars]; |
240 | memcpy(fFixPar,mfit.fFixPar,mfit.fNFinalPars*sizeof(Float_t)); | |
2f328d65 | 241 | } |
242 | // fFitPars=new Float_t[fParsSize]; | |
243 | // for(Int_t i=0;i<fParsSize;i++) fFitPars[i]=mfit.fFitPars[i]; | |
74179930 | 244 | |
245 | return *this; | |
246 | } | |
56cbeefb | 247 | |
248 | //************ tools & settings | |
249 | ||
2f328d65 | 250 | //__________________________________________________________________________ |
251 | ||
d22f0682 | 252 | void AliHFMassFitter::ComputeNFinalPars() { |
253 | switch (ftypeOfFit4Bkg) {//npar background func | |
254 | case 0: | |
255 | fNFinalPars=2; | |
256 | break; | |
257 | case 1: | |
258 | fNFinalPars=2; | |
259 | break; | |
260 | case 2: | |
261 | fNFinalPars=3; | |
262 | break; | |
263 | case 3: | |
264 | fNFinalPars=1; | |
265 | break; | |
266 | default: | |
267 | cout<<"Error in computing fNFinalPars: check ftypeOfFit4Bkg"<<endl; | |
268 | break; | |
269 | } | |
270 | ||
271 | fNFinalPars+=3; //gaussian signal | |
272 | } | |
273 | //__________________________________________________________________________ | |
274 | ||
2f328d65 | 275 | void AliHFMassFitter::ComputeParSize() { |
dc262918 | 276 | |
277 | //compute the size of the parameter array and set the data member | |
278 | ||
d22f0682 | 279 | switch (ftypeOfFit4Bkg) {//npar background func |
2f328d65 | 280 | case 0: |
281 | fParsSize = 2*3; | |
282 | break; | |
283 | case 1: | |
284 | fParsSize = 2*3; | |
285 | break; | |
286 | case 2: | |
287 | fParsSize = 3*3; | |
288 | break; | |
289 | case 3: | |
56cbeefb | 290 | fParsSize = 1*3; |
2f328d65 | 291 | break; |
292 | default: | |
56cbeefb | 293 | cout<<"Error in computing fParsSize: check ftypeOfFit4Bkg"<<endl; |
2f328d65 | 294 | break; |
295 | } | |
296 | ||
56cbeefb | 297 | fParsSize += 3; // npar refl |
298 | fParsSize += 3; // npar signal gaus | |
2f328d65 | 299 | |
56cbeefb | 300 | fParsSize*=2; // add errors |
2f328d65 | 301 | cout<<"Parameters array size "<<fParsSize<<endl; |
302 | } | |
303 | ||
3c0e7d59 | 304 | //___________________________________________________________________________ |
305 | Bool_t AliHFMassFitter::SetFixThisParam(Int_t thispar,Bool_t fixpar){ | |
306 | ||
307 | //set the value (kFALSE or kTRUE) of one element of fFixPar | |
308 | //return kFALSE if something wrong | |
309 | ||
d22f0682 | 310 | if(thispar>=fNFinalPars) { |
311 | cout<<"Error! Parameter out of bounds! Max is "<<fNFinalPars-1<<endl; | |
3c0e7d59 | 312 | return kFALSE; |
313 | } | |
d22f0682 | 314 | if(!fFixPar){ |
315 | cout<<"Initializing fFixPar..."; | |
316 | ComputeNFinalPars(); | |
317 | fFixPar=new Bool_t[fNFinalPars]; | |
318 | fFixPar[0]=kTRUE; | |
319 | for(Int_t i=1;i<fNFinalPars;i++){ | |
320 | fFixPar[i]=kFALSE; | |
321 | } | |
322 | cout<<" done."<<endl; | |
323 | } | |
324 | ||
3c0e7d59 | 325 | fFixPar[thispar]=fixpar; |
a12d80b8 | 326 | cout<<"Parameter "<<thispar<<" is now fixed"<<endl; |
3c0e7d59 | 327 | return kTRUE; |
328 | } | |
329 | ||
330 | //___________________________________________________________________________ | |
331 | Bool_t AliHFMassFitter::GetFixThisParam(Int_t thispar)const{ | |
332 | //return the value of fFixPar[thispar] | |
d22f0682 | 333 | if(thispar>=fNFinalPars) { |
334 | cout<<"Error! Parameter out of bounds! Max is "<<fNFinalPars-1<<endl; | |
3c0e7d59 | 335 | return kFALSE; |
336 | } | |
337 | if(!fFixPar) return kFALSE; | |
338 | return fFixPar[thispar]; | |
339 | ||
340 | } | |
341 | ||
56cbeefb | 342 | //___________________________________________________________________________ |
dc262918 | 343 | void AliHFMassFitter::SetHisto(const TH1F *histoToFit){ |
a60f573d | 344 | //fhistoInvMass = (TH1F*)histoToFit->Clone(); |
345 | fhistoInvMass = new TH1F(*histoToFit); | |
6321ee46 | 346 | fhistoInvMass->SetDirectory(0); |
a60f573d | 347 | cout<<"SetHisto pointer "<<fhistoInvMass<<endl; |
56cbeefb | 348 | } |
349 | ||
2f328d65 | 350 | //___________________________________________________________________________ |
351 | ||
352 | void AliHFMassFitter::SetType(Int_t fittypeb, Int_t fittypes) { | |
dc262918 | 353 | |
354 | //set the type of fit to perform for signal and background | |
355 | ||
2f328d65 | 356 | ftypeOfFit4Bkg = fittypeb; |
357 | ftypeOfFit4Sgn = fittypes; | |
358 | ComputeParSize(); | |
359 | fFitPars = new Float_t[fParsSize]; | |
360 | ||
361 | } | |
74179930 | 362 | |
fabf4d8e | 363 | //___________________________________________________________________________ |
364 | ||
56cbeefb | 365 | void AliHFMassFitter::Reset() { |
dc262918 | 366 | |
367 | //delete the histogram and reset the mean and sigma to default | |
368 | ||
a60f573d | 369 | cout<<"Reset called: delete histogram, set mean value to 1.85 and sigma to 0.012"<<endl; |
0566386c | 370 | fMass=1.85; |
371 | fSigmaSgn=0.012; | |
a60f573d | 372 | cout<<"Reset "<<fhistoInvMass<<endl; |
373 | if(fhistoInvMass) { | |
ad73ca8f | 374 | //cout<<"esiste"<<endl; |
6321ee46 | 375 | delete fhistoInvMass; |
a60f573d | 376 | fhistoInvMass=NULL; |
377 | cout<<fhistoInvMass<<endl; | |
378 | } | |
379 | else cout<<"histogram doesn't exist, do not delete"<<endl; | |
380 | ||
56cbeefb | 381 | } |
382 | ||
383 | //_________________________________________________________________________ | |
384 | ||
385 | void AliHFMassFitter::InitNtuParam(char *ntuname) { | |
dc262918 | 386 | |
56cbeefb | 387 | // Create ntuple to keep fit parameters |
dc262918 | 388 | |
56cbeefb | 389 | fntuParam=0; |
390 | 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"); | |
391 | ||
392 | } | |
393 | ||
394 | //_________________________________________________________________________ | |
395 | ||
396 | void AliHFMassFitter::FillNtuParam() { | |
397 | // Fill ntuple with fit parameters | |
398 | ||
399 | Float_t nothing=0.; | |
400 | ||
401 | if (ftypeOfFit4Bkg==2) { | |
402 | fntuParam->SetBranchAddress("intbkg1",&fFitPars[0]); | |
403 | fntuParam->SetBranchAddress("slope1",&fFitPars[1]); | |
404 | fntuParam->SetBranchAddress("conc1",&fFitPars[2]); | |
405 | fntuParam->SetBranchAddress("intGB",&fFitPars[3]); | |
406 | fntuParam->SetBranchAddress("meanGB",&fFitPars[4]); | |
407 | fntuParam->SetBranchAddress("sigmaGB",&fFitPars[5]); | |
408 | fntuParam->SetBranchAddress("intbkg2",&fFitPars[6]); | |
409 | fntuParam->SetBranchAddress("slope2",&fFitPars[7]); | |
410 | fntuParam->SetBranchAddress("conc2",&fFitPars[8]); | |
411 | fntuParam->SetBranchAddress("inttot",&fFitPars[9]); | |
412 | fntuParam->SetBranchAddress("slope3",&fFitPars[10]); | |
413 | fntuParam->SetBranchAddress("conc3",&fFitPars[11]); | |
414 | fntuParam->SetBranchAddress("intsgn",&fFitPars[12]); | |
415 | fntuParam->SetBranchAddress("meansgn",&fFitPars[13]); | |
416 | fntuParam->SetBranchAddress("sigmasgn",&fFitPars[14]); | |
417 | ||
418 | fntuParam->SetBranchAddress("intbkg1Err",&fFitPars[15]); | |
419 | fntuParam->SetBranchAddress("slope1Err",&fFitPars[16]); | |
420 | fntuParam->SetBranchAddress("conc1Err",&fFitPars[17]); | |
421 | fntuParam->SetBranchAddress("intGBErr",&fFitPars[18]); | |
422 | fntuParam->SetBranchAddress("meanGBErr",&fFitPars[19]); | |
423 | fntuParam->SetBranchAddress("sigmaGBErr",&fFitPars[20]); | |
424 | fntuParam->SetBranchAddress("intbkg2Err",&fFitPars[21]); | |
425 | fntuParam->SetBranchAddress("slope2Err",&fFitPars[22]); | |
426 | fntuParam->SetBranchAddress("conc2Err",&fFitPars[23]); | |
427 | fntuParam->SetBranchAddress("inttotErr",&fFitPars[24]); | |
428 | fntuParam->SetBranchAddress("slope3Err",&fFitPars[25]); | |
429 | fntuParam->SetBranchAddress("conc3Err",&fFitPars[26]); | |
430 | fntuParam->SetBranchAddress("intsgnErr",&fFitPars[27]); | |
431 | fntuParam->SetBranchAddress("meansgnErr",&fFitPars[28]); | |
432 | fntuParam->SetBranchAddress("sigmasgnErr",&fFitPars[29]); | |
433 | ||
434 | } else { | |
435 | ||
436 | if(ftypeOfFit4Bkg==3){ | |
437 | fntuParam->SetBranchAddress("intbkg1",&fFitPars[0]); | |
438 | fntuParam->SetBranchAddress("slope1",¬hing); | |
439 | fntuParam->SetBranchAddress("conc1",¬hing); | |
440 | fntuParam->SetBranchAddress("intGB",&fFitPars[1]); | |
441 | fntuParam->SetBranchAddress("meanGB",&fFitPars[2]); | |
442 | fntuParam->SetBranchAddress("sigmaGB",&fFitPars[3]); | |
443 | fntuParam->SetBranchAddress("intbkg2",&fFitPars[4]); | |
444 | fntuParam->SetBranchAddress("slope2",¬hing); | |
445 | fntuParam->SetBranchAddress("conc2",¬hing); | |
446 | fntuParam->SetBranchAddress("inttot",&fFitPars[6]); | |
447 | fntuParam->SetBranchAddress("slope3",¬hing); | |
448 | fntuParam->SetBranchAddress("conc3",¬hing); | |
449 | fntuParam->SetBranchAddress("intsgn",&fFitPars[6]); | |
450 | fntuParam->SetBranchAddress("meansgn",&fFitPars[7]); | |
451 | fntuParam->SetBranchAddress("sigmasgn",&fFitPars[8]); | |
452 | ||
453 | fntuParam->SetBranchAddress("intbkg1Err",&fFitPars[9]); | |
454 | fntuParam->SetBranchAddress("slope1Err",¬hing); | |
455 | fntuParam->SetBranchAddress("conc1Err",¬hing); | |
456 | fntuParam->SetBranchAddress("intGBErr",&fFitPars[10]); | |
457 | fntuParam->SetBranchAddress("meanGBErr",&fFitPars[11]); | |
458 | fntuParam->SetBranchAddress("sigmaGBErr",&fFitPars[12]); | |
459 | fntuParam->SetBranchAddress("intbkg2Err",&fFitPars[13]); | |
460 | fntuParam->SetBranchAddress("slope2Err",¬hing); | |
461 | fntuParam->SetBranchAddress("conc2Err",¬hing); | |
462 | fntuParam->SetBranchAddress("inttotErr",&fFitPars[15]); | |
463 | fntuParam->SetBranchAddress("slope3Err",¬hing); | |
464 | fntuParam->SetBranchAddress("conc3Err",¬hing); | |
465 | fntuParam->SetBranchAddress("intsgnErr",&fFitPars[15]); | |
466 | fntuParam->SetBranchAddress("meansgnErr",&fFitPars[16]); | |
467 | fntuParam->SetBranchAddress("sigmasgnErr",&fFitPars[17]); | |
468 | ||
469 | } | |
470 | else{ | |
471 | fntuParam->SetBranchAddress("intbkg1",&fFitPars[0]); | |
472 | fntuParam->SetBranchAddress("slope1",&fFitPars[1]); | |
473 | fntuParam->SetBranchAddress("conc1",¬hing); | |
474 | fntuParam->SetBranchAddress("intGB",&fFitPars[2]); | |
475 | fntuParam->SetBranchAddress("meanGB",&fFitPars[3]); | |
476 | fntuParam->SetBranchAddress("sigmaGB",&fFitPars[4]); | |
477 | fntuParam->SetBranchAddress("intbkg2",&fFitPars[5]); | |
478 | fntuParam->SetBranchAddress("slope2",&fFitPars[6]); | |
479 | fntuParam->SetBranchAddress("conc2",¬hing); | |
480 | fntuParam->SetBranchAddress("inttot",&fFitPars[7]); | |
481 | fntuParam->SetBranchAddress("slope3",&fFitPars[8]); | |
482 | fntuParam->SetBranchAddress("conc3",¬hing); | |
483 | fntuParam->SetBranchAddress("intsgn",&fFitPars[9]); | |
484 | fntuParam->SetBranchAddress("meansgn",&fFitPars[10]); | |
485 | fntuParam->SetBranchAddress("sigmasgn",&fFitPars[11]); | |
486 | ||
487 | fntuParam->SetBranchAddress("intbkg1Err",&fFitPars[12]); | |
488 | fntuParam->SetBranchAddress("slope1Err",&fFitPars[13]); | |
489 | fntuParam->SetBranchAddress("conc1Err",¬hing); | |
490 | fntuParam->SetBranchAddress("intGBErr",&fFitPars[14]); | |
491 | fntuParam->SetBranchAddress("meanGBErr",&fFitPars[15]); | |
492 | fntuParam->SetBranchAddress("sigmaGBErr",&fFitPars[16]); | |
493 | fntuParam->SetBranchAddress("intbkg2Err",&fFitPars[17]); | |
494 | fntuParam->SetBranchAddress("slope2Err",&fFitPars[18]); | |
495 | fntuParam->SetBranchAddress("conc2Err",¬hing); | |
496 | fntuParam->SetBranchAddress("inttotErr",&fFitPars[19]); | |
497 | fntuParam->SetBranchAddress("slope3Err",&fFitPars[20]); | |
498 | fntuParam->SetBranchAddress("conc3Err",¬hing); | |
499 | fntuParam->SetBranchAddress("intsgnErr",&fFitPars[21]); | |
500 | fntuParam->SetBranchAddress("meansgnErr",&fFitPars[22]); | |
501 | fntuParam->SetBranchAddress("sigmasgnErr",&fFitPars[23]); | |
502 | } | |
503 | ||
504 | } | |
505 | fntuParam->TTree::Fill(); | |
506 | } | |
507 | ||
508 | //_________________________________________________________________________ | |
509 | ||
510 | TNtuple* AliHFMassFitter::NtuParamOneShot(char *ntuname){ | |
511 | // Create, fill and return ntuple with fit parameters | |
512 | ||
513 | InitNtuParam(ntuname); | |
514 | FillNtuParam(); | |
515 | return fntuParam; | |
516 | } | |
517 | //_________________________________________________________________________ | |
518 | ||
519 | void AliHFMassFitter::RebinMass(Int_t bingroup){ | |
520 | // Rebin invariant mass histogram | |
521 | ||
3c0e7d59 | 522 | if(!fhistoInvMass){ |
523 | cout<<"Histogram not set"<<endl; | |
524 | return; | |
525 | } | |
d22f0682 | 526 | Int_t nbinshisto=fhistoInvMass->GetNbinsX(); |
56cbeefb | 527 | if(bingroup<1){ |
528 | cout<<"Error! Cannot group "<<bingroup<<" bins\n"; | |
d22f0682 | 529 | fNbin=nbinshisto; |
56cbeefb | 530 | cout<<"Kept original number of bins: "<<fNbin<<endl; |
531 | } else{ | |
532 | fhistoInvMass->Rebin(bingroup); | |
d22f0682 | 533 | if(nbinshisto%bingroup != 0) CheckRangeFit(); |
56cbeefb | 534 | fNbin = fhistoInvMass->GetNbinsX(); |
535 | cout<<"New number of bins: "<<fNbin<<endl; | |
536 | } | |
56cbeefb | 537 | |
538 | } | |
539 | ||
540 | //************* fit | |
541 | ||
542 | //___________________________________________________________________________ | |
543 | ||
fabf4d8e | 544 | Double_t AliHFMassFitter::FitFunction4MassDistr (Double_t *x, Double_t *par){ |
545 | // Fit function for signal+background | |
546 | ||
547 | ||
548 | //exponential or linear fit | |
549 | // | |
550 | // par[0] = tot integral | |
551 | // par[1] = slope | |
552 | // par[2] = gaussian integral | |
553 | // par[3] = gaussian mean | |
554 | // par[4] = gaussian sigma | |
555 | ||
556 | Double_t total,bkg=0,sgn=0; | |
557 | ||
558 | if (ftypeOfFit4Bkg==0 || ftypeOfFit4Bkg==1) { | |
559 | if(ftypeOfFit4Sgn == 0) { | |
560 | ||
561 | Double_t parbkg[2] = {par[0]-par[2], par[1]}; | |
562 | bkg = FitFunction4Bkg(x,parbkg); | |
563 | } | |
564 | if(ftypeOfFit4Sgn == 1) { | |
565 | Double_t parbkg[5] = {par[2],par[3],ffactor*par[4],par[0]-2*par[2], par[1]}; | |
566 | bkg = FitFunction4Bkg(x,parbkg); | |
567 | } | |
568 | ||
569 | sgn = FitFunction4Sgn(x,&par[2]); | |
570 | ||
571 | } | |
572 | ||
573 | //polynomial fit | |
574 | ||
575 | // par[0] = tot integral | |
576 | // par[1] = coef1 | |
577 | // par[2] = coef2 | |
578 | // par[3] = gaussian integral | |
579 | // par[4] = gaussian mean | |
580 | // par[5] = gaussian sigma | |
581 | ||
582 | if (ftypeOfFit4Bkg==2) { | |
583 | ||
584 | if(ftypeOfFit4Sgn == 0) { | |
56cbeefb | 585 | |
fabf4d8e | 586 | Double_t parbkg[3] = {par[0]-par[3], par[1], par[2]}; |
587 | bkg = FitFunction4Bkg(x,parbkg); | |
588 | } | |
589 | if(ftypeOfFit4Sgn == 1) { | |
56cbeefb | 590 | |
fabf4d8e | 591 | Double_t parbkg[6] = {par[3],par[4],ffactor*par[5],par[0]-2*par[3], par[1], par[2]}; |
16856d6e | 592 | bkg = FitFunction4Bkg(x,parbkg); |
fabf4d8e | 593 | } |
594 | ||
595 | sgn = FitFunction4Sgn(x,&par[3]); | |
596 | } | |
597 | ||
598 | if (ftypeOfFit4Bkg==3) { | |
599 | ||
600 | if(ftypeOfFit4Sgn == 0) { | |
601 | bkg=FitFunction4Bkg(x,par); | |
602 | sgn=FitFunction4Sgn(x,&par[1]); | |
603 | } | |
604 | if(ftypeOfFit4Sgn == 1) { | |
605 | Double_t parbkg[4]={par[1],par[2],ffactor*par[3],par[0]}; | |
606 | bkg=FitFunction4Bkg(x,parbkg); | |
607 | sgn=FitFunction4Sgn(x,&par[1]); | |
608 | } | |
609 | } | |
610 | ||
611 | total = bkg + sgn; | |
612 | ||
613 | return total; | |
614 | } | |
615 | ||
616 | //_________________________________________________________________________ | |
617 | Double_t AliHFMassFitter::FitFunction4Sgn (Double_t *x, Double_t *par){ | |
618 | // Fit function for the signal | |
619 | ||
620 | //gaussian = A/(sigma*sqrt(2*pi))*exp(-(x-mean)^2/2/sigma^2) | |
621 | //Par: | |
622 | // * [0] = integralSgn | |
623 | // * [1] = mean | |
624 | // * [2] = sigma | |
625 | //gaussian = [0]/TMath::Sqrt(2.*TMath::Pi())/[2]*exp[-(x-[1])*(x-[1])/(2*[2]*[2])] | |
626 | ||
627 | 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]); | |
628 | ||
629 | } | |
630 | ||
631 | //__________________________________________________________________________ | |
632 | ||
633 | Double_t AliHFMassFitter::FitFunction4Bkg (Double_t *x, Double_t *par){ | |
634 | // Fit function for the background | |
635 | ||
636 | Double_t maxDeltaM = 4.*fSigmaSgn; | |
637 | if(fSideBands && TMath::Abs(x[0]-fMass) < maxDeltaM) { | |
638 | TF1::RejectPoint(); | |
639 | return 0; | |
640 | } | |
641 | Int_t firstPar=0; | |
642 | Double_t gaus2=0,total=-1; | |
643 | if(ftypeOfFit4Sgn == 1){ | |
644 | firstPar=3; | |
645 | //gaussian = A/(sigma*sqrt(2*pi))*exp(-(x-mean)^2/2/sigma^2) | |
646 | //Par: | |
647 | // * [0] = integralSgn | |
648 | // * [1] = mean | |
649 | // * [2] = sigma | |
650 | //gaussian = [0]/TMath::Sqrt(2.*TMath::Pi())/[2]*exp[-(x-[1])*(x-[1])/(2*[2]*[2])] | |
651 | gaus2 = FitFunction4Sgn(x,par); | |
652 | } | |
653 | ||
654 | switch (ftypeOfFit4Bkg){ | |
655 | case 0: | |
656 | //exponential | |
657 | //exponential = A*exp(B*x) -> integral(exponential)=A/B*exp(B*x)](min,max) | |
658 | //-> A = B*integral/(exp(B*max)-exp(B*min)) where integral can be written | |
659 | //as integralTot- integralGaus (=par [2]) | |
660 | //Par: | |
661 | // * [0] = integralBkg; | |
662 | // * [1] = B; | |
663 | //exponential = [1]*[0]/(exp([1]*max)-exp([1]*min))*exp([1]*x) | |
664 | 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]); | |
665 | break; | |
666 | case 1: | |
667 | //linear | |
668 | //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) | |
669 | // * [0] = integralBkg; | |
670 | // * [1] = b; | |
671 | total= par[0+firstPar]/(fmaxMass-fminMass)+par[1+firstPar]*(x[0]-0.5*(fmaxMass+fminMass)); | |
672 | break; | |
673 | case 2: | |
674 | //polynomial | |
675 | //y=a+b*x+c*x**2 -> integral = a(max-min) + 1/2*b*(max^2-min^2) + | |
676 | //+ 1/3*c*(max^3-min^3) -> | |
677 | //a = (integral-1/2*b*(max^2-min^2)-1/3*c*(max^3-min^3))/(max-min) | |
678 | // * [0] = integralBkg; | |
679 | // * [1] = b; | |
680 | // * [2] = c; | |
681 | 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)); | |
682 | break; | |
683 | case 3: | |
684 | total=par[0+firstPar]; | |
685 | break; | |
686 | // default: | |
687 | // Types of Fit Functions for Background: | |
688 | // * 0 = exponential; | |
689 | // * 1 = linear; | |
690 | // * 2 = polynomial 2nd order | |
691 | // * 3 = no background"<<endl; | |
692 | ||
693 | } | |
694 | return total+gaus2; | |
695 | } | |
696 | ||
b7d4bc49 | 697 | //__________________________________________________________________________ |
698 | Bool_t AliHFMassFitter::SideBandsBounds(){ | |
699 | ||
dc262918 | 700 | //determines the ranges of the side bands |
701 | ||
b7d4bc49 | 702 | Double_t width=fhistoInvMass->GetBinWidth(8); |
703 | if (fNbin==0) fNbin=fhistoInvMass->GetNbinsX(); | |
704 | Double_t minHisto=fhistoInvMass->GetBinLowEdge(1); | |
705 | Double_t maxHisto=fhistoInvMass->GetBinLowEdge(fNbin)+width; | |
706 | ||
707 | if(fMass-fminMass < 0 || fmaxMass-fMass <0) { | |
708 | cout<<"Left limit of range > mean or right limit of range < mean: change left/right limit or initial mean value"<<endl; | |
709 | return kFALSE; | |
710 | } | |
711 | ||
dc262918 | 712 | if((TMath::Abs(fminMass-minHisto) < 10e6 || TMath::Abs(fmaxMass - maxHisto) < 10e6) && (fMass-4.*fSigmaSgn-fminMass) < 10e6){ |
b7d4bc49 | 713 | Double_t coeff = (fMass-fminMass)/fSigmaSgn; |
714 | ||
715 | fSideBandl=(Int_t)((fMass-0.5*coeff*fSigmaSgn-fminMass)/width); | |
716 | fSideBandr=(Int_t)((fMass+0.5*coeff*fSigmaSgn-fminMass)/width); | |
717 | cout<<"Changed number of sigma from 4 to "<<0.5*coeff<<" for the estimation of the side bands"<<endl; | |
718 | if (coeff<3) cout<<"Side bands inside 3 sigma, may be better use ftypeOfFit4Bkg = 3 (only signal)"<<endl; | |
719 | ||
720 | if (coeff<2) { | |
721 | cout<<"Side bands inside 2 sigma. Change mode: ftypeOfFit4Bkg = 3"<<endl; | |
722 | ftypeOfFit4Bkg=3; | |
723 | //set binleft and right without considering SetRangeFit- anyway no bkg! | |
724 | fSideBandl=(Int_t)((fMass-4.*fSigmaSgn-minHisto)/width); | |
725 | fSideBandr=(Int_t)((fMass+4.*fSigmaSgn-minHisto)/width); | |
726 | } | |
727 | } | |
728 | else { | |
729 | fSideBandl=(Int_t)((fMass-4.*fSigmaSgn-minHisto)/width); | |
730 | fSideBandr=(Int_t)((fMass+4.*fSigmaSgn-minHisto)/width); | |
a60f573d | 731 | // cout<<"\tfMass = "<<fMass<<"\tfSigmaSgn = "<<fSigmaSgn<<"\tminHisto = "<<minHisto<<endl; |
732 | // cout<<"\tbinleft = "<<fSideBandl<<"\tbinright = "<<fSideBandr<<endl; | |
b7d4bc49 | 733 | } |
734 | ||
735 | if (fSideBandl==0) { | |
736 | cout<<"Error! Range too little"; | |
737 | return kFALSE; | |
738 | } | |
b7d4bc49 | 739 | return kTRUE; |
740 | } | |
741 | ||
16856d6e | 742 | //__________________________________________________________________________ |
743 | ||
b7d4bc49 | 744 | void AliHFMassFitter::GetSideBandsBounds(Int_t &left, Int_t &right) const{ |
dc262918 | 745 | |
746 | // get the range of the side bands | |
747 | ||
b7d4bc49 | 748 | if (fSideBandl==0 && fSideBandr==0){ |
749 | cout<<"Use MassFitter method first"<<endl; | |
750 | return; | |
751 | } | |
752 | left=fSideBandl; | |
753 | right=fSideBandr; | |
754 | } | |
755 | ||
d22f0682 | 756 | //__________________________________________________________________________ |
757 | Bool_t AliHFMassFitter::CheckRangeFit(){ | |
758 | //check if the limit of the range correspond to the limit of bins. If not reset the limit to the nearer value which satisfy this condition | |
759 | ||
760 | if (!fhistoInvMass) { | |
761 | cout<<"No histogram to fit! SetHisto(TH1F* h) before! "<<endl; | |
762 | return kFALSE; | |
763 | } | |
764 | Bool_t leftok=kFALSE, rightok=kFALSE; | |
765 | Int_t nbins=fhistoInvMass->GetNbinsX(); | |
766 | Double_t width=fhistoInvMass->GetBinWidth(1); | |
767 | Double_t minhisto=fhistoInvMass->GetBinLowEdge(1), maxhisto=fhistoInvMass->GetBinLowEdge(nbins)+width; | |
768 | ||
769 | //check if limits are inside histogram range | |
770 | if( fminMass-minhisto < 0. ) { | |
771 | cout<<"Out of histogram left bound!"<<endl; | |
772 | fminMass=minhisto; | |
773 | } | |
774 | if( fmaxMass-maxhisto > 0. ) { | |
775 | cout<<"Out of histogram right bound!"<<endl; | |
776 | fmaxMass=maxhisto; | |
777 | } | |
778 | ||
779 | Int_t binl,binr; | |
780 | Double_t tmp=0.; | |
781 | tmp=fminMass; | |
782 | //calculate bin corresponding to fminMass | |
783 | binl=fhistoInvMass->FindBin(fminMass); | |
784 | if (fminMass > fhistoInvMass->GetBinCenter(binl)) binl++; | |
785 | fminMass=fhistoInvMass->GetBinLowEdge(binl); | |
786 | if(TMath::Abs(tmp-fminMass) > 1e-6){ | |
787 | cout<<"Left bound "<<tmp<<" is not allowed, changing it to the nearest value allowed: "<<fminMass<<endl; | |
788 | leftok=kTRUE; | |
789 | } | |
790 | ||
791 | tmp=fmaxMass; | |
792 | //calculate bin corresponding to fmaxMass | |
793 | binr=fhistoInvMass->FindBin(fmaxMass); | |
794 | if (fmaxMass < fhistoInvMass->GetBinCenter(binr)) binr--; | |
795 | fmaxMass=fhistoInvMass->GetBinLowEdge(binr)+width; | |
796 | if(TMath::Abs(tmp-fmaxMass) > 1e-6){ | |
797 | cout<<"Right bound "<<tmp<<" is not allowed, changing it to the nearest value allowed: "<<fmaxMass<<endl; | |
798 | rightok=kTRUE; | |
799 | } | |
800 | ||
801 | return (leftok && rightok); | |
802 | ||
803 | } | |
804 | ||
fabf4d8e | 805 | //__________________________________________________________________________ |
806 | ||
34c79b83 | 807 | Bool_t AliHFMassFitter::MassFitter(Bool_t draw){ |
fabf4d8e | 808 | // Main method of the class: performs the fit of the histogram |
ad73ca8f | 809 | |
810 | //Set default fitter Minuit in order to use gMinuit in the contour plots | |
811 | TVirtualFitter::SetDefaultFitter("Minuit"); | |
812 | ||
fabf4d8e | 813 | Int_t nFitPars=0; //total function's number of parameters |
814 | switch (ftypeOfFit4Bkg){ | |
815 | case 0: | |
816 | nFitPars=5; //3+2 | |
817 | break; | |
818 | case 1: | |
819 | nFitPars=5; //3+2 | |
820 | break; | |
821 | case 2: | |
822 | nFitPars=6; //3+3 | |
823 | break; | |
824 | case 3: | |
825 | nFitPars=4; //3+1 | |
826 | break; | |
827 | } | |
828 | ||
829 | Int_t bkgPar = nFitPars-3; //background function's number of parameters | |
830 | ||
831 | cout<<"nFitPars = "<<nFitPars<<"\tbkgPar = "<<bkgPar<<endl; | |
832 | ||
ad73ca8f | 833 | |
834 | TString listname="contourplot"; | |
835 | listname+=fcounter; | |
836 | if(!fContourGraph){ | |
837 | fContourGraph=new TList(); | |
838 | fContourGraph->SetOwner(); | |
839 | } | |
840 | ||
841 | fContourGraph->SetName(listname); | |
842 | ||
843 | ||
56cbeefb | 844 | //function names |
845 | TString bkgname="funcbkg"; | |
846 | TString bkg1name="funcbkg1"; | |
847 | TString massname="funcmass"; | |
848 | ||
fabf4d8e | 849 | //Total integral |
d22f0682 | 850 | Double_t totInt = fhistoInvMass->Integral(fhistoInvMass->FindBin(fminMass), fhistoInvMass->FindBin(fmaxMass), "width"); |
fabf4d8e | 851 | |
852 | fSideBands = kTRUE; | |
34c79b83 | 853 | Double_t width=fhistoInvMass->GetBinWidth(8); |
ad73ca8f | 854 | cout<<"fNbin"<<fNbin<<endl; |
34c79b83 | 855 | if (fNbin==0) fNbin=fhistoInvMass->GetNbinsX(); |
d22f0682 | 856 | //Double_t minHisto=fhistoInvMass->GetBinLowEdge(1); |
857 | //Double_t maxHisto=fhistoInvMass->GetBinLowEdge(fNbin)+width; | |
b7d4bc49 | 858 | Bool_t ok=SideBandsBounds(); |
859 | if(!ok) return kFALSE; | |
34c79b83 | 860 | |
fabf4d8e | 861 | //sidebands integral - first approx (from histo) |
b7d4bc49 | 862 | Double_t sideBandsInt=(Double_t)fhistoInvMass->Integral(1,fSideBandl,"width") + (Double_t)fhistoInvMass->Integral(fSideBandr,fNbin,"width"); |
863 | cout<<"------nbin = "<<fNbin<<"\twidth = "<<width<<"\tbinleft = "<<fSideBandl<<"\tbinright = "<<fSideBandr<<endl; | |
fabf4d8e | 864 | cout<<"------sideBandsInt - first approx = "<<sideBandsInt<<endl; |
b7d4bc49 | 865 | if (sideBandsInt<=0) { |
866 | cout<<"! sideBandsInt <=0. There's a problem, cannot start the fit"<<endl; | |
867 | return kFALSE; | |
868 | } | |
869 | ||
fabf4d8e | 870 | /*Fit Bkg*/ |
871 | ||
16856d6e | 872 | |
d22f0682 | 873 | TF1 *funcbkg = new TF1(bkgname.Data(),this,&AliHFMassFitter::FitFunction4Bkg,fminMass,fmaxMass,bkgPar,"AliHFMassFitter","FitFunction4Bkg"); |
56cbeefb | 874 | cout<<"Function name = "<<funcbkg->GetName()<<endl<<endl; |
fabf4d8e | 875 | |
876 | funcbkg->SetLineColor(2); //red | |
877 | ||
878 | //first fit for bkg: approx bkgint | |
879 | ||
880 | switch (ftypeOfFit4Bkg) { | |
881 | case 0: //gaus+expo | |
882 | funcbkg->SetParNames("BkgInt","Slope"); | |
883 | funcbkg->SetParameters(sideBandsInt,-2.); | |
884 | break; | |
885 | case 1: | |
886 | funcbkg->SetParNames("BkgInt","Slope"); | |
887 | funcbkg->SetParameters(sideBandsInt,-100.); | |
888 | break; | |
889 | case 2: | |
890 | funcbkg->SetParNames("BkgInt","Coef1","Coef2"); | |
891 | funcbkg->SetParameters(sideBandsInt,-10.,5); | |
892 | break; | |
893 | case 3: | |
894 | if(ftypeOfFit4Sgn==0){ | |
fabf4d8e | 895 | funcbkg->SetParNames("Const"); |
896 | funcbkg->SetParameter(0,0.); | |
897 | funcbkg->FixParameter(0,0.); | |
898 | } | |
899 | break; | |
900 | default: | |
901 | cout<<"Wrong choise of ftypeOfFit4Bkg ("<<ftypeOfFit4Bkg<<")"<<endl; | |
34c79b83 | 902 | return kFALSE; |
fabf4d8e | 903 | break; |
904 | } | |
905 | cout<<"\nBACKGROUND FIT - only combinatorial"<<endl; | |
906 | Int_t ftypeOfFit4SgnBkp=ftypeOfFit4Sgn; | |
907 | ||
908 | Double_t intbkg1=0,slope1=0,conc1=0; | |
56cbeefb | 909 | //if only signal and reflection: skip |
fabf4d8e | 910 | if (!(ftypeOfFit4Bkg==3 && ftypeOfFit4Sgn==1)) { |
911 | ftypeOfFit4Sgn=0; | |
56cbeefb | 912 | fhistoInvMass->Fit(bkgname.Data(),"R,L,E,0"); |
fabf4d8e | 913 | |
914 | for(Int_t i=0;i<bkgPar;i++){ | |
915 | fFitPars[i]=funcbkg->GetParameter(i); | |
916 | //cout<<i<<"\t"<<funcbkg->GetParameter(i)<<"\t"; | |
917 | fFitPars[nFitPars+2*bkgPar+3+i]= funcbkg->GetParError(i); | |
918 | //cout<<nFitPars+2*bkgPar+3+i<<"\t"<< funcbkg->GetParError(i)<<endl; | |
919 | } | |
b7d4bc49 | 920 | fSideBands = kFALSE; |
34c79b83 | 921 | //intbkg1 = funcbkg->GetParameter(0); |
922 | funcbkg->SetRange(fminMass,fmaxMass); | |
923 | intbkg1 = funcbkg->Integral(fminMass,fmaxMass); | |
fabf4d8e | 924 | if(ftypeOfFit4Bkg!=3) slope1 = funcbkg->GetParameter(1); |
925 | if(ftypeOfFit4Bkg==2) conc1 = funcbkg->GetParameter(2); | |
6321ee46 | 926 | cout<<"First fit: \nintbkg1 = "<<intbkg1<<"\t(Compare with par0 = "<<funcbkg->GetParameter(0)<<")\nslope1= "<<slope1<<"\nconc1 = "<<conc1<<endl; |
56cbeefb | 927 | } |
928 | else cout<<"\t\t//"<<endl; | |
fabf4d8e | 929 | |
930 | ftypeOfFit4Sgn=ftypeOfFit4SgnBkp; | |
931 | TF1 *funcbkg1=0; | |
932 | if (ftypeOfFit4Sgn == 1) { | |
933 | cout<<"\nBACKGROUND FIT WITH REFLECTION"<<endl; | |
934 | bkgPar+=3; | |
935 | ||
56cbeefb | 936 | cout<<"nFitPars = "<<nFitPars<<"\tbkgPar = "<<bkgPar<<endl; |
937 | ||
938 | funcbkg1 = new TF1(bkg1name.Data(),this,&AliHFMassFitter::FitFunction4Bkg,fminMass,fmaxMass,bkgPar,"AliHFMassFitter","FitFunction4Bkg"); | |
939 | cout<<"Function name = "<<funcbkg1->GetName()<<endl; | |
940 | ||
fabf4d8e | 941 | funcbkg1->SetLineColor(2); //red |
942 | ||
943 | if(ftypeOfFit4Bkg==2){ | |
944 | cout<<"*** Polynomial Fit ***"<<endl; | |
945 | funcbkg1->SetParNames("IntGB","MeanGB","SigmaGB","BkgInt","Coef1","Coef2"); | |
946 | funcbkg1->SetParameters(0.5*(totInt-intbkg1),fMass,ffactor*fSigmaSgn,intbkg1,slope1,conc1); | |
6321ee46 | 947 | |
948 | //cout<<"Parameters set to: "<<0.5*(totInt-intbkg1)<<"\t"<<fMass<<"\t"<<ffactor*fSigmaSgn<<"\t"<<intbkg1<<"\t"<<slope1<<"\t"<<conc1<<"\t"<<endl; | |
949 | //cout<<"Limits: ("<<fminMass<<","<<fmaxMass<<")\tnPar = "<<bkgPar<<"\tgsidebands = "<<fSideBands<<endl; | |
fabf4d8e | 950 | } else{ |
951 | if(ftypeOfFit4Bkg==3) //no background: gaus sign+ gaus broadened | |
952 | { | |
953 | cout<<"*** No background Fit ***"<<endl; | |
954 | funcbkg1->SetParNames("IntGB","MeanGB","SigmaGB","Const"); | |
955 | funcbkg1->SetParameters(0.5*totInt,fMass,ffactor*fSigmaSgn,0.); | |
956 | funcbkg1->FixParameter(3,0.); | |
957 | } else{ //expo or linear | |
958 | if(ftypeOfFit4Bkg==0) cout<<"*** Exponential Fit ***"<<endl; | |
959 | if(ftypeOfFit4Bkg==1) cout<<"*** Linear Fit ***"<<endl; | |
960 | funcbkg1->SetParNames("IntGB","MeanGB","SigmaGB","BkgInt","Slope"); | |
961 | funcbkg1->SetParameters(0.5*(totInt-intbkg1),fMass,ffactor*fSigmaSgn,intbkg1,slope1); | |
962 | } | |
963 | } | |
6321ee46 | 964 | Int_t status=fhistoInvMass->Fit(bkg1name.Data(),"R,L,E,+,0"); |
965 | if (status != 0){ | |
966 | cout<<"Minuit returned "<<status<<endl; | |
967 | return kFALSE; | |
968 | } | |
969 | ||
fabf4d8e | 970 | for(Int_t i=0;i<bkgPar;i++){ |
971 | fFitPars[bkgPar-3+i]=funcbkg1->GetParameter(i); | |
972 | //cout<<bkgPar-3+i<<"\t"<<funcbkg1->GetParameter(i); | |
973 | fFitPars[nFitPars+3*bkgPar-6+i]= funcbkg1->GetParError(i); | |
56cbeefb | 974 | //cout<<"\t"<<nFitPars+3*bkgPar-6+i<<"\t"<<funcbkg1->GetParError(i)<<endl; |
fabf4d8e | 975 | } |
976 | ||
977 | intbkg1=funcbkg1->GetParameter(3); | |
978 | if(ftypeOfFit4Bkg!=3) slope1 = funcbkg1->GetParameter(4); | |
979 | if(ftypeOfFit4Bkg==2) conc1 = funcbkg1->GetParameter(5); | |
980 | ||
981 | } else { | |
982 | bkgPar+=3; | |
983 | ||
984 | for(Int_t i=0;i<3;i++){ | |
985 | fFitPars[bkgPar-3+i]=0.; | |
56cbeefb | 986 | cout<<bkgPar-3+i<<"\t"<<0.<<"\t"; |
fabf4d8e | 987 | fFitPars[nFitPars+3*bkgPar-6+i]= 0.; |
56cbeefb | 988 | cout<<nFitPars+3*bkgPar-6+i<<"\t"<<0.<<endl; |
fabf4d8e | 989 | } |
990 | ||
991 | for(Int_t i=0;i<bkgPar-3;i++){ | |
992 | fFitPars[bkgPar+i]=funcbkg->GetParameter(i); | |
56cbeefb | 993 | cout<<bkgPar+i<<"\t"<<funcbkg->GetParameter(i)<<"\t"; |
fabf4d8e | 994 | fFitPars[nFitPars+3*bkgPar-3+i]= funcbkg->GetParError(i); |
56cbeefb | 995 | cout<<nFitPars+3*bkgPar-3+i<<"\t"<< funcbkg->GetParError(i)<<endl; |
fabf4d8e | 996 | } |
997 | ||
998 | ||
999 | } | |
1000 | ||
1001 | //sidebands integral - second approx (from fit) | |
1002 | fSideBands = kFALSE; | |
1003 | Double_t bkgInt; | |
b7d4bc49 | 1004 | cout<<"Compare intbkg1 = "<<intbkg1<<" and integral = "; |
fabf4d8e | 1005 | if(ftypeOfFit4Sgn == 1) bkgInt=funcbkg1->Integral(fminMass,fmaxMass); |
1006 | else bkgInt=funcbkg->Integral(fminMass,fmaxMass); | |
b7d4bc49 | 1007 | cout<</*"------BkgInt(Fit) = "<<*/bkgInt<<endl; |
fabf4d8e | 1008 | |
1009 | //Signal integral - first approx | |
1010 | Double_t sgnInt; | |
1011 | sgnInt = totInt-bkgInt; | |
1012 | cout<<"------TotInt = "<<totInt<<"\tsgnInt = "<<sgnInt<<endl; | |
6321ee46 | 1013 | if (sgnInt <= 0){ |
1014 | cout<<"Setting sgnInt = - sgnInt"<<endl; | |
1015 | sgnInt=- sgnInt; | |
1016 | } | |
fabf4d8e | 1017 | /*Fit All Mass distribution with exponential + gaussian (+gaussiam braodened) */ |
56cbeefb | 1018 | TF1 *funcmass = new TF1(massname.Data(),this,&AliHFMassFitter::FitFunction4MassDistr,fminMass,fmaxMass,nFitPars,"AliHFMassFitter","FitFunction4MassDistr"); |
1019 | cout<<"Function name = "<<funcmass->GetName()<<endl<<endl; | |
fabf4d8e | 1020 | funcmass->SetLineColor(4); //blue |
1021 | ||
1022 | //Set parameters | |
1023 | cout<<"\nTOTAL FIT"<<endl; | |
1024 | ||
1025 | if(nFitPars==5){ | |
1026 | funcmass->SetParNames("TotInt","Slope","SgnInt","Mean","Sigma"); | |
1027 | funcmass->SetParameters(totInt,slope1,sgnInt,fMass,fSigmaSgn); | |
3c0e7d59 | 1028 | |
56cbeefb | 1029 | //cout<<"Parameters set to: "<<totInt<<"\t"<<slope1<<"\t"<<sgnInt<<"\t"<<fMass<<"\t"<<fSigmaSgn<<"\t"<<endl; |
6321ee46 | 1030 | //cout<<"Limits: ("<<fminMass<<","<<fmaxMass<<")\tnPar = "<<nFitPars<<"\tgsidebands = "<<fSideBands<<endl; |
a12d80b8 | 1031 | if(fFixPar[0]){ |
1032 | cout<<"fix1"<<endl; | |
1033 | funcmass->FixParameter(0,totInt); | |
1034 | } | |
1035 | if(fFixPar[1]){ | |
1036 | cout<<"fix2"<<endl; | |
1037 | funcmass->FixParameter(1,slope1); | |
1038 | } | |
1039 | if(fFixPar[2]){ | |
1040 | cout<<"fix3"<<endl; | |
1041 | funcmass->FixParameter(2,sgnInt); | |
1042 | } | |
1043 | if(fFixPar[3]){ | |
1044 | cout<<"fix4"<<endl; | |
1045 | funcmass->FixParameter(3,fMass); | |
1046 | } | |
1047 | if(fFixPar[4]){ | |
1048 | cout<<"fix5"<<endl; | |
1049 | funcmass->FixParameter(4,fSigmaSgn); | |
1050 | } | |
fabf4d8e | 1051 | } |
1052 | if (nFitPars==6){ | |
1053 | funcmass->SetParNames("TotInt","Coef1","Coef2","SgnInt","Mean","Sigma"); | |
1054 | funcmass->SetParameters(totInt,slope1,conc1,sgnInt,fMass,fSigmaSgn); | |
3c0e7d59 | 1055 | |
6321ee46 | 1056 | //cout<<"Parameters set to: "<<totInt<<"\t"<<slope1<<"\t"<<conc1<<"\t"<<sgnInt<<"\t"<<fMass<<"\t"<<fSigmaSgn<<"\t"<<endl; |
1057 | //cout<<"Limits: ("<<fminMass<<","<<fmaxMass<<")\tnPar = "<<nFitPars<<"\tgsidebands = "<<fSideBands<<endl; | |
3c0e7d59 | 1058 | if(fFixPar[0])funcmass->FixParameter(0,totInt); |
1059 | if(fFixPar[1])funcmass->FixParameter(1,slope1); | |
1060 | if(fFixPar[2])funcmass->FixParameter(2,conc1); | |
1061 | if(fFixPar[3])funcmass->FixParameter(3,sgnInt); | |
1062 | if(fFixPar[4])funcmass->FixParameter(4,fMass); | |
1063 | if(fFixPar[5])funcmass->FixParameter(5,fSigmaSgn); | |
1064 | // | |
1065 | //funcmass->FixParameter(2,sgnInt); | |
fabf4d8e | 1066 | } |
1067 | if(nFitPars==4){ | |
1068 | funcmass->SetParNames("Const","SgnInt","Mean","Sigma"); | |
56cbeefb | 1069 | if(ftypeOfFit4Sgn == 1) funcmass->SetParameters(0.,0.5*totInt,fMass,fSigmaSgn); |
1070 | else funcmass->SetParameters(0.,totInt,fMass,fSigmaSgn); | |
3c0e7d59 | 1071 | if(fFixPar[0]) funcmass->FixParameter(0,0.); |
fabf4d8e | 1072 | //cout<<"Parameters set to: "<<0.5*totInt<<"\t"<<fMass<<"\t"<<fSigmaSgn<<"\t"<<endl; |
1073 | //cout<<"Limits: ("<<fminMass<<","<<fmaxMass<<")\tnPar = "<<nFitPars<<"\tgsidebands = "<<fSideBands<<endl; | |
1074 | ||
1075 | } | |
3c0e7d59 | 1076 | //funcmass->FixParameter(nFitPars-2,fMass); |
1077 | //funcmass->SetParLimits(nFitPars-1,0.007,0.05); | |
1078 | //funcmass->SetParLimits(nFitPars-2,fMass-0.01,fMass+0.01); | |
6321ee46 | 1079 | Int_t status; |
1080 | ||
1081 | status = fhistoInvMass->Fit(massname.Data(),"R,L,E,+,0"); | |
1082 | if (status != 0){ | |
1083 | cout<<"Minuit returned "<<status<<endl; | |
1084 | return kFALSE; | |
1085 | } | |
1086 | ||
fabf4d8e | 1087 | cout<<"fit done"<<endl; |
0566386c | 1088 | //reset value of fMass and fSigmaSgn to those found from fit |
1089 | fMass=funcmass->GetParameter(nFitPars-2); | |
1090 | fSigmaSgn=funcmass->GetParameter(nFitPars-1); | |
fabf4d8e | 1091 | |
1092 | for(Int_t i=0;i<nFitPars;i++){ | |
1093 | fFitPars[i+2*bkgPar-3]=funcmass->GetParameter(i); | |
1094 | fFitPars[nFitPars+4*bkgPar-6+i]= funcmass->GetParError(i); | |
56cbeefb | 1095 | //cout<<i+2*bkgPar-3<<"\t"<<funcmass->GetParameter(i)<<"\t\t"<<nFitPars+4*bkgPar-6+i<<"\t"<<funcmass->GetParError(i)<<endl; |
fabf4d8e | 1096 | } |
1097 | /* | |
1098 | //check: cout parameters | |
1099 | for(Int_t i=0;i<2*(nFitPars+2*bkgPar-3);i++){ | |
1100 | cout<<i<<"\t"<<fFitPars[i]<<endl; | |
1101 | } | |
1102 | */ | |
74179930 | 1103 | |
a60f573d | 1104 | // if(draw){ |
1105 | // TCanvas *canvas=new TCanvas(fhistoInvMass->GetName(),fhistoInvMass->GetName()); | |
1106 | // TH1F *fhistocopy=new TH1F(*fhistoInvMass); | |
1107 | // canvas->cd(); | |
1108 | // fhistocopy->DrawClone(); | |
1109 | // if(ftypeOfFit4Sgn == 1) funcbkg1->DrawClone("sames"); | |
1110 | // else funcbkg->DrawClone("sames"); | |
1111 | // funcmass->DrawClone("sames"); | |
1112 | // cout<<"Drawn"<<endl; | |
1113 | // } | |
1114 | ||
1115 | if(funcmass->GetParameter(nFitPars-1) <0 || funcmass->GetParameter(nFitPars-2) <0 || funcmass->GetParameter(nFitPars-3) <0 ) { | |
1116 | cout<<"IntS or mean or sigma negative. You may tray to SetInitialGaussianSigma(..) and SetInitialGaussianMean(..)"<<endl; | |
b7d4bc49 | 1117 | return kFALSE; |
1118 | } | |
0566386c | 1119 | |
56cbeefb | 1120 | //increase counter of number of fits done |
1121 | fcounter++; | |
1122 | ||
ad73ca8f | 1123 | //contour plots |
1124 | if(draw){ | |
1125 | ||
1126 | for (Int_t kpar=1; kpar<nFitPars;kpar++){ | |
1127 | ||
1128 | for(Int_t jpar=kpar+1;jpar<nFitPars;jpar++){ | |
1129 | cout<<"Par "<<kpar<<" and "<<jpar<<endl; | |
1130 | ||
1131 | // produce 2 contours per couple of parameters | |
1132 | TGraph* cont[2] = {0x0, 0x0}; | |
1133 | const Double_t errDef[2] = {1., 4.}; | |
1134 | for (Int_t i=0; i<2; i++) { | |
1135 | gMinuit->SetErrorDef(errDef[i]); | |
1136 | cont[i] = (TGraph*)gMinuit->Contour(80,kpar,jpar); | |
6321ee46 | 1137 | cout<<"Minuit Status = "<<gMinuit->GetStatus()<<endl; |
ad73ca8f | 1138 | } |
1139 | ||
1140 | if(!cont[0] || !cont[1]){ | |
1141 | cout<<"Skipping par "<<kpar<<" vs par "<<jpar<<endl; | |
1142 | continue; | |
1143 | } | |
1144 | ||
1145 | // set graph titles and add them to the list | |
1146 | TString title = "Contour plot"; | |
1147 | TString titleX = funcmass->GetParName(kpar); | |
1148 | TString titleY = funcmass->GetParName(jpar); | |
1149 | for (Int_t i=0; i<2; i++) { | |
1150 | cont[i]->SetName( Form("cperr%d_%d%d", i, kpar, jpar) ); | |
1151 | cont[i]->SetTitle(title); | |
1152 | cont[i]->GetXaxis()->SetTitle(titleX); | |
1153 | cont[i]->GetYaxis()->SetTitle(titleY); | |
1154 | cont[i]->GetYaxis()->SetLabelSize(0.033); | |
1155 | cont[i]->GetYaxis()->SetTitleSize(0.033); | |
1156 | cont[i]->GetYaxis()->SetTitleOffset(1.67); | |
1157 | ||
1158 | fContourGraph->Add(cont[i]); | |
1159 | } | |
1160 | ||
1161 | // plot them | |
1162 | TString cvname = Form("c%d%d", kpar, jpar); | |
1163 | TCanvas *c4=new TCanvas(cvname,cvname,600,600); | |
1164 | c4->cd(); | |
1165 | cont[1]->SetFillColor(38); | |
1166 | cont[1]->Draw("alf"); | |
1167 | cont[0]->SetFillColor(9); | |
1168 | cont[0]->Draw("lf"); | |
1169 | ||
1170 | } | |
1171 | ||
1172 | } | |
1173 | ||
1174 | } | |
1175 | ||
a60f573d | 1176 | if (ftypeOfFit4Sgn == 1 && funcbkg1) { |
1177 | delete funcbkg1; | |
1178 | funcbkg1=NULL; | |
1179 | } | |
1180 | if (funcbkg) { | |
1181 | delete funcbkg; | |
1182 | funcbkg=NULL; | |
1183 | } | |
1184 | if (funcmass) { | |
1185 | delete funcmass; | |
1186 | funcmass=NULL; | |
1187 | } | |
16856d6e | 1188 | |
1189 | AddFunctionsToHisto(); | |
a60f573d | 1190 | if (draw) DrawFit(); |
16856d6e | 1191 | |
1192 | ||
34c79b83 | 1193 | return kTRUE; |
1194 | } | |
1195 | //_________________________________________________________________________ | |
1196 | Double_t AliHFMassFitter::GetChiSquare() const{ | |
1197 | TF1 *funcmass=(TF1*)fhistoInvMass->GetFunction("funcmass"); | |
1198 | return funcmass->GetChisquare(); | |
fabf4d8e | 1199 | } |
56cbeefb | 1200 | |
b7d4bc49 | 1201 | //_________________________________________________________________________ |
1202 | Double_t AliHFMassFitter::GetReducedChiSquare() const{ | |
1203 | TF1 *funcmass=(TF1*)fhistoInvMass->GetFunction("funcmass"); | |
1204 | return funcmass->GetChisquare()/funcmass->GetNDF(); | |
1205 | } | |
1206 | ||
56cbeefb | 1207 | //*********output |
1208 | ||
fabf4d8e | 1209 | //_________________________________________________________________________ |
2f328d65 | 1210 | void AliHFMassFitter::GetFitPars(Float_t *vector) const { |
fabf4d8e | 1211 | // Return fit parameters |
a12d80b8 | 1212 | |
2f328d65 | 1213 | for(Int_t i=0;i<fParsSize;i++){ |
1214 | vector[i]=fFitPars[i]; | |
fabf4d8e | 1215 | } |
1216 | } | |
fabf4d8e | 1217 | |
fabf4d8e | 1218 | |
6321ee46 | 1219 | //_________________________________________________________________________ |
dc262918 | 1220 | void AliHFMassFitter::IntS(Float_t *valuewitherror) const { |
1221 | ||
1222 | //gives the integral of signal obtained from fit parameters | |
a12d80b8 | 1223 | if(!valuewitherror)valuewitherror=new Float_t[2]; |
dc262918 | 1224 | |
6321ee46 | 1225 | Int_t index=fParsSize/2 - 3; |
1226 | valuewitherror[0]=fFitPars[index]; | |
1227 | index=fParsSize - 3; | |
1228 | valuewitherror[1]=fFitPars[index]; | |
1229 | } | |
1230 | ||
1231 | ||
16856d6e | 1232 | //_________________________________________________________________________ |
1233 | void AliHFMassFitter::AddFunctionsToHisto(){ | |
fabf4d8e | 1234 | |
dc262918 | 1235 | //Add the background function in the complete range to the list of functions attached to the histogram |
1236 | ||
16856d6e | 1237 | cout<<"AddFunctionsToHisto called"<<endl; |
56cbeefb | 1238 | TString bkgname = "funcbkg"; |
ab0fa301 | 1239 | Int_t np=-99; |
56cbeefb | 1240 | switch (ftypeOfFit4Bkg){ |
16856d6e | 1241 | case 0: //expo |
56cbeefb | 1242 | np=2; |
1243 | break; | |
16856d6e | 1244 | case 1: //linear |
56cbeefb | 1245 | np=2; |
1246 | break; | |
16856d6e | 1247 | case 2: //pol2 |
56cbeefb | 1248 | np=3; |
1249 | break; | |
16856d6e | 1250 | case 3: //no bkg |
56cbeefb | 1251 | np=1; |
1252 | break; | |
1253 | } | |
1254 | if (ftypeOfFit4Sgn == 1) { | |
1255 | bkgname += 1; | |
1256 | np+=3; | |
1257 | } | |
16856d6e | 1258 | |
1259 | TString bkgnamesave=bkgname; | |
1260 | TString testname=bkgname; | |
1261 | testname += "FullRange"; | |
1262 | TF1 *testfunc=(TF1*)fhistoInvMass->FindObject(testname.Data()); | |
1263 | if(testfunc){ | |
1264 | cout<<"AddFunctionsToHisto already used: exiting...."<<endl; | |
1265 | return; | |
1266 | } | |
1267 | ||
1268 | TList *hlist=fhistoInvMass->GetListOfFunctions(); | |
34c79b83 | 1269 | hlist->ls(); |
16856d6e | 1270 | |
34c79b83 | 1271 | TF1 *b=(TF1*)hlist->FindObject(bkgname.Data()); |
a60f573d | 1272 | if(!b){ |
1273 | cout<<bkgname<<" not found, cannot produce "<<bkgname<<"FullRange and "<<bkgname<<"Recalc"<<endl; | |
1274 | return; | |
1275 | } | |
1276 | ||
56cbeefb | 1277 | bkgname += "FullRange"; |
16856d6e | 1278 | TF1 *bfullrange=new TF1(bkgname.Data(),this,&AliHFMassFitter::FitFunction4Bkg,fminMass,fmaxMass,np,"AliHFMassFitter","FitFunction4Bkg"); |
1279 | //cout<<bfullrange->GetName()<<endl; | |
56cbeefb | 1280 | for(Int_t i=0;i<np;i++){ |
16856d6e | 1281 | //cout<<i<<" di "<<np<<endl; |
1282 | bfullrange->SetParName(i,b->GetParName(i)); | |
1283 | bfullrange->SetParameter(i,b->GetParameter(i)); | |
1284 | bfullrange->SetParError(i,b->GetParError(i)); | |
1285 | } | |
a60f573d | 1286 | bfullrange->SetLineStyle(4); |
1287 | bfullrange->SetLineColor(14); | |
16856d6e | 1288 | |
1289 | bkgnamesave += "Recalc"; | |
1290 | ||
1291 | TF1 *blastpar=new TF1(bkgnamesave.Data(),this,&AliHFMassFitter::FitFunction4Bkg,fminMass,fmaxMass,np,"AliHFMassFitter","FitFunction4Bkg"); | |
1292 | ||
1293 | TF1 *mass=fhistoInvMass->GetFunction("funcmass"); | |
1294 | ||
1295 | if (!mass){ | |
1296 | cout<<"funcmass doesn't exist "<<endl; | |
1297 | return; | |
1298 | } | |
1299 | ||
1300 | blastpar->SetParameter(0,mass->GetParameter(0)-mass->GetParameter(np)); | |
1301 | blastpar->SetParError(0,mass->GetParError(np)); | |
1302 | if (np>=2) { | |
1303 | blastpar->SetParameter(1,mass->GetParameter(1)); | |
1304 | blastpar->SetParError(1,mass->GetParError(1)); | |
56cbeefb | 1305 | } |
16856d6e | 1306 | if (np==3) { |
1307 | blastpar->SetParameter(2,mass->GetParameter(2)); | |
1308 | blastpar->SetParError(2,mass->GetParError(2)); | |
1309 | } | |
1310 | ||
a60f573d | 1311 | blastpar->SetLineStyle(1); |
16856d6e | 1312 | blastpar->SetLineColor(2); |
1313 | ||
a12d80b8 | 1314 | hlist->Add((TF1*)bfullrange->Clone()); |
1315 | hlist->Add((TF1*)blastpar->Clone()); | |
16856d6e | 1316 | hlist->ls(); |
34c79b83 | 1317 | |
a60f573d | 1318 | if(bfullrange) { |
1319 | delete bfullrange; | |
1320 | bfullrange=NULL; | |
1321 | } | |
1322 | if(blastpar) { | |
1323 | delete blastpar; | |
1324 | blastpar=NULL; | |
1325 | } | |
16856d6e | 1326 | } |
1327 | ||
1328 | //_________________________________________________________________________ | |
1329 | ||
1330 | TH1F* AliHFMassFitter::GetHistoClone() const{ | |
1331 | ||
1332 | TH1F* hout=(TH1F*)fhistoInvMass->Clone(fhistoInvMass->GetName()); | |
1333 | return hout; | |
1334 | } | |
1335 | //_________________________________________________________________________ | |
1336 | ||
dc262918 | 1337 | void AliHFMassFitter::WriteHisto(TString path) const { |
1338 | ||
1339 | //Write the histogram in the default file HFMassFitterOutput.root | |
1340 | ||
16856d6e | 1341 | if (fcounter == 0) { |
1342 | cout<<"Use MassFitter method before WriteHisto"<<endl; | |
1343 | return; | |
1344 | } | |
1345 | TH1F* hget=(TH1F*)fhistoInvMass->Clone(); | |
1346 | ||
56cbeefb | 1347 | path += "HFMassFitterOutput.root"; |
1348 | TFile *output; | |
34c79b83 | 1349 | |
56cbeefb | 1350 | if (fcounter == 1) output = new TFile(path.Data(),"recreate"); |
1351 | else output = new TFile(path.Data(),"update"); | |
1352 | output->cd(); | |
1353 | hget->Write(); | |
ad73ca8f | 1354 | fContourGraph->Write(); |
a12d80b8 | 1355 | |
1356 | ||
56cbeefb | 1357 | output->Close(); |
fabf4d8e | 1358 | |
56cbeefb | 1359 | cout<<fcounter<<" "<<hget->GetName()<<" written in "<<path<<endl; |
fabf4d8e | 1360 | |
a60f573d | 1361 | if(output) { |
1362 | delete output; | |
1363 | output=NULL; | |
1364 | } | |
fabf4d8e | 1365 | |
fabf4d8e | 1366 | } |
1367 | ||
1368 | //_________________________________________________________________________ | |
1369 | ||
56cbeefb | 1370 | void AliHFMassFitter::WriteNtuple(TString path) const{ |
a60f573d | 1371 | //TNtuple* nget=(TNtuple*)fntuParam->Clone(); |
56cbeefb | 1372 | path += "HFMassFitterOutput.root"; |
1373 | TFile *output = new TFile(path.Data(),"update"); | |
1374 | output->cd(); | |
a60f573d | 1375 | fntuParam->Write(); |
1376 | //nget->Write(); | |
56cbeefb | 1377 | output->Close(); |
a60f573d | 1378 | //cout<<nget->GetName()<<" written in "<<path<<endl; |
1379 | cout<<fntuParam->GetName()<<" written in "<<path<<endl; | |
1380 | /* | |
1381 | if(nget) { | |
1382 | //delete nget; | |
1383 | nget=NULL; | |
1384 | } | |
1385 | */ | |
1386 | if(output) { | |
1387 | delete output; | |
1388 | output=NULL; | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | //_________________________________________________________________________ | |
d22f0682 | 1393 | void AliHFMassFitter::WriteCanvas(TString userIDstring,TString path,Double_t nsigma,Int_t writeFitInfo,Bool_t draw) const{ |
1394 | ||
1395 | //write the canvas in a root file | |
1396 | ||
1397 | gStyle->SetOptStat(0); | |
1398 | gStyle->SetCanvasColor(0); | |
1399 | gStyle->SetFrameFillColor(0); | |
1400 | ||
1401 | TString type=""; | |
a60f573d | 1402 | |
d22f0682 | 1403 | switch (ftypeOfFit4Bkg){ |
1404 | case 0: | |
1405 | type="Exp"; //3+2 | |
1406 | break; | |
1407 | case 1: | |
1408 | type="Lin"; //3+2 | |
1409 | break; | |
1410 | case 2: | |
1411 | type="Pl2"; //3+3 | |
1412 | break; | |
1413 | case 3: | |
1414 | type="noB"; //3+1 | |
1415 | break; | |
1416 | } | |
1417 | ||
1418 | TString filename=Form("%sMassFit.root",type.Data()); | |
1419 | filename.Prepend(userIDstring); | |
1420 | path.Append(filename); | |
1421 | ||
1422 | TFile* outputcv=new TFile(path.Data(),"update"); | |
1423 | ||
1424 | TCanvas* c=(TCanvas*)GetPad(nsigma,writeFitInfo); | |
1425 | c->SetName(Form("%s%s%s",c->GetName(),userIDstring.Data(),type.Data())); | |
1426 | if(draw)c->DrawClone(); | |
1427 | outputcv->cd(); | |
1428 | c->Write(); | |
1429 | outputcv->Close(); | |
1430 | } | |
1431 | ||
1432 | //_________________________________________________________________________ | |
1433 | ||
1434 | TVirtualPad* AliHFMassFitter::GetPad(Double_t nsigma,Int_t writeFitInfo)const{ | |
a12d80b8 | 1435 | //return a TVirtualPad with the fitted histograms and info |
dc262918 | 1436 | |
a60f573d | 1437 | TString cvtitle="fit of "; |
1438 | cvtitle+=fhistoInvMass->GetName(); | |
1439 | TString cvname="c"; | |
1440 | cvname+=fcounter; | |
1441 | ||
d22f0682 | 1442 | TCanvas *c=new TCanvas(cvname,cvtitle); |
1443 | PlotFit(c->cd(),nsigma,writeFitInfo); | |
a12d80b8 | 1444 | return c->cd(); |
1445 | } | |
1446 | //_________________________________________________________________________ | |
1447 | ||
d22f0682 | 1448 | void AliHFMassFitter::PlotFit(TVirtualPad* pd,Double_t nsigma,Int_t writeFitInfo)const{ |
1449 | //plot histogram, fit functions and write parameters according to verbosity level (0,1,>1) | |
a12d80b8 | 1450 | gStyle->SetOptStat(0); |
1451 | gStyle->SetCanvasColor(0); | |
1452 | gStyle->SetFrameFillColor(0); | |
d22f0682 | 1453 | |
a12d80b8 | 1454 | cout<<"nsigma = "<<nsigma<<endl; |
d22f0682 | 1455 | cout<<"Verbosity = "<<writeFitInfo<<endl; |
a12d80b8 | 1456 | |
3c0e7d59 | 1457 | TH1F* hdraw=GetHistoClone(); |
a12d80b8 | 1458 | hdraw->SetMinimum(0); |
d22f0682 | 1459 | hdraw->GetXaxis()->SetRangeUser(fminMass,fmaxMass); |
a12d80b8 | 1460 | pd->cd(); |
3c0e7d59 | 1461 | hdraw->SetMarkerStyle(20); |
a12d80b8 | 1462 | hdraw->DrawClone("PE"); |
1463 | hdraw->GetFunction("funcbkgFullRange")->DrawClone("same"); | |
1464 | hdraw->GetFunction("funcbkgRecalc")->DrawClone("same"); | |
1465 | hdraw->GetFunction("funcmass")->DrawClone("same"); | |
1466 | ||
d22f0682 | 1467 | if(writeFitInfo > 0){ |
1468 | TPaveText *pinfob=new TPaveText(0.6,0.86,1.,1.,"NDC"); | |
1469 | TPaveText *pinfom=new TPaveText(0.6,0.7,1.,.87,"NDC"); | |
1470 | pinfob->SetBorderSize(0); | |
1471 | pinfob->SetFillStyle(0); | |
1472 | pinfom->SetBorderSize(0); | |
1473 | pinfom->SetFillStyle(0); | |
a12d80b8 | 1474 | TF1* ff=fhistoInvMass->GetFunction("funcmass"); |
d22f0682 | 1475 | |
1476 | for (Int_t i=fNFinalPars-3;i<fNFinalPars;i++){ | |
1477 | pinfom->SetTextColor(kBlue); | |
a12d80b8 | 1478 | TString str=Form("%s = %f #pm %f",ff->GetParName(i),ff->GetParameter(i),ff->GetParError(i)); |
d22f0682 | 1479 | if(!(writeFitInfo==1 && i==fNFinalPars-3)) pinfom->AddText(str); |
a12d80b8 | 1480 | } |
d22f0682 | 1481 | pd->cd(); |
1482 | pinfom->DrawClone(); | |
a60f573d | 1483 | |
a12d80b8 | 1484 | TPaveText *pinfo2=new TPaveText(0.1,0.1,0.6,0.4,"NDC"); |
1485 | pinfo2->SetBorderSize(0); | |
1486 | pinfo2->SetFillStyle(0); | |
1487 | ||
1488 | Double_t signif, signal, bkg, errsignif, errsignal, errbkg; | |
1489 | ||
1490 | Significance(nsigma,signif,errsignif); | |
1491 | Signal(nsigma,signal,errsignal); | |
1492 | Background(nsigma,bkg, errbkg); | |
1493 | /* | |
1494 | Significance(1.828,1.892,signif,errsignif); | |
1495 | Signal(1.828,1.892,signal,errsignal); | |
1496 | Background(1.828,1.892,bkg, errbkg); | |
1497 | */ | |
d22f0682 | 1498 | TString str=Form("Significance (%.0f#sigma) %.1f #pm %.1f ",nsigma,signif,errsignif); |
a12d80b8 | 1499 | pinfo2->AddText(str); |
d22f0682 | 1500 | str=Form("S (%.0f#sigma) %.0f #pm %.0f ",nsigma,signal,errsignal); |
a12d80b8 | 1501 | pinfo2->AddText(str); |
d22f0682 | 1502 | str=Form("B (%.0f#sigma) %.0f #pm %.0f",nsigma,bkg,errbkg); |
a12d80b8 | 1503 | pinfo2->AddText(str); |
1504 | ||
1505 | pd->cd(); | |
a12d80b8 | 1506 | pinfo2->Draw(); |
a60f573d | 1507 | |
d22f0682 | 1508 | if(writeFitInfo > 1){ |
1509 | for (Int_t i=0;i<fNFinalPars-3;i++){ | |
1510 | pinfob->SetTextColor(kRed); | |
1511 | TString str=Form("%s = %f #pm %f",ff->GetParName(i),ff->GetParameter(i),ff->GetParError(i)); | |
1512 | pinfob->AddText(str); | |
1513 | } | |
1514 | pd->cd(); | |
1515 | pinfob->DrawClone(); | |
1516 | } | |
1517 | ||
1518 | ||
3c0e7d59 | 1519 | } |
a12d80b8 | 1520 | return; |
1521 | } | |
1522 | ||
1523 | //_________________________________________________________________________ | |
1524 | ||
d22f0682 | 1525 | void AliHFMassFitter::DrawHere(TVirtualPad* pd,Double_t nsigma,Int_t writeFitInfo) const { |
a12d80b8 | 1526 | //draws histogram together with fit functions with default nice colors in user canvas |
d22f0682 | 1527 | PlotFit(pd,nsigma,writeFitInfo); |
a12d80b8 | 1528 | |
1529 | pd->Draw(); | |
1530 | ||
1531 | } | |
1532 | //_________________________________________________________________________ | |
1533 | void AliHFMassFitter::DrawFit(Double_t nsigma) const{ | |
1534 | ||
1535 | //draws histogram together with fit functions with default nice colors | |
1536 | gStyle->SetOptStat(0); | |
1537 | gStyle->SetCanvasColor(0); | |
1538 | gStyle->SetFrameFillColor(0); | |
1539 | ||
1540 | ||
d22f0682 | 1541 | TCanvas* c=(TCanvas*)GetPad(nsigma,1); |
a12d80b8 | 1542 | c->Draw(); |
1543 | ||
fabf4d8e | 1544 | } |
fabf4d8e | 1545 | |
fabf4d8e | 1546 | |
ad73ca8f | 1547 | //_________________________________________________________________________ |
1548 | ||
1549 | void AliHFMassFitter::PrintParTitles() const{ | |
dc262918 | 1550 | |
1551 | //prints to screen the parameters names | |
1552 | ||
ad73ca8f | 1553 | TF1 *f=fhistoInvMass->GetFunction("funcmass"); |
1554 | if(!f) { | |
1555 | cout<<"Fit function not found"<<endl; | |
1556 | return; | |
1557 | } | |
1558 | ||
1559 | Int_t np=0; | |
1560 | switch (ftypeOfFit4Bkg){ | |
1561 | case 0: //expo | |
1562 | np=2; | |
1563 | break; | |
1564 | case 1: //linear | |
1565 | np=2; | |
1566 | break; | |
1567 | case 2: //pol2 | |
1568 | np=3; | |
1569 | break; | |
1570 | case 3: //no bkg | |
1571 | np=1; | |
1572 | break; | |
1573 | } | |
1574 | ||
1575 | np+=3; //3 parameter for signal | |
1576 | if (ftypeOfFit4Sgn == 1) np+=3; | |
1577 | ||
1578 | cout<<"Parameter Titles \n"; | |
1579 | for(Int_t i=0;i<np;i++){ | |
1580 | cout<<"Par "<<i<<": "<<f->GetParName(i)<<endl; | |
1581 | } | |
1582 | cout<<endl; | |
1583 | ||
1584 | } | |
1585 | ||
56cbeefb | 1586 | //************ significance |
fabf4d8e | 1587 | |
1588 | //_________________________________________________________________________ | |
1589 | ||
1590 | void AliHFMassFitter::Signal(Double_t nOfSigma,Double_t &signal,Double_t &errsignal) const { | |
1591 | // Return signal integral in mean+- n sigma | |
1592 | ||
16856d6e | 1593 | if(fcounter==0) { |
1594 | cout<<"Use MassFitter method before Signal"<<endl; | |
1595 | return; | |
1596 | } | |
56cbeefb | 1597 | |
a12d80b8 | 1598 | Double_t min=fMass-nOfSigma*fSigmaSgn; |
1599 | Double_t max=fMass+nOfSigma*fSigmaSgn; | |
56cbeefb | 1600 | |
a12d80b8 | 1601 | Signal(min,max,signal,errsignal); |
b7d4bc49 | 1602 | |
a12d80b8 | 1603 | // //functions names |
1604 | // TString bkgname= "funcbkgRecalc"; | |
1605 | // TString bkg1name="funcbkg1Recalc"; | |
1606 | // TString massname="funcmass"; | |
16856d6e | 1607 | |
b7d4bc49 | 1608 | |
a12d80b8 | 1609 | // TF1 *funcbkg=0; |
1610 | // TF1 *funcmass=fhistoInvMass->GetFunction(massname.Data()); | |
1611 | // if(!funcmass){ | |
1612 | // cout<<"AliHFMassFitter::Signal() ERROR -> Mass distr function not found!"<<endl; | |
1613 | // return; | |
1614 | // } | |
b7d4bc49 | 1615 | |
a12d80b8 | 1616 | // if(ftypeOfFit4Sgn == 0) funcbkg=fhistoInvMass->GetFunction(bkgname.Data()); |
1617 | // else funcbkg=fhistoInvMass->GetFunction(bkg1name.Data()); | |
b7d4bc49 | 1618 | |
a12d80b8 | 1619 | // if(!funcbkg){ |
1620 | // cout<<"AliHFMassFitter::Signal() ERROR -> Bkg function not found!"<<endl; | |
1621 | // return; | |
1622 | // } | |
fabf4d8e | 1623 | |
a12d80b8 | 1624 | // Int_t np=-99; |
1625 | // switch (ftypeOfFit4Bkg){ | |
1626 | // case 0: //expo | |
1627 | // np=2; | |
1628 | // break; | |
1629 | // case 1: //linear | |
1630 | // np=2; | |
1631 | // break; | |
1632 | // case 2: //pol2 | |
1633 | // np=3; | |
1634 | // break; | |
1635 | // case 3: //no bkg | |
1636 | // np=1; | |
1637 | // break; | |
1638 | // } | |
16856d6e | 1639 | |
a12d80b8 | 1640 | // Float_t intS,intSerr; |
16856d6e | 1641 | |
a12d80b8 | 1642 | // //relative error evaluation |
1643 | ||
1644 | // intS=funcmass->GetParameter(np); | |
1645 | // intSerr=funcmass->GetParError(np); | |
1646 | ||
1647 | // cout<<"Sgn relative error evaluation from fit: "<<intSerr/intS<<endl; | |
1648 | // Double_t background,errbackground; | |
1649 | // Background(nOfSigma,background,errbackground); | |
1650 | ||
1651 | // //signal +/- error in nsigma | |
1652 | // Double_t min=fMass-nOfSigma*fSigmaSgn; | |
1653 | // Double_t max=fMass+nOfSigma*fSigmaSgn; | |
1654 | ||
1655 | // Double_t mass=funcmass->Integral(min, max)/fhistoInvMass->GetBinWidth(4); | |
1656 | // signal=mass - background; | |
1657 | // errsignal=TMath::Sqrt((intSerr/intS*mass)*(intSerr/intS*mass)/*assume relative error is the same as for total integral*/ + errbackground*errbackground); | |
fabf4d8e | 1658 | return; |
a12d80b8 | 1659 | |
fabf4d8e | 1660 | } |
16856d6e | 1661 | |
fabf4d8e | 1662 | //_________________________________________________________________________ |
1663 | ||
16856d6e | 1664 | void AliHFMassFitter::Signal(Double_t min, Double_t max, Double_t &signal,Double_t &errsignal) const { |
1665 | ||
1666 | // Return signal integral in a range | |
1667 | ||
1668 | if(fcounter==0) { | |
1669 | cout<<"Use MassFitter method before Signal"<<endl; | |
1670 | return; | |
1671 | } | |
1672 | ||
56cbeefb | 1673 | //functions names |
16856d6e | 1674 | TString bkgname="funcbkgRecalc"; |
1675 | TString bkg1name="funcbkg1Recalc"; | |
56cbeefb | 1676 | TString massname="funcmass"; |
fabf4d8e | 1677 | |
b7d4bc49 | 1678 | |
1679 | TF1 *funcbkg=0; | |
56cbeefb | 1680 | TF1 *funcmass=fhistoInvMass->GetFunction(massname.Data()); |
16856d6e | 1681 | if(!funcmass){ |
1682 | cout<<"AliHFMassFitter::Signal() ERROR -> Mass distr function not found!"<<endl; | |
1683 | return; | |
1684 | } | |
1685 | ||
b7d4bc49 | 1686 | if(ftypeOfFit4Sgn == 0) funcbkg=fhistoInvMass->GetFunction(bkgname.Data()); |
1687 | else funcbkg=fhistoInvMass->GetFunction(bkg1name.Data()); | |
1688 | ||
16856d6e | 1689 | if(!funcbkg){ |
1690 | cout<<"AliHFMassFitter::Signal() ERROR -> Bkg function not found!"<<endl; | |
1691 | return; | |
1692 | } | |
1693 | ||
1694 | Int_t np=-99; | |
1695 | switch (ftypeOfFit4Bkg){ | |
1696 | case 0: //expo | |
1697 | np=2; | |
1698 | break; | |
1699 | case 1: //linear | |
1700 | np=2; | |
1701 | break; | |
1702 | case 2: //pol2 | |
1703 | np=3; | |
1704 | break; | |
1705 | case 3: //no bkg | |
1706 | np=1; | |
1707 | break; | |
1708 | } | |
b7d4bc49 | 1709 | |
16856d6e | 1710 | Double_t intS,intSerr; |
b7d4bc49 | 1711 | |
16856d6e | 1712 | //relative error evaluation |
1713 | intS=funcmass->GetParameter(np); | |
1714 | intSerr=funcmass->GetParError(np); | |
fabf4d8e | 1715 | |
16856d6e | 1716 | cout<<"Sgn relative error evaluation from fit: "<<intSerr/intS<<endl; |
1717 | Double_t background,errbackground; | |
1718 | Background(min,max,background,errbackground); | |
b7d4bc49 | 1719 | |
16856d6e | 1720 | //signal +/- error in the range |
1721 | ||
1722 | Double_t mass=funcmass->Integral(min, max)/fhistoInvMass->GetBinWidth(4); | |
1723 | signal=mass - background; | |
a60f573d | 1724 | errsignal=(intSerr/intS)*signal;/*assume relative error is the same as for total integral*/ |
16856d6e | 1725 | |
1726 | } | |
1727 | ||
1728 | //_________________________________________________________________________ | |
1729 | ||
1730 | void AliHFMassFitter::Background(Double_t nOfSigma,Double_t &background,Double_t &errbackground) const { | |
1731 | // Return background integral in mean+- n sigma | |
1732 | ||
1733 | if(fcounter==0) { | |
1734 | cout<<"Use MassFitter method before Background"<<endl; | |
1735 | return; | |
b7d4bc49 | 1736 | } |
a12d80b8 | 1737 | Double_t min=fMass-nOfSigma*fSigmaSgn; |
1738 | Double_t max=fMass+nOfSigma*fSigmaSgn; | |
b7d4bc49 | 1739 | |
a12d80b8 | 1740 | Background(min,max,background,errbackground); |
16856d6e | 1741 | |
a12d80b8 | 1742 | // //functions names |
1743 | // TString bkgname="funcbkgRecalc"; | |
1744 | // TString bkg1name="funcbkg1Recalc"; | |
16856d6e | 1745 | |
a12d80b8 | 1746 | // TF1 *funcbkg=0; |
1747 | // if(ftypeOfFit4Sgn == 0) funcbkg=fhistoInvMass->GetFunction(bkgname.Data()); | |
1748 | // else funcbkg=fhistoInvMass->GetFunction(bkg1name.Data()); | |
1749 | // if(!funcbkg){ | |
1750 | // cout<<"AliHFMassFitter::Background() ERROR -> Bkg function not found!"<<endl; | |
1751 | // return; | |
1752 | // } | |
16856d6e | 1753 | |
a12d80b8 | 1754 | // Float_t intB,intBerr;//, intT,intTerr,intS,intSerr; |
fabf4d8e | 1755 | |
a12d80b8 | 1756 | // //relative error evaluation: from final parameters of the fit |
1757 | // if(ftypeOfFit4Bkg==3 && ftypeOfFit4Sgn == 0) cout<<"No background fit: Bkg relative error evaluation put to zero"<<endl; | |
1758 | // else{ | |
1759 | ||
1760 | // intB=funcbkg->GetParameter(0); | |
1761 | // intBerr=funcbkg->GetParError(0); | |
1762 | ||
1763 | // cout<<"Bkg relative error evaluation: from final parameters of the fit: "<<intBerr/intB<<endl; | |
1764 | // } | |
1765 | ||
1766 | // Double_t min=fMass-nOfSigma*fSigmaSgn; | |
1767 | // Double_t max=fMass+nOfSigma*fSigmaSgn; | |
b7d4bc49 | 1768 | |
a12d80b8 | 1769 | // //relative error evaluation: from histo |
b7d4bc49 | 1770 | |
a12d80b8 | 1771 | // intB=fhistoInvMass->Integral(1,fSideBandl)+fhistoInvMass->Integral(fSideBandr,fNbin); |
1772 | // Double_t sum2=0; | |
56cbeefb | 1773 | |
a12d80b8 | 1774 | // for(Int_t i=1;i<=fSideBandl;i++){ |
1775 | // sum2+=fhistoInvMass->GetBinError(i)*fhistoInvMass->GetBinError(i); | |
1776 | // } | |
1777 | // for(Int_t i=fSideBandr;i<=fNbin;i++){ | |
1778 | // sum2+=fhistoInvMass->GetBinError(i)*fhistoInvMass->GetBinError(i); | |
1779 | // } | |
1780 | ||
1781 | // intBerr=TMath::Sqrt(sum2); | |
1782 | // cout<<"Bkg relative error evaluation: from histo: "<<intBerr/intB<<endl; | |
b7d4bc49 | 1783 | |
a12d80b8 | 1784 | // cout<<"Last estimation of bkg error is used"<<endl; |
b7d4bc49 | 1785 | |
a12d80b8 | 1786 | // //backround +/- error in nsigma |
1787 | // if (ftypeOfFit4Bkg == 3 && ftypeOfFit4Sgn == 0) { | |
1788 | // background = 0; | |
1789 | // errbackground = 0; | |
1790 | // } | |
1791 | // else{ | |
1792 | // background=funcbkg->Integral(min,max)/(Double_t)fhistoInvMass->GetBinWidth(2); | |
1793 | // errbackground=intBerr/intB*background; // assume relative error is the same as for total integral | |
1794 | // //cout<<"integral = "<<funcbkg->Integral(min, max)<<"\tbinW = "<<fhistoInvMass->GetBinWidth(2)<<endl; | |
1795 | // } | |
16856d6e | 1796 | return; |
1797 | ||
1798 | } | |
1799 | //___________________________________________________________________________ | |
1800 | ||
1801 | void AliHFMassFitter::Background(Double_t min, Double_t max, Double_t &background,Double_t &errbackground) const { | |
1802 | // Return background integral in a range | |
1803 | ||
1804 | if(fcounter==0) { | |
1805 | cout<<"Use MassFitter method before Background"<<endl; | |
1806 | return; | |
1807 | } | |
1808 | ||
1809 | //functions names | |
1810 | TString bkgname="funcbkgRecalc"; | |
1811 | TString bkg1name="funcbkg1Recalc"; | |
1812 | ||
1813 | TF1 *funcbkg=0; | |
1814 | if(ftypeOfFit4Sgn == 0) funcbkg=fhistoInvMass->GetFunction(bkgname.Data()); | |
1815 | else funcbkg=fhistoInvMass->GetFunction(bkg1name.Data()); | |
1816 | if(!funcbkg){ | |
1817 | cout<<"AliHFMassFitter::Background() ERROR -> Bkg function not found!"<<endl; | |
1818 | return; | |
1819 | } | |
1820 | ||
1821 | ||
1822 | Double_t intB,intBerr; | |
1823 | ||
1824 | //relative error evaluation: from final parameters of the fit | |
1825 | if(ftypeOfFit4Bkg==3 && ftypeOfFit4Sgn == 0) cout<<"No background fit: Bkg relative error evaluation put to zero"<<endl; | |
1826 | else{ | |
1827 | intB=funcbkg->GetParameter(0); | |
1828 | intBerr=funcbkg->GetParError(0); | |
1829 | cout<<"Bkg relative error evaluation: from final parameters of the fit: "<<intBerr/intB<<endl; | |
1830 | } | |
1831 | ||
1832 | //relative error evaluation: from histo | |
1833 | ||
1834 | intB=fhistoInvMass->Integral(1,fSideBandl)+fhistoInvMass->Integral(fSideBandr,fNbin); | |
1835 | Double_t sum2=0; | |
1836 | for(Int_t i=1;i<=fSideBandl;i++){ | |
1837 | sum2+=fhistoInvMass->GetBinError(i)*fhistoInvMass->GetBinError(i); | |
1838 | } | |
1839 | for(Int_t i=fSideBandr;i<=fNbin;i++){ | |
1840 | sum2+=fhistoInvMass->GetBinError(i)*fhistoInvMass->GetBinError(i); | |
1841 | } | |
1842 | ||
1843 | intBerr=TMath::Sqrt(sum2); | |
1844 | cout<<"Bkg relative error evaluation: from histo: "<<intBerr/intB<<endl; | |
1845 | ||
1846 | cout<<"Last estimation of bkg error is used"<<endl; | |
1847 | ||
1848 | //backround +/- error in the range | |
1849 | if (ftypeOfFit4Bkg == 3 && ftypeOfFit4Sgn == 0) { | |
1850 | background = 0; | |
1851 | errbackground = 0; | |
1852 | } | |
1853 | else{ | |
1854 | background=funcbkg->Integral(min,max)/(Double_t)fhistoInvMass->GetBinWidth(2); | |
1855 | errbackground=intBerr/intB*background; // assume relative error is the same as for total integral | |
1856 | //cout<<"integral = "<<funcbkg->Integral(min, max)<<"\tbinW = "<<fhistoInvMass->GetBinWidth(2)<<endl; | |
34c79b83 | 1857 | } |
fabf4d8e | 1858 | return; |
1859 | ||
1860 | } | |
1861 | ||
16856d6e | 1862 | |
fabf4d8e | 1863 | //__________________________________________________________________________ |
1864 | ||
b7d4bc49 | 1865 | void AliHFMassFitter::Significance(Double_t nOfSigma,Double_t &significance,Double_t &errsignificance) const { |
fabf4d8e | 1866 | // Return significance in mean+- n sigma |
1867 | ||
1868 | Double_t signal,errsignal,background,errbackground; | |
1869 | Signal(nOfSigma,signal,errsignal); | |
1870 | Background(nOfSigma,background,errbackground); | |
1871 | ||
1872 | significance = signal/TMath::Sqrt(signal+background); | |
b7d4bc49 | 1873 | |
fabf4d8e | 1874 | errsignificance = TMath::Sqrt(significance*significance/(signal+background)/(signal+background)*(1/4.*errsignal*errsignal+errbackground*errbackground)+significance*significance/signal/signal*errsignal*errsignal); |
b7d4bc49 | 1875 | |
fabf4d8e | 1876 | return; |
1877 | } | |
1878 | ||
1879 | //__________________________________________________________________________ | |
74179930 | 1880 | |
16856d6e | 1881 | void AliHFMassFitter::Significance(Double_t min, Double_t max, Double_t &significance,Double_t &errsignificance) const { |
1882 | // Return significance integral in a range | |
1883 | ||
1884 | Double_t signal,errsignal,background,errbackground; | |
1885 | Signal(min, max,signal,errsignal); | |
1886 | Background(min, max,background,errbackground); | |
1887 | ||
1888 | significance = signal/TMath::Sqrt(signal+background); | |
a12d80b8 | 1889 | |
16856d6e | 1890 | errsignificance = TMath::Sqrt(significance*significance/(signal+background)/(signal+background)*(1/4.*errsignal*errsignal+errbackground*errbackground)+significance*significance/signal/signal*errsignal*errsignal); |
1891 | ||
1892 | return; | |
1893 | } | |
ad73ca8f | 1894 | |
1895 |