CbmRoot
Loading...
Searching...
No Matches
CbmTimesliceRecoTracks.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau[committer], Norbert Herrmann */
5
6#include "CbmEvent.h" // For CbmEvent
7#include "CbmGlobalTrack.h" // for CbmGlobalTrack
8#include "CbmHit.h" // for HitType, kMUCHPIXELHIT, kRICHHIT
9#include "CbmPixelHit.h" // for CbmPixelHit
10#include "CbmRichRing.h" // for CbmRichRing
11#include "CbmStsTrack.h" // for CbmStsTrack
12#include "CbmTrack.h" // for CbmTrack
13#include <CbmTimesliceManager.h> // for CbmTimesliceManager
14
15#include <FairRootManager.h> // for FairRootManager
16#include <FairTask.h> // for FairTask, InitStatus, kERROR, kSUCCESS
17#include <FairTrackParam.h> // for FairTrackParam
18#include <Logger.h> // for LOG, Logger
19
20#include <Rtypes.h> // for ClassImp
21#include <TClonesArray.h> // for TClonesArray
22#include <TEveManager.h> // for TEveManager, gEve
23#include <TEvePathMark.h> // for TEvePathMark
24#include <TEveTrack.h> // for TEveTrackList, TEveTrack
25#include <TEveTrackPropagator.h> // for TEveTrackPropagator
26#include <TEveVector.h> // for TEveVector, TEveVectorT
27#include <TGenericClassInfo.h> // for TGenericClassInfo
28#include <TParticle.h> // for TParticle
29#include <TString.h> // for TString
30#include <TVector3.h> // for TVector3
31
32#include <stdio.h> // for sprintf
33#include <string.h> // for strcmp
34
35// -------------------------------------------------------------------------
37{
38 LOG(debug) << "CbmTimesliceRecoTracks::Init()";
39 FairRootManager* fManager = FairRootManager::Instance();
40
41 fCbmEvents = dynamic_cast<TClonesArray*>(fManager->GetObject("CbmEvent"));
42 fGlobalTracks = dynamic_cast<TClonesArray*>(fManager->GetObject("GlobalTrack"));
43 fStsTracks = dynamic_cast<TClonesArray*>(fManager->GetObject("StsTrack"));
44 fMvdHits = dynamic_cast<TClonesArray*>(fManager->GetObject("MvdHit"));
45 fStsHits = dynamic_cast<TClonesArray*>(fManager->GetObject("StsHit"));
46 fRichRings = dynamic_cast<TClonesArray*>(fManager->GetObject("RichRing"));
47 fRichHits = dynamic_cast<TClonesArray*>(fManager->GetObject("RichHit"));
48 fMuchPixelHits = dynamic_cast<TClonesArray*>(fManager->GetObject("MuchPixelHit"));
49 fMuchTracks = dynamic_cast<TClonesArray*>(fManager->GetObject("MuchTrack"));
50 fTrdHits = dynamic_cast<TClonesArray*>(fManager->GetObject("TrdHit"));
51 fTrdTracks = dynamic_cast<TClonesArray*>(fManager->GetObject("TrdTrack"));
52 fTofHits = dynamic_cast<TClonesArray*>(fManager->GetObject("TofHit"));
53 fTofTracks = dynamic_cast<TClonesArray*>(fManager->GetObject("TofTrack"));
54
55 if (nullptr == fTofTracks) {
56 LOG(warn) << "TofTracks not found";
57 }
58
59 if (nullptr == fCbmEvents) {
60 LOG(fatal) << "CbmTimesliceRecoTracks::Init() => CbmEvents branch not found! Task will be deactivated";
61 SetActive(kFALSE);
62 }
63
64 LOG(debug1) << "CbmTimesliceRecoTracks::Init() get track list" << fStsTracks;
65 LOG(debug1) << "CbmTimesliceRecoTracks::Init() create propagator";
67 LOG(debug1) << "CbmTimesliceRecoTracks::Init() got instance of CbmTimesliceManager ";
68
69 if (IsActive()) { return kSUCCESS; }
70 else {
71 return kERROR;
72 }
73}
74
75void CbmTimesliceRecoTracks::HandlePixelHit(TEveTrack* eveTrack, Int_t& n, const CbmPixelHit* hit, TEveVector* pMom = 0)
76{
77 eveTrack->SetPoint(n, hit->GetX(), hit->GetY(), hit->GetZ());
78 TEveVector pos = TEveVector(hit->GetX(), hit->GetY(), hit->GetZ());
79 TEvePathMark path;
80 path.fV = pos;
81 path.fTime = 0;
82
83 if (pMom) path.fP = *pMom;
84
85 eveTrack->AddPathMark(path);
86 ++n;
87}
88
89void CbmTimesliceRecoTracks::HandleTrack(TEveTrack* eveTrack, Int_t& n, const CbmTrack* recoTrack)
90{
91 Int_t nofHits = recoTrack->GetNofHits();
92
93 for (Int_t i = 0; i < nofHits; ++i) {
94 HitType hitType = recoTrack->GetHitType(i);
95 Int_t hitIndex = recoTrack->GetHitIndex(i);
96 const CbmPixelHit* pixelHit = 0;
97 LOG(debug4) << "HandleTrack: hit " << i << ", type " << hitType << ", ind " << hitIndex;
98
99 switch (hitType) {
100 case kRICHHIT: pixelHit = static_cast<const CbmPixelHit*>(fRichHits->At(hitIndex)); break;
101
102 case kMUCHPIXELHIT: pixelHit = static_cast<const CbmPixelHit*>(fMuchPixelHits->At(hitIndex)); break;
103
104 case kTRDHIT: pixelHit = static_cast<const CbmPixelHit*>(fTrdHits->At(hitIndex)); break;
105
106 case kTOFHIT: pixelHit = static_cast<const CbmPixelHit*>(fTofHits->At(hitIndex)); break;
107 default: LOG(warn) << "Pixel type " << hitType << " not supported.";
108 }
109
110 if (0 != pixelHit) HandlePixelHit(eveTrack, n, pixelHit);
111 }
112}
113
114void CbmTimesliceRecoTracks::HandleStsTrack(TEveTrack* eveTrack, Int_t& n, const CbmStsTrack* stsTrack)
115{
116 for (Int_t i = 0; i < stsTrack->GetNofMvdHits(); ++i) {
117 const CbmPixelHit* hit = static_cast<const CbmPixelHit*>(fMvdHits->At(stsTrack->GetMvdHitIndex(i)));
118
119 if (0 == n) {
120 TVector3 mom3;
121 stsTrack->GetParamFirst()->Momentum(mom3);
122 TEveVector mom = TEveVector(mom3.X(), mom3.Y(), mom3.Z());
123 HandlePixelHit(eveTrack, n, hit, &mom);
124 }
125 else
126 HandlePixelHit(eveTrack, n, hit);
127 }
128
129 for (Int_t i = 0; i < stsTrack->GetNofStsHits(); ++i) {
130 const CbmPixelHit* hit = static_cast<const CbmPixelHit*>(fStsHits->At(stsTrack->GetStsHitIndex(i)));
131
132 if (0 == n) {
133 TVector3 mom3;
134 stsTrack->GetParamFirst()->Momentum(mom3);
135 TEveVector mom = TEveVector(mom3.X(), mom3.Y(), mom3.Z());
136 HandlePixelHit(eveTrack, n, hit, &mom);
137 }
138 else
139 HandlePixelHit(eveTrack, n, hit);
140 }
141}
142
143void CbmTimesliceRecoTracks::Exec(Option_t* /*option*/)
144{
145 if (0 < fCbmEvents->GetEntriesFast()) {
147 GotoEvent(0);
148 }
149}
150void CbmTimesliceRecoTracks::GotoEvent(uint32_t uEventIdx)
151{
152 LOG(debug3) << "CbmTimesliceRecoTracks::GotoEvent " << uEventIdx;
153
154 if (fCbmEvents->GetEntriesFast() <= static_cast<Int_t>(uEventIdx)) {
155 LOG(fatal) << "CbmTimesliceRecoTracks::GotoEvent() => Failure, tried to load event " << uEventIdx << " while only "
156 << fCbmEvents->GetEntriesFast() << " events available in this TS!!!";
157 }
158
159 fEventIdx = uEventIdx;
160
161 if (CbmTimesliceManager::Instance()->GetClearHandler()) { //
162 Reset();
163 }
164
165 CbmEvent* event = dynamic_cast<CbmEvent*>(fCbmEvents->At(uEventIdx));
166
167 Int_t nofGlobalTracks = event->GetNofData(ECbmDataType::kGlobalTrack);
168 LOG(debug3) << "CbmTimesliceRecoTracks for nofGlobalTracks=" << nofGlobalTracks;
169
170 for (Int_t iGloTrk = 0; iGloTrk < nofGlobalTracks; ++iGloTrk) {
171 LOG(debug3) << "CbmTimesliceRecoTracks::GotoEvent " << iGloTrk;
172 Int_t trkId = event->GetIndex(ECbmDataType::kGlobalTrack, iGloTrk);
173 const CbmGlobalTrack* globalTrack = dynamic_cast<const CbmGlobalTrack*>(fGlobalTracks->At(trkId));
174 Int_t stsId = globalTrack->GetStsTrackIndex();
175 Int_t richId = globalTrack->GetRichRingIndex();
176 Int_t muchId = globalTrack->GetMuchTrackIndex();
177 Int_t trdId = globalTrack->GetTrdTrackIndex();
178 Int_t tofId = globalTrack->GetTofTrackIndex();
179 Int_t tofHitId = globalTrack->GetTofHitIndex();
180 LOG(debug4) << "GloTrk " << iGloTrk << " trkId " << trkId << " stsId " << stsId << " trdId " << trdId << " tofId "
181 << tofId << ", " << tofHitId;
182
183 // Global Track fit display
184 /*
185 FIXME: Not working yet, just printout
186 globalTrack->Print();
187 const FairTrackParam* tParF = globalTrack->GetParamFirst();
188 tParF->Print();
189 */
190
191 CbmStsTrack* stsTrack = nullptr;
192 if (stsId > -1) {
193 stsTrack = dynamic_cast<CbmStsTrack*>(fStsTracks->At(stsId));
194 }
195
196 Int_t n = 0;
197 Int_t pdg = 0;
198 if (nullptr != stsTrack) {
199 pdg = stsTrack->GetPidHypo();
200 }
201 TParticle P;
202 P.SetPdgCode(pdg);
203 fTrList = GetTrGroup(&P);
204 TEveTrack* eveTrack = new TEveTrack(&P, pdg, fTrPr);
205 if (fbPdgColorTrack && 0 != pdg) { //
206 fEventManager->Color(pdg);
207 }
208 else {
209 eveTrack->SetLineColor(kRed);
210 }
211 if (nullptr != stsTrack) {
212 LOG(debug3) << "HandleStsTrack " << stsId;
213 HandleStsTrack(eveTrack, n, stsTrack);
214 }
215 else {
216 LOG(debug3) << "No Sts track";
217 }
218
219 if (-1 < richId) {
220 const CbmRichRing* r = dynamic_cast<const CbmRichRing*>(fRichRings->At(richId));
221 const CbmPixelHit* rh = dynamic_cast<const CbmPixelHit*>(fRichHits->At(r->GetHit(0)));
222 CbmPixelHit h(*rh);
223 h.SetX(r->GetCenterX());
224 h.SetY(r->GetCenterY());
225 HandlePixelHit(eveTrack, n, &h);
226 }
227 else if (-1 < muchId) {
228 HandleTrack(eveTrack, n, dynamic_cast<const CbmTrack*>(fMuchTracks->At(muchId)));
229 }
230
231 LOG(debug3) << "HandleTrdTrack " << trdId;
232 if (-1 < trdId) {
233 if (nullptr == fTrdTracks) {
234 LOG(error) << GetName() << ": No TrdTrack array, return";
235 }
236 else {
237 const CbmTrack* recoTrack = dynamic_cast<const CbmTrack*>(fTrdTracks->At(trdId));
238 LOG(debug3) << "HandleTrdTrack " << trdId << ", " << recoTrack;
239 if (nullptr != recoTrack) HandleTrack(eveTrack, n, recoTrack);
240 }
241 }
242
243 if (-1 < tofId) {
244 if (nullptr == fTofTracks) {
245 LOG(error) << GetName() << ": No TofTrack array, return";
246 }
247 else {
248 const CbmTrack* recoTrack = dynamic_cast<const CbmTrack*>(fTofTracks->At(tofId));
249 LOG(debug3) << "HandleTofTrack " << tofId << ", " << recoTrack;
250 if (nullptr != recoTrack) HandleTrack(eveTrack, n, recoTrack);
251 }
252 }
253 else if (-1 < tofHitId)
254 HandlePixelHit(eveTrack, n, dynamic_cast<const CbmPixelHit*>(fTofHits->At(tofHitId)));
255
257 eveTrack->SetRnrPoints(kTRUE);
258
259 fTrList->AddElement(eveTrack);
260 LOG(debug3) << "track added " << eveTrack->GetName();
261 }
262
263 gEve->Redraw3D(kFALSE);
264}
265// -------------------------------------------------------------------------
267{
268 for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
269 TEveTrackList* ele = (TEveTrackList*) fEveTrList->At(i);
270 LOG(debug3) << GetName() << ": remove elements from " << ele->GetName();
271 gEve->RemoveElement(ele, fEventManager);
272 }
273 fEveTrList->Clear();
274}
275
276TEveTrackList* CbmTimesliceRecoTracks::GetTrGroup(TParticle* P)
277{
278 char name_buf[128];
279 snprintf(name_buf, 128, "reco_%s", P->GetName());
280 fTrList = 0;
281 for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
282 TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
283 if (strcmp(TrListIn->GetName(), name_buf) == 0) {
284 fTrList = TrListIn;
285 break;
286 }
287 }
288 if (fTrList == 0) {
289 fTrPr = new TEveTrackPropagator();
290 fTrList = new TEveTrackList(name_buf, fTrPr);
291 fTrList->SetMainColor(fEventManager->Color(P->GetPdgCode()));
292 fEveTrList->Add(fTrList);
293 gEve->AddElement(fTrList, fEventManager);
294 fTrList->SetRnrLine(kTRUE);
295 }
296 return fTrList;
297}
298
ClassImp(CbmConverterManager)
HitType
Definition CbmHit.h:21
@ kTOFHIT
Definition CbmHit.h:31
@ kTRDHIT
Definition CbmHit.h:30
@ kRICHHIT
Definition CbmHit.h:27
@ kMUCHPIXELHIT
Definition CbmHit.h:28
Data class for STS tracks.
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
int32_t GetStsTrackIndex() const
int32_t GetRichRingIndex() const
int32_t GetTofTrackIndex() const
int32_t GetTofHitIndex() const
int32_t GetMuchTrackIndex() const
int32_t GetTrdTrackIndex() const
double GetZ() const
Definition CbmHit.h:71
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
uint32_t GetHit(int32_t i) const
Definition CbmRichRing.h:39
float GetCenterX() const
Definition CbmRichRing.h:77
float GetCenterY() const
Definition CbmRichRing.h:78
Data class with information on a STS local track.
int32_t GetNofMvdHits() const
Definition CbmStsTrack.h:87
int32_t GetMvdHitIndex(int32_t iHit) const
Definition CbmStsTrack.h:75
int32_t GetStsHitIndex(int32_t iHit) const
int32_t GetNofStsHits() const
Definition CbmStsTrack.h:93
virtual Int_t Color(Int_t pdg)
static CbmTimesliceManager * Instance()
Interface class to add Cbm Hits drawing (derived from PixelHit) to CbmTimesliceManager....
TEveTrackList * GetTrGroup(TParticle *P)
void GotoEvent(uint32_t uEventIdx)
Load tracks from selected event in timeslice. RESERVED FOR GUI CALLS!
virtual void Exec(Option_t *option)
void HandleTrack(TEveTrack *eveTrack, Int_t &n, const CbmTrack *recoTrack)
void HandlePixelHit(TEveTrack *eveTrack, Int_t &n, const CbmPixelHit *hit, TEveVector *pMom)
TEveTrackPropagator * fTrPr
void HandleStsTrack(TEveTrack *eveTrack, Int_t &n, const CbmStsTrack *stsTrack)
CbmTimesliceManager * fEventManager
int32_t GetPidHypo() const
Definition CbmTrack.h:61
virtual int32_t GetNofHits() const
Definition CbmTrack.h:58
const FairTrackParam * GetParamFirst() const
Definition CbmTrack.h:68
int32_t GetHitIndex(int32_t iHit) const
Definition CbmTrack.h:59
HitType GetHitType(int32_t iHit) const
Definition CbmTrack.h:60