MpdEmcDigitKI.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. ////////////////////////////////////////////////////////////////
  2. // //
  3. // Authors : D.Peresunko, KI //
  4. // //
  5. ////////////////////////////////////////////////////////////////
  6. #include "MpdEmcDigitKI.h"
  7. #include "MpdEmcGeoUtils.h"
  8. #include "MpdEmcPointKI.h"
  9. #include "TMath.h"
  10. #include <iostream>
  11. using namespace std;
  12. // ----- Default constructor -------------------------------------------
  13. MpdEmcDigitKI::MpdEmcDigitKI() : fDetId(0), fE(0), fTime(0), fNprimary(0), fPrimary(nullptr), fPrimEdep(nullptr) {}
  14. MpdEmcDigitKI::MpdEmcDigitKI(MpdEmcPointKI* point)
  15. : fDetId(point->GetDetectorID()),
  16. fE(point->GetEnergyLoss()),
  17. fTime(point->GetTime()),
  18. fNprimary(0),
  19. fPrimary(nullptr),
  20. fPrimEdep(nullptr)
  21. {
  22. if (fE > 0) { // only primaries with non-zero energy deposition count
  23. fNprimary = 1;
  24. fPrimary = new Int_t[1];
  25. fPrimary[0] = point->GetTrackID();
  26. fPrimEdep = new Float_t[1];
  27. fPrimEdep[0] = point->GetEnergyLoss();
  28. }
  29. }
  30. MpdEmcDigitKI::MpdEmcDigitKI(int cellId, float energy, float time, int trackId)
  31. : fDetId(cellId), fE(energy), fTime(time), fNprimary(0), fPrimary(nullptr), fPrimEdep(nullptr)
  32. {
  33. if (trackId >= 0 && energy > 0) {
  34. fNprimary = 1;
  35. fPrimary = new Int_t[1];
  36. fPrimary[0] = trackId;
  37. fPrimEdep = new Float_t[1];
  38. fPrimEdep[0] = energy;
  39. }
  40. }
  41. MpdEmcDigitKI::~MpdEmcDigitKI()
  42. {
  43. if (fPrimary) {
  44. delete[] fPrimary;
  45. fPrimary = nullptr;
  46. }
  47. if (fPrimEdep) {
  48. delete[] fPrimEdep;
  49. fPrimEdep = nullptr;
  50. }
  51. }
  52. Bool_t MpdEmcDigitKI::CanAdd(MpdEmcPointKI* point) const
  53. {
  54. // Check, if point can be added (hits from the same Tower)
  55. return fDetId == (UInt_t) point->GetDetectorID();
  56. }
  57. void MpdEmcDigitKI::AddPoint(MpdEmcPointKI* point)
  58. {
  59. // Adds point (add energy, change time if necessary, add primary)
  60. if (fDetId != (UInt_t) point->GetDetectorID()) {
  61. return;
  62. }
  63. if (point->GetEnergyLoss() == 0.) { // do nothing
  64. return;
  65. }
  66. if (point->GetEnergyLoss() > fE) {
  67. fTime = point->GetTime();
  68. }
  69. // Check if track already exist
  70. Int_t iprim = point->GetTrackID();
  71. Bool_t found = false;
  72. for (Int_t i = 0; i < fNprimary; i++) {
  73. if (fPrimary[i] == iprim) {
  74. fPrimEdep[i] += point->GetEnergyLoss();
  75. found = true;
  76. break;
  77. }
  78. }
  79. if (!found) {
  80. Int_t* tmp = fPrimary;
  81. fPrimary = new Int_t[fNprimary + 1];
  82. for (int i = 0; i < fNprimary; i++) {
  83. fPrimary[i] = tmp[i];
  84. }
  85. fPrimary[fNprimary] = point->GetTrackID();
  86. if (tmp)
  87. delete[] tmp;
  88. Float_t* tmpE = fPrimEdep;
  89. fPrimEdep = new Float_t[fNprimary + 1];
  90. for (int i = 0; i < fNprimary; i++) {
  91. fPrimEdep[i] = tmpE[i];
  92. }
  93. fPrimEdep[fNprimary] = point->GetEnergyLoss();
  94. if (tmpE) {
  95. delete[] tmpE;
  96. }
  97. fNprimary++;
  98. }
  99. fE += point->GetEnergyLoss();
  100. }
  101. // ----- Print -----------------------------------------------------------
  102. void MpdEmcDigitKI::Print(const Option_t* opt) const
  103. {
  104. cout << "MpdEmcDigitKI: " << endl;
  105. cout << "\tDetId: " << fDetId << "\tDeposited energy: " << fE << "\ttime: " << fTime << endl;
  106. cout << "\tNumber of tracks in tower: " << fNprimary << endl;
  107. cout << "Tracks: " << endl;
  108. for (int i = 0; i < fNprimary; i++) {
  109. cout << i << " TrackId " << fPrimary[i] << ", deposited E " << fPrimEdep[i] << endl;
  110. }
  111. }
  112. Int_t MpdEmcDigitKI::Compare(const TObject* obj) const
  113. {
  114. const MpdEmcDigitKI* rhs = dynamic_cast<const MpdEmcDigitKI*>(obj);
  115. if (!rhs) {
  116. return 1;
  117. }
  118. if (fDetId < rhs->fDetId) {
  119. return -1;
  120. } else {
  121. if (fDetId == rhs->fDetId) {
  122. return 0;
  123. } else {
  124. return 1;
  125. }
  126. }
  127. }
  128. double MpdEmcDigitKI::GetZcenter()
  129. {
  130. // return Z coordinate in global system
  131. MpdEmcGeoUtils* geom = MpdEmcGeoUtils::GetInstance();
  132. double x, y, z;
  133. geom->DetIdToGlobalPosition(fDetId, x, y, z);
  134. return z;
  135. }
  136. double MpdEmcDigitKI::GetPhiCenter()
  137. {
  138. // return phi angle in global system
  139. MpdEmcGeoUtils* geom = MpdEmcGeoUtils::GetInstance();
  140. double x, y, z;
  141. geom->DetIdToGlobalPosition(fDetId, x, y, z);
  142. return TMath::ATan2(y, x);
  143. }
  144. // -------------------------------------------------------------------------
  145. ClassImp(MpdEmcDigitKI)