CbmRoot
CbmRecoTracks.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2016 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // -------------------------------------------------------------------------
9 // ----- CbmRecoTracks source file -----
10 // ----- Created 12/02/16 by T. Ablyazimov -----
11 // -------------------------------------------------------------------------
12 #include "CbmRecoTracks.h"
13 
14 #include "CbmGlobalTrack.h" // for CbmGlobalTrack
15 #include "CbmHit.h" // for HitType, kMUCHPIXELHIT, kRICHHIT
16 #include "CbmPixelHit.h" // for CbmPixelHit
17 #include "CbmRichRing.h" // for CbmRichRing
18 #include "CbmStsTrack.h" // for CbmStsTrack
19 #include "CbmTrack.h" // for CbmTrack
20 
21 #include <FairEventManager.h> // for FairEventManager
22 #include <FairLogger.h> // for LOG, Logger
23 #include <FairRootManager.h> // for FairRootManager
24 #include <FairTask.h> // for FairTask, InitStatus, kERROR, kSUCCESS
25 #include <FairTrackParam.h> // for FairTrackParam
26 
27 #include <Rtypes.h> // for ClassImp
28 #include <TClonesArray.h> // for TClonesArray
29 #include <TEveManager.h> // for TEveManager, gEve
30 #include <TEvePathMark.h> // for TEvePathMark
31 #include <TEveTrack.h> // for TEveTrackList, TEveTrack
32 #include <TEveTrackPropagator.h> // for TEveTrackPropagator
33 #include <TEveVector.h> // for TEveVector, TEveVectorT
34 #include <TGenericClassInfo.h> // for TGenericClassInfo
35 #include <TObjArray.h> // for TObjArray
36 #include <TParticle.h> // for TParticle
37 #include <TString.h> // for TString
38 #include <TVector3.h> // for TVector3
39 
40 #include <stdio.h> // for sprintf
41 #include <string.h> // for strcmp
42 
43 // ----- Default constructor -------------------------------------------
45  : FairTask("FairMCTracks", 0)
46  , fGlobalTracks(nullptr)
47  , fMvdHits(nullptr)
48  , fStsHits(nullptr)
49  , fStsTracks(nullptr)
50  , fRichRings(nullptr)
51  , fRichHits(nullptr)
52  , fMuchPixelHits(nullptr)
53  , fMuchTracks(nullptr)
54  , fTrdHits(nullptr)
55  , fTrdTracks(nullptr)
56  , fTofHits(nullptr)
57  , fTrPr(nullptr)
58  , fEventManager(nullptr)
59  , fEveTrList(nullptr)
60  , fEvent("")
61  , fTrList(nullptr)
62  , MinEnergyLimit(-1.)
63  , MaxEnergyLimit(-1.)
64  , PEnergy(-1.) {}
65 // -------------------------------------------------------------------------
66 
67 
68 // ----- Standard constructor ------------------------------------------
69 CbmRecoTracks::CbmRecoTracks(const char* name, Int_t iVerbose)
70  : FairTask(name, iVerbose)
71  , fGlobalTracks(nullptr)
72  , fMvdHits(nullptr)
73  , fStsHits(nullptr)
74  , fStsTracks(nullptr)
75  , fRichRings(nullptr)
76  , fRichHits(nullptr)
77  , fMuchPixelHits(nullptr)
78  , fMuchTracks(nullptr)
79  , fTrdHits(nullptr)
80  , fTrdTracks(nullptr)
81  , fTofHits(nullptr)
82  , fTrPr(nullptr)
83  , fEventManager(nullptr)
84  , fEveTrList(new TObjArray(16))
85  , fEvent("")
86  , fTrList(nullptr)
87  , MinEnergyLimit(-1.)
88  , MaxEnergyLimit(-1.)
89  , PEnergy(-1.) {}
90 // -------------------------------------------------------------------------
91 InitStatus CbmRecoTracks::Init() {
92  LOG(debug) << "FairMCTracks::Init()";
93  FairRootManager* fManager = FairRootManager::Instance();
94  fGlobalTracks = (TClonesArray*) fManager->GetObject("GlobalTrack");
95  fStsTracks = (TClonesArray*) fManager->GetObject("StsTrack");
96  fMvdHits = (TClonesArray*) fManager->GetObject("MvdHit");
97  fStsHits = (TClonesArray*) fManager->GetObject("StsHit");
98  fRichRings = (TClonesArray*) fManager->GetObject("RichRing");
99  fRichHits = (TClonesArray*) fManager->GetObject("RichHit");
100  fMuchPixelHits = (TClonesArray*) fManager->GetObject("MuchPixelHit");
101  fMuchTracks = (TClonesArray*) fManager->GetObject("MuchTrack");
102  fTrdHits = (TClonesArray*) fManager->GetObject("TrdHit");
103  fTrdTracks = (TClonesArray*) fManager->GetObject("TrdTrack");
104  fTofHits = (TClonesArray*) fManager->GetObject("TofHit");
105 
106  if (fGlobalTracks == 0) {
107  LOG(error) << "FairMCTracks::Init() branch " << GetName()
108  << "GlobalTrack branch not found! Task will be deactivated";
109  SetActive(kFALSE);
110  }
111 
112  LOG(debug1) << "FairMCTracks::Init() get track list" << fStsTracks;
113  LOG(debug1) << "FairMCTracks::Init() create propagator";
114  fEventManager = FairEventManager::Instance();
115  LOG(debug1) << "FairMCTracks::Init() get instance of FairEventManager ";
116  fEvent = "Current Event";
117  MinEnergyLimit = fEventManager->GetEvtMinEnergy();
118  MaxEnergyLimit = fEventManager->GetEvtMaxEnergy();
119  PEnergy = 0;
120  if (IsActive()) {
121  return kSUCCESS;
122  } else {
123  return kERROR;
124  }
125 }
126 
127 void CbmRecoTracks::HandlePixelHit(TEveTrack* eveTrack,
128  Int_t& n,
129  const CbmPixelHit* hit,
130  TEveVector* pMom = 0) {
131  eveTrack->SetPoint(n, hit->GetX(), hit->GetY(), hit->GetZ());
132  TEveVector pos = TEveVector(hit->GetX(), hit->GetY(), hit->GetZ());
133  TEvePathMark path;
134  path.fV = pos;
135  path.fTime = 0;
136 
137  if (pMom) path.fP = *pMom;
138 
139  eveTrack->AddPathMark(path);
140  ++n;
141 }
142 
143 void CbmRecoTracks::HandleTrack(TEveTrack* eveTrack,
144  Int_t& n,
145  const CbmTrack* recoTrack) {
146  Int_t nofHits = recoTrack->GetNofHits();
147 
148  for (Int_t i = 0; i < nofHits; ++i) {
149  HitType hitType = recoTrack->GetHitType(i);
150  Int_t hitIndex = recoTrack->GetHitIndex(i);
151  const CbmPixelHit* pixelHit = 0;
152 
153  switch (hitType) {
154  case kRICHHIT:
155  pixelHit = static_cast<const CbmPixelHit*>(fRichHits->At(hitIndex));
156  break;
157 
158  case kMUCHPIXELHIT:
159  pixelHit =
160  static_cast<const CbmPixelHit*>(fMuchPixelHits->At(hitIndex));
161  break;
162 
163  case kTRDHIT:
164  pixelHit = static_cast<const CbmPixelHit*>(fTrdHits->At(hitIndex));
165  break;
166 
167  case kTOFHIT:
168  pixelHit = static_cast<const CbmPixelHit*>(fTofHits->At(hitIndex));
169  break;
170  default: LOG(warn) << "Pixel type " << hitType << " not supported.";
171  }
172 
173  if (0 != pixelHit) HandlePixelHit(eveTrack, n, pixelHit);
174  }
175 }
176 
177 void CbmRecoTracks::HandleStsTrack(TEveTrack* eveTrack,
178  Int_t& n,
179  const CbmStsTrack* stsTrack) {
180  for (Int_t i = 0; i < stsTrack->GetNofMvdHits(); ++i) {
181  const CbmPixelHit* hit = static_cast<const CbmPixelHit*>(
182  fMvdHits->At(stsTrack->GetMvdHitIndex(i)));
183 
184  if (0 == n) {
185  TVector3 mom3;
186  stsTrack->GetParamFirst()->Momentum(mom3);
187  TEveVector mom = TEveVector(mom3.X(), mom3.Y(), mom3.Z());
188  HandlePixelHit(eveTrack, n, hit, &mom);
189  } else
190  HandlePixelHit(eveTrack, n, hit);
191  }
192 
193  for (Int_t i = 0; i < stsTrack->GetNofStsHits(); ++i) {
194  const CbmPixelHit* hit = static_cast<const CbmPixelHit*>(
195  fStsHits->At(stsTrack->GetStsHitIndex(i)));
196 
197  if (0 == n) {
198  TVector3 mom3;
199  stsTrack->GetParamFirst()->Momentum(mom3);
200  TEveVector mom = TEveVector(mom3.X(), mom3.Y(), mom3.Z());
201  HandlePixelHit(eveTrack, n, hit, &mom);
202  } else
203  HandlePixelHit(eveTrack, n, hit);
204  }
205 }
206 
207 void CbmRecoTracks::Exec(Option_t* /*option*/) {
208 
209  if (IsActive()) {
210 
211  LOG(debug1) << " CbmRecoTracks::Exec ";
212 
213  Reset();
214 
215  Int_t nofGlobalTracks = fGlobalTracks->GetEntriesFast();
216 
217  for (Int_t i = 0; i < nofGlobalTracks; ++i) {
218  LOG(debug3) << "CbmRecoTracks::Exec " << i;
219  const CbmGlobalTrack* globalTrack =
220  static_cast<const CbmGlobalTrack*>(fGlobalTracks->At(i));
221  Int_t stsId = globalTrack->GetStsTrackIndex();
222  Int_t richId = globalTrack->GetRichRingIndex();
223  Int_t muchId = globalTrack->GetMuchTrackIndex();
224  Int_t trdId = globalTrack->GetTrdTrackIndex();
225  Int_t tofId = globalTrack->GetTofHitIndex();
226 
227  if (0 > stsId) continue;
228 
229  const CbmStsTrack* stsTrack =
230  static_cast<const CbmStsTrack*>(fStsTracks->At(stsId));
231 
232  if (0 == stsTrack) continue;
233 
234  Int_t pdg = stsTrack->GetPidHypo();
235  TParticle P;
236  P.SetPdgCode(pdg);
237  fTrList = GetTrGroup(&P);
238  TEveTrack* eveTrack = new TEveTrack(&P, pdg, fTrPr);
239  eveTrack->SetLineColor(fEventManager->Color(pdg));
240  Int_t n = 0;
241  HandleStsTrack(eveTrack, n, stsTrack);
242  //LOG(info) << "GetPidHypo: " << stsTrack->GetPidHypo();
243 
244  if (-1 < richId) {
245  const CbmRichRing* r =
246  static_cast<const CbmRichRing*>(fRichRings->At(richId));
247  const CbmPixelHit* rh =
248  static_cast<const CbmPixelHit*>(fRichHits->At(r->GetHit(0)));
249  CbmPixelHit h(*rh);
250  h.SetX(r->GetCenterX());
251  h.SetY(r->GetCenterY());
252  HandlePixelHit(eveTrack, n, &h);
253  } else if (-1 < muchId)
254  HandleTrack(
255  eveTrack, n, static_cast<const CbmTrack*>(fMuchTracks->At(muchId)));
256 
257  if (-1 < trdId)
258  HandleTrack(
259  eveTrack, n, static_cast<const CbmTrack*>(fTrdTracks->At(trdId)));
260 
261  if (-1 < tofId)
263  eveTrack, n, static_cast<const CbmPixelHit*>(fTofHits->At(tofId)));
264 
265  fTrList->AddElement(eveTrack);
266  LOG(debug3) << "track added " << eveTrack->GetName();
267  }
268 
269  //fEventManager->SetEvtMaxEnergy(MaxEnergyLimit);
270  //fEventManager->SetEvtMinEnergy(MinEnergyLimit);
271  gEve->Redraw3D(kFALSE);
272  }
273 }
274 // ----- Destructor ----------------------------------------------------
276 // -------------------------------------------------------------------------
278 
279 // -------------------------------------------------------------------------
281 // -------------------------------------------------------------------------
283  for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
284  TEveTrackList* ele = (TEveTrackList*) fEveTrList->At(i);
285  gEve->RemoveElement(ele, fEventManager);
286  }
287  fEveTrList->Clear();
288 }
289 
290 TEveTrackList* CbmRecoTracks::GetTrGroup(TParticle* P) {
291  char name_buf[128];
292  sprintf(name_buf, "reco_%s", P->GetName());
293  fTrList = 0;
294  for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
295  TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
296  if (strcmp(TrListIn->GetName(), name_buf) == 0) {
297  fTrList = TrListIn;
298  break;
299  }
300  }
301  if (fTrList == 0) {
302  fTrPr = new TEveTrackPropagator();
303  fTrList = new TEveTrackList(name_buf, fTrPr);
304  fTrList->SetMainColor(fEventManager->Color(P->GetPdgCode()));
305  fEveTrList->Add(fTrList);
306  gEve->AddElement(fTrList, fEventManager);
307  fTrList->SetRnrLine(kTRUE);
308  }
309  return fTrList;
310 }
311 
CbmHit::GetZ
Double_t GetZ() const
Definition: CbmHit.h:70
CbmRecoTracks::fEventManager
FairEventManager * fEventManager
Definition: CbmRecoTracks.h:92
CbmRecoTracks::fEvent
TString fEvent
Definition: CbmRecoTracks.h:94
CbmRecoTracks::HandleTrack
void HandleTrack(TEveTrack *eveTrack, Int_t &n, const CbmTrack *recoTrack)
Definition: CbmRecoTracks.cxx:143
CbmPixelHit::GetX
Double_t GetX() const
Definition: CbmPixelHit.h:83
CbmGlobalTrack::GetMuchTrackIndex
Int_t GetMuchTrackIndex() const
Definition: CbmGlobalTrack.h:40
CbmTrack::GetNofHits
virtual Int_t GetNofHits() const
Definition: CbmTrack.h:53
CbmRecoTracks::CbmRecoTracks
CbmRecoTracks()
Definition: CbmRecoTracks.cxx:44
CbmRecoTracks::fStsHits
TClonesArray * fStsHits
Definition: CbmRecoTracks.h:82
CbmPixelHit::GetY
Double_t GetY() const
Definition: CbmPixelHit.h:84
CbmRecoTracks::fTrdTracks
TClonesArray * fTrdTracks
Definition: CbmRecoTracks.h:89
CbmGlobalTrack::GetRichRingIndex
Int_t GetRichRingIndex() const
Definition: CbmGlobalTrack.h:41
CbmRecoTracks::Init
virtual InitStatus Init()
Definition: CbmRecoTracks.cxx:91
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
kTOFHIT
@ kTOFHIT
Definition: CbmHit.h:26
CbmRecoTracks::fTrPr
TEveTrackPropagator * fTrPr
Definition: CbmRecoTracks.h:91
CbmRecoTracks::fMuchTracks
TClonesArray * fMuchTracks
Definition: CbmRecoTracks.h:87
CbmGlobalTrack.h
CbmRichRing
Definition: CbmRichRing.h:17
CbmRecoTracks::fRichRings
TClonesArray * fRichRings
Definition: CbmRecoTracks.h:84
CbmRichRing.h
CbmRecoTracks::MaxEnergyLimit
Double_t MaxEnergyLimit
Definition: CbmRecoTracks.h:99
CbmStsTrack::GetNofMvdHits
Int_t GetNofMvdHits() const
Definition: CbmStsTrack.h:84
CbmRichRing::GetHit
UInt_t GetHit(Int_t i) const
Definition: CbmRichRing.h:42
CbmTrack
Definition: CbmTrack.h:32
CbmStsTrack.h
Data class for STS tracks.
CbmGlobalTrack::GetStsTrackIndex
Int_t GetStsTrackIndex() const
Definition: CbmGlobalTrack.h:38
CbmHit.h
CbmRecoTracks::PEnergy
Double_t PEnergy
Definition: CbmRecoTracks.h:100
h
Data class with information on a STS local track.
CbmTrack.h
HitType
HitType
Definition: CbmHit.h:16
CbmRecoTracks::fMuchPixelHits
TClonesArray * fMuchPixelHits
Definition: CbmRecoTracks.h:86
CbmTrack::GetHitIndex
Int_t GetHitIndex(Int_t iHit) const
Definition: CbmTrack.h:54
CbmGlobalTrack::GetTrdTrackIndex
Int_t GetTrdTrackIndex() const
Definition: CbmGlobalTrack.h:39
CbmRecoTracks::fRichHits
TClonesArray * fRichHits
Definition: CbmRecoTracks.h:85
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmRecoTracks::fMvdHits
TClonesArray * fMvdHits
Definition: CbmRecoTracks.h:81
CbmPixelHit.h
CbmTrack::GetHitType
HitType GetHitType(Int_t iHit) const
Definition: CbmTrack.h:55
CbmTrack::GetParamFirst
const FairTrackParam * GetParamFirst() const
Definition: CbmTrack.h:61
CbmRecoTracks::HandleStsTrack
void HandleStsTrack(TEveTrack *eveTrack, Int_t &n, const CbmStsTrack *stsTrack)
Definition: CbmRecoTracks.cxx:177
kTRDHIT
@ kTRDHIT
Definition: CbmHit.h:25
CbmRecoTracks::Reset
void Reset()
Definition: CbmRecoTracks.cxx:282
CbmRecoTracks::fTofHits
TClonesArray * fTofHits
Definition: CbmRecoTracks.h:90
CbmRecoTracks::SetParContainers
virtual void SetParContainers()
Definition: CbmRecoTracks.cxx:277
CbmRecoTracks::fTrList
TEveTrackList * fTrList
Definition: CbmRecoTracks.h:95
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
CbmRecoTracks::fTrdHits
TClonesArray * fTrdHits
Definition: CbmRecoTracks.h:88
CbmRecoTracks::Finish
virtual void Finish()
Definition: CbmRecoTracks.cxx:280
CbmRecoTracks::~CbmRecoTracks
virtual ~CbmRecoTracks()
Definition: CbmRecoTracks.cxx:275
CbmRecoTracks::fEveTrList
TObjArray * fEveTrList
Definition: CbmRecoTracks.h:93
CbmRecoTracks
Definition: CbmRecoTracks.h:43
CbmStsTrack::GetMvdHitIndex
Int_t GetMvdHitIndex(Int_t iHit) const
Definition: CbmStsTrack.h:70
pos
TVector3 pos
Definition: CbmMvdSensorDigiToHitTask.cxx:60
CbmPixelHit
Definition: CbmPixelHit.h:21
kMUCHPIXELHIT
@ kMUCHPIXELHIT
Definition: CbmHit.h:23
CbmTrack::GetPidHypo
Int_t GetPidHypo() const
Definition: CbmTrack.h:56
CbmRichRing::GetCenterY
Float_t GetCenterY() const
Definition: CbmRichRing.h:81
CbmRecoTracks::MinEnergyLimit
Double_t MinEnergyLimit
Definition: CbmRecoTracks.h:98
CbmGlobalTrack::GetTofHitIndex
Int_t GetTofHitIndex() const
Definition: CbmGlobalTrack.h:42
CbmStsTrack::GetStsHitIndex
Int_t GetStsHitIndex(Int_t iHit) const
Definition: CbmStsTrack.h:98
kRICHHIT
@ kRICHHIT
Definition: CbmHit.h:22
CbmRecoTracks::Exec
virtual void Exec(Option_t *option)
Definition: CbmRecoTracks.cxx:207
CbmRecoTracks.h
CbmStsTrack
Definition: CbmStsTrack.h:37
CbmRecoTracks::HandlePixelHit
void HandlePixelHit(TEveTrack *eveTrack, Int_t &n, const CbmPixelHit *hit, TEveVector *pMom)
Definition: CbmRecoTracks.cxx:127
CbmRecoTracks::fGlobalTracks
TClonesArray * fGlobalTracks
Definition: CbmRecoTracks.h:80
CbmRichRing::GetCenterX
Float_t GetCenterX() const
Definition: CbmRichRing.h:80
CbmRecoTracks::GetTrGroup
TEveTrackList * GetTrGroup(TParticle *P)
Definition: CbmRecoTracks.cxx:290
CbmRecoTracks::fStsTracks
TClonesArray * fStsTracks
Definition: CbmRecoTracks.h:83
CbmStsTrack::GetNofStsHits
Int_t GetNofStsHits() const
Definition: CbmStsTrack.h:90