CbmRoot
Loading...
Searching...
No Matches
CbmTsDisTofTracklets.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#define TOFDisplay 1 // =1 means active, other: without Label and not relying on TEvePointSet
6#define TOFTtErr 1 // =1 means active, other: not relying on VelocityError of CbmTofTracklet
7
9
10#include "CbmEvent.h" // For CbmEvent
11#include "CbmTimesliceManager.h" // for CbmTimesliceManager
12#include "CbmTofHit.h" // for CbmTofHit
13#include "CbmTofTracklet.h" // for CbmTofTracklet
14
15#include <FairEventManager.h> // for FairEventManager
16#include <FairRootManager.h> // for FairRootManager
17#include <FairTask.h> // for FairTask, InitStatus, kERROR, kSUCCESS
18#include <Logger.h> // for LOG, Logger
19
20#include <Rtypes.h> // for ClassImp
21#include <TClonesArray.h> // for TClonesArray
22#include <TEveElement.h> // for TEveElementList
23#include <TEveManager.h> // for TEveManager, gEve
24#include <TEvePathMark.h> // for TEvePathMark
25#include <TEvePointSet.h> // for TEvePointSetArray, TEvePointSet
26#include <TEveTrack.h> // for TEveTrack, TEveTrackList
27#include <TEveTrackPropagator.h> // for TEveTrackPropagator
28#include <TEveVSDStructs.h> // for TEveRecTrack
29#include <TEveVector.h> // for TEveVector, TEveVectorT
30#include <TGLAnnotation.h>
31#include <TGLViewer.h>
32#include <TGenericClassInfo.h> // for TGenericClassInfo
33#include <TObjArray.h> // for TObjArray
34#include <TParticle.h> // for TParticle
35#include <TString.h> // for Form, TString
36
37#include <string.h> // for strcmp
38
41
42//static TGLAnnotation* anne;
43static TGLAnnotation* annt;
45static FairEventManager* fEventManager = nullptr;
46
47// ----- Default constructor -------------------------------------------
48CbmTsDisTofTracklets::CbmTsDisTofTracklets() : FairTask("CbmTsDisTofTracklets", 0)
49{
50 if (!fInstance) fInstance = this;
51}
52// -------------------------------------------------------------------------
53
54
55// ----- Standard constructor ------------------------------------------
56CbmTsDisTofTracklets::CbmTsDisTofTracklets(const char* name, Int_t iVerbose, Bool_t renderP, Bool_t renderT)
57 : FairTask(name, iVerbose)
58 , fEveTrList(new TObjArray(16))
59 , fEvePSList(new TObjArray(8))
60 , fRenderP(renderP)
61 , fRenderT(renderT)
62{
63 if (!fInstance) fInstance = this;
64}
65// -------------------------------------------------------------------------
67{
68 LOG(info) << "CbmTsDisTofTracklets::Init()";
69 FairRootManager* fManager = FairRootManager::Instance();
70 fCbmEvents = dynamic_cast<TClonesArray*>(fManager->GetObject("CbmEvent"));
71 fTrackList = dynamic_cast<TClonesArray*>(fManager->GetObject("TofTracklets"));
72 if (fTrackList == 0) {
73 LOG(warn) << "CbmTsDisTofTracklets::Init() branch " << GetName() << " Not found! Task will be deactivated ";
74 SetActive(kFALSE);
75 }
76 LOG(debug1) << "CbmTsDisTofTracklets::Init() get track list" << fTrackList;
77 /*
78 LOG(debug1) << "CbmTsDisTofTracklets::Init() create propagator";
79 fEventManager = FairEventManager::Instance();
80 fEventManager = CbmTimesliceManager::Instance();
81 LOG(debug1) << "CbmTsDisTofTracklets::Init() get instance of FairEventManager ";
82 fEvent = "Current Event";
83 MinEnergyLimit = fEventManager->GetEvtMinEnergy();
84 MaxEnergyLimit = fEventManager->GetEvtMaxEnergy();
85 PEnergy = 0;
86 */
88 fEventManager = FairEventManager::Instance();
89
90 if (nullptr == fEventManager) {
91 LOG(warn) << GetName() << ": no FairEventManager found, use TsManager ";
92 }
93 else
94 LOG(info) << "CbmTsDisTofTracklets::Init() got instance of FairEventManager ";
95
96 if (IsActive()) {
97 return kSUCCESS;
98 }
99 else {
100 return kERROR;
101 }
102}
103// -------------------------------------------------------------------------
104void CbmTsDisTofTracklets::Exec(Option_t* option)
105{
106 LOG(debug2) << " CbmTsDisTofTracklets::Exec starting with verbosity " << fVerbose << " and option " << option;
107 if (0 < fCbmEvents->GetEntriesFast()) {
109 GotoEvent(0);
110 }
111}
112void CbmTsDisTofTracklets::GotoEvent(uint32_t uEventIdx)
113{
114 if (IsActive()) {
115
116 fEventIdx = uEventIdx;
117
118 if (CbmTimesliceManager::Instance()->GetClearHandler()) { //
119 Reset();
120 }
121
122 CbmEvent* event = dynamic_cast<CbmEvent*>(fCbmEvents->At(uEventIdx));
123
124 Int_t nofTofTracks = event->GetNofData(ECbmDataType::kTofTracklet);
125 LOG(debug3) << GetName() << " : nofTofTracks " << nofTofTracks << " in event " << uEventIdx;
126
127 Reset();
128
129 CbmTofTracklet* tr;
130 const Double_t* point;
131 CbmTofHit* hit;
132 Int_t TMul[10] = {10 * 0}; //FIXME - don't use constants in code
133
134 for (Int_t iOpt = 0; iOpt < 2; iOpt++)
135 for (Int_t iTrk = 0; iTrk < nofTofTracks; ++iTrk) {
136 Int_t trkId = event->GetIndex(ECbmDataType::kTofTracklet, iTrk);
137 tr = dynamic_cast<CbmTofTracklet*>(fTrackList->At(trkId));
138 int i = iTrk;
139 // for (Int_t i = 0; i < fTrackList->GetEntriesFast(); i++) {
140 // LOG(debug4) << "CbmTsDisTofTracklets::Exec " << i;
141 // tr = (CbmTofTracklet*) fTrackList->At(i);
142 if (nullptr == tr) continue;
143 Int_t Np = tr->GetNofHits();
144
145#if TOFDisplay == 1 //List for TEvePointSets
146 if (iOpt == 0) TMul[Np]++;
147 fPSList = GetPSGroup(Np, iOpt);
148#endif
149
150 fTrList = GetTrGroup(tr->GetNofHits(), iOpt);
151 TParticle* P = new TParticle();
152 TEveTrack* track = new TEveTrack(P, tr->GetPidHypo(), fTrPr);
153 Int_t iCol = Np;
154 if (iCol > 4) iCol++;
155 track->SetAttLineAttMarker(fTrList); //set defaults
156 track->SetLineColor(iCol);
157 track->SetMarkerColor(iCol);
158 track->SetMarkerSize(2.);
159 //track->SetMarkerDraw(kTRUE);
160
161 track->SetPoint(0, tr->GetFitX(0.), tr->GetFitY(0.), 0.); //insert starting point
162 TEveVector pos0 = TEveVector(tr->GetFitX(0.), tr->GetFitY(0.), 0.);
163 TEvePathMark* path0 = new TEvePathMark();
164 path0->fV = pos0;
165 track->AddPathMark(*path0);
166
167 Double_t pbuf[3], vbuf[3];
168 TEveRecTrack rt;
169 rt.fIndex = i;
170 pbuf[0] = 0.;
171 pbuf[1] = 0.;
172 pbuf[2] = 1. / tr->GetTt(); // velocity
173 rt.fP.Set(pbuf);
174 vbuf[0] = tr->GetFitX(0.);
175 vbuf[1] = tr->GetFitY(0.);
176 vbuf[2] = 0.;
177 rt.fV.Set(vbuf);
178 track->SetName(Form("TEveTrack %d", rt.fIndex));
179
180 //track->SetStdTitle();
181 // Double_t beta, beta_err, res_x, res_y, res_z, res_t;
182 Double_t beta, beta_err, res_x, res_y, res_t;
183 switch (iOpt) {
184 case 0: track->SetStdTitle(); break;
185 case 1:
186#if TOFDisplay == 1 //setting content of label depending on available information
187 beta = (1 / tr->GetTt()) / 29.98;
188#if TOFTtErr == 1
189 beta_err = beta * (tr->GetTtErr() / tr->GetTt());
190 track->SetTitle(
191 Form("%s\nChiSqDoF = %2.2f\nbeta = %1.3f +/- %1.3f", track->GetName(), tr->GetChiSq(), beta, beta_err));
192#else
193 track->SetTitle(Form("%s\nChiSqDoF = %2.2f\nbeta = %1.3f", track->GetName(), tr->GetChiSq(), beta));
194#endif
195#else
196 track->SetStdTitle();
197#endif
198 break;
199 }
200
201#if TOFDisplay == 1
202 // initialize TEvePointSet to show Datapoints belonging to track
203 TEvePointSetArray* psa = new TEvePointSetArray(Form("TEveTrack Points %d", i), "");
204 psa->SetMarkerColor(iCol);
205 psa->SetMarkerSize(1.6);
206 if (iOpt == 0)
207 psa->SetMarkerStyle(4);
208 else
209 psa->SetMarkerStyle(5);
210 psa->InitBins("Hits", Np, 0.5, Np + 0.5);
211#endif
212
213 for (Int_t n = 0; n < Np; n++) {
214 switch (iOpt) {
215 case 0: point = tr->GetPoint(n); //pointer to member variable so GetFitPoint() would also change GetPoint()
216#if TOFDisplay == 1
217 // following belongs to filling and labeling of PointSetArray
218 psa->Fill(point[0], point[1], point[2], n + 1);
219 hit = tr->GetTofHitPointer(n);
220 res_x = (point[0] - tr->GetFitX(point[2])) / hit->GetDx();
221 res_y = (point[1] - tr->GetFitY(point[2])) / hit->GetDy();
222 res_t = (point[3] - tr->GetFitT(point[2])) / hit->GetTimeError();
223 // res_z=0;
224 psa->GetBin(n + 1)->SetTitle(Form("%s\nPointId = %d\nResiduals:\nX = %1.3f\nY = %1.3f\nT = %1.3f",
225 track->GetName(), tr->GetHitIndex(n), res_x, res_y, res_t));
226#endif
227 break;
228 case 1: // represent fit
229 point = tr->GetFitPoint(n);
230 psa->Fill(point[0], point[1], point[2], n + 1);
231 break;
232 }
233 track->SetPoint(n + 1, point[0], point[1], point[2]);
234 /*
235 LOG(info) << Form(" CbmTsDisTofTracklets::SetPoint Opt %d, n %d, %6.2f, %6.2f, %6.2f, %6.2f ", iOpt, n, point[0], point[1],
236 point[2], point[3]);
237 */
238 TEveVector pos = TEveVector(point[0], point[1], point[2]);
239 TEvePathMark* path = new TEvePathMark();
240 path->fV = pos;
241 path->fTime = point[3];
242 if (n == 0) {
243 TEveVector Mom = TEveVector(P->Px(), P->Py(), P->Pz());
244 path->fP = Mom;
245 }
246
247 track->AddPathMark(*path);
248 if (iOpt == 1 && n == Np - 1) {
249 //LOG(info) << "Add extrapolation by 20%, TBD ";
250 Double_t pointL[3];
251 pointL[2] = point[2] * 1.2;
252 pointL[0] = tr->GetFitX(pointL[2]);
253 pointL[1] = tr->GetFitY(pointL[2]);
254 track->SetPoint(n + 2, pointL[0], pointL[1], pointL[2]);
255 TEveVector posL = TEveVector(pointL[0], pointL[1], pointL[2]);
256 TEvePathMark* pathL = new TEvePathMark();
257 pathL->fV = posL;
258 track->AddPathMark(*pathL);
259 }
260
261 LOG(debug4) << "Path marker added " << path;
262 }
263#if TOFDisplay == 1
264 if (iOpt >= 0) {
265 fPSList->AddElement(psa);
266 }
267#endif
268 track->SortPathMarksByTime();
269 fTrList->AddElement(track);
270 LOG(debug3) << i << ". track added: " << track->GetName();
271 }
272 for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
273 // TEveTrackList *TrListIn=( TEveTrackList *) fEveTrList->At(i);
274 //TrListIn->FindMomentumLimits(TrListIn, kFALSE);
275 }
276
277 //fEventManager->SetEvtMaxEnergy(MaxEnergyLimit);
278 //fEventManager->SetEvtMinEnergy(MinEnergyLimit);
279 TString cEventInfo;
280 if (nullptr == fTsManager)
281 cEventInfo = Form("ev# %d ", fEventManager->GetCurrentEvent());
282 else
283 cEventInfo = Form("ev# %d ", fTsManager->GetCurrentEvent());
284
285 TString cTrackInfo = "TrklMul: "; // to be completed while building the display
286 for (Int_t i = 9; i > 0; i--)
287 if (TMul[i] > 0) cTrackInfo += Form("M%d %d/", i, TMul[i]);
288
289 TGLViewer* v = gEve->GetDefaultGLViewer();
290 /*
291 if (nullptr != anne) anne->SetText(cEventInfo);
292 else
293 anne = new TGLAnnotation(v, cEventInfo, 0.01, 0.95);
294 */
295 if (nullptr != annt)
296 annt->SetText(cTrackInfo);
297 else
298 annt = new TGLAnnotation(v, cTrackInfo, 0.01, 0.78);
299 //anne->SetTextSize(0.03); // % of window diagonal
300 //anne->SetTextColor(4);
301 annt->SetTextSize(0.03); // % of window diagonal
302 annt->SetTextColor(4);
303
304 gEve->Redraw3D(kFALSE);
305 //gEve->DoRedraw3D();
306 //gEve->Redraw3D(kTRUE);
307 }
308}
309// ----- Destructor ----------------------------------------------------
311// -------------------------------------------------------------------------
313
314// -------------------------------------------------------------------------
316// -------------------------------------------------------------------------
318{
319 for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
320 TEveTrackList* ele = (TEveTrackList*) fEveTrList->At(i);
321 //gEve->RemoveElement(ele, fEventManager);
322 LOG(debug3) << GetName() << ": remove Tr elements from " << ele->GetName();
323 ele->Clear();
324 gEve->RemoveElement(ele, fTsManager);
325 }
326 fEveTrList->Clear();
327#if TOFDisplay == 1
328 for (Int_t i = 0; i < fEvePSList->GetEntriesFast(); i++) {
329 TEveElementList* ele = (TEveElementList*) fEvePSList->At(i);
330 //gEve->RemoveElement(ele, fEventManager);
331 LOG(debug3) << GetName() << ": remove PS elements from " << ele->GetName();
332 ele->Clear();
333 gEve->RemoveElement(ele, fTsManager);
334 }
335 fEvePSList->Clear();
336#endif
337}
338
339Char_t* gs;
340TEveTrackList* CbmTsDisTofTracklets::GetTrGroup(Int_t ihmul, Int_t iOpt)
341{
342 switch (iOpt) {
343 case 0: gs = Form("Trkl_hmul%d", ihmul); break;
344 case 1: gs = Form("FTrkl_hmul%d", ihmul); break;
345 }
346 fTrList = 0;
347 for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
348 TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
349 if (strcmp(TrListIn->GetName(), gs) == 0) {
350 fTrList = TrListIn;
351 break;
352 }
353 }
354 if (fTrList == 0) {
355 fTrPr = new TEveTrackPropagator();
356 fTrList = new TEveTrackList(gs, fTrPr);
357 Int_t iCol = ihmul;
358 if (iCol > 4) iCol++;
359 fTrList->SetMainColor(iCol);
360 fEveTrList->Add(fTrList);
361#if TOFDisplay == 1
362 if (iOpt == 1) { // delete if-condition to return to old code
363 //gEve->AddElement(fTrList, fEventManager);
364 gEve->AddElement(fTrList, fTsManager);
365 }
366#else
367 //gEve->AddElement(fTrList, fEventManager);
368 gEve->AddElement(fTrList, fTsManager);
369#endif
370 fTrList->SetRecurse(kTRUE);
371 switch (iOpt) {
372 case 0: // display points
373 fTrList->SetRnrPoints(kTRUE);
374 fTrList->SetRnrLine(kFALSE);
375 fTrList->SetMarkerSize(2.);
376 fTrList->SetRnrChildren(fRenderP); // default not shown
377 break;
378 case 1: //display fit line
379 fTrList->SetRnrLine(kTRUE);
380 fTrList->SetLineWidth(2.);
381 fTrList->SetRnrChildren(fRenderT); // default not shown
382 break;
383 default:;
384 }
385 }
386 return fTrList;
387}
388#if TOFDisplay == 1
389TEveElementList* CbmTsDisTofTracklets::GetPSGroup(Int_t ihmul, Int_t iOpt)
390{
391 if (iOpt == 0)
392 gs = Form("PTrkl_hmul%d", ihmul);
393 else
394 gs = Form("FTrkl_hmul%d", ihmul);
395 fPSList = 0;
396 for (Int_t i = 0; i < fEvePSList->GetEntriesFast(); i++) {
397 TEveElementList* l = (TEveElementList*) fEvePSList->At(i);
398 if (strcmp(l->GetName(), gs) == 0) {
399 fPSList = l;
400 break;
401 }
402 }
403 if (fPSList == 0) {
404 fPSList = new TEveElementList(gs);
405 Int_t iCol = ihmul;
406 if (iCol > 4) iCol++;
407 fPSList->SetMainColor(iCol);
408 fEvePSList->Add(fPSList);
409 //gEve->AddElement(fPSList, fEventManager);
410 gEve->AddElement(fPSList, fTsManager);
411 fPSList->SetRnrChildren(fRenderP);
412 }
413 return fPSList;
414}
415#endif
416
static TGLAnnotation * annt
Char_t * gs
static CbmTimesliceManager * fTsManager
static TGLAnnotation * annt
ClassImp(CbmTsDisTofTracklets)
static FairEventManager * fEventManager
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
size_t GetNofData() const
Definition CbmEvent.cxx:58
double GetTimeError() const
Definition CbmHit.h:77
double GetDy() const
Definition CbmPixelHit.h:76
double GetDx() const
Definition CbmPixelHit.h:75
TBrowser Event display for Timeslices as Tree entry with CbmEvents in container. Function as unique I...
virtual Int_t GetCurrentEvent() const
static CbmTimesliceManager * Instance()
Provides information on attaching a TofHit to a TofTrack.
double GetFitY(double Z)
int32_t GetHitIndex(int32_t ind) const
double GetTt() const
int32_t GetNofHits() const
CbmTofHit * GetTofHitPointer(int32_t ind)
const double * GetPoint(int32_t n)
double GetFitT(double R)
const double * GetFitPoint(int32_t n)
double GetTtErr() const
int32_t GetPidHypo() const
double GetChiSq() const
double GetFitX(double Z)
TEveTrackList * GetTrGroup(Int_t ihmul, Int_t iOpt)
TEveElementList * GetPSGroup(Int_t ihuml, Int_t iOpt)
void GotoEvent(uint32_t uEventIdx)
static CbmTsDisTofTracklets * fInstance
TEveElementList * fPSList
virtual InitStatus Init()
TEveTrackPropagator * fTrPr
virtual void Exec(Option_t *option)