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