TpcLheCMTrack.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include "TObjArray.h"
  2. #include "TClonesArray.h"
  3. #include "TpcLheCMTrack.h"
  4. #include "TpcLheCMPoint.h"
  5. using namespace std;
  6. ClassImp(TpcLheCMTrack)
  7. #define PR(x) cout << #x " = " << x << "\n";
  8. //#define PR(x) ;
  9. //___________________________________________________________
  10. TpcLheCMTrack::TpcLheCMTrack() : TpcLheTrack() {
  11. // Creates a ObjArray of the hits belonging to the track.
  12. fNMapHits = 0;
  13. // fRadius = 0.;
  14. fMappingHits = new TObjArray(0);
  15. } ///:~
  16. //___________________________________________________________
  17. TpcLheCMTrack::TpcLheCMTrack(Int_t tracknumber) :
  18. TpcLheTrack(tracknumber) {
  19. // Same as default constructor except that the track number is set.
  20. fNMapHits = 0;
  21. // fRadius = 0.;
  22. fMappingHits = new TObjArray(0);
  23. SetTrackID(tracknumber);
  24. }
  25. //___________________________________________________________
  26. TpcLheCMTrack::TpcLheCMTrack(Int_t tracknumber, Int_t nhits) :
  27. TpcLheTrack(tracknumber) {
  28. // constructor for nhits
  29. fNMapHits = 0;
  30. // fRadius = 0.;
  31. fMappingHits = new TObjArray(nhits,0);
  32. SetTrackID(tracknumber);
  33. }
  34. //___________________________________________________________
  35. TpcLheCMTrack::~TpcLheCMTrack() {
  36. //
  37. // fMappingHits->Delete();
  38. // cout << " Destructor for CMTrack " << endl;
  39. // fMappingHits->IsOwner() << endl;
  40. if (fMappingHits) {
  41. // cout << " inside " << fMappingHits << endl;
  42. // // fMappingHits->Delete();
  43. delete fMappingHits;
  44. // fMappingHits = NULL;
  45. // cout << " inside " << fMappingHits << endl;
  46. }
  47. }
  48. //___________________________________________________________
  49. void TpcLheCMTrack::SetTrackID(Int_t number) {
  50. // Sets the tracknumber. If the track has already some hits
  51. // assigned the track number of the hits is also set.
  52. SetTrackNumber(number); // fTrackNumber = number;
  53. for (Int_t i = 0; i < fMappingHits->GetEntriesFast(); i++) {
  54. ((TpcLheHit*)fMappingHits->At(i))->SetTrackID(number);
  55. }
  56. }
  57. //___________________________________________________________
  58. void TpcLheCMTrack::Copy( const TpcLheCMTrack* src) {
  59. // copy
  60. fNMapHits = src->GetNumberOfPoints();
  61. // PR(fNMapHits);
  62. fMappingHits->Expand(fNMapHits);
  63. fRealHits->Expand(fNMapHits);
  64. TObjArray *hits = src->GetCMHits();
  65. for (Int_t i = 0; i < fNMapHits; i++) {
  66. fMappingHits->AddAt(hits->At(i), i);
  67. fRealHits->AddAt(dynamic_cast <TpcLheHit *> (hits->At(i)), i);
  68. }
  69. }
  70. //___________________________________________________________
  71. void TpcLheCMTrack::AddPoint(TpcLheCMPoint* point, Bool_t backward) {
  72. // Adds a given point to the track.
  73. Int_t num = fNMapHits;
  74. TpcLheHit *hit = dynamic_cast <TpcLheHit *> (point);
  75. if(backward) {
  76. fMappingHits->Expand(num+1);
  77. fRealHits->Expand(num+1);
  78. for (Int_t i = num-1; i >= 0; i--) {
  79. fMappingHits->AddAt(fMappingHits->At(i), i+1);
  80. fRealHits->AddAt(fRealHits->At(i), i+1);
  81. }
  82. fMappingHits->AddFirst(point);
  83. fRealHits->AddFirst(hit);
  84. }
  85. else {
  86. fMappingHits->AddLast(point);
  87. fRealHits->AddLast(hit);
  88. }
  89. fNMapHits++;
  90. }
  91. //___________________________________________________________
  92. void TpcLheCMTrack::SetPointsUsage() {
  93. // Release track points
  94. // cout << " map points " << fMappingHits->GetEntriesFast() << endl;
  95. for (Int_t i = 0; i < fMappingHits->GetEntriesFast(); i++) {
  96. TpcLheCMPoint *p = (TpcLheCMPoint *)fMappingHits->At(i);
  97. p->SetUsage(kTRUE);
  98. }
  99. }
  100. //___________________________________________________________
  101. void TpcLheCMTrack::Clear() {
  102. //---
  103. // cout << " map points " << fMappingHits->GetEntriesFast() << endl;
  104. if(fMappingHits && fMappingHits->GetEntriesFast() != 0) {
  105. for (Int_t i = 0; i < fMappingHits->GetEntriesFast(); i++) {
  106. TpcLheCMPoint *p = (TpcLheCMPoint *)fMappingHits->At(i);
  107. p->SetUsage(kFALSE);
  108. }
  109. fMappingHits->Clear();
  110. fMappingHits = NULL;
  111. }
  112. }
  113. //______________________________________________________________
  114. void TpcLheCMTrack::Print() {
  115. //
  116. Int_t nhit = fMappingHits->GetEntries();
  117. cout << "\n Track " << fTrackNumber << " nhits " << nhit;
  118. cout << " Primary " << fFromMainVertex << endl;
  119. cout << " vertex XYZ: " << setw(5) << fVertex.GetX();
  120. cout << " " << setw(5) << fVertex.GetY();
  121. cout << " " << setw(5) << fVertex.GetZ();
  122. cout << " Pxyz: ";
  123. cout.precision(3);
  124. cout << " " << setw(7) << fP.X();
  125. cout << " " << setw(7) << fP.Y();
  126. cout << " " << setw(7) << fP.Z();
  127. cout << endl;
  128. TpcLheCMPoint * ghit = NULL;
  129. for (Int_t j=0; j < nhit; j++) {
  130. ghit = (TpcLheCMPoint *) fMappingHits->At(j);
  131. ghit->Print();
  132. }
  133. }