File indexing completed on 2024-04-06 12:18:34
0001 #include <cmath>
0002 #include <memory>
0003
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "DataFormats/Math/interface/deltaR.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"
0011 #include "HLTrigger/JetMET/interface/HLTJetL1TMatchProducer.h"
0012
0013 template <typename T>
0014 HLTJetL1TMatchProducer<T>::HLTJetL1TMatchProducer(const edm::ParameterSet& iConfig) {
0015 jetsInput_ = iConfig.template getParameter<edm::InputTag>("jetsInput");
0016 L1Jets_ = iConfig.template getParameter<edm::InputTag>("L1Jets");
0017
0018
0019 auto const DeltaR = iConfig.template getParameter<double>("DeltaR");
0020 DeltaR2_ = DeltaR * std::abs(DeltaR);
0021
0022 m_theJetToken = consumes(jetsInput_);
0023 m_theL1JetToken = consumes(L1Jets_);
0024
0025 produces<std::vector<T>>();
0026 }
0027
0028 template <typename T>
0029 void HLTJetL1TMatchProducer<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0030 edm::ParameterSetDescription desc;
0031 desc.add<edm::InputTag>("jetsInput", edm::InputTag("hltAntiKT5PFJets"));
0032 desc.add<edm::InputTag>("L1Jets", edm::InputTag("hltCaloStage2Digis"));
0033 desc.add<double>("DeltaR", 0.5);
0034 descriptions.add(defaultModuleLabel<HLTJetL1TMatchProducer<T>>(), desc);
0035 }
0036
0037 template <typename T>
0038 void HLTJetL1TMatchProducer<T>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0039 auto const& jets = iEvent.get(m_theJetToken);
0040 auto const l1Jets = iEvent.getHandle(m_theL1JetToken);
0041
0042 bool trigger_bx_only = true;
0043
0044 auto result = std::make_unique<std::vector<T>>();
0045
0046 if (l1Jets.isValid()) {
0047 for (auto const& jet : jets) {
0048 bool isMatched = false;
0049 for (int ibx = l1Jets->getFirstBX(); ibx <= l1Jets->getLastBX(); ++ibx) {
0050 if (trigger_bx_only && (ibx != 0))
0051 continue;
0052 for (auto it = l1Jets->begin(ibx); it != l1Jets->end(ibx); it++) {
0053 if (it->et() == 0)
0054 continue;
0055 if (reco::deltaR2(jet.eta(), jet.phi(), it->eta(), it->phi()) < DeltaR2_) {
0056 isMatched = true;
0057 break;
0058 }
0059 }
0060 }
0061 if (isMatched) {
0062 result->emplace_back(jet);
0063 }
0064 }
0065 } else {
0066 edm::LogWarning("MissingProduct") << "L1Upgrade l1Jets bx collection not found.";
0067 }
0068
0069 iEvent.put(std::move(result));
0070 }