EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairBoxSetDraw.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairBoxSetDraw.cxx
1 // -------------------------------------------------------------------------
2 // ----- FairBoxSetDraw source file -----
3 // ----- Created 03/01/08 by M. Al-Turany -----
4 // -------------------------------------------------------------------------
5 
6 #include "FairBoxSetDraw.h"
7 
8 #include "FairRootManager.h"
9 #include "FairEventManager.h"
10 
11 #include "TEveManager.h"
12 #include "FairBoxSet.h"
13 #include "TClonesArray.h"
14 #include "TVector3.h"
15 
16 #include <iostream>
17 using std::cout;
18 using std::endl;
19 
21 Double_t fX, fY, fZ;
22 
23 // ----- Default constructor -------------------------------------------
25  : FairTask("FairBoxSetDraw",0),
26  fVerbose(0),
27  fList(NULL),
28  fEventManager(NULL),
29  fManager(NULL),
30  fq(NULL),
31  fX(1.),
32  fY(1.),
33  fZ(1.),
34  fTimeWindowPlus(0.),
35  fTimeWindowMinus(0.),
36  fStartTime(0.),
37  fUseEventTime(kTRUE),
38  fStartFunctor(),
39  fStopFunctor()
40 {
41 }
42 // -------------------------------------------------------------------------
43 
44 
45 
46 // ----- Standard constructor ------------------------------------------
47 FairBoxSetDraw::FairBoxSetDraw(const char* name, Int_t iVerbose)
48  : FairTask(name, iVerbose),
49  fVerbose(iVerbose),
50  fList(NULL),
51  fEventManager(NULL),
52  fManager(NULL),
53  fq(NULL),
54  fX(1.),
55  fY(1.),
56  fZ(1.),
57  fTimeWindowPlus(0.),
58  fTimeWindowMinus(0.),
59  fStartTime(0.),
60  fUseEventTime(kTRUE),
61  fStartFunctor(),
62  fStopFunctor()
63 {
64 }
65 // -------------------------------------------------------------------------
67 {
68  if(fVerbose>1) {
69  cout<< "FairBoxSetDraw::Init()" << endl;
70  }
72 
73  fList = (TClonesArray*)FairRootManager::Instance()->GetObject(GetName());
74  //std::cout << fList << std::endl;
75  if (fList==0) {
76  cout << "FairBoxSetDraw::Init() branch " << GetName() << " Not found! Task will be deactivated "<< endl;
77  SetActive(kFALSE);
78  return kERROR;
79  }
80  if(fVerbose>2) {
81  cout<< "FairBoxSetDraw::Init() get track list" << fList<< endl;
82  }
84  if(fVerbose>2) {
85  cout<< "FairBoxSetDraw::Init() get instance of FairEventManager " << endl;
86  }
87  fq=0;
88 
89  fStartFunctor = new StopTime();
90  fStopFunctor = new StopTime();
91 
92  return kSUCCESS;
93 }
94 // -------------------------------------------------------------------------
95 void FairBoxSetDraw::Exec(Option_t* option)
96 {
97  if(IsActive()) {
98  TObject* p;
99  Reset();
100  // cout<< "FairBoxSetDraw::Init() Exec! " << fList->GetEntriesFast() << endl;
101  CreateBoxSet();
102  if (FairRunAna::Instance()->IsTimeStamp()) {
103  fList->Clear();
104  Double_t eventTime = FairRootManager::Instance()->GetEventTime();
105  if (fUseEventTime) { fStartTime = eventTime - fTimeWindowMinus; }
106  cout << "EventTime: " << eventTime << " TimeWindow: " << fStartTime << " - " << eventTime + fTimeWindowPlus << std::endl;
107 
108  fList = FairRootManager::Instance()->GetData(GetName(), fStartFunctor, fStartTime, fStopFunctor, eventTime + fTimeWindowPlus); //FairRootManager::Instance()->GetEventTime() +
109 
110  }
111 
112  //fList = (TClonesArray *)fManager->GetObject(GetName());
113  if (fVerbose > 1) {
114  std::cout << GetName() << " fList: " << fList->GetEntries() << std::endl;
115  }
116  for (Int_t i=0; i<fList->GetEntriesFast(); ++i) {
117  p=fList->At(i);
118  if (fVerbose > 2) {
120 // cout << "TimeStamp: " << data->GetTimeStamp() << std::endl;
121  }
122  AddBoxes(fq, p, i);
123  }
124  gEve->AddElement(fq, fEventManager );
125  gEve->Redraw3D(kFALSE);
126  }
127 }
128 
129 void FairBoxSetDraw::AddBoxes(FairBoxSet* set, TObject* obj, Int_t i)
130 {
131  TVector3 point = GetVector(obj);
132  set->AddBox(point.X(),point.Y(),point.Z());
133  set->DigitValue(GetValue(obj, i));
134  if(fVerbose>2) {
135  cout<< "FairBoxSetDraw::Init() Add point " << i << ": " <<point.X()<< " "<<point.Y()<< " "<< point.Z()<< " " << endl;
136  }
137 }
138 
139 
140 Int_t FairBoxSetDraw::GetValue(TObject* obj, Int_t i)
141 {
142  return i;
143 }
144 
146 {
147  FairBoxSet* aBoxSet = new FairBoxSet(this, GetName());
148  aBoxSet->Reset(FairBoxSet::kBT_AABoxFixedDim, kFALSE, 32);
149  aBoxSet->SetDefWidth(0.3);
150  aBoxSet->SetDefHeight(0.3);
151  aBoxSet->SetDefDepth(0.3);
152  fq = aBoxSet;
153 
154  return aBoxSet;
155 }
156 
158 {
159  fTimeWindowMinus = val;
160 }
161 
163 {
164  fTimeWindowPlus = val;
165 }
166 
167 // ----- Destructor ----------------------------------------------------
169 {
170 }
171 // -------------------------------------------------------------------------
173 {
174 
175 }
176 // -------------------------------------------------------------------------
179 {
180 }
181 // -------------------------------------------------------------------------
183 {
184  if(fq!=0) {
185  fq->Reset();
186  gEve->RemoveElement(fq, fEventManager );
187  }
188 }
189 
190 
192 
193