Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // L1TGlobalUtil:  Utility class for parsing the L1 Trigger Menu
0002 
0003 #ifndef L1TGlobal_L1TGlobalUtil_h
0004 #define L1TGlobal_L1TGlobalUtil_h
0005 
0006 // system include files
0007 #include <memory>
0008 
0009 #include <vector>
0010 
0011 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0012 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0013 
0014 #include "CondFormats/DataRecord/interface/L1TGlobalPrescalesVetosFractRcd.h"
0015 #include "CondFormats/L1TObjects/interface/L1TGlobalPrescalesVetosFract.h"
0016 
0017 // Objects to produce for the output record.
0018 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0019 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0020 #include "CondFormats/L1TObjects/interface/L1TUtmAlgorithm.h"
0021 
0022 #include "FWCore/Framework/interface/ConsumesCollector.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Utilities/interface/ESGetToken.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026 
0027 #include "FWCore/Framework/interface/EventSetup.h"
0028 
0029 #include "L1Trigger/L1TGlobal/interface/L1TGlobalUtilHelper.h"
0030 
0031 #include "L1Trigger/L1TGlobal/interface/PrescalesVetosFractHelper.h"
0032 
0033 // forward declarations
0034 
0035 // class declaration
0036 
0037 namespace l1t {
0038 
0039   // Use this to tell the EventSetup whether it should prefetch
0040   // data when processing beginRun or an Event or both. (This
0041   // depends on when retrieveL1 and retrieveL1Setup are called)
0042   enum class UseEventSetupIn { Run, Event, RunAndEvent };
0043 
0044   class L1TGlobalUtil {
0045   public:
0046     // Using this constructor will require InputTags to be specified in the configuration
0047     L1TGlobalUtil(edm::ParameterSet const& pset,
0048                   edm::ConsumesCollector&& iC,
0049                   UseEventSetupIn use = UseEventSetupIn::Run);
0050 
0051     L1TGlobalUtil(edm::ParameterSet const& pset,
0052                   edm::ConsumesCollector& iC,
0053                   UseEventSetupIn use = UseEventSetupIn::Run);
0054 
0055     // Using this constructor will cause it to look for valid InputTags in
0056     // the following ways in the specified order until they are found.
0057     //   1. The configuration
0058     //   2. Search all products from the preferred input tags for the required type
0059     //   3. Search all products from any other process for the required type
0060     template <typename T>
0061     L1TGlobalUtil(edm::ParameterSet const& pset,
0062                   edm::ConsumesCollector&& iC,
0063                   T& module,
0064                   UseEventSetupIn use = UseEventSetupIn::Run);
0065 
0066     template <typename T>
0067     L1TGlobalUtil(edm::ParameterSet const& pset,
0068                   edm::ConsumesCollector& iC,
0069                   T& module,
0070                   UseEventSetupIn use = UseEventSetupIn::Run);
0071 
0072     // Using this constructor will cause it to look for valid InputTags in
0073     // the following ways in the specified order until they are found.
0074     //   1. The constructor arguments
0075     //   2. The configuration
0076     //   3. Search all products from the preferred input tags for the required type
0077     //   4. Search all products from any other process for the required type
0078     template <typename T>
0079     L1TGlobalUtil(edm::ParameterSet const& pset,
0080                   edm::ConsumesCollector&& iC,
0081                   T& module,
0082                   edm::InputTag const& l1tAlgBlkInputTag,
0083                   edm::InputTag const& l1tExtBlkInputTag,
0084                   UseEventSetupIn use = UseEventSetupIn::Run);
0085 
0086     template <typename T>
0087     L1TGlobalUtil(edm::ParameterSet const& pset,
0088                   edm::ConsumesCollector& iC,
0089                   T& module,
0090                   edm::InputTag const& l1tAlgBlkInputTag,
0091                   edm::InputTag const& l1tExtBlkInputTag,
0092                   UseEventSetupIn use = UseEventSetupIn::Run);
0093 
0094     /// destructor
0095     virtual ~L1TGlobalUtil();
0096 
0097     /// check that the L1TGlobalUtil has been properly initialised
0098     bool valid() const;
0099 
0100     static void fillDescription(edm::ParameterSetDescription& desc,
0101                                 edm::InputTag const& iAlg,
0102                                 edm::InputTag const& iExt,
0103                                 bool readPrescalesFromFile) {
0104       L1TGlobalUtilHelper::fillDescription(desc, iAlg, iExt, readPrescalesFromFile);
0105     }
0106 
0107     // OverridePrescalesAndMasks
0108     // The ability to override the prescale/mask file will not be part of the permanent interface of this class.
0109     // It is provided only until prescales and masks are available as CondFormats...
0110     // Most users should simply ignore this method and use the default ctor only!
0111     // Will look for prescale csv file in L1Trigger/L1TGlobal/data/Luminosity/startup/<filename>
0112     void OverridePrescalesAndMasks(std::string filename, unsigned int psColumn = 1.);
0113 
0114     /// initialize the class (mainly reserve)
0115     void retrieveL1(const edm::Event& iEvent, const edm::EventSetup& evSetup);  // using helper
0116     void retrieveL1(const edm::Event& iEvent, const edm::EventSetup& evSetup, edm::EDGetToken gtAlgToken);
0117     void retrieveL1Setup(const edm::EventSetup& evSetup);  // Use this one only during beginRun
0118     void retrieveL1Event(const edm::Event& iEvent, const edm::EventSetup& evSetup);  // using helper
0119     void retrieveL1Event(const edm::Event& iEvent, const edm::EventSetup& evSetup, edm::EDGetToken gtAlgToken);
0120 
0121     inline void setVerbosity(const int verbosity) { m_verbosity = verbosity; }
0122 
0123     inline bool getFinalOR() const { return m_finalOR; }
0124 
0125     // get the trigger bit from the name
0126     const bool getAlgBitFromName(const std::string& AlgName, int& bit) const;
0127 
0128     // get the name from the trigger bit
0129     const bool getAlgNameFromBit(int& bit, std::string& AlgName) const;
0130 
0131     // Access results for particular trigger bit
0132     const bool getInitialDecisionByBit(int& bit, bool& decision) const;
0133     const bool getIntermDecisionByBit(int& bit, bool& decision) const;
0134     const bool getFinalDecisionByBit(int& bit, bool& decision) const;
0135 
0136     // Access Prescale
0137     const bool getPrescaleByBit(int& bit, double& prescale) const;
0138 
0139     // Access Masks:
0140     // follows logic of uGT board:
0141     //       finalDecision[AlgBit]
0142     //           Final word is after application of prescales.
0143     //           A prescale = 0 effectively masks out the algorithm in the final decision word
0144     //
0145     const bool getMaskByBit(int& bit, std::vector<int>& mask) const;
0146 
0147     // Access results for particular trigger name
0148     const bool getInitialDecisionByName(const std::string& algName, bool& decision) const;
0149     const bool getIntermDecisionByName(const std::string& algName, bool& decision) const;
0150     const bool getFinalDecisionByName(const std::string& algName, bool& decision) const;
0151 
0152     // Access Prescales
0153     const bool getPrescaleByName(const std::string& algName, double& prescale) const;
0154 
0155     // Access Masks (see note) above
0156     const bool getMaskByName(const std::string& algName, std::vector<int>& mask) const;
0157 
0158     // Some inline commands to return the full vectors
0159     inline const std::vector<std::pair<std::string, bool>>& decisionsInitial() { return m_decisionsInitial; }
0160     inline const std::vector<std::pair<std::string, bool>>& decisionsInterm() { return m_decisionsInterm; }
0161     inline const std::vector<std::pair<std::string, bool>>& decisionsFinal() { return m_decisionsFinal; }
0162 
0163     // Access all prescales
0164     inline const std::vector<std::pair<std::string, double>>& prescales() { return m_prescales; }
0165 
0166     // Access Masks (see note) above
0167     inline const std::vector<std::pair<std::string, std::vector<int>>>& masks() { return m_masks; }
0168 
0169     // Menu names
0170     inline const std::string& gtTriggerMenuName() const { return m_l1GtMenu->getName(); }
0171     inline const std::string& gtTriggerMenuVersion() const { return m_l1GtMenu->getVersion(); }
0172     inline const std::string& gtTriggerMenuComment() const { return m_l1GtMenu->getComment(); }
0173 
0174     // Prescale Column
0175     inline unsigned int prescaleColumn() const { return m_PreScaleColumn; }
0176     inline unsigned int numberOfPreScaleColumns() const { return m_numberOfPreScaleColumns; }
0177 
0178   private:
0179     L1TGlobalUtil();
0180 
0181     void retrieveL1Setup(const edm::EventSetup& evSetup, bool isRun);
0182     void eventSetupConsumes(edm::ConsumesCollector& iC, UseEventSetupIn useEventSetupIn);
0183 
0184     /// clear decision vectors on a menu change
0185     void resetDecisionVectors();
0186     void resetPrescaleVectors();
0187     void resetMaskVectors();
0188     void loadPrescalesAndMasks();
0189 
0190     // trigger menu
0191     const L1TUtmTriggerMenu* m_l1GtMenu;
0192     unsigned long long m_l1GtMenuCacheID;
0193 
0194     // prescale factors
0195     bool m_readPrescalesFromFile;
0196     const l1t::PrescalesVetosFractHelper* m_l1GtPrescalesVetoes;
0197     unsigned long long m_l1GtPfAlgoCacheID;
0198 
0199     // prescales and masks
0200     bool m_filledPrescales;
0201 
0202     // algorithm maps
0203     //const AlgorithmMap* m_algorithmMap;
0204     const std::map<std::string, L1TUtmAlgorithm>* m_algorithmMap;
0205 
0206     // Number of physics triggers
0207     unsigned int m_numberPhysTriggers;
0208     const unsigned int m_maxNumberPhysTriggers = 512;
0209 
0210     //file  and container for prescale factors
0211     std::string m_preScaleFileName;
0212     unsigned int m_PreScaleColumn;
0213     unsigned int m_numberOfPreScaleColumns;
0214 
0215     std::vector<std::vector<double>> m_initialPrescaleFactorsAlgoTrig;
0216     const std::vector<std::vector<double>>* m_prescaleFactorsAlgoTrig;
0217     const std::map<int, std::vector<int>> m_initialTriggerMaskAlgoTrig;
0218     const std::map<int, std::vector<int>>* m_triggerMaskAlgoTrig;  // vector stores the BX
0219 
0220     // access to the results block from uGT
0221     edm::Handle<BXVector<GlobalAlgBlk>> m_uGtAlgBlk;
0222 
0223     // final OR
0224     bool m_finalOR;
0225 
0226     // Vectors containing the trigger name and information about that trigger
0227     std::vector<std::pair<std::string, bool>> m_decisionsInitial;
0228     std::vector<std::pair<std::string, bool>> m_decisionsInterm;
0229     std::vector<std::pair<std::string, bool>> m_decisionsFinal;
0230     std::vector<std::pair<std::string, double>> m_prescales;
0231     std::vector<std::pair<std::string, std::vector<int>>> m_masks;  // vector stores the bx's that are mask for given algo
0232 
0233     /// verbosity level
0234     int m_verbosity;
0235 
0236     std::unique_ptr<L1TGlobalUtilHelper> m_l1tGlobalUtilHelper;
0237 
0238     edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> m_L1TUtmTriggerMenuRunToken;
0239     edm::ESGetToken<L1TGlobalPrescalesVetosFract, L1TGlobalPrescalesVetosFractRcd>
0240         m_L1TGlobalPrescalesVetosFractRunToken;
0241 
0242     edm::ESGetToken<L1TUtmTriggerMenu, L1TUtmTriggerMenuRcd> m_L1TUtmTriggerMenuEventToken;
0243     edm::ESGetToken<L1TGlobalPrescalesVetosFract, L1TGlobalPrescalesVetosFractRcd>
0244         m_L1TGlobalPrescalesVetosFractEventToken;
0245   };
0246 
0247   template <typename T>
0248   L1TGlobalUtil::L1TGlobalUtil(edm::ParameterSet const& pset,
0249                                edm::ConsumesCollector&& iC,
0250                                T& module,
0251                                UseEventSetupIn useEventSetupIn)
0252       : L1TGlobalUtil(pset, iC, module, useEventSetupIn) {}
0253 
0254   template <typename T>
0255   L1TGlobalUtil::L1TGlobalUtil(edm::ParameterSet const& pset,
0256                                edm::ConsumesCollector& iC,
0257                                T& module,
0258                                UseEventSetupIn useEventSetupIn)
0259       : L1TGlobalUtil() {
0260     m_l1tGlobalUtilHelper = std::make_unique<L1TGlobalUtilHelper>(pset, iC, module);
0261     m_readPrescalesFromFile = m_l1tGlobalUtilHelper->readPrescalesFromFile();
0262     eventSetupConsumes(iC, useEventSetupIn);
0263   }
0264 
0265   template <typename T>
0266   L1TGlobalUtil::L1TGlobalUtil(edm::ParameterSet const& pset,
0267                                edm::ConsumesCollector&& iC,
0268                                T& module,
0269                                edm::InputTag const& l1tAlgBlkInputTag,
0270                                edm::InputTag const& l1tExtBlkInputTag,
0271                                UseEventSetupIn useEventSetupIn)
0272       : L1TGlobalUtil(pset, iC, module, l1tAlgBlkInputTag, l1tExtBlkInputTag, useEventSetupIn) {}
0273 
0274   template <typename T>
0275   L1TGlobalUtil::L1TGlobalUtil(edm::ParameterSet const& pset,
0276                                edm::ConsumesCollector& iC,
0277                                T& module,
0278                                edm::InputTag const& l1tAlgBlkInputTag,
0279                                edm::InputTag const& l1tExtBlkInputTag,
0280                                UseEventSetupIn useEventSetupIn)
0281       : L1TGlobalUtil() {
0282     m_l1tGlobalUtilHelper =
0283         std::make_unique<L1TGlobalUtilHelper>(pset, iC, module, l1tAlgBlkInputTag, l1tExtBlkInputTag);
0284     m_readPrescalesFromFile = m_l1tGlobalUtilHelper->readPrescalesFromFile();
0285     eventSetupConsumes(iC, useEventSetupIn);
0286   }
0287 }  // namespace l1t
0288 #endif