FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairTutorialDet4PointDraw.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- FairTutorialDet4PointDraw -----
3 // ----- Created 02.03.16 by F. Uhlig -----
4 // -------------------------------------------------------------------------
5 
7 
8 #include "FairEventManager.h" // for FairEventManager
9 #include "FairLogger.h"
10 #include "FairRootManager.h" // for FairRootManager
11 #include "FairRun.h" // for FairRunAna
12 #include "FairRuntimeDb.h" // for FairRuntimeDb
14 #include "FairTutorialDet4GeoPar.h"
15 #include "FairTutorialDet4Point.h"
16 
17 #include <TClonesArray.h> // for TClonesArray
18 #include <TEveManager.h> // for TEveManager, gEve
19 #include <TEvePointSet.h> // for TEveBoxSet, etc
20 
22  : FairTask("FairTutorialDet4PointDraw")
23  , fPointList(nullptr)
24  , fGeoPar(nullptr)
25  , fEventManager(nullptr)
26  , fq(nullptr)
27  , fColor()
28  , fStyle()
29  , fGlobalCoordinates(kTRUE)
30  , fGeoHandler(new FairTutorialDet4GeoHandler)
31 {}
32 
33 FairTutorialDet4PointDraw::FairTutorialDet4PointDraw(const char* name, Color_t color, Style_t mystyle)
34  : FairTask(name)
35  , fPointList(nullptr)
36  , fGeoPar(nullptr)
37  , fEventManager(nullptr)
38  , fq(nullptr)
39  , fColor(color)
40  , fStyle(mystyle)
41  , fGlobalCoordinates(kTRUE)
42  , fGeoHandler(new FairTutorialDet4GeoHandler)
43 {}
44 
46 {
47  // Get Base Container
48  FairRun* run = FairRun::Instance();
49  FairRuntimeDb* rtdb = run->GetRuntimeDb();
50 
51  fGeoPar = static_cast<FairTutorialDet4GeoPar*>(rtdb->getContainer("FairTutorialDet4GeoPar"));
52 }
53 
55 {
57  fPointList = static_cast<TClonesArray*>(fManager->GetObject(GetName()));
58  if (nullptr == fPointList) {
59  LOG(error) << "FairTutorialDet4PointDraw::Init() branch " << GetName()
60  << " not found! Task will be deactivated.";
61  return kERROR;
62  }
63  fEventManager = FairEventManager::Instance();
64  fq = 0;
65 
66  fGlobalCoordinates = fGeoPar->IsGlobalCoordinateSystem();
67 
68  return kSUCCESS;
69 }
70 
71 void FairTutorialDet4PointDraw::Exec(Option_t* /*option*/)
72 {
73  if (IsActive()) {
74  FairTutorialDet4Point* point = 0;
75 
76  Int_t npoints = fPointList->GetEntriesFast();
77  Reset();
78 
79  TEvePointSet* q = new TEvePointSet(GetName(), npoints, TEvePointSelectorConsumer::kTVT_XYZ);
80  q->SetOwnIds(kTRUE);
81  q->SetMarkerColor(fColor);
82  q->SetMarkerSize(1.5);
83  q->SetMarkerStyle(fStyle);
84 
85  // Int_t refCounter=0;
86 
87  for (Int_t i = 0; i < npoints; ++i) {
88  point = static_cast<FairTutorialDet4Point*>(fPointList->At(i));
89 
90  if (!point) {
91  continue;
92  }
93 
94  // Detector ID
95  Int_t detID = point->GetDetectorID();
96 
97  // Determine hit position
98  Double_t x = point->GetX();
99  Double_t y = point->GetY();
100  Double_t z = point->GetZ();
101 
102  if (!fGlobalCoordinates) {
103  Double_t local[3] = {x, y, z};
104  Double_t global[3];
105 
106  fGeoHandler->LocalToGlobal(local, global, detID);
107 
108  x = global[0];
109  y = global[1];
110  z = global[2];
111  }
112  q->SetNextPoint(x, y, z);
113  // q->SetPointId(GetValue(p, i));
114  }
115 
116  gEve->AddElement(q);
117  gEve->Redraw3D(kFALSE);
118  fq = q;
119  }
120 }
121 
123 {
124  if (fq) {
125  fq->Reset();
126  gEve->RemoveElement(fq, fEventManager);
127  }
128 }
list of container factories
Definition: FairRuntimeDb.h:24
InitStatus
Definition: FairTask.h:33
Double_t GetZ() const
Definition: FairMCPoint.h:69
Double_t GetX() const
Definition: FairMCPoint.h:67
virtual void Exec(Option_t *option)
static FairRun * Instance()
Definition: FairRun.cxx:31
static FairRootManager * Instance()
TObject * GetObject(const char *BrName)
FairBoxSet * fq
FairParSet * getContainer(const Text_t *)
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
static FairEventManager * Instance()
Double_t GetY() const
Definition: FairMCPoint.h:68
void LocalToGlobal(Double_t *local, Double_t *global, Int_t detID)
Int_t GetDetectorID() const
Definition: FairMCPoint.h:66