26 #include <Riostream.h> 34 #include <TVirtualPad.h> 36 #include <TVirtualFitter.h> 39 #include <TPaveText.h> 40 #include <TDatabasePDG.h> 66 ftypeOfFit4Bkg(
kExpo),
67 ftypeOfFit4Sgn(
kGaus),
87 cout<<
"Default constructor:"<<endl;
88 cout<<
"Remember to set the Histo, the Type, the FixPar"<<endl;
138 if (!
fWithBkg) cout<<
"Fit Histogram of Signal only"<<endl;
200 cout<<
"AliHFMassFitter destructor called"<<endl;
218 if(&mfit ==
this)
return *
this;
265 cout<<
"Info:ComputeNFinalPars... ";
286 cout<<
"Error in computing fNFinalPars: check ftypeOfFit4Bkg"<<endl;
319 cout<<
"Error in computing fParsSize: check ftypeOfFit4Bkg"<<endl;
327 cout<<
"Parameters array size "<<
fParsSize<<endl;
339 cout<<
"Parameter 0 is fixed"<<endl;
353 AliError(Form(
"Error! Parameter out of bounds! Max is %d\n",
fNFinalPars-1));
357 cout<<
"Initializing fFixPar...";
359 cout<<
" done."<<endl;
363 if(fixpar)cout<<
"Parameter "<<thispar<<
" is now fixed"<<endl;
364 else cout<<
"Parameter "<<thispar<<
" is now free"<<endl;
372 AliError(Form(
"Error! Parameter out of bounds! Max is %d\n",
fNFinalPars-1));
376 AliError(
"Error! Parameters to be fixed still not set");
413 cout<<
"Reset called: delete histogram, set mean value to 1.85 and sigma to 0.012"<<endl;
427 fntuParam=
new TNtuple(ntuname.Data(),
"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");
475 fntuParam->SetBranchAddress(
"slope1",¬hing);
476 fntuParam->SetBranchAddress(
"conc1",¬hing);
481 fntuParam->SetBranchAddress(
"slope2",¬hing);
482 fntuParam->SetBranchAddress(
"conc2",¬hing);
484 fntuParam->SetBranchAddress(
"slope3",¬hing);
485 fntuParam->SetBranchAddress(
"conc3",¬hing);
491 fntuParam->SetBranchAddress(
"slope1Err",¬hing);
492 fntuParam->SetBranchAddress(
"conc1Err",¬hing);
497 fntuParam->SetBranchAddress(
"slope2Err",¬hing);
498 fntuParam->SetBranchAddress(
"conc2Err",¬hing);
500 fntuParam->SetBranchAddress(
"slope3Err",¬hing);
501 fntuParam->SetBranchAddress(
"conc3Err",¬hing);
510 fntuParam->SetBranchAddress(
"conc1",¬hing);
516 fntuParam->SetBranchAddress(
"conc2",¬hing);
519 fntuParam->SetBranchAddress(
"conc3",¬hing);
526 fntuParam->SetBranchAddress(
"conc1Err",¬hing);
532 fntuParam->SetBranchAddress(
"conc2Err",¬hing);
535 fntuParam->SetBranchAddress(
"conc3Err",¬hing);
560 AliError(
"Histogram not set!!");
565 cout<<
"Error! Cannot group "<<bingroup<<
" bins\n";
567 cout<<
"Kept original number of bins: "<<
fNbin<<endl;
570 while(nbinshisto%bingroup != 0) {
573 cout<<
"Group "<<bingroup<<
" bins"<<endl;
576 cout<<
"New number of bins: "<<
fNbin<<endl;
602 Double_t parbkg[2] = {par[0]-par[2], par[1]};
606 Double_t parbkg[5] = {par[2],par[3],
ffactor*par[4],par[0]-2*par[2], par[1]};
627 Double_t parbkg[3] = {par[0]-par[3], par[1], par[2]};
632 Double_t parbkg[6] = {par[3],par[4],
ffactor*par[5],par[0]-2*par[3], par[1], par[2]};
664 Double_t parbkg[2] = {par[0]-par[2], par[1]};
669 Double_t parbkg[5] = {par[2],par[3],
ffactor*par[4],par[0]-par[2], par[1]};
688 Double_t parbkg[3] = {par[0]-par[3],par[1],par[2]};
692 Double_t parbkg[6] = {par[3],par[4],
ffactor*par[5],par[0]-par[3], par[1], par[2]};
715 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]);
752 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]);
760 total= par[0+firstPar]/(fmaxMass-
fminMass)+par[1+firstPar]*(x[0]-0.5*(fmaxMass+fminMass));
771 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));
775 total=par[0+firstPar];
786 Double_t mpi = TDatabasePDG::Instance()->GetParticle(211)->Mass();
788 total = par[0+firstPar]*(par[1+firstPar]+1.)/(TMath::Power(fmaxMass-mpi,par[1+firstPar]+1.)-TMath::Power(fminMass-mpi,par[1+firstPar]+1.))*TMath::Power(x[0]-mpi,par[1+firstPar]);
796 Double_t mpi = TDatabasePDG::Instance()->GetParticle(211)->Mass();
798 total = par[1+firstPar]*TMath::Sqrt(x[0] - mpi)*TMath::Exp(-1.*par[2+firstPar]*(x[0]-mpi));
824 Double_t sidebandldouble=0.,sidebandrdouble=0.;
827 AliError(
"Left limit of range > mean or right limit of range < mean: change left/right limit or initial mean value");
836 cout<<
"Changed number of sigma from 4 to "<<0.5*coeff<<
" for the estimation of the side bands"<<endl;
837 if (coeff<3) cout<<
"Side bands inside 3 sigma, may be better use ftypeOfFit4Bkg = 3 (only signal)"<<endl;
839 cout<<
"Side bands inside 2 sigma. Change mode: ftypeOfFit4Bkg = 3"<<endl;
851 cout<<
"Left side band ";
859 if(TMath::Abs(tmp-sidebandldouble) > 1e-6){
860 cout<<tmp<<
" is not allowed, changing it to the nearest value allowed: ";
862 cout<<sidebandldouble<<
" (bin "<<
fSideBandl<<
")"<<endl;
864 cout<<
"Right side band ";
871 if(TMath::Abs(tmp-sidebandrdouble) > 1e-6){
872 AliWarning(Form(
"%f is not allowed, changing it to the nearest value allowed: \n",tmp));
874 cout<<sidebandrdouble<<
" (bin "<<
fSideBandr<<
")"<<endl;
876 AliError(
"Error! Range too little");
889 cout<<
"Use MassFitter method first"<<endl;
901 cout<<
"No histogram to fit! SetHisto(TH1F* h) before! "<<endl;
904 Bool_t leftok=kFALSE, rightok=kFALSE;
911 cout<<
"Out of histogram left bound! Setting to "<<minhisto<<endl;
915 cout<<
"Out of histogram right bound! Setting to"<<maxhisto<<endl;
925 if(TMath::Abs(tmp-
fminMass) > 1e-6){
926 cout<<
"Left bound "<<tmp<<
" is not allowed, changing it to the nearest value allowed: "<<
fminMass<<endl;
935 if(TMath::Abs(tmp-
fmaxMass) > 1e-6){
936 cout<<
"Right bound "<<tmp<<
" is not allowed, changing it to the nearest value allowed: "<<
fmaxMass<<endl;
940 return (leftok && rightok);
950 TVirtualFitter::SetDefaultFitter(
"Minuit");
957 Int_t checkinnsigma=4;
960 Double_t intUnderFunc=func->Integral(range[0],range[1]);
962 cout<<
"Pick zone: IntFunc = "<<intUnderFunc<<
"; IntHist = "<<intUnderHisto<<
"\tDiff = "<<intUnderHisto-intUnderFunc<<
"\tRelDiff = "<<(intUnderHisto-intUnderFunc)/intUnderFunc<<endl;
963 Double_t diffUnderPick=(intUnderHisto-intUnderFunc);
966 cout<<
"Band (l) zone: IntFunc = "<<intUnderFunc<<
"; IntHist = "<<intUnderHisto<<
"\tDiff = "<<intUnderHisto-intUnderFunc<<
"\tRelDiff = "<<(intUnderHisto-intUnderFunc)/intUnderFunc<<endl;
967 Double_t diffUnderBands=(intUnderHisto-intUnderFunc);
968 Double_t relDiff=diffUnderPick/diffUnderBands;
969 cout<<
"Relative difference = "<<relDiff<<endl;
970 if(TMath::Abs(relDiff) < 0.25) isBkgOnly=kTRUE;
972 cout<<
"Relative difference = "<<relDiff<<
": I suppose there is some signal, continue with total fit!"<<endl;
976 cout<<
"INFO!! The histogram contains only background"<<endl;
987 cout<<
"fNFinalPars = "<<
fNFinalPars<<
"\tbkgPar = "<<bkgPar<<endl;
990 TString listname=
"contourplot";
1014 if(!ok)
return kFALSE;
1019 cout<<
"------sideBandsInt - first approx = "<<sideBandsInt<<endl;
1020 if (sideBandsInt<=0) {
1021 cout<<
"! sideBandsInt <=0. There's a problem, cannot start the fit"<<endl;
1029 cout<<
"Function name = "<<funcbkg->GetName()<<endl<<endl;
1031 funcbkg->SetLineColor(2);
1037 funcbkg->SetParNames(
"BkgInt",
"Slope");
1038 funcbkg->SetParameters(sideBandsInt,-2.);
1041 funcbkg->SetParNames(
"BkgInt",
"Slope");
1042 funcbkg->SetParameters(sideBandsInt,-100.);
1045 funcbkg->SetParNames(
"BkgInt",
"Coef1",
"Coef2");
1046 funcbkg->SetParameters(sideBandsInt,-10.,5);
1050 funcbkg->SetParNames(
"Const");
1051 funcbkg->SetParameter(0,0.);
1052 funcbkg->FixParameter(0,0.);
1056 funcbkg->SetParNames(
"BkgInt",
"Coef2");
1057 funcbkg->SetParameters(sideBandsInt,0.5);
1060 funcbkg->SetParNames(
"BkgInt",
"Coef1",
"Coef2");
1061 funcbkg->SetParameters(sideBandsInt, -10., 5.);
1064 cout<<
"Wrong choise of ftypeOfFit4Bkg ("<<
ftypeOfFit4Bkg<<
")"<<endl;
1068 cout<<
"\nBACKGROUND FIT - only combinatorial"<<endl;
1071 Double_t intbkg1=0,slope1=0,conc1=0;
1077 for(
Int_t i=0;i<bkgPar;i++){
1078 fFitPars[i]=funcbkg->GetParameter(i);
1086 intbkg1 = funcbkg->Integral(fminMass,fmaxMass);
1094 else cout<<
"\t\t//"<<endl;
1099 cout<<
"\nBACKGROUND FIT WITH REFLECTION"<<endl;
1105 cout<<
"Function name = "<<funcbkg1->GetName()<<endl;
1107 funcbkg1->SetLineColor(2);
1112 cout<<
"*** Exponential Fit ***"<<endl;
1113 funcbkg1->SetParNames(
"IntGB",
"MeanGB",
"SigmaGB",
"BkgInt",
"Slope");
1119 cout<<
"*** Linear Fit ***"<<endl;
1120 funcbkg1->SetParNames(
"IntGB",
"MeanGB",
"SigmaGB",
"BkgInt",
"Slope");
1126 cout<<
"*** Polynomial Fit ***"<<endl;
1127 funcbkg1->SetParNames(
"IntGB",
"MeanGB",
"SigmaGB",
"BkgInt",
"Coef1",
"Coef2");
1134 cout<<
"*** No background Fit ***"<<endl;
1135 funcbkg1->SetParNames(
"IntGB",
"MeanGB",
"SigmaGB",
"Const");
1137 funcbkg1->FixParameter(3,0.);
1142 cout<<
"*** Power function Fit ***"<<endl;
1143 funcbkg1->SetParNames(
"IntGB",
"MeanGB",
"SigmaGB",
"BkgInt",
"Coef2");
1149 cout<<
"*** Power function conv. with exponential Fit ***"<<endl;
1150 funcbkg1->SetParNames(
"IntGB",
"MeanGB",
"SigmaGB",
"BkgInt",
"Coef1",
"Coef2");
1160 cout<<
"Minuit returned "<<status<<endl;
1164 for(
Int_t i=0;i<bkgPar;i++){
1165 fFitPars[bkgPar-3+i]=funcbkg1->GetParameter(i);
1171 intbkg1=funcbkg1->GetParameter(3);
1180 for(
Int_t i=0;i<3;i++){
1182 cout<<bkgPar-3+i<<
"\t"<<0.<<
"\t";
1187 for(
Int_t i=0;i<bkgPar-3;i++){
1188 fFitPars[bkgPar+i]=funcbkg->GetParameter(i);
1189 cout<<bkgPar+i<<
"\t"<<funcbkg->GetParameter(i)<<
"\t";
1191 cout<<
fNFinalPars+3*bkgPar-3+i<<
"\t"<< funcbkg->GetParError(i)<<endl;
1201 if(
ftypeOfFit4Sgn == 1) bkgInt=funcbkg1->Integral(fminMass,fmaxMass);
1202 else bkgInt=funcbkg->Integral(fminMass,fmaxMass);
1207 sgnInt = totInt-bkgInt;
1210 cout<<
"Setting sgnInt = - sgnInt"<<endl;
1215 cout<<
"Function name = "<<funcmass->GetName()<<endl<<endl;
1216 funcmass->SetLineColor(4);
1219 cout<<
"\nTOTAL FIT"<<endl;
1222 funcmass->SetParNames(
"TotInt",
"Slope",
"SgnInt",
"Mean",
"Sigma");
1228 funcmass->FixParameter(0,totInt);
1231 funcmass->FixParameter(1,slope1);
1234 funcmass->FixParameter(2,sgnInt);
1237 funcmass->FixParameter(3,
fMass);
1243 if (fNFinalPars==6){
1244 funcmass->SetParNames(
"TotInt",
"Coef1",
"Coef2",
"SgnInt",
"Mean",
"Sigma");
1245 funcmass->SetParameters(totInt,slope1,conc1,sgnInt,
fMass,
fSigmaSgn);
1249 if(
fFixPar[0])funcmass->FixParameter(0,totInt);
1250 if(
fFixPar[1])funcmass->FixParameter(1,slope1);
1251 if(
fFixPar[2])funcmass->FixParameter(2,conc1);
1252 if(
fFixPar[3])funcmass->FixParameter(3,sgnInt);
1259 funcmass->SetParNames(
"Const",
"SgnInt",
"Mean",
"Sigma");
1262 if(
fFixPar[0]) funcmass->FixParameter(0,0.);
1263 if(
fFixPar[1])funcmass->FixParameter(1,sgnInt);
1275 cout<<
"Minuit returned "<<status<<endl;
1279 cout<<
"fit done"<<endl;
1281 fMass=funcmass->GetParameter(fNFinalPars-2);
1282 fMassErr=funcmass->GetParError(fNFinalPars-2);
1283 fSigmaSgn=funcmass->GetParameter(fNFinalPars-1);
1289 fFitPars[i+2*bkgPar-3]=funcmass->GetParameter(i);
1290 fFitPars[fNFinalPars+4*bkgPar-6+i]= funcmass->GetParError(i);
1300 if(funcmass->GetParameter(fNFinalPars-1) <0 || funcmass->GetParameter(fNFinalPars-2) <0 || funcmass->GetParameter(fNFinalPars-3) <0 ) {
1301 cout<<
"IntS or mean or sigma negative. You may tray to SetInitialGaussianSigma(..) and SetInitialGaussianMean(..)"<<endl;
1314 cout<<
"Par "<<kpar<<
" and "<<jpar<<endl;
1317 TGraph* cont[2] = {0x0, 0x0};
1318 const Double_t errDef[2] = {1., 4.};
1319 for (
Int_t i=0; i<2; i++) {
1320 gMinuit->SetErrorDef(errDef[i]);
1321 cont[i] = (
TGraph*)gMinuit->Contour(80,kpar,jpar);
1322 cout<<
"Minuit Status = "<<gMinuit->GetStatus()<<endl;
1325 if(!cont[0] || !cont[1]){
1326 cout<<
"Skipping par "<<kpar<<
" vs par "<<jpar<<endl;
1332 TString titleX = funcmass->GetParName(kpar);
1333 TString titleY = funcmass->GetParName(jpar);
1334 for (
Int_t i=0; i<2; i++) {
1335 cont[i]->SetName( Form(
"cperr%d_%d%d", i, kpar, jpar) );
1336 cont[i]->SetTitle(title);
1337 cont[i]->GetXaxis()->SetTitle(titleX);
1338 cont[i]->GetYaxis()->SetTitle(titleY);
1339 cont[i]->GetYaxis()->SetLabelSize(0.033);
1340 cont[i]->GetYaxis()->SetTitleSize(0.033);
1341 cont[i]->GetYaxis()->SetTitleOffset(1.67);
1347 TString cvname = Form(
"c%d%d", kpar, jpar);
1348 TCanvas *c4=
new TCanvas(cvname,cvname,600,600);
1350 cont[1]->SetFillColor(38);
1351 cont[1]->Draw(
"alf");
1352 cont[0]->SetFillColor(9);
1353 cont[0]->Draw(
"lf");
1381 TString bkgname=
"funcbkgonly";
1386 funcbkg->SetLineColor(kBlue+3);
1392 funcbkg->SetParNames(
"BkgInt",
"Slope");
1393 funcbkg->SetParameters(integral,-2.);
1396 funcbkg->SetParNames(
"BkgInt",
"Slope");
1397 funcbkg->SetParameters(integral,-100.);
1400 funcbkg->SetParNames(
"BkgInt",
"Coef1",
"Coef2");
1401 funcbkg->SetParameters(integral,-10.,5);
1404 cout<<
"Warning! This choice does not make a lot of sense..."<<endl;
1406 funcbkg->SetParNames(
"Const");
1407 funcbkg->SetParameter(0,0.);
1408 funcbkg->FixParameter(0,0.);
1412 funcbkg->SetParNames(
"BkgInt",
"Coef1");
1413 funcbkg->SetParameters(integral,0.5);
1416 funcbkg->SetParNames(
"BkgInt",
"Coef1",
"Coef2");
1417 funcbkg->SetParameters(integral,-10.,5.);
1420 cout<<
"Wrong choise of ftypeOfFit4Bkg ("<<
ftypeOfFit4Bkg<<
")"<<endl;
1429 cout<<
"Minuit returned "<<status<<endl;
1444 cout<<
"funcmass not found"<<endl;
1447 return funcmass->GetChisquare();
1455 cout<<
"funcmass not found"<<endl;
1458 return funcmass->GetChisquare()/funcmass->GetNDF();
1465 cout<<
"Bkg function not found"<<endl;
1471 Int_t binmin, binmax, binl, binr;
1477 xmin = bkgfunc->GetXmin();
1478 xmax = bkgfunc->GetXmax();
1487 for (
Int_t ib=binmin; ib<=binmax; ib++) {
1488 if (!(ib>=binl && ib<=binr)) {
1491 Float_t yexp = bkgfunc->Eval(x);
1493 chi2 = chi2 + (yobs-yexp)*(yobs-yexp)/yexp;
1505 cout<<
"Bkg function not found"<<endl;
1510 Int_t npar = bkgfunc->GetNpar();
1521 cout<<
"funcmass not found"<<endl;
1524 return funcmass->GetProb();
1543 if(!valuewitherror) {
1544 printf(
"AliHFMassFitter::IntS: got a null pointer\n");
1563 Bool_t done1=kFALSE,done2=kFALSE;
1567 testname +=
"FullRange";
1568 TF1 *testfunc=(TF1*)
fhistoInvMass->FindObject(testname.Data());
1573 testname=
"funcbkgonly";
1581 cout<<
"AddFunctionsToHisto already used: exiting...."<<endl;
1589 TF1 *bonly=(TF1*)hlist->FindObject(testname.Data());
1591 cout<<testname.Data()<<
" not found looking for complete fit"<<endl;
1593 bonly->SetLineColor(kBlue+3);
1594 hlist->Add((TF1*)bonly->Clone());
1601 TF1 *b=(TF1*)hlist->FindObject(bkgname.Data());
1603 cout<<bkgname<<
" not found, cannot produce "<<bkgname<<
"FullRange and "<<bkgname<<
"Recalc"<<endl;
1607 bkgname +=
"FullRange";
1610 for(
Int_t i=0;i<fNFinalPars-3;i++){
1611 bfullrange->SetParName(i,b->GetParName(i));
1612 bfullrange->SetParameter(i,b->GetParameter(i));
1613 bfullrange->SetParError(i,b->GetParError(i));
1615 bfullrange->SetLineStyle(4);
1616 bfullrange->SetLineColor(14);
1618 bkgnamesave +=
"Recalc";
1625 cout<<
"funcmass doesn't exist "<<endl;
1630 blastpar->SetParameter(0,mass->GetParameter(0)-mass->GetParameter(fNFinalPars-3));
1631 blastpar->SetParError(0,mass->GetParError(fNFinalPars-3));
1632 if (fNFinalPars>=5) {
1633 blastpar->SetParameter(1,mass->GetParameter(1));
1634 blastpar->SetParError(1,mass->GetParError(1));
1636 if (fNFinalPars==6) {
1637 blastpar->SetParameter(2,mass->GetParameter(2));
1638 blastpar->SetParError(2,mass->GetParError(2));
1641 blastpar->SetLineStyle(1);
1642 blastpar->SetLineColor(2);
1644 hlist->Add((TF1*)bfullrange->Clone());
1645 hlist->Add((TF1*)blastpar->Clone());
1670 cout<<
"Use MassFitter method before WriteHisto"<<endl;
1675 path +=
"HFMassFitterOutput.root";
1678 if (
fcounter == 1) output =
new TFile(path.Data(),
"recreate");
1679 else output =
new TFile(path.Data(),
"update");
1687 cout<<
fcounter<<
" "<<hget->GetName()<<
" written in "<<path<<endl;
1697 path +=
"HFMassFitterOutput.root";
1698 TFile *output =
new TFile(path.Data(),
"update");
1704 cout<<
fntuParam->GetName()<<
" written in "<<path<<endl;
1720 gStyle->SetOptStat(0);
1721 gStyle->SetCanvasColor(0);
1722 gStyle->SetFrameFillColor(0);
1748 filename.Prepend(userIDstring);
1749 path.Append(filename);
1751 TCanvas*
c =
static_cast<TCanvas*
>(
GetPad(nsigma,writeFitInfo));
1752 c->SetName(Form(
"%s%s%s",c->GetName(),userIDstring.Data(),type.Data()));
1753 if (draw) c->DrawClone();
1755 TFile outputcv(path.Data(),
"update");
1771 TCanvas*
c =
new TCanvas(cvname,cvtitle);
1772 PlotFit(c, nsigma, writeFitInfo);
1780 gStyle->SetOptStat(0);
1781 gStyle->SetCanvasColor(0);
1782 gStyle->SetFrameFillColor(0);
1784 cout<<
"nsigma = "<<nsigma<<endl;
1785 cout<<
"Verbosity = "<<writeFitInfo<<endl;
1789 if(!hdraw->GetFunction(
"funcmass") && !hdraw->GetFunction(
"funcbkgFullRange") && !hdraw->GetFunction(
"funcbkgRecalc")&& !hdraw->GetFunction(
"funcbkgonly")){
1790 cout<<
"Probably fit failed and you didn't try to refit with background only, there's no function to be drawn"<<endl;
1794 if(hdraw->GetFunction(
"funcbkgonly")){
1795 cout<<
"Drawing background fit only"<<endl;
1796 hdraw->SetMinimum(0);
1799 hdraw->SetMarkerStyle(20);
1800 hdraw->DrawClone(
"PE");
1801 hdraw->GetFunction(
"funcbkgonly")->DrawClone(
"sames");
1803 if(writeFitInfo > 0){
1804 TPaveText *pinfo=
new TPaveText(0.6,0.86,1.,1.,
"NDC");
1805 pinfo->SetBorderSize(0);
1806 pinfo->SetFillStyle(0);
1807 TF1* f=hdraw->GetFunction(
"funcbkgonly");
1809 pinfo->SetTextColor(kBlue+3);
1810 TString str=Form(
"%s = %.3f #pm %.3f",f->GetParName(i),f->GetParameter(i),f->GetParError(i));
1811 pinfo->AddText(str);
1814 pinfo->AddText(Form(
"Reduced #chi^{2} = %.3f",f->GetChisquare()/f->GetNDF()));
1822 hdraw->SetMinimum(0);
1825 hdraw->SetMarkerStyle(20);
1826 hdraw->DrawClone(
"PE");
1829 if(hdraw->GetFunction(
"funcmass")) hdraw->GetFunction(
"funcmass")->DrawClone(
"same");
1831 if(writeFitInfo > 0){
1832 TPaveText *pinfob=
new TPaveText(0.6,0.86,1.,1.,
"NDC");
1833 TPaveText *pinfom=
new TPaveText(0.6,0.7,1.,.87,
"NDC");
1834 pinfob->SetBorderSize(0);
1835 pinfob->SetFillStyle(0);
1836 pinfom->SetBorderSize(0);
1837 pinfom->SetFillStyle(0);
1841 pinfom->SetTextColor(kBlue);
1842 TString str=Form(
"%s = %.3f #pm %.3f",ff->GetParName(i),ff->GetParameter(i),ff->GetParError(i));
1843 if (ff->GetParameter(fNFinalPars-2)<0.2) str=Form(
"%s = %.3f #pm %.3f",ff->GetParName(i),ff->GetParameter(i)*1000,ff->GetParError(i)*1000);
1844 if(!(writeFitInfo==1 && i==fNFinalPars-3)) pinfom->AddText(str);
1849 TPaveText *pinfo2=
new TPaveText(0.1,0.1,0.6,0.4,
"NDC");
1850 pinfo2->SetBorderSize(0);
1851 pinfo2->SetFillStyle(0);
1853 Double_t signif, signal, bkg, errsignif, errsignal, errbkg;
1856 Signal(nsigma,signal,errsignal);
1863 TString str=Form(
"Significance (%.0f#sigma) %.1f #pm %.1f ",nsigma,signif,errsignif);
1864 pinfo2->AddText(str);
1865 str=Form(
"S (%.0f#sigma) %.0f #pm %.0f ",nsigma,signal,errsignal);
1866 pinfo2->AddText(str);
1867 str=Form(
"B (%.0f#sigma) %.0f #pm %.0f",nsigma,bkg,errbkg);
1868 pinfo2->AddText(str);
1869 if(bkg>0) str=Form(
"S/B (%.0f#sigma) %.4f ",nsigma,signal/bkg);
1870 pinfo2->AddText(str);
1875 if(writeFitInfo > 1){
1876 for (
Int_t i=0;i<fNFinalPars-3;i++){
1877 pinfob->SetTextColor(kRed);
1878 str=Form(
"%s = %f #pm %f",ff->GetParName(i),ff->GetParameter(i),ff->GetParError(i));
1879 pinfob->AddText(str);
1892 PlotFit(pd,nsigma,writeFitInfo);
1901 gStyle->SetOptStat(0);
1902 gStyle->SetCanvasColor(0);
1903 gStyle->SetFrameFillColor(0);
1906 TCanvas*
c=(TCanvas*)
GetPad(nsigma,1);
1920 cout<<
"Fit function not found"<<endl;
1924 cout<<
"Parameter Titles \n";
1926 cout<<
"Par "<<i<<
": "<<f->GetParName(i)<<endl;
1940 cout<<
"Use MassFitter method before Signal"<<endl;
1947 Signal(min,max,signal,errsignal);
1961 cout<<
"Use MassFitter method before Signal"<<endl;
1966 TString bkgname=
"funcbkgRecalc";
1967 TString bkg1name=
"funcbkg1Recalc";
1974 cout<<
"AliHFMassFitter::Signal() ERROR -> Mass distr function not found!"<<endl;
1982 cout<<
"AliHFMassFitter::Signal() ERROR -> Bkg function not found!"<<endl;
1991 intS=funcmass->GetParameter(np);
1992 intSerr=funcmass->GetParError(np);
1994 cout<<
"Sgn relative error evaluation from fit: "<<intSerr/intS<<endl;
1996 Background(min,max,background,errbackground);
2001 signal=mass - background;
2002 errsignal=(intSerr/intS)*signal;
2012 cout<<
"Use MassFitter method before Background"<<endl;
2018 Background(min,max,background,errbackground);
2029 cout<<
"Use MassFitter method before Background"<<endl;
2034 TString bkgname=
"funcbkgRecalc";
2035 TString bkg1name=
"funcbkg1Recalc";
2041 cout<<
"AliHFMassFitter::Background() ERROR -> Bkg function not found!"<<endl;
2051 intB=funcbkg->GetParameter(0);
2052 intBerr=funcbkg->GetParError(0);
2053 cout<<
"Bkg relative error evaluation: from final parameters of the fit: "<<intBerr/intB<<endl;
2067 intBerr=TMath::Sqrt(sum2);
2068 cout<<
"Bkg relative error evaluation: from histo: "<<intBerr/intB<<endl;
2070 cout<<
"Last estimation of bkg error is used"<<endl;
2079 errbackground=intBerr/intB*background;
2105 AliError(
"Number of fits is zero, check whether you made the fit before computing the significance!\n");
2109 Double_t signal,errsignal,background,errbackground;
2110 Signal(min, max,signal,errsignal);
2111 Background(min, max,background,errbackground);
2113 if (signal+background <= 0.){
2114 cout<<
"Cannot calculate significance because of div by 0!"<<endl;
2127 Int_t binmi=1,binma=h->GetNbinsX();
2129 if(maxrange>minrange){
2130 binmi=h->FindBin(minrange*1.001);
2131 binma=h->FindBin(maxrange*0.9999);
2135 hResidualTrend->SetBins(h->GetNbinsX(),h->GetXaxis()->GetXmin(),h->GetXaxis()->GetXmax());
2136 hResidualTrend->SetName(Form(
"%s_residualTrend",h->GetName()));
2137 hResidualTrend->SetTitle(Form(
"%s (Residuals)",h->GetTitle()));
2138 hResidualTrend->SetMarkerStyle(20);
2139 hResidualTrend->SetMarkerSize(1.0);
2140 hResidualTrend->Reset();
2143 hPullsTrend->SetBins(h->GetNbinsX(),h->GetXaxis()->GetXmin(),h->GetXaxis()->GetXmax());
2144 hPullsTrend->Reset();
2145 hPullsTrend->SetName(Form(
"%s_pullTrend",h->GetName()));
2146 hPullsTrend->SetTitle(Form(
"%s (Pulls)",h->GetTitle()));
2147 hPullsTrend->SetMarkerStyle(20);
2148 hPullsTrend->SetMarkerSize(1.0);
2151 hPulls->SetName(Form(
"%s_pulls",h->GetName()));
2152 hPulls->SetTitle(Form(
"%s ; Pulls",h->GetTitle()));
2153 hPulls->SetBins(40,-10,10);
2157 Double_t res=-1.e-6,min=1.e+12,max=-1.e+12;
2159 for(
Int_t jst=1;jst<=h->GetNbinsX();jst++){
2161 res=h->GetBinContent(jst)-f->Integral(h->GetBinLowEdge(jst),h->GetBinLowEdge(jst)+h->GetBinWidth(jst))/h->GetBinWidth(jst);
2162 if(jst>=binmi&&jst<=binma){
2163 arval->AddAt(res,jst-binmi);
2169 hResidualTrend->SetBinContent(jst,res);
2170 hResidualTrend->SetBinError(jst,h->GetBinError(jst));
2173 if(jst>=binmi&&jst<=binma)hPulls->Fill(res/h->GetBinError(jst));
2176 hPullsTrend->SetBinContent(jst,res/h->GetBinError(jst));
2177 hPullsTrend->SetBinError(jst,0.0001);
2180 if(hResidualTrend)hResidualTrend->GetXaxis()->SetRange(binmi,binma);
2182 hPullsTrend->GetXaxis()->SetRange(binmi,binma);
2183 hPullsTrend->SetMinimum(-7);
2184 hPullsTrend->SetMaximum(+7);
2186 if(TMath::Abs(min)>TMath::Abs(max))max=min;
2188 TH1F *hout=
new TH1F(Form(
"%s_residuals",h->GetName()),Form(
"%s ; residuals",h->GetTitle()),25,-TMath::Abs(max)*1.5,TMath::Abs(max)*1.5);
2189 for(
Int_t j=0;j<binma-binmi+1;j++){
2190 hout->Fill(arval->At(j));
2193 hout->Fit(
"gaus",
"LEM",
"",-TMath::Abs(max)*1.2,TMath::Abs(max)*1.2);
2197 hPulls->Fit(
"gaus",
"LEM",
"",-3,3);
2208 Printf(
"AliHFMassFitter::GetOverBackgroundResidualsAndPulls, invariant mass histogram not avaialble!");
2214 Printf(
"AliHFMassFitter::GetOverBackgroundResidualsAndPulls, funcbkgRecalc not available!");
2223 fbackCp->SetParameter(i,fback->GetParameter(i));
2236 Printf(
"AliHFMassFitter::GetOverBackgroundResidualsAndPulls, negative sigma: fit not performed or something went wrong, cannto draw gaussian term on top of residuals");
2241 TF1 *fgauss=
new TF1(
"signalTermForRes",
"[0]/TMath::Sqrt(2.*TMath::Pi())/[2]*TMath::Exp(-(x-[1])*(x-[1])/2./[2]/[2])",
fhistoInvMass->GetBinLowEdge(1),
fhistoInvMass->GetBinLowEdge(
fhistoInvMass->GetNbinsX()+1));
2243 fgauss->SetParameter(1,
fMass);
2245 fgauss->SetLineColor(kBlue);
2246 hResidualTrend->GetListOfFunctions()->Add(fgauss);
2256 Printf(
"AliHFMassFitter::GetAllRangeResidualsAndPulls, invariant mass histogram not avaialble!");
2262 Printf(
"AliHFMassFitter::GetAllRangeResidualsAndPulls, funcmass not available!");
2269 fmassCp->SetParameter(i,f->GetParameter(i));
2280 TPaveText *pinfom=
new TPaveText(0.6,0.7,1.,.87,
"NDC");
2281 pinfom->SetBorderSize(0);
2282 pinfom->SetFillStyle(0);
2286 pinfom->SetTextColor(kBlue);
2287 TString str=Form(
"%s = %.3f #pm %.3f",ff->GetParName(i),ff->GetParameter(i),ff->GetParError(i));
2288 if(!(mode==1 && i==fNFinalPars-3)) pinfom->AddText(str);
2293 pinfom->SetTextColor(kBlue+5);
2294 for (
Int_t i=0;i<fNFinalPars-3;i++){
2295 TString str=Form(
"%s = %.3f #pm %.3f",ff->GetParName(i),ff->GetParameter(i),ff->GetParError(i));
2296 pinfom->AddText(str);
2299 pinfom->AddText(Form(
"#chi^{2}/NDF=%.2f/%d",ff->GetChisquare(),ff->GetNDF()));
2305 TPaveText *pinfo2=
new TPaveText(0.1,0.1,0.6,0.4,
"NDC");
2306 pinfo2->SetBorderSize(0);
2307 pinfo2->SetFillStyle(0);
2309 Double_t signif, signal, bkg, errsignif, errsignal, errbkg;
2311 Signal(nsigma,signal,errsignal);
2316 TString str=Form(
"Significance (%.0f#sigma) %.1f #pm %.1f ",nsigma,signif,errsignif);
2317 pinfo2->AddText(str);
2318 str=Form(
"S (%.0f#sigma) %.0f #pm %.0f ",nsigma,signal,errsignal);
2319 pinfo2->AddText(str);
2320 str=Form(
"B (%.0f#sigma) %.0f #pm %.0f",nsigma,bkg,errbkg);
2321 pinfo2->AddText(str);
2322 if(bkg>0) str=Form(
"S/B (%.0f#sigma) %.4f ",nsigma,signal/bkg);
2323 pinfo2->AddText(str);
virtual TH1F * GetOverBackgroundResidualsAndPulls(Double_t minrange=0, Double_t maxrange=-1, TH1 *hPulls=0x0, TH1 *hResidualTrend=0x0, TH1 *hPullsTrend=0x0)
TVirtualPad * GetPad(Double_t nsigma=3, Int_t writeFitInfo=1) const
TH1F * GetHistoClone() const
Float_t * fFitPars
number of parameters of the final function
void DrawHere(TVirtualPad *pd, Double_t nsigma=3, Int_t writeFitInfo=1) const
write the canvas in a root file
Bool_t * fFixPar
kTRUE = only side bands considered
virtual Bool_t CheckRangeFit()
virtual TPaveText * GetFitParametersBox(Double_t nsigma=3., Int_t mode=0)
void SetHisto(const TH1F *histoToFit)
setters
void WriteNtuple(TString path="./") const
write the histogram
Int_t fSideBandr
left side band limit (bin number)
void GetSideBandsBounds(Int_t &lb, Int_t &hb) const
virtual void PlotFit(TVirtualPad *pd, Double_t nsigma=3, Int_t writeFitInfo=1) const
void DrawFit(Double_t nsigma=3) const
Int_t fParsSize
number of bins
virtual void IntS(Float_t *valuewitherror) const
Int_t ftypeOfFit4Sgn
0 = exponential; 1 = linear; 2 = pol2
virtual void ComputeParSize()
Double_t fmaxMass
lower mass limit
Int_t ftypeOfFit4Bkg
signal+background (kTRUE) or signal only (kFALSE)
Double_t GetFitProbability() const
virtual ~AliHFMassFitter()
Double_t fMassErr
signal gaussian mean value
virtual Bool_t RefitWithBkgOnly(Bool_t draw=kTRUE)
virtual void AddFunctionsToHisto()
void PrintParTitles() const
Int_t fmaxBinMass
bin corresponding to fminMass
virtual TPaveText * GetYieldBox(Double_t nsigma=3.)
Double_t fminMass
histogram to fit
virtual void Signal(Double_t nOfSigma, Double_t &signal, Double_t &errsignal) const
return total integral of the histogram
Int_t fNbin
bin corresponding to fmaxMass
virtual Double_t FitFunction4Bkg(Double_t *x, Double_t *par)
Double_t fRawYieldErr
signal gaussian integral
Double_t fSigmaSgnErr
signal gaussian sigma
Double_t GetChiSquare() const
Double_t GetReducedChiSquare() const
Double_t fMass
contains fit parameters
Bool_t GetFixThisParam(Int_t thispar) const
Int_t fcounter
right side band limit (bin number)
void FillNtuParam()
initialize TNtuple to store the parameters
void SetType(Int_t fittypeb, Int_t fittypes)
Int_t fNFinalPars
size of fFitPars array
void InitNtuParam(TString ntuname="ntupar")
void GetFitPars(Float_t *pars) const
virtual void Background(Double_t nOfSigma, Double_t &background, Double_t &errbackground) const
signal in (min, max) with error
virtual Double_t FitFunction4MassDistr(Double_t *x, Double_t *par)
significance in (min, max) with error
Double_t fRawYield
err signal gaussian sigma
TH1F * GetResidualsAndPulls(TH1 *h, TF1 *f, Double_t minrange=0, Double_t maxrange=-1, TH1 *hPulls=0x0, TH1 *hResidualTrend=0x0, TH1 *hPullsTrend=0x0)
void RebinMass(Int_t bingroup=1)
static void ComputeSignificance(Double_t signal, Double_t errsignal, Double_t background, Double_t errbackground, Double_t &significance, Double_t &errsignificance)
Significance calculator.
virtual Bool_t MassFitter(Bool_t draw=kTRUE)
TNtuple * fntuParam
number to multiply to the sigma of the signal to obtain the reflected gaussian
virtual void ComputeNFinalPars()
virtual void SetDefaultFixParam()
Double_t fSigmaSgn
err signal gaussian mean value
TList * fContourGraph
L, LW or Chi2.
Double_t GetBkgChiSquare()
Double_t GetBkgReducedChiSquare()
virtual TH1F * GetAllRangeResidualsAndPulls(Double_t minrange=0, Double_t maxrange=-1, TH1 *hPulls=0x0, TH1 *hResidualTrend=0x0, TH1 *hPullsTrend=0x0)
Int_t ffactor
0 = gaus; 1 = gaus+gaus broadened
void WriteHisto(TString path="./") const
the three functions above all together
Int_t fminBinMass
upper mass limit
Double_t GetSigma() const
virtual Bool_t SetFixThisParam(Int_t thispar, Bool_t fixpar)
Bool_t fSideBands
err on signal gaussian integral
Int_t fNpfits
internal counter
void Significance(Double_t nOfSigma, Double_t &significance, Double_t &errsignificance) const
backgournd in (min, max) with error
TString fFitOption
Number of points used in the fit.
virtual Double_t FitFunction4Sgn(Double_t *x, Double_t *par)
AliHFMassFitter for the fit of invariant mass distribution of charmed mesons.
virtual void WriteCanvas(TString userIDstring="", TString path="./", Double_t nsigma=3, Int_t writeFitInfo=1, Bool_t draw=kFALSE) const
write the TNtuple
AliHFMassFitter & operator=(const AliHFMassFitter &mfit)
TNtuple * NtuParamOneShot(TString ntuname="ntupar")
return the TNtuple