MakeFitDCA.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <TH2.h>
  2. using namespace std;
  3. void MakeFitDCA(TString inFileName, TString outFileName)
  4. {
  5. const float ptBins[] = {0.,0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.};
  6. const int NptBins = 12;
  7. const float etaBins[] = {-1.5,-1.2,-1.,-0.8,-0.6,-0.4,-0.2,0.,0.2,0.4,0.6,0.8,1.,1.2,1.5};
  8. const int NetaBins = 14;
  9. const int Ndim = 3;
  10. const float par[] = {0.,0.,0.,0.,0.};
  11. TF1* func[Ndim][NptBins][NetaBins];
  12. TFile* inFile = new TFile(inFileName.Data(),"read");
  13. TH2F* h_integral[Ndim];
  14. TH2F* h_mean[Ndim];
  15. TH2F* h_sigma[Ndim];
  16. TF1* sigma_pt_fit[Ndim][NetaBins];
  17. TH1F* h_sigma_X[Ndim][NetaBins];
  18. for (Int_t i_dim=0;i_dim<Ndim;i_dim++){
  19. h_integral[i_dim] = new TH2F(Form("h_integral%i",i_dim),Form("Integral of the fit function %i;p_{T};#eta;",i_dim),NptBins,ptBins,NetaBins,etaBins);
  20. h_mean[i_dim] = new TH2F(Form("h_mean%i",i_dim) ,Form("Mean of the fit function %i;p_{T};#eta;",i_dim) ,NptBins,ptBins,NetaBins,etaBins);
  21. h_sigma[i_dim] = new TH2F(Form("h_sigma%i",i_dim) ,Form("Sigma of the fit function %i;p_{T};#eta;",i_dim) ,NptBins,ptBins,NetaBins,etaBins);
  22. }
  23. for (Int_t i_dim=0;i_dim<Ndim;i_dim++){
  24. for (Int_t i_eta=0;i_eta<NetaBins;i_eta++){
  25. sigma_pt_fit[i_dim][i_eta] = new TF1(Form("sigma_pt_fit%i%i",i_dim,i_eta),"pol 7",0.,3.);
  26. //sigma_pt_fit[i_dim][i_eta]->SetParameters(par);
  27. }
  28. }
  29. for (Int_t i_dim=0;i_dim<Ndim;i_dim++){
  30. for (Int_t i_pt=0; i_pt<NptBins;i_pt++){
  31. for (Int_t i_eta=0;i_eta<NetaBins;i_eta++){
  32. cout << Form("dca_fit[%i][%i][%i]",i_dim,i_pt,i_eta) << endl;
  33. func[i_dim][i_pt][i_eta] = (TF1*) inFile->Get(Form("dca_fit_%i_%i_%i",i_dim,i_pt,i_eta));
  34. h_integral[i_dim]->SetBinContent(i_pt+1,i_eta+1,func[i_dim][i_pt][i_eta]->GetParameter(0));
  35. h_integral[i_dim]->SetBinError( i_pt+1,i_eta+1,func[i_dim][i_pt][i_eta]->GetParError(0));
  36. h_mean[i_dim] ->SetBinContent(i_pt+1,i_eta+1,func[i_dim][i_pt][i_eta]->GetParameter(1));
  37. h_mean[i_dim] ->SetBinError( i_pt+1,i_eta+1,func[i_dim][i_pt][i_eta]->GetParError(1));
  38. h_sigma[i_dim] ->SetBinContent(i_pt+1,i_eta+1,func[i_dim][i_pt][i_eta]->GetParameter(2));
  39. h_sigma[i_dim] ->SetBinError( i_pt+1,i_eta+1,func[i_dim][i_pt][i_eta]->GetParError(2));
  40. }
  41. }
  42. }
  43. for (Int_t i_dim=0;i_dim<Ndim;i_dim++){
  44. for (Int_t i_eta=0;i_eta<NetaBins;i_eta++){
  45. h_sigma_X[i_dim][i_eta] = (TH1F*) h_sigma[i_dim]->ProjectionX(Form("h_sigma_X_%i_%i",i_dim,i_eta),i_eta+1,i_eta+2,"e");
  46. }
  47. }
  48. for (Int_t i_dim=0;i_dim<Ndim;i_dim++){
  49. for (Int_t i_eta=0;i_eta<NetaBins;i_eta++){
  50. h_sigma_X[i_dim][i_eta]->Fit(sigma_pt_fit[i_dim][i_eta],"R");
  51. }
  52. }
  53. TFile* outFile = new TFile(outFileName.Data(),"recreate");
  54. outFile->cd();
  55. for (Int_t i_dim=0;i_dim<Ndim;i_dim++){
  56. h_integral[i_dim]->Write();
  57. h_mean[i_dim] ->Write();
  58. h_sigma[i_dim] ->Write();
  59. for (Int_t i_eta=0; i_eta<NetaBins; i_eta++){
  60. h_sigma_X[i_dim][i_eta]->Write();
  61. sigma_pt_fit[i_dim][i_eta]->Write();
  62. }
  63. }
  64. }