Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-12-02 10:36:17

0001 #ifndef GtBoard_h
0002 #define GtBoard_h
0003 
0004 /**
0005  * \class GlobalBoard
0006  *
0007  *
0008  * Description: Global Trigger Logic board.
0009  *
0010  * Implementation:
0011  *    <TODO: enter implementation details>
0012  *
0013  */
0014 
0015 // system include files
0016 #include <bitset>
0017 #include <cassert>
0018 #include <vector>
0019 #include <cmath>
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Utilities/interface/typedefs.h"
0024 #include "FWCore/Utilities/interface/Exception.h"
0025 
0026 #include "DataFormats/L1TGlobal/interface/GlobalObjectMapRecord.h"
0027 
0028 #include "L1Trigger/L1TGlobal/interface/AlgorithmEvaluation.h"
0029 
0030 // Trigger Objects
0031 #include "DataFormats/L1Trigger/interface/EGamma.h"
0032 #include "DataFormats/L1Trigger/interface/Muon.h"
0033 #include "DataFormats/L1Trigger/interface/MuonShower.h"
0034 #include "DataFormats/L1Trigger/interface/Tau.h"
0035 #include "DataFormats/L1Trigger/interface/Jet.h"
0036 #include "DataFormats/L1Trigger/interface/EtSum.h"
0037 #include "L1Trigger/L1TGlobal/interface/GlobalScales.h"
0038 
0039 // Objects to produce for the output record.
0040 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0041 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0042 
0043 #include "FWCore/Framework/interface/Event.h"
0044 #include "FWCore/Framework/interface/EventSetup.h"
0045 
0046 // forward declarations
0047 class TriggerMenu;
0048 class L1CaloGeometry;
0049 class L1MuTriggerScales;
0050 //class L1GtEtaPhiConversions;
0051 
0052 // class declaration
0053 
0054 namespace l1t {
0055 
0056   class GlobalBoard {
0057   public:
0058     // constructors
0059     GlobalBoard();
0060 
0061     // destructor
0062     virtual ~GlobalBoard();
0063 
0064   public:
0065     /// receive data from Global Muon Trigger
0066     void receiveCaloObjectData(const edm::Event&,
0067                                const edm::EDGetTokenT<BXVector<l1t::EGamma>>&,
0068                                const edm::EDGetTokenT<BXVector<l1t::Tau>>&,
0069                                const edm::EDGetTokenT<BXVector<l1t::Jet>>&,
0070                                const edm::EDGetTokenT<BXVector<l1t::EtSum>>&,
0071                                const bool receiveEG,
0072                                const int nrL1EG,
0073                                const bool receiveTau,
0074                                const int nrL1Tau,
0075                                const bool receiveJet,
0076                                const int nrL1Jet,
0077                                const bool receiveEtSums);
0078 
0079     void receiveMuonObjectData(const edm::Event&,
0080                                const edm::EDGetTokenT<BXVector<l1t::Muon>>&,
0081                                const bool receiveMu,
0082                                const int nrL1Mu);
0083 
0084     void receiveMuonShowerObjectData(const edm::Event&,
0085                                      const edm::EDGetTokenT<BXVector<l1t::MuonShower>>&,
0086                                      const bool receiveMuShower,
0087                                      const int nrL1MuShower);
0088 
0089     void receiveExternalData(const edm::Event&, const edm::EDGetTokenT<BXVector<GlobalExtBlk>>&, const bool receiveExt);
0090 
0091     /// initialize the class (mainly reserve)
0092     void init(const int numberPhysTriggers,
0093               const int nrL1Mu,
0094               const int nrL1MuShower,
0095               const int nrL1EG,
0096               const int nrL1Tau,
0097               const int nrL1Jet,
0098               int bxFirst,
0099               int bxLast);
0100 
0101     /// run the uGT GTL (Conditions and Algorithms)
0102     void runGTL(const edm::Event& iEvent,
0103                 const edm::EventSetup& evSetup,
0104                 const TriggerMenu* m_l1GtMenu,
0105                 const bool produceL1GtObjectMapRecord,
0106                 const int iBxInEvent,
0107                 std::unique_ptr<GlobalObjectMapRecord>& gtObjectMapRecord,  //GTO
0108                 const unsigned int numberPhysTriggers,
0109                 const int nrL1Mu,
0110                 const int nrL1MuShower,
0111                 const int nrL1EG,
0112                 const int nrL1Tau,
0113                 const int nrL1Jet);
0114 
0115     /// run the uGT FDL (Apply Prescales and Veto)
0116     void runFDL(const edm::Event& iEvent,
0117                 const int iBxInEvent,
0118                 const int totalBxInEvent,
0119                 const unsigned int numberPhysTriggers,
0120                 const std::vector<double>& prescaleFactorsAlgoTrig,
0121                 const std::vector<unsigned int>& triggerMaskAlgoTrig,
0122                 const std::vector<int>& triggerMaskVetoAlgoTrig,
0123                 const bool algorithmTriggersUnprescaled,
0124                 const bool algorithmTriggersUnmasked);
0125 
0126     /// Fill the Daq Records
0127     void fillAlgRecord(int iBxInEvent,
0128                        std::unique_ptr<GlobalAlgBlkBxCollection>& uGtAlgRecord,
0129                        int prescaleSet,
0130                        int menuUUID,
0131                        int firmwareUUID);
0132 
0133     /// clear uGT
0134     void reset();
0135     void resetMu();
0136     void resetMuonShower();
0137     void resetCalo();
0138     void resetExternal();
0139 
0140     /// print received Muon dataWord
0141     void printGmtData(const int iBxInEvent) const;
0142 
0143     /// return decision
0144     inline const std::bitset<GlobalAlgBlk::maxPhysicsTriggers>& getDecisionWord() const { return m_gtlDecisionWord; }
0145 
0146     /// return algorithm OR decision
0147     inline const std::bitset<GlobalAlgBlk::maxPhysicsTriggers>& getAlgorithmOR() const { return m_gtlAlgorithmOR; }
0148 
0149     /// return global muon trigger candidate
0150     inline const BXVector<const l1t::Muon*>* getCandL1Mu() const { return m_candL1Mu; }
0151 
0152     /// return global muon trigger candidate
0153     inline const BXVector<const l1t::MuonShower*>* getCandL1MuShower() const { return m_candL1MuShower; }
0154 
0155     /// pointer to EG data list
0156     inline const BXVector<const l1t::L1Candidate*>* getCandL1EG() const { return m_candL1EG; }
0157 
0158     /// pointer to Jet data list
0159     inline const BXVector<const l1t::L1Candidate*>* getCandL1Jet() const { return m_candL1Jet; }
0160 
0161     /// pointer to Tau data list
0162     inline const BXVector<const l1t::L1Candidate*>* getCandL1Tau() const { return m_candL1Tau; }
0163 
0164     /// pointer to Tau data list
0165     inline const BXVector<const l1t::EtSum*>* getCandL1EtSum() const { return m_candL1EtSum; }
0166 
0167     /// pointer to Tau data list
0168     inline const BXVector<const GlobalExtBlk*>* getCandL1External() const { return m_candL1External; }
0169 
0170     /*  Drop individual EtSums for Now
0171     /// pointer to ETM data list
0172     inline const l1t::EtSum* getCandL1ETM() const
0173     {
0174         return m_candETM;
0175     }
0176 
0177     /// pointer to ETT data list
0178     inline const l1t::EtSum* getCandL1ETT() const
0179     {
0180         return m_candETT;
0181     }
0182 
0183     /// pointer to HTT data list
0184     inline const l1t::EtSum* getCandL1HTT() const
0185     {
0186         return m_candHTT;
0187     }
0188 
0189     /// pointer to HTM data list
0190     inline const l1t::EtSum* getCandL1HTM() const
0191     {
0192         return m_candHTM;
0193     }
0194 */
0195 
0196     void setBxFirst(int bx);
0197     void setBxLast(int bx);
0198 
0199     void setResetPSCountersEachLumiSec(bool val) { m_resetPSCountersEachLumiSec = val; }
0200     void setSemiRandomInitialPSCounters(bool val) { m_semiRandomInitialPSCounters = val; }
0201 
0202   public:
0203     inline void setVerbosity(const int verbosity) { m_verbosity = verbosity; }
0204 
0205   private:
0206     // cached stuff
0207 
0208     // trigger menu
0209     const TriggerMenu* m_l1GtMenu;
0210     unsigned long long m_l1GtMenuCacheID;
0211 
0212     // L1 scales (phi, eta) for Mu, Calo and EnergySum objects
0213     const L1CaloGeometry* m_l1CaloGeometry;
0214     unsigned long long m_l1CaloGeometryCacheID;
0215 
0216     const L1MuTriggerScales* m_l1MuTriggerScales;
0217     unsigned long long m_l1MuTriggerScalesCacheID;
0218 
0219     // conversions for eta and phi
0220     //    L1GtEtaPhiConversions* m_gtEtaPhiConversions;
0221 
0222   private:
0223     BXVector<const l1t::Muon*>* m_candL1Mu;
0224     BXVector<const l1t::MuonShower*>* m_candL1MuShower;
0225     BXVector<const l1t::L1Candidate*>* m_candL1EG;
0226     BXVector<const l1t::L1Candidate*>* m_candL1Tau;
0227     BXVector<const l1t::L1Candidate*>* m_candL1Jet;
0228     BXVector<const l1t::EtSum*>* m_candL1EtSum;
0229     BXVector<const GlobalExtBlk*>* m_candL1External;
0230 
0231     //    BXVector<const l1t::EtSum*>* m_candETM;
0232     //    BXVector<const l1t::EtSum*>* m_candETT;
0233     //    BXVector<const l1t::EtSum*>* m_candHTM;
0234     //    BXVector<const l1t::EtSum*>* m_candHTT;
0235 
0236     int m_bxFirst_;
0237     int m_bxLast_;
0238 
0239     std::bitset<GlobalAlgBlk::maxPhysicsTriggers> m_gtlAlgorithmOR;
0240     std::bitset<GlobalAlgBlk::maxPhysicsTriggers> m_gtlDecisionWord;
0241 
0242     GlobalAlgBlk m_uGtAlgBlk;
0243 
0244     // cache of maps
0245     std::vector<AlgorithmEvaluation::ConditionEvaluationMap> m_conditionResultMaps;
0246 
0247     unsigned int m_currentLumi;
0248 
0249   private:
0250     /// verbosity level
0251     int m_verbosity;
0252     bool m_isDebugEnabled;
0253 
0254     // Flags for the OR of all algorithms at various stages. (Single bx)
0255     bool m_algInitialOr;
0256     bool m_algIntermOr;
0257     bool m_algPrescaledOr;
0258     bool m_algFinalOr;
0259     bool m_algFinalOrVeto;
0260 
0261     // Counter for number of events seen by this board
0262     unsigned int m_boardEventCount;
0263 
0264     // Information about board
0265     int m_uGtBoardNumber;
0266     bool m_uGtFinalBoard;
0267 
0268     // whether we reset the prescales each lumi or not
0269     bool m_resetPSCountersEachLumiSec = false;
0270 
0271     // start the PS counter from a random value between [1,PS] instead of PS
0272     bool m_semiRandomInitialPSCounters = false;
0273 
0274     // step-size in prescale counter corresponding to 10^p,
0275     // where p is the precision allowed for non-integer prescales;
0276     // since the introduction of L1T fractional prescales, p == 2
0277     static constexpr size_t m_singlestep = 100;
0278 
0279     // struct to increment the prescale according to fractional prescale logic in firmware
0280     struct PrescaleCounter {
0281       size_t const prescale_count;
0282       size_t trigger_counter;
0283 
0284       PrescaleCounter(double prescale, size_t const initial_counter = 0)
0285           : prescale_count(std::lround(prescale * m_singlestep)), trigger_counter(initial_counter) {
0286         if (prescale_count != 0 and (prescale_count < m_singlestep or prescale < 0)) {
0287           throw cms::Exception("PrescaleCounterConstructor")
0288               << "invalid initialisation of PrescaleCounter: prescale = " << prescale
0289               << ", prescale_count = " << prescale_count << " (< " << m_singlestep << " = m_singlestep)";
0290         }
0291       }
0292 
0293       // function to increment the prescale counter and return the decision
0294       bool accept();
0295     };
0296 
0297     // prescale counters: NumberPhysTriggers counters per bunch cross in event
0298     std::vector<std::vector<PrescaleCounter>> m_prescaleCounterAlgoTrig;
0299 
0300     // create prescale counters, initialising trigger_counter to zero
0301     static std::vector<PrescaleCounter> prescaleCounters(std::vector<double> const& prescaleFactorsAlgoTrig);
0302 
0303     // create prescale counters, initialising trigger_counter to a semirandom number between 0 and prescale_count - 1 inclusive
0304     static std::vector<PrescaleCounter> prescaleCountersWithSemirandomInitialCounter(
0305         std::vector<double> const& prescaleFactorsAlgoTrig, edm::Event const& iEvent);
0306   };
0307 
0308 }  // namespace l1t
0309 
0310 #endif