33 for (
auto& it : footprint) {
34 if (it.key() == candidate.
key())
40 struct CachingPtrCandidate {
44 packed(
isAOD ? nullptr : static_cast<
const pat::PackedCandidate*>(cPtr)) {}
51 void getImpactParameters(
const CachingPtrCandidate& candidate,
const reco::Vertex&
pv,
float&
dxy,
float&
dz) {
52 if (candidate.track !=
nullptr) {
53 dxy = candidate.track->dxy(
pv.position());
54 dz = candidate.track->dz(
pv.position());
56 dxy = candidate.packed->dxy(
pv.position());
57 dz = candidate.packed->dz(
pv.position());
126 "phoFull5x5SigmaIEtaIEta",
127 "phoFull5x5SigmaIEtaIPhi",
134 "phoFull5x5E1x3byE5x5",
135 "phoFull5x5E2x2byE5x5",
136 "phoFull5x5E2x5byE5x5",
138 "phoChargedIsolation",
139 "phoNeutralHadronIsolation",
140 "phoPhotonIsolation",
141 "phoWorstChargedIsolation",
142 "phoWorstChargedIsolationConeVeto",
143 "phoWorstChargedIsolationConeVetoPVConstr",
146 "phoHcalPFClIsolation",
147 "phoEcalPFClIsolation"};
164 ebRecHits_(consumes(
cfg.getParameter<
edm::
InputTag>(
"ebReducedRecHitCollection"))),
165 eeRecHits_(consumes(
cfg.getParameter<
edm::
InputTag>(
"eeReducedRecHitCollection"))),
166 esRecHits_(consumes(
cfg.getParameter<
edm::
InputTag>(
"esReducedRecHitCollection"))),
168 pfCandsToken_(consumes(
cfg.getParameter<
edm::
InputTag>(
"pfCandidates"))),
172 isAOD_(
cfg.getParameter<
bool>(
"isAOD")) {
187 }
else if (!
src->empty()) {
189 if (
test.isNull() || !
test.isAvailable()) {
191 <<
"DataFormat is detected as miniAOD but cannot cast to pat::Photon!";
208 std::vector<edm::Ptr<reco::Candidate>> pfCandNoNaN;
209 for (
const auto&
pf : pfCandsHandle->ptrs()) {
211 edm::LogWarning(
"PhotonIDValueMapProducer") <<
"PF candidate pT is NaN, skipping, see issue #39110" << std::endl;
213 pfCandNoNaN.push_back(
pf);
218 for (
auto const& iPho :
src->ptrs()) {
222 const auto&
seed = *(iPho->superCluster()->seed());
228 const auto& vCov = lazyToolnoZS.localCovariances(
seed);
230 vars[1].push_back(vCov[1]);
231 vars[2].push_back(lazyToolnoZS.e1x3(
seed));
232 vars[3].push_back(lazyToolnoZS.e2x2(
seed));
233 vars[4].push_back(lazyToolnoZS.e2x5Max(
seed));
234 vars[5].push_back(lazyToolnoZS.e5x5(
seed));
235 vars[6].push_back(lazyToolnoZS.eseffsirir(*(iPho->superCluster())));
246 iPho->superCluster()->x() -
pv.x(), iPho->superCluster()->y() -
pv.y(), iPho->superCluster()->z() -
pv.z());
249 float chargedIsoSum = 0.;
250 float neutralHadronIsoSum = 0.;
251 float photonIsoSum = 0.;
254 for (
auto const& iCand : pfCandNoNaN) {
275 float dR2 =
deltaR2(phoWrtVtx.Eta(), phoWrtVtx.Phi(), iCand->eta(), iCand->phi());
281 if (isInFootprint((*particleBasedIsolationMap)[iPho], iCand))
285 if (isInFootprint(
patPhotonPtr->associatedPackedPFCandidates(), iCand))
299 getImpactParameters(CachingPtrCandidate(&*iCand,
isAOD_),
pv,
dxy,
dz);
305 chargedIsoSum += iCand->pt();
309 neutralHadronIsoSum += iCand->pt();
312 photonIsoSum += iCand->pt();
315 vars[10].push_back(chargedIsoSum);
316 vars[11].push_back(neutralHadronIsoSum);
317 vars[12].push_back(photonIsoSum);
332 vars[16].push_back(iPho->trkSumPtSolidConeDR04());
334 vars[17].push_back(0.
f);
335 vars[18].push_back(0.
f);
345 auto valMap = std::make_unique<edm::ValueMap<float>>();
363 desc.add<
bool>(
"isAOD",
false);
364 descriptions.
add(
"photonIDValueMapProducer",
desc);
375 float worstIsolation = 0.0;
379 std::vector<CachingPtrCandidate> chargedCands;
380 chargedCands.reserve(pfCands.size());
381 for (
auto const& aCand : pfCands) {
390 chargedCands.emplace_back(&*aCand,
isAOD);
394 for (
unsigned int ivtx = 0; ivtx <
vertices.size(); ++ivtx) {
401 const float phoWrtVtxPhi = phoWrtVtx.phi();
402 const float phoWrtVtxEta = phoWrtVtx.eta();
406 for (
auto const& aCCand : chargedCands) {
407 auto iCand = aCCand.candidate;
409 float dR2 =
deltaR2(phoWrtVtxEta, phoWrtVtxPhi, iCand->eta(), iCand->phi());
416 getImpactParameters(aCCand,
pv,
dxy,
dz);
418 getImpactParameters(aCCand, *
vtx,
dxy,
dz);
426 worstIsolation =
std::max(sum, worstIsolation);
429 return worstIsolation;
~PhotonIDValueMapProducer() override
const unsigned char DR_VETO
ParticleType
particle types
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const unsigned char PV_CONSTRAINT
constexpr bool isNotFinite(T x)
#define DEFINE_FWK_MODULE(type)
PhotonIDValueMapProducer(const edm::ParameterSet &)
std::vector< Vertex > VertexCollection
collection of Vertex objects
constexpr float dRveto2Endcap
constexpr float coneSizeDR2
EcalClusterLazyToolsT< noZS::EcalClusterTools > EcalClusterLazyTools
const std::string names[nVars_]
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const unsigned char PT_MIN_THRESH
const edm::EDGetTokenT< EcalRecHitCollection > eeRecHits_
float computeWorstPFChargedIsolation(const reco::Photon &photon, const std::vector< edm::Ptr< reco::Candidate >> &pfCands, const reco::VertexCollection &vertices, const reco::Vertex &pv, unsigned char options, bool isAOD) const
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const edm::EDGetTokenT< EcalRecHitCollection > ebRecHits_
Abs< T >::type abs(const T &t)
constexpr float dRveto2Barrel
const edm::EDGetTokenT< reco::VertexCollection > vtxToken_
const edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandsToken_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< EcalRecHitCollection > esRecHits_
edm::Ptr< pat::Photon > patPhotonPtr
Particle reconstructed by the particle flow algorithm.
const edm::EDGetToken particleBasedIsolationToken_
Log< level::Warning, false > LogWarning
edm::Ref< l1t::PFCandidateCollection > PFCandidateRef
const edm::EDGetTokenT< edm::View< reco::Photon > > src_