CentralityCalculator.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "CentralityCalculator.h"
  2. #include <TLine.h>
  3. #include <TCanvas.h>
  4. #include <TLatex.h>
  5. #include <iostream>
  6. #include <fstream>
  7. CentralityCalculator::CentralityCalculator()
  8. {
  9. RNG = new TRandom3();
  10. for (int i = 0; i <= NmultiplicityBins; ++i)
  11. {
  12. multiplicity_bins[i] = 1;
  13. }
  14. fEfficiency = 1.;
  15. }
  16. CentralityCalculator::~CentralityCalculator()
  17. {
  18. delete RNG;
  19. delete fHmult;
  20. }
  21. Int_t CentralityCalculator::Integrate(Int_t max_bin, Float_t sum)
  22. {
  23. for (Int_t mult_bin = 1; mult_bin <= max_bin; ++mult_bin)
  24. {
  25. if (fHmult->Integral(1, mult_bin, "WIDTH") >= sum)
  26. {
  27. //return floating-point multiplicity value
  28. return fHmult->GetBinLowEdge(mult_bin) + 1 - ((fHmult->Integral(1, mult_bin, "WIDTH") - sum) / fHmult->GetBinContent(mult_bin));
  29. }
  30. }
  31. return max_bin;
  32. }
  33. Int_t CentralityCalculator::GetCent(Int_t multiplicity)
  34. {
  35. int CentrBin = -1;
  36. // --- Centrality bins selection
  37. for (int i = 0; i < 10; ++i)
  38. {
  39. if (multiplicity >= lim.L[i] && multiplicity <= lim.H[i])
  40. {
  41. CentrBin = i;
  42. break;
  43. }
  44. else
  45. CentrBin = 10;
  46. }
  47. CentrBin *= 10;
  48. return CentrBin;
  49. }
  50. Int_t CentralityCalculator::GetCentrality(Int_t multiplicity)
  51. {
  52. Int_t cent = GetCent(multiplicity);
  53. return cent;
  54. }
  55. void CentralityCalculator::Calc()
  56. {
  57. lim = CentralityBorders(fHmult);
  58. }
  59. void CentralityCalculator::DrawHistogram(TString outName)
  60. {
  61. TH1F *hist = (TH1F *)fHmult->Clone();
  62. TLine line;
  63. TCanvas *canv = new TCanvas(Form("%s", "canvas"), Form("%s", "canvas"), 900, 650);
  64. canv->cd();
  65. canv->SetLogy();
  66. hist->Draw();
  67. line.SetLineColor(1);
  68. line.SetLineWidth(2);
  69. for (int i = 0; i < (Int_t)(NmultiplicityBins / 10); i++)
  70. {
  71. line.DrawLine(lim.L[i], 0., lim.L[i], hist->GetBinContent(hist->FindBin(lim.L[i])));
  72. }
  73. TLatex tex;
  74. tex.DrawLatexNDC(0.35, 0.85, Form("Au+Au, %s, #sqrt{s_{NN}}=%3.1f GeV", fModel.Data(), fEnergy));
  75. canv->SaveAs(Form("%s", outName.Data()));
  76. }
  77. void CentralityCalculator::GenerateMacro(TString outName)
  78. {
  79. const int NcentBins = 7; // We use only 0-80%
  80. std::cout << "Int_t cent8(Int_t mult)" << std::endl;
  81. std::cout << "{" << std::endl;
  82. std::cout << " Int_t fcent = -1;" << std::endl;
  83. std::cout << " if (mult >= " << lim.L[0] << ") fcent = 0;" << std::endl;
  84. for (int i = 1; i < NcentBins; i++)
  85. {
  86. std::cout << " if (mult >= " << lim.L[i + 1]
  87. << " && mult < " << lim.L[i] << ") fcent = "
  88. << i + 1 << ";" << std::endl;
  89. }
  90. std::cout << std::endl;
  91. std::cout << " return fcent;" << std::endl;
  92. std::cout << "}" << std::endl;
  93. if (outName != "")
  94. {
  95. std::ofstream myfile;
  96. myfile.open(outName.Data());
  97. myfile << "Int_t cent8(Int_t mult)" << std::endl;
  98. myfile << "{" << std::endl;
  99. myfile << " Int_t fcent = -1;" << std::endl;
  100. myfile << " if (mult >= " << lim.L[0] << ") fcent = 0;" << std::endl;
  101. for (int i = 1; i < NcentBins; i++)
  102. {
  103. myfile << " if (mult >= " << lim.L[i]
  104. << " && mult < " << lim.L[i] << ") fcent = "
  105. << i + 1 << ";" << std::endl;
  106. }
  107. myfile << std::endl;
  108. myfile << " return fcent;" << std::endl;
  109. myfile << "}" << std::endl;
  110. myfile.close();
  111. }
  112. }