MpdPointSetDraw.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // -------------------------------------------------------------------------
  2. // ----- MpdPointSetDraw source file -----
  3. // ----- Created 03/01/08 by M. Al-Turany -----
  4. // -------------------------------------------------------------------------
  5. #include "MpdPointSetDraw.h"
  6. #include "FairRootManager.h"
  7. #include "FairLogger.h"
  8. #include "TEveManager.h"
  9. #include "TEveTreeTools.h" // for TEvePointSelectorConsumer
  10. #include "TString.h" // for Form()
  11. #include <iostream>
  12. using namespace std;
  13. // ----- Default constructor -------------------------------------------
  14. MpdPointSetDraw::MpdPointSetDraw()
  15. : FairTask("MpdPointSetDraw", 0),
  16. fVerbose(0),
  17. fEventManager(nullptr),
  18. fPointList(nullptr),
  19. fq(nullptr),
  20. fColor(0),
  21. fStyle(0)
  22. {}
  23. // ----- Standard constructor ------------------------------------------
  24. MpdPointSetDraw::MpdPointSetDraw(const char* name, Color_t color, Style_t mstyle, Int_t iVerbose)
  25. : FairTask(name, iVerbose),
  26. fVerbose(iVerbose),
  27. fEventManager(nullptr),
  28. fPointList(nullptr),
  29. fq(nullptr),
  30. fColor(color),
  31. fStyle(mstyle)
  32. {}
  33. // ----- Destructor ----------------------------------------------------
  34. MpdPointSetDraw::~MpdPointSetDraw()
  35. {}
  36. // -------------------------------------------------------------------------
  37. InitStatus MpdPointSetDraw::Init()
  38. {
  39. if (fVerbose > 0) cout<<"MpdPointSetDraw::Init()"<<endl;
  40. FairRootManager* fManager = FairRootManager::Instance();
  41. fPointList = (TClonesArray*) fManager->GetObject(GetName());
  42. if (fPointList == 0)
  43. {
  44. LOG(ERROR)<<"MpdPointSetDraw::Init() branch "<<GetName()<<" not found! Task will be deactivated";
  45. SetActive(kFALSE);
  46. }
  47. if (fVerbose > 1) cout<<"MpdPointSetDraw::Init() get point list "<<fPointList<<endl;
  48. fEventManager = MpdEventManager::Instance();
  49. if (fVerbose > 1) cout<<"MpdPointSetDraw::Init() get instance of MpdEventManager"<<endl;
  50. fq = 0;
  51. return kSUCCESS;
  52. }
  53. void MpdPointSetDraw::Exec(Option_t* /*option*/)
  54. {
  55. if (fVerbose > 0) cout<<"MpdPointSetDraw::Exec()"<<endl;
  56. if (!IsActive())
  57. return;
  58. Reset();
  59. Int_t npoints = fPointList->GetEntriesFast();
  60. if (fVerbose > 0) cout<<"MpdPointSetDraw::Exec() the number of points is "<<fPointList->GetEntries()<<endl;
  61. TEvePointSet* q = new TEvePointSet(GetName(), npoints, TEvePointSelectorConsumer::kTVT_XYZ);
  62. q->SetOwnIds(kTRUE);
  63. q->SetMarkerColor(fColor);
  64. q->SetMarkerSize(1.5);
  65. q->SetMarkerStyle(fStyle);
  66. for (Int_t i = 0; i < npoints; i++)
  67. {
  68. TObject* p = (TObject*) fPointList->At(i);
  69. if (p != 0)
  70. {
  71. TVector3 vec(GetVector(p));
  72. q->SetNextPoint(vec.X(), vec.Y(), vec.Z());
  73. q->SetPointId(GetValue(p, i));
  74. if (fVerbose > 2) cout<<"MpdPointSetDraw::Exec() add point to EVE set: "<<i<<endl;
  75. }
  76. else cout<<"CRITICAL ERROR: MpdPointSetDraw::Exec() point is not TObject"<<endl;
  77. }
  78. fq = q;
  79. AddEveElementList();
  80. //gEve->Redraw3D(kFALSE);
  81. }
  82. TObject* MpdPointSetDraw::GetValue(TObject* /*obj*/, Int_t i)
  83. {
  84. return new TNamed(Form("Point %d", i),"");
  85. }
  86. // -------------------------------------------------------------------------
  87. void MpdPointSetDraw::SetParContainers()
  88. {}
  89. /** Action after each event**/
  90. void MpdPointSetDraw::Finish()
  91. {}
  92. // -------------------------------------------------------------------------
  93. void MpdPointSetDraw::Reset()
  94. {
  95. if (fq != 0)
  96. {
  97. fq->Reset();
  98. RemoveEveElementList();
  99. }
  100. }
  101. ClassImp(MpdPointSetDraw);