Skip to content

Commit

Permalink
Merge pull request #20698 from cms-met/EcalBadCalibFilter
Browse files Browse the repository at this point in the history
Ecal bad calib filter
  • Loading branch information
cmsbuild committed Oct 29, 2017
2 parents 45a2438 + 47fd4b9 commit e2c95d1
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 2 deletions.
9 changes: 7 additions & 2 deletions PhysicsTools/PatAlgos/python/slimming/metFilterPaths_cff.py
Expand Up @@ -3,7 +3,7 @@
## We don't use "import *" because the cff contains some modules for which the C++ class doesn't exist
## and this triggers an error under unscheduled mode
from RecoMET.METFilters.metFilters_cff import HBHENoiseFilterResultProducer, HBHENoiseFilter, HBHENoiseIsoFilter, hcalLaserEventFilter
from RecoMET.METFilters.metFilters_cff import EcalDeadCellTriggerPrimitiveFilter, eeBadScFilter, ecalLaserCorrFilter, EcalDeadCellBoundaryEnergyFilter
from RecoMET.METFilters.metFilters_cff import EcalDeadCellTriggerPrimitiveFilter, eeBadScFilter, ecalLaserCorrFilter, EcalDeadCellBoundaryEnergyFilter, ecalBadCalibFilter
from RecoMET.METFilters.metFilters_cff import primaryVertexFilter, CSCTightHaloFilter, CSCTightHaloTrkMuUnvetoFilter, CSCTightHalo2015Filter, globalTightHalo2016Filter, globalSuperTightHalo2016Filter, HcalStripHaloFilter
from RecoMET.METFilters.metFilters_cff import goodVertices, trackingFailureFilter, trkPOGFilters, manystripclus53X, toomanystripclus53X, logErrorTooManyClusters
from RecoMET.METFilters.metFilters_cff import chargedHadronTrackResolutionFilter, muonBadTrackFilter
Expand All @@ -23,6 +23,7 @@
Flag_hcalLaserEventFilter = cms.Path(hcalLaserEventFilter)
Flag_EcalDeadCellTriggerPrimitiveFilter = cms.Path(EcalDeadCellTriggerPrimitiveFilter)
Flag_EcalDeadCellBoundaryEnergyFilter = cms.Path(EcalDeadCellBoundaryEnergyFilter)
Flag_ecalBadCalibFilter = cms.Path()
Flag_goodVertices = cms.Path(primaryVertexFilter)
Flag_trackingFailureFilter = cms.Path(goodVertices + trackingFailureFilter)
Flag_eeBadScFilter = cms.Path(eeBadScFilter)
Expand All @@ -45,7 +46,7 @@
Flag_METFilters = cms.Path(metFilters)

#add your new path here!!
allMetFilterPaths=['HBHENoiseFilter','HBHENoiseIsoFilter','CSCTightHaloFilter','CSCTightHaloTrkMuUnvetoFilter','CSCTightHalo2015Filter','globalTightHalo2016Filter','globalSuperTightHalo2016Filter','HcalStripHaloFilter','hcalLaserEventFilter','EcalDeadCellTriggerPrimitiveFilter','EcalDeadCellBoundaryEnergyFilter','goodVertices','eeBadScFilter',
allMetFilterPaths=['HBHENoiseFilter','HBHENoiseIsoFilter','CSCTightHaloFilter','CSCTightHaloTrkMuUnvetoFilter','CSCTightHalo2015Filter','globalTightHalo2016Filter','globalSuperTightHalo2016Filter','HcalStripHaloFilter','hcalLaserEventFilter','EcalDeadCellTriggerPrimitiveFilter','EcalDeadCellBoundaryEnergyFilter','ecalBadCalibFilter','goodVertices','eeBadScFilter',
'ecalLaserCorrFilter','trkPOGFilters','chargedHadronTrackResolutionFilter','muonBadTrackFilter',
'BadChargedCandidateFilter','BadPFMuonFilter','BadChargedCandidateSummer16Filter','BadPFMuonSummer16Filter',
'trkPOG_manystripclus53X','trkPOG_toomanystripclus53X','trkPOG_logErrorTooManyClusters','METFilters']
Expand All @@ -64,6 +65,9 @@ def miniAOD_customizeMETFiltersFastSim(process):
phase2_common.toReplaceWith( Flag_trkPOG_toomanystripclus53X, cms.Path() )
phase2_common.toReplaceWith( Flag_trkPOGFilters, cms.Path(~logErrorTooManyClusters) )

from Configuration.Eras.Modifier_run2_common_cff import run2_common
run2_common.toReplaceWith( Flag_ecalBadCalibFilter, cms.Path(ecalBadCalibFilter) )

from Configuration.Eras.Modifier_phase2_hgcal_cff import phase2_hgcal
phase2_hgcal.toReplaceWith( Flag_HBHENoiseFilter, cms.Path() )
phase2_hgcal.toReplaceWith( Flag_HBHENoiseIsoFilter, cms.Path() )
Expand All @@ -78,6 +82,7 @@ def miniAOD_customizeMETFiltersFastSim(process):
eeBadScFilter,
ecalLaserCorrFilter,
EcalDeadCellBoundaryEnergyFilter,
ecalBadCalibFilter,
primaryVertexFilter,
CSCTightHaloFilter,
CSCTightHaloTrkMuUnvetoFilter,
Expand Down
184 changes: 184 additions & 0 deletions RecoMET/METFilters/plugins/EcalBadCalibFilter.cc
@@ -0,0 +1,184 @@
// -*- C++ -*-
//
// Package: EcalBadCalibFilter
// Class: EcalBadCalibFilter
//
/**\class EcalBadCalibFilter EcalBadCalibFilter.cc
Description: <one line class summary>
Event filtering to remove events with anomalous energy intercalibrations in specific ECAL channels
*/
//
// Original Authors: D. Petyt
//


// include files

#include <iostream>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/EcalDetId/interface/EEDetId.h"
#include "DataFormats/EcalDetId/interface/EBDetId.h"
#include "DataFormats/EcalDetId/interface/EcalSubdetector.h"


#include "Geometry/CaloTopology/interface/CaloTopology.h"
#include "Geometry/CaloEventSetup/interface/CaloTopologyRecord.h"

#include "Geometry/CaloGeometry/interface/CaloGeometry.h"



using namespace std;


class EcalBadCalibFilter : public edm::global::EDFilter<> {

public:

explicit EcalBadCalibFilter(const edm::ParameterSet & iConfig);
~EcalBadCalibFilter() override {}

private:

// main filter function

bool filter(edm::StreamID, edm::Event & iEvent, const edm::EventSetup & iSetup) const override;

// input parameters
// ecal rechit collection (from AOD)
const edm::EDGetTokenT<EcalRecHitCollection> ecalRHSrcToken_;

//config parameters (defining the cuts on the bad SCs)
const double ecalMin_; // ecal rechit et threshold

const std::vector<unsigned int> baddetEcal_; // DetIds of bad Ecal channels

const bool taggingMode_;
const bool debug_; // prints out debug info if set to true

};

// read the parameters from the config file
EcalBadCalibFilter::EcalBadCalibFilter(const edm::ParameterSet & iConfig)
: ecalRHSrcToken_ (consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("EcalRecHitSource")))
, ecalMin_ (iConfig.getParameter<double>("ecalMinEt"))
, baddetEcal_ (iConfig.getParameter<std::vector<unsigned int> >("baddetEcal"))
, taggingMode_ (iConfig.getParameter<bool>("taggingMode"))
, debug_ (iConfig.getParameter<bool>("debug"))
{
produces<bool>();
}


bool EcalBadCalibFilter::filter(edm::StreamID, edm::Event & iEvent, const edm::EventSetup & iSetup) const {


// load required collections

// Ecal rechit collection
edm::Handle<EcalRecHitCollection> ecalRHs;
iEvent.getByToken(ecalRHSrcToken_, ecalRHs);

// Calo Geometry - needed for computing E_t
edm::ESHandle<CaloGeometry> pG;
iSetup.get<CaloGeometryRecord>().get(pG);


// by default the event is OK
bool pass = true;

for (const auto ecalit : baddetEcal_) {

DetId ecaldet(ecalit);

if (ecaldet.rawId()==0) continue;

// find rechit corresponding to this DetId
EcalRecHitCollection::const_iterator ecalhit=ecalRHs->find(ecaldet);

if (ecalhit==ecalRHs->end()) continue;

// if rechit not found, move to next DetId
if (ecalhit->id().rawId()==0 || ecalhit->id().rawId()!= ecaldet.rawId()) { continue; }


// define energy variables
float ene=0;
float et=0;

// rechit has been found: obtain crystal energy
ene=ecalhit->energy();

// compute transverse energy
GlobalPoint posecal=pG->getPosition(ecaldet);
float pf = posecal.perp()/posecal.mag();
et=ene*pf;


// print some debug info
if (debug_) {

int ix,iy,iz;
ix=0,iy=0,iz=0;

// ref: DataFormats/EcalDetId/interface/EcalSubdetector.h
// EcalBarrel
if (ecaldet.subdetId()==1) {
EBDetId ebdet(ecalit);
ix=ebdet.ieta();
iy=ebdet.iphi();
iz=ebdet.zside();

edm::LogInfo("EcalBadCalibFilter") << "DetId=" << ecaldet.rawId();
edm::LogInfo("EcalBadCalibFilter") << "ieta=" << ix << " iphi=" << iy << " iz=" << iz;
edm::LogInfo("EcalBadCalibFilter") << "Et=" << et << " thresh=" << ecalMin_;
}

// EcalEndcap
if (ecaldet.subdetId()==2) {
EEDetId eedet(ecalit);
ix=eedet.ix();
iy=eedet.iy();
iz=eedet.zside();

edm::LogInfo("EcalBadCalibFilter") << "DetId=" << ecaldet.rawId();
edm::LogInfo("EcalBadCalibFilter") << "ix=" << ix << " iy=" << iy << " iz=" << iz;
edm::LogInfo("EcalBadCalibFilter") << "Et=" << et << " thresh=" << ecalMin_;
}

}


// if transverse energy is above threshold and channel has bad IC
if (et>ecalMin_) {
pass=false;
if (debug_) {
edm::LogInfo("EcalBadCalibFilter") << "DUMP EVENT" << std::endl;
}
}

}


// print the decision if event is bad
if (pass==false && debug_) edm::LogInfo("EcalBadCalibFilter") << "REJECT EVENT!!!";

iEvent.put(std::make_unique<bool>(pass));

return taggingMode_ || pass;
}


#include "FWCore/Framework/interface/MakerMacros.h"

DEFINE_FWK_MODULE(EcalBadCalibFilter);
32 changes: 32 additions & 0 deletions RecoMET/METFilters/python/ecalBadCalibFilter_cfi.py
@@ -0,0 +1,32 @@
import FWCore.ParameterSet.Config as cms

ecalBadCalibFilter = cms.EDFilter(
"EcalBadCalibFilter",

# use this if using AOD:
# the Ecal rechit collection found in AOD
EcalRecHitSource = cms.InputTag('reducedEcalRecHitsEE'),


# use this if using MINIAOD:
# the Ecal rechit collection found in MINIAOD
# EERecHitSource = cms.InputTag('reducedEgamma','reducedEERecHits'),



# minimum rechit et to flag as bad:
ecalMinEt = cms.double(50.),
# DetId of bad channel:
baddetEcal = cms.vuint32(),

taggingMode = cms.bool(False),
#prints debug info for each channel if set to true
debug = cms.bool(False),
)

from Configuration.Eras.Modifier_run2_common_cff import run2_common
run2_common.toModify(ecalBadCalibFilter, baddetEcal = [872439604,872422825,872420274,872423218,
872423215,872416066,872435036,872439336,
872420273,872436907,872420147,872439731,
872436657,872420397,872439732,872439339,
872439603])
4 changes: 4 additions & 0 deletions RecoMET/METFilters/python/metFilters_cff.py
Expand Up @@ -37,6 +37,9 @@
## The ECAL laser correction filter
from RecoMET.METFilters.ecalLaserCorrFilter_cfi import *

## The ECAL bad calibration filter ____________________________________________||
from RecoMET.METFilters.ecalBadCalibFilter_cfi import *

## The Good vertices collection needed by the tracking failure filter ________||
goodVertices = cms.EDFilter(
"VertexSelector",
Expand Down Expand Up @@ -102,6 +105,7 @@
#globalTightHalo2016Filter*
#globalSuperTightHalo2016Filter*
EcalDeadCellTriggerPrimitiveFilter*
ecalBadCalibFilter*
# *goodVertices * trackingFailureFilter *
eeBadScFilter*
# ecalLaserCorrFilter *
Expand Down

0 comments on commit e2c95d1

Please sign in to comment.