diff --git a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py index 46c5953121a77..bd2e27f1b8cf1 100644 --- a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py +++ b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py @@ -194,6 +194,7 @@ Plot1D('eeBadScFilter', 'eeBadScFilter', 2, -0.5, 1.5, 'Trigger/flag bit'), Plot1D('globalSuperTightHalo2016Filter', 'globalSuperTightHalo2016Filter', 2, -0.5, 1.5, 'Trigger/flag bit'), Plot1D('globalTightHalo2016Filter', 'globalTightHalo2016Filter', 2, -0.5, 1.5, 'Trigger/flag bit'), + Plot1D('hfNoisyHitsFilter', 'hfNoisyHitsFilter', 2, -0.5, 1.5, 'Trigger/flag bit'), Plot1D('goodVertices', 'goodVertices', 2, -0.5, 1.5, 'Trigger/flag bit'), Plot1D('hcalLaserEventFilter', 'hcalLaserEventFilter', 2, -0.5, 1.5, 'Trigger/flag bit'), Plot1D('muonBadTrackFilter', 'muonBadTrackFilter', 2, -0.5, 1.5, 'Trigger/flag bit'), diff --git a/PhysicsTools/PatAlgos/python/slimming/metFilterPaths_cff.py b/PhysicsTools/PatAlgos/python/slimming/metFilterPaths_cff.py index c1789998240b3..8bfd29a8f5147 100644 --- a/PhysicsTools/PatAlgos/python/slimming/metFilterPaths_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/metFilterPaths_cff.py @@ -9,6 +9,7 @@ from RecoMET.METFilters.metFilters_cff import chargedHadronTrackResolutionFilter, muonBadTrackFilter from RecoMET.METFilters.metFilters_cff import BadChargedCandidateFilter, BadPFMuonFilter, BadPFMuonDzFilter #2016 post-ICHEPversion from RecoMET.METFilters.metFilters_cff import BadChargedCandidateSummer16Filter, BadPFMuonSummer16Filter #2016 ICHEP version +from RecoMET.METFilters.metFilters_cff import hfNoisyHitsFilter from RecoMET.METFilters.metFilters_cff import metFilters # individual filters @@ -36,6 +37,7 @@ Flag_BadChargedCandidateSummer16Filter = cms.Path(BadChargedCandidateSummer16Filter) Flag_BadPFMuonSummer16Filter = cms.Path(BadPFMuonSummer16Filter) Flag_BadPFMuonDzFilter = cms.Path(BadPFMuonDzFilter) +Flag_hfNoisyHitsFilter = cms.Path(hfNoisyHitsFilter) # and the sub-filters Flag_trkPOG_manystripclus53X = cms.Path(~manystripclus53X) @@ -49,7 +51,7 @@ #add your new path here!! allMetFilterPaths=['HBHENoiseFilter','HBHENoiseIsoFilter','CSCTightHaloFilter','CSCTightHaloTrkMuUnvetoFilter','CSCTightHalo2015Filter','globalTightHalo2016Filter','globalSuperTightHalo2016Filter','HcalStripHaloFilter','hcalLaserEventFilter','EcalDeadCellTriggerPrimitiveFilter','EcalDeadCellBoundaryEnergyFilter','ecalBadCalibFilter','goodVertices','eeBadScFilter', 'ecalLaserCorrFilter','trkPOGFilters','chargedHadronTrackResolutionFilter','muonBadTrackFilter', - 'BadChargedCandidateFilter','BadPFMuonFilter', 'BadPFMuonDzFilter','BadChargedCandidateSummer16Filter','BadPFMuonSummer16Filter', + 'BadChargedCandidateFilter','BadPFMuonFilter', 'BadPFMuonDzFilter', 'hfNoisyHitsFilter', 'BadChargedCandidateSummer16Filter','BadPFMuonSummer16Filter', 'trkPOG_manystripclus53X','trkPOG_toomanystripclus53X','trkPOG_logErrorTooManyClusters','METFilters'] @@ -101,6 +103,7 @@ def miniAOD_customizeMETFiltersFastSim(process): BadChargedCandidateFilter, BadPFMuonFilter, BadPFMuonDzFilter, + hfNoisyHitsFilter, BadChargedCandidateSummer16Filter, BadPFMuonSummer16Filter ) diff --git a/RecoMET/METFilters/plugins/HFNoisyHitsFilter.cc b/RecoMET/METFilters/plugins/HFNoisyHitsFilter.cc new file mode 100644 index 0000000000000..60e506c02b796 --- /dev/null +++ b/RecoMET/METFilters/plugins/HFNoisyHitsFilter.cc @@ -0,0 +1,148 @@ +// -*- C++ -*- +// +// Package: RecoMET/METFilters +// Class: HFNoisyHitsFilter +// +/**\class HFNoisyHitsFilter HFNoisyHitsFilter.cc RecoMET/METFilters/plugins/HFNoisyHitsFilter.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Laurent Thomas +// Created: Tue, 01 Sep 2020 11:24:33 GMT +// +// + +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/global/EDFilter.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "FWCore/Utilities/interface/Exception.h" + +#include "Geometry/CaloTopology/interface/CaloTopology.h" +#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h" + +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" + +#include "DataFormats/HcalRecHit/interface/HFRecHit.h" +#include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" +#include "DataFormats/METReco/interface/HcalPhase1FlagLabels.h" +// +// class declaration +// + +class HFNoisyHitsFilter : public edm::global::EDFilter<> { +public: + explicit HFNoisyHitsFilter(const edm::ParameterSet&); + ~HFNoisyHitsFilter() override {} + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + std::vector getNoiseBits() const; + const edm::EDGetTokenT hfhits_token_; + const edm::ESGetToken geom_token_; + const double rechitPtThreshold_; + const std::vector listOfNoises_; + const bool taggingMode_; + const bool debug_; + std::vector noiseBits_; +}; + +// +// constructors and destructor +// +HFNoisyHitsFilter::HFNoisyHitsFilter(const edm::ParameterSet& iConfig) + : hfhits_token_(consumes(iConfig.getParameter("hfrechits"))), + geom_token_(esConsumes()), + rechitPtThreshold_(iConfig.getParameter("rechitPtThreshold")), + listOfNoises_(iConfig.getParameter>("listOfNoises")), + taggingMode_(iConfig.getParameter("taggingMode")), + debug_(iConfig.getParameter("debug")) { + noiseBits_ = getNoiseBits(); + produces(); +} + +// +// member functions +// + +// ------------ method called on each new Event ------------ +bool HFNoisyHitsFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { + using namespace edm; + bool pass = true; + + // Calo Geometry - needed for computing E_t + const CaloGeometry& geo = iSetup.getData(geom_token_); + + auto const& hfHits = iEvent.get(hfhits_token_); + + //Loop over the HF rechits. If one of them has Et>X and fires one the noise bits, declare the event as bad + for (auto const& hfhit : hfHits) { + float ene = hfhit.energy(); + float et = 0; + // compute transverse energy + const GlobalPoint& poshf = geo.getPosition(hfhit.detid()); + float pf = poshf.perp() / poshf.mag(); + et = ene * pf; + if (et < rechitPtThreshold_) + continue; + int hitFlags = hfhit.flags(); + for (auto noiseBit : noiseBits_) { + if ((hitFlags >> noiseBit) & 1) { + pass = false; + break; + } + } + if (!pass) + break; + } + iEvent.put(std::make_unique(pass)); + if (debug_) + LogDebug("HFNoisyHitsFilter") << "Passing filter? " << pass; + return taggingMode_ || pass; +} + +std::vector HFNoisyHitsFilter::getNoiseBits() const { + std::vector result; + for (auto const& noise : listOfNoises_) { + if (noise == "HFLongShort") + result.push_back(HcalPhase1FlagLabels::HFLongShort); + else if (noise == "HFS8S1Ratio") + result.push_back(HcalPhase1FlagLabels::HFS8S1Ratio); + else if (noise == "HFPET") + result.push_back(HcalPhase1FlagLabels::HFPET); + else if (noise == "HFSignalAsymmetry") + result.push_back(HcalPhase1FlagLabels::HFSignalAsymmetry); + else if (noise == "HFAnomalousHit") + result.push_back(HcalPhase1FlagLabels::HFAnomalousHit); + else + throw cms::Exception("Error") << "Couldn't find the bit index associated to this string: " << noise; + } + + return result; +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void HFNoisyHitsFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("hfrechits", {"reducedHcalRecHits:hfreco"}); + desc.add("rechitPtThreshold", 20.); + desc.add>("listOfNoises", {"HFLongShort", "HFS8S1Ratio", "HFPET", "HFSignalAsymmetry"}); + desc.add("taggingMode", false); + desc.add("debug", false); + descriptions.add("hfNoisyHitsFilter", desc); +} +//define this as a plug-in +DEFINE_FWK_MODULE(HFNoisyHitsFilter); diff --git a/RecoMET/METFilters/python/metFilters_cff.py b/RecoMET/METFilters/python/metFilters_cff.py index d2116ec6d91b2..d48fb6ef09d0d 100644 --- a/RecoMET/METFilters/python/metFilters_cff.py +++ b/RecoMET/METFilters/python/metFilters_cff.py @@ -91,6 +91,9 @@ ## The muon bad track filter with Dz cut (2020) _____________________________________|| from RecoMET.METFilters.BadPFMuonDzFilter_cfi import * +#HF noise filter +from RecoMET.METFilters.hfNoisyHitsFilter_cfi import * + metFilters = cms.Sequence( HBHENoiseFilterResultProducer * HBHENoiseFilter * @@ -116,6 +119,7 @@ BadChargedCandidateFilter* BadPFMuonFilter * BadPFMuonDzFilter * + hfNoisyHitsFilter * BadChargedCandidateSummer16Filter* BadPFMuonSummer16Filter * muonBadTrackFilter