Skip to content

Commit bcaa127

Browse files
authored
Merge pull request #48226 from mmusich/mm_dev_protect_HLTPPSJetComparisonFilter
add protection to `HLTPPSJetComparisonFilter` against faulty `LHCInfo` payloads (Energy=0)
2 parents 546826d + cdd2dec commit bcaa127

File tree

1 file changed

+55
-31
lines changed

1 file changed

+55
-31
lines changed

HLTrigger/special/plugins/HLTPPSJetComparisonFilter.cc

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,57 @@ Matching can be done on the xi and/or mass+rapidity variables, using the do_xi a
99
*/
1010

1111
// include files
12-
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
13-
#include "FWCore/ParameterSet/interface/ParameterSet.h"
14-
#include "FWCore/Framework/interface/Event.h"
15-
#include "FWCore/Framework/interface/EventSetup.h"
16-
#include "FWCore/Framework/interface/global/EDFilter.h"
17-
12+
#include "CondTools/RunInfo/interface/LHCInfoCombined.h"
1813
#include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"
1914
#include "DataFormats/CTPPSReco/interface/CTPPSLocalTrackLite.h"
2015
#include "DataFormats/JetReco/interface/PFJetCollection.h"
2116
#include "DataFormats/ProtonReco/interface/ForwardProton.h"
22-
23-
#include "CondTools/RunInfo/interface/LHCInfoCombined.h"
24-
17+
#include "FWCore/Framework/interface/Event.h"
18+
#include "FWCore/Framework/interface/EventSetup.h"
2519
#include "FWCore/Framework/interface/MakerMacros.h"
20+
#include "FWCore/Framework/interface/global/EDFilter.h"
21+
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
22+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
23+
#include "FWCore/Utilities/interface/isFinite.h"
2624

2725
// class declaration
2826
//
29-
class HLTPPSJetComparisonFilter : public edm::global::EDFilter<> {
27+
class HLTPPSJetComparisonFilter : public edm::global::EDFilter<edm::LuminosityBlockCache<float>> {
3028
public:
3129
explicit HLTPPSJetComparisonFilter(const edm::ParameterSet &);
32-
~HLTPPSJetComparisonFilter() override;
30+
~HLTPPSJetComparisonFilter() override = default;
3331

3432
static void fillDescriptions(edm::ConfigurationDescriptions &);
33+
34+
std::shared_ptr<float> globalBeginLuminosityBlock(const edm::LuminosityBlock &,
35+
const edm::EventSetup &) const override;
36+
37+
void globalEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const override;
38+
3539
bool filter(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
3640

3741
private:
3842
// ----------member data ---------------------------
3943
const edm::ESGetToken<LHCInfo, LHCInfoRcd> lhcInfoToken_;
4044
const edm::ESGetToken<LHCInfoPerLS, LHCInfoPerLSRcd> lhcInfoPerLSToken_;
4145
const edm::ESGetToken<LHCInfoPerFill, LHCInfoPerFillRcd> lhcInfoPerFillToken_;
42-
const bool useNewLHCInfo_;
4346

44-
edm::ParameterSet param_;
47+
const bool useNewLHCInfo_;
4548

46-
edm::InputTag jetInputTag_; // Input tag identifying the jet track
47-
edm::EDGetTokenT<reco::PFJetCollection> jet_token_;
49+
const edm::InputTag jetInputTag_; // Input tag identifying the jet track
50+
const edm::EDGetTokenT<reco::PFJetCollection> jet_token_;
4851

49-
edm::InputTag forwardProtonInputTag_; // Input tag identifying the forward proton collection
50-
edm::EDGetTokenT<std::vector<reco::ForwardProton>> recoProtonSingleRPToken_;
52+
const edm::InputTag forwardProtonInputTag_; // Input tag identifying the forward proton collection
53+
const edm::EDGetTokenT<std::vector<reco::ForwardProton>> recoProtonSingleRPToken_;
5154

52-
double maxDiffxi_;
53-
double maxDiffm_;
54-
double maxDiffy_;
55+
const double maxDiffxi_;
56+
const double maxDiffm_;
57+
const double maxDiffy_;
5558

56-
unsigned int n_jets_;
59+
const unsigned int n_jets_;
5760

58-
bool do_xi_;
59-
bool do_my_;
61+
const bool do_xi_;
62+
const bool do_my_;
6063
};
6164

6265
// fill descriptions
@@ -90,14 +93,31 @@ void HLTPPSJetComparisonFilter::fillDescriptions(edm::ConfigurationDescriptions
9093
return;
9194
}
9295

93-
// destructor and constructor
94-
//
95-
HLTPPSJetComparisonFilter::~HLTPPSJetComparisonFilter() = default;
96+
std::shared_ptr<float> HLTPPSJetComparisonFilter::globalBeginLuminosityBlock(const edm::LuminosityBlock &,
97+
const edm::EventSetup &iSetup) const {
98+
auto cache = std::make_shared<float>();
99+
100+
LHCInfoCombined lhcInfoCombined(iSetup, lhcInfoPerLSToken_, lhcInfoPerFillToken_, lhcInfoToken_, useNewLHCInfo_);
101+
float sqs = 2. * lhcInfoCombined.energy;
102+
103+
if (sqs == 0.f || !edm::isFinite(sqs)) {
104+
edm::LogError("HLTPPSJetComparisonFilter")
105+
<< "LHC energy is zero (sqrt(s) = 0). All events in this IOV will be rejected.";
106+
}
107+
108+
*cache = sqs;
109+
return cache;
110+
}
111+
112+
void HLTPPSJetComparisonFilter::globalEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const {}
96113

97114
HLTPPSJetComparisonFilter::HLTPPSJetComparisonFilter(const edm::ParameterSet &iConfig)
98-
: lhcInfoToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoLabel")))),
99-
lhcInfoPerLSToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoPerLSLabel")))),
100-
lhcInfoPerFillToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoPerFillLabel")))),
115+
: lhcInfoToken_(esConsumes<LHCInfo, LHCInfoRcd, edm::Transition::BeginLuminosityBlock>(
116+
edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoLabel")))),
117+
lhcInfoPerLSToken_(esConsumes<LHCInfoPerLS, LHCInfoPerLSRcd, edm::Transition::BeginLuminosityBlock>(
118+
edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoPerLSLabel")))),
119+
lhcInfoPerFillToken_(esConsumes<LHCInfoPerFill, LHCInfoPerFillRcd, edm::Transition::BeginLuminosityBlock>(
120+
edm::ESInputTag("", iConfig.getParameter<std::string>("lhcInfoPerFillLabel")))),
101121
useNewLHCInfo_(iConfig.getParameter<bool>("useNewLHCInfo")),
102122

103123
jetInputTag_(iConfig.getParameter<edm::InputTag>("jetInputTag")),
@@ -118,8 +138,12 @@ HLTPPSJetComparisonFilter::HLTPPSJetComparisonFilter(const edm::ParameterSet &iC
118138
// member functions
119139
//
120140
bool HLTPPSJetComparisonFilter::filter(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
121-
LHCInfoCombined lhcInfoCombined(iSetup, lhcInfoPerLSToken_, lhcInfoPerFillToken_, lhcInfoToken_, useNewLHCInfo_);
122-
float sqs = 2. * lhcInfoCombined.energy; // get sqrt(s)
141+
// get the cached value of the LHC energy from the cache
142+
const float sqs = *luminosityBlockCache(iEvent.getLuminosityBlock().index());
143+
144+
// early return in case of not physical energy
145+
if (sqs == 0.f || !edm::isFinite(sqs))
146+
return false;
123147

124148
edm::Handle<reco::PFJetCollection> jets;
125149
iEvent.getByToken(jet_token_, jets); // get jet collection

0 commit comments

Comments
 (0)