24 template <
class T,
class U>
25 bool isInFootprint(
const T& footprint,
const U& candidate)
27 for (
auto& it : footprint) {
28 if (it.key() == candidate.key())
34 struct CachingPtrCandidate {
38 packed(isAOD?
nullptr : static_cast<const
pat::PackedCandidate*>(cPtr))
46 void getImpactParameters(
const CachingPtrCandidate& candidate,
const reco::Vertex&
pv,
float&
dxy,
float&
dz)
48 if (candidate.track !=
nullptr) {
49 dxy = candidate.track->dxy(pv.
position());
50 dz = candidate.track->dz(pv.
position());
52 dxy = candidate.packed->dxy(pv.
position());
53 dz = candidate.packed->dz(pv.
position());
76 template <
class T,
class U>
77 float computeWorstPFChargedIsolation(
109 "phoFull5x5SigmaIEtaIEta",
110 "phoFull5x5SigmaIEtaIPhi",
117 "phoFull5x5E1x3byE5x5",
118 "phoFull5x5E2x2byE5x5",
119 "phoFull5x5E2x5byE5x5",
121 "phoChargedIsolation",
122 "phoNeutralHadronIsolation",
123 "phoPhotonIsolation",
124 "phoWorstChargedIsolation",
125 "phoWorstChargedIsolationConeVeto",
126 "phoWorstChargedIsolationConeVetoPVConstr",
129 "phoHcalPFClIsolation",
130 "phoEcalPFClIsolation" 146 : usesES_(!cfg.getParameter<
edm::InputTag>(
"esReducedRecHitCollection").
label().
empty()
147 || !cfg.getParameter<
edm::InputTag>(
"esReducedRecHitCollectionMiniAOD").
label().
empty())
148 , src_( consumesCollector(), cfg,
"src",
"srcMiniAOD")
149 , ebRecHits_ (src_, consumesCollector(), cfg,
"ebReducedRecHitCollection",
"ebReducedRecHitCollectionMiniAOD")
150 , eeRecHits_ (src_, consumesCollector(), cfg,
"eeReducedRecHitCollection",
"eeReducedRecHitCollectionMiniAOD")
151 , esRecHits_ (src_, consumesCollector(), cfg,
"esReducedRecHitCollection",
"esReducedRecHitCollectionMiniAOD")
152 , vtxToken_ (src_, consumesCollector(), cfg,
"vertices",
"verticesMiniAOD")
153 , pfCandsToken_(src_, consumesCollector(), cfg,
"pfCandidates",
"pfCandidatesMiniAOD")
155 cfg.getParameter<
edm::InputTag>(
"particleBasedIsolation")) )
179 if (
test.isNull() || !
test.isAvailable()) {
181 <<
"DataFormat is detected as miniAOD but cannot cast to pat::Photon!";
186 std::unique_ptr<noZS::EcalClusterLazyTools> lazyToolnoZS;
189 lazyToolnoZS = std::make_unique<noZS::EcalClusterLazyTools>(
192 lazyToolnoZS = std::make_unique<noZS::EcalClusterLazyTools>(
201 std::vector<float> vars[
nVars_];
204 for (
unsigned i = 0;
i <
src->size(); ++
i) {
205 const auto& iPho =
src->ptrAt(
i);
210 const auto& theseed = *(iPho->superCluster()->seed());
216 std::vector<float> vCov = lazyToolnoZS->localCovariances(theseed);
218 vars[1].push_back(vCov[1]);
219 vars[2].push_back(lazyToolnoZS->e1x3(theseed));
220 vars[3].push_back(lazyToolnoZS->e2x2(theseed));
221 vars[4].push_back(lazyToolnoZS->e2x5Max(theseed));
222 vars[5].push_back(lazyToolnoZS->e5x5(theseed));
223 vars[6].push_back(lazyToolnoZS->eseffsirir(*(iPho->superCluster())));
224 vars[7].push_back(vars[2][
i] / vars[5][
i]);
225 vars[8].push_back(vars[3][i] / vars[5][i]);
226 vars[9].push_back(vars[4][i] / vars[5][i]);
234 iPho->superCluster()->x() - pv.
x(), iPho->superCluster()->y() - pv.
y(), iPho->superCluster()->z() - pv.
z());
237 float chargedIsoSum = 0.;
238 float neutralHadronIsoSum = 0.;
239 float photonIsoSum = 0.;
242 for (
unsigned int idxcand = 0; idxcand < pfCandsHandle->size(); ++idxcand) {
246 const auto& iCand = pfCandsHandle->ptrAt(idxcand);
265 float dR2 =
deltaR2(phoWrtVtx.Eta(), phoWrtVtx.Phi(), iCand->eta(), iCand->phi());
266 if (dR2 > coneSizeDR * coneSizeDR)
271 if(isInFootprint((*particleBasedIsolationMap)[iPho], iCand))
275 if(isInFootprint(
patPhotonPtr->associatedPackedPFCandidates(), iCand))
288 getImpactParameters(CachingPtrCandidate(&*iCand,
isAOD_), pv, dxy, dz);
290 if (fabs(dxy) > dxyMax || fabs(dz) > dzMax)
294 chargedIsoSum += iCand->pt();
298 neutralHadronIsoSum += iCand->pt();
301 photonIsoSum += iCand->pt();
304 vars[10].push_back(chargedIsoSum);
305 vars[11].push_back(neutralHadronIsoSum);
306 vars[12].push_back(photonIsoSum);
313 options |= PT_MIN_THRESH |
DR_VETO;
321 vars[16].push_back(iPho->trkSumPtSolidConeDR04());
323 vars[17].push_back(0.
f);
324 vars[18].push_back(0.
f);
354 descriptions.
add(
"photonIDValueMapProducer", desc);
360 template <
class T,
class U>
364 float worstIsolation = 0.0;
366 const float dRveto = photon->isEB() ? dRvetoBarrel :
dRvetoEndcap;
368 std::vector<CachingPtrCandidate> chargedCands;
369 chargedCands.reserve(pfCands->size());
370 for (
auto const& aCand : *pfCands){
377 if ((options & PT_MIN_THRESH) && aCand.pt() <
ptMin)
380 chargedCands.emplace_back(&aCand,
isAOD_);
384 for (
unsigned int ivtx = 0; ivtx < vertices->size(); ++ivtx) {
389 photon->superCluster()->y() - vtx->y(), photon->superCluster()->z() - vtx->z());
393 for (
auto const& aCCand : chargedCands) {
397 if (options & PV_CONSTRAINT)
398 getImpactParameters(aCCand, pv, dxy, dz);
400 getImpactParameters(aCCand, *vtx, dxy, dz);
402 if (fabs(dxy) > dxyMax || fabs(dz) > dzMax)
405 auto iCand = aCCand.candidate;
406 float dR2 =
deltaR2(phoWrtVtx.Eta(), phoWrtVtx.Phi(), iCand->eta(), iCand->phi());
407 if (dR2 > coneSizeDR * coneSizeDR ||
408 (options & DR_VETO && dR2 < dRveto * dRveto))
414 worstIsolation =
std::max(sum, worstIsolation);
417 return worstIsolation;
431 else if (
abs(pdgId) == 130)
433 else if (
abs(pdgId) == 211)
~PhotonIDValueMapProducer() override
const unsigned char DR_VETO
ParticleType
particle types
const unsigned char PV_CONSTRAINT
float computeWorstPFChargedIsolation(const T &photon, const U &pfCands, const edm::Handle< reco::VertexCollection > vertices, const reco::Vertex &pv, unsigned char options)
MultiTokenT< edm::View< reco::Candidate > > pfCandsToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
double y() const
y coordinate
MultiTokenT< EcalRecHitCollection > esRecHits_
PhotonIDValueMapProducer(const edm::ParameterSet &)
const Point & position() const
position
const std::string names[nVars_]
edm::EDGetToken particleBasedIsolationToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const unsigned char PT_MIN_THRESH
MultiTokenT< edm::View< reco::Photon > > src_
Abs< T >::type abs(const T &t)
double z() const
z coordinate
void produce(edm::Event &, const edm::EventSetup &) override
MultiTokenT< EcalRecHitCollection > eeRecHits_
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
ParameterDescriptionBase * add(U const &iLabel, T const &value)
MultiTokenT< reco::VertexCollection > vtxToken_
edm::Handle< T > getValidHandle(const edm::Event &iEvent)
double x() const
x coordinate
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
void add(std::string const &label, ParameterSetDescription const &psetDescription)
MultiTokenT< EcalRecHitCollection > ebRecHits_
const reco::Track * getTrackPointer(const edm::Ptr< reco::Candidate > candidate)
edm::Ptr< pat::Photon > patPhotonPtr
Particle reconstructed by the particle flow algorithm.
int getGoodTokenIndex() const
reco::PFCandidate::ParticleType candidatePdgId(const reco::Candidate *candidate)