CbmRoot
CbmTofTrackFitterKF.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------
2 // ----- CbmTofTrackFitterKF -----
3 // ----- Created 29/11/05 by D. Kresan -----
4 // -----------------------------------------------------------------------
5 #include "CbmTofTrackFitterKF.h"
6 
7 #include "CbmKFTofHit.h"
8 #include "CbmKFTrack.h"
9 
10 #include "CbmTofHit.h"
11 #include "CbmTofTracklet.h"
12 #include "FairLogger.h"
13 #include "FairRootManager.h"
14 
15 #include "TClonesArray.h"
16 
17 #include <iostream>
18 #include <vector>
19 
20 using std::cout;
21 using std::endl;
22 using std::vector;
23 
24 //________________________________________________________________________
25 //
26 // CbmTofTrackFitterKF
27 //
28 // Concrete implementation of the TOF track fitter based on Kalman filter
29 //
30 
31 // -----------------------------------------------------------------------
33  : fArrayTofHit(0), fVerbose(1), fPid(211), fKfTrack(0) {
34  fKfTrack = new CbmKFTrack();
35 }
36 // -----------------------------------------------------------------------
37 
38 // -----------------------------------------------------------------------
40  : fArrayTofHit(0), fVerbose(verbose), fPid(pid), fKfTrack(0) {
41  // Standard constructor
42  fArrayTofHit = NULL;
43  fVerbose = verbose;
44  fPid = pid;
45  fKfTrack = new CbmKFTrack();
46 }
47 // -----------------------------------------------------------------------
48 
49 
50 // -----------------------------------------------------------------------
52  // Destructor
53  delete fKfTrack;
54 }
55 // -----------------------------------------------------------------------
56 
57 
58 // -----------------------------------------------------------------------
60  // Initialisation
61 
62  // Get the pointer to FairRootManager
63  FairRootManager* rootMgr = FairRootManager::Instance();
64  if (NULL == rootMgr) {
65  cout << "-E- CbmTofTrackFitterKF::Init : "
66  << " ROOT manager is not instantiated!" << endl;
67  return;
68  }
69 
70  // Activate data branches
71  fArrayTofHit = (TClonesArray*) rootMgr->GetObject("TofHit");
72  if (NULL == fArrayTofHit) {
73  cout << "-E- CbmTofTrackFitterKF::Init : "
74  << " no TOF hit array!" << endl;
75  return;
76  }
77  // cout << Form("<D> TrackFitterKF::Init: ArrayTofHit at 0x%08x ",fArrayTofHit) <<endl;
78 }
79 // -----------------------------------------------------------------------
80 
81 
82 // -----------------------------------------------------------------------
84  LOG(debug1) << "CbmTofTrackFitterKF::DoFit starting ";
85  // Implementation of the fitting algorithm
86  if (NULL == fArrayTofHit) this->Init();
87 
88  if (NULL == fArrayTofHit) {
89  LOG(error) << "CbmTofTrackFitterKF::DoFit No fArrayTofHit ";
90  return 1;
91  }
92  // Declare variables outside the loop
93  CbmTofHit* pHit = NULL;
94  CbmKFTofHit* pKFHit = NULL;
95  Int_t hitIndex = 0;
96  Int_t materialIndex = 0;
97 
98  // Loop over TOF hits of the track
99  for (Int_t iHit = 0; iHit < pTrack->GetNofHits(); iHit++) {
100  // Get current hit index
101  hitIndex = pTrack->GetHitIndex(iHit);
102  //Get the pointer to the CbmTofHit
103  pHit = (CbmTofHit*) fArrayTofHit->At(hitIndex);
104  if (NULL == pHit) {
105  cout << "-E- CbmTofTrackFitterKF::DoFit : "
106  << " empty TOF hit : " << hitIndex << ", " << pHit << endl;
107  return 1;
108  }
109 
110  // Create CbmKFTofHit
111  pKFHit = new CbmKFTofHit();
112  pKFHit->Create(pHit);
113  materialIndex = pKFHit->MaterialIndex;
114  // Add to the KFTrack
115  fKfTrack->fHits.push_back(pKFHit);
116 
117  LOG(debug) << " TOF hit : (" << pHit->GetX() << ", " << pHit->GetY()
118  << ", " << pHit->GetZ() << ") "
119  << " is added to track. matidx=" << materialIndex;
120 
121  } // Loop over TOF hits end
122  Double_t qpini = 0.1; // FIXME: avoid constants in code
123  fKfTrack->GetRefChi2() = 0.;
124  fKfTrack->GetRefNDF() = 0;
125  FairTrackParam* pParam = (FairTrackParam*) (pTrack->GetParamLast());
126  pParam->SetQp(qpini);
128  *(const_cast<FairTrackParam*>(pTrack->GetParamLast())));
129  fKfTrack->SetPID(fPid);
130  /*
131  fKfTrack->Fit(0); // what does this do???, up/downstream flag
132  fKfTrack->Fit(1);
133  */
134  fKfTrack->Fit(0);
135  // Store parameters at first layer
137  *(const_cast<FairTrackParam*>(pTrack->GetParamFirst())));
138  if (fVerbose > 2) { pTrack->GetParamFirst()->Print(); }
139  fKfTrack->Fit(1);
140  // Store parameters at last layer
142  *(const_cast<FairTrackParam*>(pTrack->GetParamLast())));
143  if (fVerbose > 2) { pTrack->GetParamLast()->Print(); }
144 
145  // Store chi2 of fit
146  pTrack->SetChiSq(fKfTrack->GetRefChi2());
147  pTrack->SetNDF(fKfTrack->GetRefNDF());
148 
149  // Delete CbmKFTofHit objects
150  vector<CbmKFHit*>::iterator it;
151  for (it = fKfTrack->fHits.begin(); it != fKfTrack->fHits.end(); it++) {
152  pKFHit = (CbmKFTofHit*) (*it);
153  delete pKFHit;
154  }
155  fKfTrack->fHits.clear();
156 
157  LOG(debug) << "CbmTofTrackFitterKF::DoFit: TOF track fitted. chi2/ndf = "
158  << pTrack->GetChiSq() / pTrack->GetNDF();
159  if (fVerbose > 2) { cout << endl << endl; }
160 
161  return 0;
162 }
163 // -----------------------------------------------------------------------
164 // -----------------------------------------------------------------------
165 Int_t CbmTofTrackFitterKF::DoFit(CbmTofTrack* /*pTrack*/) { return 0; }
166 
167 void CbmTofTrackFitterKF::Extrapolate(const FairTrackParam* track,
168  Double_t z,
169  FairTrackParam* e_track) {
170  if (!track) return;
171  CbmKFTrack T;
172  T.SetTrackParam(*track);
173  T.Extrapolate(z);
174  if (e_track) T.GetTrackParam(*e_track);
175 }
176 
177 /*
178 void CbmTofTrackFitterKF::Extrapolate( CbmTofTracklet* track, Double_t z, FairTrackParam* e_track )
179 {
180  if( !track ) return;
181  CbmKFTrack T;
182  T.SetPID( track->GetPidHypo() );
183  const FairTrackParam *fpar = track->GetParamFirst(), *lpar = track->GetParamLast();
184 
185  if( z<=fpar->GetZ() ){ // extrapolate first parameters
186  T.SetTrackParam( *fpar );
187  T.Extrapolate( z );
188  }else if( z<fpar->GetZ()+0.1 ){ // extrapolate first parameters
189  T.SetTrackParam( *fpar );
190  T.Propagate( z );
191  }else if( lpar->GetZ()<=z ){ // extrapolate last parameters
192  T.SetTrackParam( *lpar );
193  T.Extrapolate( z );
194  }else if( lpar->GetZ()-0.1<z ){ // extrapolate last parameters
195  T.SetTrackParam( *lpar );
196  T.Propagate( z );
197  }else { // refit with smoother
198  SetKFHits( T, track);
199  T.SetTrackParam( *fpar );
200  T.Smooth( z );
201  }
202  if( e_track ) T.GetTrackParam( *e_track );
203 }
204 */
205 
207 
208  T.fHits.clear();
209  /*
210  Int_t NTofHits = ( fArrayTofHit ) ?track->GetNofHits() :0;
211 
212  fHits.resize( NTofHits );
213 
214  if( NTofHits>0 && fArrayTofHit ){
215  for (Int_t i=0; i<NTofHits;i++){
216  Int_t j = track->GetHitIndex(i);
217  fHits[i].Create( reinterpret_cast<CbmTofHit*>(fArrayTofHit->At(j)) );
218  T.fHits.push_back(&(fHits[i]));
219  }
220  }
221  */
222 }
223 
CbmHit::GetZ
Double_t GetZ() const
Definition: CbmHit.h:70
CbmTofTrackFitterKF::fPid
Int_t fPid
Definition: CbmTofTrackFitterKF.h:21
CbmTofTrackFitterKF
Definition: CbmTofTrackFitterKF.h:16
CbmPixelHit::GetX
Double_t GetX() const
Definition: CbmPixelHit.h:83
CbmTofTracklet::GetHitIndex
Int_t GetHitIndex(Int_t ind) const
Definition: CbmTofTracklet.h:51
CbmTofTracklet::GetNofHits
Int_t GetNofHits() const
Definition: CbmTofTracklet.h:48
CbmPixelHit::GetY
Double_t GetY() const
Definition: CbmPixelHit.h:84
CbmTofTracklet::SetChiSq
void SetChiSq(Double_t chiSq)
Definition: CbmTofTracklet.h:247
CbmKFTrack::SetPID
void SetPID(Int_t pidHypo)
Definition: CbmKFTrack.cxx:58
rootMgr
static FairRootManager * rootMgr
Definition: CbmDeviceHitBuilderTof.cxx:72
CbmKFTrack::GetTrackParam
void GetTrackParam(FairTrackParam &track)
Definition: CbmKFTrack.cxx:45
CbmTofTracklet
Provides information on attaching a TofHit to a TofTrack.
Definition: CbmTofTracklet.h:25
CbmTofTrackFitterKF.h
CbmTofTracklet::GetParamFirst
const FairTrackParam * GetParamFirst() const
Definition: CbmTofTracklet.h:130
CbmTofTrackFitterKF::CbmTofTrackFitterKF
CbmTofTrackFitterKF()
Definition: CbmTofTrackFitterKF.cxx:32
CbmTofTracklet.h
CbmKFTrack::GetRefChi2
Double_t & GetRefChi2()
array[15] of covariance matrix
Definition: CbmKFTrack.h:60
CbmKFTrack::GetRefNDF
Int_t & GetRefNDF()
Chi^2 after fit.
Definition: CbmKFTrack.h:61
CbmKFHit::MaterialIndex
Int_t MaterialIndex
Definition: CbmKFHit.h:22
CbmTofTracklet::GetNDF
Int_t GetNDF() const
Definition: CbmTofTracklet.h:128
CbmKFTrack.h
CbmKFTofHit
Definition: CbmKFTofHit.h:23
CbmTofTrackFitterKF::DoFit
Int_t DoFit(CbmTofTracklet *pTrack)
Definition: CbmTofTrackFitterKF.cxx:83
CbmTofTrackFitterKF::Extrapolate
void Extrapolate(const FairTrackParam *trackPar, Double_t z, FairTrackParam *e_track)
Definition: CbmTofTrackFitterKF.cxx:167
CbmKFTofHit::Create
void Create(CbmTofHit *hit)
Definition: CbmKFTofHit.cxx:23
CbmTofTrackFitterKF::SetKFHits
void SetKFHits(CbmKFTrack &T, CbmTofTracklet *track)
Definition: CbmTofTrackFitterKF.cxx:206
CbmTofTrackFitterKF::fArrayTofHit
TClonesArray * fArrayTofHit
Definition: CbmTofTrackFitterKF.h:19
CbmTofTracklet::GetParamLast
const FairTrackParam * GetParamLast() const
Definition: CbmTofTracklet.h:131
CbmKFTofHit.h
CbmTofTracklet::GetChiSq
Double_t GetChiSq() const
Definition: CbmTofTracklet.h:127
CbmTofTrackFitterKF::fKfTrack
CbmKFTrack * fKfTrack
Definition: CbmTofTrackFitterKF.h:22
CbmTofTrackFitterKF::Init
void Init()
Definition: CbmTofTrackFitterKF.cxx:59
ClassImp
ClassImp(CbmTofTrackFitterKF)
CbmTofHit
Definition: core/data/tof/CbmTofHit.h:26
CbmKFTrack
Definition: CbmKFTrack.h:21
CbmKFTrackInterface::Fit
Int_t Fit(Bool_t downstream=1)
Definition: CbmKFTrackInterface.cxx:101
CbmTofTrackFitterKF::fVerbose
Int_t fVerbose
Definition: CbmTofTrackFitterKF.h:20
CbmKFTrack::SetTrackParam
void SetTrackParam(const FairTrackParam &track)
Definition: CbmKFTrack.cxx:34
CbmTofTracklet::SetNDF
void SetNDF(Int_t ndf)
Definition: CbmTofTracklet.h:248
CbmKFTrack::fHits
std::vector< CbmKFHit * > fHits
Definition: CbmKFTrack.h:29
CbmTofTrack
Provides information on attaching a TofHit to a GlobalTrack.
Definition: CbmTofTrack.h:20
CbmTofTrackFitterKF::~CbmTofTrackFitterKF
virtual ~CbmTofTrackFitterKF()
Definition: CbmTofTrackFitterKF.cxx:51
CbmKFTrackInterface::Extrapolate
Int_t Extrapolate(Double_t z, Double_t *QP0=0)
Access to i-th hit.
Definition: CbmKFTrackInterface.cxx:39