File indexing completed on 2022-02-14 23:39:17
0001
0002 #include <atomic>
0003 #include <memory>
0004 #include <cmath>
0005 #include <iostream>
0006 #include <sstream>
0007 #include <fstream>
0008
0009
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/stream/EDFilter.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/Run.h"
0014 #include "FWCore/Framework/interface/LuminosityBlock.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0018 #include "FWCore/Common/interface/TriggerNames.h"
0019
0020 #include "DataFormats/Common/interface/Handle.h"
0021
0022 #include "DataFormats/Common/interface/TriggerResults.h"
0023 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0024
0025
0026
0027
0028
0029
0030 namespace AlCaIsolatedBunch {
0031 struct Counters {
0032 Counters() : nAll_(0), nGood_(0) {}
0033 mutable std::atomic<unsigned int> nAll_, nGood_;
0034 };
0035 }
0036
0037 class AlCaIsolatedBunchSelector : public edm::stream::EDFilter<edm::GlobalCache<AlCaIsolatedBunch::Counters> > {
0038 public:
0039 explicit AlCaIsolatedBunchSelector(edm::ParameterSet const&, const AlCaIsolatedBunch::Counters* count);
0040 ~AlCaIsolatedBunchSelector() override;
0041
0042 static std::unique_ptr<AlCaIsolatedBunch::Counters> initializeGlobalCache(edm::ParameterSet const& iConfig) {
0043 return std::make_unique<AlCaIsolatedBunch::Counters>();
0044 }
0045
0046 bool filter(edm::Event&, edm::EventSetup const&) override;
0047 void endStream() override;
0048 static void globalEndJob(const AlCaIsolatedBunch::Counters* counters);
0049 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0050
0051 private:
0052 void beginRun(edm::Run const&, edm::EventSetup const&) override;
0053 void endRun(edm::Run const&, edm::EventSetup const&) override;
0054
0055
0056 HLTConfigProvider hltConfig_;
0057 unsigned int nRun_, nAll_, nGood_;
0058 const std::string trigName_;
0059 const std::string processName_;
0060 const edm::InputTag theTriggerResultsLabel_;
0061 const edm::EDGetTokenT<edm::TriggerResults> tok_trigRes_;
0062 };
0063
0064
0065
0066
0067 AlCaIsolatedBunchSelector::AlCaIsolatedBunchSelector(const edm::ParameterSet& iConfig,
0068 const AlCaIsolatedBunch::Counters* count)
0069 : nRun_(0),
0070 nAll_(0),
0071 nGood_(0),
0072 trigName_(iConfig.getParameter<std::string>("triggerName")),
0073 processName_(iConfig.getParameter<std::string>("processName")),
0074 theTriggerResultsLabel_(iConfig.getParameter<edm::InputTag>("triggerResultLabel")),
0075 tok_trigRes_(consumes<edm::TriggerResults>(theTriggerResultsLabel_)) {
0076 edm::LogVerbatim("AlCaIsoBunch") << "Input tag for trigger results " << theTriggerResultsLabel_
0077 << " with trigger name " << trigName_ << " and process " << processName_
0078 << std::endl;
0079 }
0080
0081 AlCaIsolatedBunchSelector::~AlCaIsolatedBunchSelector() {}
0082
0083
0084
0085
0086
0087
0088 bool AlCaIsolatedBunchSelector::filter(edm::Event& iEvent, edm::EventSetup const& iSetup) {
0089 bool accept(false);
0090 ++nAll_;
0091 #ifdef EDM_ML_DEBUG
0092 edm::LogVerbatim("AlCaIsoBunch") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
0093 << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing() << std::endl;
0094 #endif
0095
0096 auto const& triggerResults = iEvent.getHandle(tok_trigRes_);
0097 if (triggerResults.isValid()) {
0098 const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
0099 const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
0100 for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
0101 int hlt = triggerResults->accept(iHLT);
0102 if (triggerNames_[iHLT].find(trigName_) != std::string::npos) {
0103 if (hlt > 0) {
0104 accept = true;
0105 #ifdef EDM_ML_DEBUG
0106 edm::LogVerbatim("AlCaIsoBunch")
0107 << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << accept << std::endl;
0108 #endif
0109 break;
0110 }
0111 }
0112 }
0113 }
0114
0115
0116 if (accept)
0117 ++nGood_;
0118 return accept;
0119
0120 }
0121
0122 void AlCaIsolatedBunchSelector::endStream() {
0123 globalCache()->nAll_ += nAll_;
0124 globalCache()->nGood_ += nGood_;
0125 }
0126
0127 void AlCaIsolatedBunchSelector::globalEndJob(const AlCaIsolatedBunch::Counters* count) {
0128 edm::LogVerbatim("AlCaIsoBunch") << "Selects " << count->nGood_ << " in " << count->nAll_ << " events" << std::endl;
0129 }
0130
0131
0132 void AlCaIsolatedBunchSelector::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0133 bool changed(false);
0134 edm::LogVerbatim("AlCaIsoBunch") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init "
0135 << hltConfig_.init(iRun, iSetup, processName_, changed) << std::endl;
0136 }
0137
0138 void AlCaIsolatedBunchSelector::endRun(edm::Run const& iRun, edm::EventSetup const&) {
0139 ++nRun_;
0140 edm::LogVerbatim("AlCaIsoBunch") << "endRun[" << nRun_ << "] " << iRun.run() << std::endl;
0141 }
0142
0143
0144 void AlCaIsolatedBunchSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0145 edm::ParameterSetDescription desc;
0146 desc.add<edm::InputTag>("triggerResultLabel", edm::InputTag("TriggerResults", "", "HLT"));
0147 desc.add<std::string>("processName", "HLT");
0148 desc.add<std::string>("triggerName", "HLT_HcalIsolatedBunch");
0149 descriptions.add("alcaIsolatedBunchSelector", desc);
0150 }
0151
0152
0153 #include "FWCore/Framework/interface/MakerMacros.h"
0154 DEFINE_FWK_MODULE(AlCaIsolatedBunchSelector);