12 TrackletLUT::TrackletLUT(
const Settings& settings) : settings_(settings) {}
15 char cregion =
'A' +
region;
17 for (
unsigned int iSeed = 0; iSeed < 12; iSeed++) {
66 unsigned int layerdisk1,
67 unsigned int layerdisk2,
68 unsigned int nbitsfinephidiff,
80 int outerrbins = (1 << outerrbits);
85 unsigned int nbendbitsinner = 3;
86 unsigned int nbendbitsouter = 3;
94 int nbinsfinephidiff = (1 << nbitsfinephidiff);
96 for (
int iphibin = 0; iphibin < nbinsfinephidiff; iphibin++) {
97 int iphidiff = iphibin;
98 if (iphibin >= nbinsfinephidiff / 2) {
99 iphidiff = iphibin - nbinsfinephidiff;
102 dphi[0] = (iphidiff - 1.5) * dfinephi;
103 dphi[1] = (iphidiff + 1.5) * dfinephi;
104 for (
int irouterbin = 0; irouterbin < outerrbins; irouterbin++) {
115 double bendinnermin = 20.0;
116 double bendinnermax = -20.0;
117 double bendoutermin = 20.0;
118 double bendoutermax = -20.0;
119 double rinvmin = 1.0;
120 for (
int i2 = 0;
i2 < 2;
i2++) {
121 for (
int i3 = 0;
i3 < 2;
i3++) {
128 double rinv1 =
rinv(0.0, -dphi[
i2], rinner, router[
i3]);
132 double abendinner =
bendstrip(rinner, rinv1, pitchinner);
133 double abendouter =
bendstrip(router[
i3], rinv1, pitchouter);
134 if (abendinner < bendinnermin)
135 bendinnermin = abendinner;
136 if (abendinner > bendinnermax)
137 bendinnermax = abendinner;
138 if (abendouter < bendoutermin)
139 bendoutermin = abendouter;
140 if (abendouter > bendoutermax)
141 bendoutermax = abendouter;
151 for (
int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) {
154 bool passinner = bend <= bendinnermax +
settings_.
bendcutte(ibend, layerdisk1, nbendbitsinner == 3) &&
156 table_.push_back(passinner && passptcut);
159 for (
int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) {
162 bool passouter = bend <= bendoutermax +
settings_.
bendcutte(ibend, layerdisk2, nbendbitsouter == 3) &&
164 table_.push_back(passouter && passptcut);
171 char cTP =
'A' + iTP;
176 name_ +=
"_stubptinnercut.tab";
178 name_ +=
"_stubptoutercut.tab";
185 unsigned int layerdisk1,
186 unsigned int layerdisk2,
187 unsigned int iAllStub,
188 unsigned int nbitsfinephidiff,
189 unsigned int nbitsfinephi,
197 unsigned int nbendbitsinner = 3;
203 for (
int innerfinephi = 0; innerfinephi < (1 << nbitsfinephi); innerfinephi++) {
204 for (
int innerbend = 0; innerbend < (1 << nbendbitsinner); innerbend++) {
205 for (
int ir = 0; ir < (1 << nirbits); ir++) {
206 unsigned int usereg = 0;
207 for (
unsigned int ireg = 0; ireg <
settings_.
nvmte(1, iSeed); ireg++) {
209 for (
int ifinephiouter = 0; ifinephiouter < (1 <<
settings_.
nfinephi(1, iSeed)); ifinephiouter++) {
212 int idphi = outerfinephi - innerfinephi;
213 bool inrange = (idphi < (1 << (nbitsfinephidiff - 1))) && (idphi >= -(1 << (nbitsfinephidiff - 1)));
215 idphi = idphi + (1 << nbitsfinephidiff);
218 idphi1 = (idphi << 3) + ir;
219 int ptinnerindexnew =
l1t::bitShift(idphi1, nbendbitsinner) + innerbend;
223 usereg = usereg | (1 << ireg);
233 char cTP =
'A' + iTP;
244 unsigned int layerdisk1,
245 unsigned int layerdisk2,
246 unsigned int innerphibits,
247 unsigned int outerphibits,
259 int outerrbins = (1 << outerrbits);
260 int innerphibins = (1 << innerphibits);
261 int outerphibins = (1 << outerphibits);
267 unsigned int nbendbitsinner = 3;
268 unsigned int nbendbitsouter = 3;
279 table_.resize((1 << nbendbitsinner),
false);
281 table_.resize((1 << nbendbitsouter),
false);
285 for (
int iphiinnerbin = 0; iphiinnerbin < innerphibins; iphiinnerbin++) {
286 phiinner[0] = innerphimin + iphiinnerbin * (innerphimax - innerphimin) / innerphibins;
287 phiinner[1] = innerphimin + (iphiinnerbin + 1) * (innerphimax - innerphimin) / innerphibins;
288 for (
int iphiouterbin = 0; iphiouterbin < outerphibins; iphiouterbin++) {
289 phiouter[0] = outerphimin + iphiouterbin * (outerphimax - outerphimin) / outerphibins;
290 phiouter[1] = outerphimin + (iphiouterbin + 1) * (outerphimax - outerphimin) / outerphibins;
291 for (
int irouterbin = 0; irouterbin < outerrbins; irouterbin++) {
302 double bendinnermin = 20.0;
303 double bendinnermax = -20.0;
304 double bendoutermin = 20.0;
305 double bendoutermax = -20.0;
306 double rinvmin = 1.0;
307 for (
int i1 = 0;
i1 < 2;
i1++) {
308 for (
int i2 = 0;
i2 < 2;
i2++) {
309 for (
int i3 = 0;
i3 < 2;
i3++) {
316 double rinv1 = -
rinv(phiinner[
i1], phiouter[
i2], rinner, router[
i3]);
321 double abendinner =
bendstrip(rinner, rinv1, pitchinner);
322 double abendouter =
bendstrip(router[
i3], rinv1, pitchouter);
323 if (abendinner < bendinnermin)
324 bendinnermin = abendinner;
325 if (abendinner > bendinnermax)
326 bendinnermax = abendinner;
327 if (abendouter < bendoutermin)
328 bendoutermin = abendouter;
329 if (abendouter > bendoutermax)
330 bendoutermax = abendouter;
341 for (
int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) {
344 bool passinner = bend > bendinnermin -
settings_.
bendcutte(ibend, layerdisk1, nbendbitsinner == 3) &&
352 table_.push_back(passinner && passptcut);
356 for (
int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) {
359 bool passouter = bend > bendoutermin -
settings_.
bendcutte(ibend, layerdisk2, nbendbitsouter == 3) &&
366 table_.push_back(passouter && passptcut);
378 name_ =
"VMSTE_" + innermem +
"_vmbendcut.tab";
380 name_ =
"VMSTE_" + outermem +
"_vmbendcut.tab";
383 name_ =
"TE_" + innermem.substr(0, innermem.size() - 2) +
"_" + outermem.substr(0, outermem.size() - 2);
385 name_ +=
"_stubptinnercut.tab";
387 name_ +=
"_stubptoutercut.tab";
397 unsigned int nphiderbits) {
398 unsigned int nsignbins = 2;
399 unsigned int nrbins = 1 << (nrbits);
400 unsigned int nphiderbins = 1 << (nphiderbits);
402 for (
unsigned int isignbin = 0; isignbin < nsignbins; isignbin++) {
403 for (
unsigned int irbin = 0; irbin < nrbins; irbin++) {
405 if (ir > (1 << (nrbits - 1)))
408 for (
unsigned int iphiderbin = 0; iphiderbin < nphiderbins; iphiderbin++) {
409 int iphider = iphiderbin;
410 if (iphider > (1 << (nphiderbits - 1)))
411 iphider -= (1 << nphiderbits);
415 double phider = iphider * k_phider;
421 double rinv = -phider * (2.0 *
t);
426 int ibendproj = 2.0 * bendproj + 15.5;
432 table_.push_back(ibendproj);
446 double rinvhalf = 0.5 * ((1 << nrinv) - 1);
455 for (
unsigned int irinv = 0; irinv < (1u << nrinv); irinv++) {
459 for (
unsigned int ibend = 0; ibend < (1u << nbits); ibend++) {
466 for (
unsigned int iprojbend = 0; iprojbend < (1u << nrinv); iprojbend++) {
467 double projbend = 0.5 * (iprojbend - rinvhalf);
468 for (
unsigned int ibend = 0; ibend < (1 <<
N_BENDBITS_2S); ibend++) {
474 for (
unsigned int iprojbend = 0; iprojbend < (1u << nrinv); iprojbend++) {
475 double projbend = 0.5 * (iprojbend - rinvhalf);
476 for (
unsigned int ibend = 0; ibend < (1 <<
N_BENDBITS_PS); ibend++) {
495 unsigned int rbins = (1 << rbits);
496 unsigned int zbins = (1 << zbits);
512 double dr = (rmax - rmin) / rbins;
517 for (
unsigned int izbin = 0; izbin <
zbins; izbin++) {
518 for (
unsigned int irbin = 0; irbin < rbins; irbin++) {
519 double r = rmin + (irbin + 0.5) *
dr;
520 double z =
zmin + (izbin + 0.5) *
dz;
523 int iznew = izbin - (1 << (zbits - 1));
525 iznew += (1 << zbits);
527 assert(iznew < (1 << zbits));
528 z =
zmin + (iznew + 0.5) *
dz;
530 int irnew = irbin - (1 << (rbits - 1));
532 irnew += (1 << rbits);
534 assert(irnew < (1 << rbits));
535 r = rmin + (irnew + 0.5) *
dr;
539 if (layerdisk >=
N_LAYER && irbin < 10)
559 if (
type == VMRTableType::disk) {
582 if (
type == VMRTableType::inneroverlap) {
588 if (
type == VMRTableType::innerthird) {
613 if (
type == VMRTableType::disk) {
624 if (
type == VMRTableType::inneroverlap) {
633 if (layerdisk == 1 || layerdisk == 2 || layerdisk == 3 || layerdisk == 4) {
640 char cregion =
'A' +
region;
651 if (
type == VMRTableType::inneroverlap) {
657 if (
type == VMRTableType::disk) {
675 double rratio1 = rmean / (
r + 0.5 *
dr);
676 double rratio2 = rmean / (
r - 0.5 *
dr);
678 double z1 = (z - 0.5 *
dz) * rratio1 + z0cut * (rratio1 - 1.0);
679 double z2 = (z + 0.5 *
dz) * rratio1 + z0cut * (rratio1 - 1.0);
680 double z3 = (z - 0.5 *
dz) * rratio2 + z0cut * (rratio2 - 1.0);
681 double z4 = (z + 0.5 *
dz) * rratio2 + z0cut * (rratio2 - 1.0);
682 double z5 = (z - 0.5 *
dz) * rratio1 - z0cut * (rratio1 - 1.0);
683 double z6 = (z + 0.5 *
dz) * rratio1 - z0cut * (rratio1 - 1.0);
684 double z7 = (z - 0.5 *
dz) * rratio2 - z0cut * (rratio2 - 1.0);
685 double z8 = (z + 0.5 *
dz) * rratio2 - z0cut * (rratio2 - 1.0);
715 int value = zbin1 / 8;
717 if (zbin2 / 8 - zbin1 / 8 > 0)
720 value += (zbin1 & 7);
722 int deltaz = zbin2 - zbin1;
727 value += (deltaz << 7);
739 double r1 = (
r + 0.5 *
dr) * (zmean + z0cut) / (z + 0.5 *
dz + z0cut);
740 double r2 = (
r - 0.5 *
dr) * (zmean - z0cut) / (z + 0.5 *
dz - z0cut);
741 double r3 = (
r + 0.5 *
dr) * (zmean + z0cut) / (z - 0.5 *
dz + z0cut);
742 double r4 = (
r - 0.5 *
dr) * (zmean - z0cut) / (z - 0.5 *
dz - z0cut);
743 double r5 = (
r + 0.5 *
dr) * (zmean - z0cut) / (z + 0.5 *
dz - z0cut);
744 double r6 = (
r - 0.5 *
dr) * (zmean + z0cut) / (z + 0.5 *
dz + z0cut);
745 double r7 = (
r + 0.5 *
dr) * (zmean - z0cut) / (z - 0.5 *
dz - z0cut);
746 double r8 = (
r - 0.5 *
dr) * (zmean + z0cut) / (z - 0.5 *
dz + z0cut);
748 double rmin =
std::min({
r1,
r2, r3, r4, r5, r6, r7, r8});
749 double rmax =
std::max({
r1,
r2, r3, r4, r5, r6, r7, r8});
777 constexpr
double rminspec = 40.0;
799 int value = rbin1 / 8;
805 if (rbin2 / 8 - rbin1 / 8 > 0)
808 value += (rbin1 & 7);
810 int deltar = rbin2 - rbin1;
828 unsigned int rbins = (1 << rbits);
833 double dr = 2.0 * drmax / rbins;
835 unsigned int bendbins = (1 << bendbits);
837 for (
unsigned int ibend = 0; ibend < bendbins; ibend++) {
838 for (
unsigned int irbin = 0; irbin < rbins; irbin++) {
852 unsigned int layerdisk,
unsigned int ibend,
unsigned int irbin,
double rmean,
double dr,
double drmax)
const {
858 double Delta = (irbin + 0.5) *
dr - drmax;
865 int idphi = dphi / kphi;
883 for (
unsigned int i = 0;
i <
table_.size();
i++) {
891 itable = (1 <<
nbits_) - 1;
897 out << endl <<
"};" << endl;
double rphicutPS(unsigned int iSeed, unsigned int idisk) const
unsigned int vmrlutrbits(unsigned int layerdisk) const
void initBendMatch(unsigned int layerdisk)
double zmatchcut(unsigned int iSeed, unsigned int ilayer) const
unsigned int nrbitsstub(unsigned int layerdisk) const
void initmatchcut(unsigned int layerdisk, MatchType type, unsigned int region)
double rDSSinner(unsigned int iBin) const
double benddecode(int ibend, int layerdisk, bool isPSmodule) const
constexpr unsigned int NRINVBITS
void initProjectionBend(double k_phider, unsigned int idisk, unsigned int nrbits, unsigned int nphiderbits)
void initteptlut(bool fillInner, bool fillTEMem, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, unsigned int innerphibits, unsigned int outerphibits, double innerphimin, double innerphimax, double outerphimin, double outerphimax, const std::string &innermem, const std::string &outermem)
double dphisectorHG() const
const Settings & settings_
static std::string LayerName(unsigned int ilayer)
constexpr unsigned int N_BENDBITS_2S
std::string to_string(const V &value)
int lookup(unsigned int index) const
double rmindiskvm() const
double rphimatchcut(unsigned int iSeed, unsigned int ilayer) const
constexpr unsigned int N_BENDBITS_PS
void initPhiCorrTable(unsigned int layerdisk, unsigned int rbits)
unsigned int NLONGVMBINS() const
std::string tablePath() const
double rmindiskl2overlapvm() const
unsigned int nbitsallstubs(unsigned int layerdisk) const
double rmean(unsigned int iLayer) const
double rDSSouter(unsigned int iBin) const
double stripPitch(bool isPSmodule) const
Abs< T >::type abs(const T &t)
double bendcutme(int ibend, int layerdisk, bool isPSmodule) const
double bendcutte(int ibend, int layerdisk, bool isPSmodule) const
double zmean(unsigned int iDisk) const
unsigned int nvmte(unsigned int inner, unsigned int iSeed) const
unsigned int nallstubs(unsigned int layerdisk) const
double rcut2S(unsigned int iSeed, unsigned int idisk) const
constexpr unsigned int N_PSLAYER
double rphicut2S(unsigned int iSeed, unsigned int idisk) const
double rcutPS(unsigned int iSeed, unsigned int idisk) const
double rinv(double phi1, double phi2, double r1, double r2)
void initTPlut(bool fillInner, unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, unsigned int nbitsfinephidiff, unsigned int iTP)
int nfinephi(unsigned int inner, unsigned int iSeed) const
unsigned int nbitsphiprojderL123() const
void initTPregionlut(unsigned int iSeed, unsigned int layerdisk1, unsigned int layerdisk2, unsigned int iAllStub, unsigned int nbitsfinephidiff, unsigned int nbitsfinephi, const TrackletLUT &tplutinner, unsigned int iTP)
double rmaxdiskvm() const
int getVMRLookup(unsigned int layerdisk, double z, double r, double dz, double dr, int iseed=-1) const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
int getphiCorrValue(unsigned int layerdisk, unsigned int ibend, unsigned int irbin, double rmean, double dr, double drmax) const
std::vector< int > table_
double krprojshiftdisk() const
double bendstrip(double r, double rinv, double stripPitch)
void initVMRTable(unsigned int layerdisk, VMRTableType type, int region=-1)
int bitShift(int num, int bits)
std::ofstream openfile(const std::string &dir, const std::string &fname, const char *file, int line)
unsigned int vmrlutzbits(unsigned int layerdisk) const
double rmaxdiskl1overlapvm() const