Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:50

0001 #include "L1Trigger/TrackFindingTMTT/interface/HTcell.h"
0002 #include "L1Trigger/TrackFindingTMTT/interface/TP.h"
0003 #include "L1Trigger/TrackFindingTMTT/interface/Stub.h"
0004 
0005 using namespace std;
0006 
0007 namespace tmtt {
0008 
0009   //=== Initialization with cfg params,
0010   //=== rapidity range of current sector, and estimated q/Pt of cell,
0011   //=== and the bin number of the cell along the q/Pt axis of the r-phi HT array,
0012   //=== and a flag indicating if this cell is the merge of smaller HT cells.
0013 
0014   HTcell::HTcell(const Settings* settings,
0015                  unsigned int iPhiSec,
0016                  unsigned int iEtaReg,
0017                  float etaMinSector,
0018                  float etaMaxSector,
0019                  float qOverPt,
0020                  unsigned int ibin_qOverPt,
0021                  bool mergedCell,
0022                  bool miniHTcell)
0023       : settings_(settings),
0024         // Sector number
0025         iPhiSec_(iPhiSec),
0026         iEtaReg_(iEtaReg),
0027         // Rapidity range of sector.
0028         etaMinSector_(etaMinSector),
0029         etaMaxSector_(etaMaxSector),
0030         // Track q/Pt.
0031         qOverPtCell_(qOverPt),
0032         // Note bin number of cell along q/Pt axis of r-phi HT array. (Not used if r-z HT).
0033         ibin_qOverPt_(ibin_qOverPt),
0034         mergedCell_(mergedCell),
0035         // Is cell in Mini-HT?
0036         miniHTcell_(miniHTcell),
0037         invPtToDphi_(settings->invPtToDphi()),  // B*c/2E11
0038         // Use filter in each HT cell using only stubs which have consistent bend?
0039         useBendFilter_(settings->useBendFilter()),
0040         // Check if subsectors are being used within each sector. These are only ever used for r-phi HT.
0041         numSubSecs_(settings->numSubSecsEta()) {
0042     // A filter is used each HT cell, which prevents more than the specified number of stubs being stored in the cell. (Reflecting memory limit of hardware).
0043     if (miniHTcell_) {
0044       maxStubsInCell_ = settings->maxStubsInCellMiniHough();
0045     } else {
0046       maxStubsInCell_ = settings->maxStubsInCell();
0047     }
0048   }
0049 
0050   //=== Termination. Search for track in this HT cell etc.
0051 
0052   void HTcell::end() {
0053     // Produce list of filtered stubs by applying all requested filters (e.g. on stub bend).
0054     // (If no filters are requested, then filtered & unfiltered stub collections will be identical).
0055 
0056     // N.B. Other filters,  such as the r-z filters, which the firmware runs after the HT because they are too slow within it,
0057     // are not defined here, but instead inside class TrkFilterAfterRphiHT.
0058 
0059     vFilteredStubs_ = vStubs_;
0060     if (useBendFilter_)
0061       vFilteredStubs_ = this->bendFilter(vFilteredStubs_);
0062 
0063     // Prevent too many stubs being stored in a single HT cell if requested (to reflect hardware memory limits).
0064     // N.B. This MUST be the last filter applied.
0065     constexpr unsigned int disableThreshold = 999;
0066     if (maxStubsInCell_ < disableThreshold)
0067       vFilteredStubs_ = this->maxStubCountFilter(vFilteredStubs_);
0068 
0069     // Calculate the number of layers the filtered stubs in this cell are in.
0070     numFilteredLayersInCell_ = this->calcNumFilteredLayers();
0071 
0072     if (numSubSecs_ > 1) {
0073       // If using subsectors within each sector, calculate the number of layers the filters stubs in this cell are in,
0074       // when one considers only the subset of the stubs within each subsector.
0075       // Look for the "best" subsector.
0076       numFilteredLayersInCellBestSubSec_ = 0;
0077       for (unsigned int i = 0; i < numSubSecs_; i++) {
0078         unsigned int numLaySubSec = this->calcNumFilteredLayers(i);
0079         numFilteredLayersInCellBestSubSec_ = max(numFilteredLayersInCellBestSubSec_, numLaySubSec);
0080       }
0081     } else {
0082       // If only 1 sub-sector, then subsector and sector are identical.
0083       numFilteredLayersInCellBestSubSec_ = numFilteredLayersInCell_;
0084     }
0085   }
0086 
0087   // Calculate how many tracker layers the filter stubs in this cell are in, when only the subset of those stubs
0088   // that are in the specified subsector are counted.
0089 
0090   unsigned int HTcell::calcNumFilteredLayers(unsigned int iSubSec) const {
0091     vector<const Stub*> stubsInSubSec;
0092     for (const Stub* s : vFilteredStubs_) {
0093       const vector<bool>& inSubSec = subSectors_.at(s);  // Find out which subsectors this stub is in.
0094       if (inSubSec[iSubSec])
0095         stubsInSubSec.push_back(s);
0096     }
0097     return Utility::countLayers(settings_, stubsInSubSec);
0098   }
0099 
0100   //=== Produce a filtered collection of stubs in this cell that all have consistent bend.
0101   //=== Only called for r-phi Hough transform.
0102 
0103   vector<Stub*> HTcell::bendFilter(const vector<Stub*>& stubs) const {
0104     // Create bend-filtered stub collection.
0105     vector<Stub*> filteredStubs;
0106     for (Stub* s : stubs) {
0107       // Require stub bend to be consistent with q/Pt of this cell.
0108 
0109       unsigned int minBin = s->min_qOverPt_bin();
0110       unsigned int maxBin = s->max_qOverPt_bin();
0111       if (mergedCell_) {
0112         if (minBin % 2 == 1)
0113           minBin--;
0114       }
0115       if (minBin <= ibin_qOverPt_ && ibin_qOverPt_ <= maxBin)
0116         filteredStubs.push_back(s);
0117     }
0118 
0119     return filteredStubs;
0120   }
0121 
0122   //=== Filter stubs so as to prevent more than specified number of stubs being stored in one cell.
0123   //=== This reflects finite memory of hardware.
0124 
0125   vector<Stub*> HTcell::maxStubCountFilter(const vector<Stub*>& stubs) const {
0126     vector<Stub*> filteredStubs;
0127     // If there are too many stubs in a cell, the hardware keeps (maxStubsInCell - 1) of the first stubs in the list
0128     // plus the last stub.
0129     if (stubs.size() > maxStubsInCell_) {
0130       for (unsigned int i = 0; i < maxStubsInCell_ - 1; i++) {  // first stubs
0131         filteredStubs.push_back(stubs[i]);
0132       }
0133       filteredStubs.push_back(stubs[stubs.size() - 1]);  // plus last stub
0134     } else {
0135       filteredStubs = stubs;
0136     }
0137     return filteredStubs;
0138   }
0139 
0140 }  // namespace tmtt