From 60f6f31d887e28b79f271752c63da98f3154d0af Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 13 Sep 2017 10:09:52 +0200 Subject: [PATCH 1/3] Fix PackedCandidate::dz(point) for cases where the track and candidate eta's differ, and point is not the associated PV --- DataFormats/PatCandidates/src/PackedCandidate.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DataFormats/PatCandidates/src/PackedCandidate.cc b/DataFormats/PatCandidates/src/PackedCandidate.cc index b7c5addda4067..d25a2c4e6d6e4 100644 --- a/DataFormats/PatCandidates/src/PackedCandidate.cc +++ b/DataFormats/PatCandidates/src/PackedCandidate.cc @@ -150,7 +150,8 @@ float pat::PackedCandidate::dxy(const Point &p) const { float pat::PackedCandidate::dz(const Point &p) const { maybeUnpackBoth(); const float phi = float(p4_.load()->Phi())+dphi_; - return (vertex_.load()->Z()-p.Z()) - ((vertex_.load()->X()-p.X()) * std::cos(phi) + (vertex_.load()->Y()-p.Y()) * std::sin(phi)) * p4_.load()->Pz()/p4_.load()->Pt(); + const float pzpt = deta_ ? std::sinh(etaAtVtx()) : p4_.load()->Pz()/p4_.load()->Pt(); + return (vertex_.load()->Z()-p.Z()) - ((vertex_.load()->X()-p.X()) * std::cos(phi) + (vertex_.load()->Y()-p.Y()) * std::sin(phi)) * pzpt; } void pat::PackedCandidate::unpackTrk() const { From 5db31d6fb6c355548ba2f1553bac6b6cd5030dc8 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 13 Sep 2017 10:11:36 +0200 Subject: [PATCH 2/3] PhotonIDValueMapProducer: on miniAOD, get dxy/dz from candidate, not from track (which may not be available) --- .../plugins/PhotonIDValueMapProducer.cc | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc index 7ad55dbfc58a9..ca449a0b4c6ae 100644 --- a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc +++ b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc @@ -76,7 +76,7 @@ class PhotonIDValueMapProducer : public edm::stream::EDProducer<> { reco::PFCandidate::ParticleType candidatePdgId(const edm::Ptr candidate, bool isAOD); - const reco::Track* getTrackPointer(const edm::Ptr candidate, bool isAOD); + std::pair getTrackDxyDz(const edm::Ptr & candidate, const reco::Particle::Point & vtxpos, bool isAOD); // The object that will compute 5x5 quantities @@ -378,13 +378,10 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup if( thisCandidateType == reco::PFCandidate::h ){ // for charged hadrons, additionally check consistency // with the PV - const reco::Track *theTrack = getTrackPointer( iCand, isAOD ); - float dxy = theTrack->dxy(pv.position()); - if(fabs(dxy) > dxyMax) continue; - - float dz = theTrack->dz(pv.position()); - if (fabs(dz) > dzMax) continue; + auto dxydz = getTrackDxyDz(iCand, pv.position(), isAOD); + if ( fabs(dxydz.first) > dxyMax) continue; + if ( fabs(dxydz.second) > dzMax) continue; // The candidate is eligible, increment the isolaiton chargedIsoSum += iCand->pt(); @@ -507,13 +504,10 @@ ::computeWorstPFChargedIsolation(const T& photon, const U& pfCandidates, if (iCand->pt() < ptMin) continue; - - const reco::Track *theTrack = getTrackPointer( iCand, isAOD ); - float dxy = theTrack->dxy(vtx->position()); - if( fabs(dxy) > dxyMax) continue; - - float dz = theTrack->dz(vtx->position()); - if ( fabs(dz) > dzMax) continue; + + auto dxydz = getTrackDxyDz(iCand, vtx->position(), isAOD); + if ( fabs(dxydz.first) > dxyMax) continue; + if ( fabs(dxydz.second) > dzMax) continue; float dR2 = deltaR2(photon_directionWrtVtx.Eta(), photon_directionWrtVtx.Phi(), iCand->eta(), iCand->phi()); @@ -552,16 +546,17 @@ PhotonIDValueMapProducer::candidatePdgId(const edm::Ptr candida return thisCandidateType; } -const reco::Track* -PhotonIDValueMapProducer::getTrackPointer(const edm::Ptr candidate, bool isAOD){ +std::pair +PhotonIDValueMapProducer::getTrackDxyDz(const edm::Ptr & candidate, const reco::Particle::Point & vtxpos, bool isAOD) { - const reco::Track* theTrack = nullptr; - if( isAOD ) - theTrack = &*( ((const recoCandPtr) candidate)->trackRef()); - else - theTrack = &( ((const patCandPtr) candidate)->pseudoTrack()); + if( isAOD ) { + const reco::Track & theTrack = *recoCandPtr(candidate)->trackRef(); + return std::make_pair(theTrack.dxy(vtxpos),theTrack.dz(vtxpos)); + } else { + const pat::PackedCandidate & theCand = *(patCandPtr(candidate)); + return std::make_pair(theCand.dxy(vtxpos),theCand.dz(vtxpos)); + } - return theTrack; } DEFINE_FWK_MODULE(PhotonIDValueMapProducer); From 852157f7e6a8e48f73e72983be4627d8f85fb2a4 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 13 Sep 2017 10:14:57 +0200 Subject: [PATCH 3/3] code-checks --- DataFormats/PatCandidates/src/PackedCandidate.cc | 6 +++--- .../plugins/PhotonIDValueMapProducer.cc | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DataFormats/PatCandidates/src/PackedCandidate.cc b/DataFormats/PatCandidates/src/PackedCandidate.cc index d25a2c4e6d6e4..3669c6bcc7efe 100644 --- a/DataFormats/PatCandidates/src/PackedCandidate.cc +++ b/DataFormats/PatCandidates/src/PackedCandidate.cc @@ -299,11 +299,11 @@ bool pat::PackedCandidate::overlap( const reco::Candidate & o ) const { } const reco::Candidate * pat::PackedCandidate::daughter( size_type ) const { - return 0; + return nullptr; } const reco::Candidate * pat::PackedCandidate::mother( size_type ) const { - return 0; + return nullptr; } const reco::Candidate * pat::PackedCandidate::daughter(const std::string&) const { @@ -321,7 +321,7 @@ reco::Candidate * pat::PackedCandidate::daughter(const std::string&) { reco::Candidate * pat::PackedCandidate::daughter( size_type ) { - return 0; + return nullptr; } double pat::PackedCandidate::vertexChi2() const { diff --git a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc index ca449a0b4c6ae..a17ad9cab6bd5 100644 --- a/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc +++ b/RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc @@ -42,13 +42,13 @@ class PhotonIDValueMapProducer : public edm::stream::EDProducer<> { public: explicit PhotonIDValueMapProducer(const edm::ParameterSet&); - ~PhotonIDValueMapProducer(); + ~PhotonIDValueMapProducer() override; static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - virtual void produce(edm::Event&, const edm::EventSetup&) override; + void produce(edm::Event&, const edm::EventSetup&) override; void writeValueMap(edm::Event &iEvent, const edm::Handle > & handle, @@ -269,7 +269,7 @@ void PhotonIDValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup if( !pfCandidatesHandle.isValid() ) iEvent.getByToken(pfCandidatesTokenMiniAOD_, pfCandidatesHandle); - if( !isAOD && src->size() ) { + if( !isAOD && !src->empty() ) { edm::Ptr test(src->ptrAt(0)); if( test.isNull() || !test.isAvailable() ) { throw cms::Exception("InvalidConfiguration") @@ -519,7 +519,7 @@ ::computeWorstPFChargedIsolation(const T& photon, const U& pfCandidates, allIsolations.push_back(sum); } - if( allIsolations.size()>0 ) + if( !allIsolations.empty() ) worstIsolation = * std::max_element( allIsolations.begin(), allIsolations.end() ); return worstIsolation;