CbmRoot
CbmGlobalTrackingTask.cxx
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 
8 #include "CbmGlobalTrack.h"
10 #include "CbmKFStsHit.h"
11 #include "CbmMvdHit.h"
12 #include "CbmStsCluster.h"
13 #include "CbmStsHit.h"
14 #include "CbmStsTrack.h"
15 #include "FairLogger.h"
16 #include "TH1F.h"
17 
18 #include <iostream>
19 
20 #define CBM_GLOBALTB_PRINT_PERF
21 
22 #ifdef CBM_GLOBALTB_PRINT_PERF
23 #ifdef __MACH__
24 #include <mach/mach_time.h>
25 #include <sys/time.h>
26 #ifndef CLOCK_REALTIME
27 #define CLOCK_REALTIME 0
28 #endif
29 #ifndef CLOCK_MONOTONIC
30 #define CLOCK_MONOTONIC 0
31 #endif
32 inline int clock_gettime(int /*clk_id*/, struct timespec* t) {
33  mach_timebase_info_data_t timebase;
34  mach_timebase_info(&timebase);
35  uint64_t time;
36  time = mach_absolute_time();
37  double nseconds =
38  ((double) time * (double) timebase.numer) / ((double) timebase.denom);
39  double seconds =
40  ((double) time * (double) timebase.numer) / ((double) timebase.denom * 1e9);
41  t->tv_sec = seconds;
42  t->tv_nsec = nseconds;
43  return 0;
44 }
45 #else
46 #include <time.h>
47 #endif
48 #endif //CBM_GLOBALTB_PRINT_PERF
49 
50 using std::cout;
51 using std::endl;
52 using std::list;
53 using std::map;
54 using std::set;
55 using std::vector;
56 
58  : fTofGeometry()
59  , fTimeSlice(0)
60  , fTofHits(0)
61  , fStsTracks(0)
62  , fStsHits(0)
63  , fMvdHits(0)
64  , fGlobalTracks(0)
65  , fKFTrack()
66  , fPrimVertex(0) {}
67 
69  fKFTrack.SetPID(211);
70 
71  if (!fTofGeometry.Read())
72  LOG(fatal) << "Could not read the ToF geometry information";
73 
74  FairRootManager* ioman = FairRootManager::Instance();
75 
76  if (0 == ioman) LOG(fatal) << "No FairRootManager";
77 
78  fTimeSlice = static_cast<CbmTimeSlice*>(ioman->GetObject("TimeSlice."));
79 
80  if (0 == fTimeSlice) LOG(fatal) << "No time slice";
81 
82  fTofHits = static_cast<TClonesArray*>(ioman->GetObject("TofHit"));
83 
84  if (0 == fTofHits) LOG(fatal) << "No ToF hits";
85 
87 
88  fStsTracks = static_cast<TClonesArray*>(ioman->GetObject("StsTrack"));
89 
90  if (0 == fStsTracks) LOG(fatal) << "No STS tracks";
91 
92  fStsHits = static_cast<TClonesArray*>(ioman->GetObject("StsHit"));
93 
94  if (0 == fStsHits) LOG(fatal) << "No STS hits";
95 
96  fMvdHits = static_cast<TClonesArray*>(ioman->GetObject("MvdHit"));
97  //fPrimVertex = static_cast<CbmVertex*> (ioman->GetObject("PrimaryVertex"));
98  // Get pointer to PrimaryVertex object from IOManager if it exists
99  // The old name for the object is "PrimaryVertex" the new one
100  // "PrimaryVertex." Check first for the new name
101  fPrimVertex = dynamic_cast<CbmVertex*>(ioman->GetObject("PrimaryVertex."));
102  if (nullptr == fPrimVertex) {
103  fPrimVertex = dynamic_cast<CbmVertex*>(ioman->GetObject("PrimaryVertex"));
104  }
105  if (nullptr == fPrimVertex) { LOG(fatal) << "No primary vertex"; }
106 
107  fGlobalTracks = new TClonesArray("CbmGlobalTrack", 100);
108  ioman->Register("GlobalTrack",
109  "Global",
111  IsOutputBranchPersistent("GlobalTrack"));
112 
113  return kSUCCESS;
114 }
115 
116 #ifdef CBM_GLOBALTB_PRINT_PERF
117 static long fullDuration = 0;
118 #endif //CBM_GLOBALTB_PRINT_PERF
119 
120 void CbmGlobalTrackingTask::Exec(Option_t* /*opt*/) {
121  fGlobalTracks->Clear();
122  Double_t startTime = fTimeSlice->GetStartTime();
123  fTofGeometry.Prepare(startTime);
124  int nofStsTracks = fStsTracks->GetEntriesFast();
125 
126  for (int i = 0; i < nofStsTracks; ++i) {
127  const CbmStsTrack* track =
128  static_cast<const CbmStsTrack*>(fStsTracks->At(i));
129  CbmGlobalTrack* globalTrack = new ((*fGlobalTracks)[i]) CbmGlobalTrack();
130  globalTrack->SetStsTrackIndex(i);
131  Int_t tofHitInd;
132  Double_t stsTrackLength = CalcStsTrackLength(track);
133  Double_t trackLength = stsTrackLength;
134  FairTrackParam param = *track->GetParamLast();
135 #ifdef CBM_GLOBALTB_PRINT_PERF
136  timespec ts;
137  clock_gettime(CLOCK_REALTIME, &ts);
138  long beginTime = ts.tv_sec * 1000000000 + ts.tv_nsec;
139 #endif //CBM_GLOBALTB_PRINT_PERF
140  //fTofGeometry.Find(param->GetX(), param->GetCovariance(0, 0), param->GetY(), param->GetCovariance(1, 1), param->GetZ(),
141  //track->GetTime(), track->GetTimeError(), param->GetTx(), TMath::Sqrt(param->GetCovariance(2, 2)), param->GetTy(), TMath::Sqrt(param->GetCovariance(3, 3)), tofHitInd);
143  param, track->GetTime(), track->GetTimeError(), tofHitInd, trackLength);
144  globalTrack->SetTofHitIndex(tofHitInd);
145  globalTrack->SetLength(stsTrackLength + trackLength);
146  globalTrack->SetParamFirst(track->GetParamFirst());
147  globalTrack->SetParamLast(&param);
148 
149  if (fPrimVertex) {
150  FairTrackParam vtxTrackParam;
151  float chiSqPrimary = 0;
153  track, fPrimVertex, &vtxTrackParam, chiSqPrimary);
154  globalTrack->SetParamPrimaryVertex(&vtxTrackParam);
155  }
156 #ifdef CBM_GLOBALTB_PRINT_PERF
157  clock_gettime(CLOCK_REALTIME, &ts);
158  long endTime = ts.tv_sec * 1000000000 + ts.tv_nsec;
159  fullDuration += endTime - beginTime;
160 #endif //CBM_GLOBALTB_PRINT_PERF
161  } //for (int i = 0; i < nofStsTracks; ++i)
162 }
163 
164 extern int nofMRPCIntersections;
165 extern int nofToFIntersections;
166 extern int nofMRPCIntersectionsT;
167 extern int globalNofHits;
168 extern int globalNofHitsT;
169 extern int globalNofHitsM;
170 
172  cout << "nofMRPCIntersections: " << nofMRPCIntersections << endl;
173  cout << "nofToFIntersections: " << nofToFIntersections << endl;
174  cout << "nofMRPCIntersectionsT: " << nofMRPCIntersectionsT << endl;
175  cout << "globalNofHits: " << globalNofHits << endl;
176  cout << "globalNofHitsT: " << globalNofHitsT << endl;
177  cout << "globalNofHitsM: " << globalNofHitsM << endl << endl << endl;
178  cout << "Full merging duration was: " << fullDuration << endl << endl << endl;
179 }
180 
182  Double_t length = 0;
183  Double_t* T = fKFTrack.GetTrack();
184  Double_t zVert = fPrimVertex ? fPrimVertex->GetZ() : 0;
185  const FairTrackParam* paramFirst = track->GetParamFirst();
186  Double_t x = paramFirst->GetX();
187  Double_t y = paramFirst->GetY();
188  Double_t z = paramFirst->GetZ();
189  Double_t p = paramFirst->GetQp() ? TMath::Abs(1 / paramFirst->GetQp()) : 1;
190  fKFTrack.SetTrackParam(*paramFirst);
191 
192  while (z > zVert) {
193  Double_t xOld = x;
194  Double_t yOld = y;
195  Double_t zOld = z;
196 
197  if (z - p > zVert)
198  z -= p;
199  else
200  z = zVert;
201 
203  x = T[0];
204  y = T[1];
205  length += TMath::Sqrt(TMath::Power(x - xOld, 2) + TMath::Power(y - yOld, 2)
206  + TMath::Power(z - zOld, 2));
207  }
208 
209  x = paramFirst->GetX();
210  y = paramFirst->GetY();
211  z = paramFirst->GetZ();
212 
213  const FairTrackParam* paramLast = track->GetParamLast();
214  int nofHits = track->GetNofHits();
215 
216  for (int i = 1; i < nofHits; ++i) {
217  Int_t hitInd = track->GetHitIndex(i);
218  HitType hitType = track->GetHitType(i);
219  CbmPixelHit* hit = static_cast<CbmPixelHit*>(
220  kMVDHIT == hitType ? fMvdHits->At(hitInd) : fStsHits->At(hitInd));
221  // Double_t nextX; (VF) not used
222  // Double_t nextY; (VF) not used
223  Double_t nextZ;
224 
225  if (i == nofHits - 1) {
226  // nextX = paramLast->GetX(); (VF) not used
227  // nextY = paramLast->GetY(); (VF) not used
228  nextZ = paramLast->GetZ();
229  } else {
230  // nextX = hit->GetX(); (VF) not used
231  // nextY = hit->GetY(); (VF) not used
232  nextZ = hit->GetZ();
233  }
234 
235  while (z < nextZ) {
236  Double_t xOld = x;
237  Double_t yOld = y;
238  Double_t zOld = z;
239 
240  if (z + p < nextZ)
241  z += p;
242  else
243  z = nextZ;
244 
246 
247  if (z == nextZ) {
248  CbmKFStsHit stsKFHit;
249 
250  if (kMVDHIT == hitType)
251  stsKFHit.Create(static_cast<CbmMvdHit*>(hit));
252  else
253  stsKFHit.Create(static_cast<CbmStsHit*>(hit));
254 
255  Double_t qp0 = T[4];
256  stsKFHit.Filter(fKFTrack, kTRUE, qp0);
257  }
258 
259  x = T[0];
260  y = T[1];
261  length +=
262  TMath::Sqrt(TMath::Power(x - xOld, 2) + TMath::Power(y - yOld, 2)
263  + TMath::Power(z - zOld, 2));
264  }
265  }
266 
267  return length;
268 }
269 
CbmHit::GetZ
Double_t GetZ() const
Definition: CbmHit.h:70
globalNofHits
int globalNofHits
Definition: CbmGlobalTrackingTof.cxx:790
CbmTrack::GetParamLast
const FairTrackParam * GetParamLast() const
Definition: CbmTrack.h:62
CbmGlobalTrackingTask::Finish
void Finish()
Definition: CbmGlobalTrackingTask.cxx:171
CbmKFStsHit
Definition: CbmKFStsHit.h:11
CbmKFStsHit::Filter
Int_t Filter(CbmKFTrackInterface &track, Bool_t downstream, Double_t &QP0)
Definition: CbmKFStsHit.cxx:82
CbmKFStsHit.h
kMVDHIT
@ kMVDHIT
Definition: CbmHit.h:21
CbmKFTrack::SetPID
void SetPID(Int_t pidHypo)
Definition: CbmKFTrack.cxx:58
CbmGlobalTrackingTask::CbmGlobalTrackingTask
CbmGlobalTrackingTask()
Definition: CbmGlobalTrackingTask.cxx:57
CbmGlobalTrack::SetParamLast
void SetParamLast(const FairTrackParam *parLast)
Definition: CbmGlobalTrack.h:62
CbmKFTrack::GetTrack
Double_t * GetTrack()
Is it electron.
Definition: CbmKFTrack.h:58
CbmGlobalTrackingTask::fTimeSlice
CbmTimeSlice * fTimeSlice
Definition: CbmGlobalTrackingTask.h:49
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
globalNofHitsT
int globalNofHitsT
Definition: CbmGlobalTrackingTof.cxx:791
CbmGlobalTrackingTask::CalcStsTrackLength
Double_t CalcStsTrackLength(const CbmStsTrack *track)
Definition: CbmGlobalTrackingTask.cxx:181
CbmGlobalTrack.h
globalNofHitsM
int globalNofHitsM
Definition: CbmGlobalTrackingTof.cxx:792
CbmGlobalTrackingTask::fTofGeometry
CbmGlobalTrackingTofGeometry fTofGeometry
Definition: CbmGlobalTrackingTask.h:48
CbmTimeSlice::GetStartTime
Double_t GetStartTime() const
Definition: CbmTimeSlice.h:108
CbmStsTrack::GetNofHits
virtual Int_t GetNofHits() const
Definition: CbmStsTrack.h:76
CbmMvdHit
Definition: CbmMvdHit.h:29
CbmKFStsHit::Create
void Create(CbmStsHit *h)
Definition: CbmKFStsHit.cxx:20
CbmStsHit
data class for a reconstructed 3-d hit in the STS
Definition: CbmStsHit.h:31
CbmGlobalTrackingTask::fTofHits
TClonesArray * fTofHits
Definition: CbmGlobalTrackingTask.h:50
CbmStsTrack.h
Data class for STS tracks.
CbmGlobalTrack::SetStsTrackIndex
void SetStsTrackIndex(Int_t iSts)
Definition: CbmGlobalTrack.h:54
CbmGlobalTrack::SetLength
void SetLength(Double_t length)
Definition: CbmGlobalTrack.h:70
CbmGlobalTrackingTask::fKFTrack
CbmKFTrack fKFTrack
Definition: CbmGlobalTrackingTask.h:55
fullDuration
static long fullDuration
Definition: CbmGlobalTrackingTask.cxx:117
HitType
HitType
Definition: CbmHit.h:16
CbmGlobalTrackingTofGeometry::Read
bool Read()
Definition: CbmGlobalTrackingTof.cxx:607
CbmTrack::GetHitIndex
Int_t GetHitIndex(Int_t iHit) const
Definition: CbmTrack.h:54
CbmVertex
Definition: CbmVertex.h:26
CbmVertex::GetZ
Double_t GetZ() const
Definition: CbmVertex.h:70
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmGlobalTrack::SetParamPrimaryVertex
void SetParamPrimaryVertex(const FairTrackParam *parPV)
Definition: CbmGlobalTrack.h:63
CbmKFParticleInterface.h
CbmGlobalTrackingTask::fStsHits
TClonesArray * fStsHits
Definition: CbmGlobalTrackingTask.h:52
CbmGlobalTrackingTofGeometry::Find
void Find(FairTrackParam &trackParams, timetype trackTime, timetype errT, Int_t &tofHitInd, Double_t &length)
Definition: CbmGlobalTrackingTof.cxx:860
CbmTrack::GetHitType
HitType GetHitType(Int_t iHit) const
Definition: CbmTrack.h:55
CbmTrack::GetParamFirst
const FairTrackParam * GetParamFirst() const
Definition: CbmTrack.h:61
CbmGlobalTrackingTask::Init
InitStatus Init()
Definition: CbmGlobalTrackingTask.cxx:68
nofMRPCIntersectionsT
int nofMRPCIntersectionsT
Definition: CbmGlobalTrackingTof.cxx:858
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
CbmGlobalTrack::SetParamFirst
void SetParamFirst(const FairTrackParam *parFirst)
Definition: CbmGlobalTrack.h:59
CbmKFParticleInterface::ExtrapolateTrackToPV
static void ExtrapolateTrackToPV(const CbmStsTrack *track, CbmVertex *pv, FairTrackParam *paramAtPV, float &chiPrim)
Definition: CbmKFParticleInterface.cxx:153
CbmTimeSlice
Bookkeeping of time-slice content.
Definition: CbmTimeSlice.h:29
CbmGlobalTrackingTofGeometry::SetTofHits
void SetTofHits(TClonesArray *v)
Definition: CbmGlobalTrackingTof.h:109
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmGlobalTrackingTask::fMvdHits
TClonesArray * fMvdHits
Definition: CbmGlobalTrackingTask.h:53
CbmMvdHit.h
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmGlobalTrackingTask.h
CbmGlobalTrackingTofGeometry::Prepare
void Prepare(timetype startTime)
Definition: CbmGlobalTrackingTof.cxx:794
CbmPixelHit
Definition: CbmPixelHit.h:21
CbmTrack::GetTime
Double_t GetTime() const
Definition: CbmTrack.h:64
CbmGlobalTrackingTask::fPrimVertex
CbmVertex * fPrimVertex
Definition: CbmGlobalTrackingTask.h:56
CbmGlobalTrack::SetTofHitIndex
void SetTofHitIndex(Int_t iTofHit)
Definition: CbmGlobalTrack.h:58
CbmGlobalTrackingTask::fGlobalTracks
TClonesArray * fGlobalTracks
Definition: CbmGlobalTrackingTask.h:54
CbmStsCluster.h
Data class for STS clusters.
nofToFIntersections
int nofToFIntersections
Definition: CbmGlobalTrackingTof.cxx:857
nofMRPCIntersections
int nofMRPCIntersections
Definition: CbmGlobalTrackingTof.cxx:856
CbmStsTrack
Definition: CbmStsTrack.h:37
CbmGlobalTrackingTask::Exec
void Exec(Option_t *opt)
Definition: CbmGlobalTrackingTask.cxx:120
CbmTrack::GetTimeError
Double_t GetTimeError() const
Definition: CbmTrack.h:65
CbmKFTrack::SetTrackParam
void SetTrackParam(const FairTrackParam &track)
Definition: CbmKFTrack.cxx:34
CbmGlobalTrackingTask::fStsTracks
TClonesArray * fStsTracks
Definition: CbmGlobalTrackingTask.h:51
CbmStsHit.h
Data class for a reconstructed hit in the STS.
CbmGlobalTrackingTask
Definition: CbmGlobalTrackingTask.h:25
CbmKFTrackInterface::Extrapolate
Int_t Extrapolate(Double_t z, Double_t *QP0=0)
Access to i-th hit.
Definition: CbmKFTrackInterface.cxx:39