CbmRoot
Loading...
Searching...
No Matches
CbmLitTrackFinderBranch.cxx
Go to the documentation of this file.
1/* Copyright (C) 2007-2021 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer], Volker Friese */
4
12
13#include "data/CbmLitHit.h"
14#include "data/CbmLitTrack.h"
22#include "utils/CbmLitMath.h"
24
25#include <algorithm>
26#include <iostream>
27
28using std::make_pair;
29
31 : fHitData()
32 , fUsedHitsSet()
33 , fUsedSeedsSet()
34 , fTracks()
35 , fFilter()
36 , fSeedSelection()
37 , fFinalSelection()
38 , fPropagator()
39 , fNofStations(0)
40 , fNofIterations(0)
41 , fIteration(0)
42 , fMaxNofHitsInValidationGate(3)
43 , fMaxNofBranches(512)
44 , fMaxNofMissingHits()
45 , fPDG()
46 , fChiSqStripHitCut()
47 , fChiSqPixelHitCut()
48 , fSigmaCoef()
49{
50}
51
53
55{
56 fTracks.clear();
57 fUsedSeedsSet.clear();
58 fUsedHitsSet.clear();
60
62 // std::cout << "CbmLitTrackFinderBranch::DoFind: iteration=" << fIteration << std::endl;
63 ArrangeHits(hits.begin(), hits.end());
64 // std::cout << fHitData.ToString();
65 InitTrackSeeds(trackSeeds.begin(), trackSeeds.end());
66 FollowTracks(fTracks.begin(), fTracks.end());
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();
74 }
75
76 static Int_t eventNo = 0;
77 //std::cout << "-I- CbmLitTrackFinderBranch: " << eventNo++ << " events processed" << std::endl;
78 return kLITSUCCESS;
79}
80
82{
83 for (HitPtrIterator it = itBegin; it != itEnd; it++) {
84 CbmLitHit* hit = *it;
85 if (fUsedHitsSet.find(hit->GetRefId()) != fUsedHitsSet.end()) {
86 continue;
87 }
88 fHitData.AddHit(hit);
89 }
91}
92
94{
95 for (TrackPtrIterator it = itBegin; it != itEnd; it++) {
96 (*it)->SetQuality(kLITGOOD);
97 }
98
99 fSeedSelection->DoSelect(itBegin, itEnd);
100
101 for (TrackPtrIterator it = itBegin; it != itEnd; it++) {
102 CbmLitTrack* track = *it;
103 if (track->GetQuality() == kLITBAD) {
104 continue;
105 }
106 if (fUsedSeedsSet.find(track->GetPreviousTrackId()) != fUsedSeedsSet.end()) {
107 continue;
108 }
109 CbmLitTrack* newTrack = new CbmLitTrack(*track);
110 newTrack->SetPDG(fPDG[fIteration]);
111 newTrack->SetChi2(0.);
112 fTracks.push_back(newTrack);
113 }
114}
115
117{
118 // Loop over the track seeds
119 for (TrackPtrIterator itTrack = itBegin; itTrack != itEnd; itTrack++) {
120 CbmLitTrack* track = *itTrack;
121
122 // Vector with track branches for one input track seed
123 vector<CbmLitTrack*> branches;
124 // Initially start with one branch which is the same as track seed
125 branches.push_back(new CbmLitTrack(*track));
126
127 for (Int_t iStation = 0; iStation < fNofStations; iStation++) { // Loop over stations
128 litfloat zMin = fHitData.GetMinZPos(iStation);
129 const vector<Int_t>& bins = fHitData.GetZPosBins(iStation);
130 // map<bin index, pair<track parameter for the bin, true if track was propagated correctly >>
131 map<Int_t, pair<CbmLitTrackParam, Bool_t>> binParamMap;
132 vector<Int_t>::const_iterator itBins;
133 for (itBins = bins.begin(); itBins != bins.end(); itBins++) {
134 binParamMap[*itBins] = make_pair<CbmLitTrackParam, Bool_t>(CbmLitTrackParam(), true);
135 }
136 // Number of branches can change in the next loop turn
137 // since branches array is filled with additional track branches
138 // which were created on current station
139 Int_t nofBranches = branches.size();
140 for (Int_t iBranch = 0; iBranch < nofBranches; iBranch++) { // Loop over branches
141 CbmLitTrack* branch = branches[iBranch];
142 // Check for the missing hits
144 continue;
145 }
146
147 CbmLitTrackParam par(*branch->GetParamLast());
148 if (fPropagator->Propagate(&par, zMin, fPDG[fIteration]) == kLITERROR) {
149 break;
150 }
151
152 // Extrapolate track parameters to each Z position in the map.
153 // This is done to improve calculation speed.
154 // In case of planar station only 1 track extrapolation is required,
155 // since all hits located at the same Z.
156 map<Int_t, pair<CbmLitTrackParam, Bool_t>>::iterator itMap;
157 for (itMap = binParamMap.begin(); itMap != binParamMap.end(); itMap++) {
158 (*itMap).second.first = par;
159 litfloat z = fHitData.GetZPosByBin(iStation, (*itMap).first);
160 if (fPropagator->Propagate(&(*itMap).second.first, z, fPDG[fIteration]) == kLITERROR) {
161 (*itMap).second.second = false;
162 }
163 }
164
165 // Loop over hits
166 map<litfloat, pair<const CbmLitHit*, CbmLitTrackParam>> chiHitPar;
167 const HitPtrVector& hits = fHitData.GetHits(iStation);
168 for (HitPtrConstIterator itHit = hits.begin(); itHit != hits.end(); itHit++) {
169 const CbmLitHit* hit = *itHit;
170 Int_t bin = fHitData.GetBinByZPos(iStation, hit->GetZ());
171 assert(binParamMap.find(bin) != binParamMap.end());
172 if (!binParamMap[bin].second) continue; // Track parameters are wrong for this propagation
173 CbmLitTrackParam tpar(binParamMap[bin].first);
174
175 // Check preliminary if hit is in the validation gate.
176 // This is done in order to speed up the algorithm.
177 // Based on the predicted track position (w/o KF update step)
178 // and maximum hit position error.
179 if (hit->GetType() == kLITPIXELHIT) {
180 const CbmLitPixelHit* pixelHit = static_cast<const CbmLitPixelHit*>(hit);
181 litfloat maxErrX = fHitData.GetMaxErrX(iStation);
182 litfloat devX = fSigmaCoef[fIteration] * (sqrt(tpar.GetCovariance(0) + maxErrX * maxErrX));
183 litfloat maxErrY = fHitData.GetMaxErrY(iStation);
184 litfloat devY = fSigmaCoef[fIteration] * (sqrt(tpar.GetCovariance(6) + maxErrY * maxErrY));
185 litfloat maxErrT = fHitData.GetMaxErrT(iStation);
186 litfloat devT = fSigmaCoef[fIteration] * (sqrt(tpar.GetCovariance(20) + maxErrT * maxErrT));
187 bool hitInside = (pixelHit->GetX() < (tpar.GetX() + devX)) && (pixelHit->GetX() > (tpar.GetX() - devX))
188 && (pixelHit->GetY() < (tpar.GetY() + devY)) && (pixelHit->GetY() > (tpar.GetY() - devY))
189 && (pixelHit->GetT() < (tpar.GetTime() + devT))
190 && (pixelHit->GetT() > (tpar.GetTime() - devT));
191 if (!hitInside) continue;
192 }
193
194 litfloat chi = std::numeric_limits<litfloat>::max();
195 fFilter->Update(&tpar, hit, chi);
196 bool hitInValidationGate = (hit->GetType() == kLITPIXELHIT && chi < fChiSqPixelHitCut[fIteration])
197 || (hit->GetType() == kLITSTRIPHIT && chi < fChiSqStripHitCut[fIteration]);
198 if (hitInValidationGate) { // Check if hit is inside validation gate
199 chiHitPar[chi] = make_pair(hit, tpar);
200 }
201 }
202
203 Int_t nofHitsInValidationGate = chiHitPar.size();
204 // Check if hit was added
205 if (nofHitsInValidationGate == 1) {
206 // Only one hit added, no additional branches are created, just update branch parameters
207 const map<litfloat, pair<const CbmLitHit*, CbmLitTrackParam>>::const_iterator it = chiHitPar.begin();
208 branch->AddHit((*it).second.first);
209 branch->SetLastStationId(iStation);
210 branch->SetParamLast(&(*it).second.second);
211 branch->SetChi2(branch->GetChi2() + (*it).first);
212 branch->SetNDF(lit::NDF(branch));
213 }
214 else if (nofHitsInValidationGate > 1) {
215 // If more than one hit is in the validation gate, than create additional branches.
216 // For the first hit use the same branch.
217 Int_t counter = 0;
218 CbmLitTrack tt(*branch);
219 map<litfloat, pair<const CbmLitHit*, CbmLitTrackParam>>::const_iterator it;
220 for (it = chiHitPar.begin(); it != chiHitPar.end(); it++) {
221 // Create new branch starting with the second hit
222 CbmLitTrack* tbranch = (it != chiHitPar.begin()) ? new CbmLitTrack(tt) : branch;
223 if (it != chiHitPar.begin()) branches.push_back(tbranch);
224 tbranch->AddHit((*it).second.first);
225 tbranch->SetLastStationId(iStation);
226 tbranch->SetParamLast(&(*it).second.second);
227 tbranch->SetChi2(tbranch->GetChi2() + (*it).first);
228 tbranch->SetNDF(lit::NDF(branch));
229 counter++;
230 // Stop if number of hits in the validation gate is too high
232 // Check if number of branches exceeds the limit.
233 // Do not create additional branches in this case and continue propagation of all current branches.
234 // Use the best hit as in case of nearest neighbor tracking.
235 if (nofBranches > fMaxNofBranches) break;
236 //if (branches.size() > fMaxNofBranches) break;
237 }
238 }
239 else { // Missing hit
240 branch->SetNofMissingHits(branch->GetNofMissingHits() + 1);
241 }
242 } // Loop over branches
243 } // Loop over stations
244 // Put somewhere a cut on maximum number of branches for one input seed
245
246 // Select the best branch
247 Int_t nofBranches = branches.size();
248 if (nofBranches > 0) {
249 // Sort all branches by quality
250 CbmLitQualitySort::DoSortChiSqOverNDF(branches.begin(), branches.end());
251 // Override existing track with the best branch
252 *track = *branches.front();
253 }
254
255 // Clean branches array
256 for_each(branches.begin(), branches.end(), DeleteObject());
257 branches.clear();
258 }
259}
260
262{
263 for (TrackPtrIterator it = itBegin; it != itEnd; it++) {
264 CbmLitTrack* track = *it;
265 if (track->GetQuality() == kLITBAD) {
266 continue;
267 }
268 for (Int_t hit = 0; hit < track->GetNofHits(); hit++) {
269 fUsedHitsSet.insert(track->GetHit(hit)->GetRefId());
270 }
271 }
272}
273
275{
276 for (TrackPtrIterator it = itBegin; it != itEnd; it++) {
277 CbmLitTrack* track = *it;
278 if (track->GetQuality() == kLITBAD) {
279 continue;
280 }
281 if (!track->CheckParams()) {
282 continue;
283 }
284 fUsedSeedsSet.insert(track->GetPreviousTrackId());
285 tracks.push_back(new CbmLitTrack(*track));
286 }
287}
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.
Track reconstruction using branching method.
Interface for track fitter 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
static LitStatus DoSortChiSqOverNDF(TrackPtrIterator itBegin, TrackPtrIterator itEnd)
Sort array of tracks by quality using (chi square / NDF).
virtual ~CbmLitTrackFinderBranch()
Destructor.
void ArrangeHits(HitPtrIterator itBegin, HitPtrIterator itEnd)
void FollowTracks(TrackPtrIterator itBegin, TrackPtrIterator itEnd)
Main track following procedure.
void RemoveHits(TrackPtrIterator itBegin, TrackPtrIterator itEnd)
Write already used hits to a used hits set.
void CopyToOutput(TrackPtrIterator itBegin, TrackPtrIterator itEnd, TrackPtrVector &tracks)
Copy tracks to output array.
void InitTrackSeeds(TrackPtrIterator itBegin, TrackPtrIterator itEnd)
Initialize track seeds.
LitStatus DoFind(HitPtrVector &hits, TrackPtrVector &trackSeeds, TrackPtrVector &tracks)
Inherited from CbmLitTrackFinder.
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)