CbmRoot
Loading...
Searching...
No Matches
CbmTsPointSetArrayDraw.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 PI-UHd, Heidelberg
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Norbert Herrmann [committer], Pierre-Alain Loizeau */
4
5// -------------------------------------------------------------------------
6// ----- CbmTsPointSetArrayDraw source file -----
7// ----- Created 18/06/22 by J. Brandt -----
8// ----- Following class FairPointSetDraw -----
9// -------------------------------------------------------------------------
11
12#include "CbmEvent.h" // for CbmEvent
13#include "CbmPixelHit.h" // for CbmPixelHit
14#include "CbmPointSetArray.h" // for CbmPointSetArray
15#include "CbmTofHit.h" // for CbmTofHit
16#include <CbmTimesliceManager.h> // for CbmTimesliceManager
17
18#include <FairRootManager.h> // for FairRootManager
19#include <FairTask.h> // for FairTask, InitStatus, kSUCCESS
20#include <Logger.h> // for LOG, Logger
21
22#include <Rtypes.h> // for kRed, ClassImp
23#include <TClonesArray.h> // for TClonesArray
24#include <TEveManager.h> // for TEveManager, gEve
25#include <TEveTreeTools.h> // for TEvePointSelectorConsumer, TEvePointS...
26#include <TGenericClassInfo.h> // for TGenericClassInfo
27#include <TVector3.h> // for TVector3
28
29#include <iomanip> // for operator<<, setprecision
30
31// ----- Standard constructor ------------------------------------------
32CbmTsPointSetArrayDraw::CbmTsPointSetArrayDraw(const char* name, Int_t colorMode, Int_t markerMode, Int_t iVerbose,
33 Bool_t render)
34 : FairTask(name, iVerbose)
35 , fVerbose(iVerbose)
36 , fColorMode(colorMode)
37 , fMarkerMode(markerMode)
38 , fRender(render)
39{
40}
41
42// -------------------------------------------------------------------------
44{
45 LOG(debug) << "CbmTsPointSetArrayDraw::Init() for " << fTofHitArrayName;
46 FairRootManager* fManager = FairRootManager::Instance();
47 fCbmEvents = dynamic_cast<TClonesArray*>(fManager->GetObject("CbmEvent"));
48 fTsPointList = static_cast<TClonesArray*>(fManager->GetObject(fTofHitArrayName.Data()));
49 if (fTsPointList == nullptr) {
50 LOG(warn) << "CbmTsPointSetArrayDraw::Init() branch " << fTofHitArrayName
51 << " not found! Task will be deactivated ";
52 SetActive(kFALSE);
53 }
54 //LOG(info) << "CbmTsPointSetArrayDraw::Init() get track list" << fTsPointList->GetName();
55 fPointList = new TClonesArray("CbmTofHit", 100); // allocate memory
57 LOG(debug1) << "CbmTsPointSetArrayDraw::Init() get instance of CbmTimesliceManager ";
58 fl = 0;
59
60 return kSUCCESS;
61}
62// -------------------------------------------------------------------------
63void CbmTsPointSetArrayDraw::Exec(Option_t* /*option*/)
64{
65 if (0 < fCbmEvents->GetEntriesFast()) {
67 GotoEvent(0);
68 }
69}
70
71void CbmTsPointSetArrayDraw::GotoEvent(uint32_t uEventIdx)
72{
73 if (IsActive()) {
74
75 if (CbmTimesliceManager::Instance()->GetClearHandler()) { //
76 Reset();
77 }
78
79 CbmEvent* event = dynamic_cast<CbmEvent*>(fCbmEvents->At(uEventIdx));
80 if (nullptr == fTsPointList) {
81 fTsPointList = static_cast<TClonesArray*>(FairRootManager::Instance()->GetObject(fTofHitArrayName.Data()));
82 if (nullptr == fTsPointList) {
83 LOG(warn) << " No " << fTofHitArrayName;
84 return;
85 }
86 }
87 if (nullptr != fPointList) fPointList->Clear();
88 int nofPoints = fTsPointList->GetEntriesFast();
89 int nPoints = 0;
90 LOG(debug3) << " Fill TofUhit from " << nofPoints << " hits in Ts.";
91 for (size_t iP = 0; iP < event->GetNofData(ECbmDataType::kTofUHit); ++iP) {
92 Int_t iPId = event->GetIndex(ECbmDataType::kTofUHit, iP); // make this generic!!
93 CbmTofHit* tHit = dynamic_cast<CbmTofHit*>(fTsPointList->At(iPId));
94 LOG(debug3) << "Add Hit " << iP << ", " << iPId << ", " << tHit << " at " << nPoints;
95 if (nullptr != tHit && iPId > -1) new ((*fPointList)[nPoints++]) CbmTofHit(*tHit);
96 }
97 nPoints = fPointList->GetEntriesFast();
98
99 //Reset();
100
101 // initialize CbmPointSetArray to display set of hits
105 l->SetSourceCS(TEvePointSelectorConsumer::kTVT_XYZ);
106 l->SetMarkerColor(kRed);
107 l->SetMarkerStyle(22);
108 l->SetMarkerSize(2.0);
109
111 l->InitBins("Hits", nPoints, 0.5, nPoints + 0.5);
112 l->InitValues(nPoints);
113
114 for (Int_t i = 1; i <= nPoints; i++) { //loop over all hits in event
115 TObject* p = static_cast<TObject*>(fPointList->At(i - 1));
116 if (p != 0) {
117 TVector3 vec(GetVector(p));
118 l->Fill(vec.X(), vec.Y(), vec.Z(), i); // fill 3D position
120 i); // fill physical information used for color and markersize
121 }
122 }
123
124 //l->ApplyColorMode(); // apply colorMode and calculate color of each bin
125 //l->ApplyMarkerMode(); // apply markerMode and calculate markersize of each bin
126 //l->ApplyTitles(); // set BBox-title of each bin and computeBBox
127
128 l->SetRnrChildren(fRender);
129 gEve->AddElement(l);
130 gEve->Redraw3D(kFALSE);
131 fl = l;
132 }
133}
134// --------------------------------------------------------------------------------
135// returns 3D-vector with position data of hit
137{
138 CbmPixelHit* p = (CbmPixelHit*) obj;
139 LOG(debug2) << "-I- CbmTsPointSetArrayDraw::GetVector(): " << p->GetX() << " " << p->GetY() << " " << p->GetZ()
140 << " ";
141 return TVector3(p->GetX(), p->GetY(), p->GetZ());
142}
143// --------------------------------------------------------------------------------
144// returns hit-time against first hit
146{
147 CbmPixelHit* p = (CbmPixelHit*) obj;
148 LOG(debug2) << "-I- CbmTsPointSetArrayDraw::GetTime(): " << p->GetTime() - fTimeOffset;
149 return p->GetTime() - fTimeOffset;
150}
151// --------------------------------------------------------------------------------
152// returns ClusterSize of Hit
154{
155 //CluSize of TofHit is stored in Flag-Variable (set in Clusterizer)
156 CbmTofHit* p = (CbmTofHit*) obj;
157 Double_t cluSize = p->GetFlag();
158 //Flag= #digis = 2*cluSize +100 if used for track
159 cluSize = ((int) cluSize % 100) / 2;
160 LOG(debug3) << "-I- CbmTsPointSetArrayDraw::GetClusterSize(): " << cluSize;
161 return cluSize;
162}
163// --------------------------------------------------------------------------------
164// returns ToT of hit
165Double_t CbmTsPointSetArrayDraw::GetTot(TObject* obj)
166{
167 // ToT of TofHit is stored in Channel-Variable (set in Clusterizer)
168 CbmTofHit* p = (CbmTofHit*) obj;
169 Double_t tot = Double_t(p->GetCh()) / (20 * GetClusterSize(p));
170 LOG(debug3) << "-I- CbmTsPointSetArrayDraw::GetTot(): " << tot;
171 return tot;
172}
173// --------------------------------------------------------------------------------
174// returns Id of hit
176{
177 CbmPixelHit* p = (CbmPixelHit*) obj;
178 return p->GetRefId();
179}
180// ---------------------------------------------------------------------------------
181// Determine time of first hit in event to use as offset
183{
184 Int_t nPoints = fPointList->GetEntriesFast();
185 fTimeOffset = 115200000000000; //32hours in ns as maximum of clock
186 fTimeMax = 0;
187 Double_t currtime;
188 CbmPixelHit* hit;
189 for (Int_t i = 0; i < nPoints; i++) { //loop over all hits in event
190 hit = static_cast<CbmPixelHit*>(fPointList->At(i));
191 currtime = hit->GetTime();
192 if (currtime < fTimeOffset) {
193 fTimeOffset = currtime;
194 }
195 else if (currtime > fTimeMax) {
196 fTimeMax = currtime;
197 }
198 }
199 fTimeMax -= fTimeOffset; //time of latest hit in event
200 LOG(debug3) << std::setprecision(15) << "-I- CbmTsPointSetArrayDraw::DetermineTimeBins: fTimeOffset " << fTimeOffset;
201}
202
203// ----- Destructor ----------------------------------------------------
205// -------------------------------------------------------------------------
207// -------------------------------------------------------------------------
210// -------------------------------------------------------------------------
212{
213 if (fl != 0) {
214 LOG(debug3) << GetName() << ": Remove Element " << fl->GetName() << ", Man " << fTsManager->GetName();
215 //fl->RemoveElementsLocal();
216 gEve->RemoveElement(fl, fTsManager);
217 }
218}
219
220
ClassImp(CbmTsPointSetArrayDraw)
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
void Clear(Option_t *)
Definition CbmEvent.h:67
double GetTime() const
Definition CbmHit.h:76
double GetZ() const
Definition CbmHit.h:71
int32_t GetRefId() const
Definition CbmHit.h:73
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
void SetMarkerMode(Int_t markerMode)
void SetColorMode(Int_t colorMode)
void FillValues(Int_t id, Double_t time, Double_t tot, Int_t cluSize, Int_t index)
FillQuantities.
void InitValues(Int_t npoints)
Init Arrays for physical Quantities.
static CbmTimesliceManager * Instance()
int32_t GetCh() const
Definition CbmTofHit.h:76
int32_t GetFlag() const
Definition CbmTofHit.h:75
Double_t GetTot(TObject *obj)
CbmTimesliceManager * fTsManager
void GotoEvent(uint32_t uEventIdx)
virtual void Exec(Option_t *option)
TVector3 GetVector(TObject *obj)
Double_t GetTime(TObject *obj)