Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef PHASE2GMT_MUONROI
0002 #define PHASE2GMT_MUONROI
0003 #include <iosfwd>
0004 #include "DataFormats/L1TMuonPhase2/interface/Constants.h"
0005 #include "DataFormats/L1TMuonPhase2/interface/MuonStub.h"
0006 #include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
0007 #include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h"
0008 #include "DataFormats/L1Trigger/interface/L1TObjComparison.h"
0009 #include "DataFormats/L1Trigger/interface/BXVector.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 namespace Phase2L1GMT {
0013 
0014   class MuonROI {
0015   public:
0016     MuonROI(int bx, uint charge, uint pt, uint quality) : bx_(bx), charge_(charge), pt_(pt), quality_(quality) {}
0017 
0018     const int bx() const { return bx_; }
0019 
0020     const uint charge() const { return charge_; }
0021 
0022     const uint pt() const { return pt_; }
0023     const int quality() const { return quality_; }
0024 
0025     const float offline_pt() const { return offline_pt_; }
0026 
0027     void setOfflinePt(float pt) { offline_pt_ = pt; }
0028 
0029     void addStub(const l1t::MuonStubRef& stub) { stubs_.push_back(stub); }
0030 
0031     void setMuonRef(const l1t::RegionalMuonCandRef& ref) {
0032       muRef_ = ref;
0033       isGlobal_ = true;
0034     }
0035     bool isGlobalMuon() const { return isGlobal_; }
0036 
0037     const l1t::RegionalMuonCandRef& muonRef() const { return muRef_; }
0038 
0039     friend std::ostream& operator<<(std::ostream& s, const MuonROI& id) {
0040       s.setf(ios::right, ios::adjustfield);
0041       s << "ROI:"
0042         << " "
0043         << "BX: " << setw(5) << id.bx_ << " "
0044         << "charge:" << setw(5) << id.charge_ << " "
0045         << "pt:" << setw(5) << id.pt_ << " "
0046         << "quality:" << setw(5) << id.quality_ << " "
0047         << "offline pt:" << setw(5) << id.offline_pt_;
0048       return s;
0049     }
0050 
0051     const l1t::MuonStubRefVector& stubs() const { return stubs_; }
0052 
0053     ap_uint<64> stubWord(const l1t::MuonStubRef& stub) const {
0054       ap_uint<64> word = 0;
0055       word = word | twos_complement(stub->coord1(), BITSSTUBCOORD);
0056       word = word | (twos_complement(stub->coord2(), BITSSTUBCOORD) << BITSSTUBCOORD);
0057       word = word | (twos_complement(stub->eta1(), BITSSTUBETA) << (2 * BITSSTUBCOORD));
0058       word = word | (twos_complement(stub->eta2(), BITSSTUBETA) << (2 * BITSSTUBCOORD + BITSSTUBETA));
0059       word = word | (twos_complement(stub->quality(), BITSSTUBPHIQUALITY) << (2 * BITSSTUBCOORD + 2 * BITSSTUBETA));
0060       word = word | (twos_complement(stub->etaQuality(), BITSSTUBETAQUALITY)
0061                      << (2 * BITSSTUBCOORD + 2 * BITSSTUBETA + BITSSTUBPHIQUALITY));
0062       word = word | (twos_complement(stub->bxNum(), BITSSTUBTIME)
0063                      << (2 * BITSSTUBCOORD + 2 * BITSSTUBETA + BITSSTUBPHIQUALITY + BITSSTUBETAQUALITY));
0064       word = word | (twos_complement(stub->id(), BITSSTUBID)
0065                      << (2 * BITSSTUBCOORD + 2 * BITSSTUBETA + BITSSTUBPHIQUALITY + BITSSTUBETAQUALITY + BITSSTUBTIME));
0066       return word;
0067     }
0068 
0069     ap_uint<32> roiWord() const {
0070       ap_uint<32> word = 0;
0071       word = word | twos_complement(bx_, BITSMUONBX);
0072       word = word | (twos_complement(isGlobal_, 1) << (BITSMUONBX));
0073       word = word | (twos_complement(charge_, 1) << (BITSMUONBX + 1));
0074       word = word | (twos_complement(pt_, BITSPT) << (BITSMUONBX + 2));
0075       word = word | (twos_complement(quality_, BITSSTAMUONQUALITY) << (BITSMUONBX + 2 + BITSPT));
0076       return word;
0077     }
0078 
0079     void printROILine() const {
0080       ap_uint<64> s0 = 0x1ff000000000000;
0081       ap_uint<64> s1 = 0x1ff000000000000;
0082       ap_uint<64> s2 = 0x1ff000000000000;
0083       ap_uint<64> s3 = 0x1ff000000000000;
0084       ap_uint<64> s4 = 0x1ff000000000000;
0085       for (const auto& s : stubs_) {
0086         if (s->tfLayer() == 0)
0087           s0 = stubWord(s);
0088         if (s->tfLayer() == 1)
0089           s1 = stubWord(s);
0090         if (s->tfLayer() == 2)
0091           s2 = stubWord(s);
0092         if (s->tfLayer() == 3)
0093           s3 = stubWord(s);
0094         if (s->tfLayer() == 4)
0095           s4 = stubWord(s);
0096       }
0097       LogDebug("MuonROI") << "MuonROI " << std::setfill('0') << std::setw(8) << std::hex
0098                           << (long long unsigned int)(roiWord().to_uint64()) << std::setfill('0') << std::setw(16)
0099                           << std::hex << (long long unsigned int)(s4.to_uint64()) << std::setfill('0') << std::setw(16)
0100                           << std::hex << (long long unsigned int)(s3.to_uint64()) << std::setfill('0') << std::setw(16)
0101                           << std::hex << (long long unsigned int)(s2.to_uint64()) << std::setfill('0') << std::setw(16)
0102                           << std::hex << (long long unsigned int)(s1.to_uint64()) << std::setfill('0') << std::setw(16)
0103                           << std::hex << (long long unsigned int)(s0.to_uint64());
0104     }
0105 
0106   private:
0107     int bx_;
0108     uint charge_;
0109     uint pt_;
0110     uint quality_;
0111     bool isGlobal_;
0112     float offline_pt_;
0113 
0114     l1t::MuonStubRefVector stubs_;
0115     l1t::RegionalMuonCandRef muRef_;
0116   };
0117 }  // namespace Phase2L1GMT
0118 
0119 #endif