CbmRoot
Loading...
Searching...
No Matches
LitTrackFinderNNVecElectron.cxx
Go to the documentation of this file.
1/* Copyright (C) 2010-2012 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
12
13#include "LitDetectorGeometryElectron.h"
14#include "LitHitDataElectron.h"
15//#include "../LitTrackSelection.h"
16#include "../LitAddMaterial.h"
17#include "../LitExtrapolation.h"
18#include "../LitFieldGrid.h"
19#include "../LitFiltration.h"
20#include "../LitHit.h"
21#include "../LitMath.h"
22#include "../LitTrack.h"
23#include "../LitTypes.h"
24#include "../LitVecPack.h"
25
26#include <algorithm>
27#include <iostream>
28#include <limits>
29
30
32 : fMaxNofMissingHits(4)
33 , fSigmaCoef(5.)
34 , fMaxCovSq(20. * 20.)
35 , fChiSqPixelHitCut(15.)
36{
37}
38
40
41void lit::parallel::LitTrackFinderNNVecElectron::DoFind(const PixelHitArray& hits, const TrackArray& trackSeeds,
42 TrackArray& tracks)
43{
44 ArrangeHits(hits);
45 InitTrackSeeds(trackSeeds);
46 FollowTracks();
47
48 // DoTrackSelectionElectron(fTracks.begin(), fTracks.end());
49
50 // Copy tracks to output
51 for (unsigned int iTrack = 0; iTrack < fTracks.size(); iTrack++) {
52 LitScalTrack* track = fTracks[iTrack];
53 if (track->GetNofHits() < 2) {
54 continue;
55 }
56 if (!track->IsGood()) {
57 continue;
58 }
59 tracks.push_back(new LitScalTrack(*track));
60 }
61
62 // for (unsigned int i = 0; i < tracks.size(); i++)
63 // std::cout << *tracks[i];
64
65 for_each(fTracks.begin(), fTracks.end(), DeleteObject());
66 fTracks.clear();
67 fHitData.Clear();
68}
69
71{
72 for (unsigned int iHit = 0; iHit < hits.size(); iHit++) {
73 LitScalPixelHit* hit = hits[iHit];
74 // if (fUsedHitsSet.find(hit->GetRefId()) != fUsedHitsSet.end()) continue;
75 fHitData.AddHit(hit->planeId, hit);
76 }
77 fHitData.SortHits();
78 // std::cout << fHitData;
79}
80
82{
83 fscal QpCut = 1. / 0.1;
84 for (unsigned int iTrack = 0; iTrack < trackSeeds.size(); iTrack++) {
85 LitScalTrack* track = trackSeeds[iTrack];
86 if (fabs(track->GetParamLast().Qp) > QpCut) {
87 continue;
88 }
89 track->SetPreviousTrackId(iTrack);
90 LitScalTrack* newTrack = new LitScalTrack(*track);
91 newTrack->SetParamLast(newTrack->GetParamFirst());
92 fTracks.push_back(newTrack);
93 }
94}
95
97{
98 // Temporary arrays to store track indices from the fTracks array
99 std::vector<unsigned int> tracksId1;
100 std::vector<unsigned int> tracksId2;
101
102 // Initially use all tracks from fTracks array
103 for (unsigned int i = 0; i < fTracks.size(); i++) {
104 tracksId1.push_back(i);
105 }
106
107 //First propagate all tracks to the first station
108 unsigned int nofTracks = tracksId1.size(); // number of tracks
109 unsigned int nofTracksVec = nofTracks / fvecLen; // number of tracks grouped in vectors
110 unsigned int dTracks = nofTracks - fvecLen * nofTracksVec; // number of tracks remained after grouping in vectors
111
112 // loop over fTracks, pack data and propagate to the first station
113 for (unsigned int iTrack = 0; iTrack < nofTracksVec; iTrack++) {
114 unsigned int start = fvecLen * iTrack;
115 // Collect track group
116 LitScalTrack* tracks[fvecLen];
117 for (unsigned int i = 0; i < fvecLen; i++) {
118 tracks[i] = fTracks[tracksId1[start + i]];
119 }
120 PropagateToFirstStation(tracks);
121 } // loop over tracks
122
123 // Propagate remaining dTracks to the first station
124 if (dTracks > 0) {
125 LitScalTrack* tracks[fvecLen];
126 std::vector<LitScalTrack> dummyTracks(fvecLen - dTracks);
127 unsigned int start = fvecLen * nofTracksVec;
128 for (unsigned int i = 0; i < dTracks; i++) {
129 tracks[i] = fTracks[tracksId1[start + i]];
130 }
131 // Check if the number of remaining tracks is less than fvecLen.
132 if (dTracks < fvecLen) {
133 for (unsigned int i = 0; i < fvecLen - dTracks; i++) {
134 tracks[dTracks + i] = &dummyTracks[i];
135 } //tracks[dTracks-1];
136 }
137 PropagateToFirstStation(tracks);
138 }
139 // end propagation to the first station
140
141 // std::cout << "Propagation to the first station finished..." << std::endl;
142
143
144 // Main loop over station groups for track following
145 unsigned char nofStationGroups = fLayout.GetNofStationGroups();
146 for (unsigned char iStationGroup = 0; iStationGroup < nofStationGroups;
147 iStationGroup++) { // loop over station groups
148 const LitStationGroupElectron<fvec>& stg = fLayout.GetStationGroup(iStationGroup);
149
150 // Loop over stations, and propagate tracks from station to station
151 unsigned char nofStations = stg.GetNofStations();
152 for (unsigned char iStation = 0; iStation < nofStations; iStation++) { // loop over stations
153
154 unsigned int nofTracks = tracksId1.size(); // number of tracks
155 unsigned int nofTracksVec = nofTracks / fvecLen; // number of tracks grouped in vectors
156 unsigned int dTracks = nofTracks - fvecLen * nofTracksVec; // number of tracks remained after grouping in vectors
157 // std::cout << "iStation --> nofTracks=" << nofTracks << " nofTracksVec=" << nofTracksVec
158 // << " dTracks=" << dTracks << std::endl;
159
160 for (unsigned int iTrack = 0; iTrack < nofTracksVec; iTrack++) { // loop over tracks
161 unsigned int start = fvecLen * iTrack;
162 // Collect track group
163 LitScalTrack* tracks[fvecLen];
164 for (unsigned int i = 0; i < fvecLen; i++) {
165 tracks[i] = fTracks[tracksId1[start + i]];
166 }
167 ProcessStation(tracks, iStationGroup, iStation);
168 } // loop over tracks
169
170 // Propagate remaining dTracks
171 if (dTracks > 0) {
172 // std::cout << "Process remaining dTracks=" << dTracks << " " << (int) iStation << ":" << (int) iStationGroup << std::endl;
173 LitScalTrack* tracks[fvecLen];
174 std::vector<LitScalTrack> dummyTracks(fvecLen - dTracks);
175 unsigned int start = fvecLen * nofTracksVec;
176 for (unsigned int i = 0; i < dTracks; i++) {
177 tracks[i] = fTracks[tracksId1[start + i]];
178 }
179 // Check if the number of remaining tracks is less than fvecLen.
180 if (dTracks < fvecLen) {
181 for (unsigned int i = 0; i < fvecLen - dTracks; i++) {
182 tracks[dTracks + i] = &dummyTracks[i];
183 } //tracks[dTracks-1];
184 }
185 ProcessStation(tracks, iStationGroup, iStation);
186 }
187
188
189 // Check missing hits in each track.
190 // Propagate further only tracks which pass the cut.
191 for (unsigned int iTrack = 0; iTrack < tracksId1.size(); iTrack++) {
192 unsigned int id = tracksId1[iTrack];
193 if (fTracks[id]->GetNofMissingHits() <= fMaxNofMissingHits) {
194 tracksId2.push_back(id);
195 }
196 }
197 tracksId1.assign(tracksId2.begin(), tracksId2.end());
198 tracksId2.clear();
199 } // loop over stations
200 } // loop over station groups
201}
202
204{
205 // Pack track parameters
206 LitTrackParamScal par[fvecLen];
207 for (unsigned int i = 0; i < fvecLen; i++) {
208 par[i] = tracks[i]->GetParamLast();
209 }
210 LitTrackParamVec lpar;
211 PackTrackParam(par, lpar);
212
213 for (unsigned char ivp = 0; ivp < fLayout.GetNofVirtualPlanes() - 1; ivp++) {
214 const LitVirtualPlaneElectronVec& vp1 = fLayout.GetVirtualPlane(ivp);
215 const LitVirtualPlaneElectronVec& vp2 = fLayout.GetVirtualPlane(ivp + 1);
216
217 // lit::parallel::LitFieldValue<fvec> v1, v2, v3;
218 // vp1.GetFieldGrid().GetFieldValue(lpar.X, lpar.Y, v1);
219 // vp1.GetFieldGridMid().GetFieldValue(lpar.X, lpar.Y, v2);
220 // vp2.GetFieldGrid().GetFieldValue(lpar.X, lpar.Y, v3);
221
222 lit::parallel::LitRK4Extrapolation(lpar, vp2.GetZ(), vp1.GetFieldGrid(), vp1.GetFieldGridMid(), vp2.GetFieldGrid());
223 lit::parallel::LitAddMaterial(lpar, vp2.GetMaterial());
224 }
225
226 //lit::parallel::LitLineExtrapolation(lpar, vp2.GetZ());
227
228 // Unpack track parameters
229 UnpackTrackParam(lpar, par);
230 for (unsigned int i = 0; i < fvecLen; i++) {
231 tracks[i]->SetParamLast(par[i]);
232 }
233}
234
236 unsigned char station)
237{
238 // std::cout << "Processing station " << (int) station << ":" << (int)stationGroup << std::endl;
239 const LitStationGroupElectron<fvec>& stg = fLayout.GetStationGroup(stationGroup);
240 const LitStationElectron<fvec>& sta = stg.GetStation(station);
241
242 // Pack track parameters
243 LitTrackParamScal par[fvecLen];
244 for (unsigned int i = 0; i < fvecLen; i++) {
245 par[i] = tracks[i]->GetParamLast();
246 }
248 PackTrackParam(par, lpar);
249
250 // Propagate to station
251 LitLineExtrapolation(lpar, sta.GetZ());
252 for (unsigned char im = 0; im < sta.GetNofMaterialsBefore(); im++) {
253 LitAddMaterial(lpar, sta.GetMaterialBefore(im));
254 }
255
256 UnpackTrackParam(lpar, par);
257 for (unsigned int i = 0; i < fvecLen; i++) {
258 CollectHits(&par[i], tracks[i], stationGroup, station);
259 }
260
261 for (unsigned char im = 0; im < sta.GetNofMaterialsAfter(); im++) {
262 LitAddMaterial(lpar, sta.GetMaterialAfter(im));
263 }
264}
265
267 unsigned char stationGroup, unsigned char station)
268{
269 PixelHitConstIteratorPair hits;
270 track->SetParamLast(*par);
271
272 const std::vector<LitScalPixelHit*>& hitvec = fHitData.GetHits(stationGroup, station);
273 fscal err = fHitData.GetMaxErr(stationGroup, station);
274
275 MinMaxIndex(par, hitvec, err, hits.first, hits.second);
276 unsigned int nofHits = std::distance(hits.first, hits.second);
277
278 bool hitAdded = AddNearestHit(track, hits, nofHits, stationGroup, station);
279
280 // Check if hit was added, if not than increase number of missing hits
281 if (!hitAdded) {
282 track->IncNofMissingHits();
283 }
284}
285
287 const PixelHitConstIteratorPair& hits,
288 unsigned int nofHits, int stationGroup, int station)
289{
290 bool hitAdded = false;
291 LitScalPixelHit* hita = NULL;
292 LitTrackParamScal param;
293 fscal chiSq = std::numeric_limits<fscal>::max();
294
295 // Pack track parameters
296 LitTrackParamScal pars[fvecLen];
297 for (unsigned int i = 0; i < fvecLen; i++) {
298 pars[i] = track->GetParamLast();
299 }
301 PackTrackParam(pars, lpar);
302
303 const std::vector<LitScalPixelHit*>& hitvec = fHitData.GetHits(stationGroup, station);
304 unsigned int nofHitsVec = nofHits / fvecLen; // number of hits grouped in vectors
305 unsigned int dHits = nofHits - fvecLen * nofHitsVec; // number of hits remained after grouping in vectors
306 for (unsigned int iHit = 0; iHit < nofHitsVec; iHit++) {
307 unsigned int start = std::distance(hitvec.begin(), hits.first) + fvecLen * iHit;
308
309 // Pack hit
310 LitScalPixelHit hit[fvecLen];
311 for (unsigned int i = 0; i < fvecLen; i++) {
312 hit[i] = *hitvec[start + i];
313 }
315 PackPixelHit(hit, lhit);
316
317 LitTrackParam<fvec> ulpar = lpar;
318
319 //First update track parameters with KF, than check whether the hit is in the validation gate.
320 fvec chisq = 0;
321 LitFiltration(ulpar, lhit, chisq);
322
323 // Unpack track parameters
324 UnpackTrackParam(ulpar, pars);
325 for (unsigned int i = 0; i < fvecLen; i++) {
326 if (chisq[i] < fChiSqPixelHitCut[i] && chisq[i] < chiSq) {
327 chiSq = chisq[i];
328 hita = hitvec[start + i]; //hit[start + i];
329 param = pars[i];
330 }
331 }
332 }
333 if (dHits > 0) {
334 unsigned int start = std::distance(hitvec.begin(), hits.first) + fvecLen * nofHitsVec;
335 LitScalPixelHit hit[fvecLen];
337 LitTrackParamScal pars[fvecLen];
339 for (unsigned int i = 0; i < dHits; i++) {
340 hit[i] = *hitvec[start + i];
341 pars[i] = track->GetParamLast();
342 }
343 // Check if the number of remaining tracks is less than fvecLen.
344 if (dHits < fvecLen) {
345 for (unsigned int i = 0; i < fvecLen - dHits; i++) {
346 hit[dHits + i] = *hitvec[start + dHits - 1];
347 pars[dHits + i] = track->GetParamLast();
348 }
349 }
350 PackPixelHit(hit, lhit);
351 PackTrackParam(pars, lpar);
352
353 //First update track parameters with KF, than check whether the hit is in the validation gate.
354 fvec chisq = 0;
355 LitFiltration(lpar, lhit, chisq);
356
357 // Unpack track parameters
358 UnpackTrackParam(lpar, pars);
359 for (unsigned int i = 0; i < fvecLen; i++) {
360 if ((chisq[i] < fChiSqPixelHitCut[i]) && (chisq[i] < chiSq)) {
361 chiSq = chisq[i];
362 hita = hitvec[start + i];
363 param = pars[i];
364 }
365 }
366 }
367
368 // if hit was attached than change track information
369 if (hita != NULL) {
370 track->AddHit(hita);
371 track->SetParamLast(param);
372 track->IncChiSq(chiSq);
373 track->SetNDF(NDF(*track));
374 hitAdded = true;
375 }
376 return hitAdded;
377}
378
380 fscal maxErr, PixelHitConstIterator& first,
381 PixelHitConstIterator& last)
382{
383 first = hits.begin();
384 last = hits.begin();
385 LitScalPixelHit hit;
386 fscal C0 = par->C0;
387 if (C0 > fMaxCovSq || C0 < 0.) {
388 return;
389 }
390 fscal devX = fSigmaCoef * (std::sqrt(C0) + maxErr);
391 hit.X = par->X - devX;
392 first = std::lower_bound(hits.begin(), hits.end(), &hit, ComparePixelHitXLess());
393 hit.X = par->X + devX;
394 last = std::lower_bound(hits.begin(), hits.end(), &hit, ComparePixelHitXLess());
395}
TClonesArray * tracks
static vector< vector< QAHit > > hits
bool first
Functions for calculation of the material effects.
Functions for track parameters extrapolation.
Class stores a grid of magnetic field values in XY slice at Z position.
Useful math functions.
Parallel SIMDized implementation of TRD tracking.
Track data class.
Header files for SSE operations.
Functions to pack and unpack vector data classes.
Functor class for convenient memory release.
Definition LitUtils.h:58
Base class for pixel hits.
Definition LitPixelHit.h:35
Base class for scalar pixel hits.
Scalar track data class.
void IncChiSq(fscal dChiSq)
Increases chi square by dChiSq.
void SetPreviousTrackId(unsigned short previousTrackId)
Sets previous trackId.
const LitTrackParamScal & GetParamFirst() const
Returns first parameter of the track.
void SetNDF(unsigned short NDF)
Sets number of degrees of freedom.
unsigned short GetNofHits() const
Returns number of hits in track.
const LitTrackParamScal & GetParamLast() const
Returns last parameter of the track.
bool IsGood() const
Returns true if track is good.
void SetParamLast(const LitTrackParamScal &param)
Sets last track parameter.
void IncNofMissingHits(unsigned short dNofMissingHits=1)
Increases number of missing hits by dNofMissingHits.
void AddHit(const LitScalPixelHit *hit)
Adds hit to track.
void DoFind(const PixelHitArray &hits, const TrackArray &trackSeeds, TrackArray &tracks)
Main function for track reconstruction.
void CollectHits(LitTrackParamScal *par, LitScalTrack *track, unsigned char stationGroup, unsigned char station)
bool AddNearestHit(LitScalTrack *track, const PixelHitConstIteratorPair &hits, unsigned int nofHits, int stationGroup, int station)
void MinMaxIndex(const LitTrackParamScal *par, const PixelHitArray &hits, fscal maxErr, PixelHitConstIterator &first, PixelHitConstIterator &last)
void ProcessStation(LitScalTrack *tracks[], unsigned char stationGroup, unsigned char station)
void PackPixelHit(const LitScalPixelHit hit[], LitPixelHit< fvec > &lhit)
Packs LitPixelHit.
Definition LitVecPack.h:151
void UnpackTrackParam(const LitTrackParam< fvec > &lpar, LitTrackParam< fscal > par[])
Unpacks LitTrackParam.
Definition LitVecPack.h:83
void LitRK4Extrapolation(LitTrackParam< T > &par, T zOut, const LitFieldGrid &field1, const LitFieldGrid &field2, const LitFieldGrid &field3)
void LitFiltration(LitTrackParam< T > &par, const LitPixelHit< T > &hit, T &chiSq)
Function implements Kalman filter update step for pixel hit.
void LitLineExtrapolation(LitTrackParam< T > &par, T zOut)
Line track extrapolation for the field free regions.
void PackTrackParam(const LitTrackParam< fscal > par[], LitTrackParam< fvec > &lpar)
Packs LitTrackParam.
Definition LitVecPack.h:49
void LitAddMaterial(LitTrackParam< T > &par, T siliconThickness)
unsigned short NDF(const LitScalTrack &track)
Returns number of degrees of freedom for the track.
Definition LitMath.h:56