CbmRoot
CbmGlobalTrackFitterKF.cxx
Go to the documentation of this file.
1 // ------------------------------------------------------------------
2 // ----- CbmGlobalTrackFitterKF -----
3 // ----- Created 07/03/2006 by D.Kresan -----
4 // ------------------------------------------------------------------
6 
7 #include "CbmKFStsHit.h"
8 #include "CbmKFTrack.h"
9 #include "CbmKFTrdHit.h"
10 
11 #include "CbmGlobalTrack.h"
12 #include "CbmStsHit.h"
13 #include "CbmStsTrack.h"
14 #include "CbmTofHit.h"
15 #include "CbmTrdHit.h"
16 #include "CbmTrdTrack.h"
17 #include "CbmVertex.h"
18 #include "FairRootManager.h"
19 
20 #include "TClonesArray.h"
21 #include "TMath.h"
22 
23 #include <iostream>
24 
25 using std::cout;
26 using std::endl;
27 using std::vector;
28 
29 //___________________________________________________________________
30 //
31 // CbmGlobalTrackFitterKF
32 //
33 // Concrete implementation of global track fitting based on the
34 // Kalman filter
35 //
36 
37 
38 // ------------------------------------------------------------------
40  : fArrayStsHit(NULL)
41  , fArrayTrdHit(NULL)
42  , fArrayTofHit(NULL)
43  , fArrayStsTrack(NULL)
44  , fArrayTrdTrack(NULL)
45  , fPrimVertex(NULL)
46  , fKfTrack(NULL) {
47  // Default constructor
48 
49  fKfTrack = new CbmKFTrack();
50  // Set mass hypothesis
51  fKfTrack->SetPID(211);
52  fVerbose = 0;
53 }
54 // ------------------------------------------------------------------
55 
56 
57 // ------------------------------------------------------------------
59  // Destructor
60  delete fKfTrack;
61 }
62 // ------------------------------------------------------------------
63 
64 
65 // ------------------------------------------------------------------
67  // Initialisation
68 
69  // Get pointer to the ROOT I/O manager
70  FairRootManager* rootMgr = FairRootManager::Instance();
71  if (NULL == rootMgr) {
72  cout << "-E- CbmGlobalTrackFitterKF::Init :"
73  << " ROOT manager is not instantiated" << endl;
74  return;
75  }
76  // Get hit arrays
77  fArrayStsHit = (TClonesArray*) rootMgr->GetObject("StsHit");
78  if (NULL == fArrayStsHit) {
79  cout << "-W- CbmGlobalTrackFitterKF::Init :"
80  << " no Sts hit array" << endl;
81  }
82  fArrayTrdHit = (TClonesArray*) rootMgr->GetObject("TrdHit");
83  if (NULL == fArrayTrdHit) {
84  cout << "-W- CbmGlobalTrackFitterKF::Init :"
85  << " no TRD hit array" << endl;
86  }
87  fArrayTofHit = (TClonesArray*) rootMgr->GetObject("TofHit");
88  if (NULL == fArrayTofHit) {
89  cout << "-W- CbmGlobalTrackFitterKF::Init :"
90  << " no TOF hit array" << endl;
91  }
92  // Get track arrays
93  fArrayStsTrack = (TClonesArray*) rootMgr->GetObject("StsTrack");
94  if (NULL == fArrayStsTrack) {
95  cout << "-W- CbmGlobalTrackFitterKF::Init : "
96  << "no STS track array!" << endl;
97  }
98  fArrayTrdTrack = (TClonesArray*) rootMgr->GetObject("TrdTrack");
99  if (NULL == fArrayTrdTrack) {
100  cout << "-W- CbmGlobalTrackFitterKF::Init : "
101  << "no TRD track array!" << endl;
102  }
103 
104  // Get pointer to PrimaryVertex object from IOManager if it exists
105  // The old name for the object is "PrimaryVertex" the new one
106  // "PrimaryVertex." Check first for the new name
107  fPrimVertex = dynamic_cast<CbmVertex*>(rootMgr->GetObject("PrimaryVertex."));
108  if (nullptr == fPrimVertex) {
109  fPrimVertex = dynamic_cast<CbmVertex*>(rootMgr->GetObject("PrimaryVertex"));
110  }
111  if (nullptr == fPrimVertex) {
112  cout << "-W- CbmGlobalTrackFitterKF::Init : "
113  << "no Primary Vertex!" << endl;
114  }
115 }
116 // ------------------------------------------------------------------
117 
118 
119 // ------------------------------------------------------------------
121  // Implementation of the fitting algorithm
122  if (NULL == glbTrack || NULL == fArrayStsTrack || NULL == fArrayTrdTrack
123  || NULL == fArrayStsHit || NULL == fArrayTrdHit || NULL == fPrimVertex)
124  return;
125 
126 
127  Double_t x_old;
128  Double_t y_old;
129  Double_t z_old;
130  Double_t x_new;
131  Double_t y_new;
132  Double_t z_new;
133  Double_t z = fPrimVertex->GetZ();
134  Double_t length = 0.;
135 
136 
137  // Get STS track index
138  Int_t stsTrackIndex = glbTrack->GetStsTrackIndex();
139  if (-1 == stsTrackIndex) { return; }
140  // Get STS track
141  CbmStsTrack* stsTrack = (CbmStsTrack*) fArrayStsTrack->At(stsTrackIndex);
142  if (NULL == stsTrack) { return; }
143  const FairTrackParam* paramFirst;
144  paramFirst = stsTrack->GetParamFirst();
145  fKfTrack->SetTrackParam(*paramFirst);
146  fKfTrack->Extrapolate(z);
147  x_old = fKfTrack->GetTrack()[0];
148  y_old = fKfTrack->GetTrack()[1];
149  z_old = z;
150  Double_t p = 1.;
151  if (paramFirst->GetQp()) { p = TMath::Abs(1. / paramFirst->GetQp()); }
152 
153  // Int_t stsHitIndex;
154  // CbmStsHit* stsHit;
155  // // Loop over hits of the STS track
156  // for(Int_t iHit = 0; iHit < stsTrack->GetNStsHits(); iHit++) {
157  // // Get hit index
158  // stsHitIndex = stsTrack->GetStsHitIndex(iHit);
159  // // Get hit
160  // stsHit = (CbmStsHit*) fArrayStsHit->At(stsHitIndex);
161  // x_new = stsHit->GetX();
162  // y_new = stsHit->GetY();
163  // z_new = stsHit->GetZ();
164  // length += TMath::Sqrt(TMath::Power(x_new-x_old, 2) +
165  // TMath::Power(y_new-y_old, 2) +
166  // TMath::Power(z_new-z_old, 2));
167  // // cout << z_old << " -> " << z_new << " => " << length << endl;
168  // x_old = x_new;
169  // y_old = y_new;
170  // z_old = z_new;
171  // }
172 
173 
174  // Get TRD track index
175  Int_t trdTrackIndex = glbTrack->GetTrdTrackIndex();
176  if (-1 == trdTrackIndex) { return; }
177  // Get TRD track
178  CbmTrdTrack* trdTrack = (CbmTrdTrack*) fArrayTrdTrack->At(trdTrackIndex);
179  if (NULL == trdTrack) { return; }
180  if (trdTrack->GetNofHits() < 2) { return; }
181  Int_t trdHitIndex = trdTrack->GetHitIndex(0);
182  CbmTrdHit* trdHit = (CbmTrdHit*) fArrayTrdHit->At(trdHitIndex);
183 
184  while (z < (trdHit->GetZ() - 2.)) {
185  z += p * 1.;
186 
187  fKfTrack->Extrapolate(z);
188  x_new = fKfTrack->GetTrack()[0];
189  y_new = fKfTrack->GetTrack()[1];
190  z_new = z;
191 
192  length += TMath::Sqrt(TMath::Power(x_new - x_old, 2)
193  + TMath::Power(y_new - y_old, 2)
194  + TMath::Power(z_new - z_old, 2));
195  x_old = x_new;
196  y_old = y_new;
197  z_old = z_new;
198  }
199 
200  // Loop over hits of the TRD track
201  for (Int_t iTrd = 1; iTrd < trdTrack->GetNofHits(); iTrd++) {
202  // Get hit index
203  trdHitIndex = trdTrack->GetHitIndex(iTrd);
204  // Get hit
205  trdHit = (CbmTrdHit*) fArrayTrdHit->At(trdHitIndex);
206  z = trdHit->GetZ();
207  fKfTrack->Extrapolate(z);
208  if (trdHit->GetDx() > trdHit->GetDy()) {
209  x_new = fKfTrack->GetTrack()[0];
210  y_new = trdHit->GetY();
211  } else {
212  x_new = trdHit->GetX();
213  y_new = fKfTrack->GetTrack()[1];
214  }
215  z_new = z;
216  length += TMath::Sqrt(TMath::Power(x_new - x_old, 2)
217  + TMath::Power(y_new - y_old, 2)
218  + TMath::Power(z_new - z_old, 2));
219  x_old = x_new;
220  y_old = y_new;
221  z_old = z_new;
222  }
223 
224 
225  Int_t tofIndex = glbTrack->GetTofHitIndex();
226  if (-1 == tofIndex) { return; }
227  CbmTofHit* tofHit = (CbmTofHit*) fArrayTofHit->At(tofIndex);
228  x_new = tofHit->GetX();
229  y_new = tofHit->GetY();
230  z_new = tofHit->GetZ();
231  length +=
232  TMath::Sqrt(TMath::Power(x_new - x_old, 2) + TMath::Power(y_new - y_old, 2)
233  + TMath::Power(z_new - z_old, 2));
234 
235 
236  glbTrack->SetLength(length);
237 }
238 // ------------------------------------------------------------------
239 
240 
CbmHit::GetZ
Double_t GetZ() const
Definition: CbmHit.h:70
CbmGlobalTrackFitterKF::fPrimVertex
CbmVertex * fPrimVertex
Definition: CbmGlobalTrackFitterKF.h:23
CbmVertex.h
CbmGlobalTrackFitterKF::DoFit
void DoFit(CbmGlobalTrack *glbTrack)
Definition: CbmGlobalTrackFitterKF.cxx:120
CbmPixelHit::GetX
Double_t GetX() const
Definition: CbmPixelHit.h:83
CbmTrack::GetNofHits
virtual Int_t GetNofHits() const
Definition: CbmTrack.h:53
CbmKFStsHit.h
CbmPixelHit::GetY
Double_t GetY() const
Definition: CbmPixelHit.h:84
CbmKFTrack::SetPID
void SetPID(Int_t pidHypo)
Definition: CbmKFTrack.cxx:58
CbmPixelHit::GetDx
Double_t GetDx() const
Definition: CbmPixelHit.h:85
CbmKFTrdHit.h
rootMgr
static FairRootManager * rootMgr
Definition: CbmDeviceHitBuilderTof.cxx:72
CbmKFTrack::GetTrack
Double_t * GetTrack()
Is it electron.
Definition: CbmKFTrack.h:58
CbmTrdHit
data class for a reconstructed Energy-4D measurement in the TRD
Definition: CbmTrdHit.h:35
CbmGlobalTrackFitterKF::~CbmGlobalTrackFitterKF
virtual ~CbmGlobalTrackFitterKF()
Definition: CbmGlobalTrackFitterKF.cxx:58
CbmGlobalTrack.h
CbmGlobalTrackFitterKF::fArrayStsHit
TClonesArray * fArrayStsHit
Definition: CbmGlobalTrackFitterKF.h:18
CbmGlobalTrackFitterKF::fKfTrack
CbmKFTrack * fKfTrack
Definition: CbmGlobalTrackFitterKF.h:24
CbmGlobalTrackFitterKF::fArrayTrdHit
TClonesArray * fArrayTrdHit
Definition: CbmGlobalTrackFitterKF.h:19
CbmPixelHit::GetDy
Double_t GetDy() const
Definition: CbmPixelHit.h:86
CbmGlobalTrackFitterKF::fArrayTrdTrack
TClonesArray * fArrayTrdTrack
Definition: CbmGlobalTrackFitterKF.h:22
CbmStsTrack.h
Data class for STS tracks.
CbmGlobalTrack::GetStsTrackIndex
Int_t GetStsTrackIndex() const
Definition: CbmGlobalTrack.h:38
CbmGlobalTrack::SetLength
void SetLength(Double_t length)
Definition: CbmGlobalTrack.h:70
CbmGlobalTrackFitterKF::Init
void Init()
Definition: CbmGlobalTrackFitterKF.cxx:66
CbmGlobalTrackFitterKF::fArrayStsTrack
TClonesArray * fArrayStsTrack
Definition: CbmGlobalTrackFitterKF.h:21
CbmGlobalTrackFitterKF
Definition: CbmGlobalTrackFitterKF.h:15
ClassImp
ClassImp(CbmGlobalTrackFitterKF)
CbmTrack::GetHitIndex
Int_t GetHitIndex(Int_t iHit) const
Definition: CbmTrack.h:54
CbmGlobalTrack::GetTrdTrackIndex
Int_t GetTrdTrackIndex() const
Definition: CbmGlobalTrack.h:39
CbmVertex
Definition: CbmVertex.h:26
CbmGlobalTrackFitterKF::fArrayTofHit
TClonesArray * fArrayTofHit
Definition: CbmGlobalTrackFitterKF.h:20
CbmGlobalTrackFitter::fVerbose
Int_t fVerbose
Definition: CbmGlobalTrackFitter.h:16
CbmTrdHit.h
Class for hits in TRD detector.
CbmVertex::GetZ
Double_t GetZ() const
Definition: CbmVertex.h:70
CbmKFTrack.h
CbmTrack::GetParamFirst
const FairTrackParam * GetParamFirst() const
Definition: CbmTrack.h:61
CbmGlobalTrackFitterKF.h
CbmTrdTrack
Definition: CbmTrdTrack.h:22
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
CbmGlobalTrackFitterKF::CbmGlobalTrackFitterKF
CbmGlobalTrackFitterKF()
Definition: CbmGlobalTrackFitterKF.cxx:39
CbmTofHit
Definition: core/data/tof/CbmTofHit.h:26
CbmGlobalTrack::GetTofHitIndex
Int_t GetTofHitIndex() const
Definition: CbmGlobalTrack.h:42
CbmTrdTrack.h
CbmStsTrack
Definition: CbmStsTrack.h:37
CbmKFTrack
Definition: CbmKFTrack.h:21
CbmKFTrack::SetTrackParam
void SetTrackParam(const FairTrackParam &track)
Definition: CbmKFTrack.cxx:34
CbmStsHit.h
Data class for a reconstructed hit in the STS.
CbmKFTrackInterface::Extrapolate
Int_t Extrapolate(Double_t z, Double_t *QP0=0)
Access to i-th hit.
Definition: CbmKFTrackInterface.cxx:39