From 57f96fb76e3c19e432dc317a5adff801fbd6afac Mon Sep 17 00:00:00 2001 From: Ivan Razumov Date: Mon, 25 Mar 2024 14:08:21 +0100 Subject: [PATCH] [CPP20][L1,UPGRADE] Replace some enums with constexpr ints --- DataFormats/CSCDigi/interface/CSCConstants.h | 87 +++++++------ .../interface/CSCTFConstants.h | 2 +- .../interface/TTTrack_TrackWord.h | 12 +- .../interface/L1GctHtMissLut.h | 2 +- .../plugins/L1DummyProducer.h | 5 +- .../src/L1ExtraTestAnalyzer.cc | 2 +- .../Phase2L1ParticleFlow/interface/JetId.h | 2 +- .../Phase2L1ParticleFlow/interface/TauNNId.h | 2 +- L1Trigger/Phase2L1ParticleFlow/src/JetId.cc | 4 +- L1Trigger/Phase2L1ParticleFlow/src/TauNNId.cc | 2 +- L1Trigger/RPCTrigger/interface/RPCConst.h | 19 ++- .../plugins/ProducerKFout.cc | 6 +- .../TrackTrigger/plugins/TTStubBuilder.h | 2 +- L1Trigger/VertexFinder/src/VertexFinder.cc | 116 ++++++++---------- 14 files changed, 120 insertions(+), 143 deletions(-) diff --git a/DataFormats/CSCDigi/interface/CSCConstants.h b/DataFormats/CSCDigi/interface/CSCConstants.h index fdf285da94d9e..b4501336b6fef 100644 --- a/DataFormats/CSCDigi/interface/CSCConstants.h +++ b/DataFormats/CSCDigi/interface/CSCConstants.h @@ -53,51 +53,50 @@ class CSCConstants { }; // distrips, strips, half-strips - enum Strip_Info { - // Each CFEB reads out 8 distrips... - NUM_DISTRIPS_PER_CFEB = 8, - //...16 strips... - NUM_STRIPS_PER_CFEB = 2 * NUM_DISTRIPS_PER_CFEB, - //...32 half-strips. - NUM_HALF_STRIPS_PER_CFEB = 2 * NUM_STRIPS_PER_CFEB, - // There are exactly 80 or 112 strips... - MAX_NUM_STRIPS_RUN1 = MAX_CFEBS_RUN1 * NUM_STRIPS_PER_CFEB, // 80 - MAX_NUM_STRIPS_RUN2 = MAX_CFEBS_RUN2 * NUM_STRIPS_PER_CFEB, // 112 - //...and 160 or 224 half-strips for 5 or 7 CFEBs... - MAX_NUM_HALF_STRIPS_RUN1 = MAX_CFEBS_RUN1 * NUM_HALF_STRIPS_PER_CFEB, // 160 - MAX_NUM_HALF_STRIPS_RUN2 = MAX_CFEBS_RUN2 * NUM_HALF_STRIPS_PER_CFEB, // 224 - // ...but depending on the chamber, there may or may not be strip staggering. - /* CMS-MUO-16-001: "[..] alternate layers in a CSC are staggered by half a strip width, except + static constexpr int + // Each CFEB reads out 8 distrips... + NUM_DISTRIPS_PER_CFEB = 8, + //...16 strips... + NUM_STRIPS_PER_CFEB = 2 * NUM_DISTRIPS_PER_CFEB, + //...32 half-strips. + NUM_HALF_STRIPS_PER_CFEB = 2 * NUM_STRIPS_PER_CFEB, + // There are exactly 80 or 112 strips... + MAX_NUM_STRIPS_RUN1 = MAX_CFEBS_RUN1 * NUM_STRIPS_PER_CFEB, // 80 + MAX_NUM_STRIPS_RUN2 = MAX_CFEBS_RUN2 * NUM_STRIPS_PER_CFEB, // 112 + //...and 160 or 224 half-strips for 5 or 7 CFEBs... + MAX_NUM_HALF_STRIPS_RUN1 = MAX_CFEBS_RUN1 * NUM_HALF_STRIPS_PER_CFEB, // 160 + MAX_NUM_HALF_STRIPS_RUN2 = MAX_CFEBS_RUN2 * NUM_HALF_STRIPS_PER_CFEB, // 224 + // ...but depending on the chamber, there may or may not be strip staggering. + /* CMS-MUO-16-001: "[..] alternate layers in a CSC are staggered by half a strip width, except in the ME1/1 chambers where the strips are narrower and the effect is small" */ - // _TRIGGER is added at the end, because these constants are only used in the trigger - MAX_NUM_HALF_STRIPS_RUN1_TRIGGER = 1 + MAX_NUM_HALF_STRIPS_RUN1, // 161 - MAX_NUM_HALF_STRIPS_RUN2_TRIGGER = 1 + MAX_NUM_HALF_STRIPS_RUN2, // 225 - // Number of strips in ME11 (special case) - NUM_STRIPS_ME1A_GANGED = NUM_CFEBS_ME1A_GANGED * NUM_STRIPS_PER_CFEB, // 16 - NUM_STRIPS_ME1A_UNGANGED = NUM_CFEBS_ME1A_UNGANGED * NUM_STRIPS_PER_CFEB, // 48 - NUM_STRIPS_ME1B = NUM_CFEBS_ME1B * NUM_STRIPS_PER_CFEB, // 64 - // Number of half-strips in ME11 (special case) - NUM_HALF_STRIPS_ME1A_GANGED = NUM_CFEBS_ME1A_GANGED * NUM_HALF_STRIPS_PER_CFEB, // 32 - NUM_HALF_STRIPS_ME1A_UNGANGED = NUM_CFEBS_ME1A_UNGANGED * NUM_HALF_STRIPS_PER_CFEB, // 96 - NUM_HALF_STRIPS_ME1B = NUM_CFEBS_ME1B * NUM_HALF_STRIPS_PER_CFEB, // 128 - NUM_HALF_STRIPS_ME11_GANGED = NUM_CFEBS_ME11_GANGED * NUM_HALF_STRIPS_PER_CFEB, // 160 - NUM_HALF_STRIPS_ME11_UNGANGED = NUM_CFEBS_ME11_UNGANGED * NUM_HALF_STRIPS_PER_CFEB, // 224 - // max halfstrip number in ME1/1 chambers - MAX_HALF_STRIP_ME1A_GANGED = NUM_HALF_STRIPS_ME1A_GANGED - 1, // 31 - MAX_HALF_STRIP_ME1A_UNGANGED = NUM_HALF_STRIPS_ME1A_UNGANGED - 1, // 95 - MAX_HALF_STRIP_ME1B = NUM_HALF_STRIPS_ME1B - 1, // 127 - // half-strips for the rest of the system - NUM_HALF_STRIPS_ME12 = NUM_CFEBS_ME12 * NUM_HALF_STRIPS_PER_CFEB, // 160 - NUM_HALF_STRIPS_ME13 = NUM_CFEBS_ME13 * NUM_HALF_STRIPS_PER_CFEB, // 128 - NUM_HALF_STRIPS_ME21 = NUM_CFEBS_ME21 * NUM_HALF_STRIPS_PER_CFEB, // 160 - NUM_HALF_STRIPS_ME22 = NUM_CFEBS_ME22 * NUM_HALF_STRIPS_PER_CFEB, // 160 - NUM_HALF_STRIPS_ME31 = NUM_CFEBS_ME31 * NUM_HALF_STRIPS_PER_CFEB, // 160 - NUM_HALF_STRIPS_ME32 = NUM_CFEBS_ME32 * NUM_HALF_STRIPS_PER_CFEB, // 160 - NUM_HALF_STRIPS_ME41 = NUM_CFEBS_ME41 * NUM_HALF_STRIPS_PER_CFEB, // 160 - NUM_HALF_STRIPS_ME42 = NUM_CFEBS_ME42 * NUM_HALF_STRIPS_PER_CFEB, // 160 - // useful for the comparator code algorithm - INVALID_HALF_STRIP = 65535 - }; + // _TRIGGER is added at the end, because these constants are only used in the trigger + MAX_NUM_HALF_STRIPS_RUN1_TRIGGER = 1 + MAX_NUM_HALF_STRIPS_RUN1, // 161 + MAX_NUM_HALF_STRIPS_RUN2_TRIGGER = 1 + MAX_NUM_HALF_STRIPS_RUN2, // 225 + // Number of strips in ME11 (special case) + NUM_STRIPS_ME1A_GANGED = NUM_CFEBS_ME1A_GANGED * NUM_STRIPS_PER_CFEB, // 16 + NUM_STRIPS_ME1A_UNGANGED = NUM_CFEBS_ME1A_UNGANGED * NUM_STRIPS_PER_CFEB, // 48 + NUM_STRIPS_ME1B = NUM_CFEBS_ME1B * NUM_STRIPS_PER_CFEB, // 64 + // Number of half-strips in ME11 (special case) + NUM_HALF_STRIPS_ME1A_GANGED = NUM_CFEBS_ME1A_GANGED * NUM_HALF_STRIPS_PER_CFEB, // 32 + NUM_HALF_STRIPS_ME1A_UNGANGED = NUM_CFEBS_ME1A_UNGANGED * NUM_HALF_STRIPS_PER_CFEB, // 96 + NUM_HALF_STRIPS_ME1B = NUM_CFEBS_ME1B * NUM_HALF_STRIPS_PER_CFEB, // 128 + NUM_HALF_STRIPS_ME11_GANGED = NUM_CFEBS_ME11_GANGED * NUM_HALF_STRIPS_PER_CFEB, // 160 + NUM_HALF_STRIPS_ME11_UNGANGED = NUM_CFEBS_ME11_UNGANGED * NUM_HALF_STRIPS_PER_CFEB, // 224 + // max halfstrip number in ME1/1 chambers + MAX_HALF_STRIP_ME1A_GANGED = NUM_HALF_STRIPS_ME1A_GANGED - 1, // 31 + MAX_HALF_STRIP_ME1A_UNGANGED = NUM_HALF_STRIPS_ME1A_UNGANGED - 1, // 95 + MAX_HALF_STRIP_ME1B = NUM_HALF_STRIPS_ME1B - 1, // 127 + // half-strips for the rest of the system + NUM_HALF_STRIPS_ME12 = NUM_CFEBS_ME12 * NUM_HALF_STRIPS_PER_CFEB, // 160 + NUM_HALF_STRIPS_ME13 = NUM_CFEBS_ME13 * NUM_HALF_STRIPS_PER_CFEB, // 128 + NUM_HALF_STRIPS_ME21 = NUM_CFEBS_ME21 * NUM_HALF_STRIPS_PER_CFEB, // 160 + NUM_HALF_STRIPS_ME22 = NUM_CFEBS_ME22 * NUM_HALF_STRIPS_PER_CFEB, // 160 + NUM_HALF_STRIPS_ME31 = NUM_CFEBS_ME31 * NUM_HALF_STRIPS_PER_CFEB, // 160 + NUM_HALF_STRIPS_ME32 = NUM_CFEBS_ME32 * NUM_HALF_STRIPS_PER_CFEB, // 160 + NUM_HALF_STRIPS_ME41 = NUM_CFEBS_ME41 * NUM_HALF_STRIPS_PER_CFEB, // 160 + NUM_HALF_STRIPS_ME42 = NUM_CFEBS_ME42 * NUM_HALF_STRIPS_PER_CFEB, // 160 + // useful for the comparator code algorithm + INVALID_HALF_STRIP = 65535; // CSCs have 6 layers. The key (reference) layer is the third layer enum Layer_Info { NUM_LAYERS = 6, KEY_CLCT_LAYER = 3, KEY_ALCT_LAYER = 3 }; diff --git a/DataFormats/L1CSCTrackFinder/interface/CSCTFConstants.h b/DataFormats/L1CSCTrackFinder/interface/CSCTFConstants.h index 52764890fe96b..6cc2c45bb7f3b 100644 --- a/DataFormats/L1CSCTrackFinder/interface/CSCTFConstants.h +++ b/DataFormats/L1CSCTrackFinder/interface/CSCTFConstants.h @@ -31,7 +31,7 @@ class CSCTFConstants { enum Digis_Info { MAX_DIGIS_PER_ALCT = 10, MAX_DIGIS_PER_CLCT = 8 }; - enum eta_info { etaBins = 1 << CSCBitWidths::kGlobalEtaBitWidth }; + static constexpr int etaBins = 1 << CSCBitWidths::kGlobalEtaBitWidth; enum MPC_stubs { maxStubs = 3 }; diff --git a/DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h b/DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h index c235c7f545ba3..f08b0100fe1d6 100644 --- a/DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h +++ b/DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h @@ -49,11 +49,11 @@ class TTTrack_TrackWord { kPhiSize = 12, // Width of phi kRinvSize = 15, // Width of Rinv kValidSize = 1, // Valid bit - - kTrackWordSize = kValidSize + kRinvSize + kPhiSize + kChi2RPhiSize + kTanlSize + kZ0Size + kChi2RZSize + kD0Size + - kBendChi2Size + kHitPatternSize + kMVAQualitySize + - kMVAOtherSize, // Width of the track word in bits }; + static constexpr int kTrackWordSize = kValidSize + kRinvSize + kPhiSize + kChi2RPhiSize + kTanlSize + kZ0Size + + kChi2RZSize + kD0Size + kBendChi2Size + kHitPatternSize + kMVAQualitySize + + kMVAOtherSize // Width of the track word in bits + ; enum TrackBitLocations { // The location of the least significant bit (LSB) and most significant bit (MSB) in the track word for different fields @@ -129,8 +129,8 @@ class TTTrack_TrackWord { typedef ap_uint otherMVA_t; // Specialized MVA selection // Track word types - typedef std::bitset tkword_bs_t; // Entire track word; - typedef ap_uint tkword_t; // Entire track word; + typedef std::bitset tkword_bs_t; // Entire track word; + typedef ap_uint tkword_t; // Entire track word; public: // ----------Constructors -------------------------- diff --git a/L1Trigger/GlobalCaloTrigger/interface/L1GctHtMissLut.h b/L1Trigger/GlobalCaloTrigger/interface/L1GctHtMissLut.h index 0d9243d8e8b6c..29736bd56e947 100644 --- a/L1Trigger/GlobalCaloTrigger/interface/L1GctHtMissLut.h +++ b/L1Trigger/GlobalCaloTrigger/interface/L1GctHtMissLut.h @@ -21,7 +21,7 @@ class L1GctHtMissLut : public L1GctLut<16, 12> { public: - enum numberOfBits { kHxOrHyMissComponentNBits = 8, kHtMissMagnitudeNBits = 7, kHtMissAngleNBits = 5 }; + static constexpr int kHxOrHyMissComponentNBits = 8, kHtMissMagnitudeNBits = 7, kHtMissAngleNBits = 5; // Definitions. static const int NAddress, NData; diff --git a/L1Trigger/HardwareValidation/plugins/L1DummyProducer.h b/L1Trigger/HardwareValidation/plugins/L1DummyProducer.h index 8b5abfa5fae73..fb79751c45058 100644 --- a/L1Trigger/HardwareValidation/plugins/L1DummyProducer.h +++ b/L1Trigger/HardwareValidation/plugins/L1DummyProducer.h @@ -504,8 +504,9 @@ inline void L1DummyProducer::SimpleDigi(int, //tbd: set non-trivial random values dg.clear(); // set contents to zero //CSCDetId( int iendcap, int istation, int iring, int ichamber, int ilayer = 0 ); - enum eMinNum { MIN_ENDCAP = 1, MIN_STATION = 1, MIN_RING = 1, MIN_CHAMBER = 1, MIN_LAYER = 1 }; - enum eMaxNum { MAX_ENDCAP = 2, MAX_STATION = 4, MAX_RING = 4, MAX_CHAMBER = 36, MAX_LAYER = 6 }; + static constexpr int MIN_ENDCAP = 1, MIN_STATION = 1, MIN_RING = 1, MIN_CHAMBER = 1, MIN_LAYER = 1; + static constexpr int MAX_ENDCAP = 2, MAX_STATION = 4, MAX_RING = 4, MAX_CHAMBER = 36, MAX_LAYER = 6; + float rnd = engine->flat(); int ec = (int)(MIN_ENDCAP + (MAX_ENDCAP - MIN_ENDCAP) * rnd + 1); int st = (int)(MIN_STATION + (MAX_STATION - MIN_STATION) * rnd + 1); diff --git a/L1Trigger/L1ExtraFromDigis/src/L1ExtraTestAnalyzer.cc b/L1Trigger/L1ExtraFromDigis/src/L1ExtraTestAnalyzer.cc index 1adebabaa6a00..5dbaa192094d6 100644 --- a/L1Trigger/L1ExtraFromDigis/src/L1ExtraTestAnalyzer.cc +++ b/L1Trigger/L1ExtraFromDigis/src/L1ExtraTestAnalyzer.cc @@ -105,7 +105,7 @@ L1ExtraTestAnalyzer::L1ExtraTestAnalyzer(const edm::ParameterSet &iConfig) "Triggers", 2 * l1extra::L1ParticleMap::kNumOfL1TriggerTypes + 1, -0.75, - l1extra::L1ParticleMap::kNumOfL1TriggerTypes + 0.5 - 0.75) { + static_cast(l1extra::L1ParticleMap::kNumOfL1TriggerTypes) + 0.5 - 0.75) { // now do what ever initialization is needed } diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/JetId.h b/L1Trigger/Phase2L1ParticleFlow/interface/JetId.h index 8dd4d14a7afcf..4c940d5d9ea90 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/JetId.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/JetId.h @@ -43,7 +43,7 @@ class JetId { unique_ptr fPt_; unique_ptr fEta_; unique_ptr fPhi_; - unique_ptr fId_; + unique_ptr fId_; unique_ptr fCharge_; unique_ptr fDZ_; unique_ptr fDX_; diff --git a/L1Trigger/Phase2L1ParticleFlow/interface/TauNNId.h b/L1Trigger/Phase2L1ParticleFlow/interface/TauNNId.h index 92ed901ae8db7..cbbbcee4f2a4a 100644 --- a/L1Trigger/Phase2L1ParticleFlow/interface/TauNNId.h +++ b/L1Trigger/Phase2L1ParticleFlow/interface/TauNNId.h @@ -26,6 +26,6 @@ class TauNNId { unique_ptr fPt_; unique_ptr fEta_; unique_ptr fPhi_; - unique_ptr fId_; + unique_ptr fId_; }; #endif diff --git a/L1Trigger/Phase2L1ParticleFlow/src/JetId.cc b/L1Trigger/Phase2L1ParticleFlow/src/JetId.cc index 3692ad912c6d0..611949001b85c 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/JetId.cc +++ b/L1Trigger/Phase2L1ParticleFlow/src/JetId.cc @@ -13,7 +13,7 @@ JetId::JetId(const std::string &iInput, fPt_ = std::make_unique(fNParticles_); fEta_ = std::make_unique(fNParticles_); fPhi_ = std::make_unique(fNParticles_); - fId_ = std::make_unique(fNParticles_); + fId_ = std::make_unique(fNParticles_); fCharge_ = std::make_unique(fNParticles_); fDZ_ = std::make_unique(fNParticles_); fDX_ = std::make_unique(fNParticles_); @@ -31,7 +31,7 @@ JetId::JetId(const std::string &iInput, const std::string &iOutput, const BJetTF fPt_ = std::make_unique(fNParticles_); fEta_ = std::make_unique(fNParticles_); fPhi_ = std::make_unique(fNParticles_); - fId_ = std::make_unique(fNParticles_); + fId_ = std::make_unique(fNParticles_); fCharge_ = std::make_unique(fNParticles_); fDZ_ = std::make_unique(fNParticles_); fDX_ = std::make_unique(fNParticles_); diff --git a/L1Trigger/Phase2L1ParticleFlow/src/TauNNId.cc b/L1Trigger/Phase2L1ParticleFlow/src/TauNNId.cc index 3cce460c0337c..d4d790e115610 100644 --- a/L1Trigger/Phase2L1ParticleFlow/src/TauNNId.cc +++ b/L1Trigger/Phase2L1ParticleFlow/src/TauNNId.cc @@ -17,7 +17,7 @@ TauNNId::TauNNId(const std::string &iInput, fPt_ = std::make_unique(fNParticles_); fEta_ = std::make_unique(fNParticles_); fPhi_ = std::make_unique(fNParticles_); - fId_ = std::make_unique(fNParticles_); + fId_ = std::make_unique(fNParticles_); fInput_ = iInput; } diff --git a/L1Trigger/RPCTrigger/interface/RPCConst.h b/L1Trigger/RPCTrigger/interface/RPCConst.h index a3789b3358077..84f692a6df314 100644 --- a/L1Trigger/RPCTrigger/interface/RPCConst.h +++ b/L1Trigger/RPCTrigger/interface/RPCConst.h @@ -22,16 +22,15 @@ class RPCConst { public: - enum { - ITOW_MIN = 0, //!< Minimal number of abs(m_tower_number) - ITOW_MAX = 16, //!< Maximal number of abs(m_tower_number) - //ITOW_MAX_LOWPT = 7, //!< Max m_tower number to which low_pt algorithm is used - IPT_MAX = 31, //!< Max pt bin code - NSTRIPS = 1152, //!< m_Number of Rpc strips in phi direction. - NSEG = NSTRIPS / 8, //!< m_Number of trigger segments. One segment covers 8 RPC strips - //!numRegions(); iRegion++) { int buffered_tracks[] = {0, 0}; - for (int iTrack = 0; - iTrack < setup_->numFramesIO() * ((double)TTBV::S_ / TTTrack_TrackWord::TrackBitWidths::kTrackWordSize); + for (int iTrack = 0; iTrack < setup_->numFramesIO() * ((double)TTBV::S_ / TTTrack_TrackWord::kTrackWordSize); iTrack++) { for (int iWorker = 0; iWorker < setup_->kfNumWorker(); iWorker++) { for (int iLink = 0; iLink < setup_->tfpNumChannel(); iLink++) { @@ -376,8 +375,7 @@ namespace trklet { if (it.second == outputStreamsTracks[iLink][(int)(iTrack - 1) / 3].first) trackRef = it.first; } - if ((int)iTrack / 3 <= - setup_->numFramesIO() * ((double)TTBV::S_ / TTTrack_TrackWord::TrackBitWidths::kTrackWordSize)) + if ((int)iTrack / 3 <= setup_->numFramesIO() * ((double)TTBV::S_ / TTTrack_TrackWord::kTrackWordSize)) accepted[iLink].emplace_back( std::make_pair(trackRef, (sortedPartialTracks[iLink][iTrack - 1].slice(partialTrackWordBits_) + diff --git a/L1Trigger/TrackTrigger/plugins/TTStubBuilder.h b/L1Trigger/TrackTrigger/plugins/TTStubBuilder.h index b26ae396c0d65..e29f77cd796c4 100644 --- a/L1Trigger/TrackTrigger/plugins/TTStubBuilder.h +++ b/L1Trigger/TrackTrigger/plugins/TTStubBuilder.h @@ -51,7 +51,7 @@ class TTStubBuilder : public edm::one::EDProducer { ~TTStubBuilder() override; // TTStub bendOffset has this added to it, if stub truncated by FE, to indicate reason. - enum FEreject { CBCFailOffset = 500, CICFailOffset = 1000 }; + static constexpr int CBCFailOffset = 500, CICFailOffset = 1000; private: /// Data members diff --git a/L1Trigger/VertexFinder/src/VertexFinder.cc b/L1Trigger/VertexFinder/src/VertexFinder.cc index 7778f4fe4fbfa..4bb266cc6d434 100644 --- a/L1Trigger/VertexFinder/src/VertexFinder.cc +++ b/L1Trigger/VertexFinder/src/VertexFinder.cc @@ -761,71 +761,55 @@ namespace l1tVertexFinder { void VertexFinder::fastHistoEmulation() { // Relevant constants for the track word - enum TrackBitWidths { - kZ0Size = 12, // Width of z-position (40cm / 0.1) - kZ0MagSize = 5, // Width of z-position magnitude (signed) - kPtSize = 14, // Width of pt - kPtMagSize = 9, // Width of pt magnitude (unsigned) - kReducedPrecisionPt = 7, // Width of the reduced precision, integer only, pt - }; - - enum HistogramBitWidths { - kBinSize = 8, // Width of a single bin in z - kBinFixedSize = 8, // Width of a single z0 bin in fixed point representation - kBinFixedMagSize = 5, // Width (magnitude) of a single z0 bin in fixed point representation - kSlidingSumSize = 11, // Width of the sum of a window of bins - kInverseSize = 14, // Width of the inverse sum - kInverseMagSize = 1, // Width of the inverse sum magnitude (unsigned) - kWeightedSlidingSumSize = 20, // Width of the pT weighted sliding sum - kWeightedSlidingSumMagSize = 10, // Width of the pT weighted sliding sum magnitude (signed) - kWindowSize = 3, // Number of bins in the window used to sum histogram bins - kSumPtLinkSize = 9, // Number of bits used to represent the sum of track pts in a single bin from a single link - - kSumPtWindowBits = BitsToRepresent(HistogramBitWidths::kWindowSize * (1 << HistogramBitWidths::kSumPtLinkSize)), - // Number of bits to represent the untruncated sum of track pts in a single bin from a single link - kSumPtUntruncatedLinkSize = TrackBitWidths::kPtSize + 2, - kSumPtUntruncatedLinkMagSize = TrackBitWidths::kPtMagSize + 2, - }; - - static constexpr unsigned int kTableSize = - ((1 << HistogramBitWidths::kSumPtLinkSize) - 1) * HistogramBitWidths::kWindowSize; - - typedef ap_ufixed pt_t; + static constexpr int kZ0Size = 12, // Width of z-position (40cm / 0.1) + kZ0MagSize = 5, // Width of z-position magnitude (signed) + kPtSize = 14, // Width of pt + kPtMagSize = 9, // Width of pt magnitude (unsigned) + kReducedPrecisionPt = 7 // Width of the reduced precision, integer only, pt + ; + + static constexpr int + kBinSize = 8, // Width of a single bin in z + kBinFixedSize = 8, // Width of a single z0 bin in fixed point representation + kBinFixedMagSize = 5, // Width (magnitude) of a single z0 bin in fixed point representation + kSlidingSumSize = 11, // Width of the sum of a window of bins + kInverseSize = 14, // Width of the inverse sum + kInverseMagSize = 1, // Width of the inverse sum magnitude (unsigned) + kWeightedSlidingSumSize = 20, // Width of the pT weighted sliding sum + kWeightedSlidingSumMagSize = 10, // Width of the pT weighted sliding sum magnitude (signed) + kWindowSize = 3, // Number of bins in the window used to sum histogram bins + kSumPtLinkSize = 9, // Number of bits used to represent the sum of track pts in a single bin from a single link + + kSumPtWindowBits = BitsToRepresent(kWindowSize * (1 << kSumPtLinkSize)), + // Number of bits to represent the untruncated sum of track pts in a single bin from a single link + kSumPtUntruncatedLinkSize = kPtSize + 2, kSumPtUntruncatedLinkMagSize = kPtMagSize + 2; + + static constexpr unsigned int kTableSize = ((1 << kSumPtLinkSize) - 1) * kWindowSize; + + typedef ap_ufixed pt_t; // Same size as TTTrack_TrackWord::z0_t, but now taking into account the sign bit (i.e. 2's complement) - typedef ap_int z0_t; + typedef ap_int z0_t; // 7 bits chosen to represent values between [0,127] // This is the next highest power of 2 value to our chosen track pt saturation value (100) - typedef ap_ufixed - track_pt_fixed_t; + typedef ap_ufixed track_pt_fixed_t; // Histogram bin index - typedef ap_uint histbin_t; + typedef ap_uint histbin_t; // Histogram bin in fixed point representation, before truncation - typedef ap_ufixed - histbin_fixed_t; + typedef ap_ufixed histbin_fixed_t; // This type is slightly arbitrary, but 2 bits larger than untruncated track pt to store sums in histogram bins // with truncation just before vertex-finding - typedef ap_ufixed + typedef ap_ufixed histbin_pt_sum_fixed_t; // This value is slightly arbitrary, but small enough that the windows sums aren't too big. - typedef ap_ufixed - link_pt_sum_fixed_t; - // Enough bits to store HistogramBitWidths::kWindowSize * (2**HistogramBitWidths::kSumPtLinkSize) - typedef ap_ufixed - window_pt_sum_fixed_t; + typedef ap_ufixed link_pt_sum_fixed_t; + // Enough bits to store kWindowSize * (2**kSumPtLinkSize) + typedef ap_ufixed window_pt_sum_fixed_t; // pt weighted sum of bins in window - typedef ap_fixed - zsliding_t; + typedef ap_fixed zsliding_t; // Sum of histogram bins in window - typedef ap_uint slidingsum_t; + typedef ap_uint slidingsum_t; // Inverse of sum of bins in a given window - typedef ap_ufixed - inverse_t; + typedef ap_ufixed inverse_t; auto track_quality_check = [&](const track_pt_fixed_t& pt) -> bool { // Track quality cuts @@ -836,14 +820,13 @@ namespace l1tVertexFinder { auto fetch_bin = [&](const z0_t& z0, int nbins) -> std::pair { // Increase the the number of bits in the word to allow for additional dynamic range - ap_int z0_13 = z0; + ap_int z0_13 = z0; // Add a number equal to half of the range in z0, meaning that the range is now [0, 2*z0_max] - ap_int absz0_13 = z0_13 + (1 << (TrackBitWidths::kZ0Size - 1)); - // Shift the bits down to truncate the dynamic range to the most significant HistogramBitWidths::kBinFixedSize bits - ap_int absz0_13_reduced = - absz0_13 >> (TrackBitWidths::kZ0Size - HistogramBitWidths::kBinFixedSize); + ap_int absz0_13 = z0_13 + (1 << (kZ0Size - 1)); + // Shift the bits down to truncate the dynamic range to the most significant kBinFixedSize bits + ap_int absz0_13_reduced = absz0_13 >> (kZ0Size - kBinFixedSize); // Put the relevant bits into the histbin_t container - histbin_t bin = absz0_13_reduced.range(HistogramBitWidths::kBinFixedSize - 1, 0); + histbin_t bin = absz0_13_reduced.range(kBinFixedSize - 1, 0); if (settings_->debug() > 2) { edm::LogInfo("VertexProducer") @@ -919,11 +902,11 @@ namespace l1tVertexFinder { } // Find the weighted position within the window in index space (width = 1) - for (ap_uint w = 0; w < HistogramBitWidths::kWindowSize; ++w) { + for (ap_uint w = 0; w < kWindowSize; ++w) { zvtx_sliding_sum += (binpt.at(w) * w); if (settings_->debug() >= 1) { *log << "(" << w << " * " << binpt.at(w) << ")"; - if (w < HistogramBitWidths::kWindowSize - 1) { + if (w < kWindowSize - 1) { *log << " + "; } } @@ -1025,8 +1008,7 @@ namespace l1tVertexFinder { // Now, truncation should happen after histograms are filled but prior to the vertex-finding part of the algo for (unsigned int hb = 0; hb < hist.size(); ++hb) { link_pt_sum_fixed_t bin_trunc = hist_untruncated.at(hb).range( - HistogramBitWidths::kSumPtUntruncatedLinkSize - 1, - HistogramBitWidths::kSumPtUntruncatedLinkSize - HistogramBitWidths::kSumPtUntruncatedLinkMagSize); + kSumPtUntruncatedLinkSize - 1, kSumPtUntruncatedLinkSize - kSumPtUntruncatedLinkMagSize); hist.at(hb) = bin_trunc; if (settings_->debug() > 2) { edm::LogInfo("VertexProducer") << "fastHistoEmulation::truncating histogram bin pt once filling is complete \n" @@ -1042,7 +1024,7 @@ namespace l1tVertexFinder { // and compute the sums using sliding windows ... sum_i_i+(w-1) where i in (0,nbins-w) and w is the window size std::vector hist_window_sums(nsums, 0); for (unsigned int b = 0; b < nsums; ++b) { - for (unsigned int w = 0; w < HistogramBitWidths::kWindowSize; ++w) { + for (unsigned int w = 0; w < kWindowSize; ++w) { unsigned int index = b + w; hist_window_sums.at(b) += hist.at(index); } @@ -1055,7 +1037,7 @@ namespace l1tVertexFinder { histbin_t b_max = 0; window_pt_sum_fixed_t max_pt = 0; zsliding_t zvtx_sliding = -999; - std::vector binpt_max(HistogramBitWidths::kWindowSize, 0); + std::vector binpt_max(kWindowSize, 0); // Find the maxima of the sums for (unsigned int i = 0; i < hist_window_sums.size(); i++) { @@ -1065,9 +1047,7 @@ namespace l1tVertexFinder { if (hist_window_sums.at(i) > max_pt) { b_max = i; max_pt = hist_window_sums.at(b_max); - std::copy(std::begin(hist) + b_max, - std::begin(hist) + b_max + HistogramBitWidths::kWindowSize, - std::begin(binpt_max)); + std::copy(std::begin(hist) + b_max, std::begin(hist) + b_max + kWindowSize, std::begin(binpt_max)); // Find the weighted position only for the highest sum pt window zvtx_sliding = weighted_position(b_max, binpt_max, max_pt, nbins);