Skip to content

Commit

Permalink
Produce combined module MemPrint & LUT files for reduced project (cms…
Browse files Browse the repository at this point in the history
…-sw#189)

* Changes from Anders

* code-formatted
  • Loading branch information
tomalin committed Nov 9, 2022
1 parent 8f79ec2 commit 5e167c3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
18 changes: 18 additions & 0 deletions L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
// This class writes out the variuos look up tables
// for all modules.
//////////////////////////////////////////////////////////////////
//
// This class has methods to build the LUT (LookUp Tables) used by the track finding
// It also provides a method to write out the file for use by the firmware implementation
//
//
#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletLUT_h
#define L1Trigger_TrackFindingTracklet_interface_TrackletLUT_h

Expand Down Expand Up @@ -49,13 +54,18 @@ namespace trklet {
//region only used for name - should be removed
void initmatchcut(unsigned int layerdisk, MatchType type, unsigned int region);

//Builds LUT that for each TP returns if the phi differences between inner and outer
//stub is consistent with the pT cut and the stub pair should be kept.
void initTPlut(bool fillInner,
unsigned int iSeed,
unsigned int layerdisk1,
unsigned int layerdisk2,
unsigned int nbitsfinephidiff,
unsigned int iTP);

//Builds a lut for the TP ro decide if the region should be used. This is used in the
//first stage of the TP to decide which regions in the outer layer an inner stub needs
//to be combined with
void initTPregionlut(unsigned int iSeed,
unsigned int layerdisk1,
unsigned int layerdisk2,
Expand All @@ -65,6 +75,7 @@ namespace trklet {
const TrackletLUT& tplutinner,
unsigned int iTP);

//Stub pt consistency for tracklet engine
void initteptlut(bool fillInner,
bool fillTEMem,
unsigned int iSeed,
Expand All @@ -79,21 +90,28 @@ namespace trklet {
const std::string& innermem,
const std::string& outermem);

//This LUT uses the phi derivative known in the projection to calculate the corresponding bend
void initProjectionBend(double k_phider, unsigned int idisk, unsigned int nrbits, unsigned int nphiderbits);

//This LUT implements consistence check for match engine to check that stub bend is consistent with projection
void initBendMatch(unsigned int layerdisk);

void initProjectionDiskRadius(int nrbits);

enum VMRTableType { me, disk, inner, inneroverlap, innerthird };

//In the VMR we used the position of the stub (r, z) to calculate the bin and fine rz position the stub has
//region only used for name - should be removed
void initVMRTable(unsigned int layerdisk, VMRTableType type, int region = -1);

//Used in barrel to calculate the phi position of a stub at the nominal radis of the layer based on the stub radial
//psotion and bend
void initPhiCorrTable(unsigned int layerdisk, unsigned int rbits);

//writes out the LUT in standared format for firmware
void writeTable() const;

//Evaluate the LUT
int lookup(unsigned int index) const;

unsigned int size() const { return table_.size(); }
Expand Down
43 changes: 37 additions & 6 deletions L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ std::vector<std::array<double, 2>> TrackletLUT::getBendCut(unsigned int layerdis
void TrackletLUT::initmatchcut(unsigned int layerdisk, MatchType type, unsigned int region) {
char cregion = 'A' + region;

for (unsigned int iSeed = 0; iSeed < 12; iSeed++) {
for (unsigned int iSeed = 0; iSeed < N_SEED; iSeed++) {
if (type == barrelphi) {
table_.push_back(settings_.rphimatchcut(iSeed, layerdisk) / (settings_.kphi1() * settings_.rmean(layerdisk)));
}
Expand Down Expand Up @@ -318,8 +318,10 @@ void TrackletLUT::initTPlut(bool fillInner,
iphidiff = iphibin - nbinsfinephidiff;
}
//min and max dphi
dphi[0] = (iphidiff - 1.5) * dfinephi;
dphi[1] = (iphidiff + 1.5) * dfinephi;
//ramge of dphi to consider due to resolution
double deltaphi = 1.5;
dphi[0] = (iphidiff - deltaphi) * dfinephi;
dphi[1] = (iphidiff + deltaphi) * dfinephi;
for (int irouterbin = 0; irouterbin < outerrbins; irouterbin++) {
if (iSeed == Seed::D1D2 || iSeed == Seed::D3D4 || iSeed == Seed::L1D1 || iSeed == Seed::L2D1) {
router[0] =
Expand Down Expand Up @@ -468,6 +470,8 @@ void TrackletLUT::initTPlut(bool fillInner,
}
}

nbits_ = 8;

positive_ = false;
char cTP = 'A' + iTP;

Expand Down Expand Up @@ -1023,7 +1027,9 @@ void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int re
}
}

if (layerdisk >= N_LAYER && irbin < 10) //special case for the tabulated radii in 2S disks
unsigned int NRING =
5; //number of 2S rings in disks. This is multiplied below by two since we have two halfs of a module
if (layerdisk >= N_LAYER && irbin < 2 * NRING) //special case for the tabulated radii in 2S disks
r = (layerdisk < N_LAYER + 2) ? settings_.rDSSinner(irbin) : settings_.rDSSouter(irbin);

int bin;
Expand Down Expand Up @@ -1155,7 +1161,8 @@ int TrackletLUT::getVMRLookup(unsigned int layerdisk, double z, double r, double
double z0cut = settings_.z0cut();

if (layerdisk < N_LAYER) {
if (iseed == Seed::L2L3 && std::abs(z) < 52.0)
double zcutL2L3 = 52.0; //Stubs closer to IP in z will not be used for L2L3 seeds
if (iseed == Seed::L2L3 && std::abs(z) < zcutL2L3)
return -1;

double rmean = settings_.rmean(layerdisk);
Expand Down Expand Up @@ -1355,7 +1362,8 @@ int TrackletLUT::getphiCorrValue(
double Delta = (irbin + 0.5) * dr - drmax;

//calculate the phi correction - this is a somewhat approximate formula
double dphi = (Delta / 0.18) * bend * settings_.stripPitch(psmodule) / rmean;
double drnom = 0.18; //This is the nominal module separation for which bend is referenced
double dphi = (Delta / drnom) * bend * settings_.stripPitch(psmodule) / rmean;

double kphi = psmodule ? settings_.kphi() : settings_.kphi1();

Expand Down Expand Up @@ -1393,6 +1401,29 @@ void TrackletLUT::writeTable() const {
}
out << endl << "};" << endl;
out.close();

string name = name_;

name[name_.size() - 3] = 'd';
name[name_.size() - 2] = 'a';
name[name_.size() - 1] = 't';

out = openfile(settings_.tablePath(), name, __FILE__, __LINE__);

int width = (nbits_ + 3) / 4;

for (unsigned int i = 0; i < table_.size(); i++) {
int itable = table_[i];
if (positive_) {
if (table_[i] < 0) {
itable = (1 << nbits_) - 1;
}
}

out << uppercase << setfill('0') << setw(width) << hex << itable << dec << endl;
}

out.close();
}

int TrackletLUT::lookup(unsigned int index) const {
Expand Down

0 comments on commit 5e167c3

Please sign in to comment.