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