FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairPointSetDraw.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- FairPointSetDraw source file -----
10 // ----- Created 03/01/08 by M. Al-Turany -----
11 // -------------------------------------------------------------------------
12 #include "FairPointSetDraw.h"
13 
14 #include "FairDataSourceI.h"
15 #include "FairEventManager.h" // for FairEventManager
16 #include "FairRootManager.h" // for FairRootManager
17 #include "FairTCASource.h"
18 
19 #include <TClonesArray.h> // for TClonesArray
20 #include <TEveManager.h> // for TEveManager, gEve
21 #include <TEvePointSet.h> // for TEvePointSet
22 #include <TEveTreeTools.h> // for TEvePointSelectorConsumer, etc
23 #include <TNamed.h> // for TNamed
24 #include <TString.h> // for Form
25 #include <TVector3.h> // for TVector3
26 #include <iostream> // for operator<<, basic_ostream, etc
27 
28 class TObject;
29 
31  : FairTask("FairPointSetDraw", 0)
32  , fVerbose(0)
33  , fq(nullptr)
34  , fColor(0)
35  , fStyle(0)
36 {}
37 
38 FairPointSetDraw::FairPointSetDraw(const char* name, Color_t color, Style_t mstyle, Int_t iVerbose)
39  : FairTask(name, iVerbose)
40  , fVerbose(iVerbose)
41  , fq(nullptr)
42  , fColor(color)
43  , fStyle(mstyle)
44 {}
45 
47  FairDataSourceI* dataSource,
48  Color_t color,
49  Style_t mstyle,
50  Int_t iVerbose)
51  : FairTask(name, iVerbose)
52  , fVerbose(iVerbose)
53  , fq(nullptr)
54  , fColor(color)
55  , fStyle(mstyle)
56  , fDataSource(dataSource)
57 {}
58 
60 {
61  LOG(info) << "FairPointSetDraw::Init()";
62  fq = 0;
63 
64  if (fDataSource == nullptr) {
65  fDataSource = new FairTCASource(GetName());
66  }
67  if (fDataSource->Init() != kSUCCESS) {
68  LOG(error) << "FairPointSetDraw::Init() branch " << GetName() << " not found!";
69  SetActive(kFALSE);
70  return kERROR;
71  }
72  // gEve->AddElement(fq, fEventManager );
73  return kSUCCESS;
74 }
75 
76 void FairPointSetDraw::Exec(Option_t* /*option*/)
77 {
78  Double_t timeOffset = 0.0;
79  if (IsActive()) {
80  if (FairEventManager::Instance()->GetClearHandler() == kTRUE) {
81  fDataSource->Reset();
82  }
83  fDataSource->RetrieveData(FairEventManager::Instance()->GetEvtTime());
84  Int_t npoints = fDataSource->GetNData();
85  Reset();
86  TEvePointSet* q = new TEvePointSet(GetName(), npoints, TEvePointSelectorConsumer::kTVT_XYZ);
87  q->SetOwnIds(kTRUE);
88  q->SetMarkerColor(fColor);
89  q->SetMarkerSize(1.5);
90  q->SetMarkerStyle(fStyle);
91  double tmin, tmax;
93  bool checkTime = tmin < tmax;
94 
95  for (Int_t i = 0; i < npoints; ++i) {
96 
97  TVector3 vec(GetVector(fDataSource->GetData(i)));
98  if (checkTime) {
99  double time = fDataSource->GetTime(i);
100  if (fUseTimeOffset == kTRUE && time > -1.0)
101  time += timeOffset;
102  if (time > 0) {
104  if (time < tmin || time > tmax) {
105  continue;
106  }
107  }
108  }
109  q->SetNextPoint(vec.X(), vec.Y(), vec.Z());
110  // q->SetPointId(GetValue(p, i));
111  }
112  gEve->AddElement(q);
113  gEve->Redraw3D(kFALSE);
114  fq = q;
115  }
116 }
117 
118 // TObject* FairPointSetDraw::GetValue(TObject* /*obj*/, Int_t i) { return new TNamed(Form("Point %d", i), ""); }
119 
120 FairPointSetDraw::~FairPointSetDraw() { delete (fDataSource); }
121 
123 
126 
128 {
129  if (fq != 0) {
130  fq->Reset();
131  gEve->RemoveElement(fq, FairEventManager::Instance());
132  }
133 }
134 
virtual InitStatus Init()
InitStatus
Definition: FairTask.h:33
virtual void RetrieveData(double time)
ClassImp(FairEventBuilder)
Handles a TClonesArray as input object. No timebased operations are done and the TClonesArray is hand...
Definition: FairTCASource.h:19
virtual InitStatus Init()
virtual void Finish()
FairBoxSet * fq
TEvePointSet * fq
virtual double GetTime(int index)
virtual TObject * GetData(int index)=0
void GetTimeLimits(Double_t &min, Double_t &max)
Abstract interface class to handle different input data for event and timebased data.
virtual void Reset()=0
static FairEventManager * Instance()
virtual int GetNData()=0
virtual void SetParContainers()
virtual TVector3 GetVector(TObject *obj)=0
virtual void Exec(Option_t *option)