26 bool isInFootprint(
const T& footprint,
29 for (
auto& it : footprint) {
30 if (it.key() == candidate.
key())
36 struct CachingPtrCandidate {
40 packed(isAOD?
nullptr : static_cast<const
pat::PackedCandidate*>(cPtr))
48 void getImpactParameters(
const CachingPtrCandidate& candidate,
const reco::Vertex&
pv,
float&
dxy,
float&
dz)
50 if (candidate.track !=
nullptr) {
51 dxy = candidate.track->dxy(pv.
position());
52 dz = candidate.track->dz(pv.
position());
54 dxy = candidate.packed->dxy(pv.
position());
55 dz = candidate.packed->dz(pv.
position());
71 else if (
abs(pdgId) == 130)
73 else if (
abs(pdgId) == 211)
98 float computeWorstPFChargedIsolation(
103 unsigned char options,
bool isAOD)
const;
123 "phoFull5x5SigmaIEtaIEta",
124 "phoFull5x5SigmaIEtaIPhi",
131 "phoFull5x5E1x3byE5x5",
132 "phoFull5x5E2x2byE5x5",
133 "phoFull5x5E2x5byE5x5",
135 "phoChargedIsolation",
136 "phoNeutralHadronIsolation",
137 "phoPhotonIsolation",
138 "phoWorstChargedIsolation",
139 "phoWorstChargedIsolationConeVeto",
140 "phoWorstChargedIsolationConeVetoPVConstr",
143 "phoHcalPFClIsolation",
144 "phoEcalPFClIsolation" 160 : usesES_(!cfg.getParameter<
edm::InputTag>(
"esReducedRecHitCollection").
label().
empty()
161 || !cfg.getParameter<
edm::InputTag>(
"esReducedRecHitCollectionMiniAOD").
label().
empty())
162 , src_( consumesCollector(), cfg,
"src",
"srcMiniAOD")
163 , ebRecHits_ (src_, consumesCollector(), cfg,
"ebReducedRecHitCollection",
"ebReducedRecHitCollectionMiniAOD")
164 , eeRecHits_ (src_, consumesCollector(), cfg,
"eeReducedRecHitCollection",
"eeReducedRecHitCollectionMiniAOD")
165 , esRecHits_ (src_, consumesCollector(), cfg,
"esReducedRecHitCollection",
"esReducedRecHitCollectionMiniAOD")
166 , vtxToken_ (src_, consumesCollector(), cfg,
"vertices",
"verticesMiniAOD")
167 , pfCandsToken_(src_, consumesCollector(), cfg,
"pfCandidates",
"pfCandidatesMiniAOD")
169 cfg.getParameter<
edm::InputTag>(
"particleBasedIsolation")) )
188 }
else if (!
src->empty()) {
190 if (
test.isNull() || !
test.isAvailable()) {
192 <<
"DataFormat is detected as miniAOD but cannot cast to pat::Photon!";
197 std::unique_ptr<noZS::EcalClusterLazyTools> lazyToolnoZS;
200 lazyToolnoZS = std::make_unique<noZS::EcalClusterLazyTools>(
203 lazyToolnoZS = std::make_unique<noZS::EcalClusterLazyTools>(
215 for (
unsigned i = 0;
i <
src->size(); ++
i) {
216 const auto& iPho =
src->ptrAt(
i);
221 const auto& theseed = *(iPho->superCluster()->seed());
227 std::vector<float> vCov = lazyToolnoZS->localCovariances(theseed);
229 vars[1].push_back(vCov[1]);
230 vars[2].push_back(lazyToolnoZS->e1x3(theseed));
231 vars[3].push_back(lazyToolnoZS->e2x2(theseed));
232 vars[4].push_back(lazyToolnoZS->e2x5Max(theseed));
233 vars[5].push_back(lazyToolnoZS->e5x5(theseed));
234 vars[6].push_back(lazyToolnoZS->eseffsirir(*(iPho->superCluster())));
235 vars[7].push_back(vars[2][
i] / vars[5][
i]);
236 vars[8].push_back(vars[3][i] / vars[5][i]);
237 vars[9].push_back(vars[4][i] / vars[5][i]);
245 iPho->superCluster()->x() - pv.
x(), iPho->superCluster()->y() - pv.
y(), iPho->superCluster()->z() - pv.
z());
248 float chargedIsoSum = 0.;
249 float neutralHadronIsoSum = 0.;
250 float photonIsoSum = 0.;
253 for (
unsigned int idxcand = 0; idxcand < pfCandsHandle->size(); ++idxcand) {
257 const auto& iCand = pfCandsHandle->ptrAt(idxcand);
276 float dR2 =
deltaR2(phoWrtVtx.Eta(), phoWrtVtx.Phi(), iCand->eta(), iCand->phi());
277 if (dR2 > coneSizeDR * coneSizeDR)
282 if(isInFootprint((*particleBasedIsolationMap)[iPho], iCand))
286 if(isInFootprint(
patPhotonPtr->associatedPackedPFCandidates(), iCand))
300 getImpactParameters(CachingPtrCandidate(&*iCand, isAOD), pv, dxy, dz);
302 if (fabs(dxy) > dxyMax || fabs(dz) > dzMax)
306 chargedIsoSum += iCand->pt();
310 neutralHadronIsoSum += iCand->pt();
313 photonIsoSum += iCand->pt();
316 vars[10].push_back(chargedIsoSum);
317 vars[11].push_back(neutralHadronIsoSum);
318 vars[12].push_back(photonIsoSum);
325 options |= PT_MIN_THRESH |
DR_VETO;
333 vars[16].push_back(iPho->trkSumPtSolidConeDR04());
335 vars[17].push_back(0.
f);
336 vars[18].push_back(0.
f);
366 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){
388 if ((options & PT_MIN_THRESH) && aCand.pt() <
ptMin)
391 chargedCands.emplace_back(&aCand, isAOD);
395 for (
unsigned int ivtx = 0; ivtx < vertices.size(); ++ivtx) {
404 for (
auto const& aCCand : chargedCands) {
408 if (options & PV_CONSTRAINT)
409 getImpactParameters(aCCand, pv, dxy, dz);
411 getImpactParameters(aCCand, *vtx, dxy, dz);
413 if (fabs(dxy) > dxyMax || fabs(dz) > dzMax)
416 auto iCand = aCCand.candidate;
417 float dR2 =
deltaR2(phoWrtVtx.Eta(), phoWrtVtx.Phi(), iCand->eta(), iCand->phi());
418 if (dR2 > coneSizeDR * coneSizeDR ||
419 (options & DR_VETO && dR2 < dRveto * dRveto))
425 worstIsolation =
std::max(sum, worstIsolation);
428 return worstIsolation;
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
~PhotonIDValueMapProducer() override
const unsigned char DR_VETO
float computeWorstPFChargedIsolation(const reco::Photon &photon, const edm::View< reco::Candidate > &pfCands, const reco::VertexCollection &vertices, const reco::Vertex &pv, unsigned char options, bool isAOD) const
ParticleType
particle types
const unsigned char PV_CONSTRAINT
const MultiTokenT< EcalRecHitCollection > esRecHits_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
double y() const
y coordinate
PhotonIDValueMapProducer(const edm::ParameterSet &)
const MultiTokenT< EcalRecHitCollection > ebRecHits_
std::vector< Vertex > VertexCollection
collection of Vertex objects
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
const MultiTokenT< edm::View< reco::Photon > > src_
const Point & position() const
position
const std::string names[nVars_]
const MultiTokenT< EcalRecHitCollection > eeRecHits_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const unsigned char PT_MIN_THRESH
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Abs< T >::type abs(const T &t)
double z() const
z coordinate
edm::Handle< T > getValidHandle(const edm::Event &iEvent) const
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double x() const
x coordinate
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
XYZVectorD XYZVector
spatial vector with cartesian internal representation
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
edm::Ptr< pat::Photon > patPhotonPtr
Particle reconstructed by the particle flow algorithm.
int getGoodTokenIndex() const
const edm::EDGetToken particleBasedIsolationToken_
const MultiTokenT< edm::View< reco::Candidate > > pfCandsToken_
const MultiTokenT< reco::VertexCollection > vtxToken_