L1Algo.h 22.4 KB
Newer Older
1
2
/* Copyright (C) 2007-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
   SPDX-License-Identifier: GPL-3.0-only
Administrator's avatar
Administrator committed
3
   Authors: Maksym Zyzak, Valentina Akishina, Igor Kulakov */
4

5
#ifndef L1Algo_h
Sergey Gorbunov's avatar
Sergey Gorbunov committed
6
#define L1Algo_h
7
8
9

// #define TBB // TODO: Doesn't work now. Renew

Administrator's avatar
Administrator committed
10
/// Debug features
11
12
13
// #define PULLS            // triplets pulls
// #define TRIP_PERFORMANCE // triplets efficiencies
// #define DOUB_PERFORMANCE // doublets efficiencies
Sergey Gorbunov's avatar
Sergey Gorbunov committed
14
// #define DRAW             // event display
15
16
17
18
19
20
21
#ifdef DRAW
class L1AlgoDraw;
#include "CbmL1Track.h"
#endif
//#define XXX               // time debug
//#define COUNTERS          // diff counters (hits, doublets, ... )

22
#define MERGE_CLONES
23
24
25
26
27
28
29
// #define TRACKS_FROM_TRIPLETS_ITERATION kAllPrimIter

//#define HitErrors
//#define GLOBAL
//#define mCBM

#define LAST_ITERATION kAllSecIter
Administrator's avatar
Administrator committed
30
#define FIND_GAPED_TRACKS  // use triplets with gaps
31
32
33
34
35
36
#define USE_RL_TABLE
#ifndef TRACKS_FROM_TRIPLETS
#define EXTEND_TRACKS
#endif
//#define USE_EVENT_NUMBER
//#endif
37
//#define MERGE_CLONES
38
39


40
41
42
43
#include <iomanip>
#include <iostream>
#include <map>

Administrator's avatar
Administrator committed
44
#include "L1Branch.h"
45
#include "L1Field.h"
46
#include "L1Grid.h"
Sergey Gorbunov's avatar
Sergey Gorbunov committed
47
#include "L1Hit.h"
48
49
50
#include "L1HitPoint.h"
#include "L1HitsSortHelper.h"
#include "L1Portion.h"
51
52
53
54
#include "L1Station.h"
#include "L1Track.h"
#include "L1TrackPar.h"
#include "L1TrackParFit.h"
Administrator's avatar
Administrator committed
55
#include "L1Triplet.h"
Sergey Gorbunov's avatar
Sergey Gorbunov committed
56
#include "L1Vector.h"
57
58
59
60
61
62
63
64
65
66
67
68

#ifdef _OPENMP
#include "omp.h"
#endif

using std::map;

#ifdef PULLS
#define TRIP_PERFORMANCE
class L1AlgoPulls;
#endif
#ifdef TRIP_PERFORMANCE
Administrator's avatar
Administrator committed
69
70
template<Tindex NHits>
class L1AlgoEfficiencyPerformance;
71
72
#endif
#ifdef DOUB_PERFORMANCE
Administrator's avatar
Administrator committed
73
74
template<Tindex NHits>
class L1AlgoEfficiencyPerformance;
75
76
77
78
#endif
typedef int Tindex;


Administrator's avatar
Administrator committed
79
80
class L1Algo {
public:
Sergey Gorbunov's avatar
Sergey Gorbunov committed
81
  L1Algo(int nThreads = 1);
Administrator's avatar
Administrator committed
82

83
84
  L1Algo(const L1Algo&) = delete;
  L1Algo operator=(const L1Algo&) = delete;
Administrator's avatar
Administrator committed
85

86
87
88
89
90
91
92
93
94
95
96
  /// set a default particle mass for the track fit
  /// it is used during reconstruction
  /// for the multiple scattering and energy loss estimation
  void SetDefaultParticleMass(float mass) { fDefaultMass = mass; }

  /// get default particle mass
  float GetDefaultParticleMass() const { return fDefaultMass; }

  /// get default particle mass squared
  float GetDefaultParticleMass2() const { return fDefaultMass * fDefaultMass; }

Sergey Gorbunov's avatar
Sergey Gorbunov committed
97
98
  static const int kMaxNthreads = 1;
  static const int nSta         = 25;
99

100
101
  float fDefaultMass = 0.10565800;  // muon mass

Sergey Gorbunov's avatar
Sergey Gorbunov committed
102
  L1Vector<L1Triplet> fTriplets[nSta][kMaxNthreads] {{"L1Algo::fTriplets"}};  // created triplets at station + thread
103

Sergey Gorbunov's avatar
Sergey Gorbunov committed
104
105
  // Track candidates created out of adjacent triplets before the final track selection.
  // The candidates may share any amount of hits.
Sergey Gorbunov's avatar
Sergey Gorbunov committed
106
  L1Vector<L1Branch> fTrackCandidates[kMaxNthreads] {"L1Algo::fTrackCandidates"};
Administrator's avatar
Administrator committed
107

Sergey Gorbunov's avatar
Sergey Gorbunov committed
108
  Tindex fDupletPortionStopIndex[nSta] {0};                            // end of the duplet portions for the station
Sergey Gorbunov's avatar
Sergey Gorbunov committed
109
  L1Vector<Tindex> fDupletPortionSize {"L1Algo::fDupletPortionSize"};  // N duplets in a portion
Administrator's avatar
Administrator committed
110

Sergey Gorbunov's avatar
Sergey Gorbunov committed
111
112
113
114
  //
  // Temporary vectors used by the clone merger
  //
  // vectors that are parallel to fTracks
Sergey Gorbunov's avatar
Sergey Gorbunov committed
115
116
117
118
119
120
121
122
123
124
  L1Vector<unsigned short> fMergerTrackFirstStation {"L1Algo::fMergerTrackFirstStation"};  // first station of a track
  L1Vector<unsigned short> fMergerTrackLastStation {"L1Algo::fMergerTrackLastStation"};    // last station of a track
  L1Vector<THitI> fMergerTrackFirstHit {"L1Algo::fMergerTrackFirstHit"};  // index of the first tracks hit
  L1Vector<THitI> fMergerTrackLastHit {"L1Algo::fMergerTrackLastHit"};    // index of the last tracks hit
  L1Vector<unsigned short> fMergerTrackNeighbour {
    "L1Algo::fMergerTrackNeighbour"};                             // track that can be merged with the given track
  L1Vector<float> fMergerTrackChi2 {"L1Algo::fMergerTrackChi2"};  // chi2 of the merge
  L1Vector<char> fMergerTrackIsStored {"L1Algo::fMergerTrackIsStored"};  // is the track already stored to the output
  L1Vector<char> fMergerTrackIsDownstreamNeighbour {
    "L1Algo::fMergerTrackIsDownstreamNeighbour"};  // is the track a downstream neighbor of another track
Sergey Gorbunov's avatar
Sergey Gorbunov committed
125
  // other vectors
Sergey Gorbunov's avatar
Sergey Gorbunov committed
126
127
  L1Vector<L1Track> fMergerTracksNew {"L1Algo::fMergerTracksNew"};    // vector of tracks after the merge
  L1Vector<THitI> fMergerRecoHitsNew {"L1Algo::fMergerRecoHitsNew"};  // vector of track hits after the merge
Administrator's avatar
Administrator committed
128
129


130
#ifdef DRAW
Sergey Gorbunov's avatar
Sergey Gorbunov committed
131
  L1AlgoDraw* draw {nullptr};
Sergey Gorbunov's avatar
Sergey Gorbunov committed
132
  void DrawRecoTracksTime(const L1Vector<CbmL1Track>& tracks);
133
#endif
Administrator's avatar
Administrator committed
134
135


Sergey Gorbunov's avatar
Sergey Gorbunov committed
136
  void Init(const L1Vector<fscal>& geo, const bool UseHitErrors, const bool mCBMmode);
Administrator's avatar
Administrator committed
137

Sergey Gorbunov's avatar
Sergey Gorbunov committed
138
  void SetData(L1Vector<L1Hit>& StsHits_, int nStsStrips_, L1Vector<fscal>& StsZPos_, L1Vector<unsigned char>& SFlag_,
Sergey Gorbunov's avatar
Sergey Gorbunov committed
139
               const THitI* StsHitsStartIndex_, const THitI* StsHitsStopIndex_);
Administrator's avatar
Administrator committed
140

141
142
  void PrintHits();

Administrator's avatar
Administrator committed
143
  /// The main procedure - find tracks.
144
145
  void CATrackFinder();

Administrator's avatar
Administrator committed
146
  /// Track fitting procedures
147
148
  void KFTrackFitter_simple();  // version, which use procedured used during the reconstruction
  void L1KFTrackFitter();       // version from SIMD-KF benchmark
149
150

  void L1KFTrackFitterMuch();
Administrator's avatar
Administrator committed
151

152
153
  float GetMaxInvMom() const { return MaxInvMom[0]; }

Administrator's avatar
Administrator committed
154
155
156
  /// ----- Input data -----
  // filled in CbmL1::ReadEvent();

Sergey Gorbunov's avatar
Sergey Gorbunov committed
157
  void SetNThreads(int n);
Administrator's avatar
Administrator committed
158

159
160
161
162
  enum
  {
    MaxNStations = 25
  };
Administrator's avatar
Administrator committed
163

Sergey Gorbunov's avatar
Sergey Gorbunov committed
164
165
166
167
168
  int NStations {0};     // number of all detector stations
  int NMvdStations {0};  // number of mvd stations
  int NStsStations {0};  // number of sts stations
  int NFStations {0};    // ?

Administrator's avatar
Administrator committed
169
  L1Station vStations[MaxNStations] _fvecalignment;  // station info
Sergey Gorbunov's avatar
Sergey Gorbunov committed
170
  L1Vector<L1Material> fRadThick {"fRadThick"};      // material for each station
171

Sergey Gorbunov's avatar
Sergey Gorbunov committed
172
173
174
175
  int NStsStrips {0};                   // number of strips
  L1Vector<fscal>* vStsZPos {nullptr};  // all possible z-positions of hits
  L1Vector<L1Hit>* vStsHits {nullptr};  // hits as a combination of front-, backstrips and z-position
  L1Grid vGrid[MaxNStations];           // hits as a combination of front-, backstrips and z-position
176
  L1Grid vGridTime[MaxNStations];
Administrator's avatar
Administrator committed
177

Sergey Gorbunov's avatar
Sergey Gorbunov committed
178
  L1Vector<unsigned char>* fStripFlag {nullptr};  // information of hits station & using hits in tracks;
Administrator's avatar
Administrator committed
179

Sergey Gorbunov's avatar
Sergey Gorbunov committed
180
  double CATime {0.};  // time of trackfinding
Administrator's avatar
Administrator committed
181

Sergey Gorbunov's avatar
Sergey Gorbunov committed
182
183
  L1Vector<L1Track> fTracks {"L1Algo::fTracks"};    // reconstructed tracks
  L1Vector<THitI> fRecoHits {"L1Algo::fRecoHits"};  // packed hits of reconstructed tracks
Administrator's avatar
Administrator committed
184

Sergey Gorbunov's avatar
Sergey Gorbunov committed
185
186
  const THitI* StsHitsStartIndex {nullptr};  // station-bounders in vStsHits array
  const THitI* StsHitsStopIndex {nullptr};   // station-bounders in vStsHits array
Administrator's avatar
Administrator committed
187
188
189


  //  L1Branch* pointer;
Sergey Gorbunov's avatar
Sergey Gorbunov committed
190
  unsigned int NHitsIsecAll {0};
191

Sergey Gorbunov's avatar
Sergey Gorbunov committed
192
193
194
195
196
197
198
199
  L1Vector<L1Hit> vStsDontUsedHits_A {"L1Algo::vStsDontUsedHits_A"};
  L1Vector<L1Hit> vStsDontUsedHits_B {"L1Algo::vStsDontUsedHits_B"};
  L1Vector<L1Hit> vStsDontUsedHits_Buf {"L1Algo::vStsDontUsedHits_Buf"};
  L1Vector<L1HitPoint> vStsDontUsedHitsxy_A {"L1Algo::vStsDontUsedHitsxy_A"};
  L1Vector<L1HitPoint> vStsDontUsedHitsxy_buf {"L1Algo::vStsDontUsedHitsxy_buf"};
  L1Vector<L1HitPoint> vStsDontUsedHitsxy_B {"L1Algo::vStsDontUsedHitsxy_B"};
  L1Vector<L1Track> fTracks_local[kMaxNthreads] {"L1Algo::fTracks_local"};
  L1Vector<THitI> fRecoHits_local[kMaxNthreads] {"L1Algo::fRecoHits_local"};
200

Sergey Gorbunov's avatar
Sergey Gorbunov committed
201
202
203
  L1Vector<THitI> RealIHit_v {"L1Algo::RealIHit_v"};
  L1Vector<THitI> RealIHit_v_buf {"L1Algo::RealIHit_v_buf"};
  L1Vector<THitI> RealIHit_v_buf2 {"L1Algo::RealIHit_v_buf2"};
Administrator's avatar
Administrator committed
204
205

#ifdef _OPENMP
Sergey Gorbunov's avatar
Sergey Gorbunov committed
206
207
  L1Vector<omp_lock_t> fHitToBestTrackF {"L1Algo::fHitToBestTrackF"};
  L1Vector<omp_lock_t> fHitToBestTrackB {"L1Algo::fHitToBestTrackB"};
Administrator's avatar
Administrator committed
208
209
#endif

Sergey Gorbunov's avatar
Sergey Gorbunov committed
210
211
  L1Vector<int> fStripToTrack {"L1Algo::fStripToTrack"};    // front strip to track pointers
  L1Vector<int> fStripToTrackB {"L1Algo::fStripToTrackB"};  // back strip to track pointers
Administrator's avatar
Administrator committed
212

Sergey Gorbunov's avatar
Sergey Gorbunov committed
213
214
215
216
  int fNThreads {0};
  bool fUseHitErrors {0};
  bool fmCBMmode {0};
  bool fGlobal {0};
217

Sergey Gorbunov's avatar
Sergey Gorbunov committed
218
219
  fvec EventTime[kMaxNthreads][kMaxNthreads] {{0}};
  fvec Err[kMaxNthreads][kMaxNthreads] {{0}};
Administrator's avatar
Administrator committed
220
221
222


  /// standard sizes of the arrays
223
224
  enum
  {
Administrator's avatar
Administrator committed
225
226
227
228
229
230
231
232
233
234
235
236
    multiCoeff = 1,  // central - 1, mbias


    coeff = 64 / 4,

    Portion = 1024 / coeff,  // portion of left hits

    MaxPortionDoublets = 10000 / 5 * 64 / 2 / coeff /*/ multiCoeff*/ * 1,
    MaxPortionTriplets = 10000 * 5 * 64 / 2 / coeff /*/ multiCoeff*/ * 1,
    MaxNPortion        = 40 * coeff / multiCoeff,


237
238
    MaxArrSize = MaxNPortion * MaxPortionDoublets
                 / MaxNStations  //200000,  // standart size of big arrays  // mas be 40000 for normal work in cbmroot!
Administrator's avatar
Administrator committed
239
240
241
242
243
  };


  /// --- data used during finding iterations

Sergey Gorbunov's avatar
Sergey Gorbunov committed
244
245
246
247
248
249
250
251
252
253
254
  int isec {0};  // iteration
  L1Vector<L1Hit>* vStsHitsUnused {nullptr};
  L1Vector<THitI>* RealIHitP {nullptr};
  L1Vector<THitI>* RealIHitPBuf {nullptr};
  L1Vector<L1HitPoint>* vStsHitPointsUnused {nullptr};
  THitI* RealIHit {nullptr};  // index in vStsHits indexed by index in vStsHitsUnused

  THitI StsHitsUnusedStartIndex[MaxNStations + 1] {0};
  THitI StsHitsUnusedStopIndex[MaxNStations + 1] {0};
  THitI StsHitsUnusedStartIndexEnd[MaxNStations + 1] {0};
  THitI StsHitsUnusedStopIndexEnd[MaxNStations + 1] {0};
Administrator's avatar
Administrator committed
255
256


Sergey Gorbunov's avatar
Sergey Gorbunov committed
257
  L1Vector<int> TripForHit[2] {"L1Algo::TripForHit"};
258
259


Administrator's avatar
Administrator committed
260
261
262
  //  fvec u_front[Portion/fvecLen], u_back[Portion/fvecLen];
  //  fvec zPos[Portion/fvecLen];
  //  fvec fHitTime[Portion/fvecLen];
263

Sergey Gorbunov's avatar
Sergey Gorbunov committed
264
  nsL1::vector<L1TrackPar>::TSimd fT_3[kMaxNthreads];
265

Sergey Gorbunov's avatar
Sergey Gorbunov committed
266
267
268
  L1Vector<THitI> fhitsl_3[kMaxNthreads] {"L1Algo::fhitsl_3"};
  L1Vector<THitI> fhitsm_3[kMaxNthreads] {"L1Algo::fhitsm_3"};
  L1Vector<THitI> fhitsr_3[kMaxNthreads] {"L1Algo::fhitsr_3"};
269

Sergey Gorbunov's avatar
Sergey Gorbunov committed
270
271
272
273
274
275
276
277
278
  nsL1::vector<fvec>::TSimd fu_front3[kMaxNthreads];
  nsL1::vector<fvec>::TSimd fu_back3[kMaxNthreads];
  nsL1::vector<fvec>::TSimd fz_pos3[kMaxNthreads];
  nsL1::vector<fvec>::TSimd fTimeR[kMaxNthreads];
  nsL1::vector<fvec>::TSimd fTimeER[kMaxNthreads];
  nsL1::vector<fvec>::TSimd dx[kMaxNthreads];
  nsL1::vector<fvec>::TSimd dy[kMaxNthreads];
  nsL1::vector<fvec>::TSimd du[kMaxNthreads];
  nsL1::vector<fvec>::TSimd dv[kMaxNthreads];
279
280


Administrator's avatar
Administrator committed
281
282
283
284
285
286
287
288
289
290
  //   Tindex NHits_l[MaxNStations];
  //   Tindex NHits_l_P[MaxNStations];
  /// ----- Output data -----

  friend class CbmL1;

  const L1FieldValue& GetVtxFieldValue() const { return vtxFieldValue; }
  const L1FieldRegion& GetVtxFieldRegion() const { return vtxFieldRegion; }
  /// ----- Hit-point-strips conversion routines ------

Sergey Gorbunov's avatar
Sergey Gorbunov committed
291
  void GetHitCoor(const L1Hit& _h, fscal& _x, fscal& _y, fscal& _z, const L1Station& sta);
292
293
294
295
296

  void dUdV_to_dY(const fvec& u, const fvec& v, fvec& _y, const L1Station& sta);

  void dUdV_to_dX(const fvec& u, const fvec& v, fvec& _x, const L1Station& sta);

297
  void dUdV_to_dXdY(const fvec& u, const fvec& v, fvec& _xy, const L1Station& sta);
298

Sergey Gorbunov's avatar
Sergey Gorbunov committed
299
  void GetHitCoor(const L1Hit& _h, fscal& _x, fscal& _y, char iS);
300
301
302
303
304
  void StripsToCoor(const fscal& u, const fscal& v, fscal& x, fscal& y,
                    const L1Station& sta) const;  // convert strip positions to coordinates
  void StripsToCoor(const fscal& u, const fscal& v, fvec& x, fvec& y,
                    const L1Station& sta) const;  // convert strip positions to coordinates
  void StripsToCoor(const fvec& u, const fvec& v, fvec& x, fvec& y, const L1Station& sta) const;
Sergey Gorbunov's avatar
Sergey Gorbunov committed
305
  L1HitPoint CreateHitPoint(const L1Hit& hit,
306
                            char ista);  // full the hit point by hit information.
Administrator's avatar
Administrator committed
307

Sergey Gorbunov's avatar
Sergey Gorbunov committed
308
  void CreateHitPoint(const L1Hit& hit, char ista, L1HitPoint& point);
309
310
311
  inline int PackIndex(const int& a, const int& b, const int& c);

  inline int UnPackIndex(const int& i, int& a, int& b, int& c);
Administrator's avatar
Administrator committed
312
  /// -- Flags routines --
313
314
  inline __attribute__((always_inline)) static unsigned char GetFStation(unsigned char flag) { return flag / 4; }
  inline __attribute__((always_inline)) static bool GetFUsed(unsigned char flag) { return (flag & 0x02) != 0; }
Administrator's avatar
Administrator committed
315
  //   bool GetFUsedD  ( unsigned char flag ){ return (flag&0x01)!=0; }
316

Administrator's avatar
Administrator committed
317
318
319
320
private:
  /// =================================  FUNCTIONAL PART  =================================

  /// ----- Subroutines used by L1Algo::CATrackFinder() ------
321

322
323
  void CAFindTrack(int ista, L1Branch& best_tr, unsigned char& best_L, fscal& best_chi2, const L1Triplet* curr_trip,
                   L1Branch& curr_tr, unsigned char& curr_L, fscal& curr_chi2, unsigned char min_best_l,
Administrator's avatar
Administrator committed
324
325
326
327
328
329
330
331
332
                   L1Branch* new_tr);


  /// Fit track
  /// t - track with hits
  /// T - track params
  /// dir - 0 - forward, 1 - backward
  /// qp0 - momentum for extrapolation
  /// initialize - should be params ititialized. 1 - yes.
333
  void BranchFitterFast(const L1Branch& t, L1TrackPar& T, const bool dir, const fvec qp0 = 0.,
Administrator's avatar
Administrator committed
334
335
336
                        const bool initParams = true);

  /// Fit track. more precise than FitterFast
337
  void BranchFitter(const L1Branch& t, L1TrackPar& T, const bool dir, const fvec qp0 = 0.,
Administrator's avatar
Administrator committed
338
339
340
341
342
343
344
                    const bool initParams = true);

  /// Find additional hits for existing track
  /// t - track with hits
  /// T - track params
  /// dir - 0 - forward, 1 - backward
  /// qp0 - momentum for extrapolation
345
  void FindMoreHits(L1Branch& t, L1TrackPar& T, const bool dir, const fvec qp0 = 0.0);
Administrator's avatar
Administrator committed
346
347
348
349
350
351

  /// Find additional hits for existing track
  /// return chi2
  fscal BranchExtender(L1Branch& t);

  /// ----- Subroutines used by L1Algo::CAMergeClones() ------
352
353
354
355
  void InvertCholetsky(fvec a[15]);
  void MultiplySS(fvec const C[15], fvec const V[15], fvec K[5][5]);
  void MultiplyMS(fvec const C[5][5], fvec const V[15], fvec K[15]);
  void MultiplySR(fvec const C[15], fvec const r_in[5], fvec r_out[5]);
356
  void FilterTracks(fvec const r[5], fvec const C[15], fvec const m[5], fvec const V[15], fvec R[5], fvec W[15],
Administrator's avatar
Administrator committed
357
                    fvec* chi2);
358
359
  void CAMergeClones();

Administrator's avatar
Administrator committed
360

361
362
363
  inline __attribute__((always_inline)) void PackLocation(unsigned int& location, unsigned int& triplet,
                                                          unsigned int iStation, unsigned int& thread)
  {
Administrator's avatar
Administrator committed
364
365
366
    location = (triplet << 11) | (thread << 3) | iStation;
  }

367
368
  inline __attribute__((always_inline)) void UnPackStation(unsigned int& location, unsigned int& iStation)
  {
Administrator's avatar
Administrator committed
369
370
371
    iStation = location & 0x7;
  }

372
373
  inline __attribute__((always_inline)) void UnPackThread(unsigned int& location, unsigned int& thread)
  {
Administrator's avatar
Administrator committed
374
375
376
    thread = (location >> 3) & 0xFF;
  }

377
378
  inline __attribute__((always_inline)) void UnPackTriplet(unsigned int& location, unsigned int& triplet)
  {
Administrator's avatar
Administrator committed
379
380
381
    triplet = (location >> 11);
  }

382
383
  inline __attribute__((always_inline)) void SetFStation(unsigned char& flag, unsigned int iStation)
  {
Administrator's avatar
Administrator committed
384
385
    flag = iStation * 4 + (flag % 4);
  }
386
  inline __attribute__((always_inline)) void SetFUsed(unsigned char& flag) { flag |= 0x02; }
Administrator's avatar
Administrator committed
387
  //   void SetFUsedD   ( unsigned char &flag ){ flag |= 0x01; }
388
  inline __attribute__((always_inline)) void SetFUnUsed(unsigned char& flag) { flag &= 0xFC; }
Administrator's avatar
Administrator committed
389
390
391
  //   void SetFUnUsedD ( unsigned char &flag ){ flag &= 0xFE; }

  /// Prepare the portion of left hits data
392
  void f10(  // input
393
    Tindex start_lh, Tindex n1_l, L1HitPoint* StsHits_l,
Administrator's avatar
Administrator committed
394
    // output
395
396
    fvec* u_front_l, fvec* u_back_l, fvec* zPos_l, THitI* hitsl, fvec* HitTime_l, fvec* HitTimeEr, fvec* Event_l,
    fvec* d_x, fvec* d_y, fvec* d_xy, fvec* d_u, fvec* d_v);
Administrator's avatar
Administrator committed
397
398

  /// Get the field approximation. Add the target to parameters estimation. Propagate to middle station.
399
  void f11(  // input
400
401
402
    int istal, int istam, Tindex n1_V,

    fvec* u_front_l, fvec* u_back_l, fvec* zPos_l, fvec* HitTime_l, fvec* HitTimeEr,
Administrator's avatar
Administrator committed
403
    // output
404
    L1TrackPar* T_1, L1FieldRegion* fld_1, fvec* d_x, fvec* d_y, fvec* d_xy, fvec* d_u, fvec* d_v);
Administrator's avatar
Administrator committed
405
406

  /// Find the doublets. Reformat data in the portion of doublets.
407
  void f20(  // input
408
    Tindex n1, L1Station& stam, L1HitPoint* vStsHits_m, L1TrackPar* T_1, THitI* hitsl_1,
Administrator's avatar
Administrator committed
409
410

    // output
Sergey Gorbunov's avatar
Sergey Gorbunov committed
411
    Tindex& n2, L1Vector<THitI>& i1_2,
Administrator's avatar
Administrator committed
412

413
#ifdef DOUB_PERFORMANCE
Sergey Gorbunov's avatar
Sergey Gorbunov committed
414
    L1Vector<THitI>& hitsl_2,
Administrator's avatar
Administrator committed
415
#endif  // DOUB_PERFORMANCE
Sergey Gorbunov's avatar
Sergey Gorbunov committed
416
    L1Vector<THitI>& hitsm_2, fvec* Event, L1Vector<char>& lmDuplets);
Administrator's avatar
Administrator committed
417
418
419

  /// Add the middle hits to parameters estimation. Propagate to right station.
  /// Find the triplets (right hit). Reformat data in the portion of triplets.
420
  void f30(  // input
421
    L1HitPoint* vStsHits_r, L1Station& stam, L1Station& star,
Administrator's avatar
Administrator committed
422

423
    int istam, int istar, L1HitPoint* vStsHits_m, L1TrackPar* T_1, L1FieldRegion* fld_1, THitI* hitsl_1,
Administrator's avatar
Administrator committed
424

Sergey Gorbunov's avatar
Sergey Gorbunov committed
425
    Tindex n2, L1Vector<THitI>& hitsm_2, L1Vector<THitI>& i1_2,
Administrator's avatar
Administrator committed
426

Sergey Gorbunov's avatar
Sergey Gorbunov committed
427
    const L1Vector<char>& mrDuplets,
Administrator's avatar
Administrator committed
428
    // output
Sergey Gorbunov's avatar
Sergey Gorbunov committed
429
430
    Tindex& n3, nsL1::vector<L1TrackPar>::TSimd& T_3, L1Vector<THitI>& hitsl_3, L1Vector<THitI>& hitsm_3,
    L1Vector<THitI>& hitsr_3, nsL1::vector<fvec>::TSimd& u_front_3, nsL1::vector<fvec>::TSimd& u_back_3,
Administrator's avatar
Administrator committed
431
    nsL1::vector<fvec>::TSimd& z_Pos_3,
432
433
    //    nsL1::vector<fvec>::TSimd& dx_,
    //    nsL1::vector<fvec>::TSimd& dy_,
434
    nsL1::vector<fvec>::TSimd& du_, nsL1::vector<fvec>::TSimd& dv_, nsL1::vector<fvec>::TSimd& timeR,
Administrator's avatar
Administrator committed
435
436
437
    nsL1::vector<fvec>::TSimd& timeER);

  /// Add the right hits to parameters estimation.
438
  void f31(  // input
439
    Tindex n3_V, L1Station& star, nsL1::vector<fvec>::TSimd& u_front_3, nsL1::vector<fvec>::TSimd& u_back_3,
Administrator's avatar
Administrator committed
440
    nsL1::vector<fvec>::TSimd& z_Pos_3,
441
442
    //    nsL1::vector<fvec>::TSimd& dx_,
    //    nsL1::vector<fvec>::TSimd& dy_,
443
    nsL1::vector<fvec>::TSimd& du_, nsL1::vector<fvec>::TSimd& dv_, nsL1::vector<fvec>::TSimd& timeR,
Administrator's avatar
Administrator committed
444
445
446
447
448
449
    nsL1::vector<fvec>::TSimd& timeER,
    // output
    nsL1::vector<L1TrackPar>::TSimd& T_3);

  /// Refit Triplets.
  void f32(  // input
Sergey Gorbunov's avatar
Sergey Gorbunov committed
450
451
    Tindex n3, int istal, nsL1::vector<L1TrackPar>::TSimd& T_3, L1Vector<THitI>& hitsl_3, L1Vector<THitI>& hitsm_3,
    L1Vector<THitI>& hitsr_3, int nIterations = 0);
Administrator's avatar
Administrator committed
452
453

  /// Select triplets. Save them into vTriplets.
454
  void f4(  // input
Sergey Gorbunov's avatar
Sergey Gorbunov committed
455
456
    Tindex n3, int istal, int istam, int istar, nsL1::vector<L1TrackPar>::TSimd& T_3, L1Vector<THitI>& hitsl_3,
    L1Vector<THitI>& hitsm_3, L1Vector<THitI>& hitsr_3,
Administrator's avatar
Administrator committed
457
    // output
Sergey Gorbunov's avatar
Sergey Gorbunov committed
458
    Tindex& nstaltriplets, L1Vector<THitI>* hitsn_3 = 0, L1Vector<THitI>* hitsr_5 = 0
Administrator's avatar
Administrator committed
459
460
461
462
463
464
465
466

    // #ifdef XXX
    //                 ,unsigned int &stat_n_trip
    // #endif
  );


  /// Find neighbours of triplets. Calculate level of triplets.
467
  void f5(  // input
Administrator's avatar
Administrator committed
468
469
470
471
472
473
    // output
    int* nlevel);


  /// Find doublets on station
  void DupletsStaPort(  // input
Sergey Gorbunov's avatar
Sergey Gorbunov committed
474
    int istal, int istam, Tindex ip, L1Vector<Tindex>& n_g, Tindex* portionStopIndex_,
Administrator's avatar
Administrator committed
475
476

    // output
477
    L1TrackPar* T_1, L1FieldRegion* fld_1, THitI* hitsl_1,
Administrator's avatar
Administrator committed
478

Sergey Gorbunov's avatar
Sergey Gorbunov committed
479
    L1Vector<char>& lmDuplets,
Administrator's avatar
Administrator committed
480
481


Sergey Gorbunov's avatar
Sergey Gorbunov committed
482
    Tindex& n_2, L1Vector<THitI>& i1_2, L1Vector<THitI>& hitsm_2);
Administrator's avatar
Administrator committed
483
484
485

  /// Find triplets on station
  void TripletsStaPort(  // input
486
487
    int istal, int istam, int istar, Tindex& nstaltriplets, L1TrackPar* T_1, L1FieldRegion* fld_1, THitI* hitsl_1,

Sergey Gorbunov's avatar
Sergey Gorbunov committed
488
    Tindex& n_2, L1Vector<THitI>& i1_2, L1Vector<THitI>& hitsm_2,
Administrator's avatar
Administrator committed
489

Sergey Gorbunov's avatar
Sergey Gorbunov committed
490
    const L1Vector<char>& mrDuplets
Administrator's avatar
Administrator committed
491
492
493
494
495
496
497
498
499

    // output


  );


  ///  ------ Subroutines used by L1Algo::KFTrackFitter()  ------

500
501
502
  void GuessVec(L1TrackPar& t, fvec* xV, fvec* yV, fvec* zV, fvec* Sy, fvec* wV, int NHits, fvec* zCur = 0);
  void GuessVec(L1TrackParFit& t, fvec* xV, fvec* yV, fvec* zV, fvec* Sy, fvec* wV, int NHits, fvec* zCur = 0,
                fvec* timeV = 0, fvec* w_time = 0);
Administrator's avatar
Administrator committed
503
504

  void FilterFirst(L1TrackPar& track, fvec& x, fvec& y, L1Station& st);
505
506
507
508
  void FilterFirst(L1TrackParFit& track, fvec& x, fvec& y, fvec& t, L1Station& st);
  void FilterFirst(L1TrackParFit& track, fvec& x, fvec& y, fvec& t, fvec& t_er, L1Station& st);

  void FilterFirst(L1TrackParFit& track, fvec& x, fvec& y, fvec& t, fvec& t_er, L1Station& st, fvec& dx, fvec& dy,
Administrator's avatar
Administrator committed
509
                   fvec& dxy);
510
  void FilterFirstL(L1TrackParFit& track, fvec& x, fvec& y, fvec& t, fvec& t_er, L1Station& st, fvec& dx, fvec& dy,
Administrator's avatar
Administrator committed
511
512
513
                    fvec& dxy);


514
#ifdef TBB
515
516
  enum
  {
Administrator's avatar
Administrator committed
517
518
519
    nthreads = 3,  // number of threads
    nblocks  = 1   // number of stations on one thread
  };
520
521
522

  friend class ParalleledDup;
  friend class ParalleledTrip;
Administrator's avatar
Administrator committed
523
#endif  // TBB
524
#ifdef TBB2
Administrator's avatar
Administrator committed
525
public:
526
  Tindex thrId;
Administrator's avatar
Administrator committed
527
528
529
530
531
#endif  // TBB2
private:
  /// =================================  DATA PART  =================================

  /// ----- Different parameters of CATrackFinder -----
532

Sergey Gorbunov's avatar
Sergey Gorbunov committed
533
  Tindex FIRSTCASTATION {0};  //first station used in CA
534

Administrator's avatar
Administrator committed
535
536
  // fNFindIterations - set number of interation for trackfinding
  // itetation of finding:
537
#ifdef FIND_GAPED_TRACKS
538
539
  enum
  {
Administrator's avatar
Administrator committed
540
541
542
543
544
545
546
547
548
549
    kFastPrimIter,     // primary fast tracks
    kAllPrimIter,      // primary all tracks
    kAllPrimJumpIter,  // primary tracks with jumped triplets
    kAllSecIter,       // secondary all tracks
    kAllPrimEIter,     // primary all electron tracks
    kAllSecEIter,      // secondary all electron tracks

    kFastPrimJumpIter,  // primary fast tracks with jumped triplets
    kFastPrimIter2,
    kAllSecJumpIter  // secondary tracks with jumped triplets
550
551
  };
#ifdef TRACKS_FROM_TRIPLETS
552
553
  enum
  {
Administrator's avatar
Administrator committed
554
555
    fNFindIterations = TRACKS_FROM_TRIPLETS_ITERATION + 1
  };  // TODO investigate kAllPrimJumpIter & kAllSecJumpIter
556
#else
Administrator's avatar
Administrator committed
557

558
559
  enum
  {
560
    fNFindIterations = 4
Administrator's avatar
Administrator committed
561
  };  // TODO investigate kAllPrimJumpIter & kAllSecJumpIter
562

Administrator's avatar
Administrator committed
563

564
565
#endif
#else
566
567
  enum
  {
Administrator's avatar
Administrator committed
568
569
570
571
572
573
574
575
576
    kFastPrimIter = 0,  // primary fast tracks
    kAllPrimIter,       // primary all tracks
    kAllSecIter,        // secondary all tracks
    kFastPrimJumpIter,  // disabled
    kAllPrimJumpIter,   // disabled
    kFastPrimIter2,
    kAllSecJumpIter,
    kAllPrimEIter,
    kAllSecEIter
577
  };
Administrator's avatar
Administrator committed
578
579
#endif  // FIND_GAPED_TRACKS

Sergey Gorbunov's avatar
Sergey Gorbunov committed
580
  map<int, int> threadNumberToCpuMap {};
Administrator's avatar
Administrator committed
581

582

Sergey Gorbunov's avatar
Sergey Gorbunov committed
583
584
585
586
587
  float TRACK_CHI2_CUT {10.f};
  float TRIPLET_CHI2_CUT {5.f};  // cut for selecting triplets before collecting tracks.per one DoF
  float DOUBLET_CHI2_CUT {5.f};
  float TIME_CUT1 {0.f};
  float TIME_CUT2 {0.f};
Administrator's avatar
Administrator committed
588

Sergey Gorbunov's avatar
Sergey Gorbunov committed
589
590
  fvec MaxDZ {
    0.f};  // correction in order to take into account overlaping and iff z. if sort by y then it is max diff between same station's modules (~0.4cm)
Administrator's avatar
Administrator committed
591
592
593

  /// parameters which are different for different iterations. Set in the begin of CAL1TrackFinder

Sergey Gorbunov's avatar
Sergey Gorbunov committed
594
595
596
597
598
599
600
601
602
  float Pick_gather {0.f};    // same for attaching additional hits to track
  float PickNeighbour {0.f};  // (PickNeighbour < dp/dp_error)  =>  triplets are neighbours
  fvec MaxInvMom {0.f};       // max considered q/p for tracks
  fvec MaxSlope {0.f};        // max slope (tx\ty) in prim vertex
  fvec targX {0.f};  // target coor TODO: set defaults to a crasy value to be sure that the target is initialised later
  fvec targY {0.f};
  fvec targZ {0.f};
  L1FieldValue targB _fvecalignment {};                // field in the target point
  L1XYMeasurementInfo TargetXYInfo _fvecalignment {};  // target constraint  [cm]
Administrator's avatar
Administrator committed
603
604


Sergey Gorbunov's avatar
Sergey Gorbunov committed
605
606
  L1FieldRegion vtxFieldRegion _fvecalignment {};  // really doesn't used
  L1FieldValue vtxFieldValue _fvecalignment {};    // field at teh vertex position.
Administrator's avatar
Administrator committed
607
608
609

  //  int TripNumThread;

Sergey Gorbunov's avatar
Sergey Gorbunov committed
610
611
612
  int fTrackingLevel {0};     // currently not used
  int fGhostSuppression {0};  // currently not used
  float fMomentumCutOff {0};  // currently not used
Administrator's avatar
Administrator committed
613
614

  /// ----- Debug features -----
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
#ifdef PULLS
  L1AlgoPulls* fL1Pulls;
#endif
#ifdef TRIP_PERFORMANCE
  L1AlgoEfficiencyPerformance<3>* fL1Eff_triplets;
  L1AlgoEfficiencyPerformance<3>* fL1Eff_triplets2;
#endif
#ifdef DOUB_PERFORMANCE
  L1AlgoEfficiencyPerformance<2>* fL1Eff_doublets;
#endif
#ifdef DRAW
  friend class L1AlgoDraw;
#endif
} _fvecalignment;

#endif