CbmRoot
CbmTrdTrackFitterKF.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------
2 // ----- CbmTrdTrackFitterKF -----
3 // ----- Created 29/11/05 by D. Kresan -----
4 // -----------------------------------------------------------------------
5 #include "CbmTrdTrackFitterKF.h"
6 
7 #include "CbmKFTrack.h"
8 #include "CbmKFTrdHit.h"
9 
10 #include "CbmTrdHit.h"
11 #include "CbmTrdTrack.h"
12 #include "FairRootManager.h"
13 
14 #include "TClonesArray.h"
15 
16 #include <iostream>
17 #include <vector>
18 
19 using std::cout;
20 using std::endl;
21 using std::vector;
22 
23 //________________________________________________________________________
24 //
25 // CbmTrdTrackFitterKF
26 //
27 // Concrete implementation of the TRD track fitter based on Kalman filter
28 //
29 
30 
31 // -----------------------------------------------------------------------
33  : fArrayTrdHit(0), fVerbose(1), fPid(211), fKfTrack(0) {
34  fKfTrack = new CbmKFTrack();
35 }
36 // -----------------------------------------------------------------------
37 
38 
39 // -----------------------------------------------------------------------
41  : fArrayTrdHit(0), fVerbose(verbose), fPid(pid), fKfTrack(0) {
42  // Standard constructor
43  fArrayTrdHit = NULL;
44  fVerbose = verbose;
45  fPid = pid;
46  fKfTrack = new CbmKFTrack();
47 }
48 // -----------------------------------------------------------------------
49 
50 
51 // -----------------------------------------------------------------------
53  // Destructor
54  delete fKfTrack;
55 }
56 // -----------------------------------------------------------------------
57 
58 
59 // -----------------------------------------------------------------------
61  // Initialisation
62 
63  // Get the pointer to FairRootManager
64  FairRootManager* rootMgr = FairRootManager::Instance();
65  if (NULL == rootMgr) {
66  cout << "-E- CbmTrdTrackFitterKF::Init : "
67  << " ROOT manager is not instantiated!" << endl;
68  return;
69  }
70 
71  // Activate data branches
72  fArrayTrdHit = (TClonesArray*) rootMgr->GetObject("TrdHit");
73  if (NULL == fArrayTrdHit) {
74  cout << "-E- CbmTrdTrackFitterKF::Init : "
75  << " no TRD hit array!" << endl;
76  return;
77  }
78 }
79 // -----------------------------------------------------------------------
80 
81 
82 // -----------------------------------------------------------------------
84  // Implementation of the fitting algorithm
85  if (NULL == fArrayTrdHit) return 1;
86 
87  // Declare variables outside the loop
88  CbmTrdHit* pHit = NULL;
89  CbmKFTrdHit* pKFHit = NULL;
90  Int_t hitIndex = 0;
91  Int_t materialIndex = 0;
92  Double_t eLoss = 0.;
93 
94  // Loop over TRD hits of the track
95  for (Int_t iHit = 0; iHit < pTrack->GetNofHits(); iHit++) {
96  // Get current hit index
97  hitIndex = pTrack->GetHitIndex(iHit);
98  //Get the pointer to the CbmTrdHit
99  pHit = (CbmTrdHit*) fArrayTrdHit->At(hitIndex);
100  if (NULL == pHit) {
101  cout << "-E- CbmTrdTrackFitterKF::DoFit : "
102  << " empty TRD hit : " << hitIndex << ", " << pHit << endl;
103  return 1;
104  }
105  // Accumulate TR energy loss
106  eLoss += pHit->GetELoss();
107  // Create CbmKFTrdHit
108  pKFHit = new CbmKFTrdHit();
109  pKFHit->Create(pHit);
110  materialIndex = pKFHit->MaterialIndex;
111  // Add to the KFTrack
112  fKfTrack->fHits.push_back(pKFHit);
113  if (fVerbose > 2) {
114  cout << " TRD hit : (" << pHit->GetX() << ", " << pHit->GetY() << ", "
115  << pHit->GetZ() << ") "
116  << " is added to track. matidx=" << materialIndex << endl;
117  }
118  } // Loop over TRD hits
119 
120  fKfTrack->GetRefChi2() = 0.;
121  fKfTrack->GetRefNDF() = 0;
123  *(const_cast<FairTrackParam*>(pTrack->GetParamLast())));
124  fKfTrack->SetPID(fPid);
125 
126  fKfTrack->Fit(0);
127  fKfTrack->Fit(1);
128  fKfTrack->Fit(0);
129  // Store parameters at first layer
131  *(const_cast<FairTrackParam*>(pTrack->GetParamFirst())));
132  if (fVerbose > 2) {
133  // pTrack->GetParamFirst()->Print();
134  }
135  fKfTrack->Fit(1);
136  // Store parameters at last layer
138  *(const_cast<FairTrackParam*>(pTrack->GetParamLast())));
139  if (fVerbose > 2) {
140  // pTrack->GetParamLast()->Print();
141  }
142 
143  // Store chi2 of fit
144  pTrack->SetChiSq(fKfTrack->GetRefChi2());
145  pTrack->SetNDF(fKfTrack->GetRefNDF());
146 
147  // Store accumulated TR energy loss
148  pTrack->SetELoss(eLoss);
149 
150  // Delete CbmKFTrdHit objects
151  vector<CbmKFHit*>::iterator it;
152  for (it = fKfTrack->fHits.begin(); it != fKfTrack->fHits.end(); it++) {
153  pKFHit = (CbmKFTrdHit*) (*it);
154  delete pKFHit;
155  }
156  fKfTrack->fHits.clear();
157 
158  if (fVerbose > 1) {
159  cout << "TRD track fitted. chi2/ndf = "
160  << pTrack->GetChiSq() / pTrack->GetNDF() << endl;
161  if (fVerbose > 2) { cout << endl << endl; }
162  }
163 
164  return 0;
165 }
166 // -----------------------------------------------------------------------
167 
168 
CbmHit::GetZ
Double_t GetZ() const
Definition: CbmHit.h:70
CbmTrack::GetChiSq
Double_t GetChiSq() const
Definition: CbmTrack.h:58
CbmTrack::GetParamLast
const FairTrackParam * GetParamLast() const
Definition: CbmTrack.h:62
CbmTrdTrackFitterKF::fVerbose
Int_t fVerbose
Definition: CbmTrdTrackFitterKF.h:19
CbmTrdTrackFitterKF::CbmTrdTrackFitterKF
CbmTrdTrackFitterKF()
Definition: CbmTrdTrackFitterKF.cxx:32
CbmPixelHit::GetX
Double_t GetX() const
Definition: CbmPixelHit.h:83
CbmTrdTrackFitterKF::DoFit
Int_t DoFit(CbmTrdTrack *pTrack)
Definition: CbmTrdTrackFitterKF.cxx:83
CbmTrack::GetNofHits
virtual Int_t GetNofHits() const
Definition: CbmTrack.h:53
CbmTrdTrackFitterKF::fArrayTrdHit
TClonesArray * fArrayTrdHit
Definition: CbmTrdTrackFitterKF.h:18
CbmPixelHit::GetY
Double_t GetY() const
Definition: CbmPixelHit.h:84
CbmKFTrack::SetPID
void SetPID(Int_t pidHypo)
Definition: CbmKFTrack.cxx:58
CbmTrdHit::GetELoss
Double_t GetELoss() const
Definition: CbmTrdHit.h:79
CbmTrdTrackFitterKF
Definition: CbmTrdTrackFitterKF.h:15
CbmKFTrdHit.h
rootMgr
static FairRootManager * rootMgr
Definition: CbmDeviceHitBuilderTof.cxx:72
CbmKFTrack::GetTrackParam
void GetTrackParam(FairTrackParam &track)
Definition: CbmKFTrack.cxx:45
CbmTrdHit
data class for a reconstructed Energy-4D measurement in the TRD
Definition: CbmTrdHit.h:35
CbmTrdTrackFitterKF.h
CbmTrack::SetNDF
void SetNDF(Int_t ndf)
Definition: CbmTrack.h:71
CbmKFTrack::GetRefChi2
Double_t & GetRefChi2()
array[15] of covariance matrix
Definition: CbmKFTrack.h:60
CbmTrdTrackFitterKF::~CbmTrdTrackFitterKF
virtual ~CbmTrdTrackFitterKF()
Definition: CbmTrdTrackFitterKF.cxx:52
CbmKFTrack::GetRefNDF
Int_t & GetRefNDF()
Chi^2 after fit.
Definition: CbmKFTrack.h:61
CbmKFHit::MaterialIndex
Int_t MaterialIndex
Definition: CbmKFHit.h:22
CbmTrack::GetHitIndex
Int_t GetHitIndex(Int_t iHit) const
Definition: CbmTrack.h:54
CbmKFTrdHit::Create
void Create(CbmTrdHit *hit)
Definition: CbmKFTrdHit.cxx:23
CbmTrack::SetChiSq
void SetChiSq(Double_t chiSq)
Definition: CbmTrack.h:70
CbmTrack::GetNDF
Int_t GetNDF() const
Definition: CbmTrack.h:59
CbmTrdHit.h
Class for hits in TRD detector.
CbmKFTrack.h
CbmTrdTrackFitterKF::Init
void Init()
Definition: CbmTrdTrackFitterKF.cxx:60
CbmTrack::GetParamFirst
const FairTrackParam * GetParamFirst() const
Definition: CbmTrack.h:61
CbmTrdTrackFitterKF::fPid
Int_t fPid
Definition: CbmTrdTrackFitterKF.h:20
ClassImp
ClassImp(CbmTrdTrackFitterKF)
CbmTrdTrack
Definition: CbmTrdTrack.h:22
CbmTrdTrack::SetELoss
void SetELoss(Double_t eLoss)
Definition: CbmTrdTrack.h:43
CbmTrdTrackFitterKF::fKfTrack
CbmKFTrack * fKfTrack
Definition: CbmTrdTrackFitterKF.h:21
CbmTrdTrack.h
CbmKFTrdHit
Definition: CbmKFTrdHit.h:23
CbmKFTrack
Definition: CbmKFTrack.h:21
CbmKFTrackInterface::Fit
Int_t Fit(Bool_t downstream=1)
Definition: CbmKFTrackInterface.cxx:101
CbmKFTrack::SetTrackParam
void SetTrackParam(const FairTrackParam &track)
Definition: CbmKFTrack.cxx:34
CbmKFTrack::fHits
std::vector< CbmKFHit * > fHits
Definition: CbmKFTrack.h:29