Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-03 00:12:20

0001 #ifndef L1Trigger_TrackFindingTracklet_interface_Settings_h
0002 #define L1Trigger_TrackFindingTracklet_interface_Settings_h
0003 
0004 #include <iostream>
0005 #include <string>
0006 #include <array>
0007 #include <set>
0008 #include <cassert>
0009 #include <cmath>
0010 #include <unordered_map>
0011 #include <map>
0012 #include <vector>
0013 
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "FWCore/Utilities/interface/Exception.h"
0016 
0017 namespace tt {
0018   class Setup;
0019 }
0020 
0021 namespace trklet {
0022 
0023   constexpr unsigned int N_SECTOR = 9;  // # of phi sectors for L1TK processing
0024 
0025   constexpr int N_LAYER = 6;                 // # of barrel layers assumed
0026   constexpr int N_DISK = 5;                  // # of endcap disks assumed
0027   constexpr unsigned int N_PSLAYER = 3;      // # of barrel PS layers assumed
0028   constexpr unsigned int N_SEED = 12;        // # of tracklet+triplet seeds
0029   constexpr unsigned int N_SEED_PROMPT = 8;  // # of tracklet (prompt) seeds
0030 
0031   constexpr unsigned int N_DSS_MOD = 5;  // # of rings with 2S modules per disk
0032 
0033   constexpr unsigned int N_BENDBITS_PS = 3;  // Number of bend bits for PS modules
0034   constexpr unsigned int N_BENDBITS_2S = 4;  // Number of bend bits for 2S modules
0035 
0036   constexpr unsigned int NRINVBITS = 5;     //number of bit for rinv in bend match table
0037   constexpr unsigned int NFINERZBITS = 3;   //number of bit for r or z within a r/z bin
0038   constexpr unsigned int NFINEPHIBITS = 3;  //number of bits for phi within a vm bin
0039   constexpr unsigned int N_RZBITS = 3;      //number of bit for the r/z bins
0040   constexpr unsigned int N_PHIBITS = 3;     //number of bit for the phi bins
0041 
0042   constexpr unsigned int N_VMSTUBSMAX = 15;     // maximum number of stubs in VM bin
0043   constexpr unsigned int N_BITSMEMADDRESS = 7;  // Number of bits for address in memories
0044 
0045   constexpr double sixth = 1.0 / 6.0;  //Commonly used factor
0046   constexpr double third = 1.0 / 3.0;  //Commonly used factor
0047 
0048   constexpr double VMROUTERCUTZL2 = 50.0;      //Min L2 z for inner allstub
0049   constexpr double VMROUTERCUTZL1L3L5 = 95.0;  //Max z for inner barrel layers
0050   constexpr double VMROUTERCUTZL1 = 70.0;      //Max z for L1 barrel seeding
0051   constexpr double VMROUTERCUTRD1D3 = 55.0;    //Max r for disk seeds
0052 
0053   enum Seed { L1L2 = 0, L2L3, L3L4, L5L6, D1D2, D3D4, L1D1, L2D1, L2L3L4, L4L5L6, L2L3D1, D1D2L2 };
0054   enum LayerDisk { L1 = 0, L2, L3, L4, L5, L6, D1, D2, D3, D4, D5 };
0055 
0056   class Settings {
0057   public:
0058     Settings() {};
0059     ~Settings() = default;
0060     void passSetup(const tt::Setup* setup) { setup_ = setup; }
0061     const tt::Setup* setup() const { return setup_; }
0062 
0063     // processing & memory modules, wiring, etc.
0064     std::string const& fitPatternFile() const { return fitPatternFile_; }
0065     std::string const& processingModulesFile() const { return processingModulesFile_; }
0066     std::string const& memoryModulesFile() const { return memoryModulesFile_; }
0067     std::string const& wiresFile() const { return wiresFile_; }
0068     std::string const& tableTEDFile() const { return tableTEDFile_; }
0069     std::string const& tableTREFile() const { return tableTREFile_; }
0070 
0071     void setFitPatternFile(std::string fitPatternFileName) { fitPatternFile_ = fitPatternFileName; }
0072     void setProcessingModulesFile(std::string processingModulesFileName) {
0073       processingModulesFile_ = processingModulesFileName;
0074     }
0075     void setMemoryModulesFile(std::string memoryModulesFileName) { memoryModulesFile_ = memoryModulesFileName; }
0076     void setWiresFile(std::string wiresFileName) { wiresFile_ = wiresFileName; }
0077     void setTableTEDFile(std::string tableTEDFileName) { tableTEDFile_ = tableTEDFileName; }
0078     void setTableTREFile(std::string tableTREFileName) { tableTREFile_ = tableTREFileName; }
0079 
0080     unsigned int nzbitsstub(unsigned int layerdisk) const { return nzbitsstub_[layerdisk]; }
0081     unsigned int nphibitsstub(unsigned int layerdisk) const { return nphibitsstub_[layerdisk]; }
0082     unsigned int nrbitsstub(unsigned int layerdisk) const { return nrbitsstub_[layerdisk]; }
0083 
0084     unsigned int nrbitsprojderdisk() const { return nrbitsprojderdisk_; }
0085     unsigned int nbitsphiprojderL123() const { return nbitsphiprojderL123_; }
0086     unsigned int nbitsphiprojderL456() const { return nbitsphiprojderL456_; }
0087     unsigned int nbitszprojderL123() const { return nbitszprojderL123_; }
0088     unsigned int nbitszprojderL456() const { return nbitszprojderL456_; }
0089 
0090     unsigned int nbendbitsmedisk() const { return nbendbitsmedisk_; }
0091 
0092     bool useSeed(unsigned int iSeed) const { return useseeding_.find(iSeed) != useseeding_.end(); }
0093     unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const {
0094       if (combined_) {
0095         return nbitsvmtecm_[inner][iSeed];
0096       }
0097       return nbitsvmte_[inner][iSeed];
0098     }
0099     unsigned int nvmte(unsigned int inner, unsigned int iSeed) const { return (1 << nbitsvmte(inner, iSeed)); }
0100 
0101     unsigned int nbitsvmme(unsigned int layerdisk) const { return nbitsvmme_[layerdisk]; }
0102     unsigned int nvmme(unsigned int layerdisk) const { return (1 << nbitsvmme_[layerdisk]); }
0103 
0104     unsigned int nbitsallstubs(unsigned int layerdisk) const { return nbitsallstubs_[layerdisk]; }
0105     unsigned int nallstubs(unsigned int layerdisk) const { return (1 << nbitsallstubs_[layerdisk]); }
0106 
0107     bool writeMonitorData(std::string module) const {
0108       if (writeMonitorData_.find(module) == writeMonitorData_.end()) {
0109         throw cms::Exception("BadConfig") << "Settings::writeMonitorData module = " << module << " not known";
0110       }
0111       return writeMonitorData_.at(module);
0112     }
0113 
0114     unsigned int maxStep(std::string module) const {
0115       if (maxstep_.find(module) == maxstep_.end()) {
0116         throw cms::Exception("BadConfig")
0117             << __FILE__ << " " << __LINE__ << " maxStep module = " << module << " not known";
0118       }
0119       return extended_ ? (maxstep_.at(module) + maxstepoffset_extended_) : (maxstep_.at(module) + maxstepoffset_);
0120     }
0121 
0122     double zlength() const { return zlength_; }
0123     double rmaxdisk() const { return rmaxdisk_; }
0124     double rmindisk() const { return rmindisk_; }
0125 
0126     double drmax() const { return rmaxdisk_ / deltarzfract_; }
0127     double dzmax() const { return zlength_ / deltarzfract_; }
0128 
0129     double half2SmoduleWidth() const { return half2SmoduleWidth_; }
0130 
0131     int nfinephi(unsigned int inner, unsigned int iSeed) const { return nfinephi_[inner][iSeed]; }
0132     double nphireg(unsigned int inner, unsigned int iSeed) const {
0133       if (combined_) {
0134         return nphiregcm_[inner][iSeed];
0135       }
0136       return nphireg_[inner][iSeed];
0137     }
0138     double lutwidthtab(unsigned int inner, unsigned int iSeed) const { return lutwidthtab_[inner][iSeed]; }
0139     double lutwidthtabextended(unsigned int inner, unsigned int iSeed) const {
0140       return lutwidthtabextended_[inner][iSeed];
0141     }
0142 
0143     unsigned int seedlayers(int inner, int seed) const {
0144       int layerdisk = seedlayers_[seed][inner];
0145       assert(layerdisk >= 0);
0146       return layerdisk;
0147     }
0148 
0149     unsigned int teunits(unsigned int iSeed) const { return teunits_[iSeed]; }
0150     unsigned int trpunits(unsigned int iSeed) const { return trpunits_[iSeed]; }
0151 
0152     unsigned int NTC(int seed) const { return ntc_[seed]; }
0153 
0154     unsigned int projlayers(unsigned int iSeed, unsigned int i) const { return projlayers_[iSeed][i]; }
0155     unsigned int projdisks(unsigned int iSeed, unsigned int i) const { return projdisks_[iSeed][i]; }
0156     double rphimatchcut(unsigned int iSeed, unsigned int ilayer) const { return rphimatchcut_[ilayer][iSeed]; }
0157     double zmatchcut(unsigned int iSeed, unsigned int ilayer) const { return zmatchcut_[ilayer][iSeed]; }
0158     double rphicutPS(unsigned int iSeed, unsigned int idisk) const { return rphicutPS_[idisk][iSeed]; }
0159     double rcutPS(unsigned int iSeed, unsigned int idisk) const { return rcutPS_[idisk][iSeed]; }
0160     double rphicut2S(unsigned int iSeed, unsigned int idisk) const { return rphicut2S_[idisk][iSeed]; }
0161     double rcut2S(unsigned int iSeed, unsigned int idisk) const { return rcut2S_[idisk][iSeed]; }
0162 
0163     double rmean(unsigned int iLayer) const { return irmean_[iLayer] * rmaxdisk_ / 4096; }
0164     double rmax(unsigned int iLayer) const { return rmean(iLayer) + drmax(); }
0165     double rmin(unsigned int iLayer) const { return rmean(iLayer) - drmax(); }
0166     double zmean(unsigned int iDisk) const { return izmean_[iDisk] * zlength_ / 2048; }
0167     double zmax(unsigned int iDisk) const { return zmean(iDisk) + dzmax(); }
0168     double zmin(unsigned int iDisk) const { return zmean(iDisk) - dzmax(); }
0169 
0170     double zmindisk(unsigned int iDisk) const { return zmean(iDisk) - zsepdisk_ / 2; }
0171     double zmaxdisk(unsigned int iDisk) const { return zmean(iDisk) + zsepdisk_ / 2; }
0172 
0173     double rDSSinner(unsigned int iBin) const {
0174       return rDSSinner_mod_[iBin / 2] + halfstrip_ * ((iBin % 2 == 0) ? -1 : 1);
0175     }
0176     double rDSSouter(unsigned int iBin) const {
0177       return rDSSouter_mod_[iBin / 2] + halfstrip_ * ((iBin % 2 == 0) ? -1 : 1);
0178     }
0179 
0180     unsigned int vmrlutzbits(unsigned int layerdisk) const { return vmrlutzbits_[layerdisk]; }
0181     unsigned int vmrlutrbits(unsigned int layerdisk) const { return vmrlutrbits_[layerdisk]; }
0182 
0183     bool printDebugKF() const { return printDebugKF_; }
0184     bool debugTracklet() const { return debugTracklet_; }
0185     bool writetrace() const { return writetrace_; }
0186 
0187     bool warnNoMem() const { return warnNoMem_; }
0188     bool warnNoDer() const { return warnNoDer_; }
0189 
0190     bool writeMem() const { return writeMem_; }
0191     bool writeTable() const { return writeTable_; }
0192     bool writeConfig() const { return writeConfig_; }
0193 
0194     std::string memPath() const { return memPath_; }
0195     std::string tablePath() const { return tablePath_; }
0196 
0197     bool writeVerilog() const { return writeVerilog_; }
0198     bool writeHLS() const { return writeHLS_; }
0199     bool writeInvTable() const { return writeInvTable_; }
0200     bool writeHLSInvTable() const { return writeHLSInvTable_; }
0201 
0202     unsigned int writememsect() const { return writememsect_; }
0203 
0204     bool enableTripletTables() const { return enableTripletTables_; }
0205     bool writeTripletTables() const { return writeTripletTables_; }
0206 
0207     bool writeoutReal() const { return writeoutReal_; }
0208 
0209     bool bookHistos() const { return bookHistos_; }
0210 
0211     double ptcut() const { return ptcut_; }
0212     double rinvcut() const { return 0.01 * c_ * bfield_ / ptcut_; }  //0.01 to convert to cm-1
0213 
0214     double c() const { return c_; }
0215 
0216     double rinvmax() const { return 0.01 * c_ * bfield_ / ptmin_; }
0217 
0218     int alphashift() const { return alphashift_; }
0219     int nbitsalpha() const { return nbitsalpha_; }
0220     int alphaBitsTable() const { return alphaBitsTable_; }
0221     int nrinvBitsTable() const { return nrinvBitsTable_; }
0222 
0223     unsigned int MEBinsBits() const { return MEBinsBits_; }
0224     unsigned int MEBins() const { return 1u << MEBinsBits_; }
0225     unsigned int MEBinsDisks() const { return MEBinsDisks_; }
0226     unsigned int maxStubsPerBin() const { return maxStubsPerBin_; }
0227 
0228     std::string geomext() const {
0229       std::string geo = extended_ ? "hourglassExtended" : "hourglass";
0230       if (combined_)
0231         geo += "Combined";
0232       return geo;
0233     }
0234 
0235     bool exactderivatives() const { return exactderivatives_; }
0236     bool exactderivativesforfloating() const { return exactderivativesforfloating_; }
0237     bool useapprox() const { return useapprox_; }
0238     bool usephicritapprox() const { return usephicritapprox_; }
0239 
0240     unsigned int minIndStubs() const { return minIndStubs_; }
0241     std::string removalType() const { return removalType_; }
0242     std::string mergeComparison() const { return mergeComparison_; }
0243     bool doKF() const { return doKF_; }
0244     bool doMultipleMatches() const { return doMultipleMatches_; }
0245     bool fakefit() const { return fakefit_; }
0246     void setFakefit(bool fakefit) { fakefit_ = fakefit; }
0247     bool storeTrackBuilderOutput() const { return storeTrackBuilderOutput_; }
0248     void setStoreTrackBuilderOutput(bool storeTrackBuilderOutput) {
0249       storeTrackBuilderOutput_ = storeTrackBuilderOutput;
0250     }
0251     void setRemovalType(std::string removalType) { removalType_ = removalType; }
0252     void setDoMultipleMatches(bool doMultipleMatches) { doMultipleMatches_ = doMultipleMatches; }
0253 
0254     // configurable
0255     unsigned int nHelixPar() const { return nHelixPar_; }
0256     void setNHelixPar(unsigned int nHelixPar) { nHelixPar_ = nHelixPar; }
0257 
0258     bool extended() const { return extended_; }
0259     void setExtended(bool extended) { extended_ = extended; }
0260     bool duplicateMPs() const { return duplicateMPs_; }
0261     const std::array<bool, N_LAYER + N_DISK>& layersDisksDuplicatedEqualProjBalance() const {
0262       return layersDisksDuplicatedEqualProjBalance_;
0263     }
0264     const std::array<bool, N_LAYER + N_DISK>& layersDisksDuplicatedWeightedProjBalance() const {
0265       return layersDisksDuplicatedWeightedProjBalance_;
0266     }
0267     bool combined() const { return combined_; }
0268     void setCombined(bool combined) { combined_ = combined; }
0269     bool reduced() const { return reduced_; }
0270     void setReduced(bool reduced) { reduced_ = reduced; }
0271     bool inventStubs() const { return inventStubs_; }
0272     void setInventStubs(bool inventStubs) { inventStubs_ = inventStubs; }
0273 
0274     double bfield() const { return bfield_; }
0275     void setBfield(double bfield) { bfield_ = bfield; }
0276 
0277     unsigned int nStrips(bool isPSmodule) const { return isPSmodule ? nStrips_PS_ : nStrips_2S_; }
0278     void setNStrips_PS(unsigned int nStrips_PS) { nStrips_PS_ = nStrips_PS; }
0279     void setNStrips_2S(unsigned int nStrips_2S) { nStrips_2S_ = nStrips_2S; }
0280 
0281     double stripPitch(bool isPSmodule) const { return isPSmodule ? stripPitch_PS_ : stripPitch_2S_; }
0282     void setStripPitch_PS(double stripPitch_PS) { stripPitch_PS_ = stripPitch_PS; }
0283     void setStripPitch_2S(double stripPitch_2S) { stripPitch_2S_ = stripPitch_2S; }
0284 
0285     double sensorSpacing2S() const { return sensorSpacing_2S_; }
0286 
0287     double stripLength(bool isPSmodule) const { return isPSmodule ? stripLength_PS_ : stripLength_2S_; }
0288     void setStripLength_PS(double stripLength_PS) { stripLength_PS_ = stripLength_PS; }
0289     void setStripLength_2S(double stripLength_2S) { stripLength_2S_ = stripLength_2S; }
0290 
0291     //Following functions are used for duplicate removal
0292     //Function which returns the value corresponding to the overlap size for the overlap rinv bins in DR
0293     double rinvOverlapSize() const { return rinvOverlapSize_; }
0294     //Function which returns the value corresponding to the overlap size for the overlap phi bins in DR
0295     double phiOverlapSize() const { return phiOverlapSize_; }
0296     //Function which returns the value corresponding to the number of tracks that are compared to all the other tracks per rinv bin
0297     unsigned int numTracksComparedPerBin() const { return numTracksComparedPerBin_; }
0298     //Returns the rinv bin edges you need for duplicate removal bins
0299     const std::vector<double>& rinvBins() const { return rinvBins_; }
0300     //Returns the phi bin edges you need for duplicate removal bins
0301     const std::vector<double>& phiBins() const { return phiBins_; }
0302 
0303     std::string skimfile() const { return skimfile_; }
0304     void setSkimfile(std::string skimfile) { skimfile_ = skimfile; }
0305 
0306     unsigned int nbitstrackletindex() const { return nbitstrackletindex_; }
0307     void setNbitstrackletindex(unsigned int nbitstrackletindex) { nbitstrackletindex_ = nbitstrackletindex; }
0308 
0309     unsigned int nbitsitc() const { return nbitsitc_; }
0310     unsigned int nbitsseed() const { return (extended_ ? nbitsseedextended_ : nbitsseed_); }
0311     unsigned int nbitstcindex() const { return nbitsseed() + nbitsitc(); }
0312     void setNbitsitc(unsigned int nbitsitc) { nbitsitc_ = nbitsitc; }
0313     void setNbitsseed(unsigned int nbitsseed) { nbitsseed_ = nbitsseed; }
0314     void setNbitsseedextended(unsigned int nbitsseed) { nbitsseedextended_ = nbitsseed; }
0315 
0316     // Phi width of nonant including overlaps (at widest point).
0317     double dphisectorHG() const {
0318       //These values are used in the DTC emulation code.
0319       double rsectmin = 21.8;
0320       double rsectmax = 112.7;
0321       return 2 * M_PI / N_SECTOR + rinvmax() * std::max(rcrit_ - rsectmin, rsectmax - rcrit_);
0322     }
0323 
0324     double rcrit() const { return rcrit_; }
0325 
0326     double dphisector() const { return 2 * M_PI / N_SECTOR; }
0327 
0328     double phicritmin() const { return 0.5 * dphisectorHG() - M_PI / N_SECTOR; }
0329     double phicritmax() const { return dphisectorHG() - 0.5 * dphisectorHG() + M_PI / N_SECTOR; }
0330 
0331     double phicritminmc() const { return phicritmin() - dphicritmc_; }
0332     double phicritmaxmc() const { return phicritmax() + dphicritmc_; }
0333 
0334     // Stub digitization granularities
0335     double kphi() const { return dphisectorHG() / (1 << nphibitsstub(0)); }
0336     double kphi1() const { return dphisectorHG() / (1 << nphibitsstub(N_LAYER - 1)); }
0337     double kphi(unsigned int layerdisk) const { return dphisectorHG() / (1 << nphibitsstub(layerdisk)); }
0338 
0339     double kz() const { return 2.0 * zlength_ / (1 << nzbitsstub_[0]); }
0340     double kz(unsigned int layerdisk) const { return 2.0 * zlength_ / (1 << nzbitsstub_[layerdisk]); }
0341     double kr() const { return rmaxdisk_ / (1 << nrbitsstub_[N_LAYER]); }
0342     double krbarrel() const { return 2.0 * drmax() / (1 << nrbitsstub_[0]); }
0343 
0344     double maxrinv() const { return maxrinv_; }
0345     double maxd0() const { return maxd0_; }
0346     unsigned int nbitsd0() const { return nbitsd0_; }
0347 
0348     double kd0() const { return 2 * maxd0_ / (1 << nbitsd0_); }
0349 
0350     double rinvcutte() const { return 0.01 * c_ * bfield_ / ptcutte_; }  //0.01 to convert to cm-1
0351 
0352     double rmindiskvm() const { return rmindiskvm_; }
0353     double rmaxdiskvm() const { return rmaxdiskvm_; }
0354 
0355     double rmaxdiskl1overlapvm() const { return rmaxdiskl1overlapvm_; }
0356     double rmindiskl2overlapvm() const { return rmindiskl2overlapvm_; }
0357     double rmindiskl3overlapvm() const { return rmindiskl3overlapvm_; }
0358 
0359     double rPS2S() const { return rPS2S_; }
0360 
0361     double z0cut() const { return z0cut_; }
0362 
0363     double disp_z0cut() const { return disp_z0cut_; }
0364 
0365     unsigned int NLONGVMBITS() const { return NLONGVMBITS_; }
0366     unsigned int NLONGVMBINS() const { return (1 << NLONGVMBITS_); }
0367 
0368     unsigned int ntrackletmax() const { return ((1 << nbitstrackletindex_) - 1); }
0369 
0370     //Bits used to store track parameter in tracklet
0371     int nbitsrinv() const { return nbitsrinv_; }
0372     int nbitsphi0() const { return nbitsphi0_; }
0373     int nbitst() const { return nbitst_; }
0374     int nbitsz0() const { return nbitsz0_; }
0375 
0376     //track and tracklet parameters
0377     int rinv_shift() const { return rinv_shift_; }
0378     int phi0_shift() const { return phi0_shift_; }
0379     int t_shift() const { return t_shift_; }
0380     int z0_shift() const { return z0_shift_; }
0381 
0382     //projections are coarsened from global to stub precision
0383 
0384     //projection to R parameters
0385     int SS_phiL_shift() const { return SS_phiL_shift_; }
0386     int PS_zL_shift() const { return PS_zL_shift_; }
0387 
0388     int SS_phiderL_shift() const { return SS_phiderL_shift_; }
0389     int PS_zderL_shift() const { return PS_zderL_shift_; }
0390     int SS_zderL_shift() const { return SS_zderL_shift_; }
0391 
0392     //projection to Z parameters
0393     int SS_phiD_shift() const { return SS_phiD_shift_; }
0394     int PS_rD_shift() const { return PS_rD_shift_; }
0395 
0396     int SS_phiderD_shift() const { return SS_phiderD_shift_; }
0397     int PS_rderD_shift() const { return PS_rderD_shift_; }
0398 
0399     //numbers needed for matches & fit, unclear what they are.
0400     int phi0bitshift() const { return phi0bitshift_; }
0401     int phiderbitshift() const { return phiderbitshift_; }
0402     int zderbitshift() const { return zderbitshift_; }
0403 
0404     int phiresidbits() const { return phiresidbits_; }
0405     int zresidbits() const { return zresidbits_; }
0406     int rresidbits() const { return rresidbits_; }
0407 
0408     //Trackfit
0409     int fitrinvbitshift() const { return fitrinvbitshift_; }
0410     int fitphi0bitshift() const { return fitphi0bitshift_; }
0411     int fittbitshift() const { return fittbitshift_; }
0412     int fitz0bitshift() const { return fitz0bitshift_; }
0413 
0414     //r correction bits
0415     int rcorrbits() const { return rcorrbits_; }
0416 
0417     int chisqphifactbits() const { return chisqphifactbits_; }
0418     int chisqzfactbits() const { return chisqzfactbits_; }
0419 
0420     // Helix param digisation granularities
0421     //0.02 here is the maximum range in rinv values that can be represented
0422     double krinvpars() const {
0423       int shift = ceil(-log2(0.02 * rmaxdisk_ / ((1 << nbitsrinv_) * dphisectorHG())));
0424       return dphisectorHG() / rmaxdisk_ / (1 << shift);
0425     }
0426     double kphi0pars() const { return 2 * kphi1(); }
0427     double ktpars() const { return maxt_ / (1 << nbitst_); }
0428     double kz0pars() const { return kz(); }
0429     double kd0pars() const { return kd0(); }
0430 
0431     double kphider() const { return kphi() / kr() / 256; }
0432     double kphiderdisk() const { return kphi() / kr() / 128; }
0433     double kzder() const { return 1.0 / 64; }
0434     double krder() const { return 1.0 / 128; }
0435 
0436     //This is a 'historical accident' and should be fixed so that we don't
0437     //have the factor if 2
0438     double krprojshiftdisk() const { return 2 * kr(); }
0439 
0440     double benddecode(unsigned int ibend, unsigned int layerdisk, bool isPSmodule) const {
0441       if (layerdisk >= N_LAYER && (!isPSmodule))
0442         layerdisk += N_DISK;
0443       double bend = benddecode_[layerdisk][ibend];
0444       assert(bend < 99.0);
0445       return bend;
0446     }
0447 
0448     double bendcut(unsigned int ibend, unsigned int layerdisk, bool isPSmodule) const {
0449       if (layerdisk >= N_LAYER && (!isPSmodule))
0450         layerdisk += N_DISK;
0451       double bendcut = bendcut_[layerdisk][ibend];
0452       if (bendcut <= 0.0)
0453         std::cout << "bendcut : " << layerdisk << " " << ibend << " " << isPSmodule << std::endl;
0454       assert(bendcut > 0.0);
0455       return bendcut;
0456     }
0457 
0458     // DTC in given ATCA crate slot.
0459     std::string slotToDTCname(unsigned int slot) const { return slotToDTCname_.at(slot); }
0460 
0461     // Tracker layers read by given DTC.
0462     const std::vector<int>& dtcLayers(const std::string& dtcName) const {
0463       auto iter = dtclayers_.find(dtcName);
0464       assert(iter != dtclayers_.end());
0465       return iter->second;
0466     }
0467 
0468     double bendcutte(int ibend, int layerdisk, bool isPSmodule) const { return bendcut(ibend, layerdisk, isPSmodule); }
0469 
0470     double bendcutme(int ibend, int layerdisk, bool isPSmodule) const {
0471       //Should understand why larger cut needed in disks
0472       double fact = (layerdisk < N_LAYER) ? 1.0 : 1.8;
0473       return fact * bendcut(ibend, layerdisk, isPSmodule);
0474     }
0475 
0476     bool useCalcBendCuts = true;
0477 
0478     double bendcutTE(unsigned int seed, bool inner) const {
0479       if (inner) {
0480         return bendcutTE_[seed][0];
0481       } else {
0482         return bendcutTE_[seed][1];
0483       }
0484     }
0485 
0486     double bendcutME(unsigned int layerdisk, bool isPSmodule) const {
0487       if (layerdisk >= N_LAYER && (!isPSmodule))
0488         layerdisk += N_DISK;
0489 
0490       return bendcutME_[layerdisk];
0491     }
0492 
0493     //layers/disks used by each seed
0494     std::array<std::array<int, 3>, N_SEED> seedlayers() const { return seedlayers_; }
0495 
0496     //projection layers by seed index. For each seeding index (row) the list of layers that we consider projections to
0497     std::array<std::array<unsigned int, N_LAYER - 2>, N_SEED> projlayers() const { return projlayers_; }
0498 
0499     //projection disks by seed index. For each seeding index (row) the list of diks that we consider projections to
0500     std::array<std::array<unsigned int, N_DISK>, N_SEED> projdisks() const { return projdisks_; }
0501 
0502   private:
0503     const tt::Setup* setup_;
0504 
0505     std::string fitPatternFile_;
0506     std::string processingModulesFile_;
0507     std::string memoryModulesFile_;
0508     std::string wiresFile_;
0509     std::string tableTEDFile_;
0510     std::string tableTREFile_;
0511 
0512     double rcrit_{55.0};  // critical radius for the hourglass configuration
0513 
0514     double dphicritmc_{0.005};
0515 
0516     //fraction of full r and z range that stubs can be located within layer/disk
0517     double deltarzfract_{32.0};
0518 
0519     double maxt_{32.0};  //range in t that we must cover
0520 
0521     std::array<unsigned int, N_LAYER> irmean_{{851, 1269, 1784, 2347, 2936, 3697}};
0522     std::array<unsigned int, N_DISK> izmean_{{2239, 2645, 3163, 3782, 4523}};
0523 
0524     std::array<unsigned int, N_LAYER + N_DISK> nzbitsstub_{{12, 12, 12, 8, 8, 8, 7, 7, 7, 7, 7}};
0525     std::array<unsigned int, N_LAYER + N_DISK> nphibitsstub_{{14, 14, 14, 17, 17, 17, 14, 14, 14, 14, 14}};
0526     std::array<unsigned int, N_LAYER + N_DISK> nrbitsstub_{{7, 7, 7, 7, 7, 7, 12, 12, 12, 12, 12}};
0527 
0528     unsigned int nrbitsprojderdisk_{9};
0529     unsigned int nbitsphiprojderL123_{10};
0530     unsigned int nbitsphiprojderL456_{10};
0531     unsigned int nbitszprojderL123_{10};
0532     unsigned int nbitszprojderL456_{9};
0533 
0534     unsigned int nbendbitsmedisk_{4};  // Always 4 bits even for PS disk hits, for HLS compatibility
0535 
0536     std::set<unsigned int> useseeding_{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
0537 
0538     std::array<unsigned int, N_LAYER + N_DISK> nbitsallstubs_{{3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}};
0539     std::array<unsigned int, N_LAYER + N_DISK> nbitsvmme_{{2, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2}};
0540     std::array<std::array<unsigned int, N_SEED>, 3> nbitsvmte_{
0541         {{{2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 3, 2}},  // (3 = #stubs/triplet, only row 1+2 used for tracklet)
0542          {{3, 2, 3, 3, 2, 2, 2, 2, 3, 3, 2, 2}},
0543          {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1}}}};
0544 
0545     std::array<std::array<unsigned int, N_SEED>, 3> nbitsvmtecm_{
0546         {{{2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 3, 2}},  // (3 = #stubs/triplet, only row 1+2 used for tracklet)
0547          {{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2}},
0548          {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1}}}};
0549 
0550     // FIX: There should be 3 PS10G slots & 3 PS (5G) ones.
0551     // (Will change output files used by HLS).
0552     std::vector<std::string> slotToDTCname_{
0553         "PS10G_1", "PS10G_2", "PS10G_3", "PS10G_4", "PS_1", "PS_2", "2S_1", "2S_2", "2S_3", "2S_4", "2S_5", "2S_6"};
0554 
0555     std::map<std::string, std::vector<int> > dtclayers_{{"PS10G_1", {0, 6, 8, 10}},
0556                                                         {"PS10G_2", {0, 7, 9}},
0557                                                         {"PS10G_3", {1, 7}},
0558                                                         {"PS10G_4", {6, 8, 10}},
0559                                                         {"PS_1", {2, 7}},
0560                                                         {"PS_2", {2, 9}},
0561                                                         {"2S_1", {3, 4}},
0562                                                         {"2S_2", {4}},
0563                                                         {"2S_3", {5}},
0564                                                         {"2S_4", {5, 8}},
0565                                                         {"2S_5", {6, 9}},
0566                                                         {"2S_6", {7, 10}}};
0567 
0568     double rmindiskvm_{22.5};
0569     double rmaxdiskvm_{67.0};
0570 
0571     double rmaxdiskl1overlapvm_{45.0};
0572     double rmindiskl2overlapvm_{40.0};
0573     double rmindiskl3overlapvm_{50.0};
0574 
0575     double rPS2S_{60.0};
0576 
0577     double z0cut_{15.0};
0578 
0579     double disp_z0cut_{27.0};
0580 
0581     unsigned int NLONGVMBITS_{3};
0582 
0583     double zlength_{120.0};
0584     double rmaxdisk_{120.0};
0585     double rmindisk_{20.0};
0586 
0587     double zsepdisk_{1.5};  //cm
0588 
0589     double half2SmoduleWidth_{4.57};
0590 
0591     double maxrinv_{0.006};
0592     double maxd0_{10.0};
0593 
0594     unsigned int nbitsd0_{13};
0595 
0596     double ptmin_{2.0};  //minumim pt for tracks
0597 
0598     double ptcutte_{1.8};  //Minimum pt in TE
0599 
0600     // VALUE AUTOMATICALLY INCREASED FOR EXTENDED TRACKING BY PYTHON CFG
0601     unsigned int nbitstrackletindex_{7};  //Bits used to store the tracklet index
0602 
0603     unsigned int nbitsitc_{4};           //Bits used to store the iTC, a unique
0604                                          //identifier assigned to each TC within a sector
0605     unsigned int nbitsseed_{3};          //Bits used to store the seed number
0606     unsigned int nbitsseedextended_{4};  //Bits used to store the seed number
0607                                          //in the extended project
0608 
0609     //Bits used to store track parameter in tracklet
0610     int nbitsrinv_{14};
0611     int nbitsphi0_{18};
0612     int nbitst_{14};
0613     int nbitsz0_{10};
0614 
0615     //track and tracklet parameters
0616     int rinv_shift_{-8};  // Krinv = 2^shift * Kphi/Kr
0617     int phi0_shift_{1};   // Kphi0 = 2^shift * Kphi
0618     int t_shift_{-10};    // Kt    = 2^shift * Kz/Kr
0619     int z0_shift_{0};     // Kz0   = 2^shift * kz
0620 
0621     //projections are coarsened from global to stub precision
0622 
0623     //projection to R parameters
0624     int SS_phiL_shift_{0};
0625     int PS_zL_shift_{0};  // z projections have global precision in ITC
0626 
0627     int SS_phiderL_shift_{-5};
0628     int PS_zderL_shift_{-7};  // Kderz = 2^shift * Kz/Kr
0629     int SS_zderL_shift_{-7};
0630 
0631     //projection to Z parameters
0632     int SS_phiD_shift_{3};
0633     int PS_rD_shift_{1};  // a bug?! coarser by a factor of two then stubs??
0634 
0635     int SS_phiderD_shift_{-4};
0636     int PS_rderD_shift_{-6};  //Kderrdisk = 2^shift * Kr/Kz
0637 
0638     //numbers needed for matches & fit, unclear what they are.
0639     int phi0bitshift_{1};
0640     int phiderbitshift_{7};
0641     int zderbitshift_{6};
0642 
0643     int phiresidbits_{12};
0644     int zresidbits_{9};
0645     int rresidbits_{7};
0646 
0647     //Trackfit
0648     int fitrinvbitshift_{9};  //6 OK?
0649     int fitphi0bitshift_{6};  //4 OK?
0650     int fittbitshift_{10};    //4 OK? //lower number gives rounding problems
0651     int fitz0bitshift_{8};    //6 OK?
0652 
0653     //r correction bits
0654     int rcorrbits_{6};
0655 
0656     int chisqphifactbits_{14};
0657     int chisqzfactbits_{14};
0658 
0659     std::array<unsigned int, N_SEED> teunits_{{5, 2, 5, 3, 3, 2, 3, 2, 0, 0, 0, 0}};       //teunits used by seed
0660     std::array<unsigned int, N_SEED> trpunits_{{0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10}};  //trpunits used by seed
0661 
0662     std::array<unsigned int, N_LAYER + N_DISK> vmrlutzbits_{
0663         {7, 7, 7, 7, 7, 7, 3, 3, 3, 3, 3}};  // zbits used by LUT in VMR
0664     std::array<unsigned int, N_LAYER + N_DISK> vmrlutrbits_{
0665         {4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8}};  // rbits used by LUT in VMR
0666 
0667     std::array<std::array<unsigned int, N_SEED>, 3> nfinephi_{
0668         {{{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}},    //inner  (3 = #stubs/triplet, only row 1+2 used for tracklet)
0669          {{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}},    //outer
0670          {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3}}}};  //outermost (triplets only)
0671 
0672     //These are the number of bits used for the VM regions in the TE by seedindex
0673     //FIXME not independed nbitsvmte
0674     std::array<std::array<unsigned int, N_SEED>, 3> nphireg_{
0675         {{{5, 4, 4, 4, 4, 4, 4, 3, 4, 4, 5, 4}},    //inner
0676          {{5, 4, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4}},    //outer
0677          {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4}}}};  //outermost (triplets only)
0678 
0679     //For combined modules
0680     std::array<std::array<unsigned int, N_SEED>, 3> nphiregcm_{
0681         {{{5, 4, 4, 4, 4, 4, 4, 3, 4, 4, 5, 4}},    //inner
0682          {{5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4}},    //outer
0683          {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4}}}};  //outermost (triplets only)
0684 
0685     // These are the number of bits to represent lutval for VM memories in TE
0686     std::array<std::array<unsigned int, N_SEED>, 3> lutwidthtab_{{{{10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 11, 0}},
0687                                                                   {{6, 6, 6, 6, 10, 10, 10, 10, 0, 0, 6, 0}},
0688                                                                   {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6}}}};
0689 
0690     // These are the number of bits to represent lutval for VM memories in TED
0691     // TO DO: tune lutwidthtabextended_ values
0692 
0693     /* std::array<std::array<unsigned int, N_SEED>, 3> lutwidthtabextended_{ */
0694     /*     {{{11, 11, 21, 21, 21, 21, 11, 11, 0, 0, 21, 0}}, */
0695     /*      {{6, 6, 6, 6, 10, 10, 10, 10, 0, 0, 6, 0}}, */
0696     /*      {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6}}}}; */
0697 
0698     std::array<std::array<unsigned int, N_SEED>, 3> lutwidthtabextended_{
0699         {{{21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21}},
0700          {{21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21}},
0701          {{21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21}}}};
0702 
0703     //layers/disks used by each seed
0704     std::array<std::array<int, 3>, N_SEED> seedlayers_{{{{0, 1, -1}},   //L1L2
0705                                                         {{1, 2, -1}},   //1 L2L3
0706                                                         {{2, 3, -1}},   //2 L3L4
0707                                                         {{4, 5, -1}},   //3 L5L6
0708                                                         {{6, 7, -1}},   //4 D1D2
0709                                                         {{8, 9, -1}},   //5 D3D4
0710                                                         {{0, 6, -1}},   //6 L1D1
0711                                                         {{1, 6, -1}},   //7 L2D1
0712                                                         {{2, 3, 1}},    //8 L2L3L4
0713                                                         {{4, 5, 3}},    //9 L4L5L6
0714                                                         {{1, 2, 6}},    //10 L2L3D1
0715                                                         {{6, 7, 1}}}};  //11 D1D2L2
0716 
0717     //Number of tracklet calculators for the prompt seeding combinations
0718     std::array<unsigned int, N_SEED> ntc_{{12, 4, 4, 4, 4, 4, 8, 4, 0, 0, 0, 0}};
0719 
0720     //projection layers by seed index. For each seeding index (row) the list of layers that we consider projections to
0721     std::array<std::array<unsigned int, N_LAYER - 2>, N_SEED> projlayers_{{{{3, 4, 5, 6}},  //0 L1L2
0722                                                                            {{1, 4, 5, 6}},  //1 L2L3
0723                                                                            {{1, 2, 5, 6}},  //2 L3L4
0724                                                                            {{1, 2, 3, 4}},  //3 L5L6
0725                                                                            {{1, 2}},        //4 D1D2
0726                                                                            {{1}},           //5 D3D4
0727                                                                            {{}},            //6 L1D1
0728                                                                            {{1}},           //7 L2D1
0729                                                                            {{1, 5, 6}},     //8 L2L3L4
0730                                                                            {{1, 2, 3}},     //9 L4L5L6
0731                                                                            {{1}},           //10 L2L3D1
0732                                                                            {{1}}}};         //11 D1D2L2
0733 
0734     //projection disks by seed index. For each seeding index (row) the list of diks that we consider projections to
0735     std::array<std::array<unsigned int, N_DISK>, N_SEED> projdisks_{{{{1, 2, 3, 4}},  //0 L1L2
0736                                                                      {{1, 2, 3, 4}},  //1 L2L3
0737                                                                      {{1, 2}},        //2 L3L4
0738                                                                      {{}},            //3 L5L6
0739                                                                      {{3, 4, 5}},     //4 D1D2
0740                                                                      {{1, 2, 5}},     //5 D3D4
0741                                                                      {{2, 3, 4, 5}},  //6 L1D1
0742                                                                      {{2, 3, 4}},     //7 L2D1
0743                                                                      {{1, 2, 3}},     //8 L2L3L4
0744                                                                      {{}},            //9 L4L5L6
0745                                                                      {{2, 3, 4}},     //10 L2L3D1
0746                                                                      {{3, 4}}}};      //11 D1D2L2
0747 
0748     //rphi cuts for layers - the column is the seedindex
0749     std::array<std::array<double, N_SEED>, N_LAYER> rphimatchcut_{
0750         {{{0.0, 0.1, 0.07, 0.08, 0.07, 0.05, 0.0, 0.05, 0.08, 0.15, 0.125, 0.15}},  //Layer 1
0751          {{0.0, 0.0, 0.06, 0.08, 0.05, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.0}},         //Layer 2
0752          {{0.1, 0.0, 0.0, 0.08, 0.0, 0.0, 0.0, 0.0, 0.0, 0.08, 0.0, 0.0}},          //Layer 3
0753          {{0.19, 0.19, 0.0, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}},         //Layer 4
0754          {{0.4, 0.4, 0.08, 0.0, 0.0, 0.0, 0.0, 0.0, 0.08, 0.0, 0.0, 0.0}},          //Layer 5
0755          {{0.5, 0.0, 0.19, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.0, 0.0}}}};         //Layer 6
0756 
0757     //z cuts for layers - the column is the seedindex
0758     std::array<std::array<double, N_SEED>, N_LAYER> zmatchcut_{
0759         {{{0.0, 0.7, 5.5, 15.0, 1.5, 2.0, 0.0, 1.5, 1.0, 8.0, 1.0, 1.5}},   //Layer 1
0760          {{0.0, 0.0, 3.5, 15.0, 1.25, 0.0, 0.0, 0.0, 0.0, 7.0, 0.0, 0.0}},  //Layer 2
0761          {{0.7, 0.0, 0.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 0.0, 0.0}},    //Layer 3
0762          {{3.0, 3.0, 0.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}},    //Layer 4
0763          {{3.0, 3.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.5, 0.0, 0.0, 0.0}},    //Layer 5
0764          {{4.0, 0.0, 9.5, 0.0, 0.0, 0.0, 0.0, 0.0, 4.5, 0.0, 0.0, 0.0}}}};  //Layer 6
0765 
0766     //rphi cuts for PS modules in disks - the column is the seedindex
0767     std::array<std::array<double, N_SEED>, N_DISK> rphicutPS_{
0768         {{{0.2, 0.2, 0.0, 0.0, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}},     //disk 1
0769          {{0.2, 0.2, 0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.0, 0.0, 0.15, 0.0}},    //disk 2
0770          {{0.25, 0.2, 0.0, 0.0, 0.15, 0.0, 0.2, 0.15, 0.0, 0.0, 0.0, 0.2}},  //disk 3
0771          {{0.5, 0.2, 0.0, 0.0, 0.2, 0.0, 0.3, 0.5, 0.0, 0.0, 0.0, 0.0}},     //disk 4
0772          {{0.0, 0.0, 0.0, 0.0, 0.25, 0.1, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0}}}};  //disk 5
0773 
0774     //r cuts for PS modules in disks - the column is the seedindex
0775     std::array<std::array<double, N_SEED>, N_DISK> rcutPS_{
0776         {{{0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}},    //disk 1
0777          {{0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 0.5, 0.0}},    //disk 2
0778          {{0.5, 0.5, 0.0, 0.0, 0.5, 0.0, 0.6, 0.8, 0.0, 0.0, 0.0, 0.4}},    //disk 3
0779          {{0.5, 0.5, 0.0, 0.0, 0.8, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0}},    //disk 4
0780          {{0.0, 0.0, 0.0, 0.0, 1.0, 0.5, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0}}}};  //disk 5
0781 
0782     //rphi cuts for 2S modules in disks = the column is the seedindex
0783     std::array<std::array<double, N_SEED>, N_DISK> rphicut2S_{
0784         {{{0.5, 0.5, 0.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.0, 0.0, 0.0}},    //disk 1
0785          {{0.5, 0.5, 0.8, 0.0, 0.0, 0.0, 0.5, 0.15, 0.3, 0.0, 0.68, 0.0}},  //disk 2
0786          {{0.5, 0.5, 0.0, 0.0, 0.15, 0.0, 0.2, 0.25, 0.0, 0.0, 0.8, 0.1}},  //disk 3
0787          {{0.5, 0.5, 0.0, 0.0, 0.2, 0.0, 0.25, 0.5, 0.0, 0.0, 0.6, 0.4}},   //disk 4
0788          {{0.0, 0.0, 0.0, 0.0, 0.4, 0.2, 0.4, 0.0, 0.0, 0.0, 0.0, 0.8}}}};  //disk 5
0789 
0790     //r cuts for 2S modules in disks -the column is the seedindex
0791     std::array<std::array<double, N_SEED>, N_DISK> rcut2S_{
0792         {{{3.8, 3.8, 3.8, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0}},    //disk 1
0793          {{3.8, 3.8, 3.8, 0.0, 0.0, 0.0, 3.8, 3.4, 3.0, 0.0, 3.0, 0.0}},    //disk 2
0794          {{3.6, 3.8, 0.0, 0.0, 3.6, 0.0, 3.6, 3.8, 0.0, 0.0, 3.8, 3.0}},    //disk 3
0795          {{3.6, 3.8, 0.0, 0.0, 3.6, 0.0, 3.5, 3.8, 0.0, 0.0, 3.0, 3.0}},    //disk 4
0796          {{0.0, 0.0, 0.0, 0.0, 3.6, 3.4, 3.7, 0.0, 0.0, 0.0, 0.0, 3.0}}}};  //disk 5
0797 
0798     //returns the mean bend (in strips at a 1.8 mm separation) for bendcode
0799     std::array<std::array<double, 16>, 16> benddecode_{
0800         {{{0.0, 0.5, 0.7, 0.8, 89.9, -1.0, -0.9, -0.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}},  //L1 PS
0801          {{0.0, 0.7, 1.0, 1.5, 89.9, -1.5, -1.0, -0.7, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}},  //L2 PS
0802          {{0.0, 1.0, 1.8, 2.2, 89.9, -2.2, -1.8, -1.0, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}},  //L3 PS
0803          {{0.0, 0.7, 1.2, 1.8, 2.1, 2.6, 3.2, 3.5, 89.9, -3.5, -3.2, -2.6, -2.1, -1.8, -1.2, -0.7}},      //L4 2S
0804          {{0.0, 0.8, 1.2, 1.8, 2.2, 3.2, 4.1, 4.4, 89.9, -4.4, -4.1, -3.2, -2.2, -1.8, -1.2, -0.8}},      //L5 2S
0805          {{0.0, 0.9, 1.8, 2.8, 3.8, 4.5, 5.3, 5.9, 89.9, -5.9, -5.3, -4.5, -3.8, -2.8, -1.8, -0.9}},      //L6 2S
0806          {{0.0, 0.8, 1.2, 2.0, 89.9, -2.0, -1.2, -0.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}},  //D1 PS
0807          {{0.0, 1.5, 1.8, 2.4, 89.9, -2.4, -1.8, -1.4, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}},  //D2 PS
0808          {{0.0, 1.7, 2.0, 2.2, 89.9, -2.2, -2.0, -1.7, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}},  //D3 PS
0809          {{0.0, 1.8, 2.0, 2.4, 89.9, -2.4, -2.0, -1.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}},  //D4 PS
0810          {{0.0, 2.0, 2.2, 2.4, 89.9, -2.4, -2.0, -1.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}},  //D5 PS
0811          {{0.0, 1.8, 2.3, 2.5, 3.0, 3.9, 4.5, 5.2, 89.9, -5.2, -4.5, -3.9, -3.0, -2.5, -2.3, -1.8}},      //D1 2S
0812          {{0.0, 2.0, 2.4, 2.9, 3.2, 4.0, 4.8, 5.2, 89.9, -5.2, -4.8, -4.0, -3.2, -2.9, -2.4, -2.0}},      //D2 2S
0813          {{0.0, 2.0, 2.4, 2.7, 3.6, 3.7, 4.4, 4.6, 89.9, -4.6, -4.4, -3.7, -3.6, -2.7, -2.4, -2.0}},      //D3 2S
0814          {{0.0, 2.0, 2.6, 3.2, 3.8, 4.0, 4.4, 4.4, 89.9, -4.4, -4.4, -4.0, -3.8, -3.2, -2.6, -2.0}},      //D4 2S
0815          {{0.0, 2.0, 3.2, 3.4, 3.9, 3.9, 4.4, 4.4, 89.9, -4.4, -4.4, -3.9, -3.9, -3.4, -3.2, -2.0}}}};    //D5 2S
0816 
0817     //returns the bend 'cut' (in strips at a 1.8 mm separation) for bendcode
0818     std::array<std::array<double, 16>, 16> bendcut_{
0819         {{{1.5, 1.2, 0.8, 0.8, 99.9, 0.8, 0.8, 1.2, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}},  //L1 PS
0820          {{1.5, 1.3, 1.0, 1.0, 99.9, 1.0, 1.0, 1.3, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}},  //L2 PS
0821          {{1.6, 1.5, 1.0, 1.0, 99.9, 1.0, 1.0, 1.5, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}},  //L3 PS
0822          {{1.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}},          //L4 2S
0823          {{1.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}},          //L5 2S
0824          {{1.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}},          //L6 2S
0825          {{1.8, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}},  //D1 PS
0826          {{1.8, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}},  //D2 PS
0827          {{1.8, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}},  //D3 PS
0828          {{2.2, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}},  //D4 PS
0829          {{2.2, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}},  //D5 PS
0830          {{2.0, 1.2, 1.2, 1.2, 1.5, 1.5, 1.5, 1.5, 99.9, 1.5, 1.5, 1.5, 1.5, 1.2, 1.2, 1.2}},          //D1 2S
0831          {{2.0, 1.2, 1.2, 1.2, 1.5, 1.5, 1.5, 1.5, 99.9, 1.5, 1.5, 1.5, 1.5, 1.2, 1.2, 1.2}},          //D2 2S
0832          {{2.2, 1.5, 1.5, 1.5, 2.0, 2.0, 2.0, 2.0, 99.9, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5, 1.5}},          //D3 2S
0833          {{2.5, 1.5, 1.5, 2.0, 2.0, 2.0, 2.0, 2.0, 99.9, 2.0, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5}},          //D4 2S
0834          {{2.5, 1.5, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 99.9, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.5}}}};        //D5 2S
0835 
0836     double FEbendcut = sqrt(1 / 6.0);
0837 
0838     double bendcutTE_[N_SEED_PROMPT][2] = {{2.2 * FEbendcut, 2.5 * FEbendcut},   //L1L2
0839                                            {2.0 * FEbendcut, 2.0 * FEbendcut},   //L2L3
0840                                            {2.0 * FEbendcut, 2.6 * FEbendcut},   //L3L4
0841                                            {2.4 * FEbendcut, 2.4 * FEbendcut},   //L5L6
0842                                            {2.5 * FEbendcut, 2.2 * FEbendcut},   //D1D2 PS
0843                                            {2.0 * FEbendcut, 2.0 * FEbendcut},   //D3D4 PS
0844                                            {2.0 * FEbendcut, 2.4 * FEbendcut},   //L1D1 PS
0845                                            {2.2 * FEbendcut, 2.2 * FEbendcut}};  //L2D1 PS
0846 
0847     double bendcutME_[N_LAYER + 2 * N_DISK] = {2.0 * FEbendcut,   //0  L1
0848                                                2.5 * FEbendcut,   //1  L2
0849                                                2.0 * FEbendcut,   //2  L3
0850                                                2.5 * FEbendcut,   //3  L4
0851                                                2.2 * FEbendcut,   //4  L5
0852                                                2.3 * FEbendcut,   //5  L6
0853                                                4.0 * FEbendcut,   //6  D1 PS
0854                                                3.5 * FEbendcut,   //7  D2 PS
0855                                                3.5 * FEbendcut,   //8  D3 PS
0856                                                3.5 * FEbendcut,   //9  D4 PS
0857                                                2.7 * FEbendcut,   //10 D5 PS
0858                                                3.5 * FEbendcut,   //11 D1 2S
0859                                                3.4 * FEbendcut,   //12 D2 2S
0860                                                3.5 * FEbendcut,   //13 D3 2S
0861                                                3.7 * FEbendcut,   //14 D4 2S
0862                                                3.5 * FEbendcut};  //15 D5 2S
0863 
0864     // Offset to the maximum number of steps in each processing step:
0865     // Set to 0 (default) means standard truncation
0866     // Set to large value, e.g. 10000, to disable truncation
0867     unsigned int maxstepoffset_{0};
0868     // turn off truncation for displaced tracking (not implemented properly for displaced seeding)
0869     unsigned int maxstepoffset_extended_{10000};
0870 
0871     //Number of processing steps for one event (108=18TM*240MHz/40MHz)
0872 
0873     //IR should be set to 108 to match the FW for the summer chain, but ultimately should be at 156
0874     std::unordered_map<std::string, unsigned int> maxstep_{
0875         {"IR", 156},  //IR will run at a higher clock speed to handle
0876                       //input links running at 25 Gbits/s
0877         //Set to 108 to match firmware project 240 MHz clock
0878 
0879         {"VMR", 107},
0880         {"TE", 107},
0881         {"TC", 108},
0882         {"PR", 108},
0883         {"ME", 108},
0884         //NOTE: The MC is set to 108, but `mergedepth`
0885         //removes 3 iterations to emulate the delay
0886         //due to the HLS priority encoder
0887         {"MC", 108},
0888         {"TB", 108},
0889         {"MP", 108},
0890         {"TP", 108},
0891         {"TPD", 108},
0892         {"TRE", 108},
0893         {"DR", 108}};  //Specifies how many tracks allowed per bin in DR
0894 
0895     // If set to true this creates txt files, which the ROOT macros in
0896     // https://github.com/cms-L1TK/TrackPerf/tree/master/PatternReco
0897     // can then use to study truncation of individual algo steps within tracklet chain.
0898     std::unordered_map<std::string, bool> writeMonitorData_{{"IL", false},
0899                                                             {"TE", false},
0900                                                             {"CT", false},
0901                                                             {"HitPattern", false},
0902                                                             {"ChiSq", false},
0903                                                             {"Seeds", false},
0904                                                             {"FT", false},
0905                                                             {"Residuals", false},
0906                                                             {"StubBend", false},
0907                                                             {"MC", false},
0908                                                             {"MP", false},
0909                                                             {"ME", false},
0910                                                             {"AP", false},
0911                                                             {"VMP", false},
0912                                                             {"TrackProjOcc", false},
0913                                                             {"TC", false},
0914                                                             {"Pars", false},
0915                                                             {"TPars", false},
0916                                                             {"TPD", false},
0917                                                             {"TrackletPars", false},
0918                                                             {"TED", false},
0919                                                             {"TP", false},
0920                                                             {"TRE", false},
0921                                                             {"VMR", false},
0922                                                             {"StubsLayer", false},
0923                                                             {"StubsLayerSector", false},
0924                                                             {"HitEff", false},
0925                                                             {"MatchEff", false},
0926                                                             {"IFit", false},
0927                                                             {"AS", false},
0928                                                             {"WriteEmptyProj", false}};
0929 
0930     std::array<double, N_DSS_MOD> rDSSinner_mod_{{68.9391, 78.7750, 85.4550, 96.3150, 102.3160}};
0931     std::array<double, N_DSS_MOD> rDSSouter_mod_{{66.4903, 76.7750, 84.4562, 94.9920, 102.3160}};
0932 
0933     //we want the center of the two strip positions in a module, not just the center of a module
0934     double halfstrip_{2.5};
0935 
0936     // various printouts for debugging and warnings
0937     bool printDebugKF_{false};   // if true print lots of debugging statements related to the KF fit
0938     bool debugTracklet_{false};  //Print detailed debug information about tracklet tracking
0939     bool writetrace_{false};     //Print out details about parsing configuration files
0940 
0941     bool warnNoMem_{false};  //If true will print out warnings about missing projection memories
0942     bool warnNoDer_{false};  //If true will print out warnings about missing track fit derivatives
0943 
0944     //--- These used to create files needed by HLS code.
0945     bool writeMem_{false};     //If true will print out content of memories (between algo steps) to files
0946     bool writeTable_{false};   //If true will print out content of LUTs to files
0947     bool writeConfig_{false};  //If true will print out the autogenerated configuration as files
0948     std::string memPath_{"../data/MemPrints/"};  //path for writing memories
0949     std::string tablePath_{"../data/LUTs/"};     //path for writing LUTs
0950 
0951     // Write various lookup tables and autogenerated code (from iMath)
0952     bool writeVerilog_{false};      //Write out auto-generated Verilog mudules used by TCs
0953     bool writeHLS_{false};          //Write out auto-generated HLS mudules used by TCs
0954     bool writeInvTable_{false};     //Write out tables of drinv and invt in tracklet calculator for Verilog module
0955     bool writeHLSInvTable_{false};  //Write out tables of drinv and invt in tracklet calculator for HLS module
0956 
0957     unsigned int writememsect_{3};  //writemem only for this sector (note that the files will have _4 extension)
0958 
0959     bool enableTripletTables_{false};  //Enable the application of the TED and
0960                                        //TRE tables; when this flag is false,
0961                                        //the tables will not be read from disk
0962     bool writeTripletTables_{false};   //Train and write the TED and TRE tables. N.B.: the tables
0963                                        //cannot be applied while they are being trained, i.e.,
0964                                        //this flag effectively turns off the cuts in
0965                                        //TrackletEngineDisplaced and TripletEngine
0966 
0967     bool writeoutReal_{false};
0968 
0969     //set to true/false to turn on/off histogram booking internal to the tracking (class "HistBase/HistImp", does nothing in central CMSSW)
0970     bool bookHistos_{false};
0971 
0972     // pt constants
0973     double ptcut_{1.91};  //Minimum pt cut
0974 
0975     // Parameters for bit sizes
0976     int alphashift_{12};
0977     int nbitsalpha_{4};      //bits used to store alpha
0978     int alphaBitsTable_{2};  //For number of bits in track derivative table
0979     int nrinvBitsTable_{3};  //number of bits for tabulating rinv dependence
0980 
0981     unsigned int MEBinsBits_{3};
0982     unsigned int MEBinsDisks_{8};      //on each side
0983     unsigned int maxStubsPerBin_{15};  //16 causes overflow!
0984 
0985     // Options for chisq fit
0986     bool exactderivatives_{false};
0987     bool exactderivativesforfloating_{true};  //only for the floating point
0988     bool useapprox_{true};          //use approximate postion based on integer representation for floating point
0989     bool usephicritapprox_{false};  //use floating point approximate version of phicrit cut if true
0990 
0991     // Duplicate Removal
0992     // "merge" (hybrid dup removal)
0993     // "ichi" (pairwise, keep track with best ichisq), "nstub" (pairwise, keep track with more stubs)
0994     // "grid" (TMTT-like removal), "" (no removal)
0995     unsigned int minIndStubs_{3};  // not used with merge removal
0996 
0997 #ifdef USEHYBRID
0998     // Duplicate track removal algo. VALUE HERE OVERRIDDEN BY PYTHON CFG
0999     std::string removalType_{"merge"};
1000     // "CompareBest" (recommended) Compares only the best stub in each track for each region (best = smallest phi residual)
1001     // and will merge the two tracks if stubs are shared in three or more regions
1002     // "CompareAll" Compares all stubs in a region, looking for matches, and will merge the two tracks if stubs are shared in three or more regions
1003     std::string mergeComparison_{"CompareBest"};
1004     bool doKF_{true};
1005 #else
1006     std::string removalType_{"ichi"};
1007     std::string mergeComparison_{""};
1008     bool doKF_{false};
1009 #endif
1010 
1011     // VALUE OVERRIDDEN BY PYTHON CFG
1012     // When false, match calculator does not save multiple matches, even when doKF=true.
1013     // This is a temporary fix for compatibilty with HLS. We will need to implement multiple match
1014     // printing in emulator eventually, possibly after CMSSW-integration inspired rewrites
1015     // Use false when generating HLS files, use true when doing full hybrid tracking
1016     bool doMultipleMatches_{true};
1017 
1018     // NEXT 2 VALUES OVERRIDDEN BY PYTHON CFG
1019     // if true, run a dummy fit, producing TTracks directly from output of tracklet pattern reco stage
1020     bool fakefit_{false};
1021     // if true, EDProducer fills additional bit & clock accurate TrackBuilder EDProduct
1022     bool storeTrackBuilderOutput_{false};
1023 
1024     // NEXT 3 VALUES OVERRIDDEN BY PYTHON CFG
1025     unsigned int nHelixPar_{4};  // 4 or 5 param helix fit
1026     bool extended_{false};       // turn on displaced tracking
1027     bool reduced_{false};        // use reduced (Summer Chain) config
1028     bool inventStubs_{false};    // invent seeding stub coordinates based on tracklet traj
1029 
1030     // Use combined TP (TE+TC) & MP (PR+ME+MC) config (with prompt tracking)
1031     bool combined_{true};
1032     // N.B. For extended tracking, this combined_ is overridden by python cfg
1033     // to false, but combined modules are nonetheless used by default.
1034     // If you don't want them, edit l1tTTTracksFromTrackletEmulation_cfi.py
1035     // to refer to *_hourglassExtended.dat .
1036 
1037     // Use chain with duplicated MPs for L3,L4 to reduce truncation issue
1038     // Balances load from projections roughly in half for each of the two MPs
1039     bool duplicateMPs_{false};
1040 
1041     // Determines which layers, disks the MatchProcessor is duplicated for
1042     // (note: in TCB by default always duplicated for phi B, C as truncation is significantly worse than A, D)
1043     // All layers, disks disabled by default, also is overwritten by above duplicateMPs bool
1044 
1045     // EqualProjBalancing is for layers for which the projections to each duplicated MP are split in half sequentially
1046     std::array<bool, N_LAYER + N_DISK> layersDisksDuplicatedEqualProjBalance_{
1047         {false, false, false, false, false, false, false, false, false, false, false}};
1048 
1049     // Weighted proj balancing is for specifically L4, L5 where the split of the projections is weighted to account for
1050     // Higher occupancy in the L1L2 seed to minimize truncation
1051     std::array<bool, N_LAYER + N_DISK> layersDisksDuplicatedWeightedProjBalance_{
1052         {false, false, false, false, false, false, false, false, false, false, false}};
1053 
1054     // Example use where for L3, L4, L5, D2, D3, the layers/disks where truncation is worst
1055     //std::array<bool, N_LAYER + N_DISK> layersDisksDuplicatedEqualProjBalance_{{0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0}};
1056     //std::array<bool, N_LAYER + N_DISK> layersDisksDuplicatedWeightedProjBalance_{{0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}};
1057 
1058     std::string skimfile_{""};  //if not empty events will be written out in ascii format to this file
1059 
1060     double bfield_{3.8112};  //B-field in T
1061     double c_{0.299792458};  //speed of light m/ns
1062 
1063     unsigned int nStrips_PS_{960};
1064     unsigned int nStrips_2S_{1016};
1065 
1066     double stripPitch_PS_{0.01};
1067     double stripPitch_2S_{0.009};
1068 
1069     double stripLength_PS_{0.1467};
1070     double stripLength_2S_{5.0250};
1071 
1072     // The DR binning below disabled, as doesn't match latest FW.
1073 
1074     //Following values are used for duplicate removal
1075     //Only one bin currently used.
1076     std::vector<double> rinvBins_{-rinvcut(), rinvcut()};
1077     std::vector<double> phiBins_{0, dphisectorHG()};
1078     //Overlap size for the overlap rinv bins in DR
1079     double rinvOverlapSize_{0.0004};
1080     //Overlap size for the overlap phi bins in DR
1081     double phiOverlapSize_{M_PI / 360};
1082     //The maximum number of tracks that are compared to all the other tracks per rinv bin
1083     int numTracksComparedPerBin_{9999};
1084 
1085     double sensorSpacing_2S_{0.18};
1086   };
1087 
1088   constexpr unsigned int N_TILTED_RINGS = 12;  // # of tilted rings per half-layer in TBPS layers
1089   constexpr std::array<unsigned int, N_PSLAYER> N_MOD_PLANK = {{7, 11, 15}};  // # of flat barrel modules/plank in TBPS
1090 
1091   constexpr unsigned int N_TRKLSEED = 7;  // # of tracklet seeds
1092   constexpr unsigned int N_PROJ = 4;      // # of projections (beyond stubs from tracklet seed)
1093 
1094   // chi2 fitting
1095   constexpr unsigned int N_FITPARAM = 4;  // # of fit parameters for chi2 fit
1096   constexpr unsigned int N_FITSTUB = 6;   // max # of number of stubs used
1097 
1098   constexpr unsigned int N_TRACKDER_PTBIN = 4;
1099   constexpr unsigned int N_TRACKDER_INDEX = 1000;
1100 
1101 }  // namespace trklet
1102 
1103 #endif