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

Fix PackedCandidate::dz and PhotonIDValueMapProducer #20491

Merged
merged 3 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions DataFormats/PatCandidates/src/PackedCandidate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -298,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 {
Expand All @@ -320,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 {
Expand Down
47 changes: 21 additions & 26 deletions RecoEgamma/PhotonIdentification/plugins/PhotonIDValueMapProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<edm::View<reco::Photon> > & handle,
Expand Down Expand Up @@ -76,7 +76,7 @@ class PhotonIDValueMapProducer : public edm::stream::EDProducer<> {
reco::PFCandidate::ParticleType
candidatePdgId(const edm::Ptr<reco::Candidate> candidate, bool isAOD);

const reco::Track* getTrackPointer(const edm::Ptr<reco::Candidate> candidate, bool isAOD);
std::pair<float,float> getTrackDxyDz(const edm::Ptr<reco::Candidate> & candidate, const reco::Particle::Point & vtxpos, bool isAOD);


// The object that will compute 5x5 quantities
Expand Down Expand Up @@ -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<pat::Photon> test(src->ptrAt(0));
if( test.isNull() || !test.isAvailable() ) {
throw cms::Exception("InvalidConfiguration")
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand All @@ -525,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;
Expand All @@ -552,16 +546,17 @@ PhotonIDValueMapProducer::candidatePdgId(const edm::Ptr<reco::Candidate> candida
return thisCandidateType;
}

const reco::Track*
PhotonIDValueMapProducer::getTrackPointer(const edm::Ptr<reco::Candidate> candidate, bool isAOD){
std::pair<float,float>
PhotonIDValueMapProducer::getTrackDxyDz(const edm::Ptr<reco::Candidate> & 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);