Test3DFitter.C 4.2 KB

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