Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:10:22

0001 // C++ headers
0002 #include <cstring>
0003 #include <string>
0004 
0005 // CMSSW headers
0006 #include "CondFormats/DataRecord/interface/L1TUtmTriggerMenuRcd.h"
0007 #include "CondFormats/L1TObjects/interface/L1TUtmTriggerMenu.h"
0008 #include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h"
0009 #include "DQMServices/Core/interface/DQMStore.h"
0010 #include "DataFormats/Common/interface/Handle.h"
0011 #include "DataFormats/Common/interface/TriggerResults.h"
0012 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0013 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0014 #include "FWCore/Framework/interface/ESHandle.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018 #include "FWCore/Framework/interface/LuminosityBlock.h"
0019 #include "FWCore/Framework/interface/Run.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0024 #include "FWCore/ParameterSet/interface/Registry.h"
0025 #include "FWCore/ServiceRegistry/interface/Service.h"
0026 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0027 
0028 namespace {
0029   typedef dqm::reco::DQMStore DQMStore;
0030   typedef dqm::reco::MonitorElement MonitorElement;
0031 
0032   struct RunBasedHistograms {
0033     dqm::reco::MonitorElement* orbit_bx_all;
0034     std::vector<dqm::reco::MonitorElement*> orbit_bx;
0035     std::vector<dqm::reco::MonitorElement*> orbit_bx_all_byLS;
0036   };
0037 }  // namespace
0038 
0039 class TriggerBxVsOrbitMonitor : public DQMGlobalEDAnalyzer<RunBasedHistograms> {
0040 public:
0041   explicit TriggerBxVsOrbitMonitor(edm::ParameterSet const&);
0042   ~TriggerBxVsOrbitMonitor() override = default;
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046 private:
0047   void dqmBeginRun(edm::Run const&, edm::EventSetup const&, RunBasedHistograms&) const override;
0048   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&, RunBasedHistograms&) const override;
0049   void dqmAnalyze(edm::Event const&, edm::EventSetup const&, RunBasedHistograms const&) const override;
0050 
0051   // number of bunch crossings
0052   static const unsigned int s_bx_range = 3564;
0053   static const unsigned int s_orbit_range = 262144;  // 2**18 orbits in 1 LS
0054 
0055   // TCDS trigger types
0056   // see https://twiki.cern.ch/twiki/bin/viewauth/CMS/TcdsEventRecord
0057   static constexpr const char* const s_tcds_trigger_types[] = {
0058       "Empty",          //  0 - No trigger
0059       "Physics",        //  1 - GT trigger
0060       "Calibration",    //  2 - Sequence trigger (calibration)
0061       "Random",         //  3 - Random trigger
0062       "Auxiliary",      //  4 - Auxiliary (CPM front panel NIM input) trigger
0063       nullptr,          //  5 - reserved
0064       nullptr,          //  6 - reserved
0065       nullptr,          //  7 - reserved
0066       "Cyclic",         //  8 - Cyclic trigger
0067       "Bunch-pattern",  //  9 - Bunch-pattern trigger
0068       "Software",       // 10 - Software trigger
0069       "TTS",            // 11 - TTS-sourced trigger
0070       nullptr,          // 12 - reserved
0071       nullptr,          // 13 - reserved
0072       nullptr,          // 14 - reserved
0073       nullptr           // 15 - reserved
0074   };
0075 
0076   // module configuration
0077   const edm::EDGetTokenT<GlobalAlgBlkBxCollection> m_l1t_results;
0078   const edm::EDGetTokenT<edm::TriggerResults> m_hlt_results;
0079   const std::string m_dqm_path;
0080   const int m_minLS;
0081   const int m_maxLS;
0082   const int m_minBX;
0083   const int m_maxBX;
0084 };
0085 
0086 // definition
0087 constexpr const char* const TriggerBxVsOrbitMonitor::s_tcds_trigger_types[];
0088 
0089 void TriggerBxVsOrbitMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0090   edm::ParameterSetDescription desc;
0091   desc.addUntracked<edm::InputTag>("l1tResults", edm::InputTag("gtStage2Digis"));
0092   desc.addUntracked<edm::InputTag>("hltResults", edm::InputTag("TriggerResults"));
0093   desc.addUntracked<std::string>("dqmPath", "HLT/TriggerBx");
0094   desc.addUntracked<int>("minLS", 134);
0095   desc.addUntracked<int>("maxLS", 136);
0096   desc.addUntracked<int>("minBX", 894);
0097   desc.addUntracked<int>("maxBX", 912);
0098   descriptions.add("triggerBxVsOrbitMonitor", desc);
0099 }
0100 
0101 TriggerBxVsOrbitMonitor::TriggerBxVsOrbitMonitor(edm::ParameterSet const& config)
0102     :  // module configuration
0103       m_l1t_results(consumes<GlobalAlgBlkBxCollection>(config.getUntrackedParameter<edm::InputTag>("l1tResults"))),
0104       m_hlt_results(consumes<edm::TriggerResults>(config.getUntrackedParameter<edm::InputTag>("hltResults"))),
0105       m_dqm_path(config.getUntrackedParameter<std::string>("dqmPath")),
0106       m_minLS(config.getUntrackedParameter<int>("minLS")),
0107       m_maxLS(config.getUntrackedParameter<int>("maxLS")),
0108       m_minBX(config.getUntrackedParameter<int>("minBX")),
0109       m_maxBX(config.getUntrackedParameter<int>("maxBX")) {}
0110 
0111 void TriggerBxVsOrbitMonitor::dqmBeginRun(edm::Run const& run,
0112                                           edm::EventSetup const& setup,
0113                                           RunBasedHistograms& histograms) const {
0114   size_t nLS = m_maxLS - m_minLS + 1;
0115 
0116   histograms.orbit_bx_all_byLS.clear();
0117   histograms.orbit_bx_all_byLS.resize(nLS);
0118 
0119   histograms.orbit_bx.clear();
0120   histograms.orbit_bx.resize(std::size(s_tcds_trigger_types));
0121 }
0122 
0123 void TriggerBxVsOrbitMonitor::bookHistograms(DQMStore::IBooker& booker,
0124                                              edm::Run const& run,
0125                                              edm::EventSetup const& setup,
0126                                              RunBasedHistograms& histograms) const {
0127   // TCDS trigger type plots
0128   size_t size = std::size(s_tcds_trigger_types);
0129   size_t nLS = m_maxLS - m_minLS + 1;
0130   size_t nBX = m_maxBX - m_minBX + 1;
0131 
0132   // book 2D histogram to monitor all TCDS trigger types in a single plot
0133   booker.setCurrentFolder(m_dqm_path + "/orbitVsBX");
0134   histograms.orbit_bx_all = booker.book2D("OrbitVsBX",
0135                                           "Event orbits vs. bunch crossing",
0136                                           nBX,
0137                                           m_minBX - 0.5,
0138                                           m_maxBX + 0.5,
0139                                           s_orbit_range + 1,
0140                                           -0.5,
0141                                           s_orbit_range + 0.5);
0142   histograms.orbit_bx_all->setXTitle("BX");
0143   histograms.orbit_bx_all->setYTitle("orbit");
0144 
0145   for (unsigned int i = 0; i < nLS; ++i) {
0146     std::string iname = std::to_string(i);
0147     histograms.orbit_bx_all_byLS[i] = booker.book2D("OrbitVsBX_LS" + iname,
0148                                                     "Event orbits vs. bunch crossing, for lumisection " + iname,
0149                                                     nBX,
0150                                                     m_minBX - 0.5,
0151                                                     m_maxBX + 0.5,
0152                                                     s_orbit_range + 1,
0153                                                     -0.5,
0154                                                     s_orbit_range + 0.5);
0155     histograms.orbit_bx_all_byLS[i]->setXTitle("BX");
0156     histograms.orbit_bx_all_byLS[i]->setYTitle("orbit");
0157   }
0158 
0159   booker.setCurrentFolder(m_dqm_path + "/orbitVsBX/TCDS");
0160   for (unsigned int i = 0; i < size; ++i) {
0161     if (s_tcds_trigger_types[i]) {
0162       histograms.orbit_bx[i] = booker.book2D("OrbitVsBX_" + std::string(s_tcds_trigger_types[i]),
0163                                              "Event orbits vs. bunch crossing " + std::string(s_tcds_trigger_types[i]),
0164                                              nBX,
0165                                              m_minBX - 0.5,
0166                                              m_maxBX + 0.5,
0167                                              s_orbit_range + 1,
0168                                              -0.5,
0169                                              s_orbit_range + 0.5);
0170       histograms.orbit_bx[i]->setXTitle("BX");
0171       histograms.orbit_bx[i]->setYTitle("orbit");
0172     }
0173   }
0174 }
0175 
0176 void TriggerBxVsOrbitMonitor::dqmAnalyze(edm::Event const& event,
0177                                          edm::EventSetup const& setup,
0178                                          RunBasedHistograms const& histograms) const {
0179   unsigned int type = event.experimentType();
0180   unsigned int ls = event.id().luminosityBlock();
0181   unsigned int orbit = event.orbitNumber() % s_orbit_range;
0182   unsigned int bx = event.bunchCrossing();
0183   histograms.orbit_bx_all->Fill(bx, orbit);
0184 
0185   int iLS = ls - m_minLS;
0186   if (iLS >= 0 and iLS < int(histograms.orbit_bx_all_byLS.size()))
0187     histograms.orbit_bx_all_byLS[iLS]->Fill(bx, orbit);
0188 
0189   // monitor the bx distribution for the TCDS trigger types
0190   size_t size = std::size(s_tcds_trigger_types);
0191   if (type < size and histograms.orbit_bx[type]) {
0192     histograms.orbit_bx[type]->Fill(bx, orbit);
0193   }
0194 }
0195 
0196 //define this as a plug-in
0197 #include "FWCore/Framework/interface/MakerMacros.h"
0198 DEFINE_FWK_MODULE(TriggerBxVsOrbitMonitor);