Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef L1Trigger_TrackFindingTMTT_HTcell_h
0002 #define L1Trigger_TrackFindingTMTT_HTcell_h
0003 
0004 #include "L1Trigger/TrackFindingTMTT/interface/Utility.h"
0005 #include "L1Trigger/TrackFindingTMTT/interface/Stub.h"
0006 #include "FWCore/Utilities/interface/Exception.h"
0007 
0008 #include <vector>
0009 #include <map>
0010 #include <algorithm>
0011 #include <utility>
0012 
0013 //=== A single cell in a Hough Transform array.
0014 
0015 namespace tmtt {
0016 
0017   class Settings;
0018   class Stub;
0019 
0020   class HTcell {
0021   public:
0022     // Initialization with cfg params,
0023     // sector number, rapidity range of current sector, estimated q/Pt of cell,
0024     // and the bin number of the cell along the q/Pt axis of the r-phi HT array,
0025     // and a flag indicating if this cell is the merge of smaller HT cells.
0026     HTcell(const Settings* settings,
0027            unsigned int iPhiSec,
0028            unsigned int iEtaReg,
0029            float etaMinSector,
0030            float etaMaxSector,
0031            float qOverPt,
0032            unsigned int ibin_qOverPt,
0033            bool mergedCell,
0034            bool miniHTcell = false);
0035 
0036     // Add stub to this cell in HT array.
0037     void store(Stub* stub) { vStubs_.push_back(stub); }
0038 
0039     // Add stub to this cell in HT array, indicating also which subsectors within the sector is consistent with.
0040     void store(Stub* stub, const std::vector<bool>& inSubSecs) {
0041       this->store(stub);
0042       subSectors_[stub] = inSubSecs;
0043       if (inSubSecs.size() != numSubSecs_)
0044         throw cms::Exception("LogicError") << "HTcell: Wrong number of subsectors!";
0045     }
0046 
0047     // Termination. Search for track in this HT cell etc.
0048     void end();
0049 
0050     //=== Cfg of cell
0051 
0052     // Does this HTcell correspond to merged HT cells (e.g. 2x2)?
0053     bool mergedCell() const { return mergedCell_; }
0054 
0055     //=== Get results
0056     //=== Most of these functions operate on the filtered stubs, which are stubs passing any requested stub filters (e.g. bend filter).
0057     //=== If no filters were requested, they are identical to the unfiltered stubs.)
0058 
0059     // Get filtered stubs in this cell in HT array.
0060     const std::vector<Stub*>& stubs() const { return vFilteredStubs_; }
0061 
0062     // Check if a specific stub is in this cell and survived filtering.
0063     bool stubInCell(const Stub* stub) const {
0064       return (std::count(vFilteredStubs_.begin(), vFilteredStubs_.end(), stub) > 0);
0065     }
0066 
0067     // Check if a specific stub was stored to this cell (without checking if it survived filtering).
0068     bool stubStoredInCell(const Stub* stub) const { return (std::count(vStubs_.begin(), vStubs_.end(), stub) > 0); }
0069 
0070     //-- Return info useful for deciding if there is a track candidate in this cell.
0071     // Number of filtered stubs
0072     unsigned int numStubs() const { return vFilteredStubs_.size(); }
0073     // Number of tracker layers with filtered stubs
0074     unsigned int numLayers() const { return numFilteredLayersInCell_; }
0075     // Number of tracker layers with filtered stubs,  requiring all stubs to be in same subsector to be counted. The number returned is the highest layer count found in any of the subsectors in this sector. If subsectors are not used, it is equal to numLayers().
0076     unsigned int numLayersSubSec() const { return numFilteredLayersInCellBestSubSec_; }
0077 
0078     // Useful for debugging.
0079     unsigned int numUnfilteredStubs() const { return vStubs_.size(); }  // Number of unfiltered stubs
0080 
0081     //=== Check if stubs in this cell form valid track candidate.
0082 
0083     // N.B. If subsectors within a sector are not being used, then numFilteredLayersInCellBestSubSec_ = numFilteredLayersInCell_.
0084     // WARNING: If some tracks are killed as the r-phi HT array can't read them out within the TM period,
0085     // killed tracks are still found by this function. It is in HTbase::calcTrackCands2D() that they are killed.
0086     bool trackCandFound() const {
0087       return (numFilteredLayersInCellBestSubSec_ >=
0088               Utility::numLayerCut(Utility::AlgoStep::HT, settings_, iPhiSec_, iEtaReg_, std::abs(qOverPtCell_)));
0089     }
0090 
0091     //=== Disable filters (used for debugging).
0092 
0093     void disableBendFilter() { useBendFilter_ = false; }
0094 
0095   private:
0096     // Calculate how many tracker layers the filtered stubs in this cell are in
0097     unsigned int calcNumFilteredLayers() const { return Utility::countLayers(settings_, vFilteredStubs_); }
0098 
0099     // Calculate how many tracker layers the filter stubs in this cell are in, when only the subset of those stubs
0100     // that are in the specified subsector are counted.
0101     unsigned int calcNumFilteredLayers(unsigned int iSubSec) const;
0102 
0103     // Estimate track bend angle at a given radius, derived using the track q/Pt at the centre of this HT cell, ignoring scattering.
0104     float dphi(float rad) const { return (invPtToDphi_ * rad * qOverPtCell_); }
0105 
0106     // Produce a filtered collection of stubs in this cell that all have consistent bend
0107     std::vector<Stub*> bendFilter(const std::vector<Stub*>& stubs) const;
0108 
0109     // Filter stubs so as to prevent more than specified number of stubs being stored in one cell.
0110     // This reflects finite memory of hardware.
0111     std::vector<Stub*> maxStubCountFilter(const std::vector<Stub*>& stubs) const;
0112 
0113   private:
0114     //=== Configuration parameters
0115 
0116     const Settings* settings_;
0117 
0118     unsigned int iPhiSec_;  // Sector number
0119     unsigned int iEtaReg_;
0120 
0121     float etaMinSector_;  // rapidity range of this sector.
0122     float etaMaxSector_;
0123 
0124     float qOverPtCell_;  // track q/Pt corresponding to centre of this cell.
0125 
0126     // Note bin number of cell along q/Pt axis of r-phi HT array. (Not used for r-z HT).
0127     unsigned int ibin_qOverPt_;
0128     // Is this HT cell the merge of smaller HT cells?
0129     bool mergedCell_;
0130 
0131     // Is this cell in Mini-HT?
0132     bool miniHTcell_;
0133 
0134     float invPtToDphi_;  // B*c/2E11
0135 
0136     // Use filter in each HT cell using only stubs which have consistent bend?
0137     bool useBendFilter_;
0138     // 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).
0139     unsigned int maxStubsInCell_;
0140 
0141     // Number of subsectors (if any) within each sector.
0142     unsigned int numSubSecs_;
0143 
0144     //=== data
0145 
0146     std::vector<Stub*> vStubs_;          // Stubs in this cell
0147     std::vector<Stub*> vFilteredStubs_;  // Ditto after all requested stub filters (e.g. bend filter)
0148 
0149     unsigned int numFilteredLayersInCell_;
0150     unsigned int numFilteredLayersInCellBestSubSec_;
0151     std::map<const Stub*, std::vector<bool>> subSectors_;  // Subsectors in sector stub consistent with.
0152   };
0153 
0154 }  // namespace tmtt
0155 #endif