Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HF noise event filter #31328

Merged
merged 4 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PhysicsTools/NanoAOD/python/nanoDQM_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
5 changes: 4 additions & 1 deletion PhysicsTools/PatAlgos/python/slimming/metFilterPaths_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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']


Expand Down Expand Up @@ -101,6 +103,7 @@ def miniAOD_customizeMETFiltersFastSim(process):
BadChargedCandidateFilter,
BadPFMuonFilter,
BadPFMuonDzFilter,
hfNoisyHitsFilter,
BadChargedCandidateSummer16Filter,
BadPFMuonSummer16Filter
)
Expand Down
148 changes: 148 additions & 0 deletions RecoMET/METFilters/plugins/HFNoisyHitsFilter.cc
Original file line number Diff line number Diff line change
@@ -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 <memory>

// 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<HcalPhase1FlagLabels::HFStatusFlag> getNoiseBits() const;
const edm::EDGetTokenT<HFRecHitCollection> hfhits_token_;
const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geom_token_;
const double rechitPtThreshold_;
const std::vector<std::string> listOfNoises_;
const bool taggingMode_;
const bool debug_;
std::vector<HcalPhase1FlagLabels::HFStatusFlag> noiseBits_;
};

//
// constructors and destructor
//
HFNoisyHitsFilter::HFNoisyHitsFilter(const edm::ParameterSet& iConfig)
: hfhits_token_(consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfrechits"))),
geom_token_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
rechitPtThreshold_(iConfig.getParameter<double>("rechitPtThreshold")),
listOfNoises_(iConfig.getParameter<std::vector<std::string>>("listOfNoises")),
taggingMode_(iConfig.getParameter<bool>("taggingMode")),
debug_(iConfig.getParameter<bool>("debug")) {
noiseBits_ = getNoiseBits();
produces<bool>();
}

//
// 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<bool>(pass));
if (debug_)
LogDebug("HFNoisyHitsFilter") << "Passing filter? " << pass;
return taggingMode_ || pass;
}

std::vector<HcalPhase1FlagLabels::HFStatusFlag> HFNoisyHitsFilter::getNoiseBits() const {
std::vector<HcalPhase1FlagLabels::HFStatusFlag> 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<edm::InputTag>("hfrechits", {"reducedHcalRecHits:hfreco"});
desc.add<double>("rechitPtThreshold", 20.);
desc.add<std::vector<std::string>>("listOfNoises", {"HFLongShort", "HFS8S1Ratio", "HFPET", "HFSignalAsymmetry"});
desc.add<bool>("taggingMode", false);
desc.add<bool>("debug", false);
descriptions.add("hfNoisyHitsFilter", desc);
}
//define this as a plug-in
DEFINE_FWK_MODULE(HFNoisyHitsFilter);
4 changes: 4 additions & 0 deletions RecoMET/METFilters/python/metFilters_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -116,6 +119,7 @@
BadChargedCandidateFilter*
BadPFMuonFilter *
BadPFMuonDzFilter *
hfNoisyHitsFilter *
BadChargedCandidateSummer16Filter*
BadPFMuonSummer16Filter *
muonBadTrackFilter
Expand Down