CbmRoot
CbmEvDisTracks.cxx
Go to the documentation of this file.
1 #// -------------------------------------------------------------------------
2 // ----- following FairMCTracks source file -----
3 // ----- Created 10/12/07 by M. Al-Turany -----
4 // -------------------------------------------------------------------------
5 #define TOFDisplay \
6  1 // =1 means active, other: without Label and not relying on TEvePointSet
7 #define TOFTtErr \
8  1 // =1 means active, other: not relying on VelocityError of CbmTofTracklet
9 
10 #include "CbmEvDisTracks.h"
11 
12 #include "CbmTofHit.h" // for CbmTofHit
13 #include "CbmTofTracklet.h" // for CbmTofTracklet
14 
15 #include <FairEventManager.h> // for FairEventManager
16 #include <FairLogger.h> // for LOG, Logger
17 #include <FairRootManager.h> // for FairRootManager
18 #include <FairTask.h> // for FairTask, InitStatus, kERROR, kSUCCESS
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 <TGenericClassInfo.h> // for TGenericClassInfo
31 #include <TObjArray.h> // for TObjArray
32 #include <TParticle.h> // for TParticle
33 #include <TString.h> // for Form, TString
34 
35 #include <string.h> // for strcmp
36 
39 
40 // ----- Default constructor -------------------------------------------
42  : FairTask("CbmEvDisTracks", 0)
43  , fTrackList(nullptr)
44  , fTrPr(nullptr)
45  , fEventManager(nullptr)
46  , fEveTrList(nullptr)
47  , fEvent("")
48  , fTrList(nullptr)
49  , fEvePSList(nullptr)
50  , fPSList(nullptr)
51  , fRenderP(kFALSE)
52  , fRenderT(kTRUE)
53  , MinEnergyLimit(-1.)
54  , MaxEnergyLimit(-1.)
55  , PEnergy(-1.) {
56  if (!fInstance) fInstance = this;
57 }
58 // -------------------------------------------------------------------------
59 
60 
61 // ----- Standard constructor ------------------------------------------
63  Int_t iVerbose,
64  Bool_t renderP,
65  Bool_t renderT)
66  : FairTask(name, iVerbose)
67  , fTrackList(nullptr)
68  , fTrPr(nullptr)
69  , fEventManager(nullptr)
70  , fEveTrList(new TObjArray(16))
71  , fEvent("")
72  , fTrList(nullptr)
73  , fEvePSList(new TObjArray(8))
74  , fPSList(nullptr)
75  , fRenderP(renderP)
76  , fRenderT(renderT)
77  , MinEnergyLimit(-1.)
78  , MaxEnergyLimit(-1.)
79  , PEnergy(-1.) {
80  if (!fInstance) fInstance = this;
81 }
82 // -------------------------------------------------------------------------
83 InitStatus CbmEvDisTracks::Init() {
84  LOG(debug) << "CbmEvDisTracks::Init()";
85  FairRootManager* fManager = FairRootManager::Instance();
86  fTrackList = (TClonesArray*) fManager->GetObject("TofTracks");
87  if (fTrackList == 0) {
88  LOG(warn) << "CbmEvDisTracks::Init() branch " << GetName()
89  << " Not found! Task will be deactivated ";
90  SetActive(kFALSE);
91  }
92  LOG(debug1) << "CbmEvDisTracks::Init() get track list" << fTrackList;
93  LOG(debug1) << "CbmEvDisTracks::Init() create propagator";
94  fEventManager = FairEventManager::Instance();
95  LOG(debug1) << "CbmEvDisTracks::Init() get instance of FairEventManager ";
96  fEvent = "Current Event";
97  MinEnergyLimit = fEventManager->GetEvtMinEnergy();
98  MaxEnergyLimit = fEventManager->GetEvtMaxEnergy();
99  PEnergy = 0;
100  if (IsActive()) {
101  return kSUCCESS;
102  } else {
103  return kERROR;
104  }
105 }
106 // -------------------------------------------------------------------------
107 void CbmEvDisTracks::Exec(Option_t* option) {
108 
109  if (IsActive()) {
110 
111  LOG(debug2) << " CbmEvDisTracks::Exec starting with verbosity " << fVerbose
112  << " and option " << option;
113  CbmTofTracklet* tr;
114  const Double_t* point;
115  CbmTofHit* hit;
116 
117  Reset();
118 
119  LOG(debug4) << " CbmEvDisTracks:: NTrks " << fTrackList->GetEntries();
120 
121  for (Int_t iOpt = 0; iOpt < 2; iOpt++)
122  for (Int_t i = 0; i < fTrackList->GetEntriesFast(); i++) {
123  LOG(debug4) << "CbmEvDisTracks::Exec " << i;
124  tr = (CbmTofTracklet*) fTrackList->At(i);
125  if (nullptr == tr) continue;
126  Int_t Np = tr->GetNofHits();
127 
128 #if TOFDisplay == 1 //List for TEvePointSets
129  fPSList = GetPSGroup(Np, iOpt);
130 #endif
131 
132  fTrList = GetTrGroup(tr->GetNofHits(), iOpt);
133  TParticle* P = new TParticle();
134  TEveTrack* track = new TEveTrack(P, tr->GetPidHypo(), fTrPr);
135  Int_t iCol = Np;
136  if (iCol > 4) iCol++;
137  track->SetAttLineAttMarker(fTrList); //set defaults
138  track->SetLineColor(iCol);
139  track->SetMarkerColor(iCol);
140  track->SetMarkerSize(2.);
141  //track->SetMarkerDraw(kTRUE);
142 
143  track->SetPoint(
144  0, tr->GetFitX(0.), tr->GetFitY(0.), 0.); //insert starting point
145  TEveVector pos0 = TEveVector(tr->GetFitX(0.), tr->GetFitY(0.), 0.);
146  TEvePathMark* path0 = new TEvePathMark();
147  path0->fV = pos0;
148  track->AddPathMark(*path0);
149 
150  Double_t pbuf[3], vbuf[3];
151  TEveRecTrack rt;
152  rt.fIndex = i;
153  pbuf[0] = 0.;
154  pbuf[1] = 0.;
155  pbuf[2] = 1. / tr->GetTt(); // velocity
156  rt.fP.Set(pbuf);
157  vbuf[0] = tr->GetFitX(0.);
158  vbuf[1] = tr->GetFitY(0.);
159  vbuf[2] = 0.;
160  rt.fV.Set(vbuf);
161  track->SetName(Form("TEveTrack %d", rt.fIndex));
162 
163  //track->SetStdTitle();
164  // Double_t beta, beta_err, res_x, res_y, res_z, res_t;
165  Double_t beta, beta_err, res_x, res_y, res_t;
166  switch (iOpt) {
167  case 0: track->SetStdTitle(); break;
168  case 1:
169 #if TOFDisplay \
170  == 1 //setting content of label depending on available information
171  beta = (1 / tr->GetTt()) / 29.98;
172 #if TOFTtErr == 1
173  beta_err = beta * (tr->GetTtErr() / tr->GetTt());
174  track->SetTitle(Form("%s\nChiSqDoF = %2.2f\nbeta = %1.3f +/- %1.3f",
175  track->GetName(),
176  tr->GetChiSq(),
177  beta,
178  beta_err));
179 #else
180  track->SetTitle(Form("%s\nChiSqDoF = %2.2f\nbeta = %1.3f",
181  track->GetName(),
182  tr->GetChiSq(),
183  beta));
184 #endif
185 #else
186  track->SetStdTitle();
187 #endif
188  break;
189  }
190 
191 #if TOFDisplay == 1
192  // initialize TEvePointSet to show Datapoints belonging to track
193  TEvePointSetArray* psa =
194  new TEvePointSetArray(Form("TEveTrack Points %d", i), "");
195  psa->SetMarkerColor(iCol);
196  psa->SetMarkerSize(2.0);
197  psa->SetMarkerStyle(4);
198  psa->InitBins("Hits", Np, 0.5, Np + 0.5);
199 #endif
200 
201  for (Int_t n = 0; n < Np; n++) {
202  switch (iOpt) {
203  case 0:
204  point = tr->GetPoint(
205  n); //pointer to membervaribale so GetFitPoint() would also change GetPoint()
206 #if TOFDisplay == 1
207  // follwing belongs to filling and labeling of PointSetArray
208  psa->Fill(point[0], point[1], point[2], n + 1);
209  hit = tr->GetTofHitPointer(n);
210  res_x = (point[0] - tr->GetFitX(point[2])) / hit->GetDx();
211  res_y = (point[1] - tr->GetFitY(point[2])) / hit->GetDy();
212  res_t = (point[3] - tr->GetFitT(point[2])) / hit->GetTimeError();
213  // res_z=0;
214  psa->GetBin(n + 1)->SetTitle(Form(
215  "%s\nPointId = %d\nResiduals:\nX = %1.3f\nY = %1.3f\nT = %1.3f",
216  track->GetName(),
217  tr->GetHitIndex(n),
218  res_x,
219  res_y,
220  res_t));
221 #endif
222  break;
223  case 1: point = tr->GetFitPoint(n); break;
224  }
225  track->SetPoint(n + 1, point[0], point[1], point[2]);
226  LOG(debug4) << Form(
227  " CbmEvDisTracks::Exec SetPoint %d, %6.2f, %6.2f, %6.2f, %6.2f ",
228  n,
229  point[0],
230  point[1],
231  point[2],
232  point[3]);
233 
234  TEveVector pos = TEveVector(point[0], point[1], point[2]);
235  TEvePathMark* path = new TEvePathMark();
236  path->fV = pos;
237  path->fTime = point[3];
238  if (n == 0) {
239  TEveVector Mom = TEveVector(P->Px(), P->Py(), P->Pz());
240  path->fP = Mom;
241  }
242  LOG(debug4) << "Path marker added " << path;
243 
244  track->AddPathMark(*path);
245 
246  LOG(debug4) << "Path marker added " << path;
247  }
248 #if TOFDisplay == 1
249  if (iOpt == 0) { fPSList->AddElement(psa); }
250 #endif
251  track->SortPathMarksByTime();
252  fTrList->AddElement(track);
253  LOG(debug3) << i << ". track added: " << track->GetName();
254  }
255  for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
256  // TEveTrackList *TrListIn=( TEveTrackList *) fEveTrList->At(i);
257  //TrListIn->FindMomentumLimits(TrListIn, kFALSE);
258  }
259  fEventManager->SetEvtMaxEnergy(MaxEnergyLimit);
260  fEventManager->SetEvtMinEnergy(MinEnergyLimit);
261  gEve->Redraw3D(kFALSE);
262  //gEve->DoRedraw3D();
263  //gEve->Redraw3D(kTRUE);
264  }
265 }
266 // ----- Destructor ----------------------------------------------------
268 // -------------------------------------------------------------------------
270 
271 // -------------------------------------------------------------------------
273 // -------------------------------------------------------------------------
275  for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
276  TEveTrackList* ele = (TEveTrackList*) fEveTrList->At(i);
277  gEve->RemoveElement(ele, fEventManager);
278  }
279  fEveTrList->Clear();
280 #if TOFDisplay == 1
281  for (Int_t i = 0; i < fEvePSList->GetEntriesFast(); i++) {
282  TEveElementList* ele = (TEveElementList*) fEvePSList->At(i);
283  gEve->RemoveElement(ele, fEventManager);
284  }
285  fEvePSList->Clear();
286 #endif
287 }
288 
289 Char_t* gr;
290 TEveTrackList* CbmEvDisTracks::GetTrGroup(Int_t ihmul, Int_t iOpt) {
291  switch (iOpt) {
292  case 0: gr = Form("Trkl_hmul%d", ihmul); break;
293  case 1: gr = Form("FTrkl_hmul%d", ihmul); break;
294  }
295  fTrList = 0;
296  for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
297  TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
298  if (strcmp(TrListIn->GetName(), gr) == 0) {
299  fTrList = TrListIn;
300  break;
301  }
302  }
303  if (fTrList == 0) {
304  fTrPr = new TEveTrackPropagator();
305  fTrList = new TEveTrackList(gr, fTrPr);
306  Int_t iCol = ihmul;
307  if (iCol > 4) iCol++;
308  fTrList->SetMainColor(iCol);
309  fEveTrList->Add(fTrList);
310 #if TOFDisplay == 1
311  if (iOpt == 1) { // delete if-condition to return to old code
312  gEve->AddElement(fTrList, fEventManager);
313  }
314 #else
315  gEve->AddElement(fTrList, fEventManager);
316 #endif
317  fTrList->SetRecurse(kTRUE);
318  switch (iOpt) {
319  case 0: // display points
320  fTrList->SetRnrPoints(kTRUE);
321  fTrList->SetRnrLine(kFALSE);
322  fTrList->SetMarkerSize(2.);
323  fTrList->SetRnrChildren(fRenderP); // default not shown
324  break;
325  case 1: //display fit line
326  fTrList->SetRnrLine(kTRUE);
327  fTrList->SetLineWidth(2.);
328  fTrList->SetRnrChildren(fRenderT); // default not shown
329  break;
330  default:;
331  }
332  }
333  return fTrList;
334 }
335 #if TOFDisplay == 1
336 TEveElementList* CbmEvDisTracks::GetPSGroup(Int_t ihmul, Int_t /*iOpt*/) {
337  gr = Form("PTrkl_hmul%d", ihmul);
338  fPSList = 0;
339  for (Int_t i = 0; i < fEvePSList->GetEntriesFast(); i++) {
340  TEveElementList* l = (TEveElementList*) fEvePSList->At(i);
341  if (strcmp(l->GetName(), gr) == 0) {
342  fPSList = l;
343  break;
344  }
345  }
346  if (fPSList == 0) {
347  fPSList = new TEveElementList(gr);
348  Int_t iCol = ihmul;
349  if (iCol > 4) iCol++;
350  fPSList->SetMainColor(iCol);
351  fEvePSList->Add(fPSList);
352  gEve->AddElement(fPSList, fEventManager);
353  fPSList->SetRnrChildren(fRenderP);
354  }
355  return fPSList;
356 }
357 #endif
358 
CbmEvDisTracks::fEventManager
FairEventManager * fEventManager
Definition: CbmEvDisTracks.h:73
CbmEvDisTracks::fTrList
TEveTrackList * fTrList
Definition: CbmEvDisTracks.h:76
CbmTofTracklet::GetHitIndex
Int_t GetHitIndex(Int_t ind) const
Definition: CbmTofTracklet.h:51
CbmEvDisTracks::~CbmEvDisTracks
virtual ~CbmEvDisTracks()
Definition: CbmEvDisTracks.cxx:267
CbmTofTracklet::GetNofHits
Int_t GetNofHits() const
Definition: CbmTofTracklet.h:48
CbmEvDisTracks::Init
virtual InitStatus Init()
Definition: CbmEvDisTracks.cxx:83
CbmPixelHit::GetDx
Double_t GetDx() const
Definition: CbmPixelHit.h:85
CbmEvDisTracks::fTrackList
TClonesArray * fTrackList
Definition: CbmEvDisTracks.h:71
CbmTofTracklet
Provides information on attaching a TofHit to a TofTrack.
Definition: CbmTofTracklet.h:25
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
gr
Char_t * gr
Definition: CbmEvDisTracks.cxx:289
CbmEvDisTracks::Exec
virtual void Exec(Option_t *option)
Definition: CbmEvDisTracks.cxx:107
CbmEvDisTracks::Reset
void Reset()
Definition: CbmEvDisTracks.cxx:274
CbmEvDisTracks::fRenderT
Bool_t fRenderT
Definition: CbmEvDisTracks.h:82
CbmPixelHit::GetDy
Double_t GetDy() const
Definition: CbmPixelHit.h:86
CbmHit::GetTimeError
Double_t GetTimeError() const
Definition: CbmHit.h:76
CbmTofTracklet.h
CbmEvDisTracks::GetPSGroup
TEveElementList * GetPSGroup(Int_t ihuml, Int_t iOpt)
Definition: CbmEvDisTracks.cxx:336
CbmEvDisTracks::fEveTrList
TObjArray * fEveTrList
Definition: CbmEvDisTracks.h:74
CbmTofTracklet::GetTtErr
Double_t GetTtErr() const
Definition: CbmTofTracklet.h:56
CbmEvDisTracks::PEnergy
Double_t PEnergy
Definition: CbmEvDisTracks.h:85
CbmEvDisTracks::fPSList
TEveElementList * fPSList
Definition: CbmEvDisTracks.h:78
CbmEvDisTracks
Definition: CbmEvDisTracks.h:32
CbmEvDisTracks::fRenderP
Bool_t fRenderP
Definition: CbmEvDisTracks.h:81
ClassImp
ClassImp(CbmEvDisTracks)
CbmTofTracklet::GetTt
Double_t GetTt() const
Definition: CbmTofTracklet.h:54
CbmEvDisTracks::fInstance
static CbmEvDisTracks * fInstance
Definition: CbmEvDisTracks.h:88
CbmEvDisTracks::fEvent
TString fEvent
Definition: CbmEvDisTracks.h:75
CbmEvDisTracks::fTrPr
TEveTrackPropagator * fTrPr
Definition: CbmEvDisTracks.h:72
CbmEvDisTracks::MinEnergyLimit
Double_t MinEnergyLimit
Definition: CbmEvDisTracks.h:83
CbmEvDisTracks.h
CbmEvDisTracks::GetTrGroup
TEveTrackList * GetTrGroup(Int_t ihmul, Int_t iOpt)
Definition: CbmEvDisTracks.cxx:290
CbmTofTracklet::GetFitX
Double_t GetFitX(Double_t Z)
Definition: CbmTofTracklet.cxx:516
CbmTofTracklet::GetPoint
const Double_t * GetPoint(Int_t n)
Definition: CbmTofTracklet.cxx:494
CbmTofTracklet::GetFitPoint
const Double_t * GetFitPoint(Int_t n)
Definition: CbmTofTracklet.cxx:504
CbmEvDisTracks::MaxEnergyLimit
Double_t MaxEnergyLimit
Definition: CbmEvDisTracks.h:84
CbmTofTracklet::GetFitY
Double_t GetFitY(Double_t Z)
Definition: CbmTofTracklet.cxx:520
CbmTofTracklet::GetChiSq
Double_t GetChiSq() const
Definition: CbmTofTracklet.h:127
CbmEvDisTracks::Finish
virtual void Finish()
Definition: CbmEvDisTracks.cxx:272
pos
TVector3 pos
Definition: CbmMvdSensorDigiToHitTask.cxx:60
CbmEvDisTracks::CbmEvDisTracks
CbmEvDisTracks()
Definition: CbmEvDisTracks.cxx:41
CbmEvDisTracks::fEvePSList
TObjArray * fEvePSList
Definition: CbmEvDisTracks.h:77
CbmTofHit
Definition: core/data/tof/CbmTofHit.h:26
CbmTofTracklet::GetFitT
Double_t GetFitT(Double_t R)
Definition: CbmTofTracklet.cxx:524
CbmTofTracklet::GetTofHitPointer
CbmTofHit * GetTofHitPointer(Int_t ind)
Definition: CbmTofTracklet.h:72
CbmEvDisTracks::SetParContainers
virtual void SetParContainers()
Definition: CbmEvDisTracks.cxx:269
CbmTofTracklet::GetPidHypo
Int_t GetPidHypo() const
Definition: CbmTofTracklet.h:45