Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:29

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