CMS 3D CMS Logo

Projection.cc
Go to the documentation of this file.
1 
4 
6 #include <algorithm>
7 
8 using namespace std;
9 using namespace trklet;
10 
11 void Projection::init(Settings const& settings,
12  unsigned int layerdisk,
13  int iphiproj,
14  int irzproj,
15  int iphider,
16  int irzder,
17  double phiproj,
18  double rzproj,
19  double phiprojder,
20  double rzprojder,
21  double phiprojapprox,
22  double rzprojapprox,
23  double phiprojderapprox,
24  double rzprojderapprox,
25  bool isPSseed) {
26  assert(layerdisk < N_LAYER + N_DISK);
27 
28  valid_ = true;
29 
30  fpgaphiproj_.set(iphiproj, settings.nphibitsstub(layerdisk), true, __LINE__, __FILE__);
31 
32  if (layerdisk < N_LAYER) {
33  fpgarzproj_.set(irzproj, settings.nzbitsstub(layerdisk), false, __LINE__, __FILE__);
34  } else {
35  fpgarzproj_.set(irzproj, settings.nrbitsstub(layerdisk), false, __LINE__, __FILE__);
36  }
37 
38  if (layerdisk < N_LAYER) {
39  if (layerdisk < N_PSLAYER) {
40  fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__);
41  fpgarzprojder_.set(irzder, settings.nbitszprojderL123(), false, __LINE__, __FILE__);
42  } else {
43  fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL456(), false, __LINE__, __FILE__);
44  fpgarzprojder_.set(irzder, settings.nbitszprojderL456(), false, __LINE__, __FILE__);
45  }
46  } else {
47  fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__);
48  fpgarzprojder_.set(irzder, settings.nrbitsprojderdisk(), false, __LINE__, __FILE__);
49  }
50 
51  if (layerdisk < N_LAYER) {
56  int offset = isPSseed ? 1 : 4;
57 
58  int ztemp = fpgarzproj_.value() >> (fpgarzproj_.nbits() - settings.MEBinsBits() - NFINERZBITS);
59  unsigned int zbin1 = (1 << (settings.MEBinsBits() - 1)) + ((ztemp - offset) >> NFINERZBITS);
60  unsigned int zbin2 = (1 << (settings.MEBinsBits() - 1)) + ((ztemp + offset) >> NFINERZBITS);
61 
62  if (zbin1 >= settings.MEBins()) {
63  zbin1 = 0; //note that zbin1 is unsigned
64  }
65  if (zbin2 >= settings.MEBins()) {
66  zbin2 = settings.MEBins() - 1;
67  }
68 
69  assert(zbin1 <= zbin2);
70  assert(zbin2 - zbin1 <= 1);
71 
72  fpgarzbin1projvm_.set(zbin1, settings.MEBinsBits(), true, __LINE__, __FILE__); // first z bin
73 
74  int nextbin = zbin1 != zbin2;
75  fpgarzbin2projvm_.set(nextbin, 1, true, __LINE__, __FILE__); // need to check adjacent z bin?
76 
77  //fine vm z bits. Use 4 bits for fine position. starting at zbin 1
78  int finez = ((1 << (settings.MEBinsBits() + NFINERZBITS - 1)) + ztemp) - (zbin1 << NFINERZBITS);
79 
80  fpgafinerzvm_.set(finez, NFINERZBITS + 1, true, __LINE__, __FILE__); // fine z postions starting at zbin1
81 
82  } else {
83  //TODO the -3 and +3 should be evaluated and efficiency for matching hits checked.
84  //This code should be migrated in the ProjectionRouter
85  double roffset = 3.0;
86  int rbin1 = 8.0 * (irzproj * settings.krprojshiftdisk() - roffset - settings.rmindiskvm()) /
87  (settings.rmaxdisk() - settings.rmindiskvm());
88  int rbin2 = 8.0 * (irzproj * settings.krprojshiftdisk() + roffset - settings.rmindiskvm()) /
89  (settings.rmaxdisk() - settings.rmindiskvm());
90 
91  if (rbin1 < 0) {
92  rbin1 = 0;
93  }
94  rbin2 = clamp(rbin2, 0, 7);
95 
96  assert(rbin1 <= rbin2);
97  assert(rbin2 - rbin1 <= 1);
98 
99  int finer = 64 *
100  ((irzproj * settings.krprojshiftdisk() - settings.rmindiskvm()) -
101  rbin1 * (settings.rmaxdisk() - settings.rmindiskvm()) / 8.0) /
102  (settings.rmaxdisk() - settings.rmindiskvm());
103 
104  finer = clamp(finer, 0, 15);
105 
106  int diff = rbin1 != rbin2;
107  if (irzder < 0)
108  rbin1 += 8;
109 
110  fpgarzbin1projvm_.set(rbin1, 4, true, __LINE__, __FILE__); // first r bin
111  fpgarzbin2projvm_.set(diff, 1, true, __LINE__, __FILE__); // need to check adjacent r bin
112 
113  fpgafinerzvm_.set(finer, 4, true, __LINE__, __FILE__); // fine r postions starting at rbin1
114  }
115 
116  //fine phi bits
117  int projfinephi =
118  (fpgaphiproj_.value() >>
119  (fpgaphiproj_.nbits() - (settings.nbitsallstubs(layerdisk) + settings.nbitsvmme(layerdisk) + NFINEPHIBITS))) &
120  ((1 << NFINEPHIBITS) - 1);
121  fpgafinephivm_.set(projfinephi, NFINEPHIBITS, true, __LINE__, __FILE__); // fine phi postions
122 
123  phiproj_ = phiproj;
124  rzproj_ = rzproj;
125  phiprojder_ = phiprojder;
126  rzprojder_ = rzprojder;
127 
128  phiprojapprox_ = phiprojapprox;
129  rzprojapprox_ = rzprojapprox;
130  phiprojderapprox_ = phiprojderapprox;
131  rzprojderapprox_ = rzprojderapprox;
132 }
unsigned int MEBinsBits() const
Definition: Settings.h:221
constexpr int N_DISK
Definition: Settings.h:22
unsigned int nrbitsstub(unsigned int layerdisk) const
Definition: Settings.h:84
int init
Definition: HydjetWrapper.h:64
double rmindiskvm() const
Definition: Settings.h:327
static const uint16_t valid_
Definition: Constants.h:17
assert(be >=bs)
unsigned int nbitszprojderL456() const
Definition: Settings.h:90
unsigned int nrbitsprojderdisk() const
Definition: Settings.h:86
unsigned int nbitsphiprojderL456() const
Definition: Settings.h:88
unsigned int nbitsallstubs(unsigned int layerdisk) const
Definition: Settings.h:106
unsigned int nzbitsstub(unsigned int layerdisk) const
Definition: Settings.h:82
unsigned int nphibitsstub(unsigned int layerdisk) const
Definition: Settings.h:83
unsigned int nbitszprojderL123() const
Definition: Settings.h:89
unsigned int MEBins() const
Definition: Settings.h:222
unsigned int nbitsvmme(unsigned int layerdisk) const
Definition: Settings.h:103
constexpr unsigned int NFINERZBITS
Definition: Settings.h:33
constexpr unsigned int N_PSLAYER
Definition: Settings.h:23
double rmaxdisk() const
Definition: Settings.h:125
constexpr unsigned int NFINEPHIBITS
Definition: Settings.h:34
unsigned int nbitsphiprojderL123() const
Definition: Settings.h:87
double krprojshiftdisk() const
Definition: Settings.h:413
constexpr int N_LAYER
Definition: Settings.h:21