Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include <iomanip>
0005 #include <filesystem>
0006 
0007 using namespace std;
0008 using namespace trklet;
0009 
0010 VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings)
0011     : MemoryBase(name, settings), bendtable_(settings) {
0012   //set the layer or disk that the memory is in
0013   initLayerDisk(6, layer_, disk_);
0014 
0015   layerdisk_ = initLayerDisk(6);
0016 
0017   //Pointer to other VMStub memory for creating stub pairs
0018   other_ = nullptr;
0019 
0020   //What type of seeding is this memory used for
0021   initSpecialSeeding(11, overlap_, extra_, extended_);
0022 
0023   string subname = name.substr(12, 2);
0024   phibin_ = subname[0] - '0';
0025   if (subname[1] != 'n') {
0026     phibin_ = 10 * phibin_ + (subname[1] - '0');
0027   }
0028 
0029   isinner_ = (layer_ % 2 == 1 or disk_ % 2 == 1);
0030   // special cases with overlap seeding
0031   if (overlap_ and layer_ == 2)
0032     isinner_ = true;
0033   if (overlap_ and layer_ == 3)
0034     isinner_ = false;
0035   if (overlap_ and disk_ == 1)
0036     isinner_ = false;
0037 
0038   if (extra_ and layer_ == 2)
0039     isinner_ = true;
0040   if (extra_ and layer_ == 3)
0041     isinner_ = false;
0042   // more special cases for triplets
0043   if (!overlap_ and extended_ and layer_ == 2)
0044     isinner_ = true;
0045   if (!overlap_ and extended_ and layer_ == 3)
0046     isinner_ = false;
0047   if (overlap_ and extended_ and layer_ == 2)
0048     isinner_ = false;
0049   if (overlap_ and extended_ and disk_ == 1)
0050     isinner_ = false;
0051 
0052   stubsbinnedvm_.resize(settings_.NLONGVMBINS());
0053 }
0054 
0055 bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) {
0056   //If the pt of the stub is consistent with the allowed pt of tracklets
0057   //in that can be formed in this VM and the other VM used in the TE.
0058 
0059   if (settings_.combined()) {
0060     if (disk_ > 0) {
0061       assert(vmstub.stub()->isPSmodule());
0062     }
0063     bool negdisk = vmstub.stub()->disk().value() < 0.0;
0064     if (negdisk)
0065       bin += 4;
0066     assert(bin < (int)stubsbinnedvm_.size());
0067     if (stubsbinnedvm_[bin].size() < N_VMSTUBSMAX) {
0068       stubsbinnedvm_[bin].push_back(vmstub);
0069       stubsvm_.push_back(vmstub);
0070     }
0071     return true;
0072   }
0073 
0074   bool pass = false;
0075   if (settings_.extended() && bendtable_.size() == 0) {
0076     pass = true;
0077   } else {
0078     pass = bendtable_.lookup(vmstub.bend().value());
0079   }
0080 
0081   if (!pass) {
0082     if (settings_.debugTracklet())
0083       edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = "
0084                                    << settings_.benddecode(vmstub.bend().value(), layerdisk_, vmstub.isPSmodule());
0085     return false;
0086   }
0087 
0088   bool negdisk = vmstub.stub()->disk().value() < 0.0;
0089 
0090   if (overlap_) {
0091     if (disk_ == 1) {
0092       assert(bin < 4);
0093       if (negdisk)
0094         bin += 4;
0095       if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
0096         return false;
0097       stubsbinnedvm_[bin].push_back(vmstub);
0098       if (settings_.debugTracklet())
0099         edm::LogVerbatim("Tracklet") << getName() << " Stub in disk = " << disk_ << "  in bin = " << bin;
0100     } else if (layer_ == 2) {
0101       if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
0102         return false;
0103       stubsbinnedvm_[bin].push_back(vmstub);
0104     }
0105   } else {
0106     if (vmstub.stub()->layerdisk() < N_LAYER) {
0107       if (!isinner_) {
0108         if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
0109           return false;
0110         stubsbinnedvm_[bin].push_back(vmstub);
0111       }
0112 
0113     } else {
0114       if (disk_ % 2 == 0) {
0115         assert(bin < 4);
0116         if (negdisk)
0117           bin += 4;
0118         if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
0119           return false;
0120         stubsbinnedvm_[bin].push_back(vmstub);
0121       }
0122     }
0123   }
0124   if (settings_.debugTracklet())
0125     edm::LogVerbatim("Tracklet") << "Adding stubs to " << getName();
0126   if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin())
0127     return false;
0128   stubsvm_.push_back(vmstub);
0129   return true;
0130 }
0131 
0132 // TODO - should migrate away from using this method for any binned memory
0133 bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) {
0134   FPGAWord binlookup = vmstub.vmbits();
0135 
0136   assert(binlookup.value() >= 0);
0137   int bin = (binlookup.value() / 8);
0138 
0139   //If the pt of the stub is consistent with the allowed pt of tracklets
0140   //in that can be formed in this VM and the other VM used in the TE.
0141 
0142   bool pass = false;
0143   if (settings_.extended() && bendtable_.size() == 0) {
0144     pass = true;
0145   } else {
0146     pass = bendtable_.lookup(vmstub.bend().value());
0147   }
0148 
0149   if (!pass) {
0150     if (settings_.debugTracklet())
0151       edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = "
0152                                    << settings_.benddecode(vmstub.bend().value(), layerdisk_, vmstub.isPSmodule());
0153     return false;
0154   }
0155 
0156   bool negdisk = vmstub.stub()->disk().value() < 0.0;
0157 
0158   if (!extended_) {
0159     if (overlap_) {
0160       if (disk_ == 1) {
0161         assert(bin < 4);
0162         if (negdisk)
0163           bin += 4;
0164         stubsbinnedvm_[bin].push_back(vmstub);
0165         if (settings_.debugTracklet()) {
0166           edm::LogVerbatim("Tracklet") << getName() << " Stub with lookup = " << binlookup.value()
0167                                        << " in disk = " << disk_ << "  in bin = " << bin;
0168         }
0169       }
0170     } else {
0171       if (vmstub.stub()->layerdisk() < N_LAYER) {
0172         if (!isinner_) {
0173           stubsbinnedvm_[bin].push_back(vmstub);
0174         }
0175 
0176       } else {
0177         if (disk_ % 2 == 0) {
0178           assert(bin < 4);
0179           if (negdisk)
0180             bin += 4;
0181           stubsbinnedvm_[bin].push_back(vmstub);
0182         }
0183       }
0184     }
0185   } else {  //extended
0186     if (!isinner_) {
0187       if (layer_ > 0) {
0188         stubsbinnedvm_[bin].push_back(vmstub);
0189       } else {
0190         if (overlap_) {
0191           assert(disk_ == 1);  // D1 from L2L3D1
0192 
0193           //bin 0 is PS, 1 through 3 is 2S
0194           if (vmstub.stub()->isPSmodule()) {
0195             bin = 0;
0196           } else {
0197             bin = vmstub.stub()->r().value();  // 0 to 9
0198             bin = bin >> 2;                    // 0 to 2
0199             bin += 1;
0200           }
0201         }
0202         assert(bin < 4);
0203         if (negdisk)
0204           bin += 4;
0205         stubsbinnedvm_[bin].push_back(vmstub);
0206       }
0207     }
0208   }
0209 
0210   if (settings_.debugTracklet())
0211     edm::LogVerbatim("Tracklet") << "Adding stubs to " << getName();
0212   stubsvm_.push_back(vmstub);
0213   return true;
0214 }
0215 
0216 void VMStubsTEMemory::clean() {
0217   stubsvm_.clear();
0218   for (auto& stubsbinnedvm : stubsbinnedvm_) {
0219     stubsbinnedvm.clear();
0220   }
0221 }
0222 
0223 void VMStubsTEMemory::writeStubs(bool first, unsigned int iSector) {
0224   iSector_ = iSector;
0225   const string dirVM = settings_.memPath() + "VMStubsTE/";
0226   openFile(first, dirVM, "VMStubs_");
0227 
0228   if (isinner_) {  // inner VM for TE purpose
0229     for (unsigned int j = 0; j < stubsvm_.size(); j++) {
0230       out_ << "0x";
0231       out_ << std::setfill('0') << std::setw(2);
0232       out_ << hex << j << dec;
0233       string stub = stubsvm_[j].str();
0234       out_ << " " << stub << " " << trklet::hexFormat(stub) << endl;
0235     }
0236   } else {  // outer VM for TE purpose
0237     for (unsigned int i = 0; i < stubsbinnedvm_.size(); i++) {
0238       for (unsigned int j = 0; j < stubsbinnedvm_[i].size(); j++) {
0239         string stub = stubsbinnedvm_[i][j].str();
0240         out_ << hex << i << " " << j << dec << " " << stub << " " << trklet::hexFormat(stub) << endl;
0241       }
0242     }
0243   }
0244 
0245   out_.close();
0246 }
0247 
0248 void VMStubsTEMemory::getPhiRange(double& phimin, double& phimax, unsigned int iSeed, unsigned int inner) {
0249   int nvm = -1;
0250   if (overlap_) {
0251     if (layer_ > 0) {
0252       nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
0253     }
0254     if (disk_ > 0) {
0255       nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed);
0256     }
0257   } else {
0258     if (layer_ > 0) {
0259       nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
0260       if (extra_) {
0261         nvm = settings_.nallstubs(layer_ - 1) * settings_.nvmte(inner, iSeed);
0262       }
0263     }
0264     if (disk_ > 0) {
0265       nvm = settings_.nallstubs(disk_ + N_DISK) * settings_.nvmte(inner, iSeed);
0266     }
0267   }
0268   assert(nvm > 0);
0269   assert(nvm <= 32);
0270   double dphi = settings_.dphisectorHG() / nvm;
0271   phimax = phibin() * dphi;
0272   phimin = phimax - dphi;
0273 
0274   return;
0275 }
0276 
0277 void VMStubsTEMemory::setbendtable(const TrackletLUT& bendtable) { bendtable_ = bendtable; }