CMS 3D CMS Logo

TrackletCalculatorBase.cc
Go to the documentation of this file.
9 
14 
15 using namespace std;
16 using namespace trklet;
17 
18 TrackletCalculatorBase::TrackletCalculatorBase(string name, Settings const& settings, Globals* global)
19  : ProcessBase(name, settings, global) {}
20 
22  double z1,
23  double phi1,
24  double r2,
25  double z2,
26  double phi2,
27  double,
28  double& rinv,
29  double& phi0,
30  double& t,
31  double& z0,
32  double phiproj[N_LAYER - 2],
33  double zproj[N_LAYER - 2],
34  double phider[N_LAYER - 2],
35  double zder[N_LAYER - 2],
36  double phiprojdisk[N_DISK],
37  double rprojdisk[N_DISK],
38  double phiderdisk[N_DISK],
39  double rderdisk[N_DISK]) {
40  double deltaphi = reco::reduceRange(phi1 - phi2);
41 
42  double dist = sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi));
43 
44  rinv = 2 * sin(deltaphi) / dist;
45 
46  double phi1tmp = phi1 - phimin_;
47 
48  phi0 = reco::reduceRange(phi1tmp + asin(0.5 * r1 * rinv));
49 
50  double rhopsi1 = 2 * asin(0.5 * r1 * rinv) / rinv;
51  double rhopsi2 = 2 * asin(0.5 * r2 * rinv) / rinv;
52 
53  t = (z1 - z2) / (rhopsi1 - rhopsi2);
54 
55  z0 = z1 - t * rhopsi1;
56 
57  for (unsigned int i = 0; i < N_LAYER - 2; i++) {
59  rinv,
60  phi0,
61  t,
62  z0,
63  phiproj[i],
64  zproj[i],
65  phider[i],
66  zder[i]);
67  }
68 
69  for (unsigned int i = 0; i < N_DISK; i++) {
70  exactprojdisk(settings_.zmean(i), rinv, phi0, t, z0, phiprojdisk[i], rprojdisk[i], phiderdisk[i], rderdisk[i]);
71  }
72 }
73 
75  double z1,
76  double phi1,
77  double r2,
78  double z2,
79  double phi2,
80  double,
81  double& rinv,
82  double& phi0,
83  double& t,
84  double& z0,
85  double phiprojLayer[N_PSLAYER], //=3 (project to PS barrel layers only)
86  double zprojLayer[N_PSLAYER],
87  double phiderLayer[N_PSLAYER],
88  double zderLayer[N_PSLAYER],
89  double phiproj[N_DISK - 2], //=3 (max project to 3 other disks)
90  double rproj[N_DISK - 2],
91  double phider[N_DISK - 2],
92  double rder[N_DISK - 2]) {
93  double deltaphi = reco::reduceRange(phi1 - phi2);
94 
95  double dist = sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi));
96 
97  rinv = 2 * sin(deltaphi) / dist;
98 
99  double phi1tmp = phi1 - phimin_;
100 
101  phi0 = reco::reduceRange(phi1tmp + asin(0.5 * r1 * rinv));
102 
103  double rhopsi1 = 2 * asin(0.5 * r1 * rinv) / rinv;
104  double rhopsi2 = 2 * asin(0.5 * r2 * rinv) / rinv;
105 
106  t = (z1 - z2) / (rhopsi1 - rhopsi2);
107 
108  z0 = z1 - t * rhopsi1;
109 
110  for (unsigned int i = 0; i < N_DISK - 2; i++) {
112  rinv,
113  phi0,
114  t,
115  z0,
116  phiproj[i],
117  rproj[i],
118  phider[i],
119  rder[i]);
120  }
121 
122  for (unsigned int i = 0; i < N_DISK - 2; i++) {
123  exactproj(settings_.rmean(i), rinv, phi0, t, z0, phiprojLayer[i], zprojLayer[i], phiderLayer[i], zderLayer[i]);
124  }
125 }
126 
128  double z1,
129  double phi1,
130  double r2,
131  double z2,
132  double phi2,
133  double,
134  double& rinv,
135  double& phi0,
136  double& t,
137  double& z0,
138  double phiprojLayer[N_PSLAYER],
139  double zprojLayer[N_PSLAYER],
140  double phiderLayer[N_PSLAYER],
141  double zderLayer[N_PSLAYER],
142  double phiproj[N_DISK - 2],
143  double rproj[N_DISK - 2],
144  double phider[N_DISK - 2],
145  double rder[N_DISK - 2]) {
146  double deltaphi = reco::reduceRange(phi1 - phi2);
147 
148  double dist = sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi));
149 
150  rinv = 2 * sin(deltaphi) / dist;
151 
152  if (r1 > r2)
153  rinv = -rinv;
154 
155  double phi1tmp = phi1 - phimin_;
156 
157  phi0 = reco::reduceRange(phi1tmp + asin(0.5 * r1 * rinv));
158 
159  double rhopsi1 = 2 * asin(0.5 * r1 * rinv) / rinv;
160  double rhopsi2 = 2 * asin(0.5 * r2 * rinv) / rinv;
161 
162  t = (z1 - z2) / (rhopsi1 - rhopsi2);
163 
164  z0 = z1 - t * rhopsi1;
165 
166  for (int i = 0; i < 4; i++) {
167  exactprojdisk(settings_.zmean(i + 1), rinv, phi0, t, z0, phiproj[i], rproj[i], phider[i], rder[i]);
168  }
169 
170  for (int i = 0; i < 1; i++) {
171  exactproj(settings_.rmean(i), rinv, phi0, t, z0, phiprojLayer[i], zprojLayer[i], phiderLayer[i], zderLayer[i]);
172  }
173 }
174 
176  double rinv,
177  double phi0,
178  double t,
179  double z0,
180  double& phiproj,
181  double& zproj,
182  double& phider,
183  double& zder) {
184  phiproj = phi0 - asin(0.5 * rproj * rinv);
185  zproj = z0 + (2 * t / rinv) * asin(0.5 * rproj * rinv);
186 
187  phider = -0.5 * rinv / sqrt(1 - pow(0.5 * rproj * rinv, 2));
188  zder = t / sqrt(1 - pow(0.5 * rproj * rinv, 2));
189 }
190 
192  double rinv,
193  double phi0,
194  double t,
195  double z0,
196  double& phiproj,
197  double& rproj,
198  double& phider,
199  double& rder) {
200  if (t < 0)
201  zproj = -zproj;
202 
203  double tmp = rinv * (zproj - z0) / (2.0 * t);
204  rproj = (2.0 / rinv) * sin(tmp);
205  phiproj = phi0 - tmp;
206 
207  phider = -rinv / (2 * t);
208  rder = cos(tmp) / t;
209 }
210 
212  disk = std::abs(disk);
213 
214  FPGAWord fpgar = tracklet->proj(N_LAYER + disk - 1).fpgarzproj();
215 
216  if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm())
217  return;
218  if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk())
219  return;
220 
221  FPGAWord fpgaphi = tracklet->proj(N_LAYER + disk - 1).fpgaphiproj();
222 
223  int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5);
224 
225  int iphi = iphivmRaw / (32 / settings_.nallstubs(disk + N_LAYER - 1));
226 
227  addProjectionDisk(disk, iphi, trackletprojdisks_[disk - 1][iphi], tracklet);
228 }
229 
230 bool TrackletCalculatorBase::addLayerProj(Tracklet* tracklet, int layer) {
231  assert(layer > 0);
232 
233  FPGAWord fpgaz = tracklet->proj(layer - 1).fpgarzproj();
234  FPGAWord fpgaphi = tracklet->proj(layer - 1).fpgaphiproj();
235 
236  if (fpgaphi.atExtreme())
237  edm::LogProblem("Tracklet") << "at extreme! " << fpgaphi.value();
238 
239  assert(!fpgaphi.atExtreme());
240 
241  if (fpgaz.atExtreme())
242  return false;
243 
244  if (std::abs(fpgaz.value() * settings_.kz()) > settings_.zlength())
245  return false;
246 
247  int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5);
248  int iphi = iphivmRaw / (32 / settings_.nallstubs(layer - 1));
249 
250  addProjection(layer, iphi, trackletprojlayers_[layer - 1][iphi], tracklet);
251 
252  return true;
253 }
254 
256  int iphi,
257  TrackletProjectionsMemory* trackletprojs,
258  Tracklet* tracklet) {
259  if (trackletprojs == nullptr) {
260  if (settings_.warnNoMem()) {
261  edm::LogVerbatim("Tracklet") << "No projection memory exists in " << getName() << " for layer = " << layer
262  << " iphi = " << iphi + 1;
263  }
264  return;
265  }
266  assert(trackletprojs != nullptr);
267  trackletprojs->addProj(tracklet);
268 }
269 
271  int iphi,
272  TrackletProjectionsMemory* trackletprojs,
273  Tracklet* tracklet) {
274  if (iSeed_ == Seed::L3L4 && abs(disk) == 4)
275  return; //L3L4 projections to D3 are not used. Should be in configuration
276  if (trackletprojs == nullptr) {
277  if (iSeed_ == Seed::L3L4 && abs(disk) == 3)
278  return; //L3L4 projections to D3 are not used.
279  if (settings_.warnNoMem()) {
280  edm::LogVerbatim("Tracklet") << "No projection memory exists in " << getName() << " for disk = " << abs(disk)
281  << " iphi = " << iphi + 1;
282  }
283  return;
284  }
285  assert(trackletprojs != nullptr);
286  trackletprojs->addProj(tracklet);
287 }
288 
289 bool TrackletCalculatorBase::goodTrackPars(bool goodrinv, bool goodz0) {
290  bool success = true;
291  if (!goodrinv) {
292  if (settings_.debugTracklet()) {
293  edm::LogVerbatim("Tracklet") << getName() << " TrackletCalculatorBase irinv too large";
294  }
295  success = false;
296  }
297  if (!goodz0) {
298  if (settings_.debugTracklet()) {
299  edm::LogVerbatim("Tracklet") << getName() << " TrackletCalculatorBase z0 cut to large";
300  }
301  success = false;
302  }
303  return success;
304 }
305 
306 bool TrackletCalculatorBase::inSector(int iphi0, int irinv, double phi0approx, double rinvapprox) {
307  double phicritapprox = phi0approx - asin(0.5 * settings_.rcrit() * rinvapprox);
308 
309  int ifactor = 0.5 * settings_.rcrit() * settings_.krinvpars() / settings_.kphi0pars() * (1 << 8);
310  int iphicrit = iphi0 - (irinv >> 8) * ifactor;
311 
312  int iphicritmincut = settings_.phicritminmc() / globals_->ITC_L1L2()->phi0_final.K();
313  int iphicritmaxcut = settings_.phicritmaxmc() / globals_->ITC_L1L2()->phi0_final.K();
314 
315  bool keepapprox = (phicritapprox > settings_.phicritminmc()) && (phicritapprox < settings_.phicritmaxmc()),
316  keep = (iphicrit > iphicritmincut) && (iphicrit < iphicritmaxcut);
317  if (settings_.debugTracklet())
318  if (keepapprox && !keep)
319  edm::LogVerbatim("Tracklet") << getName()
320  << " Tracklet kept with exact phicrit cut but not approximate, phicritapprox: "
321  << phicritapprox;
322  if (settings_.usephicritapprox()) {
323  return keepapprox;
324  } else {
325  return keep;
326  }
327 
328  return true;
329 }
330 
331 bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub,
332  const L1TStub* innerStub,
333  const Stub* outerFPGAStub,
334  const L1TStub* outerStub) {
335  if (settings_.debugTracklet()) {
336  edm::LogVerbatim("Tracklet") << "TrackletCalculatorBase " << getName()
337  << " trying stub pair in layer (inner outer): " << innerFPGAStub->layer().value()
338  << " " << outerFPGAStub->layer().value();
339  }
340 
341  assert(outerFPGAStub->layerdisk() < N_LAYER);
342  assert(layerdisk1_ == (unsigned int)innerFPGAStub->layer().value());
344 
345  double r1 = innerStub->r();
346  double z1 = innerStub->z();
347  double phi1 = innerStub->phi();
348 
349  double r2 = outerStub->r();
350  double z2 = outerStub->z();
351  double phi2 = outerStub->phi();
352 
353  double rinv, phi0, t, z0;
354 
355  double phiproj[N_LAYER - 2], zproj[N_LAYER - 2], phider[N_LAYER - 2], zder[N_LAYER - 2];
356  double phiprojdisk[N_DISK], rprojdisk[N_DISK], phiderdisk[N_DISK], rderdisk[N_DISK];
357 
358  exacttracklet(r1,
359  z1,
360  phi1,
361  r2,
362  z2,
363  phi2,
364  outerStub->sigmaz(),
365  rinv,
366  phi0,
367  t,
368  z0,
369  phiproj,
370  zproj,
371  phider,
372  zder,
373  phiprojdisk,
374  rprojdisk,
375  phiderdisk,
376  rderdisk);
377 
378  if (settings_.useapprox()) {
379  phi1 = innerFPGAStub->phiapprox(phimin_, phimax_);
380  z1 = innerFPGAStub->zapprox();
381  r1 = innerFPGAStub->rapprox();
382 
383  phi2 = outerFPGAStub->phiapprox(phimin_, phimax_);
384  z2 = outerFPGAStub->zapprox();
385  r2 = outerFPGAStub->rapprox();
386  }
387 
388  double rinvapprox, phi0approx, tapprox, z0approx;
389  double phiprojapprox[N_LAYER - 2], zprojapprox[N_LAYER - 2];
390  double phiprojdiskapprox[N_DISK], rprojdiskapprox[N_DISK];
391 
393  if (iSeed_ == 0)
394  ITC = globals_->ITC_L1L2();
395  else if (iSeed_ == 1)
396  ITC = globals_->ITC_L2L3();
397  else if (iSeed_ == 2)
398  ITC = globals_->ITC_L3L4();
399  else
400  ITC = globals_->ITC_L5L6();
401 
402  ITC->r1.set_fval(r1 - settings_.rmean(layerdisk1_));
404  ITC->z1.set_fval(z1);
405  ITC->z2.set_fval(z2);
406  double sphi1 = angle0to2pi::make0To2pi(phi1 - phimin_);
407  double sphi2 = angle0to2pi::make0To2pi(phi2 - phimin_);
408 
409  ITC->phi1.set_fval(sphi1);
410  ITC->phi2.set_fval(sphi2);
411 
416 
417  ITC->zproj0.set_fval(t > 0 ? settings_.zmean(0) : -settings_.zmean(0));
418  ITC->zproj1.set_fval(t > 0 ? settings_.zmean(1) : -settings_.zmean(1));
419  ITC->zproj2.set_fval(t > 0 ? settings_.zmean(2) : -settings_.zmean(2));
420  ITC->zproj3.set_fval(t > 0 ? settings_.zmean(3) : -settings_.zmean(3));
421  ITC->zproj4.set_fval(t > 0 ? settings_.zmean(4) : -settings_.zmean(4));
422 
423  ITC->rinv_final.calculate();
424  ITC->phi0_final.calculate();
425  ITC->t_final.calculate();
426  ITC->z0_final.calculate();
427 
428  ITC->phiL_0_final.calculate();
429  ITC->phiL_1_final.calculate();
430  ITC->phiL_2_final.calculate();
431  ITC->phiL_3_final.calculate();
432 
433  ITC->zL_0_final.calculate();
434  ITC->zL_1_final.calculate();
435  ITC->zL_2_final.calculate();
436  ITC->zL_3_final.calculate();
437 
438  ITC->phiD_0_final.calculate();
439  ITC->phiD_1_final.calculate();
440  ITC->phiD_2_final.calculate();
441  ITC->phiD_3_final.calculate();
442  ITC->phiD_4_final.calculate();
443 
444  ITC->rD_0_final.calculate();
445  ITC->rD_1_final.calculate();
446  ITC->rD_2_final.calculate();
447  ITC->rD_3_final.calculate();
448  ITC->rD_4_final.calculate();
449 
450  ITC->der_phiL_final.calculate();
451  ITC->der_zL_final.calculate();
452  ITC->der_phiD_final.calculate();
453  ITC->der_rD_final.calculate();
454 
455  //store the approximate results
456  rinvapprox = ITC->rinv_final.fval();
457  phi0approx = ITC->phi0_final.fval();
458  tapprox = ITC->t_final.fval();
459  z0approx = ITC->z0_final.fval();
460 
461  phiprojapprox[0] = ITC->phiL_0_final.fval();
462  phiprojapprox[1] = ITC->phiL_1_final.fval();
463  phiprojapprox[2] = ITC->phiL_2_final.fval();
464  phiprojapprox[3] = ITC->phiL_3_final.fval();
465 
466  zprojapprox[0] = ITC->zL_0_final.fval();
467  zprojapprox[1] = ITC->zL_1_final.fval();
468  zprojapprox[2] = ITC->zL_2_final.fval();
469  zprojapprox[3] = ITC->zL_3_final.fval();
470 
471  phiprojdiskapprox[0] = ITC->phiD_0_final.fval();
472  phiprojdiskapprox[1] = ITC->phiD_1_final.fval();
473  phiprojdiskapprox[2] = ITC->phiD_2_final.fval();
474  phiprojdiskapprox[3] = ITC->phiD_3_final.fval();
475  phiprojdiskapprox[4] = ITC->phiD_4_final.fval();
476 
477  rprojdiskapprox[0] = ITC->rD_0_final.fval();
478  rprojdiskapprox[1] = ITC->rD_1_final.fval();
479  rprojdiskapprox[2] = ITC->rD_2_final.fval();
480  rprojdiskapprox[3] = ITC->rD_3_final.fval();
481  rprojdiskapprox[4] = ITC->rD_4_final.fval();
482 
483  //now binary
484 
485  int irinv, iphi0, it, iz0;
486  Projection projs[N_LAYER + N_DISK];
487 
488  int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2];
489  int iphiprojdisk[N_DISK], irprojdisk[N_DISK];
490 
491  int ir1 = innerFPGAStub->r().value();
492  int iphi1 = innerFPGAStub->phi().value();
493  int iz1 = innerFPGAStub->z().value();
494 
495  int ir2 = outerFPGAStub->r().value();
496  int iphi2 = outerFPGAStub->phi().value();
497  int iz2 = outerFPGAStub->z().value();
498 
501  ir1 <<= (8 - settings_.nrbitsstub(layerdisk1_));
502  ir2 <<= (8 - settings_.nrbitsstub(layerdisk2_));
503 
506 
507  ITC->r1.set_ival(ir1);
508  ITC->r2.set_ival(ir2);
509  ITC->z1.set_ival(iz1);
510  ITC->z2.set_ival(iz2);
511  ITC->phi1.set_ival(iphi1);
512  ITC->phi2.set_ival(iphi2);
513 
514  ITC->rinv_final.calculate();
515  ITC->phi0_final.calculate();
516  ITC->t_final.calculate();
517  ITC->z0_final.calculate();
518 
519  ITC->phiL_0_final.calculate();
520  ITC->phiL_1_final.calculate();
521  ITC->phiL_2_final.calculate();
522  ITC->phiL_3_final.calculate();
523 
524  ITC->zL_0_final.calculate();
525  ITC->zL_1_final.calculate();
526  ITC->zL_2_final.calculate();
527  ITC->zL_3_final.calculate();
528 
529  ITC->phiD_0_final.calculate();
530  ITC->phiD_1_final.calculate();
531  ITC->phiD_2_final.calculate();
532  ITC->phiD_3_final.calculate();
533  ITC->phiD_4_final.calculate();
534 
535  ITC->rD_0_final.calculate();
536  ITC->rD_1_final.calculate();
537  ITC->rD_2_final.calculate();
538  ITC->rD_3_final.calculate();
539  ITC->rD_4_final.calculate();
540 
541  ITC->der_phiL_final.calculate();
542  ITC->der_zL_final.calculate();
543  ITC->der_phiD_final.calculate();
544  ITC->der_rD_final.calculate();
545 
546  //store the binary results
547  irinv = ITC->rinv_final.ival();
548  iphi0 = ITC->phi0_final.ival();
549  it = ITC->t_final.ival();
550  iz0 = ITC->z0_final.ival();
551 
552  iphiproj[0] = ITC->phiL_0_final.ival();
553  iphiproj[1] = ITC->phiL_1_final.ival();
554  iphiproj[2] = ITC->phiL_2_final.ival();
555  iphiproj[3] = ITC->phiL_3_final.ival();
556 
557  izproj[0] = ITC->zL_0_final.ival();
558  izproj[1] = ITC->zL_1_final.ival();
559  izproj[2] = ITC->zL_2_final.ival();
560  izproj[3] = ITC->zL_3_final.ival();
561 
563  if (settings_.debugTracklet()) {
564  edm::LogVerbatim("Tracklet") << getName() << " Failed rinv or z0 cut";
565  }
566  return false;
567  }
568 
569  if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) {
570  if (settings_.debugTracklet()) {
571  edm::LogVerbatim("Tracklet") << getName() << " Failed in sector check";
572  }
573  return false;
574  }
575 
576  for (unsigned int i = 0; i < N_LAYER - 2; ++i) {
577  //reject projection if z is out of range
578  if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1)))
579  continue;
580  if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1)))
581  continue;
582 
583  //reject projection if phi is out of range
584  if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1)
585  continue;
586  if (iphiproj[i] <= 0)
587  continue;
588 
589  //Adjust bits for r and z projection depending on layer
590  if (settings_.projlayers(iSeed_, i) <= 3) { //TODO clean up logic
592  } else {
593  izproj[i] >>= (settings_.nzbitsstub(0) - settings_.nzbitsstub(5));
594  }
595 
596  projs[settings_.projlayers(iSeed_, i) - 1].init(settings_,
598  iphiproj[i],
599  izproj[i],
600  ITC->der_phiL_final.ival(),
601  ITC->der_zL_final.ival(),
602  phiproj[i],
603  zproj[i],
604  phider[i],
605  zder[i],
606  phiprojapprox[i],
607  zprojapprox[i],
608  ITC->der_phiL_final.fval(),
609  ITC->der_zL_final.fval(),
610  !(iSeed_ == 2 || iSeed_ == 3));
611  }
612 
613  iphiprojdisk[0] = ITC->phiD_0_final.ival();
614  iphiprojdisk[1] = ITC->phiD_1_final.ival();
615  iphiprojdisk[2] = ITC->phiD_2_final.ival();
616  iphiprojdisk[3] = ITC->phiD_3_final.ival();
617  iphiprojdisk[4] = ITC->phiD_4_final.ival();
618 
619  irprojdisk[0] = ITC->rD_0_final.ival();
620  irprojdisk[1] = ITC->rD_1_final.ival();
621  irprojdisk[2] = ITC->rD_2_final.ival();
622  irprojdisk[3] = ITC->rD_3_final.ival();
623  irprojdisk[4] = ITC->rD_4_final.ival();
624 
625  if (std::abs(it * ITC->t_final.K()) > 1.0) {
626  for (unsigned int i = 0; i < N_DISK; ++i) {
627  if (iphiprojdisk[i] <= 0)
628  continue;
629  if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1)
630  continue;
631 
632  if (irprojdisk[i] < settings_.rmindisk() / ITC->rD_0_final.K() ||
633  irprojdisk[i] >= settings_.rmaxdisk() / ITC->rD_0_final.K())
634  continue;
635 
636  projs[i + N_LAYER].init(settings_,
637  i + N_LAYER,
638  iphiprojdisk[i],
639  irprojdisk[i],
640  ITC->der_phiD_final.ival(),
641  ITC->der_rD_final.ival(),
642  phiprojdisk[i],
643  rprojdisk[i],
644  phiderdisk[i],
645  rderdisk[i],
646  phiprojdiskapprox[i],
647  rprojdiskapprox[i],
648  ITC->der_phiD_final.fval(),
649  ITC->der_rD_final.fval(),
650  !(iSeed_ == 2 || iSeed_ == 3));
651  }
652  }
653 
654  if (settings_.writeMonitorData("TPars")) {
655  globals_->ofstream("trackletpars.txt")
656  << "Trackpars " << layerdisk1_ + 1 << " " << rinv << " " << rinvapprox << " " << ITC->rinv_final.fval()
657  << " " << phi0 << " " << phi0approx << " " << ITC->phi0_final.fval() << " " << t << " " << tapprox << " "
658  << ITC->t_final.fval() << " " << z0 << " " << z0approx << " " << ITC->z0_final.fval() << endl;
659  }
660 
661  Tracklet* tracklet = new Tracklet(settings_,
662  iSeed_,
663  innerFPGAStub,
664  nullptr,
665  outerFPGAStub,
666  rinv,
667  phi0,
668  0.0,
669  z0,
670  t,
671  rinvapprox,
672  phi0approx,
673  0.0,
674  z0approx,
675  tapprox,
676  irinv,
677  iphi0,
678  0,
679  iz0,
680  it,
681  projs,
682  false);
683 
684  if (settings_.debugTracklet()) {
685  edm::LogVerbatim("Tracklet") << "TrackletCalculator " << getName() << " Found tracklet for seed = " << iSeed_ << " "
686  << iSector_ << " phi0 = " << phi0;
687  }
688 
690  tracklet->setTCIndex(TCIndex_);
691 
692  if (settings_.writeMonitorData("Seeds")) {
693  ofstream fout("seeds.txt", ofstream::app);
694  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() << endl;
695  fout.close();
696  }
697  trackletpars_->addTracklet(tracklet);
698 
699  if (settings_.bookHistos()) {
701  int tp = tracklet->tpseed();
702  hists->fillTrackletParams(settings_,
703  globals_,
704  iSeed_,
705  iSector_,
706  rinvapprox,
707  irinv * ITC->rinv_final.K(),
708  phi0approx,
709  iphi0 * ITC->phi0_final.K(),
710  asinh(tapprox),
711  asinh(it * ITC->t_final.K()),
712  z0approx,
713  iz0 * ITC->z0_final.K(),
714  tp);
715  }
716 
717  bool addL3 = false;
718  bool addL4 = false;
719  bool addL5 = false;
720  bool addL6 = false;
721  for (unsigned int j = 0; j < N_LAYER - 2; j++) {
722  int lproj = settings_.projlayers(iSeed_, j);
723  bool added = false;
724  if (tracklet->validProj(lproj - 1)) {
725  added = addLayerProj(tracklet, lproj);
726  if (added && lproj == 3)
727  addL3 = true;
728  if (added && lproj == 4)
729  addL4 = true;
730  if (added && lproj == 5)
731  addL5 = true;
732  if (added && lproj == 6)
733  addL6 = true;
734  }
735  }
736 
737  for (unsigned int j = 0; j < N_DISK - 1; j++) { //no projections to 5th disk!!
738  int disk = j + 1;
739  if (disk == 4 && addL3)
740  continue;
741  if (disk == 3 && addL4)
742  continue;
743  if (disk == 2 && addL5)
744  continue;
745  if (disk == 1 && addL6)
746  continue;
747  if (it < 0)
748  disk = -disk;
749  if (tracklet->validProj(N_LAYER + abs(disk) - 1)) {
750  addDiskProj(tracklet, disk);
751  }
752  }
753 
754  return true;
755 }
756 
757 bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub,
758  const L1TStub* innerStub,
759  const Stub* outerFPGAStub,
760  const L1TStub* outerStub) {
761  if (settings_.debugTracklet()) {
762  edm::LogVerbatim("Tracklet") << "TrackletCalculator::execute calculate disk seeds";
763  }
764 
765  int sign = 1;
766  if (innerFPGAStub->disk().value() < 0)
767  sign = -1;
768 
769  int disk = innerFPGAStub->disk().value();
770  assert(abs(disk) == 1 || abs(disk) == 3);
771 
772  assert(innerStub->isPSmodule());
773  assert(outerStub->isPSmodule());
774 
775  double r1 = innerStub->r();
776  double z1 = innerStub->z();
777  double phi1 = innerStub->phi();
778 
779  double r2 = outerStub->r();
780  double z2 = outerStub->z();
781  double phi2 = outerStub->phi();
782 
783  if (r2 < r1 + 2.0) {
784  return false; //Protection... Should be handled cleaner to avoid problem with floating point calculation
785  }
786 
787  double rinv, phi0, t, z0;
788 
789  double phiproj[N_PSLAYER], zproj[N_PSLAYER], phider[N_PSLAYER], zder[N_PSLAYER];
790  double phiprojdisk[N_DISK - 2], rprojdisk[N_DISK - 2], phiderdisk[N_DISK - 2], rderdisk[N_DISK - 2];
791 
793  z1,
794  phi1,
795  r2,
796  z2,
797  phi2,
798  outerStub->sigmaz(),
799  rinv,
800  phi0,
801  t,
802  z0,
803  phiproj,
804  zproj,
805  phider,
806  zder,
807  phiprojdisk,
808  rprojdisk,
809  phiderdisk,
810  rderdisk);
811 
812  //Truncates floating point positions to integer representation precision
813  if (settings_.useapprox()) {
814  phi1 = innerFPGAStub->phiapprox(phimin_, phimax_);
815  z1 = innerFPGAStub->zapprox();
816  r1 = innerFPGAStub->rapprox();
817 
818  phi2 = outerFPGAStub->phiapprox(phimin_, phimax_);
819  z2 = outerFPGAStub->zapprox();
820  r2 = outerFPGAStub->rapprox();
821  }
822 
823  double rinvapprox, phi0approx, tapprox, z0approx;
824  double phiprojapprox[N_PSLAYER], zprojapprox[N_PSLAYER];
825  double phiprojdiskapprox[N_DISK - 2], rprojdiskapprox[N_DISK - 2];
826 
828  if (disk == 1)
829  ITC = globals_->ITC_F1F2();
830  else if (disk == 3)
831  ITC = globals_->ITC_F3F4();
832  else if (disk == -1)
833  ITC = globals_->ITC_B1B2();
834  else
835  ITC = globals_->ITC_B3B4();
836 
837  ITC->r1.set_fval(r1);
838  ITC->r2.set_fval(r2);
839  int signt = t > 0 ? 1 : -1;
840  ITC->z1.set_fval(z1 - signt * settings_.zmean(layerdisk1_ - N_LAYER));
841  ITC->z2.set_fval(z2 - signt * settings_.zmean(layerdisk2_ - N_LAYER));
842  double sphi1 = angle0to2pi::make0To2pi(phi1 - phimin_);
843  double sphi2 = angle0to2pi::make0To2pi(phi2 - phimin_);
844  ITC->phi1.set_fval(sphi1);
845  ITC->phi2.set_fval(sphi2);
846 
847  ITC->rproj0.set_fval(settings_.rmean(0));
848  ITC->rproj1.set_fval(settings_.rmean(1));
849  ITC->rproj2.set_fval(settings_.rmean(2));
850 
851  ITC->zproj0.set_fval(signt * settings_.zmean(settings_.projdisks(iSeed_, 0) - 1));
852  ITC->zproj1.set_fval(signt * settings_.zmean(settings_.projdisks(iSeed_, 1) - 1));
853  ITC->zproj2.set_fval(signt * settings_.zmean(settings_.projdisks(iSeed_, 2) - 1));
854 
855  ITC->rinv_final.calculate();
856  ITC->phi0_final.calculate();
857  ITC->t_final.calculate();
858  ITC->z0_final.calculate();
859 
860  ITC->phiL_0_final.calculate();
861  ITC->phiL_1_final.calculate();
862  ITC->phiL_2_final.calculate();
863 
864  ITC->zL_0_final.calculate();
865  ITC->zL_1_final.calculate();
866  ITC->zL_2_final.calculate();
867 
868  ITC->phiD_0_final.calculate();
869  ITC->phiD_1_final.calculate();
870  ITC->phiD_2_final.calculate();
871 
872  ITC->rD_0_final.calculate();
873  ITC->rD_1_final.calculate();
874  ITC->rD_2_final.calculate();
875 
876  ITC->der_phiL_final.calculate();
877  ITC->der_zL_final.calculate();
878  ITC->der_phiD_final.calculate();
879  ITC->der_rD_final.calculate();
880 
881  //store the approximate results
882  rinvapprox = ITC->rinv_final.fval();
883  phi0approx = ITC->phi0_final.fval();
884  tapprox = ITC->t_final.fval();
885  z0approx = ITC->z0_final.fval();
886 
887  phiprojapprox[0] = ITC->phiL_0_final.fval();
888  phiprojapprox[1] = ITC->phiL_1_final.fval();
889  phiprojapprox[2] = ITC->phiL_2_final.fval();
890 
891  zprojapprox[0] = ITC->zL_0_final.fval();
892  zprojapprox[1] = ITC->zL_1_final.fval();
893  zprojapprox[2] = ITC->zL_2_final.fval();
894 
895  phiprojdiskapprox[0] = ITC->phiD_0_final.fval();
896  phiprojdiskapprox[1] = ITC->phiD_1_final.fval();
897  phiprojdiskapprox[2] = ITC->phiD_2_final.fval();
898 
899  rprojdiskapprox[0] = ITC->rD_0_final.fval();
900  rprojdiskapprox[1] = ITC->rD_1_final.fval();
901  rprojdiskapprox[2] = ITC->rD_2_final.fval();
902 
903  //now binary
904 
905  int irinv, iphi0, it, iz0;
906  int iphiproj[N_PSLAYER], izproj[N_PSLAYER];
907 
908  int iphiprojdisk[N_DISK - 2], irprojdisk[N_DISK - 2];
909 
910  int ir1 = innerFPGAStub->r().value();
911  int iphi1 = innerFPGAStub->phi().value();
912  int iz1 = innerFPGAStub->z().value();
913 
914  int ir2 = outerFPGAStub->r().value();
915  int iphi2 = outerFPGAStub->phi().value();
916  int iz2 = outerFPGAStub->z().value();
917 
918  //To get same precission as for layers.
919  iphi1 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0));
920  iphi2 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0));
921 
922  ITC->r1.set_ival(ir1);
923  ITC->r2.set_ival(ir2);
924  ITC->z1.set_ival(iz1);
925  ITC->z2.set_ival(iz2);
926  ITC->phi1.set_ival(iphi1);
927  ITC->phi2.set_ival(iphi2);
928 
929  ITC->rinv_final.calculate();
930  ITC->phi0_final.calculate();
931  ITC->t_final.calculate();
932  ITC->z0_final.calculate();
933 
934  ITC->phiL_0_final.calculate();
935  ITC->phiL_1_final.calculate();
936  ITC->phiL_2_final.calculate();
937 
938  ITC->zL_0_final.calculate();
939  ITC->zL_1_final.calculate();
940  ITC->zL_2_final.calculate();
941 
942  ITC->phiD_0_final.calculate();
943  ITC->phiD_1_final.calculate();
944  ITC->phiD_2_final.calculate();
945 
946  ITC->rD_0_final.calculate();
947  ITC->rD_1_final.calculate();
948  ITC->rD_2_final.calculate();
949 
950  ITC->der_phiL_final.calculate();
951  ITC->der_zL_final.calculate();
952  ITC->der_phiD_final.calculate();
953  ITC->der_rD_final.calculate();
954 
955  //store the binary results
956  irinv = ITC->rinv_final.ival();
957  iphi0 = ITC->phi0_final.ival();
958  it = ITC->t_final.ival();
959  iz0 = ITC->z0_final.ival();
960 
961  iphiproj[0] = ITC->phiL_0_final.ival();
962  iphiproj[1] = ITC->phiL_1_final.ival();
963  iphiproj[2] = ITC->phiL_2_final.ival();
964 
965  izproj[0] = ITC->zL_0_final.ival();
966  izproj[1] = ITC->zL_1_final.ival();
967  izproj[2] = ITC->zL_2_final.ival();
968 
970  return false;
971 
972  if (!inSector(iphi0, irinv, phi0approx, rinvapprox))
973  return false;
974 
975  Projection projs[N_LAYER + N_DISK];
976 
977  for (unsigned int i = 0; i < N_DISK - 2; ++i) {
978  //Check is outside z range
979  if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1)))
980  continue;
981  if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1)))
982  continue;
983 
984  //Check if outside phi range
985  if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1)
986  continue;
987  if (iphiproj[i] <= 0)
988  continue;
989 
990  //shift bits - allways in PS modules for disk seeding
991  iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0));
992 
993  projs[i].init(settings_,
994  i,
995  iphiproj[i],
996  izproj[i],
997  ITC->der_phiL_final.ival(),
998  ITC->der_zL_final.ival(),
999  phiproj[i],
1000  zproj[i],
1001  phider[i],
1002  zder[i],
1003  phiprojapprox[i],
1004  zprojapprox[i],
1005  ITC->der_phiL_final.fval(),
1006  ITC->der_zL_final.fval(),
1007  true);
1008  }
1009 
1010  iphiprojdisk[0] = ITC->phiD_0_final.ival();
1011  iphiprojdisk[1] = ITC->phiD_1_final.ival();
1012  iphiprojdisk[2] = ITC->phiD_2_final.ival();
1013 
1014  irprojdisk[0] = ITC->rD_0_final.ival();
1015  irprojdisk[1] = ITC->rD_1_final.ival();
1016  irprojdisk[2] = ITC->rD_2_final.ival();
1017 
1018  for (unsigned int i = 0; i < N_DISK - 2; ++i) {
1019  //check that phi projection in range
1020  if (iphiprojdisk[i] <= 0)
1021  continue;
1022  if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1)
1023  continue;
1024 
1025  //check that r projection in range
1026  if (irprojdisk[i] <= 0 || irprojdisk[i] >= settings_.rmaxdisk() / ITC->rD_0_final.K())
1027  continue;
1028 
1029  projs[settings_.projdisks(iSeed_, i) + N_LAYER - 1].init(settings_,
1031  iphiprojdisk[i],
1032  irprojdisk[i],
1033  ITC->der_phiD_final.ival(),
1034  ITC->der_rD_final.ival(),
1035  phiprojdisk[i],
1036  rprojdisk[i],
1037  phiderdisk[i],
1038  rderdisk[i],
1039  phiprojdiskapprox[i],
1040  rprojdiskapprox[i],
1041  ITC->der_phiD_final.fval(),
1042  ITC->der_rD_final.fval(),
1043  true);
1044  }
1045 
1046  if (settings_.writeMonitorData("TPars")) {
1047  globals_->ofstream("trackletparsdisk.txt")
1048  << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << rinvapprox << " "
1049  << ITC->rinv_final.fval() << " " << phi0 << " " << phi0approx << " " << ITC->phi0_final.fval() << " " << t
1050  << " " << tapprox << " " << ITC->t_final.fval() << " " << z0 << " " << z0approx << " " << ITC->z0_final.fval()
1051  << endl;
1052  }
1053 
1054  Tracklet* tracklet = new Tracklet(settings_,
1055  iSeed_,
1056  innerFPGAStub,
1057  nullptr,
1058  outerFPGAStub,
1059  rinv,
1060  phi0,
1061  0.0,
1062  z0,
1063  t,
1064  rinvapprox,
1065  phi0approx,
1066  0.0,
1067  z0approx,
1068  tapprox,
1069  irinv,
1070  iphi0,
1071  0,
1072  iz0,
1073  it,
1074  projs,
1075  true);
1076 
1077  if (settings_.debugTracklet()) {
1078  edm::LogVerbatim("Tracklet") << "Found tracklet for disk seed = " << iSeed_ << " " << tracklet << " " << iSector_;
1079  }
1080 
1082  tracklet->setTCIndex(TCIndex_);
1083 
1084  if (settings_.writeMonitorData("Seeds")) {
1085  ofstream fout("seeds.txt", ofstream::app);
1086  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() << endl;
1087  fout.close();
1088  }
1089  trackletpars_->addTracklet(tracklet);
1090 
1091  if (tracklet->validProj(0)) {
1092  addLayerProj(tracklet, 1);
1093  }
1094 
1095  if (tracklet->validProj(1)) {
1096  addLayerProj(tracklet, 2);
1097  }
1098 
1099  for (unsigned int j = 0; j < N_DISK - 2; j++) {
1100  if (tracklet->validProj(N_LAYER + settings_.projdisks(iSeed_, j) - 1)) {
1101  addDiskProj(tracklet, sign * settings_.projdisks(iSeed_, j));
1102  }
1103  }
1104 
1105  return true;
1106 }
1107 
1109  const L1TStub* innerStub,
1110  const Stub* outerFPGAStub,
1111  const L1TStub* outerStub) {
1112  //Deal with overlap stubs here
1113  assert(outerFPGAStub->layerdisk() < N_LAYER);
1114 
1115  assert(innerFPGAStub->layerdisk() >= N_LAYER);
1116 
1117  int disk = innerFPGAStub->disk().value();
1118 
1119  if (settings_.debugTracklet()) {
1120  edm::LogVerbatim("Tracklet") << "trying to make overlap tracklet for seed = " << iSeed_ << " " << getName();
1121  }
1122 
1123  double r1 = innerStub->r();
1124  double z1 = innerStub->z();
1125  double phi1 = innerStub->phi();
1126 
1127  double r2 = outerStub->r();
1128  double z2 = outerStub->z();
1129  double phi2 = outerStub->phi();
1130 
1131  //Protection for wrong radii. Could be handled cleaner to avoid problem with floating point calculation and with overflows in the integer calculation.
1132  if (r1 < r2 + 1.5) {
1133  return false;
1134  }
1135 
1136  double rinv, phi0, t, z0;
1137 
1138  double phiproj[N_PSLAYER], zproj[N_PSLAYER], phider[N_PSLAYER], zder[N_PSLAYER];
1139  double phiprojdisk[N_DISK - 1], rprojdisk[N_DISK - 1], phiderdisk[N_DISK - 1], rderdisk[N_DISK - 1];
1140 
1142  z1,
1143  phi1,
1144  r2,
1145  z2,
1146  phi2,
1147  outerStub->sigmaz(),
1148  rinv,
1149  phi0,
1150  t,
1151  z0,
1152  phiproj,
1153  zproj,
1154  phider,
1155  zder,
1156  phiprojdisk,
1157  rprojdisk,
1158  phiderdisk,
1159  rderdisk);
1160 
1161  //Truncates floating point positions to integer representation precision
1162  if (settings_.useapprox()) {
1163  phi1 = innerFPGAStub->phiapprox(phimin_, phimax_);
1164  z1 = innerFPGAStub->zapprox();
1165  r1 = innerFPGAStub->rapprox();
1166 
1167  phi2 = outerFPGAStub->phiapprox(phimin_, phimax_);
1168  z2 = outerFPGAStub->zapprox();
1169  r2 = outerFPGAStub->rapprox();
1170  }
1171 
1172  double rinvapprox, phi0approx, tapprox, z0approx;
1173  double phiprojapprox[N_PSLAYER], zprojapprox[N_PSLAYER];
1174  double phiprojdiskapprox[N_DISK - 1], rprojdiskapprox[N_DISK - 1];
1175 
1177  int ll = outerFPGAStub->layer().value() + 1;
1178  if (ll == 1 && disk == 1)
1179  ITC = globals_->ITC_L1F1();
1180  else if (ll == 2 && disk == 1)
1181  ITC = globals_->ITC_L2F1();
1182  else if (ll == 1 && disk == -1)
1183  ITC = globals_->ITC_L1B1();
1184  else if (ll == 2 && disk == -1)
1185  ITC = globals_->ITC_L2B1();
1186  else
1187  throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!";
1188 
1189  ITC->r1.set_fval(r2 - settings_.rmean(ll - 1));
1190  ITC->r2.set_fval(r1);
1191  int signt = t > 0 ? 1 : -1;
1192  ITC->z1.set_fval(z2);
1193  ITC->z2.set_fval(z1 - signt * settings_.zmean(layerdisk2_ - N_LAYER));
1194  double sphi1 = angle0to2pi::make0To2pi(phi1 - phimin_);
1195  double sphi2 = angle0to2pi::make0To2pi(phi2 - phimin_);
1196  ITC->phi1.set_fval(sphi2);
1197  ITC->phi2.set_fval(sphi1);
1198 
1199  ITC->rproj0.set_fval(settings_.rmean(0));
1200  ITC->rproj1.set_fval(settings_.rmean(1));
1201  ITC->rproj2.set_fval(settings_.rmean(2));
1202 
1203  ITC->zproj0.set_fval(signt * settings_.zmean(1));
1204  ITC->zproj1.set_fval(signt * settings_.zmean(2));
1205  ITC->zproj2.set_fval(signt * settings_.zmean(3));
1206  ITC->zproj3.set_fval(signt * settings_.zmean(4));
1207 
1208  ITC->rinv_final.calculate();
1209  ITC->phi0_final.calculate();
1210  ITC->t_final.calculate();
1211  ITC->z0_final.calculate();
1212 
1213  ITC->phiL_0_final.calculate();
1214  ITC->phiL_1_final.calculate();
1215  ITC->phiL_2_final.calculate();
1216 
1217  ITC->zL_0_final.calculate();
1218  ITC->zL_1_final.calculate();
1219  ITC->zL_2_final.calculate();
1220 
1221  ITC->phiD_0_final.calculate();
1222  ITC->phiD_1_final.calculate();
1223  ITC->phiD_2_final.calculate();
1224  ITC->phiD_3_final.calculate();
1225 
1226  ITC->rD_0_final.calculate();
1227  ITC->rD_1_final.calculate();
1228  ITC->rD_2_final.calculate();
1229  ITC->rD_3_final.calculate();
1230 
1231  ITC->der_phiL_final.calculate();
1232  ITC->der_zL_final.calculate();
1233  ITC->der_phiD_final.calculate();
1234  ITC->der_rD_final.calculate();
1235 
1236  //store the approximate results
1237  rinvapprox = ITC->rinv_final.fval();
1238  phi0approx = ITC->phi0_final.fval();
1239  tapprox = ITC->t_final.fval();
1240  z0approx = ITC->z0_final.fval();
1241 
1242  phiprojapprox[0] = ITC->phiL_0_final.fval();
1243  phiprojapprox[1] = ITC->phiL_1_final.fval();
1244  phiprojapprox[2] = ITC->phiL_2_final.fval();
1245 
1246  zprojapprox[0] = ITC->zL_0_final.fval();
1247  zprojapprox[1] = ITC->zL_1_final.fval();
1248  zprojapprox[2] = ITC->zL_2_final.fval();
1249 
1250  phiprojdiskapprox[0] = ITC->phiD_0_final.fval();
1251  phiprojdiskapprox[1] = ITC->phiD_1_final.fval();
1252  phiprojdiskapprox[2] = ITC->phiD_2_final.fval();
1253  phiprojdiskapprox[3] = ITC->phiD_3_final.fval();
1254 
1255  rprojdiskapprox[0] = ITC->rD_0_final.fval();
1256  rprojdiskapprox[1] = ITC->rD_1_final.fval();
1257  rprojdiskapprox[2] = ITC->rD_2_final.fval();
1258  rprojdiskapprox[3] = ITC->rD_3_final.fval();
1259 
1260  //now binary
1261 
1262  int irinv, iphi0, it, iz0;
1263  int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2];
1264  int iphiprojdisk[N_DISK], irprojdisk[N_DISK];
1265 
1266  int ir2 = innerFPGAStub->r().value();
1267  int iphi2 = innerFPGAStub->phi().value();
1268  int iz2 = innerFPGAStub->z().value();
1269 
1270  int ir1 = outerFPGAStub->r().value();
1271  int iphi1 = outerFPGAStub->phi().value();
1272  int iz1 = outerFPGAStub->z().value();
1273 
1274  //To get global precission
1275  ir1 = l1t::bitShift(ir1, (8 - settings_.nrbitsstub(ll - 1)));
1276  iphi1 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0));
1277  iphi2 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0));
1278 
1279  ITC->r1.set_ival(ir1);
1280  ITC->r2.set_ival(ir2);
1281  ITC->z1.set_ival(iz1);
1282  ITC->z2.set_ival(iz2);
1283  ITC->phi1.set_ival(iphi1);
1284  ITC->phi2.set_ival(iphi2);
1285 
1286  ITC->rinv_final.calculate();
1287  ITC->phi0_final.calculate();
1288  ITC->t_final.calculate();
1289  ITC->z0_final.calculate();
1290 
1291  ITC->phiL_0_final.calculate();
1292  ITC->phiL_1_final.calculate();
1293  ITC->phiL_2_final.calculate();
1294 
1295  ITC->zL_0_final.calculate();
1296  ITC->zL_1_final.calculate();
1297  ITC->zL_2_final.calculate();
1298 
1299  ITC->phiD_0_final.calculate();
1300  ITC->phiD_1_final.calculate();
1301  ITC->phiD_2_final.calculate();
1302  ITC->phiD_3_final.calculate();
1303 
1304  ITC->rD_0_final.calculate();
1305  ITC->rD_1_final.calculate();
1306  ITC->rD_2_final.calculate();
1307  ITC->rD_3_final.calculate();
1308 
1309  ITC->der_phiL_final.calculate();
1310  ITC->der_zL_final.calculate();
1311  ITC->der_phiD_final.calculate();
1312  ITC->der_rD_final.calculate();
1313 
1314  //store the binary results
1315  irinv = ITC->rinv_final.ival();
1316  iphi0 = ITC->phi0_final.ival();
1317  it = ITC->t_final.ival();
1318  iz0 = ITC->z0_final.ival();
1319 
1320  iphiproj[0] = ITC->phiL_0_final.ival();
1321  iphiproj[1] = ITC->phiL_1_final.ival();
1322  iphiproj[2] = ITC->phiL_2_final.ival();
1323 
1324  izproj[0] = ITC->zL_0_final.ival();
1325  izproj[1] = ITC->zL_1_final.ival();
1326  izproj[2] = ITC->zL_2_final.ival();
1327 
1328  iphiprojdisk[0] = ITC->phiD_0_final.ival();
1329  iphiprojdisk[1] = ITC->phiD_1_final.ival();
1330  iphiprojdisk[2] = ITC->phiD_2_final.ival();
1331  iphiprojdisk[3] = ITC->phiD_3_final.ival();
1332 
1333  irprojdisk[0] = ITC->rD_0_final.ival();
1334  irprojdisk[1] = ITC->rD_1_final.ival();
1335  irprojdisk[2] = ITC->rD_2_final.ival();
1336  irprojdisk[3] = ITC->rD_3_final.ival();
1337 
1339  return false;
1340 
1341  if (!inSector(iphi0, irinv, phi0approx, rinvapprox))
1342  return false;
1343 
1344  Projection projs[N_LAYER + N_DISK];
1345 
1346  for (unsigned int i = 0; i < N_DISK - 2; ++i) {
1347  //check that zproj is in range
1348  if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1)))
1349  continue;
1350  if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1)))
1351  continue;
1352 
1353  //check that phiproj is in range
1354  if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1)
1355  continue;
1356  if (iphiproj[i] <= 0)
1357  continue;
1358 
1359  //adjust bits for PS modules (no 2S modules in overlap seeds)
1360  iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0));
1361 
1362  projs[i].init(settings_,
1363  i,
1364  iphiproj[i],
1365  izproj[i],
1366  ITC->der_phiL_final.ival(),
1367  ITC->der_zL_final.ival(),
1368  phiproj[i],
1369  zproj[i],
1370  phider[i],
1371  zder[i],
1372  phiprojapprox[i],
1373  zprojapprox[i],
1374  ITC->der_phiL_final.fval(),
1375  ITC->der_zL_final.fval(),
1376  true);
1377  }
1378 
1379  for (int i = 0; i < 4; ++i) {
1380  //check that phi projection in range
1381  if (iphiprojdisk[i] <= 0)
1382  continue;
1383  if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1)
1384  continue;
1385 
1386  //check that r projection in range
1387  if (irprojdisk[i] <= 0 || irprojdisk[i] >= settings_.rmaxdisk() / ITC->rD_0_final.K())
1388  continue;
1389 
1390  projs[N_LAYER + i + 1].init(settings_,
1391  N_LAYER + i + 1,
1392  iphiprojdisk[i],
1393  irprojdisk[i],
1394  ITC->der_phiD_final.ival(),
1395  ITC->der_rD_final.ival(),
1396  phiprojdisk[i],
1397  rprojdisk[i],
1398  phiderdisk[i],
1399  rderdisk[i],
1400  phiprojdiskapprox[i],
1401  rprojdiskapprox[i],
1402  ITC->der_phiD_final.fval(),
1403  ITC->der_rD_final.fval(),
1404  true);
1405  }
1406 
1407  if (settings_.writeMonitorData("TPars")) {
1408  globals_->ofstream("trackletparsoverlap.txt")
1409  << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << irinv << " " << ITC->rinv_final.fval() << " "
1410  << phi0 << " " << iphi0 << " " << ITC->phi0_final.fval() << " " << t << " " << it << " "
1411  << ITC->t_final.fval() << " " << z0 << " " << iz0 << " " << ITC->z0_final.fval() << endl;
1412  }
1413 
1414  Tracklet* tracklet = new Tracklet(settings_,
1415  iSeed_,
1416  innerFPGAStub,
1417  nullptr,
1418  outerFPGAStub,
1419  rinv,
1420  phi0,
1421  0.0,
1422  z0,
1423  t,
1424  rinvapprox,
1425  phi0approx,
1426  0.0,
1427  z0approx,
1428  tapprox,
1429  irinv,
1430  iphi0,
1431  0,
1432  iz0,
1433  it,
1434  projs,
1435  false,
1436  true);
1437 
1438  if (settings_.debugTracklet()) {
1439  edm::LogVerbatim("Tracklet") << "Found tracklet in overlap seed = " << iSeed_ << " " << tracklet << " " << iSector_;
1440  }
1441 
1443  tracklet->setTCIndex(TCIndex_);
1444 
1445  if (settings_.writeMonitorData("Seeds")) {
1446  ofstream fout("seeds.txt", ofstream::app);
1447  fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() << endl;
1448  fout.close();
1449  }
1450  trackletpars_->addTracklet(tracklet);
1451 
1452  int layer = outerFPGAStub->layer().value() + 1;
1453 
1454  if (layer == 2) {
1455  if (tracklet->validProj(0)) {
1456  addLayerProj(tracklet, 1);
1457  }
1458  }
1459 
1460  for (unsigned int disk = 2; disk < 6; disk++) {
1461  if (layer == 2 && disk == 5)
1462  continue;
1463  if (tracklet->validProj(N_LAYER + disk - 1)) {
1464  addDiskProj(tracklet, disk);
1465  }
1466  }
1467 
1468  return true;
1469 }
Log< level::Info, true > LogVerbatim
double kz() const
Definition: Settings.h:314
double phi() const
Definition: L1TStub.h:65
double zapprox() const
Definition: Stub.cc:158
double fval() const
Definition: imath.h:213
constexpr int N_DISK
Definition: Settings.h:22
bool diskSeeding(const Stub *innerFPGAStub, const L1TStub *innerStub, const Stub *outerFPGAStub, const L1TStub *outerStub)
const FPGAWord & r() const
Definition: Stub.h:60
bool bookHistos() const
Definition: Settings.h:207
unsigned int nrbitsstub(unsigned int layerdisk) const
Definition: Settings.h:84
std::string name_
Definition: ProcessBase.h:38
IMATH_TrackletCalculator * ITC_L2L3()
Definition: Globals.h:49
constexpr T reduceRange(T x)
Definition: deltaPhi.h:18
double phiapprox(double phimin, double) const
Definition: Stub.cc:177
const FPGAWord & z() const
Definition: Stub.h:61
double phicritmaxmc() const
Definition: Settings.h:307
bool goodTrackPars(bool goodrinv, bool goodz0)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double rmindisk() const
Definition: Settings.h:126
double zlength() const
Definition: Settings.h:124
Projection & proj(int layerdisk)
Definition: Tracklet.h:87
Settings const & settings_
Definition: ProcessBase.h:40
bool addLayerProj(Tracklet *tracklet, int layer)
double z() const
Definition: L1TStub.h:59
void exacttrackletOverlap(double r1, double z1, double phi1, double r2, double z2, double phi2, double, double &rinv, double &phi0, double &t, double &z0, double phiprojLayer[N_PSLAYER], double zprojLayer[N_PSLAYER], double phiderLayer[N_PSLAYER], double zderLayer[N_PSLAYER], double phiproj[N_DISK - 2], double rproj[N_DISK - 2], double phider[N_DISK - 2], double rder[N_DISK - 2])
Globals * globals_
Definition: ProcessBase.h:41
double rmindiskvm() const
Definition: Settings.h:327
double krinvpars() const
Definition: Settings.h:397
void set_fval(double fval)
Definition: imath.h:494
IMATH_TrackletCalculatorOverlap * ITC_L2B1()
Definition: Globals.h:61
void exacttracklet(double r1, double z1, double phi1, double r2, double z2, double phi2, double, double &rinv, double &phi0, double &t, double &z0, double phiproj[N_LAYER - 2], double zproj[N_LAYER - 2], double phider[N_LAYER - 2], double zder[N_LAYER - 2], double phiprojdisk[N_DISK], double rprojdisk[N_DISK], double phiderdisk[N_DISK], double rderdisk[N_DISK])
assert(be >=bs)
double phicritminmc() const
Definition: Settings.h:306
IMATH_TrackletCalculatorDisk * ITC_B1B2()
Definition: Globals.h:55
const FPGAWord & fpgaphiproj() const
Definition: Projection.h:39
void exactprojdisk(double zproj, double rinv, double phi0, double t, double z0, double &phiproj, double &rproj, double &phider, double &rder)
unsigned int isPSmodule() const
Definition: L1TStub.h:96
double kphi0pars() const
Definition: Settings.h:401
const FPGAWord & disk() const
Definition: Stub.h:68
bool warnNoMem() const
Definition: Settings.h:185
bool overlapSeeding(const Stub *innerFPGAStub, const L1TStub *innerStub, const Stub *outerFPGAStub, const L1TStub *outerStub)
IMATH_TrackletCalculatorDisk * ITC_F3F4()
Definition: Globals.h:54
unsigned int projlayers(unsigned int iSeed, unsigned int i) const
Definition: Settings.h:155
IMATH_TrackletCalculatorOverlap * ITC_L1F1()
Definition: Globals.h:58
void init(Settings const &settings, unsigned int layerdisk, int iphiproj, int irzproj, int iphider, int irzder, double phiproj, double rzproj, double phiprojder, double rzprojder, double phiprojapprox, double rzprojapprox, double phiprojderapprox, double rzprojderapprox, bool isPSseed)
Definition: Projection.cc:11
void addProjection(int layer, int iphi, TrackletProjectionsMemory *trackletprojs, Tracklet *tracklet)
unsigned int nzbitsstub(unsigned int layerdisk) const
Definition: Settings.h:82
unsigned int nphibitsstub(unsigned int layerdisk) const
Definition: Settings.h:83
double rmean(unsigned int iLayer) const
Definition: Settings.h:164
bool local_passes() const
Definition: imath.cc:315
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
IMATH_TrackletCalculator * ITC_L1L2()
Definition: Globals.h:48
int value() const
Definition: FPGAWord.h:24
void exacttrackletdisk(double r1, double z1, double phi1, double r2, double z2, double phi2, double, double &rinv, double &phi0, double &t, double &z0, double phiprojLayer[N_PSLAYER], double zprojLayer[N_PSLAYER], double phiderLayer[N_PSLAYER], double zderLayer[N_PSLAYER], double phiproj[N_DISK - 2], double rproj[N_DISK - 2], double phider[N_DISK - 2], double rder[N_DISK - 2])
unsigned int projdisks(unsigned int iSeed, unsigned int i) const
Definition: Settings.h:156
TrackletParametersMemory * trackletpars_
bool writeMonitorData(std::string module) const
Definition: Settings.h:109
unsigned int layerdisk() const
Definition: Stub.cc:185
double rapprox() const
Definition: Stub.cc:144
double zmean(unsigned int iDisk) const
Definition: Settings.h:167
void setTCIndex(int index)
Definition: Tracklet.h:210
double K() const
Definition: imath.h:247
std::vector< std::vector< TrackletProjectionsMemory * > > trackletprojdisks_
unsigned int nallstubs(unsigned int layerdisk) const
Definition: Settings.h:107
bool debugTracklet() const
Definition: Settings.h:182
constexpr unsigned int N_PSLAYER
Definition: Settings.h:23
IMATH_TrackletCalculatorDisk * ITC_B3B4()
Definition: Globals.h:56
void exactproj(double rproj, double rinv, double phi0, double t, double z0, double &phiproj, double &zproj, double &phider, double &zder)
double rmaxdisk() const
Definition: Settings.h:125
std::vector< std::vector< TrackletProjectionsMemory * > > trackletprojlayers_
int nbits() const
Definition: FPGAWord.h:25
IMATH_TrackletCalculatorDisk * ITC_F1F2()
Definition: Globals.h:53
void setTrackletIndex(unsigned int index)
Definition: Tracklet.cc:796
double rinv(double phi1, double phi2, double r1, double r2)
Definition: Util.h:49
int getISeed() const
Definition: Tracklet.cc:801
constexpr valType make0To2pi(valType angle)
Definition: deltaPhi.h:67
long int ival() const
Definition: imath.h:214
IMATH_TrackletCalculator * ITC_L5L6()
Definition: Globals.h:51
const FPGAWord & fpgarzproj() const
Definition: Projection.h:44
void addDiskProj(Tracklet *tracklet, int disk)
IMATH_TrackletCalculator * ITC_L3L4()
Definition: Globals.h:50
void addProjectionDisk(int disk, int iphi, TrackletProjectionsMemory *trackletprojs, Tracklet *tracklet)
void set_ival(int ival)
Definition: imath.h:502
double r() const
Definition: L1TStub.h:60
IMATH_TrackletCalculatorOverlap * ITC_L1B1()
Definition: Globals.h:59
IMATH_TrackletCalculatorOverlap * ITC_L2F1()
Definition: Globals.h:60
std::ofstream & ofstream(std::string fname)
Definition: Globals.cc:44
HistBase *& histograms()
Definition: Globals.h:38
double krprojshiftdisk() const
Definition: Settings.h:413
const FPGAWord & layer() const
Definition: Stub.h:67
const FPGAWord & phi() const
Definition: Stub.h:62
double sigmaz() const
Definition: L1TStub.h:74
tmp
align.sh
Definition: createJobs.py:716
bool usephicritapprox() const
Definition: Settings.h:236
std::string const & getName() const
Definition: ProcessBase.h:22
bool calculate(int debug_level=0)
bool useapprox() const
Definition: Settings.h:235
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
bool validProj(int layerdisk) const
Definition: Tracklet.h:82
int bitShift(int num, int bits)
Definition: BitShift.h:6
bool inSector(int iphi0, int irinv, double phi0approx, double rinvapprox)
bool atExtreme() const
Definition: FPGAWord.cc:79
constexpr int N_LAYER
Definition: Settings.h:21
bool barrelSeeding(const Stub *innerFPGAStub, const L1TStub *innerStub, const Stub *outerFPGAStub, const L1TStub *outerStub)
double rcrit() const
Definition: Settings.h:299