Skip to content

Commit

Permalink
Merge pull request #32462 from guitargeek/slimmedPhotons_HI_1
Browse files Browse the repository at this point in the history
Correctly add HIPhotonIsolation to pat::photon
  • Loading branch information
cmsbuild committed Dec 19, 2020
2 parents 393431e + e299916 commit d495a3c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 50 deletions.
14 changes: 10 additions & 4 deletions RecoEgamma/EgammaPhotonProducers/python/reducedEgamma_cfi.py
Expand Up @@ -32,6 +32,8 @@
photonFloatValueMapOutput = cms.vstring(),
ootPhotonFloatValueMapSources = cms.VInputTag(),
ootPhotonFloatValueMapOutput = cms.vstring(),
hiPhotonIsolationMapInput = cms.InputTag(""),
hiPhotonIsolationMapOutput = cms.string(""),
gsfElectronFloatValueMapSources = cms.VInputTag(),
gsfElectronFloatValueMapOutput = cms.vstring(),
applyPhotonCalibOnData = cms.bool(False),
Expand Down Expand Up @@ -116,9 +118,13 @@
run2_miniAOD_94XFall17 | run2_miniAOD_80XLegacy | run2_miniAOD_UL).makeProcessModifier(calibrateReducedEgamma)

from Configuration.ProcessModifiers.pp_on_AA_cff import pp_on_AA
pp_on_AA.toModify(reducedEgamma,
ootPhotons = cms.InputTag(""),

pp_on_AA.toModify(
reducedEgamma,
ootPhotons = "",
keepPhotons = "pt>15 && abs(eta)<2.5",
slimRelinkPhotons = "pt>15 && abs(eta)<2.5",
relinkPhotons = "pt>15 && abs(eta)<2.5"
)
relinkPhotons = "pt>15 && abs(eta)<2.5",
hiPhotonIsolationMapInput = "photonIsolationHIProducerppGED",
hiPhotonIsolationMapOutput = "photonIsolationHIProducerppGED"
)
92 changes: 48 additions & 44 deletions RecoEgamma/EgammaPhotonProducers/src/ReducedEGProducer.cc
Expand Up @@ -16,6 +16,7 @@
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/EgammaCandidates/interface/Conversion.h"
#include "DataFormats/EgammaCandidates/interface/HIPhotonIsolation.h"
#include "DataFormats/EgammaCandidates/interface/Photon.h"
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
#include "DataFormats/EgammaCandidates/interface/PhotonCore.h"
Expand Down Expand Up @@ -47,7 +48,6 @@
class ReducedEGProducer : public edm::stream::EDProducer<> {
public:
ReducedEGProducer(const edm::ParameterSet& ps);
~ReducedEGProducer() override;

void beginRun(edm::Run const&, const edm::EventSetup&) final;
void produce(edm::Event& evt, const edm::EventSetup& es) final;
Expand Down Expand Up @@ -166,6 +166,9 @@ class ReducedEGProducer : public edm::stream::EDProducer<> {
std::vector<edm::EDGetTokenT<edm::ValueMap<float>>> ootPhotonFloatValueMapTs_;
std::vector<edm::EDGetTokenT<edm::ValueMap<float>>> gsfElectronFloatValueMapTs_;

const edm::EDGetTokenT<reco::HIPhotonIsolationMap> recoHIPhotonIsolationMapInputToken_;
const std::string recoHIPhotonIsolationMapOutputName_;

const bool applyPhotonCalibOnData_;
const bool applyPhotonCalibOnMC_;
const bool applyGsfElectronCalibOnData_;
Expand Down Expand Up @@ -238,6 +241,13 @@ ReducedEGProducer::ReducedEGProducer(const edm::ParameterSet& config)
config.getParameter<edm::InputTag>("photonsPFValMap"))),
gsfElectronPfCandMapT_(consumes<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(
config.getParameter<edm::InputTag>("gsfElectronsPFValMap"))),
recoHIPhotonIsolationMapInputToken_{
!config.getParameter<edm::InputTag>("hiPhotonIsolationMapInput").label().empty()
? consumes<reco::HIPhotonIsolationMap>(config.getParameter<edm::InputTag>("hiPhotonIsolationMapInput"))
: edm::EDGetTokenT<reco::HIPhotonIsolationMap>{}},
recoHIPhotonIsolationMapOutputName_{!recoHIPhotonIsolationMapInputToken_.isUninitialized()
? config.getParameter<std::string>("hiPhotonIsolationMapOutput")
: std::string{}},
//calibration flags
applyPhotonCalibOnData_(config.getParameter<bool>("applyPhotonCalibOnData")),
applyPhotonCalibOnMC_(config.getParameter<bool>("applyPhotonCalibOnMC")),
Expand Down Expand Up @@ -285,32 +295,23 @@ ReducedEGProducer::ReducedEGProducer(const edm::ParameterSet& config)
if (not aTag.label().empty())
ootPhotonT_ = consumes<reco::PhotonCollection>(aTag);

const std::vector<edm::InputTag>& photonidinputs = config.getParameter<std::vector<edm::InputTag>>("photonIDSources");
for (const edm::InputTag& tag : photonidinputs) {
for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("photonIDSources")) {
photonIdTs_.emplace_back(consumes<edm::ValueMap<bool>>(tag));
}

const std::vector<edm::InputTag>& gsfelectronidinputs =
config.getParameter<std::vector<edm::InputTag>>("gsfElectronIDSources");
for (const edm::InputTag& tag : gsfelectronidinputs) {
for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("gsfElectronIDSources")) {
gsfElectronIdTs_.emplace_back(consumes<edm::ValueMap<float>>(tag));
}

const std::vector<edm::InputTag>& photonpfclusterisoinputs =
config.getParameter<std::vector<edm::InputTag>>("photonFloatValueMapSources");
for (const edm::InputTag& tag : photonpfclusterisoinputs) {
for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("photonFloatValueMapSources")) {
photonFloatValueMapTs_.emplace_back(consumes<edm::ValueMap<float>>(tag));
}

const std::vector<edm::InputTag>& ootphotonpfclusterisoinputs =
config.getParameter<std::vector<edm::InputTag>>("ootPhotonFloatValueMapSources");
for (const edm::InputTag& tag : ootphotonpfclusterisoinputs) {
for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("ootPhotonFloatValueMapSources")) {
ootPhotonFloatValueMapTs_.emplace_back(consumes<edm::ValueMap<float>>(tag));
}

const std::vector<edm::InputTag>& gsfelectronpfclusterisoinputs =
config.getParameter<std::vector<edm::InputTag>>("gsfElectronFloatValueMapSources");
for (const edm::InputTag& tag : gsfelectronpfclusterisoinputs) {
for (const edm::InputTag& tag : config.getParameter<std::vector<edm::InputTag>>("gsfElectronFloatValueMapSources")) {
gsfElectronFloatValueMapTs_.emplace_back(consumes<edm::ValueMap<float>>(tag));
}

Expand Down Expand Up @@ -368,10 +369,11 @@ ReducedEGProducer::ReducedEGProducer(const edm::ParameterSet& config)
for (const std::string& outid : outGsfElectronFloatValueMaps_) {
produces<edm::ValueMap<float>>(outid);
}
if (!recoHIPhotonIsolationMapInputToken_.isUninitialized()) {
produces<reco::HIPhotonIsolationMap>(recoHIPhotonIsolationMapOutputName_);
}
}

ReducedEGProducer::~ReducedEGProducer() {}

void ReducedEGProducer::beginRun(edm::Run const& run, const edm::EventSetup& iSetup) { hcalHitSel_.setup(iSetup); }

void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
Expand Down Expand Up @@ -501,6 +503,12 @@ void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
std::vector<std::vector<float>> ootPhotonFloatValueMapVals(ootPhotonFloatValueMapHandles.size());
std::vector<std::vector<float>> gsfElectronFloatValueMapVals(gsfElectronFloatValueMapHandles.size());

// HI photon iso value maps
reco::HIPhotonIsolationMap const* recoHIPhotonIsolationMapInputValueMap =
!recoHIPhotonIsolationMapInputToken_.isUninitialized() ? &theEvent.get(recoHIPhotonIsolationMapInputToken_)
: nullptr;
std::vector<reco::HIPhotonIsolation> recoHIPhotonIsolationMapInputVals;

//loop over photons and fill maps
index = -1;
for (const auto& photon : *photonHandle) {
Expand Down Expand Up @@ -535,6 +543,11 @@ void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
photonFloatValueMapVals[subindex++].push_back((*photonFloatValueMapHandle)[photonref]);
}

// HI photon isolation
if (!recoHIPhotonIsolationMapInputToken_.isUninitialized()) {
recoHIPhotonIsolationMapInputVals.push_back((*recoHIPhotonIsolationMapInputValueMap)[photonref]);
}

//link photon core
const reco::PhotonCoreRef& photonCore = photon.photonCore();
linkCore(photonCore, *photonCores, photonCoreMap);
Expand Down Expand Up @@ -655,9 +668,7 @@ void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
}

// Save additional ambiguous gsf tracks in a map:
for (reco::GsfTrackRefVector::const_iterator igsf = gsfElectron.ambiguousGsfTracksBegin();
igsf != gsfElectron.ambiguousGsfTracksEnd();
++igsf) {
for (auto igsf = gsfElectron.ambiguousGsfTracksBegin(); igsf != gsfElectron.ambiguousGsfTracksEnd(); ++igsf) {
const reco::GsfTrackRef& ambigGsfTrack = *igsf;
if (!gsfTrackMap.count(ambigGsfTrack)) {
gsfTracks->push_back(*ambigGsfTrack);
Expand Down Expand Up @@ -793,10 +804,8 @@ void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& the

//CaloClusters
//put calocluster output collections in event and get orphan handles to create ptrs
const edm::OrphanHandle<reco::CaloClusterCollection>& outEBEEClusterHandle =
theEvent.put(std::move(ebeeClusters), outEBEEClusters_);
const edm::OrphanHandle<reco::CaloClusterCollection>& outESClusterHandle =
theEvent.put(std::move(esClusters), outESClusters_);
const auto& outEBEEClusterHandle = theEvent.put(std::move(ebeeClusters), outEBEEClusters_);
const auto& outESClusterHandle = theEvent.put(std::move(esClusters), outESClusters_);
;

//Loop over SuperClusters and relink GEDPhoton + GSFElectron CaloClusters
Expand All @@ -818,14 +827,10 @@ void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
}
}
//put superclusters and conversions in the event
const edm::OrphanHandle<reco::SuperClusterCollection>& outSuperClusterHandle =
theEvent.put(std::move(superClusters), outSuperClusters_);
const edm::OrphanHandle<reco::ConversionCollection>& outConversionHandle =
theEvent.put(std::move(conversions), outConversions_);
const edm::OrphanHandle<reco::ConversionCollection>& outSingleConversionHandle =
theEvent.put(std::move(singleConversions), outSingleConversions_);
const edm::OrphanHandle<reco::GsfTrackCollection>& outGsfTrackHandle =
theEvent.put(std::move(gsfTracks), outGsfTracks_);
const auto& outSuperClusterHandle = theEvent.put(std::move(superClusters), outSuperClusters_);
const auto& outConversionHandle = theEvent.put(std::move(conversions), outConversions_);
const auto& outSingleConversionHandle = theEvent.put(std::move(singleConversions), outSingleConversions_);
const auto& outGsfTrackHandle = theEvent.put(std::move(gsfTracks), outGsfTracks_);

//Loop over PhotonCores and relink GEDPhoton SuperClusters (and conversions)
for (reco::PhotonCore& photonCore : *photonCores) {
Expand Down Expand Up @@ -858,13 +863,11 @@ void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
}

//put photoncores and gsfelectroncores into the event
const edm::OrphanHandle<reco::PhotonCoreCollection>& outPhotonCoreHandle =
theEvent.put(std::move(photonCores), outPhotonCores_);
const auto& outPhotonCoreHandle = theEvent.put(std::move(photonCores), outPhotonCores_);
edm::OrphanHandle<reco::PhotonCoreCollection> outOOTPhotonCoreHandle;
if (!ootPhotonT_.isUninitialized())
outOOTPhotonCoreHandle = theEvent.put(std::move(ootPhotonCores), outOOTPhotonCores_);
const edm::OrphanHandle<reco::GsfElectronCoreCollection>& outgsfElectronCoreHandle =
theEvent.put(std::move(gsfElectronCores), outGsfElectronCores_);
const auto& outgsfElectronCoreHandle = theEvent.put(std::move(gsfElectronCores), outGsfElectronCores_);

//loop over photons, oot photons, and electrons and relink the cores
for (reco::Photon& photon : *photons) {
Expand All @@ -884,9 +887,7 @@ void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
// Also in this loop let's relink ambiguous tracks
std::vector<reco::GsfTrackRef> ambigTracksInThisElectron;
// Here we loop over the ambiguous tracks and save them in a vector
for (reco::GsfTrackRefVector::const_iterator igsf = gsfElectron.ambiguousGsfTracksBegin();
igsf != gsfElectron.ambiguousGsfTracksEnd();
++igsf) {
for (auto igsf = gsfElectron.ambiguousGsfTracksBegin(); igsf != gsfElectron.ambiguousGsfTracksEnd(); ++igsf) {
ambigTracksInThisElectron.push_back(*igsf);
}

Expand All @@ -911,12 +912,11 @@ void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
}

//(finally) store the output photon and electron collections
const edm::OrphanHandle<reco::PhotonCollection>& outPhotonHandle = theEvent.put(std::move(photons), outPhotons_);
const auto& outPhotonHandle = theEvent.put(std::move(photons), outPhotons_);
edm::OrphanHandle<reco::PhotonCollection> outOOTPhotonHandle;
if (!ootPhotonT_.isUninitialized())
outOOTPhotonHandle = theEvent.put(std::move(ootPhotons), outOOTPhotons_);
const edm::OrphanHandle<reco::GsfElectronCollection>& outGsfElectronHandle =
theEvent.put(std::move(gsfElectrons), outGsfElectrons_);
const auto& outGsfElectronHandle = theEvent.put(std::move(gsfElectrons), outGsfElectrons_);

//still need to output relinked valuemaps

Expand Down Expand Up @@ -970,6 +970,11 @@ void ReducedEGProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
}
}

// HI photon iso value maps
if (!recoHIPhotonIsolationMapInputToken_.isUninitialized()) {
fillMap(outPhotonHandle, recoHIPhotonIsolationMapInputVals, theEvent, recoHIPhotonIsolationMapOutputName_);
}

//electron iso value maps
index = 0;
for (auto const& vals : gsfElectronFloatValueMapVals) {
Expand Down Expand Up @@ -1250,7 +1255,6 @@ void ReducedEGProducer::calibrateElectron(reco::GsfElectron& electron,
electron.setCorrectedEcalEnergy(newEcalEnergy);
electron.setCorrectedEcalEnergyError(newEcalEnergyErr);

math::XYZTLorentzVector newP4 =
math::XYZTLorentzVector(oldP4.x() * corr, oldP4.y() * corr, oldP4.z() * corr, newEnergy);
math::XYZTLorentzVector newP4{oldP4.x() * corr, oldP4.y() * corr, oldP4.z() * corr, newEnergy};
electron.correctMomentum(newP4, electron.trackMomentumError(), newEnergyErr);
}
Expand Up @@ -141,8 +141,7 @@ def setup_mva(val_pset,cat_pset,prod_name,mva_name):
modifierName = cms.string('EGExtraInfoModifierFromHIPhotonIsolationValueMaps'),
electron_config = cms.PSet(),
photon_config = cms.PSet(
photonSrc = cms.InputTag("gedPhotons"),
photonIsolationHI = cms.InputTag("photonIsolationHIProducerppGED")
photonIsolationHI = cms.InputTag("reducedEgamma:photonIsolationHIProducerppGED")
)
)

Expand Down

0 comments on commit d495a3c

Please sign in to comment.