CMS 3D CMS Logo

VMRouterTable.cc
Go to the documentation of this file.
1 // VMRouterTable: Lookup table used by the VMRouter to route stubs and provide information about which VMStubs are needed by the TrackletEngine
4 
5 #include <algorithm>
6 
7 using namespace std;
8 using namespace trklet;
9 
10 VMRouterTable::VMRouterTable(Settings const& settings) : settings_(settings) {}
11 
12 VMRouterTable::VMRouterTable(Settings const& settings, unsigned int layerdisk) : settings_(settings) {
13  init(layerdisk);
14 }
15 
16 void VMRouterTable::init(unsigned int layerdisk) {
17  zbits_ = settings_.vmrlutzbits(layerdisk);
18  rbits_ = settings_.vmrlutrbits(layerdisk);
19 
20  rbins_ = (1 << rbits_);
21  zbins_ = (1 << zbits_);
22 
23  if (layerdisk < N_LAYER) {
24  zmin_ = -settings_.zlength();
26  rmin_ = settings_.rmean(layerdisk) - settings_.drmax();
27  rmax_ = settings_.rmean(layerdisk) + settings_.drmax();
28  } else {
29  rmin_ = 0;
31  zmin_ = settings_.zmean(layerdisk - N_LAYER) - settings_.dzmax();
32  zmax_ = settings_.zmean(layerdisk - N_LAYER) + settings_.dzmax();
33  }
34 
35  dr_ = (rmax_ - rmin_) / rbins_;
36  dz_ = (zmax_ - zmin_) / zbins_;
37 
39 
40  for (int izbin = 0; izbin < zbins_; izbin++) {
41  for (int irbin = 0; irbin < rbins_; irbin++) {
42  double r = rmin_ + (irbin + 0.5) * dr_;
43  double z = zmin_ + (izbin + 0.5) * dz_;
44 
45  if (layerdisk > (N_LAYER - 1) && irbin < 10) //special case for the tabulated radii in 2S disks
46  r = (layerdisk <= 7) ? settings_.rDSSinner(irbin) : settings_.rDSSouter(irbin);
47 
48  int bin;
49  if (layerdisk < N_LAYER) {
50  double zproj = z * settings_.rmean(layerdisk) / r;
51  bin = NBINS * (zproj + settings_.zlength()) / (2 * settings_.zlength());
52  } else {
53  double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z;
55  }
56  if (bin < 0)
57  bin = 0;
58  if (bin >= NBINS)
59  bin = NBINS - 1;
60  vmrtable_.push_back(bin);
61 
62  if (layerdisk >= N_LAYER) {
63  double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z;
64  bin = 0.5 * NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm());
65  if (bin < 0)
66  bin = 0;
67  if (bin >= NBINS / 2)
68  bin = NBINS / 2 - 1;
69  vmrtabletedisk_.push_back(bin);
70  }
71 
72  if (layerdisk == 0 || layerdisk == 2 || layerdisk == 4 || layerdisk == 6 || layerdisk == 8) {
73  vmrtableteinner_.push_back(getLookup(layerdisk + 1, z, r));
74  }
75 
76  if (layerdisk == 1) {
77  vmrtableteinner_.push_back(getLookup(layerdisk + 1, z, r, 1));
78  }
79 
80  if (layerdisk == 1) { //projection from L2 to D1 for L2L3D1 seeding
81  vmrtableteinnerThird_.push_back(getLookup(6, z, r, 10));
82  }
83 
84  if (layerdisk == 4) { //projection from L5 to L4 for L5L6L4 seeding
85  vmrtableteinnerThird_.push_back(getLookup(3, z, r));
86  }
87 
88  if (layerdisk == 2) { //projection from L3 to L5 for L3L4L2 seeding
89  vmrtableteinnerThird_.push_back(getLookup(1, z, r));
90  }
91 
92  if (layerdisk == 6) { //projection from D1 to L2 for D1D2L2 seeding
93  vmrtableteinnerThird_.push_back(getLookup(1, z, r));
94  }
95 
96  if (layerdisk == 0 || layerdisk == 1) {
97  vmrtableteinneroverlap_.push_back(getLookup(6, z, r, layerdisk + 6));
98  }
99  }
100  }
101 }
102 
103 int VMRouterTable::getLookup(unsigned int layerdisk, double z, double r, int iseed) {
104  double z0cut = settings_.z0cut();
105 
106  if (layerdisk < N_LAYER) {
107  if (iseed == 1 && std::abs(z) < 52.0)
108  return -1;
109 
110  double rmean = settings_.rmean(layerdisk);
111 
112  double rratio1 = rmean / (r + 0.5 * dr_);
113  double rratio2 = rmean / (r - 0.5 * dr_);
114 
115  double z1 = (z - 0.5 * dz_) * rratio1 + z0cut * (rratio1 - 1.0);
116  double z2 = (z + 0.5 * dz_) * rratio1 + z0cut * (rratio1 - 1.0);
117  double z3 = (z - 0.5 * dz_) * rratio2 + z0cut * (rratio2 - 1.0);
118  double z4 = (z + 0.5 * dz_) * rratio2 + z0cut * (rratio2 - 1.0);
119  double z5 = (z - 0.5 * dz_) * rratio1 - z0cut * (rratio1 - 1.0);
120  double z6 = (z + 0.5 * dz_) * rratio1 - z0cut * (rratio1 - 1.0);
121  double z7 = (z - 0.5 * dz_) * rratio2 - z0cut * (rratio2 - 1.0);
122  double z8 = (z + 0.5 * dz_) * rratio2 - z0cut * (rratio2 - 1.0);
123 
124  double zmin = std::min({z1, z2, z3, z4, z5, z6, z7, z8});
125  double zmax = std::max({z1, z2, z3, z4, z5, z6, z7, z8});
126 
128 
129  int zbin1 = NBINS * (zmin + settings_.zlength()) / (2 * settings_.zlength());
130  int zbin2 = NBINS * (zmax + settings_.zlength()) / (2 * settings_.zlength());
131 
132  if (zbin1 >= NBINS)
133  return -1;
134  if (zbin2 < 0)
135  return -1;
136 
137  if (zbin2 >= NBINS)
138  zbin2 = NBINS - 1;
139  if (zbin1 < 0)
140  zbin1 = 0;
141 
142  // This is a 10 bit word:
143  // xxx|yyy|z|rrr
144  // xxx is the delta z window
145  // yyy is the z bin
146  // z is flag to look in next bin
147  // rrr first fine z bin
148  // NOTE : this encoding is not efficient z is one if xxx+rrr is greater than 8
149  // and xxx is only 1,2, or 3
150  // should also reject xxx=0 as this means projection is outside range
151 
152  int value = zbin1 / 8;
153  value *= 2;
154  if (zbin2 / 8 - zbin1 / 8 > 0)
155  value += 1;
156  value *= 8;
157  value += (zbin1 & 7);
158  assert(value / 8 < 15);
159  int deltaz = zbin2 - zbin1;
160  if (deltaz > 7) {
161  deltaz = 7;
162  }
163  assert(deltaz < 8);
164  value += (deltaz << 7);
165 
166  return value;
167 
168  } else {
169  if (std::abs(z) < 2.0 * z0cut)
170  return -1;
171 
172  double zmean = settings_.zmean(layerdisk - N_LAYER);
173  if (z < 0.0)
174  zmean = -zmean;
175 
176  double r1 = (r + 0.5 * dr_) * (zmean + z0cut) / (z + 0.5 * dz_ + z0cut);
177  double r2 = (r - 0.5 * dr_) * (zmean - z0cut) / (z + 0.5 * dz_ - z0cut);
178  double r3 = (r + 0.5 * dr_) * (zmean + z0cut) / (z - 0.5 * dz_ + z0cut);
179  double r4 = (r - 0.5 * dr_) * (zmean - z0cut) / (z - 0.5 * dz_ - z0cut);
180  double r5 = (r + 0.5 * dr_) * (zmean - z0cut) / (z + 0.5 * dz_ - z0cut);
181  double r6 = (r - 0.5 * dr_) * (zmean + z0cut) / (z + 0.5 * dz_ + z0cut);
182  double r7 = (r + 0.5 * dr_) * (zmean - z0cut) / (z - 0.5 * dz_ - z0cut);
183  double r8 = (r - 0.5 * dr_) * (zmean + z0cut) / (z - 0.5 * dz_ + z0cut);
184 
185  double rmin = std::min({r1, r2, r3, r4, r5, r6, r7, r8});
186  double rmax = std::max({r1, r2, r3, r4, r5, r6, r7, r8});
187 
189 
190  double rmindisk = settings_.rmindiskvm();
191  double rmaxdisk = settings_.rmaxdiskvm();
192 
193  if (iseed == 6)
194  rmaxdisk = settings_.rmaxdiskl1overlapvm();
195  if (iseed == 7)
196  rmindisk = settings_.rmindiskl2overlapvm();
197  if (iseed == 10)
198  rmaxdisk = settings_.rmaxdisk();
199 
200  if (rmin > rmaxdisk)
201  return -1;
202  if (rmax > rmaxdisk)
203  rmax = rmaxdisk;
204 
205  if (rmax < rmindisk)
206  return -1;
207  if (rmin < rmindisk)
208  rmin = rmindisk;
209 
210  int rbin1 = NBINS * (rmin - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm());
211  int rbin2 = NBINS * (rmax - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm());
212 
213  if (iseed == 10) {
214  constexpr double rminspec = 40.0;
215  rbin1 = NBINS * (rmin - rminspec) / (settings_.rmaxdisk() - rminspec);
216  rbin2 = NBINS * (rmax - rminspec) / (settings_.rmaxdisk() - rminspec);
217  }
218 
219  if (rbin2 >= NBINS)
220  rbin2 = NBINS - 1;
221  if (rbin1 < 0)
222  rbin1 = 0;
223 
224  // This is a 9 bit word:
225  // xxx|yy|z|rrr
226  // xxx is the delta r window
227  // yy is the r bin yy is three bits for overlaps
228  // z is flag to look in next bin
229  // rrr fine r bin
230  // NOTE : this encoding is not efficient z is one if xxx+rrr is greater than 8
231  // and xxx is only 1,2, or 3
232  // should also reject xxx=0 as this means projection is outside range
233 
234  bool overlap = iseed == 6 || iseed == 7 || iseed == 10;
235 
236  int value = rbin1 / 8;
237  if (overlap) {
238  if (z < 0.0)
239  value += 4;
240  }
241  value *= 2;
242  if (rbin2 / 8 - rbin1 / 8 > 0)
243  value += 1;
244  value *= 8;
245  value += (rbin1 & 7);
246  assert(value / 8 < 15);
247  int deltar = rbin2 - rbin1;
248  if (deltar > 7)
249  deltar = 7;
250  if (overlap) {
251  value += (deltar << 7);
252  } else {
253  value += (deltar << 6);
254  }
255 
256  return value;
257  }
258 }
259 
260 int VMRouterTable::lookup(int zbin, int rbin) {
261  int index = zbin * rbins_ + rbin;
262  assert(index >= 0 && index < (int)vmrtable_.size());
263  return vmrtable_[index];
264 }
265 
266 int VMRouterTable::lookupdisk(int zbin, int rbin) {
267  int index = zbin * rbins_ + rbin;
268  assert(index >= 0 && index < (int)vmrtabletedisk_.size());
269  return vmrtabletedisk_[index];
270 }
271 
272 int VMRouterTable::lookupinner(int zbin, int rbin) {
273  int index = zbin * rbins_ + rbin;
274  assert(index >= 0 && index < (int)vmrtableteinner_.size());
275  return vmrtableteinner_[index];
276 }
277 
278 int VMRouterTable::lookupinneroverlap(int zbin, int rbin) {
279  int index = zbin * rbins_ + rbin;
280  assert(index >= 0 && index < (int)vmrtableteinneroverlap_.size());
282 }
283 
284 int VMRouterTable::lookupinnerThird(int zbin, int rbin) {
285  int index = zbin * rbins_ + rbin;
286  assert(index >= 0 && index < (int)vmrtableteinnerThird_.size());
288 }
trklet::VMRouterTable::getLookup
int getLookup(unsigned int layerdisk, double z, double r, int iseed=-1)
Definition: VMRouterTable.cc:103
Settings.h
trklet::Settings::rmindiskvm
double rmindiskvm() const
Definition: Settings.h:260
trklet::VMRouterTable::vmrtable_
std::vector< int > vmrtable_
Definition: VMRouterTable.h:53
trklet::VMRouterTable::vmrtableteinneroverlap_
std::vector< int > vmrtableteinneroverlap_
Definition: VMRouterTable.h:56
NBINS
const int NBINS
Definition: CaloCachedShapeIntegrator.cc:3
trklet::VMRouterTable::zmax_
double zmax_
Definition: VMRouterTable.h:41
trklet::VMRouterTable::lookupdisk
int lookupdisk(int zbin, int rbin)
Definition: VMRouterTable.cc:266
trklet::Settings::dzmax
double dzmax() const
Definition: Settings.h:106
min
T min(T a, T b)
Definition: MathUtil.h:58
trklet::Settings::rmaxdiskl1overlapvm
double rmaxdiskl1overlapvm() const
Definition: Settings.h:263
VMRouterTable.h
trklet::Settings::vmrlutrbits
unsigned int vmrlutrbits(unsigned int layerdisk) const
Definition: Settings.h:143
trklet::Settings
Definition: Settings.h:26
trklet::Settings::rmindiskl2overlapvm
double rmindiskl2overlapvm() const
Definition: Settings.h:264
cms::cuda::assert
assert(be >=bs)
trklet::VMRouterTable::rbits_
int rbits_
Definition: VMRouterTable.h:47
deltar
Definition: deltar.py:1
trklet::Settings::rmean
double rmean(unsigned int iLayer) const
Definition: Settings.h:128
trklet::VMRouterTable::lookupinneroverlap
int lookupinneroverlap(int zbin, int rbin)
Definition: VMRouterTable.cc:278
trklet::Settings::rDSSinner
double rDSSinner(unsigned int iBin) const
Definition: Settings.h:135
SiStripMonitorCluster_cfi.zmin
zmin
Definition: SiStripMonitorCluster_cfi.py:200
trklet::Settings::rDSSouter
double rDSSouter(unsigned int iBin) const
Definition: Settings.h:138
testProducerWithPsetDescEmpty_cfi.z2
z2
Definition: testProducerWithPsetDescEmpty_cfi.py:41
trklet::VMRouterTable::settings_
Settings const & settings_
Definition: VMRouterTable.h:35
trklet::VMRouterTable::lookup
int lookup(int zbin, int rbin)
Definition: VMRouterTable.cc:260
trklet::VMRouterTable::dz_
double dz_
Definition: VMRouterTable.h:44
trklet::VMRouterTable::dr_
double dr_
Definition: VMRouterTable.h:43
trklet::VMRouterTable::zbits_
int zbits_
Definition: VMRouterTable.h:46
SiStripMonitorCluster_cfi.zmax
zmax
Definition: SiStripMonitorCluster_cfi.py:201
trklet::VMRouterTable::VMRouterTable
VMRouterTable(Settings const &settings)
Definition: VMRouterTable.cc:10
trklet::N_LAYER
constexpr int N_LAYER
Definition: Settings.h:19
trklet::VMRouterTable::lookupinnerThird
int lookupinnerThird(int zbin, int rbin)
Definition: VMRouterTable.cc:284
trklet::Settings::zmean
double zmean(unsigned int iDisk) const
Definition: Settings.h:131
trklet::VMRouterTable::lookupinner
int lookupinner(int zbin, int rbin)
Definition: VMRouterTable.cc:272
trklet::Settings::drmax
double drmax() const
Definition: Settings.h:105
trklet::Settings::rmaxdisk
double rmaxdisk() const
Definition: Settings.h:102
iseed
int iseed
Definition: AMPTWrapper.h:134
trklet::Settings::NLONGVMBINS
unsigned int NLONGVMBINS() const
Definition: Settings.h:272
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
trklet::VMRouterTable::rmin_
double rmin_
Definition: VMRouterTable.h:37
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
value
Definition: value.py:1
goodZToMuMu_cfi.overlap
overlap
Definition: goodZToMuMu_cfi.py:108
trklet
Definition: AllProjectionsMemory.h:9
trklet::VMRouterTable::zmin_
double zmin_
Definition: VMRouterTable.h:40
trklet::VMRouterTable::rbins_
int rbins_
Definition: VMRouterTable.h:50
trklet::VMRouterTable::vmrtableteinnerThird_
std::vector< int > vmrtableteinnerThird_
Definition: VMRouterTable.h:57
trklet::VMRouterTable::vmrtabletedisk_
std::vector< int > vmrtabletedisk_
Definition: VMRouterTable.h:54
alignCSCRings.r
r
Definition: alignCSCRings.py:93
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
trklet::VMRouterTable::init
void init(unsigned int layerdisk)
Definition: VMRouterTable.cc:16
std
Definition: JetResolutionObject.h:76
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
trklet::Settings::vmrlutzbits
unsigned int vmrlutzbits(unsigned int layerdisk) const
Definition: Settings.h:142
relativeConstraints.value
value
Definition: relativeConstraints.py:53
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
trklet::VMRouterTable::rmax_
double rmax_
Definition: VMRouterTable.h:38
trklet::Settings::z0cut
double z0cut() const
Definition: Settings.h:269
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
trklet::VMRouterTable::vmrtableteinner_
std::vector< int > vmrtableteinner_
Definition: VMRouterTable.h:55
trklet::VMRouterTable::zbins_
int zbins_
Definition: VMRouterTable.h:49
trklet::Settings::rmaxdiskvm
double rmaxdiskvm() const
Definition: Settings.h:261
trklet::Settings::zlength
double zlength() const
Definition: Settings.h:101