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
0023 #include "DataFormats/Common/interface/TriggerResults.h"
0024 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0025
0026
0027
0028
0029
0030
0031 namespace AlCaIsoTracksProdFilter {
0032 struct Counters {
0033 Counters() : nAll_(0), nGood_(0) {}
0034 mutable std::atomic<unsigned int> nAll_, nGood_;
0035 };
0036 }
0037
0038 class AlCaIsoTracksProducerFilter : public edm::stream::EDFilter<edm::GlobalCache<AlCaIsoTracksProdFilter::Counters> > {
0039 public:
0040 explicit AlCaIsoTracksProducerFilter(edm::ParameterSet const&, const AlCaIsoTracksProdFilter::Counters* count);
0041 ~AlCaIsoTracksProducerFilter() override;
0042
0043 static std::unique_ptr<AlCaIsoTracksProdFilter::Counters> initializeGlobalCache(edm::ParameterSet const& iConfig) {
0044 return std::make_unique<AlCaIsoTracksProdFilter::Counters>();
0045 }
0046
0047 bool filter(edm::Event&, edm::EventSetup const&) override;
0048 void endStream() override;
0049 static void globalEndJob(const AlCaIsoTracksProdFilter::Counters* counters);
0050 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0051
0052 private:
0053 void beginRun(edm::Run const&, edm::EventSetup const&) override;
0054 void endRun(edm::Run const&, edm::EventSetup const&) override;
0055
0056
0057 HLTConfigProvider hltConfig_;
0058 unsigned int nRun_, nAll_, nGood_;
0059 const std::vector<std::string> trigNames_;
0060 const std::string processName_;
0061 const edm::InputTag triggerResultsLabel_;
0062 const edm::EDGetTokenT<edm::TriggerResults> tok_trigRes_;
0063 };
0064
0065 AlCaIsoTracksProducerFilter::AlCaIsoTracksProducerFilter(const edm::ParameterSet& iConfig,
0066 const AlCaIsoTracksProdFilter::Counters* count)
0067 : nRun_(0),
0068 nAll_(0),
0069 nGood_(0),
0070 trigNames_(iConfig.getParameter<std::vector<std::string> >("triggers")),
0071 processName_(iConfig.getParameter<std::string>("processName")),
0072 triggerResultsLabel_(iConfig.getParameter<edm::InputTag>("triggerResultLabel")),
0073 tok_trigRes_(consumes<edm::TriggerResults>(triggerResultsLabel_)) {
0074 edm::LogVerbatim("HcalIsoTrack") << "Use process name " << processName_ << " Labels " << triggerResultsLabel_
0075 << " selecting " << trigNames_.size() << " triggers\n";
0076 for (unsigned int k = 0; k < trigNames_.size(); ++k) {
0077 edm::LogVerbatim("HcalIsoTrack") << "Trigger[" << k << "] " << trigNames_[k] << std::endl;
0078 }
0079 }
0080
0081 AlCaIsoTracksProducerFilter::~AlCaIsoTracksProducerFilter() {}
0082
0083 bool AlCaIsoTracksProducerFilter::filter(edm::Event& iEvent, edm::EventSetup const& iSetup) {
0084 ++nAll_;
0085 edm::LogVerbatim("HcalIsoTrack") << "Run " << iEvent.id().run() << " Event " << iEvent.id().event() << " Luminosity "
0086 << iEvent.luminosityBlock() << " Bunch " << iEvent.bunchCrossing() << std::endl;
0087
0088
0089 bool triggerSatisfied(false);
0090 if (trigNames_.empty()) {
0091 triggerSatisfied = true;
0092 } else {
0093 auto const& triggerResults = iEvent.getHandle(tok_trigRes_);
0094 if (triggerResults.isValid()) {
0095 std::vector<std::string> modules;
0096 const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
0097 const std::vector<std::string>& triggerNames_ = triggerNames.triggerNames();
0098 for (unsigned int iHLT = 0; iHLT < triggerResults->size(); iHLT++) {
0099 int hlt = triggerResults->accept(iHLT);
0100 for (unsigned int i = 0; i < trigNames_.size(); ++i) {
0101 if (triggerNames_[iHLT].find(trigNames_[i]) != std::string::npos) {
0102 #ifdef EDM_ML_DEBUG
0103 edm::LogVerbatim("HcalIsoTrack")
0104 << triggerNames_[iHLT] << " has got HLT flag " << hlt << ":" << triggerSatisfied;
0105 #endif
0106 if (hlt > 0) {
0107 triggerSatisfied = true;
0108 break;
0109 }
0110 }
0111 }
0112 if (triggerSatisfied)
0113 break;
0114 }
0115 }
0116 }
0117 #ifdef EDM_ML_DEBUG
0118 edm::LogVerbatim("HcalIsoTrack") << "AlCaIsoTracksProducerFilter:: triggerSatisfied: " << triggerSatisfied;
0119 #endif
0120 if (triggerSatisfied)
0121 ++nGood_;
0122 return triggerSatisfied;
0123 }
0124
0125 void AlCaIsoTracksProducerFilter::endStream() {
0126 globalCache()->nAll_ += nAll_;
0127 globalCache()->nGood_ += nGood_;
0128 }
0129
0130 void AlCaIsoTracksProducerFilter::globalEndJob(const AlCaIsoTracksProdFilter::Counters* count) {
0131 edm::LogVerbatim("HcalIsoTrack") << "Selects " << count->nGood_ << " in " << count->nAll_ << " events " << std::endl;
0132 }
0133
0134 void AlCaIsoTracksProducerFilter::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0135 bool changed(false);
0136 bool flag = hltConfig_.init(iRun, iSetup, processName_, changed);
0137 edm::LogVerbatim("HcalIsoTrack") << "Run[" << nRun_ << "] " << iRun.run() << " hltconfig.init " << flag << std::endl;
0138 }
0139
0140 void AlCaIsoTracksProducerFilter::endRun(edm::Run const& iRun, edm::EventSetup const&) {
0141 ++nRun_;
0142 edm::LogVerbatim("HcalIsoTrack") << "endRun[" << nRun_ << "] " << iRun.run() << std::endl;
0143 }
0144
0145 void AlCaIsoTracksProducerFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0146
0147
0148 edm::ParameterSetDescription desc;
0149 desc.add<edm::InputTag>("triggerResultLabel", edm::InputTag("TriggerResults", "", "HLT"));
0150 std::vector<std::string> trigger = {"HLT_IsoTrackHB", "HLT_IsoTrackHE"};
0151 desc.add<std::vector<std::string> >("triggers", trigger);
0152 desc.add<std::string>("processName", "HLT");
0153 descriptions.add("alcaIsoTracksProducerFilter", desc);
0154 }
0155
0156 #include "FWCore/Framework/interface/MakerMacros.h"
0157 DEFINE_FWK_MODULE(AlCaIsoTracksProducerFilter);