MpdTpcEDepParams.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /// \class MpdTpcEDepParams
  2. ///
  3. /// Parameters for MPD TPC dE/dx simulation
  4. /// \author Igor Rufanov (LHEP, JINR, Dubna) - development
  5. /// \author Alexander Zinchenko (LHEP, JINR, Dubna) - porting to MpdRoot
  6. /// 18/11/2019
  7. #include "MpdTpcEDepParams.h"
  8. #include <TFile.h>
  9. #include <TH2D.h>
  10. #include <TMath.h>
  11. #include <TRandom.h>
  12. //#include <TSystem.h>
  13. #include <iostream>
  14. using std::cout;
  15. using std::endl;
  16. using std::vector;
  17. MpdTpcEDepParams* MpdTpcEDepParams::fgTpcEdepParams = nullptr;
  18. //__________________________________________________________________________
  19. MpdTpcEDepParams* MpdTpcEDepParams::Instance()
  20. {
  21. /// Get pointer to the TPC ionization loss patameter object
  22. if (!fgTpcEdepParams) {
  23. fgTpcEdepParams = new MpdTpcEDepParams;
  24. // Automatic deletion
  25. std::atexit(DestroyInstance);
  26. }
  27. return fgTpcEdepParams;
  28. }
  29. //__________________________________________________________________________
  30. void MpdTpcEDepParams::Init()
  31. {
  32. /// Get histograms and initialize parameters
  33. TFile *file = new TFile("$VMCWORKDIR/input/TpcEDepParamsHeed.root");
  34. TH1D *h = (TH1D*) file->Get("NCollTab");
  35. fNCollDensBgBins = h->GetNbinsX();
  36. fCollDensL10BgMin = h->GetBinCenter(1);
  37. //fCollDensL10BgMin = -0.5;
  38. fCollDensL10BgMax = h->GetBinCenter(fNCollDensBgBins);
  39. fCollDensL10BgStep = (fCollDensL10BgMax - fCollDensL10BgMin) / (fNCollDensBgBins - 1);
  40. fCollDens = new Double_t [fNCollDensBgBins];
  41. for (Int_t i = 0; i < fNCollDensBgBins; i++)
  42. fCollDens[i] = h->GetBinContent(i+1);
  43. TH2D *he = (TH2D*) file->Get("InvertedProbFuncEDep2");
  44. fNEneBgBins = he->GetNbinsX();
  45. fEneL10BgMin = he->GetXaxis()->GetBinCenter(1);
  46. fEneL10BgMax = he->GetXaxis()->GetBinCenter(fNEneBgBins);
  47. fEneL10BgStep = (fEneL10BgMax - fEneL10BgMin) / (fNEneBgBins - 1);
  48. fNEneProbBins = he->GetNbinsY();
  49. fEneProbStep = 1.0 / (fNEneProbBins - 2);
  50. vector<Double_t> probs(fNEneProbBins);
  51. fEne.resize(fNEneBgBins, probs);
  52. for (Int_t i = 0; i < fNEneBgBins; i++) {
  53. for (Int_t j = 0; j < fNEneProbBins; j++) {
  54. //fEne[i][j] = he->GetBinContent(i+1,j+1);
  55. fEne[i][j] = he->GetBinContent(i+1,j+2);
  56. }
  57. }
  58. file->Close();
  59. }
  60. //__________________________________________________________________________
  61. Double_t MpdTpcEDepParams::GetCollisionDensity (Double_t log10bg)
  62. {
  63. /// Number of clusters / cm vs log10(beta*gamma)
  64. Double_t bin = (log10bg - fCollDensL10BgMin) / fCollDensL10BgStep;
  65. if (bin <= 0.) return fCollDens[0];
  66. else if (bin >= fNCollDensBgBins-2) return fCollDens [fNCollDensBgBins-2];
  67. else {
  68. Int_t ib = (Int_t) bin;
  69. Double_t d = bin - ib;
  70. return fCollDens[ib] * (1.0 - d) + fCollDens[ib+1] * d;
  71. }
  72. }
  73. //__________________________________________________________________________
  74. Double_t MpdTpcEDepParams::GetRandEnergy (Double_t log10bg)
  75. {
  76. /// Energy in the cluster vs log10(beta*gamma)
  77. Int_t ib = 0;//, ib1 = 0;
  78. Double_t bin = (log10bg - fEneL10BgMin) / fEneL10BgStep;
  79. if (bin <= 0.) ib = 0;
  80. else if (bin >= fNEneBgBins-1) ib = fNEneBgBins - 1;
  81. else {
  82. //ib = round( bin);
  83. // smearing at bin boundary
  84. ib = (Int_t) bin;
  85. Double_t d = bin - ib;
  86. if (gRandom->Uniform(0.,1.) > (1.0-d)) ib++;
  87. if (ib >= fNEneBgBins) exit(0);
  88. }
  89. /*
  90. else {
  91. ib = (Int_t) (bin + 0.5);
  92. if (ib >= fNEneBgBins) exit(0);
  93. }
  94. */
  95. /*
  96. else {
  97. // Linear combination
  98. ib = ib1 = (Int_t) bin;
  99. if (ib1 < fNEneBgBins - 1) ++ib1;
  100. }
  101. */
  102. Double_t prob = gRandom->Uniform(0.,1.);
  103. Double_t probBin = prob / fEneProbStep;
  104. Int_t ip = (Int_t) probBin;
  105. Double_t p = probBin - ip;
  106. Double_t l10 = fEne[ib][ip] * (1.-p) + fEne[ib][ip+1] * p;
  107. //Double_t l101 = fEne[ib1][ip] * (1.-p) + fEne[ib1][ip+1] * p;
  108. //Double_t d = bin - ib;
  109. //l10 = l10 * (1.0 - d) + l101 * d;
  110. if (ip + 1 >= fNEneProbBins) exit(0);
  111. //cout << l10 << " " << ib << " " << ip << endl;
  112. return TMath::Power(10.,l10);
  113. /*
  114. Double_t l10 = TMath::Power(10., fEne[ib][ip]);
  115. Double_t l101 = TMath::Power(10., fEne[ib][ip+1]);
  116. return l10 * (1.0 - p) + l101 * p;
  117. */
  118. }
  119. //__________________________________________________________________________
  120. Double_t MpdTpcEDepParams::GetEloss (Double_t log10bg, Double_t charge, Double_t step)
  121. {
  122. /// Energy loss for given log10(beta*gamma) and step
  123. Double_t collDens = GetCollisionDensity (log10bg) *charge*charge;
  124. Double_t nColl = gRandom->PoissonD (collDens * step);
  125. Double_t eloss = 0;
  126. for (Int_t i = 0; i < nColl; ++i) eloss += GetRandEnergy (log10bg);
  127. //cout << nColl << " xxxx " << eloss << endl;
  128. return eloss * 1e-9;
  129. }
  130. //__________________________________________________________________________