CbmRoot
CbmLitTrackFinderNN.cxx
Go to the documentation of this file.
1 
8 
9 #include "data/CbmLitHit.h"
10 #include "data/CbmLitPixelHit.h"
11 #include "data/CbmLitTrack.h"
12 #include "data/CbmLitTrackParam.h"
16 #include "utils/CbmLitMath.h"
18 
19 #include <algorithm>
20 #include <cmath>
21 #include <iostream>
22 #include <limits>
23 #include <map>
24 #include <set>
25 
26 using std::make_pair;
27 using std::map;
28 using std::set;
29 using std::sqrt;
30 
32  : fTracks()
33  , fFilter()
34  , fSeedSelection()
35  , fFinalSelection()
36  , fPropagator()
37  , fNofStations(0)
38  , fNofIterations(0)
39  , fIteration(0)
40  , fHitData()
41  , fUsedHitsSet()
42  , fUsedSeedsSet()
43  , fMaxNofMissingHits()
44  , fPDG()
45  , fChiSqStripHitCut()
46  , fChiSqPixelHitCut()
47  , fSigmaCoef() {}
48 
50 
52  TrackPtrVector& trackSeeds,
54  fTracks.clear();
55  fUsedSeedsSet.clear();
56  fUsedHitsSet.clear();
58 
60  // std::cout << "CbmLitTrackFinderNN::DoFind: iteration=" << fIteration << std::endl;
61  ArrangeHits(hits.begin(), hits.end());
62  // std::cout << fHitData.ToString();
63 
64  InitTrackSeeds(trackSeeds.begin(), trackSeeds.end());
65  FollowTracks(fTracks.begin(), fTracks.end());
66 
67  fFinalSelection->DoSelect(fTracks.begin(), fTracks.end());
68  RemoveHits(fTracks.begin(), fTracks.end());
69  CopyToOutput(fTracks.begin(), fTracks.end(), tracks);
70 
71  for_each(fTracks.begin(), fTracks.end(), DeleteObject());
72  fTracks.clear();
73  fHitData.Clear();
74  }
75 
76  //std::cout << "tracks.size()=" << tracks.size() << std::endl;
77  //for (Int_t i = 0; i < tracks.size(); i++) {
78  // std::cout << i << " " << tracks[i]->ToString();
79  //}
80 
81  static Int_t eventNo = 0;
82  std::cout << "CbmLitTrackFinderNN::DoFind: " << eventNo++
83  << " events processed" << std::endl;
84  return kLITSUCCESS;
85 }
86 
88  HitPtrIterator itEnd) {
89  for (HitPtrIterator it = itBegin; it != itEnd; it++) {
90  CbmLitHit* hit = *it;
91  if (fUsedHitsSet.find(hit->GetRefId()) != fUsedHitsSet.end()) {
92  continue;
93  } // FIXME Check if it works correctly for MUCH-TRD
94  fHitData.AddHit(hit);
95  }
96  fHitData.Arrange();
97 }
98 
100  TrackPtrIterator itEnd) {
101  for (TrackPtrIterator it = itBegin; it != itEnd; it++) {
102  (*it)->SetQuality(kLITGOOD);
103  }
104 
105  fSeedSelection->DoSelect(itBegin, itEnd);
106 
107  for (TrackPtrIterator it = itBegin; it != itEnd; it++) {
108  CbmLitTrack* track = *it;
109  if (track->GetQuality() == kLITBAD) { continue; }
110  if (fUsedSeedsSet.find(track->GetPreviousTrackId())
111  != fUsedSeedsSet.end()) {
112  continue;
113  }
114  track->SetPDG(fPDG[fIteration]);
115  track->SetChi2(0.);
116  fTracks.push_back(new CbmLitTrack(*track));
117  }
118 }
119 
121  TrackPtrIterator itEnd) {
122  for (TrackPtrIterator itTrack = itBegin; itTrack != itEnd; itTrack++) {
123  CbmLitTrack* track = *itTrack;
124 
125  for (Int_t iStation = 0; iStation < fNofStations; iStation++) {
126  CbmLitTrackParam par(*track->GetParamLast());
127 
128  litfloat zMin = fHitData.GetMinZPos(iStation);
129  if (fPropagator->Propagate(&par, zMin, fPDG[fIteration]) == kLITERROR) {
130  break;
131  }
132 
133  const vector<Int_t>& bins = fHitData.GetZPosBins(iStation);
134  // map<bin index, pair<track parameter for the bin, true if track was propagated correctly >>
135  map<Int_t, pair<CbmLitTrackParam, Bool_t>> binParamMap;
136  vector<Int_t>::const_iterator itBins;
137  for (itBins = bins.begin(); itBins != bins.end(); itBins++) {
138  binParamMap[*itBins] =
139  make_pair<CbmLitTrackParam, Bool_t>(CbmLitTrackParam(), true);
140  }
141 
142  // Extrapolate track parameters to each Z position in the map.
143  // This is done to improve calculation speed.
144  // In case of planar station only 1 track extrapolation is required,
145  // since all hits located at the same Z.
146  map<Int_t, pair<CbmLitTrackParam, Bool_t>>::iterator itMap;
147  for (itMap = binParamMap.begin(); itMap != binParamMap.end(); itMap++) {
148  (*itMap).second.first = par;
149  litfloat z = fHitData.GetZPosByBin(iStation, (*itMap).first);
150  if (fPropagator->Propagate(&(*itMap).second.first, z, fPDG[fIteration])
151  == kLITERROR) {
152  (*itMap).second.second = false;
153  }
154  }
155 
156  // Loop over hits
157  litfloat minChiSq =
158  std::numeric_limits<litfloat>::max(); // minimum chi-square of hit
159  const CbmLitHit* minHit = NULL; // Pointer to hit with minimum chi-square
160  CbmLitTrackParam minPar; // Track parameters for closest hit
161  const HitPtrVector& hits = fHitData.GetHits(iStation);
162  for (HitPtrConstIterator itHit = hits.begin(); itHit != hits.end();
163  itHit++) {
164  const CbmLitHit* hit = *itHit;
165  Int_t bin = fHitData.GetBinByZPos(iStation, hit->GetZ());
166  assert(binParamMap.find(bin) != binParamMap.end());
167  if (!binParamMap[bin].second)
168  continue; // Track parameters are wrong for this propagation
169  CbmLitTrackParam tpar(binParamMap[bin].first);
170 
171  // Check preliminary if hit is in the validation gate.
172  // This is done in order to speed up the algorithm.
173  // Based on the predicted track position (w/o KF update step)
174  // and maximum hit position error.
175  if (hit->GetType() == kLITPIXELHIT) {
176  const CbmLitPixelHit* pixelHit =
177  static_cast<const CbmLitPixelHit*>(hit);
178  litfloat maxErrX = fHitData.GetMaxErrX(iStation);
180  * (sqrt(tpar.GetCovariance(0) + maxErrX * maxErrX));
181  litfloat maxErrY = fHitData.GetMaxErrY(iStation);
183  * (sqrt(tpar.GetCovariance(6) + maxErrY * maxErrY));
184  litfloat maxErrT = fHitData.GetMaxErrT(iStation);
186  * (sqrt(tpar.GetCovariance(20) + maxErrT * maxErrT));
187  bool hitInside = (pixelHit->GetX() < (tpar.GetX() + devX))
188  && (pixelHit->GetX() > (tpar.GetX() - devX))
189  && (pixelHit->GetY() < (tpar.GetY() + devY))
190  && (pixelHit->GetY() > (tpar.GetY() - devY))
191  && (pixelHit->GetT() < (tpar.GetTime() + devT))
192  && (pixelHit->GetT() > (tpar.GetTime() - devT));
193  if (!hitInside) continue;
194  }
195 
197  fFilter->Update(&tpar, hit, chi);
198  bool hitInValidationGate = (hit->GetType() == kLITPIXELHIT
199  && chi < fChiSqPixelHitCut[fIteration])
200  || (hit->GetType() == kLITSTRIPHIT
201  && chi < fChiSqStripHitCut[fIteration]);
202  if (
203  hitInValidationGate
204  && chi
205  < minChiSq) { // Check if hit is inside validation gate and closer to the track.
206  minChiSq = chi;
207  minHit = hit;
208  minPar = tpar;
209  }
210  }
211 
212  if (minHit != NULL) { // Check if hit was added
213  track->AddHit(minHit);
214  track->SetLastStationId(iStation);
215  track->SetParamLast(&minPar);
216  track->SetChi2(track->GetChi2() + minChiSq);
217  track->SetNDF(lit::NDF(track));
218  } else { // Missing hit
219  track->SetNofMissingHits(track->GetNofMissingHits() + 1);
221  break;
222  }
223  }
224  }
225  }
226 }
227 
229  TrackPtrIterator itEnd) {
230  for (TrackPtrIterator it = itBegin; it != itEnd; it++) {
231  CbmLitTrack* track = *it;
232  if (track->GetQuality() == kLITBAD) { continue; }
233  for (Int_t hit = 0; hit < track->GetNofHits(); hit++) {
234  fUsedHitsSet.insert(track->GetHit(hit)->GetRefId());
235  }
236  }
237 }
238 
240  TrackPtrIterator itEnd,
242  for (TrackPtrIterator it = itBegin; it != itEnd; it++) {
243  CbmLitTrack* track = *it;
244  if (track->GetQuality() == kLITBAD) { continue; }
245  if (!track->CheckParams()) { continue; }
246  fUsedSeedsSet.insert(track->GetPreviousTrackId());
247  tracks.push_back(new CbmLitTrack(*track));
248  }
249 }
CbmLitHit::GetT
litfloat GetT() const
Definition: CbmLitHit.h:50
CbmLitTrackParam.h
Data class for track parameters.
CbmLitTrackFinderNN::fTracks
TrackPtrVector fTracks
Definition: CbmLitTrackFinderNN.h:104
CbmLitHitData::Arrange
void Arrange()
Must be called after all hits are added.
Definition: CbmLitHitData.cxx:120
litfloat
double litfloat
Definition: CbmLitFloat.h:15
CbmLitTrackFinderNN::DoFind
virtual LitStatus DoFind(HitPtrVector &hits, TrackPtrVector &trackSeeds, TrackPtrVector &tracks)
Inherited from CbmLitTrackFinder.
Definition: CbmLitTrackFinderNN.cxx:51
CbmLitTrackFinderNN::fFilter
TrackUpdatePtr fFilter
Definition: CbmLitTrackFinderNN.h:112
fPropagator
TrackPropagatorPtr fPropagator
Definition: CbmGlobalTrackingTof.cxx:19
CbmLitTrackFinderNN::RemoveHits
void RemoveHits(TrackPtrIterator itBegin, TrackPtrIterator itEnd)
Write already used hits to a used hits set.
Definition: CbmLitTrackFinderNN.cxx:228
kLITGOOD
@ kLITGOOD
Definition: CbmLitEnums.h:32
CbmLitMemoryManagment.h
CbmLitHitData::GetZPosByBin
litfloat GetZPosByBin(Int_t station, Int_t bin) const
Return Z positions of hit.
Definition: CbmLitHitData.cxx:96
CbmLitTrackFinderNN::ArrangeHits
void ArrangeHits(HitPtrIterator itBegin, HitPtrIterator itEnd)
Definition: CbmLitTrackFinderNN.cxx:87
CbmLitTrackParam::GetX
litfloat GetX() const
Definition: CbmLitTrackParam.h:53
CbmLitTrackFinderNN::fUsedHitsSet
std::set< Int_t > fUsedHitsSet
Definition: CbmLitTrackFinderNN.h:106
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
CbmLitTrack::SetNofMissingHits
void SetNofMissingHits(Int_t nofMissingHits)
Definition: CbmLitTrack.h:87
CbmLitHit::GetZ
litfloat GetZ() const
Definition: CbmLitHit.h:48
CbmLitTrackParam
Data class for track parameters.
Definition: CbmLitTrackParam.h:29
CbmLitTrack::GetChi2
litfloat GetChi2() const
Definition: CbmLitTrack.h:58
CbmLitTrackSelection.h
Interface for track selection algorithm.
CbmLitTrackFinderNN::fHitData
CbmLitHitData fHitData
Definition: CbmLitTrackFinderNN.h:105
CbmLitTrackParam::GetY
litfloat GetY() const
Definition: CbmLitTrackParam.h:54
CbmLitTrackFinderNN::fMaxNofMissingHits
vector< Int_t > fMaxNofMissingHits
Definition: CbmLitTrackFinderNN.h:119
CbmLitHit::GetRefId
Int_t GetRefId() const
Definition: CbmLitHit.h:46
CbmLitTrackFinderNN::fNofIterations
Int_t fNofIterations
Definition: CbmLitTrackFinderNN.h:115
CbmLitTrackParam::GetCovariance
litfloat GetCovariance(int index) const
Definition: CbmLitTrackParam.h:60
CbmLitPixelHit.h
Base data class for pixel hits.
fFilter
TrackUpdatePtr fFilter
Definition: CbmGlobalTrackingTof.cxx:21
CbmLitTrackUpdate.h
Interface for track update algorithm.
CbmLitHitData::Clear
void Clear()
Clear array of hits.
Definition: CbmLitHitData.cxx:108
CbmLitTrackFinderNN::CbmLitTrackFinderNN
CbmLitTrackFinderNN()
Constructor.
Definition: CbmLitTrackFinderNN.cxx:31
CbmLitTrack::SetParamLast
void SetParamLast(const CbmLitTrackParam *par)
Definition: CbmLitTrack.h:82
kLITSUCCESS
@ kLITSUCCESS
Definition: CbmLitEnums.h:24
DeleteObject
Definition: CbmLitMemoryManagment.h:5
CbmLitHitData::GetMaxErrY
litfloat GetMaxErrY(Int_t station) const
Definition: CbmLitHitData.cxx:78
CbmLitTrackFinderNN::FollowTracks
void FollowTracks(TrackPtrIterator itBegin, TrackPtrIterator itEnd)
Follow tracks through detector.
Definition: CbmLitTrackFinderNN.cxx:120
CbmLitTrack::SetPDG
void SetPDG(Int_t pdg)
Definition: CbmLitTrack.h:80
CbmLitTrack::SetNDF
void SetNDF(Int_t ndf)
Definition: CbmLitTrack.h:78
CbmLitTrack::SetLastStationId
void SetLastStationId(Int_t lastPlaneId)
Definition: CbmLitTrack.h:85
TrackPtrIterator
std::vector< CbmTofTrack * >::iterator TrackPtrIterator
Definition: CbmTofTypes.h:21
CbmLitPixelHit::GetY
litfloat GetY() const
Definition: CbmLitPixelHit.h:38
lit::NDF
Int_t NDF(const CbmLitTrack *track)
Definition: CbmLitMath.cxx:79
CbmLitHitData::GetZPosBins
const vector< Int_t > & GetZPosBins(Int_t station) const
Return bin numbers for Z positions of hits.
Definition: CbmLitHitData.cxx:92
CbmLitTrack::GetPreviousTrackId
Int_t GetPreviousTrackId() const
Definition: CbmLitTrack.h:60
TrackPtrVector
std::vector< CbmTofTrack * > TrackPtrVector
Definition: CbmTofTypes.h:22
CbmLitHit
Base data class for hits.
Definition: CbmLitHit.h:26
tracks
TClonesArray * tracks
Definition: Analyze_matching.h:17
HitPtrIterator
std::vector< CbmTofHit * >::iterator HitPtrIterator
Definition: CbmTofTypes.h:17
kLITSTRIPHIT
@ kLITSTRIPHIT
Definition: CbmLitEnums.h:15
CbmLitMath.h
CbmLitTrackPropagator.h
CbmLitTrackFinderNN::fPDG
vector< Int_t > fPDG
Definition: CbmLitTrackFinderNN.h:120
kLITERROR
@ kLITERROR
Definition: CbmLitEnums.h:25
CbmLitTrack
Base data class for track.
Definition: CbmLitTrack.h:30
CbmLitPixelHit
Base data class for pixel hits.
Definition: CbmLitPixelHit.h:22
kLITPIXELHIT
@ kLITPIXELHIT
Definition: CbmLitEnums.h:16
kLITBAD
@ kLITBAD
Definition: CbmLitEnums.h:33
CbmLitTrackFinderNN::CopyToOutput
void CopyToOutput(TrackPtrIterator itBegin, TrackPtrIterator itEnd, TrackPtrVector &tracks)
Copy tracks to output array.
Definition: CbmLitTrackFinderNN.cxx:239
first
bool first
Definition: LKFMinuit.cxx:143
CbmLitTrack::GetParamLast
const CbmLitTrackParam * GetParamLast() const
Definition: CbmLitTrack.h:63
CbmLitTrackFinderNN::fSigmaCoef
vector< litfloat > fSigmaCoef
Definition: CbmLitTrackFinderNN.h:124
CbmLitTrackFinderNN::fFinalSelection
TrackSelectionPtr fFinalSelection
Definition: CbmLitTrackFinderNN.h:110
CbmLitTrackFinderNN::fPropagator
TrackPropagatorPtr fPropagator
Definition: CbmLitTrackFinderNN.h:111
CbmLitTrack::CheckParams
Bool_t CheckParams() const
Return true if track parameters are correct.
Definition: CbmLitTrack.h:127
CbmLitPixelHit::GetX
litfloat GetX() const
Definition: CbmLitPixelHit.h:37
CbmLitTrackFinderNN::fIteration
Int_t fIteration
Definition: CbmLitTrackFinderNN.h:116
CbmLitHitData::GetHits
const HitPtrVector & GetHits(Int_t station)
Return array of hits.
Definition: CbmLitHitData.cxx:66
CbmLitHitData::GetBinByZPos
Int_t GetBinByZPos(Int_t station, litfloat zPos) const
Return bin number for hit Z position.
Definition: CbmLitHitData.cxx:100
CbmLitTrackFinderNN::~CbmLitTrackFinderNN
virtual ~CbmLitTrackFinderNN()
Destructor.
Definition: CbmLitTrackFinderNN.cxx:49
CbmLitTrackFinderNN::fNofStations
Int_t fNofStations
Definition: CbmLitTrackFinderNN.h:114
CbmLitTrack.h
Base data class for track.
hits
static vector< vector< QAHit > > hits
Definition: CbmTofHitFinderTBQA.cxx:114
CbmLitHitData::GetMaxErrT
litfloat GetMaxErrT(Int_t station) const
Definition: CbmLitHitData.cxx:82
CbmLitHitData::AddHit
void AddHit(CbmLitHit *hit)
Add hit.
Definition: CbmLitHitData.cxx:44
CbmLitTrack::GetNofMissingHits
Int_t GetNofMissingHits() const
Definition: CbmLitTrack.h:71
CbmLitTrackFinderNN::InitTrackSeeds
void InitTrackSeeds(TrackPtrIterator itBegin, TrackPtrIterator itEnd)
Initialize track seeds and copy to local array.
Definition: CbmLitTrackFinderNN.cxx:99
CbmLitTrackFinderNN::fSeedSelection
TrackSelectionPtr fSeedSelection
Definition: CbmLitTrackFinderNN.h:109
HitPtrConstIterator
std::vector< CbmTofHit * >::const_iterator HitPtrConstIterator
Definition: CbmTofTypes.h:19
CbmLitTrackFinderNN::fUsedSeedsSet
std::set< Int_t > fUsedSeedsSet
Definition: CbmLitTrackFinderNN.h:107
LitStatus
LitStatus
Definition: CbmLitEnums.h:23
CbmLitTrackParam::GetTime
litfloat GetTime() const
Definition: CbmLitTrackParam.h:59
max
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:36
CbmLitTrack::GetQuality
LitTrackQa GetQuality() const
Definition: CbmLitTrack.h:57
CbmLitTrack::GetHit
const CbmLitHit * GetHit(Int_t index) const
Definition: CbmLitTrack.h:65
CbmLitHit::GetType
LitHitType GetType() const
Definition: CbmLitHit.h:47
CbmLitTrack::AddHit
void AddHit(const CbmLitHit *hit)
Add hit to track. No additional memory is allocated for hit.
Definition: CbmLitTrack.h:96
CbmLitTrackFinderNN::fChiSqPixelHitCut
vector< litfloat > fChiSqPixelHitCut
Definition: CbmLitTrackFinderNN.h:122
CbmLitHitData::GetMinZPos
litfloat GetMinZPos(Int_t station) const
Return minimum Z position of hits.
Definition: CbmLitHitData.cxx:104
CbmLitHit.h
Base data class for hits.
CbmLitTrack::SetChi2
void SetChi2(litfloat chi2)
Definition: CbmLitTrack.h:77
CbmLitTrack::GetNofHits
Int_t GetNofHits() const
Definition: CbmLitTrack.h:56
CbmLitTrackFinderNN::fChiSqStripHitCut
vector< litfloat > fChiSqStripHitCut
Definition: CbmLitTrackFinderNN.h:121
CbmLitTrackFinderNN.h
Implementation of nearest neighbor tracking algorithm.
HitPtrVector
std::vector< CbmTofHit * > HitPtrVector
Definition: CbmTofTypes.h:14
CbmLitHitData::GetMaxErrX
litfloat GetMaxErrX(Int_t station) const
Definition: CbmLitHitData.cxx:74
CbmLitHitData::SetNofStations
void SetNofStations(Int_t nofStations)
Set number of stations.
Definition: CbmLitHitData.cxx:28