Test3DFitter.C 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include <TFile.h>
  2. #include <TCanvas.h>
  3. #include <TH1.h>
  4. #include <TH3.h>
  5. #include <iostream>
  6. #include <vector>
  7. #include <TString.h>
  8. #include "HbtFitter.h"
  9. //_________________
  10. void Test3DFitter(const char* inFileName = "auau200_pions_3d_cent8.root",
  11. const char* oFileName = "oTest3DFitter.root") {
  12. Int_t mPartType = 3;
  13. Int_t mSourceForm = 0;
  14. Int_t mNonFemtoForm = 0;
  15. Double_t mCoulombSR = 6.;
  16. Bool_t mExcludePoints = false;
  17. Double_t mProjValLo = 0.;
  18. Double_t mProjValHi = 0.05;
  19. TFile *inFile = TFile::Open(inFileName);
  20. //TH3F* hNumer = (TH3F*)inFile->Get("hQinvNum");
  21. //TH3F* hDenom = (TH3F*)inFile->Get("hQinvDen");
  22. TH3F* hNumer = (TH3F*)inFile->Get("hPionBPLCMSFrameKtCF_1_Num_bin_2");
  23. TH3F* hDenom = (TH3F*)inFile->Get("hPionBPLCMSFrameKtCF_1_Den_bin_2");
  24. TH3F* hQinv = (TH3F*)inFile->Get("hPionBPLCMSFrameKtCF_1_Qinv_bin_2");
  25. //Normalazing Qinv histogram in order to get pure Qinv weights
  26. hQinv->Divide(hDenom);
  27. Int_t mQoutNbins = hNumer->GetNbinsX();
  28. Double_t mQoutLo = hNumer->GetXaxis()->GetBinLowEdge(1);
  29. Double_t mQoutHi = hNumer->GetXaxis()->GetBinUpEdge(mQoutNbins);
  30. Int_t mQsideNbins = hNumer->GetNbinsY();
  31. Double_t mQsideLo = hNumer->GetYaxis()->GetBinLowEdge(1);
  32. Double_t mQsideHi = hNumer->GetYaxis()->GetBinUpEdge(mQsideNbins);
  33. Int_t mQlongNbins = hNumer->GetNbinsZ();
  34. Double_t mQlongLo = hNumer->GetZaxis()->GetBinLowEdge(1);
  35. Double_t mQlongHi = hNumer->GetZaxis()->GetBinUpEdge(mQlongNbins);
  36. HbtFitter *fitter = new HbtFitter(mPartType,mSourceForm,mNonFemtoForm,mExcludePoints);
  37. fitter->SetFitMethod(1); //Log-Likelihood
  38. fitter->SetCorrectOnMc(false);
  39. fitter->SetProjectionType(false); //Project by vals
  40. fitter->Set3DBinsNum(mQoutNbins,mQsideNbins,mQlongNbins);
  41. fitter->Set3DHistoRange(mQoutLo,mQoutHi,
  42. mQsideLo,mQsideHi,
  43. mQlongLo,mQlongHi);
  44. fitter->UseCoulombCorrection(true); //on/off Coulomb correction
  45. fitter->Set3DNumer(hNumer);
  46. fitter->Set3DDenom(hDenom);
  47. fitter->Set3DCoulomb(hQinv);
  48. fitter->SetCoulombSourceRadius(mCoulombSR);
  49. //Set fit range
  50. fitter->Set3DFitRange(0., 0.25, 0., 0.25, 0., 0.25);
  51. //Fix cross-term parameters
  52. fitter->FixFitParameter3D(4); //out-side
  53. fitter->FixFitParameter3D(5); //out-long
  54. fitter->FixFitParameter3D(6); //side-long
  55. //Main magic
  56. fitter->Fit3D();
  57. fitter->MakeProjections();
  58. std::cout << "Chi2: " << fitter->GetChi2() << " NDF: " << fitter->GetNDF()
  59. << " Chi2/NDF: " << fitter->GetChi2PerNDF() << std::endl;
  60. TFile *outFile = new TFile(oFileName,"recreate");
  61. //Obtain projections
  62. TH1F* hCorrFctnQoutProj = fitter->Get3DOutProjection();
  63. TH1F* hCorrFctnQsideProj = fitter->Get3DSideProjection();
  64. TH1F* hCorrFctnQlongProj = fitter->Get3DLongProjection();
  65. TH1F* hFitQoutProj = fitter->Get3DFitOutProjection();
  66. TH1F* hFitQsideProj = fitter->Get3DFitSideProjection();
  67. TH1F* hFitQlongProj = fitter->Get3DFitLongProjection();
  68. TCanvas *canv = new TCanvas("canv","canv",800,600);
  69. canv->Divide(3,1);
  70. canv->cd(1);
  71. hCorrFctnQoutProj->Draw();
  72. hCorrFctnQoutProj->GetXaxis()->SetRange(0.,0.3);
  73. hFitQoutProj->SetLineColor(kRed);
  74. hFitQoutProj->Draw("sameL");
  75. canv->cd(2);
  76. hCorrFctnQsideProj->Draw();
  77. hCorrFctnQsideProj->GetXaxis()->SetRange(0.,0.3);
  78. hFitQsideProj->SetLineColor(kRed);
  79. hFitQsideProj->Draw("sameL");
  80. canv->cd(3);
  81. hCorrFctnQlongProj->Draw();
  82. hCorrFctnQlongProj->GetXaxis()->SetRange(0.,0.3);
  83. hFitQlongProj->SetLineColor(kRed);
  84. hFitQlongProj->Draw("sameL");
  85. //outFile->Write();
  86. hCorrFctnQoutProj->Write();
  87. hCorrFctnQsideProj->Write();
  88. hCorrFctnQlongProj->Write();
  89. hFitQoutProj->Write();
  90. hFitQsideProj->Write();
  91. hFitQlongProj->Write();
  92. outFile->Close();
  93. std::vector<double> mRetVal = fitter->GetFemto3DParameters();
  94. std::vector<double> mRetValErr = fitter->GetFemto3DParError();
  95. std::vector<double> mRetNonFemtoVal = fitter->GetNonFemto3DParameters();
  96. std::vector<double> mRetNonFemtoValErr = fitter->GetNonFemto3DParError();
  97. double chi2PerNDF = fitter->GetChi2PerNDF();
  98. std::cout << "Fit parameters:" << std::endl;
  99. std::cout << "Chi2/NDF: " << chi2PerNDF << std::endl;
  100. for(unsigned int iVal = 0; iVal < mRetVal.size(); iVal++) {
  101. std::cout << Form("Par: %d %4.3f+/-%4.3f",iVal,mRetVal.at(iVal),
  102. mRetValErr.at(iVal)) << std::endl;
  103. }
  104. std::cout << Form("Norm: %4.3f+/-%4.3f",mRetNonFemtoVal.at(0),
  105. mRetNonFemtoValErr.at(0)) << std::endl;
  106. }