Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-31 23:13:57

0001 #ifndef L1TBPTX_H
0002 #define L1TBPTX_H
0003 
0004 /*
0005  * \file L1TBPTX.h
0006  *
0007  * \author J. Pela
0008  *
0009 */
0010 
0011 // system include files
0012 #include <memory>
0013 #include <unistd.h>
0014 
0015 // user include files
0016 #include "FWCore/Framework/interface/Frameworkfwd.h"
0017 
0018 #include "FWCore/Framework/interface/ESHandle.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/LuminosityBlock.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 
0025 #include "DQMServices/Core/interface/DQMStore.h"
0026 #include "FWCore/ServiceRegistry/interface/Service.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 
0029 #include "DQM/L1TMonitor/interface/L1TOMDSHelper.h"
0030 
0031 //Data Formats
0032 #include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
0033 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0034 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
0035 
0036 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0037 
0038 #include <TString.h>
0039 
0040 #include <iostream>
0041 #include <fstream>
0042 #include <string>
0043 #include <vector>
0044 
0045 class RateBuffer {
0046 public:
0047   void fill(int ls, bool isAlgo, int bit, double rate) {
0048     if (isAlgo) {
0049       m_lsAlgoRate[std::pair<int, int>(ls, bit)] = rate;
0050     } else {
0051       m_lsTechRate[std::pair<int, int>(ls, bit)] = rate;
0052     }
0053   }
0054   double getLSRate(int ls, bool isAlgo, int bit, double rate) {
0055     if (isAlgo) {
0056       return m_lsAlgoRate[std::pair<int, int>(ls, bit)];
0057     } else {
0058       return m_lsTechRate[std::pair<int, int>(ls, bit)];
0059     }
0060   }
0061   double getLSAlgoRate(int ls, int bit, double rate) { return m_lsAlgoRate[std::pair<int, int>(ls, bit)]; }
0062   double getLSTechRate(int ls, int bit, double rate) { return m_lsTechRate[std::pair<int, int>(ls, bit)]; }
0063 
0064 private:
0065   std::map<std::pair<int, int>, double> m_lsAlgoRate;
0066   std::map<std::pair<int, int>, double> m_lsTechRate;
0067 };
0068 
0069 class L1GtTriggerMenu;
0070 class L1GtTriggerMenuRcd;
0071 class L1GtPrescaleFactors;
0072 class L1GtPrescaleFactorsAlgoTrigRcd;
0073 class L1GtPrescaleFactorsTechTrigRcd;
0074 
0075 class L1TBPTX : public DQMOneEDAnalyzer<edm::one::WatchLuminosityBlocks> {
0076 public:
0077   enum BeamMode {
0078     NOMODE = 1,
0079     SETUP = 2,
0080     INJPILOT = 3,
0081     INJINTR = 4,
0082     INJNOMN = 5,
0083     PRERAMP = 6,
0084     RAMP = 7,
0085     FLATTOP = 8,
0086     SQUEEZE = 9,
0087     ADJUST = 10,
0088     STABLE = 11,
0089     UNSTABLE = 12,
0090     BEAMDUMP = 13,
0091     RAMPDOWN = 14,
0092     RECOVERY = 15,
0093     INJDUMP = 16,
0094     CIRCDUMP = 17,
0095     ABORT = 18,
0096     CYCLING = 19,
0097     WBDUMP = 20,
0098     NOBEAM = 21
0099   };
0100 
0101   enum Errors {
0102     UNKNOWN = 1,
0103     WARNING_DB_CONN_FAILED = 2,
0104     WARNING_DB_QUERY_FAILED = 3,
0105     WARNING_DB_INCORRECT_NBUNCHES = 4,
0106     ERROR_UNABLE_RETRIVE_PRODUCT = 5,
0107     ERROR_TRIGGERALIAS_NOTVALID = 6,
0108     ERROR_LSBLOCK_NOTVALID = 7
0109   };
0110 
0111 public:
0112   L1TBPTX(const edm::ParameterSet& ps);  // Constructor
0113   ~L1TBPTX() override;                   // Destructor
0114 
0115 protected:
0116   void analyze(const edm::Event& e, const edm::EventSetup& c) override;  // Analyze
0117   void bookHistograms(DQMStore::IBooker& ibooker, const edm::Run&, const edm::EventSetup&) override;
0118   void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
0119 
0120   void beginLuminosityBlock(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& c) override;
0121   void endLuminosityBlock(edm::LuminosityBlock const& lumiBlock, edm::EventSetup const& c) override;
0122 
0123   // Private Methods
0124 private:
0125   void getBeamConfOMDS();
0126   void doFractionInSync(bool iForce = false, bool iBad = false);
0127   void certifyLSBlock(std::string iTrigger, int iInitLs, int iEndLs, float iValue);
0128 
0129   // Variables
0130 private:
0131   edm::ParameterSet m_parameters;
0132   std::vector<edm::ParameterSet> m_monitorBits;
0133   std::vector<edm::ParameterSet> m_monitorRates;
0134   std::string m_outputFile;  // file name for ROOT ouput
0135 
0136   // bool
0137   bool m_verbose;
0138   bool m_currentLSValid;
0139   bool* m_processedLS;
0140 
0141   // Int
0142   std::map<TString, int> m_effNumerator;
0143   std::map<TString, int> m_effDenominator;
0144   std::map<TString, int> m_missFireNumerator;
0145   std::map<TString, int> m_missFireDenominator;
0146 
0147   int m_refPrescaleSet;
0148   int m_currentPrescalesIndex;
0149   unsigned int m_currentLS;  // Current LS
0150   unsigned int m_currentGTLS;
0151   //unsigned int                         m_eventLS;
0152   unsigned int m_lhcFill;  //
0153 
0154   // Vectors
0155   BeamConfiguration m_beamConfig;  // Current Bunch Structure
0156   std::vector<std::pair<int, int> > m_selAlgoBit;
0157   std::vector<std::pair<int, int> > m_selTechBit;
0158 
0159   // Const Vectors
0160   const std::vector<std::vector<int> >* m_prescaleFactorsAlgoTrig;
0161   const std::vector<std::vector<int> >* m_prescaleFactorsTechTrig;
0162 
0163   // Maps
0164   std::map<int, TString> m_algoBit_Alias;
0165   std::map<int, TString> m_techBit_Alias;
0166 
0167   std::map<TString, MonitorElement*> m_meAlgoEfficiency;
0168   std::map<TString, MonitorElement*> m_meAlgoMissFire;
0169   std::map<TString, MonitorElement*> m_meTechEfficiency;
0170   std::map<TString, MonitorElement*> m_meTechMissFire;
0171 
0172   std::map<std::pair<bool, int>, MonitorElement*> m_meRate;
0173   std::map<std::pair<bool, int>, double> m_l1Rate;
0174 
0175   // MonitorElement
0176   MonitorElement* m_ErrorMonitor;
0177 
0178   // Input tags
0179   edm::EDGetTokenT<Level1TriggerScalersCollection> m_scalersSource;  // Where to get L1 Scalers
0180   edm::EDGetTokenT<L1GlobalTriggerEvmReadoutRecord> m_l1GtEvmSource;
0181   edm::EDGetTokenT<L1GlobalTriggerReadoutRecord> m_l1GtDataDaqInputTag;
0182   edm::ESGetToken<L1GtTriggerMenu, L1GtTriggerMenuRcd> l1gtMenuToken_;
0183   edm::ESGetToken<L1GtPrescaleFactors, L1GtPrescaleFactorsAlgoTrigRcd> l1GtPfAlgoToken_;
0184   edm::ESGetToken<L1GtPrescaleFactors, L1GtPrescaleFactorsTechTrigRcd> l1GtPfTechToken_;
0185 };
0186 
0187 #endif