CMS 3D CMS Logo

DataFormats.h
Go to the documentation of this file.
1 #ifndef L1Trigger_TrackerTFP_DataFormats_h
2 #define L1Trigger_TrackerTFP_DataFormats_h
3 
4 /*----------------------------------------------------------------------
5 Classes to calculate and provide dataformats used by Track Trigger emulator
6 enabling automated conversions from frames to stubs/tracks and vice versa
7 In data members of classes Stub* & Track* below, the variables describing
8 stubs/tracks are stored both in digitial format as a 64b word in frame_,
9 and in undigitized format in an std::tuple. (This saves CPU)
10 ----------------------------------------------------------------------*/
11 
17 
18 #include <vector>
19 #include <cmath>
20 #include <initializer_list>
21 #include <tuple>
22 #include <iostream>
23 #include <string>
24 
25 namespace trackerTFP {
26 
27  // track trigger processes
28  enum class Process { begin, fe = begin, dtc, pp, gp, ht, mht, zht, kfin, kf, dr, end, x };
29  // track trigger variables
30  enum class Variable {
31  begin,
32  r = begin,
33  phi,
34  z,
35  layer,
36  sectorsPhi,
37  sectorEta,
38  sectorPhi,
39  phiT,
40  inv2R,
41  zT,
42  cot,
43  dPhi,
44  dZ,
45  match,
46  hitPattern,
47  phi0,
48  z0,
49  end,
50  x
51  };
52  // track trigger process order
53  constexpr std::initializer_list<Process> Processes = {Process::fe,
62  Process::dr};
63  // conversion: Process to int
64  inline constexpr int operator+(Process p) { return static_cast<int>(p); }
65  // conversion: Variable to int
66  inline constexpr int operator+(Variable v) { return static_cast<int>(v); }
67  // increment of Process
68  inline constexpr Process operator++(Process p) { return Process(+p + 1); }
69  // increment of Variable
70  inline constexpr Variable operator++(Variable v) { return Variable(+v + 1); }
71 
72  //Base class representing format of a variable
73  class DataFormat {
74  public:
75  DataFormat(bool twos) : twos_(twos), width_(0), base_(1.), range_(0.) {}
77  // converts int to bitvector
78  TTBV ttBV(int i) const { return TTBV(i, width_, twos_); }
79  // converts double to bitvector
80  TTBV ttBV(double d) const { return TTBV(d, base_, width_, twos_); }
81  // extracts int from bitvector, removing these bits from bitvector
82  void extract(TTBV& in, int& out) const { out = in.extract(width_, twos_); }
83  // extracts double from bitvector, removing these bits from bitvector
84  void extract(TTBV& in, double& out) const { out = in.extract(base_, width_, twos_); }
85  // extracts double from bitvector, removing these bits from bitvector
86  void extract(TTBV& in, TTBV& out) const { out = in.slice(width_, twos_); }
87  // attaches integer to bitvector
88  void attach(const int i, TTBV& ttBV) const { ttBV += TTBV(i, width_, twos_); }
89  // attaches double to bitvector
90  void attach(const double d, TTBV& ttBV) const { ttBV += TTBV(d, base_, width_, twos_); }
91  // attaches bitvector to bitvector
92  void attach(const TTBV bv, TTBV& ttBV) const { ttBV += bv; }
93  // converts int to double
94  double floating(int i) const { return (i + .5) * base_; }
95  // converts double to int
96  int integer(double d) const { return std::floor(d / base_ + 1.e-12); }
97  // converts double to int and back to double
98  double digi(double d) const { return floating(integer(d)); }
99  // converts binary integer value to twos complement integer value
100  int toSigned(int i) const { return i - std::pow(2, width_) / 2; }
101  // converts twos complement integer value to binary integer value
102  int toUnsigned(int i) const { return i + std::pow(2, width_) / 2; }
103  // converts floating point value to binary integer value
104  int toUnsigned(double d) const { return this->integer(d) + std::pow(2, width_) / 2; }
105  // returns false if data format would oferflow for this double value
106  bool inRange(double d, bool digi = false) const {
107  const double range = digi ? base_ * pow(2, width_) : range_;
108  return d >= -range / 2. && d < range / 2.;
109  }
110  // returns false if data format would oferflow for this int value
111  bool inRange(int i) const { return inRange(floating(i)); }
112  // true if twos'complement or false if binary representation is chosen
113  bool twos() const { return twos_; }
114  // number of used bits
115  int width() const { return width_; }
116  // precision
117  double base() const { return base_; }
118  // covered range
119  double range() const { return range_; }
120 
121  protected:
122  // true if twos'complement or false if binary representation is chosen
123  bool twos_;
124  // number of used bits
125  int width_;
126  // precision
127  double base_;
128  // covered range
129  double range_;
130  };
131 
132  // class representing format of a specific variable
133  template <Variable v, Process p>
134  class Format : public DataFormat {
135  public:
136  Format(const edm::ParameterSet& iConfig, const tt::Setup* setup);
137  ~Format() {}
138  };
139 
140  template <>
142  template <>
144  template <>
146  template <>
148  template <>
150  template <>
152  template <>
154  template <>
156  template <>
158  template <>
160  template <>
162  template <>
164  template <>
166  template <>
168  template <>
170  template <>
172  template <>
174  template <>
176  template <>
178  template <>
180  template <>
182  template <>
184  template <>
186  template <>
188  template <>
190  template <>
192  template <>
194  template <>
196  template <>
198  template <>
200  template <>
202  template <>
204  template <>
206  template <>
208  template <>
210 
216  class DataFormats {
217  private:
218  // variable flavour mapping, Each row below declares which processing steps use the variable named in the comment at the end of the row
219  static constexpr std::array<std::array<Process, +Process::end>, +Variable::end> config_ = {{
220  // Process::fe Process::dtc Process::pp Process::gp Process::ht Process::mht Process::zht Process::kfin Process::kf Process::dr
221  {{Process::x,
222  Process::ht,
223  Process::ht,
224  Process::ht,
225  Process::ht,
226  Process::ht,
227  Process::ht,
228  Process::ht,
229  Process::ht,
230  Process::x}}, // Variable::r
231  {{Process::x,
232  Process::dtc,
233  Process::dtc,
234  Process::gp,
235  Process::ht,
236  Process::mht,
237  Process::zht,
240  Process::x}}, // Variable::phi
241  {{Process::x,
242  Process::dtc,
243  Process::dtc,
244  Process::gp,
245  Process::gp,
246  Process::gp,
247  Process::zht,
250  Process::x}}, // Variable::z
251  {{Process::x,
252  Process::ht,
253  Process::ht,
254  Process::ht,
255  Process::ht,
256  Process::ht,
257  Process::ht,
258  Process::x,
259  Process::x,
260  Process::x}}, // Variable::layer
261  {{Process::x,
262  Process::dtc,
263  Process::dtc,
264  Process::x,
265  Process::x,
266  Process::x,
267  Process::x,
268  Process::x,
269  Process::x,
270  Process::x}}, // Variable::sectorsPhi
271  {{Process::x,
272  Process::gp,
273  Process::gp,
274  Process::gp,
275  Process::gp,
276  Process::gp,
277  Process::gp,
278  Process::gp,
279  Process::gp,
280  Process::x}}, // Variable::sectorEta
281  {{Process::x,
282  Process::x,
283  Process::x,
284  Process::gp,
285  Process::gp,
286  Process::gp,
287  Process::gp,
288  Process::gp,
289  Process::gp,
290  Process::x}}, // Variable::sectorPhi
291  {{Process::x,
292  Process::ht,
293  Process::ht,
294  Process::ht,
295  Process::ht,
296  Process::mht,
297  Process::mht,
298  Process::mht,
299  Process::kf,
300  Process::x}}, // Variable::phiT
301  {{Process::x,
302  Process::ht,
303  Process::ht,
304  Process::ht,
305  Process::ht,
306  Process::mht,
307  Process::mht,
308  Process::mht,
309  Process::kf,
310  Process::dr}}, // Variable::inv2R
311  {{Process::x,
312  Process::x,
313  Process::x,
314  Process::x,
315  Process::x,
316  Process::x,
317  Process::zht,
318  Process::zht,
319  Process::kf,
320  Process::x}}, // Variable::zT
321  {{Process::x,
322  Process::x,
323  Process::x,
324  Process::x,
325  Process::x,
326  Process::x,
327  Process::zht,
328  Process::zht,
329  Process::kf,
330  Process::dr}}, // Variable::cot
331  {{Process::x,
332  Process::x,
333  Process::x,
334  Process::x,
335  Process::x,
336  Process::x,
337  Process::x,
340  Process::x}}, // Variable::dPhi
341  {{Process::x,
342  Process::x,
343  Process::x,
344  Process::x,
345  Process::x,
346  Process::x,
347  Process::x,
350  Process::x}}, // Variable::dZ
351  {{Process::x,
352  Process::x,
353  Process::x,
354  Process::x,
355  Process::x,
356  Process::x,
357  Process::x,
358  Process::x,
359  Process::kf,
360  Process::x}}, // Variable::match
361  {{Process::x,
362  Process::x,
363  Process::x,
364  Process::x,
365  Process::x,
366  Process::x,
367  Process::x,
369  Process::x,
370  Process::x}}, // Variable::hitPattern
371  {{Process::x,
372  Process::x,
373  Process::x,
374  Process::x,
375  Process::x,
376  Process::x,
377  Process::x,
378  Process::x,
379  Process::x,
380  Process::dr}}, // Variable::phi0
381  {{Process::x,
382  Process::x,
383  Process::x,
384  Process::x,
385  Process::x,
386  Process::x,
387  Process::x,
388  Process::x,
389  Process::x,
390  Process::dr}} // Variable::z0
391  }};
392  // stub word assembly, shows which stub variables are used by each process
393  static constexpr std::array<std::initializer_list<Variable>, +Process::end> stubs_ = {{
394  {}, // Process::fe
395  {Variable::r,
397  Variable::z,
403  Variable::inv2R}, // Process::dtc
404  {Variable::r,
406  Variable::z,
412  Variable::inv2R}, // Process::pp
414  {Variable::r,
416  Variable::z,
420  Variable::phiT}, // Process::ht
421  {Variable::r,
423  Variable::z,
428  Variable::inv2R}, // Process::mht
429  {Variable::r,
431  Variable::z,
437  Variable::zT,
438  Variable::cot}, // Process::zht
441  {} // Process::dr
442  }};
443  // track word assembly, shows which track variables are used by each process
444  static constexpr std::array<std::initializer_list<Variable>, +Process::end> tracks_ = {{
445  {}, // Process::fe
446  {}, // Process::dtc
447  {}, // Process::pp
448  {}, // Process::gp
449  {}, // Process::ht
450  {}, // Process::mht
451  {}, // Process::zht
457  Variable::zT,
458  Variable::cot}, // Process::kfin
465  Variable::zT}, // Process::kf
467  }};
468 
469  public:
470  DataFormats();
471  DataFormats(const edm::ParameterSet& iConfig, const tt::Setup* setup);
473  // bool indicating if hybrid or tmtt being used
474  bool hybrid() const { return iConfig_.getParameter<bool>("UseHybrid"); }
475  // converts bits to ntuple of variables
476  template <typename... Ts>
477  void convertStub(Process p, const tt::Frame& bv, std::tuple<Ts...>& data) const;
478  // converts ntuple of variables to bits
479  template <typename... Ts>
480  void convertStub(Process p, const std::tuple<Ts...>& data, tt::Frame& bv) const;
481  // converts bits to ntuple of variables
482  template <typename... Ts>
483  void convertTrack(Process p, const tt::Frame& bv, std::tuple<Ts...>& data) const;
484  // converts ntuple of variables to bits
485  template <typename... Ts>
486  void convertTrack(Process p, const std::tuple<Ts...>& data, tt::Frame& bv) const;
487  // access to run-time constants
488  const tt::Setup* setup() const { return setup_; }
489  // number of bits being used for specific variable flavour
490  int width(Variable v, Process p) const { return formats_[+v][+p]->width(); }
491  // precision being used for specific variable flavour
492  double base(Variable v, Process p) const { return formats_[+v][+p]->base(); }
493  // number of unused frame bits for a given Stub flavour
495  // number of unused frame bits for a given Track flavour
497  // number of channels of a given process on a TFP
498  int numChannel(Process p) const { return numChannel_[+p]; }
499  // number of channels of a given process for whole system
500  int numStreams(Process p) const { return numStreams_[+p]; }
501  //
502  int numStreamsStubs(Process p) const { return numStreamsStubs_[+p]; }
503  //
504  int numStreamsTracks(Process p) const { return numStreamsTracks_[+p]; }
505  // access to spedific format
506  const DataFormat& format(Variable v, Process p) const { return *formats_[+v][+p]; }
507  // critical radius defining region overlap shape in cm
508  double chosenRofPhi() const { return hybrid() ? setup_->hybridChosenRofPhi() : setup_->chosenRofPhi(); }
509 
510  private:
511  // number of unique data formats
513  // method to count number of unique data formats
514  template <Variable v = Variable::begin, Process p = Process::begin>
515  void countFormats();
516  // constructs data formats of all unique used variables and flavours
517  template <Variable v = Variable::begin, Process p = Process::begin>
518  void fillDataFormats();
519  // helper (loop) data formats of all unique used variables and flavours
520  template <Variable v, Process p, Process it = Process::begin>
521  void fillFormats();
522  // helper (loop) to convert bits to ntuple of variables
523  template <int it = 0, typename... Ts>
524  void extractStub(Process p, TTBV& ttBV, std::tuple<Ts...>& data) const;
525  // helper (loop) to convert bits to ntuple of variables
526  template <int it = 0, typename... Ts>
527  void extractTrack(Process p, TTBV& ttBV, std::tuple<Ts...>& data) const;
528  // helper (loop) to convert ntuple of variables to bits
529  template <int it = 0, typename... Ts>
530  void attachStub(Process p, const std::tuple<Ts...>& data, TTBV& ttBV) const;
531  // helper (loop) to convert ntuple of variables to bits
532  template <int it = 0, typename... Ts>
533  void attachTrack(Process p, const std::tuple<Ts...>& data, TTBV& ttBV) const;
534  // configuration during construction
536  // stored run-time constants
538  // collection of unique formats
539  std::vector<DataFormat> dataFormats_;
540  // variable flavour mapping
541  std::vector<std::vector<DataFormat*>> formats_;
542  // number of unused frame bits for a all Stub flavours
543  std::vector<int> numUnusedBitsStubs_;
544  // number of unused frame bits for a all Track flavours
545  std::vector<int> numUnusedBitsTracks_;
546  // number of channels of all processes on a TFP
547  std::vector<int> numChannel_;
548  // number of channels of all processes for whole system
549  std::vector<int> numStreams_;
550  //
551  std::vector<int> numStreamsStubs_;
552  //
553  std::vector<int> numStreamsTracks_;
554  };
555 
556  // base class to represent stubs
557  template <typename... Ts>
558  class Stub {
559  public:
560  // construct Stub from Frame
562  template <typename... Others>
563  // construct Stub from other Stub
564  Stub(const Stub<Others...>& stub, Ts... data);
565  // construct Stub from TTStubRef
566  Stub(const TTStubRef& ttStubRef, const DataFormats* dataFormats, Process p, Ts... data);
567  Stub() {}
568  ~Stub() {}
569  // true if frame valid, false if gap in data stream
570  explicit operator bool() const { return frame_.first.isNonnull(); }
571  // access to DataFormats
572  const DataFormats* dataFormats() const { return dataFormats_; }
573  // stub flavour
574  Process p() const { return p_; }
575  // acess to frame
576  tt::FrameStub frame() const { return frame_; }
577  // access to TTStubRef
578  TTStubRef ttStubRef() const { return frame_.first; }
579  // access to bitvector
580  tt::Frame bv() const { return frame_.second; }
581  // id of collection this stub belongs to
582  int trackId() const { return trackId_; }
583 
584  protected:
585  // number of used bits for given variable
586  int width(Variable v) const { return dataFormats_->width(v, p_); }
587  // precision of given variable
588  double base(Variable v) const { return dataFormats_->base(v, p_); }
589  // format of given variable
591  // all dataformats
593  // stub flavour
595  // underlying TTStubRef and bitvector
597  // ntuple of variables this stub is assemled of
599  // id of collection this stub belongs to
600  int trackId_;
601  };
602 
603  // class to represent stubs generated by process patch pannel
604  class StubPP : public Stub<double, double, double, int, TTBV, int, int, int, int> {
605  public:
606  // construct StubPP from Frame
608  ~StubPP() {}
609  // true if stub belongs to given sector
610  bool inSector(int sector) const { return sectors_[sector]; }
611  // sectors this stub belongs to
612  std::vector<int> sectors() const { return sectors_.ids(); }
613  // stub radius wrt chosenRofPhi
614  double r() const { return std::get<0>(data_); }
615  // stub phi wrt processing nonant centre
616  double phi() const { return std::get<1>(data_); }
617  // stub z
618  double z() const { return std::get<2>(data_); }
619  // reduced layer id
620  int layer() const { return std::get<3>(data_); }
621  // phi sector map to which this stub belongs to
622  TTBV sectorsPhi() const { return std::get<4>(data_); }
623  // first eta sector this stub belongs to
624  int sectorEtaMin() const { return std::get<5>(data_); }
625  // last eta sector this stub belongs to
626  int sectorEtaMax() const { return std::get<6>(data_); }
627  // first inv2R bin this stub belongs to
628  int inv2RMin() const { return std::get<7>(data_); }
629  // last inv2R bin this stub belongs to
630  int inv2RMax() const { return std::get<8>(data_); }
631 
632  private:
633  // sectors this stub belongs to
635  };
636 
637  // class to represent stubs generated by process geometric processor
638  class StubGP : public Stub<double, double, double, int, int, int> {
639  public:
640  // construct StubGP from Frame
642  // construct StubGO from StubPP
643  StubGP(const StubPP& stub, int sectorPhi, int sectorEta);
644  ~StubGP() {}
645  // true if stub belongs to given inv2R bin
646  bool inInv2RBin(int inv2RBin) const { return inv2RBins_[inv2RBin]; }
647  // inv2R bins this stub belongs to
648  std::vector<int> inv2RBins() const { return inv2RBins_.ids(); }
649  // stub phi sector
650  int sectorPhi() const { return sectorPhi_; }
651  // stub eta sector
652  int sectorEta() const { return sectorEta_; }
653  // stub radius wrt chosenRofPhi
654  double r() const { return std::get<0>(data_); }
655  // stub phi wrt phi sector centre
656  double phi() const { return std::get<1>(data_); }
657  // stub z residual wrt eta sector
658  double z() const { return std::get<2>(data_); }
659  // reduced layer id
660  int layer() const { return std::get<3>(data_); }
661  // first inv2R bin this stub belongs to
662  int inv2RMin() const { return std::get<4>(data_); }
663  // last inv2R bin this stub belongs to
664  int inv2RMax() const { return std::get<5>(data_); }
665 
666  private:
667  // inv2R bins this stub belongs to
669  // stub phi sector
671  // stub eta sector
673  };
674 
675  // class to represent stubs generated by process hough transform
676  class StubHT : public Stub<double, double, double, int, int, int, int> {
677  public:
678  // construct StubHT from Frame
679  StubHT(const tt::FrameStub& frame, const DataFormats* dataFormats, int inv2R);
680  // construct StubHT from StubGP and HT cell assignment
681  StubHT(const StubGP& stub, int phiT, int inv2R);
682  ~StubHT() {}
683  // stub qOver pt
684  int inv2R() const { return inv2R_; }
685  // stub radius wrt chosenRofPhi
686  double r() const { return std::get<0>(data_); };
687  // stub phi residual wrt track parameter
688  double phi() const { return std::get<1>(data_); };
689  // stub z residual wrt eta sector
690  double z() const { return std::get<2>(data_); };
691  // reduced layer id
692  int layer() const { return std::get<3>(data_); };
693  // phi sector
694  int sectorPhi() const { return std::get<4>(data_); };
695  // eta sector
696  int sectorEta() const { return std::get<5>(data_); };
697  // stub phi at radius chosenRofPhi wrt phi sector centre
698  int phiT() const { return std::get<6>(data_); };
699 
700  private:
701  // fills track id
702  void fillTrackId();
703  // stub qOver pt
704  int inv2R_;
705  };
706 
707  // class to represent stubs generated by process mini hough transform
708  class StubMHT : public Stub<double, double, double, int, int, int, int, int> {
709  public:
710  // construct StubMHT from Frame
712  // construct StubMHT from StubHT and MHT cell assignment
713  StubMHT(const StubHT& stub, int phiT, int inv2R);
714  ~StubMHT() {}
715  // stub radius wrt choenRofPhi
716  double r() const { return std::get<0>(data_); }
717  // stub phi residual wrt finer track parameter
718  double phi() const { return std::get<1>(data_); }
719  // stub z rsidual wrt eta sector
720  double z() const { return std::get<2>(data_); }
721  // reduced layer id
722  int layer() const { return std::get<3>(data_); }
723  // phi sector
724  int sectorPhi() const { return std::get<4>(data_); }
725  // eta sector
726  int sectorEta() const { return std::get<5>(data_); }
727  // stub phi at radius chosenRofPhi wrt phi sector centre
728  int phiT() const { return std::get<6>(data_); }
729  // stub inv2R
730  int inv2R() const { return std::get<7>(data_); }
731 
732  private:
733  // fills track id
734  void fillTrackId();
735  };
736 
737  // class to represent stubs generated by process z hough transform
738  class StubZHT : public Stub<double, double, double, int, int, int, int, int, int, int> {
739  public:
740  // construct StubZHT from Frame
742  // construct StubZHT from StubMHT
743  StubZHT(const StubMHT& stub);
744  //
745  StubZHT(const StubZHT& stub, double zT, double cot, int id);
746  //
747  StubZHT(const StubZHT& stub, int cot, int zT);
748  ~StubZHT() {}
749  // stub radius wrt chonseRofPhi
750  double r() const { return std::get<0>(data_); }
751  // stub phiresiudal wrt finer track parameter
752  double phi() const { return std::get<1>(data_); }
753  // stub z residual to track parameter
754  double z() const { return std::get<2>(data_); }
755  // reduced layer id
756  int layer() const { return std::get<3>(data_); }
757  // phi sector
758  int sectorPhi() const { return std::get<4>(data_); }
759  // eta sector
760  int sectorEta() const { return std::get<5>(data_); }
761  // stub phi at radius chosenRofPhi wrt phi sector centre
762  int phiT() const { return std::get<6>(data_); }
763  // stub inv2R
764  int inv2R() const { return std::get<7>(data_); }
765  // stub z at radius chosenRofZ wrt eta sector centre
766  int zT() const { return std::get<8>(data_); }
767  // stub cotTheta wrt eta sector cotTheta
768  int cot() const { return std::get<9>(data_); }
769  double cotf() const { return cot_; }
770  double ztf() const { return zT_; }
771  double chi() const { return chi_; }
772 
773  private:
774  // fills track id
775  void fillTrackId();
776  double r_;
777  double chi_;
778  double cot_;
779  double zT_;
780  };
781 
782  // class to represent stubs generated by process kfin
783  class StubKFin : public Stub<double, double, double, double, double> {
784  public:
785  // construct StubKFin from Frame
787  // construct StubKFin from StubZHT
788  StubKFin(const StubZHT& stub, double dPhi, double dZ, int layer);
789  // construct StubKFin from TTStubRef
791  const DataFormats* dataFormats,
792  double r,
793  double phi,
794  double z,
795  double dPhi,
796  double dZ,
797  int layer);
799  // kf layer id
800  int layer() const { return layer_; }
801  // stub radius wrt chosenRofPhi
802  double r() const { return std::get<0>(data_); }
803  // stub phi residual wrt finer track parameter
804  double phi() const { return std::get<1>(data_); }
805  // stub z residual wrt track parameter
806  double z() const { return std::get<2>(data_); }
807  // stub phi uncertainty
808  double dPhi() const { return std::get<3>(data_); }
809  // stub z uncertainty
810  double dZ() const { return std::get<4>(data_); }
811 
812  private:
813  // kf layer id
814  int layer_;
815  };
816 
817  // class to represent stubs generated by process kalman filter
818  class StubKF : public Stub<double, double, double, double, double> {
819  public:
820  // construct StubKF from Frame
821  StubKF(const tt::FrameStub& frame, const DataFormats* dataFormats, int layer);
822  // construct StubKF from StubKFin
823  StubKF(const StubKFin& stub, double inv2R, double phiT, double cot, double zT);
824  ~StubKF() {}
825  // kf layer id
826  int layer() const { return layer_; }
827  // stub radius wrt choenRofPhi
828  double r() const { return std::get<0>(data_); }
829  // stub phi residual wrt fitted parameter
830  double phi() const { return std::get<1>(data_); }
831  // stub z residual wrt fitted parameter
832  double z() const { return std::get<2>(data_); }
833  // stub phi uncertainty
834  double dPhi() const { return std::get<3>(data_); }
835  // stub z uncertainty
836  double dZ() const { return std::get<4>(data_); }
837 
838  private:
839  // kf layer id
840  int layer_;
841  };
842 
843  // base class to represent tracks
844  template <typename... Ts>
845  class Track {
846  public:
847  // construct Track from Frame
849  // construct Track from other Track
850  template <typename... Others>
851  Track(const Track<Others...>& track, Ts... data);
852  // construct Track from Stub
853  template <typename... Others>
854  Track(const Stub<Others...>& stub, const TTTrackRef& ttTrackRef, Ts... data);
855  // construct Track from TTTrackRef
857  ~Track() {}
858  // true if frame valid, false if gap in data stream
859  explicit operator bool() const { return frame_.first.isNonnull(); }
860  // access to DataFormats
861  const DataFormats* dataFormats() const { return dataFormats_; }
862  // track flavour
863  Process p() const { return p_; }
864  // acces to frame
865  tt::FrameTrack frame() const { return frame_; }
866  // access to TTTrackRef
867  TTTrackRef ttTrackRef() const { return frame_.first; }
868  // access to bitvector
869  tt::Frame bv() const { return frame_.second; }
870  // access to ntuple of variables this track is assemled of
871  std::tuple<Ts...> data() const { return data_; }
872 
873  protected:
874  //number of bits uesd of given variable
875  int width(Variable v) const { return dataFormats_->width(v, p_); }
876  // precision of given variable
877  double base(Variable v) const { return dataFormats_->base(v, p_); }
878  // access to run-time constants
879  const tt::Setup* setup() const { return dataFormats_->setup(); }
880  // format of given variable
882  // format of given variable and process
884  // all data formats
886  // track flavour
888  // underlying TTTrackRef and bitvector
890  // ntuple of variables this track is assemled of
892  };
893 
894  class TrackKFin : public Track<TTBV, int, int, double, double, double, double> {
895  public:
896  // construct TrackKFin from Frame
897  TrackKFin(const tt::FrameTrack& frame, const DataFormats* dataFormats, const std::vector<StubKFin*>& stubs);
898  // construct TrackKFin from StubKFin
899  TrackKFin(const StubZHT& stub, const TTTrackRef& ttTrackRef, const TTBV& maybePattern);
900  // construct TrackKFin from TTTrackRef
902  const DataFormats* dataFormats,
903  const TTBV& maybePattern,
904  double phiT,
905  double qOverPt,
906  double zT,
907  double cot,
908  int sectorPhi,
909  int sectorEta);
911  // pattern of layers which are only maybe crossed by found candidate
912  const TTBV& maybePattern() const { return std::get<0>(data_); }
913  // phi sector
914  int sectorPhi() const { return std::get<1>(data_); }
915  // eta sector
916  int sectorEta() const { return std::get<2>(data_); }
917  // track phi at radius chosenRofPhi wrt phi sector centre
918  double phiT() const { return std::get<3>(data_); }
919  // track inv2R
920  double inv2R() const { return std::get<4>(data_); }
921  // track z at radius chosenRofZ wrt eta sector centre
922  double zT() const { return std::get<5>(data_); }
923  // track cotTheta wrt seta sector cotTheta
924  double cot() const { return std::get<6>(data_); }
925  //
926  TTBV hitPattern() const { return hitPattern_; }
927  // true if given layer has a hit
928  bool hitPattern(int index) const { return hitPattern_[index]; }
929  // true if given layer has a hit or is a maybe layer
930  bool maybePattern(int index) const { return hitPattern_[index] || maybePattern()[index]; }
931  // stubs on a given layer
932  std::vector<StubKFin*> layerStubs(int layer) const { return stubs_[layer]; }
933  // firts stub on a given layer
934  StubKFin* layerStub(int layer) const { return stubs_[layer].front(); }
935  // selection of ttStubRefs for given hit ids on given layers
936  std::vector<TTStubRef> ttStubRefs(const TTBV& hitPattern, const std::vector<int>& layerMap) const;
937  // stubs organized in layer
938  std::vector<std::vector<StubKFin*>> stubs() const { return stubs_; }
939  // global cotTheta
940  double cotGlobal() const { return cot() + setup()->sectorCot(sectorEta()); }
941 
942  private:
943  // stubs organized in layer
944  std::vector<std::vector<StubKFin*>> stubs_;
945  //
947  };
948 
949  // class to represent tracks generated by process kalman filter
950  class TrackKF : public Track<int, int, int, double, double, double, double> {
951  public:
952  // construct TrackKF from Frame
954  // construct TrackKF from TrackKFKFin
955  TrackKF(const TrackKFin& track, double phiT, double inv2R, double zT, double cot);
956  ~TrackKF() {}
957  // true if kf prameter consistent with mht parameter
958  bool match() const { return std::get<0>(data_); }
959  // phi sector
960  int sectorPhi() const { return std::get<1>(data_); }
961  // eta sector
962  int sectorEta() const { return std::get<2>(data_); }
963  // track phi at radius chosenRofPhi wrt phi sector centre
964  double phiT() const { return std::get<3>(data_); }
965  // track qOver pt
966  double inv2R() const { return std::get<4>(data_); }
967  // track cotTheta wrt eta sector cotTheta
968  double cot() const { return std::get<5>(data_); }
969  // track z at radius chosenRofZ wrt eta sector centre
970  double zT() const { return std::get<6>(data_); }
971  // global cotTheta
972  double cotGlobal() const { return cot() + setup()->sectorCot(sectorEta()); }
973  // conversion to TTTrack with given stubs
974  TTTrack<Ref_Phase2TrackerDigi_> ttTrack(const std::vector<StubKF>& stubs) const;
975 
976  private:
977  };
978 
979  //Class to represent KFout 96-bit track for use in distribution server
980  class TrackKFOut {
981  public:
982  TrackKFOut() : TrackKFOut(0, 0, 0, 0, tt::FrameTrack(), 0, 0, false) {}
983  // construct TrackKF from Partial Tracks
987  int sortKey,
988  const tt::FrameTrack& track,
989  int trackID,
990  int linkID,
991  bool valid)
995  sortKey_(sortKey),
996  track_(track),
997  trackID_(trackID),
998  linkID_(linkID),
999  valid_(valid){};
1000 
1002 
1003  int sortKey() const { return sortKey_; }
1004 
1005  bool dataValid() const { return valid_; }
1006 
1007  int trackID() const { return trackID_; }
1008  int linkID() const { return linkID_; }
1009 
1010  TTBV PartialTrack1() const { return PartialTrack1_; }
1011  TTBV PartialTrack2() const { return PartialTrack2_; }
1012  TTBV PartialTrack3() const { return PartialTrack3_; }
1013 
1014  tt::FrameTrack track() const { return track_; }
1015 
1016  private:
1023  int linkID_;
1024  bool valid_;
1025  };
1026 
1027  typedef std::vector<TrackKFOut> TrackKFOutSACollection;
1028  typedef std::shared_ptr<TrackKFOut> TrackKFOutSAPtr;
1029  typedef std::vector<TrackKFOutSAPtr> TrackKFOutSAPtrCollection;
1030  typedef std::vector<std::vector<std::shared_ptr<TrackKFOut>>> TrackKFOutSAPtrCollections;
1031  typedef std::vector<std::vector<std::vector<std::shared_ptr<TrackKFOut>>>> TrackKFOutSAPtrCollectionss;
1032  // class to represent tracks generated by process duplicate removal
1033  class TrackDR : public Track<double, double, double, double> {
1034  public:
1035  // construct TrackDR from Frame
1037  // construct TrackDR from TrackKF
1038  TrackDR(const TrackKF& track);
1040  // track phi at radius 0 wrt processing nonant centre
1041  double phi0() const { return std::get<0>(data_); }
1042  // track inv2R
1043  double inv2R() const { return std::get<1>(data_); }
1044  // track z at radius 0
1045  double z0() const { return std::get<2>(data_); }
1046  // track cotThea
1047  double cot() const { return std::get<3>(data_); }
1048  // conversion to TTTrack
1050 
1051  private:
1052  };
1053 
1054 } // namespace trackerTFP
1055 
1057 
1058 #endif
double cot() const
Definition: DataFormats.h:968
std::vector< std::vector< std::vector< std::shared_ptr< TrackKFOut > > > > TrackKFOutSAPtrCollectionss
Definition: DataFormats.h:1031
double dPhi() const
Definition: DataFormats.h:808
int inv2R() const
Definition: DataFormats.h:764
bool inRange(double d, bool digi=false) const
Definition: DataFormats.h:106
constexpr std::initializer_list< Process > Processes
Definition: DataFormats.h:53
double zT() const
Definition: DataFormats.h:970
StubKFin * layerStub(int layer) const
Definition: DataFormats.h:934
double base(Variable v, Process p) const
Definition: DataFormats.h:492
double r() const
Definition: DataFormats.h:802
bool inInv2RBin(int inv2RBin) const
Definition: DataFormats.h:646
TTBV PartialTrack2() const
Definition: DataFormats.h:1011
Process p() const
Definition: DataFormats.h:863
double phiT() const
Definition: DataFormats.h:964
std::bitset< TTBV::S_ > Frame
Definition: TTTypes.h:58
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
StubGP(const tt::FrameStub &frame, const DataFormats *dataFormats, int sectorPhi, int sectorEta)
Definition: DataFormats.cc:198
double phi() const
Definition: DataFormats.h:718
TTTrack< Ref_Phase2TrackerDigi_ > ttTrack(const std::vector< StubKF > &stubs) const
Definition: DataFormats.cc:484
int trackId() const
Definition: DataFormats.h:582
int sectorEtaMax() const
Definition: DataFormats.h:626
int sectorEta() const
Definition: DataFormats.h:726
double base() const
Definition: DataFormats.h:117
std::vector< int > numUnusedBitsStubs_
Definition: DataFormats.h:543
double phi() const
Definition: DataFormats.h:830
TrackKFOut(TTBV PartialTrack1, TTBV PartialTrack2, TTBV PartialTrack3, int sortKey, const tt::FrameTrack &track, int trackID, int linkID, bool valid)
Definition: DataFormats.h:984
const tt::Setup * setup_
Definition: DataFormats.h:537
tt::FrameTrack frame() const
Definition: DataFormats.h:865
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:20
std::pair< TTStubRef, Frame > FrameStub
Definition: TTTypes.h:60
TTBV ttBV(int i) const
Definition: DataFormats.h:78
int numStreams(Process p) const
Definition: DataFormats.h:500
int sectorPhi() const
Definition: DataFormats.h:694
const TTBV & maybePattern() const
Definition: DataFormats.h:912
Class to process and provide run-time constants used by Track Trigger emulators.
Definition: Setup.h:44
bool inSector(int sector) const
Definition: DataFormats.h:610
int phiT() const
Definition: DataFormats.h:762
double z() const
Definition: DataFormats.h:806
DataFormat format(Variable v, Process p) const
Definition: DataFormats.h:883
void extract(TTBV &in, double &out) const
Definition: DataFormats.h:84
double r() const
Definition: DataFormats.h:716
double dPhi() const
Definition: DataFormats.h:834
int layer() const
Definition: DataFormats.h:660
std::vector< std::vector< std::shared_ptr< TrackKFOut > > > TrackKFOutSAPtrCollections
Definition: DataFormats.h:1030
double cotf() const
Definition: DataFormats.h:769
double cotGlobal() const
Definition: DataFormats.h:972
constexpr Process operator++(Process p)
Definition: DataFormats.h:68
tt::FrameTrack track_
Definition: DataFormats.h:1021
int layer() const
Definition: DataFormats.h:756
double dZ() const
Definition: DataFormats.h:836
void convertStub(Process p, const tt::Frame &bv, std::tuple< Ts... > &data) const
constexpr int pow(int x)
Definition: conifer.h:24
double z() const
Definition: DataFormats.h:618
double chosenRofPhi() const
Definition: Setup.h:213
void extractStub(Process p, TTBV &ttBV, std::tuple< Ts... > &data) const
Definition: DataFormats.cc:111
StubZHT(const tt::FrameStub &frame, const DataFormats *dataFormats)
Definition: DataFormats.cc:271
double r() const
Definition: DataFormats.h:614
TTBV PartialTrack1() const
Definition: DataFormats.h:1010
Process p() const
Definition: DataFormats.h:574
std::vector< std::vector< StubKFin * > > stubs_
Definition: DataFormats.h:944
int phiT() const
Definition: DataFormats.h:698
int inv2R() const
Definition: DataFormats.h:684
void extractTrack(Process p, TTBV &ttBV, std::tuple< Ts... > &data) const
Definition: DataFormats.cc:144
TTBV PartialTrack3() const
Definition: DataFormats.h:1012
int sectorPhi() const
Definition: DataFormats.h:758
DataFormat format(Variable v) const
Definition: DataFormats.h:590
std::vector< int > numStreamsTracks_
Definition: DataFormats.h:553
TTStubRef ttStubRef() const
Definition: DataFormats.h:578
Format(const edm::ParameterSet &iConfig, const tt::Setup *setup)
TTBV sectorsPhi() const
Definition: DataFormats.h:622
Track(const tt::FrameTrack &frame, const DataFormats *dataFormats, Process p)
Definition: DataFormats.cc:393
double phi() const
Definition: DataFormats.h:616
int width(Variable v, Process p) const
Definition: DataFormats.h:490
double chosenRofPhi() const
Definition: DataFormats.h:508
int numChannel(Process p) const
Definition: DataFormats.h:498
int integer(double d) const
Definition: DataFormats.h:96
StubHT(const tt::FrameStub &frame, const DataFormats *dataFormats, int inv2R)
Definition: DataFormats.cc:218
std::pair< TTTrackRef, Frame > FrameTrack
Definition: TTTypes.h:62
StubKFin(const tt::FrameStub &frame, const DataFormats *dataFormats, int layer)
Definition: DataFormats.cc:353
void attach(const double d, TTBV &ttBV) const
Definition: DataFormats.h:90
double zT() const
Definition: DataFormats.h:922
int sectorEta() const
Definition: DataFormats.h:696
const DataFormats * dataFormats_
Definition: DataFormats.h:592
#define EVENTSETUP_DATA_DEFAULT_RECORD(_data_, _record_)
int sectorPhi() const
Definition: DataFormats.h:960
int layer() const
Definition: DataFormats.h:826
Definition: TTTypes.h:54
int layer() const
Definition: DataFormats.h:722
double z() const
Definition: DataFormats.h:832
TTBV hitPattern() const
Definition: DataFormats.h:926
double phiT() const
Definition: DataFormats.h:918
double inv2R() const
Definition: DataFormats.h:966
double inv2R() const
Definition: DataFormats.h:1043
TrackDR(const tt::FrameTrack &frame, const DataFormats *dataFormats)
Definition: DataFormats.cc:523
TTBV ttBV(double d) const
Definition: DataFormats.h:80
int layer() const
Definition: DataFormats.h:692
std::vector< int > ids(bool b=true, bool singed=false) const
Definition: TTBV.h:334
tt::FrameTrack frame_
Definition: DataFormats.h:889
void attach(const TTBV bv, TTBV &ttBV) const
Definition: DataFormats.h:92
tt::FrameTrack track() const
Definition: DataFormats.h:1014
int sectorPhi() const
Definition: DataFormats.h:724
double cot() const
Definition: DataFormats.h:924
const DataFormats * dataFormats_
Definition: DataFormats.h:885
std::tuple< Ts... > data() const
Definition: DataFormats.h:871
double r() const
Definition: DataFormats.h:686
double r() const
Definition: DataFormats.h:750
double floating(int i) const
Definition: DataFormats.h:94
double cotGlobal() const
Definition: DataFormats.h:940
double phi0() const
Definition: DataFormats.h:1041
int sectorEta() const
Definition: DataFormats.h:962
int numUnusedBitsTracks(Process p) const
Definition: DataFormats.h:496
double range() const
Definition: DataFormats.h:119
const DataFormats * dataFormats() const
Definition: DataFormats.h:572
const tt::Setup * setup() const
Definition: DataFormats.h:879
bool maybePattern(int index) const
Definition: DataFormats.h:930
double phi() const
Definition: DataFormats.h:752
int width(Variable v) const
Definition: DataFormats.h:875
std::shared_ptr< TrackKFOut > TrackKFOutSAPtr
Definition: DataFormats.h:1028
tt::Frame bv() const
Definition: DataFormats.h:869
int sectorPhi() const
Definition: DataFormats.h:914
void attachTrack(Process p, const std::tuple< Ts... > &data, TTBV &ttBV) const
StubPP(const tt::FrameStub &frame, const DataFormats *dataFormats)
Definition: DataFormats.cc:191
d
Definition: ztail.py:151
TrackKFin(const tt::FrameTrack &frame, const DataFormats *dataFormats, const std::vector< StubKFin *> &stubs)
Definition: DataFormats.cc:416
static constexpr std::array< std::initializer_list< Variable >,+Process::end > stubs_
Definition: DataFormats.h:393
bool match() const
Definition: DataFormats.h:958
std::vector< int > sectors() const
Definition: DataFormats.h:612
int inv2RMin() const
Definition: DataFormats.h:662
int sectorPhi() const
Definition: DataFormats.h:650
int width(Variable v) const
Definition: DataFormats.h:586
double hybridChosenRofPhi() const
Definition: Setup.h:266
TTTrackRef ttTrackRef() const
Definition: DataFormats.h:867
int sectorEtaMin() const
Definition: DataFormats.h:624
int inv2RMax() const
Definition: DataFormats.h:664
std::vector< TrackKFOutSAPtr > TrackKFOutSAPtrCollection
Definition: DataFormats.h:1029
int toUnsigned(double d) const
Definition: DataFormats.h:104
std::vector< std::vector< DataFormat * > > formats_
Definition: DataFormats.h:541
const DataFormats * dataFormats() const
Definition: DataFormats.h:861
std::vector< int > inv2RBins() const
Definition: DataFormats.h:648
static constexpr std::array< std::array< Process,+Process::end >,+Variable::end > config_
Definition: DataFormats.h:219
double r() const
Definition: DataFormats.h:828
const tt::Setup * setup() const
Definition: DataFormats.h:488
void attachStub(Process p, const std::tuple< Ts... > &data, TTBV &ttBV) const
bool dataValid() const
Definition: DataFormats.h:1005
std::vector< StubKFin * > layerStubs(int layer) const
Definition: DataFormats.h:932
double z() const
Definition: DataFormats.h:720
int inv2R() const
Definition: DataFormats.h:730
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
edm::ParameterSet iConfig_
Definition: DataFormats.h:535
tt::Frame bv() const
Definition: DataFormats.h:580
int toSigned(int i) const
Definition: DataFormats.h:100
void convertTrack(Process p, const tt::Frame &bv, std::tuple< Ts... > &data) const
double r() const
Definition: DataFormats.h:654
std::vector< DataFormat > dataFormats_
Definition: DataFormats.h:539
double ztf() const
Definition: DataFormats.h:770
int numStreamsTracks(Process p) const
Definition: DataFormats.h:504
std::tuple< Ts... > data_
Definition: DataFormats.h:891
double dZ() const
Definition: DataFormats.h:810
void extract(TTBV &in, int &out) const
Definition: DataFormats.h:82
int sectorEta() const
Definition: DataFormats.h:760
double phi() const
Definition: DataFormats.h:688
double phi() const
Definition: DataFormats.h:656
StubMHT(const tt::FrameStub &frame, const DataFormats *dataFormats)
Definition: DataFormats.cc:239
int toUnsigned(int i) const
Definition: DataFormats.h:102
std::vector< TTStubRef > ttStubRefs(const TTBV &hitPattern, const std::vector< int > &layerMap) const
Definition: DataFormats.cc:458
TTTrack< Ref_Phase2TrackerDigi_ > ttTrack() const
Definition: DataFormats.cc:536
bool hitPattern(int index) const
Definition: DataFormats.h:928
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
TrackKF(const tt::FrameTrack &frame, const DataFormats *dataFormats)
Definition: DataFormats.cc:468
int numStreamsStubs(Process p) const
Definition: DataFormats.h:502
static constexpr std::array< std::initializer_list< Variable >,+Process::end > tracks_
Definition: DataFormats.h:444
int layer() const
Definition: DataFormats.h:620
double chi() const
Definition: DataFormats.h:771
int sectorEta() const
Definition: DataFormats.h:652
bool inRange(int i) const
Definition: DataFormats.h:111
StubKF(const tt::FrameStub &frame, const DataFormats *dataFormats, int layer)
Definition: DataFormats.cc:376
std::tuple< Ts... > data_
Definition: DataFormats.h:598
void attach(const int i, TTBV &ttBV) const
Definition: DataFormats.h:88
std::vector< int > numUnusedBitsTracks_
Definition: DataFormats.h:545
constexpr int operator+(Process p)
Definition: DataFormats.h:64
double z0() const
Definition: DataFormats.h:1045
void extract(TTBV &in, TTBV &out) const
Definition: DataFormats.h:86
std::vector< int > numStreamsStubs_
Definition: DataFormats.h:551
DataFormat format(Variable v) const
Definition: DataFormats.h:881
double inv2R() const
Definition: DataFormats.h:920
tt::FrameStub frame() const
Definition: DataFormats.h:576
Class to calculate and provide dataformats used by Track Trigger emulator.
Definition: DataFormats.h:216
std::vector< std::vector< StubKFin * > > stubs() const
Definition: DataFormats.h:938
tt::FrameStub frame_
Definition: DataFormats.h:596
double digi(double d) const
Definition: DataFormats.h:98
double sectorCot(int eta) const
Definition: Setup.h:428
int sectorEta() const
Definition: DataFormats.h:916
std::vector< int > numChannel_
Definition: DataFormats.h:547
double z() const
Definition: DataFormats.h:658
int numUnusedBitsStubs(Process p) const
Definition: DataFormats.h:494
double base(Variable v) const
Definition: DataFormats.h:588
double z() const
Definition: DataFormats.h:690
int inv2RMax() const
Definition: DataFormats.h:630
double cot() const
Definition: DataFormats.h:1047
double z() const
Definition: DataFormats.h:754
double phi() const
Definition: DataFormats.h:804
int phiT() const
Definition: DataFormats.h:728
std::vector< TrackKFOut > TrackKFOutSACollection
Definition: DataFormats.h:1027
const DataFormat & format(Variable v, Process p) const
Definition: DataFormats.h:506
std::vector< int > numStreams_
Definition: DataFormats.h:549
double base(Variable v) const
Definition: DataFormats.h:877
int inv2RMin() const
Definition: DataFormats.h:628