MpdBoxSetDraw.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // -------------------------------------------------------------------------
  2. // ----- MpdBoxSetDraw source file -----
  3. // ----- Created 03/01/08 by M. Al-Turany -----
  4. // -------------------------------------------------------------------------
  5. #include "MpdBoxSetDraw.h"
  6. #include "MpdBoxSet.h"
  7. #include "FairRunAna.h"
  8. #include "TEveManager.h" // for TEveManager, gEve
  9. #include <iostream>
  10. using namespace std;
  11. // ----- Default constructor -------------------------------------------
  12. MpdBoxSetDraw::MpdBoxSetDraw()
  13. : FairTask("MpdBoxSetDraw", 0),
  14. fVerbose(0),
  15. fList(NULL),
  16. fEventManager(NULL),
  17. fManager(NULL),
  18. fq(NULL),
  19. fX(0.3),
  20. fY(0.3),
  21. fZ(0.3),
  22. fTimeWindowPlus(0.),
  23. fTimeWindowMinus(0.),
  24. fStartTime(0.),
  25. fUseEventTime(kTRUE),
  26. isRedraw(kFALSE),
  27. fStartFunctor(),
  28. fStopFunctor()
  29. {
  30. }
  31. // ----- Standard constructor ------------------------------------------
  32. MpdBoxSetDraw::MpdBoxSetDraw(const char* name, Int_t iVerbose)
  33. : FairTask(name, iVerbose),
  34. fVerbose(iVerbose),
  35. fList(NULL),
  36. fEventManager(NULL),
  37. fManager(NULL),
  38. fq(NULL),
  39. fX(0.3),
  40. fY(0.3),
  41. fZ(0.3),
  42. fTimeWindowPlus(0.),
  43. fTimeWindowMinus(0.),
  44. fStartTime(0.),
  45. fUseEventTime(kTRUE),
  46. isRedraw(kFALSE),
  47. fStartFunctor(),
  48. fStopFunctor()
  49. {
  50. }
  51. // ----- Destructor ----------------------------------------------------
  52. MpdBoxSetDraw::~MpdBoxSetDraw()
  53. {
  54. }
  55. InitStatus MpdBoxSetDraw::Init()
  56. {
  57. if (fVerbose > 1) cout<<"MpdBoxSetDraw::Init()"<<endl;
  58. fManager = FairRootManager::Instance();
  59. fList = (TClonesArray*) FairRootManager::Instance()->GetObject(GetName());
  60. if (fList == 0)
  61. {
  62. cout<<"MpdBoxSetDraw::Init() branch "<<GetName()<<" not found! Task will be deactivated"<<endl;
  63. SetActive(kFALSE);
  64. return kERROR;
  65. }
  66. if (fVerbose > 2) cout<<"MpdBoxSetDraw::Init() get track list "<<fList<<endl;
  67. fEventManager = MpdEventManager::Instance();
  68. if (fVerbose > 2) cout<<"MpdBoxSetDraw::Init() get instance of MpdEventManager"<<endl;
  69. fq = 0;
  70. fStartFunctor = new StopTime();
  71. fStopFunctor = new StopTime();
  72. return kSUCCESS;
  73. }
  74. // -------------------------------------------------------------------------
  75. void MpdBoxSetDraw::Exec(Option_t* /*option*/)
  76. {
  77. if (!IsActive())
  78. return;
  79. Reset();
  80. CreateBoxSet();
  81. if (FairRunAna::Instance()->IsTimeStamp())
  82. {
  83. fList->Clear();
  84. Double_t eventTime = fManager->GetEventTime();
  85. if (fUseEventTime)
  86. fStartTime = eventTime - fTimeWindowMinus;
  87. cout<<"EventTime: "<<eventTime<<" TimeWindow: "<<fStartTime<<" - "<<eventTime + fTimeWindowPlus<<endl;
  88. fList = fManager->GetData(GetName(), fStartFunctor, fStartTime, fStopFunctor, eventTime + fTimeWindowPlus); //FairRootManager::Instance()->GetEventTime() +
  89. }
  90. if (fVerbose > 1) cout<<GetName()<<" fList: "<<fList->GetEntries()<<endl;
  91. for (Int_t i = 0; i < fList->GetEntriesFast(); i++)
  92. {
  93. TObject* p = fList->At(i);
  94. AddBoxes(fq, p, i);
  95. }
  96. gEve->AddElement(fq, fEventManager);
  97. if (isRedraw) gEve->Redraw3D();
  98. }
  99. void MpdBoxSetDraw::AddBoxes(MpdBoxSet* set, TObject* obj, Int_t i)
  100. {
  101. TVector3 point = GetVector(obj);
  102. set->AddBox(point.X(), point.Y(), point.Z());
  103. set->DigitValue(GetValue(obj, i));
  104. if (fVerbose > 2) cout<<"MpdBoxSetDraw::Init() Add point "<<i<<": "<<point.X()<<" "<<point.Y()<<" "<<point.Z()<<" "<<endl;
  105. }
  106. Int_t MpdBoxSetDraw::GetValue(TObject* /*obj*/, Int_t i)
  107. {
  108. return i;
  109. }
  110. MpdBoxSet* MpdBoxSetDraw::CreateBoxSet()
  111. {
  112. MpdBoxSet* aBoxSet = new MpdBoxSet(this, GetName());
  113. aBoxSet->Reset(MpdBoxSet::kBT_AABoxFixedDim, kFALSE, 64);
  114. aBoxSet->SetDefWidth(fX);
  115. aBoxSet->SetDefHeight(fY);
  116. aBoxSet->SetDefDepth(fZ);
  117. fq = aBoxSet;
  118. return aBoxSet;
  119. }
  120. void MpdBoxSetDraw::SetParContainers()
  121. {
  122. }
  123. /** Action after each event**/
  124. void MpdBoxSetDraw::Finish()
  125. {
  126. }
  127. void MpdBoxSetDraw::Reset()
  128. {
  129. if (fq != 0)
  130. {
  131. fq->Reset();
  132. gEve->RemoveElement(fq, fEventManager);
  133. }
  134. }
  135. ClassImp(MpdBoxSetDraw)