Skip to content

Commit

Permalink
Merge branch 'cat80x' of github.com:vallot/CATTools into cat80x
Browse files Browse the repository at this point in the history
  • Loading branch information
tt8888tt committed Feb 26, 2017
2 parents 92e0a45 + e0ac9ef commit bbec7f9
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 57 deletions.
77 changes: 77 additions & 0 deletions CatProducer/plugins/BadECALSlewRateMitigationFilter2016.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "DataFormats/Common/interface/EDCollection.h"
#include "DataFormats/DetId/interface/DetId.h"

#include <memory>
#include <vector>
#include <string>

using namespace std;

class BadECALSlewRateMitigationFilter2016 : public edm::stream::EDFilter<>
{
public:
BadECALSlewRateMitigationFilter2016(const edm::ParameterSet& pset);
~BadECALSlewRateMitigationFilter2016() {};

bool filter(edm::Event& event, const edm::EventSetup& eventSetup) override;

private:
edm::EDGetTokenT<bool> dupECALClusterToken_;
edm::EDGetTokenT<edm::EDCollection<DetId>> hitsNotReplacedToken_;

const bool doFilter_;
};

BadECALSlewRateMitigationFilter2016::BadECALSlewRateMitigationFilter2016(const edm::ParameterSet& pset):
doFilter_(pset.getUntrackedParameter<bool>("doFilter", false))
{
dupECALClusterToken_ = consumes<bool>(edm::InputTag("particleFlowEGammaGSFixed:dupECALClusters"));
hitsNotReplacedToken_ = consumes<edm::EDCollection<DetId>>(edm::InputTag("ecalMultiAndGSGlobalRecHitEB:hitsNotReplaced"));

produces<bool>();
}

bool BadECALSlewRateMitigationFilter2016::filter(edm::Event& event, const edm::EventSetup& eventSetup)
{
bool isAccepted = true;

do {
if ( !event.isRealData() ) break; // always accept MC

edm::Handle<bool> dupECALClusterHandle;
event.getByToken(dupECALClusterToken_, dupECALClusterHandle);

edm::Handle<edm::EDCollection<DetId>> hitsNotReplacedHandle;
event.getByToken(hitsNotReplacedToken_, hitsNotReplacedHandle);

if ( dupECALClusterHandle.isValid() and *dupECALClusterHandle == true ) {
// Duplicated ECAL clusters must be false
isAccepted = false;
break;
}

if ( hitsNotReplacedHandle.isValid() and !hitsNotReplacedHandle->empty() ) {
// There should no "hits not replaced"
isAccepted = false;
break;
}

} while (false);

event.put(std::move(std::make_unique<bool>(isAccepted)));

if ( !doFilter_ ) return true;
return isAccepted;
}

DEFINE_FWK_MODULE(BadECALSlewRateMitigationFilter2016);
27 changes: 0 additions & 27 deletions CatProducer/plugins/CATElectronProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace cat {
edm::EDGetTokenT<pat::PackedCandidateCollection> pfSrc_;
edm::EDGetTokenT<reco::BeamSpot> beamLineSrc_;
edm::EDGetTokenT<double> rhoLabel_;
edm::EDGetTokenT<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit>>> ebRecHitsToken_;

bool runOnMC_;

Expand Down Expand Up @@ -142,7 +141,6 @@ cat::CATElectronProducer::CATElectronProducer(const edm::ParameterSet & iConfig)
pfSrc_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfSrc"))),
beamLineSrc_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"))),
rhoLabel_(consumes<double>(iConfig.getParameter<edm::InputTag>("rhoLabel"))),
ebRecHitsToken_(consumes<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit>>>(iConfig.getParameter<edm::InputTag>("ebRecHits"))),
electronIDs_(iConfig.getParameter<std::vector<std::string> >("electronIDs"))
{

Expand Down Expand Up @@ -183,16 +181,11 @@ cat::CATElectronProducer::produce(edm::Event & iEvent, const edm::EventSetup & i
iEvent.getByToken(rhoLabel_, rhoHandle);
double rhoIso = std::max(*(rhoHandle.product()), 0.0);

edm::Handle<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit>>> ebRecHitsHandle;

GlobalPoint pVertex(pv.position().x(),pv.position().y(),pv.position().z());

if (runOnMC_){
iEvent.getByToken(mcLabel_,genParticles);
}
else {
iEvent.getByToken(ebRecHitsToken_, ebRecHitsHandle);
}

ESHandle<TransientTrackBuilder> trackBuilder;
iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",trackBuilder);
Expand All @@ -216,26 +209,6 @@ cat::CATElectronProducer::produce(edm::Event & iEvent, const edm::EventSetup & i
// nan protection - smearing fails for soft electrons
if ( std::isnan(std::abs(aElectron.p())) ) aElectron = *unsmearedElecRef;

// Redisual scale correction is needed for Moriond17 analysis. see https://twiki.cern.ch/twiki/bin/view/CMS/EGMSmearer
// this residual correction have to be applied ONLY FOR DATA with BARREL RecHits
if ( !runOnMC_ ) {
// FIXME: maybe it should be removed in the future
DetId detid = aPatElectron.superCluster()->seed()->seed();
const EcalRecHit * rh = 0;
if (detid.subdetId() == EcalBarrel) {
auto rh_i = ebRecHitsHandle->find(detid);
if( rh_i != ebRecHitsHandle->end()) rh = &(*rh_i);
else rh = NULL;
}
if ( rh ) {
double Ecorr=1;
if(rh->energy() > 200 && rh->energy()<300) Ecorr=1.0199;
else if(rh->energy()>300 && rh->energy()<400) Ecorr= 1.052;
else if(rh->energy()>400 && rh->energy()<500) Ecorr = 1.015;
aElectron.setP4(Ecorr*aElectron.p4());
}
}

if (runOnMC_){
aElectron.setGenParticleRef(aPatElectron.genParticleRef());
aElectron.setMCMatched( mcMatch( aElectron.p4(), genParticles ) );
Expand Down
27 changes: 0 additions & 27 deletions CatProducer/plugins/CATPhotonProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ namespace cat {
edm::EDGetTokenT<reco::GenParticleCollection> mcLabel_;

edm::EDGetTokenT<double> rhoLabel_;
edm::EDGetTokenT<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit>>> ebRecHitsToken_;

bool runOnMC_;

Expand All @@ -78,7 +77,6 @@ cat::CATPhotonProducer::CATPhotonProducer(const edm::ParameterSet & iConfig) :
vertexLabel_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexLabel"))),
mcLabel_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("mcLabel"))),
rhoLabel_(consumes<double>(iConfig.getParameter<edm::InputTag>("rhoLabel"))),
ebRecHitsToken_(consumes<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit>>>(iConfig.getParameter<edm::InputTag>("ebRecHits"))),
photonIDs_(iConfig.getParameter<std::vector<std::string> >("photonIDs"))
{
produces<std::vector<cat::Photon> >();
Expand Down Expand Up @@ -111,15 +109,10 @@ cat::CATPhotonProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSe
iEvent.getByToken(rhoLabel_, rhoHandle);
double rhoIso = std::max(*(rhoHandle.product()), 0.0);

edm::Handle<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit>>> ebRecHitsHandle;

Handle<reco::GenParticleCollection> genParticles;
if (runOnMC_){
iEvent.getByToken(mcLabel_,genParticles);
}
else {
iEvent.getByToken(ebRecHitsToken_, ebRecHitsHandle);
}

std::vector<edm::Handle<edm::ValueMap<bool> > > idhandles;
std::vector<pat::Photon::IdPair> ids;
Expand All @@ -139,26 +132,6 @@ cat::CATPhotonProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSe
auto phosRef = src->refAt(j);
auto unsmearedPhotRef = unsmearedPhotHandle->refAt(j);

// Redisual scale correction is needed for Moriond17 analysis. see https://twiki.cern.ch/twiki/bin/view/CMS/EGMSmearer
// this residual correction have to be applied ONLY FOR DATA with BARREL RecHits
if ( !runOnMC_ ) {
// FIXME: maybe it should be removed in the future
DetId detid = aPatPhoton.superCluster()->seed()->seed();
const EcalRecHit * rh = 0;
if (detid.subdetId() == EcalBarrel) {
auto rh_i = ebRecHitsHandle->find(detid);
if( rh_i != ebRecHitsHandle->end()) rh = &(*rh_i);
else rh = NULL;
}
if ( rh ) {
double Ecorr=1;
if(rh->energy() > 200 && rh->energy()<300) Ecorr=1.0199;
else if(rh->energy()>300 && rh->energy()<400) Ecorr= 1.052;
else if(rh->energy()>400 && rh->energy()<500) Ecorr = 1.015;
aPhoton.setP4(Ecorr*aPhoton.p4());
}
}

if (runOnMC_){
aPhoton.setGenParticleRef(aPatPhoton.genParticleRef());
if(mcMatch(aPatPhoton.p4(), genParticles ) == 1) aPhoton.setMCMatched( true);
Expand Down
2 changes: 2 additions & 0 deletions CatProducer/python/catTools_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def catTool(process, runOnMC=True, useMiniAOD=True):
from FWCore.PythonUtilities.LumiList import LumiList
process.lumiMask = cms.EDFilter("LumiMaskFilter",
LumiSections = LumiList('%s/src/CATTools/CatProducer/data/LumiMask/%s.txt'%(os.environ['CMSSW_BASE'], cat.lumiJSON)).getVLuminosityBlockRange())

process.load("CATTools.CatProducer.eventCleaning.badECALSlewRateMitigationFilter2016_cfi")

useJECfile = True
jecFiles = cat.JetEnergyCorrection
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import FWCore.ParameterSet.Config as cms

badECALSlewRateMitigationFilter2016 = cms.EDFilter("BadECALSlewRateMitigationFilter2016",
)
1 change: 0 additions & 1 deletion CatProducer/python/producers/electronProducer_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
pfSrc = cms.InputTag("packedPFCandidates"),
beamLineSrc = cms.InputTag("offlineBeamSpot"),
rhoLabel = cms.InputTag("fixedGridRhoAll"),
ebRecHits = cms.InputTag("reducedEgamma","reducedEBRecHits"),
electronIDSources = cms.PSet(),
electronIDs = cms.vstring(), ## Defined in CatProducer/python/patTools/egmVersionedID_cff.py
)
1 change: 0 additions & 1 deletion CatProducer/python/producers/photonProducer_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
src = cms.InputTag("slimmedPhotons"),
unsmearedPhotons = cms.InputTag("slimmedPhotons"),
rhoLabel = cms.InputTag("fixedGridRhoFastjetAll"),
ebRecHits = cms.InputTag("reducedEgamma","reducedEBRecHits"),
mcLabel = cms.InputTag("prunedGenParticles"),
vertexLabel = cms.InputTag('catVertex'),
beamLineSrc = cms.InputTag("offlineBeamSpot"),
Expand Down
2 changes: 2 additions & 0 deletions CatProducer/python/producers/triggerProducer_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
"Flag_HBHENoiseIsoFilter",
"Flag_EcalDeadCellTriggerPrimitiveFilter",
"Flag_eeBadScFilter",
"Flag_badMuons", "Flag_duplicateMuons", "Flag_noBadMuons",
),
bools = cms.VInputTag(
cms.InputTag("BadChargedCandidateFilter"),
cms.InputTag("BadPFMuonFilter"),
cms.InputTag("badECALSlewRateMitigationFilter2016"),
),
),
)
2 changes: 1 addition & 1 deletion Validation/python/commonTestInput_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
commonTestMiniAODs = {
"sig":cms.untracked.vstring("root://cmsxrootd.fnal.gov//store/mc/RunIISummer16MiniAODv2/TT_TuneCUETP8M2T4_13TeV-powheg-pythia8/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6-v1/50000/0693E0E7-97BE-E611-B32F-0CC47A78A3D8.root",),
"bkg":cms.untracked.vstring("root://cmsxrootd.fnal.gov//store/mc/RunIISummer16MiniAODv2/WJetsToLNu_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/MINIAODSIM/PUMoriond17_80X_mcRun2_asymptotic_2016_TrancheIV_v6-v1/120000/0AF0207B-EFBE-E611-B4BE-0CC47A7FC858.root",),
"data":cms.untracked.vstring("root://cmsxrootd.fnal.gov///store/data/Run2016C/SingleMuon/MINIAOD/23Sep2016-v1/80000/82AF08FC-3B87-E611-A209-FA163E3F4268.root",),
"data":cms.untracked.vstring("root://cmsxrootd.fnal.gov///store/data/Run2016H/MuonEG/MINIAOD/03Feb2017_ver2-v1/100000/044366C7-4AEE-E611-8CF7-0025905B856E.root",),
}

0 comments on commit bbec7f9

Please sign in to comment.