Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/ServiceRegistry/interface/Service.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/Common/interface/TriggerNames.h"
0008 #include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h"
0009 #include "DataFormats/Common/interface/TriggerResults.h"
0010 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0011 
0012 #include "TrigObjTnPHistColl.h"
0013 
0014 class TrigObjTnPSource : public DQMGlobalEDAnalyzer<std::vector<TrigObjTnPHistColl>> {
0015 public:
0016   explicit TrigObjTnPSource(const edm::ParameterSet&);
0017   ~TrigObjTnPSource() override = default;
0018   TrigObjTnPSource(const TrigObjTnPSource&) = delete;
0019   TrigObjTnPSource& operator=(const TrigObjTnPSource&) = delete;
0020 
0021   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0022 
0023   void dqmAnalyze(const edm::Event&, const edm::EventSetup&, const std::vector<TrigObjTnPHistColl>&) const override;
0024   void bookHistograms(DQMStore::IBooker&,
0025                       const edm::Run&,
0026                       const edm::EventSetup&,
0027                       std::vector<TrigObjTnPHistColl>&) const override;
0028   void dqmBeginRun(const edm::Run&, const edm::EventSetup&, std::vector<TrigObjTnPHistColl>&) const override;
0029 
0030 private:
0031   edm::EDGetTokenT<trigger::TriggerEvent> trigEvtToken_;
0032   edm::EDGetTokenT<edm::TriggerResults> trigResultsToken_;
0033   std::string hltProcess_;
0034   //it would be more memory efficient to save this as a vector of TrigTnPHistColls and then use this to instance
0035   //the TrigTnPHistColls for each run, something to do for the future
0036   std::vector<edm::ParameterSet> histCollConfigs_;
0037 };
0038 
0039 TrigObjTnPSource::TrigObjTnPSource(const edm::ParameterSet& config)
0040     : trigEvtToken_(consumes<trigger::TriggerEvent>(config.getParameter<edm::InputTag>("triggerEvent"))),
0041       trigResultsToken_(consumes<edm::TriggerResults>(config.getParameter<edm::InputTag>("triggerResults"))),
0042       hltProcess_(config.getParameter<edm::InputTag>("triggerResults").process()),
0043       histCollConfigs_(config.getParameter<std::vector<edm::ParameterSet>>("histColls")) {}
0044 
0045 void TrigObjTnPSource::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0046   edm::ParameterSetDescription desc;
0047   desc.add<edm::InputTag>("triggerEvent", edm::InputTag("hltTriggerSummaryAOD::HLT"));
0048   desc.add<edm::InputTag>("triggerResults", edm::InputTag("TriggerResults::HLT"));
0049   desc.addVPSet("histColls", TrigObjTnPHistColl::makePSetDescription(), std::vector<edm::ParameterSet>());
0050   descriptions.add("trigObjTnPSource", desc);
0051 }
0052 
0053 void TrigObjTnPSource::bookHistograms(DQMStore::IBooker& iBooker,
0054                                       const edm::Run& run,
0055                                       const edm::EventSetup& setup,
0056                                       std::vector<TrigObjTnPHistColl>& tnpHistColls) const {
0057   tnpHistColls.clear();
0058   HLTConfigProvider hltConfig;
0059   bool hltChanged = false;
0060   hltConfig.init(run, setup, hltProcess_, hltChanged);
0061   for (auto& histCollConfig : histCollConfigs_)
0062     tnpHistColls.emplace_back(TrigObjTnPHistColl(histCollConfig));
0063   for (auto& histColl : tnpHistColls) {
0064     histColl.init(hltConfig);
0065     histColl.bookHists(iBooker);
0066   }
0067 }
0068 
0069 void TrigObjTnPSource::dqmBeginRun(const edm::Run& run,
0070                                    const edm::EventSetup& setup,
0071                                    std::vector<TrigObjTnPHistColl>& tnpHistColls) const {}
0072 
0073 void TrigObjTnPSource::dqmAnalyze(const edm::Event& event,
0074                                   const edm::EventSetup& setup,
0075                                   const std::vector<TrigObjTnPHistColl>& tnpHistColls) const {
0076   edm::Handle<trigger::TriggerEvent> trigEvtHandle;
0077   event.getByToken(trigEvtToken_, trigEvtHandle);
0078   edm::Handle<edm::TriggerResults> trigResultsHandle;
0079   event.getByToken(trigResultsToken_, trigResultsHandle);
0080   //DQM should never crash the HLT under any circumstances (except at configure)
0081   if (trigEvtHandle.isValid() && trigResultsHandle.isValid()) {
0082     for (auto& histColl : tnpHistColls) {
0083       histColl.fill(*trigEvtHandle, *trigResultsHandle, event.triggerNames(*trigResultsHandle));
0084     }
0085   }
0086 }
0087 
0088 DEFINE_FWK_MODULE(TrigObjTnPSource);