CalcNewXY.C 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #include <iostream>
  2. #include <TFile.h>
  3. #include <TH1D.h>
  4. #include <TH2D.h>
  5. #include <TF1.h>
  6. #include <TGraphErrors.h>
  7. const int Niter = 20;
  8. const int NptBins = 15;
  9. const Double_t ptBins[NptBins + 1] = {0.2, 0.4, 0.6, 0.8, 1., 1.2, 1.4, 1.6, 1.8, 2., 2.2, 2.4, 2.6, 2.8, 3., 3.2};
  10. void CalcNewXY(const Char_t *inFileName, const Char_t *outFileName)
  11. {
  12. TFile *fi = new TFile(inFileName, "read");
  13. fi->cd();
  14. TH2D *hNewXYCut[NptBins];
  15. TH1D *hNewX[NptBins], *hNewYPion[NptBins], *hNewYKaon[NptBins];
  16. TF1 *gausPionX[NptBins], *gausPionY[NptBins];
  17. TF1 *gausKaonX[NptBins], *gausKaonY[NptBins];
  18. TF1 *gausPiBgX[NptBins], *gausPiBgY[NptBins];
  19. TF1 *gausKaBgX[NptBins], *gausKaBgY[NptBins];
  20. TF1 *gausDoubleX[NptBins], *gausDoublePionY[NptBins], *gausDoubleKaonY[NptBins];
  21. TF1 *polPionX, *polKaonX, *polPionY, *polKaonY, *polMeanX;
  22. TGraphErrors *grSigmPionX, *grSigmPionY, *grSigmKaonX, *grSigmKaonY;
  23. TGraphErrors *grMeanKaonX;
  24. std::vector<Double_t> vXX, vXYPion, vXeX, vXeYPion, vXYKaon, vXeYKaon;
  25. std::vector<Double_t> vYX, vYYPion, vYeX, vYeYPion, vYYKaon, vYeYKaon;
  26. std::vector<Double_t> vMeanKaonX, vMeanKaoneX;
  27. for (int i = 0; i < NptBins; i++)
  28. {
  29. hNewXYCut[i] = (TH2D *)fi->Get(Form("hPionNewXYCut%i", i));
  30. gausPionX[i] = new TF1(Form("gausPionX%i", i), "gaus", -0.1, 0.1);
  31. gausKaonX[i] = new TF1(Form("gausKaonX%i", i), "gaus", 0.15, 0.3);
  32. gausPionY[i] = new TF1(Form("gausPionY%i", i), "gaus", -0.1, 0.1);
  33. gausKaonY[i] = new TF1(Form("gausKaonY%i", i), "gaus", -0.1, 0.1);
  34. gausPiBgX[i] = new TF1(Form("gausPiBgX%i", i), "gaus", -0.2, 0.2);
  35. gausKaBgX[i] = new TF1(Form("gausKaBgX%i", i), "gaus", 0.1, 0.4);
  36. gausPiBgY[i] = new TF1(Form("gausPiBgY%i", i), "gaus", -0.2, 0.2);
  37. gausKaBgY[i] = new TF1(Form("gausKaBgY%i", i), "gaus", -0.2, 0.2);
  38. gausDoubleX[i] = new TF1(Form("gausDoubleX%i", i), "gaus(0)+gaus(3)+gaus(6)+gaus(9)", -0.2, 0.8);
  39. gausDoublePionY[i] = new TF1(Form("gausDoublePionY%i", i), "gaus(0)+gaus(3)", -0.4, 0.4);
  40. gausDoubleKaonY[i] = new TF1(Form("gausDoubleKaonY%i", i), "gaus(0)+gaus(3)", -0.4, 0.4);
  41. }
  42. for (int i = 0; i < NptBins; i++)
  43. {
  44. hNewX[i] = (TH1D *)hNewXYCut[i]->ProjectionX(Form("hNewX%i", i));
  45. hNewYKaon[i] = (TH1D *)hNewXYCut[i]->ProjectionY(Form("hNewYKaon%i", i),(Int_t)hNewXYCut[i]->GetXaxis()->FindBin(0.16),(Int_t)hNewXYCut[i]->GetXaxis()->FindBin(0.5));
  46. hNewYPion[i] = (TH1D *)hNewXYCut[i]->ProjectionY(Form("hNewYPion%i", i),(Int_t)hNewXYCut[i]->GetXaxis()->FindBin(-0.2),(Int_t)hNewXYCut[i]->GetXaxis()->FindBin(0.2));
  47. }
  48. polPionX = new TF1("polPionX","pol3",0.2,3.2);
  49. polKaonX = new TF1("polKaonX","pol3",0.2,3.2);
  50. polPionY = new TF1("polPionY","pol3",0.2,3.2);
  51. polKaonY = new TF1("polKaonY","pol3",0.2,3.2);
  52. polMeanX = new TF1("polMeanX","pol3",0.2,2.);
  53. Double_t parX[12], parYPion[6], parYKaon[6];
  54. std::cout << "Fitting procedure begins" << std::endl;
  55. for (int i = 0; i < NptBins; i++)
  56. {
  57. std::cout << "pT-range " << i << std::endl;
  58. for (int j = 0; j < Niter; j++)
  59. {
  60. hNewX[i]->Fit(gausPionX[i], "RQ0");
  61. hNewX[i]->Fit(gausKaonX[i], "RQ0");
  62. hNewX[i]->Fit(gausPiBgX[i], "RQ0");
  63. hNewX[i]->Fit(gausKaBgX[i], "RQ0");
  64. hNewYPion[i]->Fit(gausPionY[i], "RQ0");
  65. hNewYKaon[i]->Fit(gausKaonY[i], "RQ0");
  66. hNewYPion[i]->Fit(gausPiBgY[i], "RQ0");
  67. hNewYKaon[i]->Fit(gausKaBgY[i], "RQ0");
  68. }
  69. gausPionX[i]->GetParameters(&parX[0]);
  70. gausKaonX[i]->GetParameters(&parX[3]);
  71. gausPiBgX[i]->GetParameters(&parX[6]);
  72. gausKaBgX[i]->GetParameters(&parX[9]);
  73. gausPionY[i]->GetParameters(&parYPion[0]);
  74. gausKaonY[i]->GetParameters(&parYKaon[0]);
  75. gausPiBgY[i]->GetParameters(&parYPion[3]);
  76. gausKaBgY[i]->GetParameters(&parYKaon[3]);
  77. gausDoubleX[i]->SetParameters(parX);
  78. gausDoublePionY[i]->SetParameters(parYPion);
  79. gausDoubleKaonY[i]->SetParameters(parYKaon);
  80. for (int j = 0; j < Niter; j++)
  81. {
  82. if (j != Niter - 1)
  83. {
  84. hNewX[i]->Fit(gausDoubleX[i], "RQ0");
  85. hNewYPion[i]->Fit(gausDoublePionY[i], "RQ0");
  86. hNewYKaon[i]->Fit(gausDoubleKaonY[i], "RQ0");
  87. }
  88. if (j == Niter - 1)
  89. {
  90. hNewX[i]->Fit(gausDoubleX[i], "R");
  91. hNewYPion[i]->Fit(gausDoublePionY[i], "R");
  92. hNewYKaon[i]->Fit(gausDoubleKaonY[i], "R");
  93. }
  94. }
  95. vXX.push_back(0.5 * (ptBins[i] + ptBins[i + 1]));
  96. vYX.push_back(0.5 * (ptBins[i] + ptBins[i + 1]));
  97. vXeX.push_back(0.);
  98. vYeX.push_back(0.);
  99. //Pion sigma (NewX)
  100. if ((gausDoubleX[i]->GetParameter(8) < 0 && gausDoubleX[i]->GetParameter(2) >= 0) || (gausDoubleX[i]->GetParameter(2) >= 0 && gausDoubleX[i]->GetParameter(2) < gausDoubleX[i]->GetParameter(8)))
  101. {
  102. vXYPion.push_back(gausDoubleX[i]->GetParameter(2));
  103. vXeYPion.push_back(gausDoubleX[i]->GetParError(2));
  104. }
  105. else
  106. {
  107. vXYPion.push_back(gausDoubleX[i]->GetParameter(8));
  108. vXeYPion.push_back(gausDoubleX[i]->GetParError(8));
  109. }
  110. //Kaon sigma (NewX)
  111. if (gausDoubleX[i]->GetParameter(11) < 0 || (gausDoubleX[i]->GetParameter(5) >= 0 && gausDoubleX[i]->GetParameter(5) < gausDoubleX[i]->GetParameter(11)))
  112. {
  113. vXYKaon.push_back(gausDoubleX[i]->GetParameter(5));
  114. vXeYKaon.push_back(gausDoubleX[i]->GetParError(5));
  115. vMeanKaonX.push_back(gausDoubleX[i]->GetParameter(4));
  116. vMeanKaoneX.push_back(gausDoubleX[i]->GetParError(4));
  117. }
  118. else
  119. {
  120. vXYKaon.push_back(gausDoubleX[i]->GetParameter(11));
  121. vXeYKaon.push_back(gausDoubleX[i]->GetParError(11));
  122. vMeanKaonX.push_back(gausDoubleX[i]->GetParameter(10));
  123. vMeanKaoneX.push_back(gausDoubleX[i]->GetParError(10));
  124. }
  125. //Pion sigma (NewY)
  126. if (gausDoublePionY[i]->GetParameter(5) < 0 || (gausDoublePionY[i]->GetParameter(2) >= 0 && gausDoublePionY[i]->GetParameter(2) < gausDoublePionY[i]->GetParameter(5)))
  127. {
  128. vYYPion.push_back(gausDoublePionY[i]->GetParameter(2));
  129. vYeYPion.push_back(gausDoublePionY[i]->GetParError(2));
  130. }
  131. else
  132. {
  133. vYYPion.push_back(gausDoublePionY[i]->GetParameter(5));
  134. vYeYPion.push_back(gausDoublePionY[i]->GetParError(5));
  135. }
  136. //Kaon sigma (NewY)
  137. if (gausDoubleKaonY[i]->GetParameter(5) < 0 || (gausDoubleKaonY[i]->GetParameter(2) >= 0 && gausDoubleKaonY[i]->GetParameter(2) < gausDoubleKaonY[i]->GetParameter(5)))
  138. {
  139. vYYKaon.push_back(gausDoubleKaonY[i]->GetParameter(2));
  140. vYeYKaon.push_back(gausDoubleKaonY[i]->GetParError(2));
  141. }
  142. else
  143. {
  144. vYYKaon.push_back(gausDoubleKaonY[i]->GetParameter(5));
  145. vYeYKaon.push_back(gausDoubleKaonY[i]->GetParError(5));
  146. }
  147. }
  148. grSigmPionX = new TGraphErrors(vXX.size(), &vXX[0], &vXYPion[0], &vXeX[0], &vXeYPion[0]);
  149. grSigmKaonX = new TGraphErrors(vXX.size(), &vXX[0], &vXYKaon[0], &vXeX[0], &vXeYKaon[0]);
  150. grSigmPionY = new TGraphErrors(vYX.size(), &vYX[0], &vYYPion[0], &vYeX[0], &vYeYPion[0]);
  151. grSigmKaonY = new TGraphErrors(vYX.size(), &vYX[0], &vYYKaon[0], &vYeX[0], &vYeYKaon[0]);
  152. grMeanKaonX = new TGraphErrors(vXX.size(), &vXX[0], &vMeanKaonX[0], &vXeX[0], &vMeanKaoneX[0]);
  153. grSigmPionX->SetName("grSigmPionX");
  154. grSigmKaonX->SetName("grSigmKaonX");
  155. grSigmPionY->SetName("grSigmPionY");
  156. grSigmKaonY->SetName("grSigmKaonY");
  157. grMeanKaonX->SetName("grMeanKaonX");
  158. // Removing negative points
  159. for (int i=0;i<vXX.size();i++)
  160. {
  161. if (grSigmPionX->GetY()[i] < 0 || (i!=0 && grSigmPionX->GetY()[i] > 5*grSigmPionX->GetY()[i-1]) ) {grSigmPionX->RemovePoint(i); i--;}
  162. if (grSigmKaonX->GetY()[i] < 0 || (i!=0 && grSigmKaonX->GetY()[i] > 5*grSigmKaonX->GetY()[i-1]) ) {grSigmKaonX->RemovePoint(i); i--;}
  163. if (grSigmPionY->GetY()[i] < 0 || (i!=0 && grSigmPionY->GetY()[i] > 5*grSigmPionY->GetY()[i-1]) ) {grSigmPionY->RemovePoint(i); i--;}
  164. if (grSigmKaonY->GetY()[i] < 0 || (i!=0 && grSigmKaonY->GetY()[i] > 5*grSigmKaonY->GetY()[i-1]) ) {grSigmKaonY->RemovePoint(i); i--;}
  165. }
  166. for (int j = 0; j < Niter; j++)
  167. {
  168. if (j != Niter - 1)
  169. {
  170. grSigmPionX->Fit(polPionX,"RQ0");
  171. grSigmKaonX->Fit(polKaonX,"RQ0");
  172. grSigmPionY->Fit(polPionY,"RQ0");
  173. grSigmKaonY->Fit(polKaonY,"RQ0");
  174. grMeanKaonX->Fit(polMeanX,"RQ0");
  175. }
  176. if (j == Niter - 1)
  177. {
  178. grSigmPionX->Fit(polPionX,"R");
  179. grSigmKaonX->Fit(polKaonX,"R");
  180. grSigmPionY->Fit(polPionY,"R");
  181. grSigmKaonY->Fit(polKaonY,"R");
  182. grMeanKaonX->Fit(polMeanX,"R");
  183. }
  184. }
  185. TFile *fo = new TFile(outFileName, "recreate");
  186. fo->cd();
  187. for (int i = 0; i < NptBins; i++)
  188. {
  189. hNewX[i]->Write();
  190. }
  191. for (int i = 0; i < NptBins; i++)
  192. {
  193. gausDoubleX[i]->Write();
  194. }
  195. for (int i = 0; i < NptBins; i++)
  196. {
  197. hNewYPion[i]->Write();
  198. hNewYKaon[i]->Write();
  199. }
  200. for (int i = 0; i < NptBins; i++)
  201. {
  202. gausDoublePionY[i]->Write();
  203. gausDoubleKaonY[i]->Write();
  204. }
  205. grSigmPionX->Write();
  206. grSigmKaonX->Write();
  207. grSigmPionY->Write();
  208. grSigmKaonY->Write();
  209. grMeanKaonX->Write();
  210. polPionX->Write();
  211. polKaonX->Write();
  212. polPionY->Write();
  213. polKaonY->Write();
  214. polMeanX->Write();
  215. }