Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-24 22:51:28

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