Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-05-27 01:56:22

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