File indexing completed on 2022-08-23 02:45:56
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 alCaIsolatedBunchFilter {
0031 struct Counters {
0032 Counters() : nAll_(0), nGood_(0) {}
0033 mutable std::atomic<unsigned int> nAll_, nGood_;
0034 };
0035 }
0036
0037 class AlCaIsolatedBunchFilter : public edm::stream::EDFilter<edm::GlobalCache<alCaIsolatedBunchFilter::Counters> > {
0038 public:
0039 explicit AlCaIsolatedBunchFilter(edm::ParameterSet const&, const alCaIsolatedBunchFilter::Counters* count);
0040 ~AlCaIsolatedBunchFilter() override;
0041
0042 static std::unique_ptr<alCaIsolatedBunchFilter::Counters> initializeGlobalCache(edm::ParameterSet const& iConfig) {
0043 return std::make_unique<alCaIsolatedBunchFilter::Counters>();
0044 }
0045
0046 bool filter(edm::Event&, edm::EventSetup const&) override;
0047 void endStream() override;
0048 static void globalEndJob(const alCaIsolatedBunchFilter::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::vector<std::string> trigJetNames_, trigIsoBunchNames_;
0059 const std::string processName_;
0060 const edm::InputTag theTriggerResultsLabel_;
0061 const edm::EDGetTokenT<edm::TriggerResults> tok_trigRes_;
0062 };
0063
0064
0065
0066
0067 AlCaIsolatedBunchFilter::AlCaIsolatedBunchFilter(const edm::ParameterSet& iConfig,
0068 const alCaIsolatedBunchFilter::Counters* count)
0069 : nRun_(0),
0070 nAll_(0),
0071 nGood_(0),
0072 trigJetNames_(iConfig.getParameter<std::vector<std::string> >("triggerJet")),
0073 trigIsoBunchNames_(iConfig.getParameter<std::vector<std::string> >("triggerIsoBunch")),
0074 processName_(iConfig.getParameter<std::string>("processName")),
0075 theTriggerResultsLabel_(iConfig.getParameter<edm::InputTag>("triggerResultLabel")),
0076 tok_trigRes_(consumes<edm::TriggerResults>(theTriggerResultsLabel_)) {
0077 edm::LogVerbatim("AlCaIsoBunch") << "Input tag for trigger results " << theTriggerResultsLabel_ << " with "
0078 << trigIsoBunchNames_.size() << ":" << trigJetNames_.size() << " trigger names and"
0079 << " process " << processName_ << std::endl;
0080 for (unsigned int k = 0; k < trigIsoBunchNames_.size(); ++k)
0081 edm::LogVerbatim("AlCaIsoBunch") << "Isolated Bunch[" << k << "] " << trigIsoBunchNames_[k] << std::endl;
0082 for (unsigned int k = 0; k < trigJetNames_.size(); ++k)
0083 edm::LogVerbatim("AlCaIsoBunch") << "Jet Trigger[" << k << "] " << trigJetNames_[k] << std::endl;
0084 }
0085
0086 AlCaIsolatedBunchFilter::~AlCaIsolatedBunchFilter() {}
0087
0088
0089
0090
0091
0092
0093 bool AlCaIsolatedBunchFilter::filter(edm::Event& iEvent, edm::EventSetup const& iSetup) {
0094 bool accept(false);
0095 ++nAll_;
0096 #ifdef EDM_ML_DEBUG
0097 edm::LogVerbatim("AlCaIsoBunch") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
0098 << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing() << std::endl;
0099 #endif
0100
0101 if ((trigIsoBunchNames_.empty()) && (trigJetNames_.empty())) {
0102 accept = true;
0103 } else {
0104
0105 auto const& triggerResults = iEvent.getHandle(tok_trigRes_);
0106 if (triggerResults.isValid()) {
0107 const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
0108 const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
0109 bool jet(false), isobunch(false);
0110 for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
0111 int hlt = triggerResults->accept(iHLT);
0112 if (!jet) {
0113 for (unsigned int i = 0; i < trigJetNames_.size(); ++i) {
0114 if (triggerNames_[iHLT].find(trigJetNames_[i]) != std::string::npos) {
0115 if (hlt > 0)
0116 jet = true;
0117 if (jet) {
0118 #ifdef EDM_ML_DEBUG
0119 edm::LogVerbatim("AlCaIsoBunch")
0120 << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << jet << ":" << isobunch << std::endl;
0121 #endif
0122 break;
0123 }
0124 }
0125 }
0126 }
0127 if (!isobunch) {
0128 for (unsigned int i = 0; i < trigIsoBunchNames_.size(); ++i) {
0129 if (triggerNames_[iHLT].find(trigIsoBunchNames_[i]) != std::string::npos) {
0130 if (hlt > 0)
0131 isobunch = true;
0132 if (isobunch) {
0133 #ifdef EDM_ML_DEBUG
0134 edm::LogVerbatim("AlCaIsoBunch")
0135 << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << jet << ":" << isobunch << std::endl;
0136 #endif
0137 break;
0138 }
0139 }
0140 }
0141 }
0142 if (jet && isobunch) {
0143 accept = true;
0144 break;
0145 }
0146 }
0147 }
0148 }
0149
0150
0151 if (accept)
0152 ++nGood_;
0153 return accept;
0154
0155 }
0156
0157 void AlCaIsolatedBunchFilter::endStream() {
0158 globalCache()->nAll_ += nAll_;
0159 globalCache()->nGood_ += nGood_;
0160 }
0161
0162 void AlCaIsolatedBunchFilter::globalEndJob(const alCaIsolatedBunchFilter::Counters* count) {
0163 edm::LogVerbatim("AlCaIsoBunch") << "Selects " << count->nGood_ << " in " << count->nAll_ << " events" << std::endl;
0164 }
0165
0166
0167 void AlCaIsolatedBunchFilter::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0168 bool changed(false);
0169 edm::LogVerbatim("AlCaIsoBunch") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init "
0170 << hltConfig_.init(iRun, iSetup, processName_, changed) << std::endl;
0171 }
0172
0173 void AlCaIsolatedBunchFilter::endRun(edm::Run const& iRun, edm::EventSetup const&) {
0174 ++nRun_;
0175 edm::LogVerbatim("AlCaIsoBunch") << "endRun[" << nRun_ << "] " << iRun.run() << std::endl;
0176 }
0177
0178
0179 void AlCaIsolatedBunchFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0180 edm::ParameterSetDescription desc;
0181 desc.add<edm::InputTag>("triggerResultLabel", edm::InputTag("TriggerResults", "", "HLT"));
0182 desc.add<std::string>("processName", "HLT");
0183 std::vector<std::string> isobunch = {"HLT_ZeroBias_IsolatedBunches"};
0184 desc.add<std::vector<std::string> >("triggerIsoBunch", isobunch);
0185 std::vector<std::string> triggers = {"HLT_AK8PFJet",
0186 "HLT_AK8PFHT",
0187 "HLT_CaloJet",
0188 "HLT_HT",
0189 "HLT_JetE",
0190 "HLT_PFHT",
0191 "HLT_DiPFJet",
0192 "HLT_PFJet",
0193 "HLT_DiCentralPFJet",
0194 "HLT_QuadPFJet",
0195 "HLT_L1_TripleJet_VBF",
0196 "HLT_QuadJet",
0197 "HLT_DoubleJet",
0198 "HLT_AK8DiPFJet",
0199 "HLT_AK4CaloJet",
0200 "HLT_AK4PFJet"};
0201 desc.add<std::vector<std::string> >("triggerJet", triggers);
0202 descriptions.add("alcaIsolatedBunchFilter", desc);
0203 }
0204
0205
0206 #include "FWCore/Framework/interface/MakerMacros.h"
0207 DEFINE_FWK_MODULE(AlCaIsolatedBunchFilter);