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

Change the isolation in the reco::Photon to the value computed by CITK #16759

Merged
31 changes: 31 additions & 0 deletions PhysicsTools/IsolationAlgos/plugins/CITKPFIsolationSumProducer.cc
Expand Up @@ -40,6 +40,8 @@ namespace citk {
const edm::EventSetup&) override final;

void produce(edm::Event&, const edm::EventSetup&) override final;

static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);

private:
// datamembers
Expand Down Expand Up @@ -171,6 +173,35 @@ namespace citk {
}
}
}

// ParameterSet description for module
void PFIsolationSumProducer::fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
edm::ParameterSetDescription iDesc;
iDesc.setComment("isolation sum producer");

iDesc.add<edm::InputTag>("srcToIsolate", edm::InputTag("no default"))->setComment("calculate isolation for this collection");
iDesc.add<edm::InputTag>("srcForIsolationCone", edm::InputTag("no default"))->setComment("collection for the isolation calculation: like particleFlow ");

edm::ParameterSetDescription descIsoConeDefinitions;
descIsoConeDefinitions.add<std::string>("isolationAlgo", "no default");
descIsoConeDefinitions.add<double>("coneSize", 0.3);
descIsoConeDefinitions.add<std::string>("isolateAgainst", "no default");
descIsoConeDefinitions.add<std::vector<unsigned>>("miniAODVertexCodes", {2,3});
descIsoConeDefinitions.addOptional<double>("VetoConeSizeBarrel", 0.0);
descIsoConeDefinitions.addOptional<double>("VetoConeSizeEndcaps", 0.0);
descIsoConeDefinitions.addOptional<int>("vertexIndex",0);
descIsoConeDefinitions.addOptional<edm::InputTag>("particleBasedIsolation",edm::InputTag("no default"))->setComment("map for footprint removal that is used for photons");


std::vector<edm::ParameterSet> isolationConeDefinitions;
edm::ParameterSet chargedHadrons, neutralHadrons,photons;
isolationConeDefinitions.push_back(chargedHadrons);
isolationConeDefinitions.push_back(neutralHadrons);
isolationConeDefinitions.push_back(photons);
iDesc.addVPSet("isolationConeDefinitions", descIsoConeDefinitions, isolationConeDefinitions);

descriptions.add("CITKPFIsolationSumProducer", iDesc);
}
}

#endif
@@ -0,0 +1,25 @@
import FWCore.ParameterSet.Config as cms

IsoConeDefinitions = cms.VPSet(cms.PSet( isolationAlgo = cms.string('PhotonPFIsolationWithMapBasedVeto'),
coneSize = cms.double(0.3),
isolateAgainst = cms.string('h+'),
miniAODVertexCodes = cms.vuint32(2,3),
vertexIndex = cms.int32(0),
particleBasedIsolation = cms.InputTag("particleBasedIsolation", "gedPhotons"),

),
cms.PSet( isolationAlgo = cms.string('PhotonPFIsolationWithMapBasedVeto'),
coneSize = cms.double(0.3),
isolateAgainst = cms.string('h0'),
miniAODVertexCodes = cms.vuint32(2,3),
vertexIndex = cms.int32(0),
particleBasedIsolation = cms.InputTag("particleBasedIsolation", "gedPhotons"),
),
cms.PSet( isolationAlgo = cms.string('PhotonPFIsolationWithMapBasedVeto'),
coneSize = cms.double(0.3),
isolateAgainst = cms.string('gamma'),
miniAODVertexCodes = cms.vuint32(2,3),
vertexIndex = cms.int32(0),
particleBasedIsolation = cms.InputTag("particleBasedIsolation", "gedPhotons"),
)
)
Expand Up @@ -2,7 +2,7 @@

from CommonTools.ParticleFlow.pfNoPileUpIso_cff import *
from CommonTools.ParticleFlow.pfParticleSelection_cff import *
from RecoEgamma.EgammaIsolationAlgos.egmPhotonIsolationMiniAOD_cff import IsoConeDefinitions
from RecoEgamma.EgammaIsolationAlgos.egmIsoConeDefinitions_cfi import IsoConeDefinitions

pfNoPileUpCandidates = pfAllChargedHadrons.clone()
pfNoPileUpCandidates.pdgId.extend(pfAllNeutralHadronsAndPhotons.pdgId)
Expand Down
@@ -1,28 +1,6 @@
import FWCore.ParameterSet.Config as cms

IsoConeDefinitions = cms.VPSet(cms.PSet( isolationAlgo = cms.string('PhotonPFIsolationWithMapBasedVeto'),
coneSize = cms.double(0.3),
isolateAgainst = cms.string('h+'),
miniAODVertexCodes = cms.vuint32(2,3),
vertexIndex = cms.int32(0),
particleBasedIsolation = cms.InputTag("particleBasedIsolation", "gedPhotons"),

),
cms.PSet( isolationAlgo = cms.string('PhotonPFIsolationWithMapBasedVeto'),
coneSize = cms.double(0.3),
isolateAgainst = cms.string('h0'),
miniAODVertexCodes = cms.vuint32(2,3),
vertexIndex = cms.int32(0),
particleBasedIsolation = cms.InputTag("particleBasedIsolation", "gedPhotons"),
),
cms.PSet( isolationAlgo = cms.string('PhotonPFIsolationWithMapBasedVeto'),
coneSize = cms.double(0.3),
isolateAgainst = cms.string('gamma'),
miniAODVertexCodes = cms.vuint32(2,3),
vertexIndex = cms.int32(0),
particleBasedIsolation = cms.InputTag("particleBasedIsolation", "gedPhotons"),
)
)
from RecoEgamma.EgammaIsolationAlgos.egmIsoConeDefinitions_cfi import IsoConeDefinitions

egmPhotonIsolationMiniAOD = cms.EDProducer( "CITKPFIsolationSumProducer",
srcToIsolate = cms.InputTag("slimmedPhotons"),
Expand Down
10 changes: 8 additions & 2 deletions RecoEgamma/EgammaPhotonProducers/interface/GEDPhotonProducer.h
Expand Up @@ -37,6 +37,7 @@
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"


// GEDPhotonProducer inherits from EDProducer, so it can be a module:
class GEDPhotonProducer : public edm::stream::EDProducer<> {

Expand Down Expand Up @@ -72,7 +73,7 @@ class GEDPhotonProducer : public edm::stream::EDProducer<> {
edm::ValueMap<reco::PhotonRef> pfEGCandToPhotonMap,
edm::Handle< reco::VertexCollection >& pvVertices,
reco::PhotonCollection & outputCollection,
int& iSC);
int& iSC, const edm::Handle<edm::ValueMap<float>>& chargedHadrons_, const edm::Handle<edm::ValueMap<float>>& neutralHadrons_, const edm::Handle<edm::ValueMap<float>>& photons_);


// std::string PhotonCoreCollection_;
Expand All @@ -88,12 +89,17 @@ class GEDPhotonProducer : public edm::stream::EDProducer<> {
edm::EDGetTokenT<reco::PFCandidateCollection> pfCandidates_;
edm::EDGetTokenT<CaloTowerCollection> hcalTowers_;
edm::EDGetTokenT<reco::VertexCollection> vertexProducer_;
//for isolation with map-based veto
edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef > > > particleBasedIsolationToken;
//photon isolation sums
edm::EDGetTokenT<edm::ValueMap<float> > phoChargedIsolationToken_CITK;
edm::EDGetTokenT<edm::ValueMap<float> > phoNeutralHadronIsolationToken_CITK;
edm::EDGetTokenT<edm::ValueMap<float> > phoPhotonIsolationToken_CITK;

std::string conversionProducer_;
std::string conversionCollection_;
std::string valueMapPFCandPhoton_;

PFPhotonIsolationCalculator* thePFBasedIsolationCalculator_;
PhotonIsolationCalculator* thePhotonIsolationCalculator_;

//AA
Expand Down
Expand Up @@ -22,6 +22,9 @@
gedPhotons.photonProducer = cms.InputTag("gedPhotonsTmp")
gedPhotons.outputPhotonCollection = cms.string("")
gedPhotons.reconstructionStep = cms.string("final")
gedPhotons.chargedHadronIsolation = cms.InputTag("egmPhotonIsolationCITK:h+-DR030-")
gedPhotons.neutralHadronIsolation = cms.InputTag("egmPhotonIsolationCITK:h0-DR030-")
gedPhotons.photonIsolation = cms.InputTag("egmPhotonIsolationCITK:gamma-DR030-")
gedPhotonSequence = cms.Sequence(gedPhotons)


Expand Down
43 changes: 29 additions & 14 deletions RecoEgamma/EgammaPhotonProducers/src/GEDPhotonProducer.cc
Expand Up @@ -68,6 +68,13 @@ GEDPhotonProducer::GEDPhotonProducer(const edm::ParameterSet& config) :
pfCandidates_ =
consumes<reco::PFCandidateCollection>(conf_.getParameter<edm::InputTag>("pfCandidates"));

phoChargedIsolationToken_CITK =
consumes<edm::ValueMap<float>>(conf_.getParameter<edm::InputTag>("chargedHadronIsolation"));
phoNeutralHadronIsolationToken_CITK =
consumes<edm::ValueMap<float>>(conf_.getParameter<edm::InputTag>("neutralHadronIsolation"));
phoPhotonIsolationToken_CITK =
consumes<edm::ValueMap<float>>(conf_.getParameter<edm::InputTag>("photonIsolation"));

} else {

photonCoreProducerT_ =
Expand Down Expand Up @@ -211,21 +218,13 @@ GEDPhotonProducer::~GEDPhotonProducer()

void GEDPhotonProducer::beginRun (edm::Run const& r, edm::EventSetup const & theEventSetup) {

if ( reconstructionStep_ == "final" ) {
thePFBasedIsolationCalculator_ = new PFPhotonIsolationCalculator();
edm::ParameterSet pfIsolationCalculatorSet = conf_.getParameter<edm::ParameterSet>("PFIsolationCalculatorSet");
thePFBasedIsolationCalculator_->setup(pfIsolationCalculatorSet);
}else{
if ( reconstructionStep_ != "final" ) {
thePhotonEnergyCorrector_ -> init(theEventSetup);
}

}

void GEDPhotonProducer::endRun (edm::Run const& r, edm::EventSetup const & theEventSetup) {

if ( reconstructionStep_ == "final" ) {
delete thePFBasedIsolationCalculator_;
}
}


Expand All @@ -244,9 +243,17 @@ void GEDPhotonProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
Handle<reco::PhotonCoreCollection> photonCoreHandle;
bool validPhotonHandle= false;
Handle<reco::PhotonCollection> photonHandle;
//value maps for isolation
edm::Handle<edm::ValueMap<float> > phoChargedIsolationMap_CITK;
edm::Handle<edm::ValueMap<float> > phoNeutralHadronIsolationMap_CITK;
edm::Handle<edm::ValueMap<float> > phoPhotonIsolationMap_CITK;

if ( reconstructionStep_ == "final" ) {
theEvent.getByToken(photonProducerT_,photonHandle);
//get isolation objects
theEvent.getByToken(phoChargedIsolationToken_CITK,phoChargedIsolationMap_CITK);
theEvent.getByToken(phoNeutralHadronIsolationToken_CITK,phoNeutralHadronIsolationMap_CITK);
theEvent.getByToken(phoPhotonIsolationToken_CITK,phoPhotonIsolationMap_CITK);
if ( photonHandle.isValid()) {
validPhotonHandle=true;
} else {
Expand Down Expand Up @@ -391,7 +398,10 @@ void GEDPhotonProducer::produce(edm::Event& theEvent, const edm::EventSetup& the
pfEGCandToPhotonMap,
vertexHandle,
outputPhotonCollection,
iSC);
iSC,
phoChargedIsolationMap_CITK,
phoNeutralHadronIsolationMap_CITK,
phoPhotonIsolationMap_CITK);



Expand Down Expand Up @@ -702,7 +712,7 @@ void GEDPhotonProducer::fillPhotonCollection(edm::Event& evt,
const edm::Handle<reco::PFCandidateCollection> pfEGCandidateHandle,
edm::ValueMap<reco::PhotonRef> pfEGCandToPhotonMap,
edm::Handle< reco::VertexCollection > & vertexHandle,
reco::PhotonCollection & outputPhotonCollection, int& iSC) {
reco::PhotonCollection & outputPhotonCollection, int& iSC, const edm::Handle<edm::ValueMap<float>>& chargedHadrons_, const edm::Handle<edm::ValueMap<float>>& neutralHadrons_, const edm::Handle<edm::ValueMap<float>>& photons_) {



Expand Down Expand Up @@ -737,12 +747,17 @@ void GEDPhotonProducer::fillPhotonCollection(edm::Event& evt,
// Calculate the PF isolation and ID - for the time being there is no calculation. Only the setting
reco::Photon::PflowIsolationVariables pfIso;
reco::Photon::PflowIDVariables pfID;
if( thedet != DetId::Forward ) {
thePFBasedIsolationCalculator_->calculate (&newCandidate, pfCandidateHandle, vertexHandle, evt, es, pfIso );
}

//get the pointer for the photon object
edm::Ptr<reco::Photon> photonPtr(photonHandle, lSC);

pfIso.chargedHadronIso = (*chargedHadrons_)[photonPtr] ;
pfIso.neutralHadronIso = (*neutralHadrons_)[photonPtr];
pfIso.photonIso = (*photons_)[photonPtr];
newCandidate.setPflowIsolationVariables(pfIso);
newCandidate.setPflowIDVariables(pfID);


// do the regression
thePhotonEnergyCorrector_->calculate(evt, newCandidate, subdet, *vertexHandle, es);
if ( candidateP4type_ == "fromEcalEnergy") {
Expand Down
25 changes: 24 additions & 1 deletion RecoParticleFlow/PFProducer/python/particleFlowEGamma_cff.py
Expand Up @@ -8,6 +8,29 @@
from RecoEgamma.EgammaPhotonProducers.gedPhotonSequence_cff import *
from RecoEgamma.EgammaElectronProducers.gedGsfElectronSequence_cff import *
from RecoEgamma.EgammaElectronProducers.pfBasedElectronIso_cff import *
from RecoEgamma.EgammaIsolationAlgos.particleBasedIsoProducer_cfi import particleBasedIsolation as _particleBasedIsolation
from RecoEgamma.EgammaIsolationAlgos.egmPhotonIsolationAOD_cff import egmPhotonIsolationAOD as _egmPhotonIsolationAOD

from CommonTools.ParticleFlow.pfNoPileUpIso_cff import pfPileUpIso, pfNoPileUpIso, pfNoPileUpIsoSequence
from RecoEgamma.EgammaIsolationAlgos.egmIsolationDefinitions_cff import pfNoPileUpCandidates
from RecoEgamma.EgammaIsolationAlgos.egmIsoConeDefinitions_cfi import IsoConeDefinitions as IsoConeDefinitionsTmp

particleBasedIsolationTmp = _particleBasedIsolation.clone()
particleBasedIsolationTmp.photonProducer = cms.InputTag("gedPhotonsTmp")
particleBasedIsolationTmp.electronProducer = cms.InputTag("gedGsfElectronsTmp")
particleBasedIsolationTmp.pfCandidates = cms.InputTag("particleFlowTmp")
particleBasedIsolationTmp.valueMapPhoPFblockIso = cms.string("gedPhotonsTmp")
particleBasedIsolationTmp.valueMapElePFblockIso = cms.string("gedGsfElectronsTmp")

egmPhotonIsolationCITK = _egmPhotonIsolationAOD.clone()

for iPSet in IsoConeDefinitionsTmp:
iPSet.particleBasedIsolation = cms.InputTag("particleBasedIsolationTmp", "gedPhotonsTmp")


egmPhotonIsolationCITK.srcToIsolate = cms.InputTag("gedPhotonsTmp")
egmPhotonIsolationCITK.srcForIsolationCone = cms.InputTag("pfNoPileUpCandidates")
egmPhotonIsolationCITK.isolationConeDefinitions = IsoConeDefinitionsTmp

particleFlowEGammaFull = cms.Sequence(particleFlowEGamma*gedGsfElectronSequenceTmp*gedPhotonSequenceTmp)
particleFlowEGammaFinal = cms.Sequence(gedPhotonSequence*gedElectronPFIsoSequence)
particleFlowEGammaFinal = cms.Sequence(particleBasedIsolationTmp*pfNoPileUpIsoSequence*pfNoPileUpCandidates*egmPhotonIsolationCITK*gedPhotonSequence*gedElectronPFIsoSequence)