Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:56:30

0001 #include "L1Trigger/TrackFindingTracklet/interface/TrackletProcessorDisplaced.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
0003 #include "L1Trigger/TrackFindingTracklet/interface/Globals.h"
0004 #include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h"
0005 #include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h"
0006 #include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h"
0007 #include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h"
0008 #include "L1Trigger/TrackFindingTracklet/interface/Util.h"
0009 #include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h"
0010 
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 #include "DataFormats/Math/interface/deltaPhi.h"
0014 
0015 #include <utility>
0016 #include <tuple>
0017 
0018 using namespace std;
0019 using namespace trklet;
0020 
0021 TrackletProcessorDisplaced::TrackletProcessorDisplaced(string name, Settings const& settings, Globals* globals)
0022     : TrackletCalculatorDisplaced(name, settings, globals),
0023       innerTable_(settings),
0024       innerOverlapTable_(settings),
0025       innerThirdTable_(settings) {
0026   innerallstubs_.clear();
0027   middleallstubs_.clear();
0028   outerallstubs_.clear();
0029   stubpairs_.clear();
0030   innervmstubs_.clear();
0031   outervmstubs_.clear();
0032 
0033   const unsigned layerdiskPosInName = 4;
0034   const unsigned regionPosInName1 = 9;
0035 
0036   // iAllStub_ = -1;
0037   layerdisk_ = initLayerDisk(layerdiskPosInName);
0038 
0039   unsigned int region = name.substr(1)[regionPosInName1] - 'A';
0040   // assert(region < settings_.nallstubs(layerdisk_));
0041 
0042   if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 ||
0043       layerdisk_ == LayerDisk::L5 || layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) {
0044     innerTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::inner, region);  //projection to next layer/disk
0045   }
0046 
0047   if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2) {
0048     innerOverlapTable_.initVMRTable(
0049         layerdisk_, TrackletLUT::VMRTableType::inneroverlap, region);  //projection to disk from layer
0050   }
0051 
0052   if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 ||
0053       layerdisk_ == LayerDisk::D1) {
0054     innerThirdTable_.initVMRTable(
0055         layerdisk_, TrackletLUT::VMRTableType::innerthird, region);  //projection to third layer/disk
0056   }
0057 
0058   nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_);
0059   nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_);
0060 
0061   for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) {
0062     vector<TrackletProjectionsMemory*> tmp(settings_.nallstubs(ilayer), nullptr);
0063     trackletprojlayers_.push_back(tmp);
0064   }
0065 
0066   for (unsigned int idisk = 0; idisk < N_DISK; idisk++) {
0067     vector<TrackletProjectionsMemory*> tmp(settings_.nallstubs(idisk + N_LAYER), nullptr);
0068     trackletprojdisks_.push_back(tmp);
0069   }
0070 
0071   // initLayerDisksandISeed(layerdisk1_, layerdisk2_, iSeed_);
0072 
0073   layer_ = 0;
0074   disk_ = 0;
0075   layer1_ = 0;
0076   layer2_ = 0;
0077   layer3_ = 0;
0078   disk1_ = 0;
0079   disk2_ = 0;
0080   disk3_ = 0;
0081 
0082   constexpr unsigned layerPosInName1 = 4;
0083   constexpr unsigned diskPosInName1 = 4;
0084   constexpr unsigned layer1PosInName1 = 4;
0085   constexpr unsigned disk1PosInName1 = 4;
0086   constexpr unsigned layer2PosInName1 = 6;
0087   constexpr unsigned disk2PosInName1 = 6;
0088 
0089   string name1 = name.substr(1);  //this is to correct for "TPD" having one more letter then "TP"
0090   if (name1[3] == 'L')
0091     layer_ = name1[layerPosInName1] - '0';
0092   if (name1[3] == 'D')
0093     disk_ = name1[diskPosInName1] - '0';
0094 
0095   if (name1[3] == 'L')
0096     layer1_ = name1[layer1PosInName1] - '0';
0097   if (name1[3] == 'D')
0098     disk1_ = name1[disk1PosInName1] - '0';
0099   if (name1[5] == 'L')
0100     layer2_ = name1[layer2PosInName1] - '0';
0101   if (name1[5] == 'D')
0102     disk2_ = name1[disk2PosInName1] - '0';
0103 
0104   // set TC index
0105   iSeed_ = 0;
0106 
0107   int iTC = name1[regionPosInName1] - 'A';
0108 
0109   if (name1.substr(3, 6) == "L3L4L2") {
0110     iSeed_ = 8;
0111     layer3_ = 2;
0112   } else if (name1.substr(3, 6) == "L5L6L4") {
0113     iSeed_ = 9;
0114     layer3_ = 4;
0115   } else if (name1.substr(3, 6) == "L2L3D1") {
0116     iSeed_ = 10;
0117     disk3_ = 1;
0118   } else if (name1.substr(3, 6) == "D1D2L2") {
0119     iSeed_ = 11;
0120     layer3_ = 2;
0121   }
0122   assert(iSeed_ != 0);
0123 
0124   constexpr int TCIndexMin = 128;
0125   constexpr int TCIndexMax = 191;
0126 
0127   TCIndex_ = (iSeed_ << 4) + iTC;
0128   assert(TCIndex_ >= TCIndexMin && TCIndex_ < TCIndexMax);
0129 
0130   assert((layer_ != 0) || (disk_ != 0));
0131 }
0132 
0133 void TrackletProcessorDisplaced::addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory) {
0134   outputProj = dynamic_cast<TrackletProjectionsMemory*>(memory);
0135   assert(outputProj != nullptr);
0136 }
0137 
0138 void TrackletProcessorDisplaced::addOutput(MemoryBase* memory, string output) {
0139   if (settings_.writetrace()) {
0140     edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
0141                                  << output;
0142   }
0143 
0144   if (output == "trackpar") {
0145     auto* tmp = dynamic_cast<TrackletParametersMemory*>(memory);
0146     assert(tmp != nullptr);
0147     trackletpars_ = tmp;
0148     return;
0149   }
0150 
0151   if (output.substr(0, 7) == "projout") {
0152     //output is on the form 'projoutL2PHIC' or 'projoutD3PHIB'
0153     auto* tmp = dynamic_cast<TrackletProjectionsMemory*>(memory);
0154     assert(tmp != nullptr);
0155 
0156     constexpr unsigned layerdiskPosInprojout = 8;
0157     constexpr unsigned phiPosInprojout = 12;
0158 
0159     unsigned int layerdisk = output[layerdiskPosInprojout] - '1';  //layer or disk counting from 0
0160     unsigned int phiregion = output[phiPosInprojout] - 'A';        //phiregion counting from 0
0161 
0162     if (output[7] == 'L') {
0163       assert(layerdisk < N_LAYER);
0164       assert(phiregion < trackletprojlayers_[layerdisk].size());
0165       //check that phiregion not already initialized
0166       assert(trackletprojlayers_[layerdisk][phiregion] == nullptr);
0167       trackletprojlayers_[layerdisk][phiregion] = tmp;
0168       return;
0169     }
0170 
0171     if (output[7] == 'D') {
0172       assert(layerdisk < N_DISK);
0173       assert(phiregion < trackletprojdisks_[layerdisk].size());
0174       //check that phiregion not already initialized
0175       assert(trackletprojdisks_[layerdisk][phiregion] == nullptr);
0176       trackletprojdisks_[layerdisk][phiregion] = tmp;
0177       return;
0178     }
0179   }
0180 
0181   throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output;
0182 }
0183 
0184 void TrackletProcessorDisplaced::addInput(MemoryBase* memory, string input) {
0185   if (settings_.writetrace()) {
0186     edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
0187                                  << input;
0188   }
0189 
0190   if (input == "thirdallstubin") {
0191     auto* tmp = dynamic_cast<AllStubsMemory*>(memory);
0192     assert(tmp != nullptr);
0193     innerallstubs_.push_back(tmp);
0194     return;
0195   }
0196   if (input == "firstallstubin") {
0197     auto* tmp = dynamic_cast<AllStubsMemory*>(memory);
0198     assert(tmp != nullptr);
0199     middleallstubs_.push_back(tmp);
0200     return;
0201   }
0202   if (input == "secondallstubin") {
0203     auto* tmp = dynamic_cast<AllStubsMemory*>(memory);
0204     assert(tmp != nullptr);
0205     outerallstubs_.push_back(tmp);
0206     return;
0207   }
0208   if (input.substr(0, 8) == "stubpair") {
0209     auto* tmp = dynamic_cast<StubPairsMemory*>(memory);
0210     assert(tmp != nullptr);
0211     stubpairs_.push_back(tmp);
0212     return;
0213   }
0214 
0215   if (input == "thirdvmstubin") {
0216     auto* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
0217     assert(tmp != nullptr);
0218     innervmstubs_.push_back(tmp);
0219     return;
0220   }
0221   if (input == "secondvmstubin") {
0222     auto* tmp = dynamic_cast<VMStubsTEMemory*>(memory);
0223     assert(tmp != nullptr);
0224     // outervmstubs_ = tmp;
0225     outervmstubs_.push_back(tmp);
0226     return;
0227   }
0228 
0229   throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input;
0230 }
0231 
0232 void TrackletProcessorDisplaced::execute(unsigned int iSector, double phimin, double phimax) {
0233   // unsigned int nThirdStubs = 0;
0234   // unsigned int nOuterStubs = 0;
0235   count_ = 0;
0236 
0237   phimin_ = phimin;
0238   phimax_ = phimax;
0239   iSector_ = iSector;
0240 
0241   assert(!innerallstubs_.empty());
0242   assert(!middleallstubs_.empty());
0243   assert(!outerallstubs_.empty());
0244   assert(!innervmstubs_.empty());
0245   assert(!outervmstubs_.empty());
0246   assert(stubpairs_.empty());
0247 
0248   for (auto& iInnerMem : middleallstubs_) {
0249     assert(iInnerMem->nStubs() == iInnerMem->nStubs());
0250     for (unsigned int j = 0; j < iInnerMem->nStubs(); j++) {
0251       const Stub* firstallstub = iInnerMem->getStub(j);
0252 
0253       if (settings_.debugTracklet()) {
0254         edm::LogVerbatim("Tracklet") << "In " << getName() << " have first stub\n";
0255       }
0256 
0257       int inner = 0;
0258       bool negdisk = (firstallstub->disk().value() < 0);
0259       int indexz = (((1 << (firstallstub->z().nbits() - 1)) + firstallstub->z().value()) >>
0260                     (firstallstub->z().nbits() - nbitszfinebintable_));
0261       int indexr = -1;
0262       if (layerdisk_ > (N_LAYER - 1)) {
0263         if (negdisk) {
0264           indexz = (1 << nbitszfinebintable_) - indexz;
0265         }
0266         indexr = firstallstub->r().value();
0267         if (firstallstub->isPSmodule()) {
0268           indexr = firstallstub->r().value() >> (firstallstub->r().nbits() - nbitsrfinebintable_);
0269         }
0270       } else {
0271         //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values.
0272         indexr = (((1 << (firstallstub->r().nbits() - 1)) + firstallstub->r().value()) >>
0273                   (firstallstub->r().nbits() - nbitsrfinebintable_));
0274       }
0275 
0276       assert(indexz >= 0);
0277       assert(indexr >= 0);
0278       assert(indexz < (1 << nbitszfinebintable_));
0279       assert(indexr < (1 << nbitsrfinebintable_));
0280 
0281       // int melut = meTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
0282       // assert(melut >= 0);
0283 
0284       unsigned int lutwidth = settings_.lutwidthtab(inner, iSeed_);
0285       if (settings_.extended()) {
0286         lutwidth = settings_.lutwidthtabextended(inner, iSeed_);
0287       }
0288 
0289       int lutval = -999;
0290 
0291       if (iSeed_ < Seed::L1D1 || iSeed_ > Seed::L2D1) {
0292         lutval = innerTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
0293       } else {
0294         lutval = innerOverlapTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
0295       }
0296 
0297       if (lutval == -1)
0298         continue;
0299       if (settings_.extended() &&
0300           (iSeed_ == Seed::L2L3L4 || iSeed_ == Seed::L4L5L6 || iSeed_ == Seed::D1D2L2 || iSeed_ == Seed::L2L3D1)) {
0301         int lutval2 = innerThirdTable_.lookup((indexz << nbitsrfinebintable_) + indexr);
0302         if (lutval2 != -1)
0303           lutval += (lutval2 << 10);
0304       }
0305 
0306       assert(lutval >= 0);
0307       // assert(lutwidth > 0);
0308 
0309       FPGAWord binlookup(lutval, lutwidth, true, __LINE__, __FILE__);
0310 
0311       if ((layer1_ == 3 && layer2_ == 4) || (layer1_ == 5 && layer2_ == 6)) {
0312         if (settings_.debugTracklet()) {
0313           edm::LogVerbatim("Tracklet") << getName() << " Layer-layer pair\n";
0314         }
0315 
0316         constexpr int andlookupbits = 1023;
0317         constexpr int shiftzdiffmax = 7;
0318         constexpr int andnewbin = 127;
0319         constexpr int divbin = 8;
0320         constexpr int andzbinfirst = 7;
0321         constexpr int shiftstart = 1;
0322         constexpr int andlast = 1;
0323         constexpr int maxlast = 8;
0324 
0325         int lookupbits = binlookup.value() & andlookupbits;
0326         int zdiffmax = (lookupbits >> shiftzdiffmax);
0327         int newbin = (lookupbits & andnewbin);
0328         int bin = newbin / divbin;
0329 
0330         int zbinfirst = newbin & andzbinfirst;
0331 
0332         int start = (bin >> shiftstart);
0333         int last = start + (bin & andlast);
0334 
0335         assert(last < maxlast);
0336 
0337         if (settings_.debugTracklet()) {
0338           edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last << endl;
0339         }
0340 
0341         for (int ibin = start; ibin <= last; ibin++) {
0342           for (unsigned int m = 0; m < outervmstubs_.size(); m++) {
0343             for (unsigned int j = 0; j < outervmstubs_.at(m)->nVMStubsBinned(ibin); j++) {
0344               if (settings_.debugTracklet()) {
0345                 edm::LogVerbatim("Tracklet")
0346                     << "In " << getName() << " have second stub(1) " << ibin << " " << j << endl;
0347               }
0348 
0349               const VMStubTE& secondvmstub = outervmstubs_.at(m)->getVMStubTEBinned(ibin, j);
0350 
0351               int zbin = (secondvmstub.vmbits().value() & 7);
0352               if (start != ibin)
0353                 zbin += 8;
0354               if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) {
0355                 if (settings_.debugTracklet()) {
0356                   edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin";
0357                 }
0358                 continue;
0359               }
0360 
0361               if ((layer2_ == 4 && layer3_ == 2) || (layer2_ == 6 && layer3_ == 4)) {
0362                 constexpr int vmbitshift = 10;
0363                 constexpr int andlookupbits_ = 1023;
0364                 constexpr int andnewbin_ = 127;
0365                 constexpr int divbin_ = 8;
0366                 constexpr int shiftstart_ = 1;
0367                 constexpr int andlast_ = 1;
0368 
0369                 int lookupbits_ = (int)((binlookup.value() >> vmbitshift) & andlookupbits_);
0370                 int newbin_ = (lookupbits_ & andnewbin_);
0371                 int bin_ = newbin_ / divbin_;
0372 
0373                 int start_ = (bin_ >> shiftstart_);
0374                 int last_ = start_ + (bin_ & andlast_);
0375 
0376                 if (settings_.debugTracklet()) {
0377                   edm::LogVerbatim("Tracklet")
0378                       << "Will look in zbins for third stub" << start_ << " to " << last_ << endl;
0379                 }
0380 
0381                 for (int ibin_ = start_; ibin_ <= last_; ibin_++) {
0382                   for (unsigned int k = 0; k < innervmstubs_.size(); k++) {
0383                     for (unsigned int l = 0; l < innervmstubs_.at(k)->nVMStubsBinned(ibin_); l++) {
0384                       if (settings_.debugTracklet()) {
0385                         edm::LogVerbatim("Tracklet") << "In " << getName() << " have third stub\n";
0386                       }
0387 
0388                       const VMStubTE& thirdvmstub = innervmstubs_.at(k)->getVMStubTEBinned(ibin_, l);
0389 
0390                       const Stub* innerFPGAStub = firstallstub;
0391                       const Stub* middleFPGAStub = secondvmstub.stub();
0392                       const Stub* outerFPGAStub = thirdvmstub.stub();
0393 
0394                       const L1TStub* innerStub = innerFPGAStub->l1tstub();
0395                       const L1TStub* middleStub = middleFPGAStub->l1tstub();
0396                       const L1TStub* outerStub = outerFPGAStub->l1tstub();
0397 
0398                       if (settings_.debugTracklet()) {
0399                         edm::LogVerbatim("Tracklet")
0400                             << "LLL seeding\n"
0401                             << innerFPGAStub->strbare() << middleFPGAStub->strbare() << outerFPGAStub->strbare()
0402                             << innerStub->stubword() << middleStub->stubword() << outerStub->stubword()
0403                             << innerFPGAStub->layerdisk() << middleFPGAStub->layerdisk() << outerFPGAStub->layerdisk();
0404                       }
0405 
0406                       if (settings_.debugTracklet()) {
0407                         edm::LogVerbatim("Tracklet")
0408                             << "TrackletCalculatorDisplaced execute " << getName() << "[" << iSector_ << "]";
0409                       }
0410 
0411                       if (innerFPGAStub->layerdisk() >= N_LAYER && middleFPGAStub->layerdisk() >= N_LAYER &&
0412                           outerFPGAStub->layerdisk() >= N_LAYER) {
0413                         throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!";
0414                       }
0415 
0416                       if (settings_.debugTracklet()) {
0417                         edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced execute done";
0418                       }
0419                     }
0420                   }
0421                 }
0422               }
0423             }
0424           }
0425         }
0426 
0427       } else if (layer1_ == 2 && layer2_ == 3) {
0428         if (settings_.debugTracklet()) {
0429           edm::LogVerbatim("Tracklet") << getName() << " Layer-layer pair";
0430         }
0431 
0432         constexpr int andlookupbits = 1023;
0433         constexpr int shiftzdiffmax = 7;
0434         constexpr int andnewbin = 127;
0435         constexpr int divbin = 8;
0436         constexpr int andzbinfirst = 7;
0437         constexpr int shiftstart = 1;
0438         constexpr int andlast = 1;
0439         constexpr int maxlast = 8;
0440 
0441         int lookupbits = binlookup.value() & andlookupbits;
0442         int zdiffmax = (lookupbits >> shiftzdiffmax);
0443         int newbin = (lookupbits & andnewbin);
0444         int bin = newbin / divbin;
0445 
0446         int zbinfirst = newbin & andzbinfirst;
0447 
0448         int start = (bin >> shiftstart);
0449         int last = start + (bin & andlast);
0450 
0451         assert(last < maxlast);
0452 
0453         if (settings_.debugTracklet()) {
0454           edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last;
0455         }
0456 
0457         for (int ibin = start; ibin <= last; ibin++) {
0458           for (unsigned int m = 0; m < outervmstubs_.size(); m++) {
0459             for (unsigned int j = 0; j < outervmstubs_.at(m)->nVMStubsBinned(ibin); j++) {
0460               if (settings_.debugTracklet()) {
0461                 edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(1) " << ibin << " " << j;
0462               }
0463 
0464               const VMStubTE& secondvmstub = outervmstubs_.at(m)->getVMStubTEBinned(ibin, j);
0465 
0466               int zbin = (secondvmstub.vmbits().value() & 7);
0467               if (start != ibin)
0468                 zbin += 8;
0469               if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) {
0470                 if (settings_.debugTracklet()) {
0471                   edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin";
0472                 }
0473                 continue;
0474               }
0475 
0476               if (layer2_ == 3 && disk3_ == 1) {
0477                 constexpr int vmbitshift = 10;
0478                 constexpr int andlookupbits_ = 1023;
0479                 constexpr int andnewbin_ = 127;
0480                 constexpr int divbin_ = 8;
0481                 constexpr int shiftstart_ = 1;
0482                 constexpr int andlast_ = 1;
0483 
0484                 int lookupbits_ = (int)((binlookup.value() >> vmbitshift) & andlookupbits_);
0485                 int newbin_ = (lookupbits_ & andnewbin_);
0486                 int bin_ = newbin_ / divbin_;
0487 
0488                 int start_ = (bin_ >> shiftstart_);
0489                 int last_ = start_ + (bin_ & andlast_);
0490 
0491                 for (int ibin_ = start_; ibin_ <= last_; ibin_++) {
0492                   for (unsigned int k = 0; k < innervmstubs_.size(); k++) {
0493                     for (unsigned int l = 0; l < innervmstubs_.at(k)->nVMStubsBinned(ibin_); l++) {
0494                       if (settings_.debugTracklet()) {
0495                         edm::LogVerbatim("Tracklet") << "In " << getName() << " have third stub";
0496                       }
0497 
0498                       const VMStubTE& thirdvmstub = innervmstubs_.at(k)->getVMStubTEBinned(ibin_, l);
0499 
0500                       const Stub* innerFPGAStub = firstallstub;
0501                       const Stub* middleFPGAStub = secondvmstub.stub();
0502                       const Stub* outerFPGAStub = thirdvmstub.stub();
0503 
0504                       const L1TStub* innerStub = innerFPGAStub->l1tstub();
0505                       const L1TStub* middleStub = middleFPGAStub->l1tstub();
0506                       const L1TStub* outerStub = outerFPGAStub->l1tstub();
0507 
0508                       if (settings_.debugTracklet()) {
0509                         edm::LogVerbatim("Tracklet")
0510                             << "LLD seeding\n"
0511                             << innerFPGAStub->strbare() << middleFPGAStub->strbare() << outerFPGAStub->strbare()
0512                             << innerStub->stubword() << middleStub->stubword() << outerStub->stubword()
0513                             << innerFPGAStub->layerdisk() << middleFPGAStub->layerdisk() << outerFPGAStub->layerdisk();
0514                       }
0515 
0516                       if (settings_.debugTracklet()) {
0517                         edm::LogVerbatim("Tracklet")
0518                             << "TrackletCalculatorDisplaced execute " << getName() << "[" << iSector_ << "]";
0519                       }
0520 
0521                       if (settings_.debugTracklet()) {
0522                         edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced execute done";
0523                       }
0524                     }
0525                   }
0526                 }
0527               }
0528             }
0529           }
0530         }
0531 
0532       } else if (disk1_ == 1 && disk2_ == 2) {
0533         if (settings_.debugTracklet())
0534           edm::LogVerbatim("Tracklet") << getName() << " Disk-disk pair";
0535 
0536         constexpr int andlookupbits = 511;
0537         constexpr int shiftrdiffmax = 6;
0538         constexpr int andnewbin = 63;
0539         constexpr int divbin = 8;
0540         constexpr int andrbinfirst = 7;
0541         constexpr int shiftstart = 1;
0542         constexpr int andlast = 1;
0543         constexpr int maxlast = 8;
0544 
0545         int lookupbits = binlookup.value() & andlookupbits;
0546         bool negdisk = firstallstub->disk().value() < 0;
0547         int rdiffmax = (lookupbits >> shiftrdiffmax);
0548         int newbin = (lookupbits & andnewbin);
0549         int bin = newbin / divbin;
0550 
0551         int rbinfirst = newbin & andrbinfirst;
0552 
0553         int start = (bin >> shiftstart);
0554         if (negdisk)
0555           start += 4;
0556         int last = start + (bin & andlast);
0557         assert(last < maxlast);
0558 
0559         for (int ibin = start; ibin <= last; ibin++) {
0560           for (unsigned int m = 0; m < outervmstubs_.size(); m++) {
0561             if (settings_.debugTracklet()) {
0562               edm::LogVerbatim("Tracklet")
0563                   << getName() << " looking for matching stub in " << outervmstubs_.at(m)->getName()
0564                   << " in bin = " << ibin << " with " << outervmstubs_.at(m)->nVMStubsBinned(ibin) << " stubs";
0565             }
0566 
0567             for (unsigned int j = 0; j < outervmstubs_.at(m)->nVMStubsBinned(ibin); j++) {
0568               const VMStubTE& secondvmstub = outervmstubs_.at(m)->getVMStubTEBinned(ibin, j);
0569               int rbin = (secondvmstub.vmbits().value() & 7);
0570               if (start != ibin)
0571                 rbin += 8;
0572               if (rbin < rbinfirst)
0573                 continue;
0574               if (rbin - rbinfirst > rdiffmax)
0575                 continue;
0576 
0577               if (disk2_ == 2 && layer3_ == 2) {
0578                 constexpr int vmbitshift = 10;
0579                 constexpr int andlookupbits_ = 1023;
0580                 constexpr int andnewbin_ = 127;
0581                 constexpr int divbin_ = 8;
0582                 constexpr int shiftstart_ = 1;
0583                 constexpr int andlast_ = 1;
0584 
0585                 int lookupbits_ = (int)((binlookup.value() >> vmbitshift) & andlookupbits_);
0586                 int newbin_ = (lookupbits_ & andnewbin_);
0587                 int bin_ = newbin_ / divbin_;
0588 
0589                 int start_ = (bin_ >> shiftstart_);
0590                 int last_ = start_ + (bin_ & andlast_);
0591 
0592                 if (firstallstub->disk().value() < 0) {  //TODO - negative disk should come from memory
0593                   start_ = settings_.NLONGVMBINS() - last_ - 1;
0594                   last_ = settings_.NLONGVMBINS() - start_ - 1;
0595                 }
0596 
0597                 for (int ibin_ = start_; ibin_ <= last_; ibin_++) {
0598                   for (unsigned int k = 0; k < innervmstubs_.size(); k++) {
0599                     for (unsigned int l = 0; l < innervmstubs_.at(k)->nVMStubsBinned(ibin_); l++) {
0600                       if (settings_.debugTracklet()) {
0601                         edm::LogVerbatim("Tracklet") << "In " << getName() << " have third stub";
0602                       }
0603 
0604                       const VMStubTE& thirdvmstub = innervmstubs_.at(k)->getVMStubTEBinned(ibin_, l);
0605 
0606                       const Stub* innerFPGAStub = firstallstub;
0607                       const Stub* middleFPGAStub = secondvmstub.stub();
0608                       const Stub* outerFPGAStub = thirdvmstub.stub();
0609 
0610                       const L1TStub* innerStub = innerFPGAStub->l1tstub();
0611                       const L1TStub* middleStub = middleFPGAStub->l1tstub();
0612                       const L1TStub* outerStub = outerFPGAStub->l1tstub();
0613 
0614                       if (settings_.debugTracklet()) {
0615                         edm::LogVerbatim("Tracklet")
0616                             << "DDL seeding\n"
0617                             << innerFPGAStub->strbare() << middleFPGAStub->strbare() << outerFPGAStub->strbare()
0618                             << innerStub->stubword() << middleStub->stubword() << outerStub->stubword()
0619                             << innerFPGAStub->layerdisk() << middleFPGAStub->layerdisk() << outerFPGAStub->layerdisk();
0620                       }
0621 
0622                       if (settings_.debugTracklet()) {
0623                         edm::LogVerbatim("Tracklet")
0624                             << "TrackletCalculatorDisplaced execute " << getName() << "[" << iSector_ << "]";
0625                       }
0626 
0627                       if (settings_.debugTracklet()) {
0628                         edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced execute done";
0629                       }
0630                     }
0631                   }
0632                 }
0633               }
0634             }
0635           }
0636         }
0637       }
0638     }
0639   }
0640 }