Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:33:39

0001 #include "L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h"
0003 #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h"
0004 #include "L1Trigger/TrackFindingTracklet/interface/Globals.h"
0005 #include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
0006 #include "L1Trigger/TrackFindingTracklet/interface/Util.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 
0011 #include <filesystem>
0012 
0013 using namespace trklet;
0014 using namespace std;
0015 
0016 TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global)
0017     : ProcessBase(name, settings, global), innerptlut_(settings), outerptlut_(settings) {
0018   stubpairs_ = nullptr;
0019   innervmstubs_ = nullptr;
0020   outervmstubs_ = nullptr;
0021 
0022   initLayerDisksandISeed(layerdisk1_, layerdisk2_, iSeed_);
0023 
0024   innerphibits_ = settings.nfinephi(0, iSeed_);
0025   outerphibits_ = settings.nfinephi(1, iSeed_);
0026 }
0027 
0028 void TrackletEngine::addOutput(MemoryBase* memory, string output) {
0029   if (settings_.writetrace()) {
0030     edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
0031                                  << output;
0032   }
0033   if (output == "stubpairout") {
0034     StubPairsMemory* tmp = dynamic_cast<StubPairsMemory*>(memory);
0035     assert(tmp != nullptr);
0036     stubpairs_ = tmp;
0037     return;
0038   }
0039   throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
0040 }
0041 
0042 void TrackletEngine::addInput(MemoryBase* memory, string input) {
0043   if (settings_.writetrace()) {
0044     edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
0045                                  << input;
0046   }
0047   if (input == "innervmstubin") {
0048     VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
0049     assert(tmp != nullptr);
0050     innervmstubs_ = tmp;
0051     setVMPhiBin();
0052     return;
0053   }
0054   if (input == "outervmstubin") {
0055     VMStubsTEMemory* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
0056     assert(tmp != nullptr);
0057     outervmstubs_ = tmp;
0058     setVMPhiBin();
0059     return;
0060   }
0061   throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
0062 }
0063 
0064 void TrackletEngine::execute() {
0065   if (!settings_.useSeed(iSeed_))
0066     return;
0067 
0068   unsigned int countall = 0;
0069   unsigned int countpass = 0;
0070 
0071   assert(innervmstubs_ != nullptr);
0072   assert(outervmstubs_ != nullptr);
0073 
0074   for (unsigned int i = 0; i < innervmstubs_->nVMStubs(); i++) {
0075     const VMStubTE& innervmstub = innervmstubs_->getVMStubTE(i);
0076     FPGAWord lookupbits = innervmstub.vmbits();
0077 
0078     unsigned int nbits = 7;
0079     if (iSeed_ == 4 || iSeed_ == 5)
0080       nbits = 6;
0081     int rzdiffmax = lookupbits.bits(nbits, lookupbits.nbits() - nbits);
0082     int rzbinfirst = lookupbits.bits(0, 3);
0083     int start = lookupbits.bits(4, nbits - 4);
0084     int next = lookupbits.bits(3, 1);
0085 
0086     if ((iSeed_ == 4 || iSeed_ == 5) && innervmstub.stub()->disk().value() < 0) {  //TODO - need to store negative disk
0087       start += 4;
0088     }
0089     int last = start + next;
0090 
0091     for (int ibin = start; ibin <= last; ibin++) {
0092       for (unsigned int j = 0; j < outervmstubs_->nVMStubsBinned(ibin); j++) {
0093         if (countall >= settings_.maxStep("TE"))
0094           break;
0095         countall++;
0096         const VMStubTE& outervmstub = outervmstubs_->getVMStubTEBinned(ibin, j);
0097 
0098         int rzbin = outervmstub.vmbits().bits(0, 3);
0099 
0100         FPGAWord iphiinnerbin = innervmstub.finephi();
0101         FPGAWord iphiouterbin = outervmstub.finephi();
0102 
0103         unsigned int index = (iphiinnerbin.value() << outerphibits_) + iphiouterbin.value();
0104 
0105         if (iSeed_ >= 4) {  //Also use r-position
0106           int ir = ((ibin & 3) << 1) + (rzbin >> 2);
0107           index = (index << 3) + ir;
0108         }
0109 
0110         if (start != ibin)
0111           rzbin += 8;
0112         if ((rzbin < rzbinfirst) || (rzbin - rzbinfirst > rzdiffmax)) {
0113           continue;
0114         }
0115 
0116         FPGAWord innerbend = innervmstub.bend();
0117         FPGAWord outerbend = outervmstub.bend();
0118 
0119         int ptinnerindex = (index << innerbend.nbits()) + innerbend.value();
0120         int ptouterindex = (index << outerbend.nbits()) + outerbend.value();
0121 
0122         if (!(innerptlut_.lookup(ptinnerindex) && outerptlut_.lookup(ptouterindex))) {
0123           if (settings_.debugTracklet()) {
0124             edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : "
0125                                          << settings_.benddecode(
0126                                                 innervmstub.bend().value(), layerdisk1_, innervmstub.isPSmodule())
0127                                          << " "
0128                                          << settings_.benddecode(
0129                                                 outervmstub.bend().value(), layerdisk2_, outervmstub.isPSmodule());
0130           }
0131           continue;
0132         }
0133 
0134         if (settings_.debugTracklet())
0135           edm::LogVerbatim("Tracklet") << "Adding stub pair in " << getName();
0136 
0137         stubpairs_->addStubPair(innervmstub, outervmstub);
0138         countpass++;
0139       }
0140     }
0141   }
0142 
0143   if (settings_.writeMonitorData("TE")) {
0144     globals_->ofstream("trackletengine.txt") << getName() << " " << countall << " " << countpass << endl;
0145   }
0146 }
0147 
0148 void TrackletEngine::setVMPhiBin() {
0149   if (innervmstubs_ == nullptr || outervmstubs_ == nullptr)
0150     return;
0151 
0152   innervmstubs_->setother(outervmstubs_);
0153   outervmstubs_->setother(innervmstubs_);
0154 
0155   double innerphimin, innerphimax;
0156   innervmstubs_->getPhiRange(innerphimin, innerphimax, iSeed_, 0);
0157 
0158   double outerphimin, outerphimax;
0159   outervmstubs_->getPhiRange(outerphimin, outerphimax, iSeed_, 1);
0160 
0161   string innermem = innervmstubs_->getName().substr(6);
0162   string outermem = outervmstubs_->getName().substr(6);
0163 
0164   innerptlut_.initteptlut(true,
0165                           false,
0166                           iSeed_,
0167                           layerdisk1_,
0168                           layerdisk2_,
0169                           innerphibits_,
0170                           outerphibits_,
0171                           innerphimin,
0172                           innerphimax,
0173                           outerphimin,
0174                           outerphimax,
0175                           innermem,
0176                           outermem);
0177 
0178   outerptlut_.initteptlut(false,
0179                           false,
0180                           iSeed_,
0181                           layerdisk1_,
0182                           layerdisk2_,
0183                           innerphibits_,
0184                           outerphibits_,
0185                           innerphimin,
0186                           innerphimax,
0187                           outerphimin,
0188                           outerphimax,
0189                           innermem,
0190                           outermem);
0191 
0192   TrackletLUT innertememlut(settings_);
0193   TrackletLUT outertememlut(settings_);
0194 
0195   innertememlut.initteptlut(true,
0196                             true,
0197                             iSeed_,
0198                             layerdisk1_,
0199                             layerdisk2_,
0200                             innerphibits_,
0201                             outerphibits_,
0202                             innerphimin,
0203                             innerphimax,
0204                             outerphimin,
0205                             outerphimax,
0206                             innermem,
0207                             outermem);
0208 
0209   outertememlut.initteptlut(false,
0210                             true,
0211                             iSeed_,
0212                             layerdisk1_,
0213                             layerdisk2_,
0214                             innerphibits_,
0215                             outerphibits_,
0216                             innerphimin,
0217                             innerphimax,
0218                             outerphimin,
0219                             outerphimax,
0220                             innermem,
0221                             outermem);
0222 
0223   innervmstubs_->setbendtable(innertememlut);
0224   outervmstubs_->setbendtable(outertememlut);
0225 }