MpdMCTracks.cxx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // -------------------------------------------------------------------------
  2. // ----- MpdMCTracks source file -----
  3. // ----- Created 10/12/07 by M. Al-Turany -----
  4. // -------------------------------------------------------------------------
  5. #include "MpdMCTracks.h"
  6. #include "FairRootManager.h"
  7. #include "FairLogger.h"
  8. #include "TEveManager.h" // for gEve
  9. #include "TEvePathMark.h"
  10. #include "TEveVector.h"
  11. #include "TGeoTrack.h"
  12. #include "TMathBase.h"
  13. #include "TObjArray.h"
  14. #include <iostream>
  15. using namespace std;
  16. // ----- Default constructor -------------------------------------------
  17. MpdMCTracks::MpdMCTracks()
  18. : FairTask("MpdMCTracks", 0),
  19. fTrackList(NULL),
  20. fTrPr(NULL),
  21. fEventManager(NULL),
  22. fEveTrList(NULL),
  23. fTrList(NULL),
  24. MinEnergyLimit(-1.),
  25. MaxEnergyLimit(-1.),
  26. PEnergy(-1.)
  27. {
  28. }
  29. // ----- Standard constructor ------------------------------------------
  30. MpdMCTracks::MpdMCTracks(const char* name, Int_t iVerbose)
  31. : FairTask(name, iVerbose),
  32. fTrackList(NULL),
  33. fTrPr(NULL),
  34. fEventManager(NULL),
  35. fEveTrList(new TObjArray(16)),
  36. fTrList(NULL),
  37. MinEnergyLimit(-1.),
  38. MaxEnergyLimit(-1.),
  39. PEnergy(-1.)
  40. {
  41. }
  42. // ----- Destructor ----------------------------------------------------
  43. MpdMCTracks::~MpdMCTracks()
  44. {
  45. }
  46. // -------------------------------------------------------------------------
  47. InitStatus MpdMCTracks::Init()
  48. {
  49. LOG(DEBUG)<<"MpdMCTracks::Init()";
  50. FairRootManager* fManager = FairRootManager::Instance();
  51. fEventManager = MpdEventManager::Instance();
  52. LOG(DEBUG1) << "MpdMCTracks::Init() get instance of MpdEventManager ";
  53. fTrackList = (TClonesArray*) fManager->GetObject("GeoTracks");
  54. if (fTrackList == 0)
  55. {
  56. LOG(ERROR)<<"MpdMCTracks::Init() branch "<<GetName()<<" not found! Task will be deactivated";
  57. SetActive(kFALSE);
  58. }
  59. LOG(DEBUG1)<<"MpdMCTracks::Init() get track list "<<fTrackList;
  60. MinEnergyLimit = fEventManager->GetEvtMinEnergy();
  61. MaxEnergyLimit = fEventManager->GetEvtMaxEnergy();
  62. PEnergy = 0;
  63. if (IsActive()) return kSUCCESS;
  64. else return kERROR;
  65. }
  66. // -------------------------------------------------------------------------
  67. void MpdMCTracks::Exec(Option_t* /*option*/)
  68. {
  69. if (!IsActive())
  70. return;
  71. LOG(DEBUG1)<<"MpdMCTracks::Exec";
  72. Reset();
  73. TGeoTrack* tr;
  74. const Double_t* point;
  75. for (Int_t i = 0; i < fTrackList->GetEntriesFast(); i++)
  76. {
  77. LOG(DEBUG3)<<"MpdMCTracks::Exec "<<i;
  78. tr = (TGeoTrack*) fTrackList->At(i);
  79. TParticle* P = (TParticle*) tr->GetParticle();
  80. PEnergy = P->Energy();
  81. MinEnergyLimit = TMath::Min(PEnergy, MinEnergyLimit);
  82. MaxEnergyLimit = TMath::Max(PEnergy, MaxEnergyLimit);
  83. LOG(DEBUG3)<<"MinEnergyLimit "<<MinEnergyLimit<<" MaxEnergyLimit "<<MaxEnergyLimit;
  84. if ((fEventManager->IsPriOnly() && (P->GetMother(0) > -1)))
  85. continue;
  86. if ((fEventManager->GetCurrentPDG() != 0) && (fEventManager->GetCurrentPDG() != tr->GetPDG()))
  87. continue;
  88. LOG(DEBUG3)<<"PEnergy "<<PEnergy<<" Min "<<fEventManager->GetMinEnergy()<<" Max "<<fEventManager->GetMaxEnergy();
  89. if ((PEnergy < fEventManager->GetMinEnergy()) || (PEnergy > fEventManager->GetMaxEnergy()))
  90. continue;
  91. fTrList = GetTrGroup(P);
  92. TEveTrack* track = new TEveTrack(P, tr->GetPDG(), fTrPr);
  93. track->SetLineColor(fEventManager->Color(tr->GetPDG()));
  94. Int_t Np = tr->GetNpoints();
  95. for (Int_t n = 0; n < Np; n++)
  96. {
  97. point = tr->GetPoint(n);
  98. track->SetPoint(n, point[0], point[1], point[2]);
  99. TEveVector pos = TEveVector(point[0], point[1], point[2]);
  100. TEvePathMark* path = new TEvePathMark();
  101. path->fV = pos;
  102. path->fTime = point[3];
  103. if (n == 0)
  104. {
  105. TEveVector Mom = TEveVector(P->Px(), P->Py(), P->Pz());
  106. path->fP = Mom;
  107. }
  108. track->AddPathMark(*path);
  109. LOG(DEBUG4)<<"Path marker added "<<path;
  110. delete path;
  111. }
  112. fTrList->AddElement(track);
  113. LOG(DEBUG3)<<"Track added "<<track->GetName();
  114. }
  115. //for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++)
  116. //{
  117. // TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
  118. // TrListIn->FindMomentumLimits(TrListIn, kFALSE);
  119. //}
  120. fEventManager->SetEvtMinEnergy(MinEnergyLimit);
  121. fEventManager->SetEvtMaxEnergy(MaxEnergyLimit);
  122. //gEve->Redraw3D(kFALSE);
  123. }
  124. // -------------------------------------------------------------------------
  125. void MpdMCTracks::SetParContainers()
  126. {
  127. }
  128. // -------------------------------------------------------------------------
  129. void MpdMCTracks::Finish()
  130. {
  131. }
  132. // -------------------------------------------------------------------------
  133. void MpdMCTracks::Reset()
  134. {
  135. for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++)
  136. {
  137. TEveTrackList* ele = (TEveTrackList*) fEveTrList->At(i);
  138. gEve->RemoveElement(ele, fEventManager->EveMCTracks);
  139. }
  140. fEveTrList->Clear();
  141. }
  142. TEveTrackList* MpdMCTracks::GetTrGroup(TParticle* P)
  143. {
  144. fTrList = 0;
  145. for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++)
  146. {
  147. TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
  148. if (strcmp(TrListIn->GetName(), P->GetName()) == 0)
  149. {
  150. fTrList = TrListIn;
  151. break;
  152. }
  153. }
  154. if (fTrList == 0)
  155. {
  156. fTrPr = new TEveTrackPropagator();
  157. fTrList = new TEveTrackList(P->GetName(), fTrPr);
  158. // set track color by particle PDG from MpdEventManager
  159. fTrList->SetMainColor(fEventManager->Color(P->GetPdgCode()));
  160. fTrList->SetRnrLine(kTRUE);
  161. fEveTrList->Add(fTrList);
  162. fEventManager->AddEventElement(fTrList, MCTrackList);
  163. }
  164. return fTrList;
  165. }
  166. ClassImp(MpdMCTracks)