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