From 863334d27184b66a612d815a4ea4c032d8efec26 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 4 Sep 2017 11:24:05 +0200 Subject: [PATCH 1/6] PatCandidates Lepton.h : make the miniPFIsolation() const --- DataFormats/PatCandidates/interface/Lepton.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataFormats/PatCandidates/interface/Lepton.h b/DataFormats/PatCandidates/interface/Lepton.h index 821cc81a76c15..200cd78a4e233 100644 --- a/DataFormats/PatCandidates/interface/Lepton.h +++ b/DataFormats/PatCandidates/interface/Lepton.h @@ -193,7 +193,7 @@ namespace pat { void hcalIsoDeposit(const IsoDeposit &dep) { setIsoDeposit(pat::HcalIso, dep); } void userIsoDeposit(const IsoDeposit &dep, uint8_t index=0) { setIsoDeposit(IsolationKeys(UserBaseIso + index), dep); } - const PFIsolation& miniPFIsolation() { return miniPFIsolation_; } + const PFIsolation& miniPFIsolation() const { return miniPFIsolation_; } void setMiniPFIsolation(PFIsolation const& iso) { miniPFIsolation_ = iso; } protected: From 68f737b843ad30fd817c8f056a94671fe785dd63 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 4 Sep 2017 13:25:58 +0200 Subject: [PATCH 2/6] add dZ from PV to PAT Electron & Muon --- DataFormats/PatCandidates/interface/Electron.h | 2 +- DataFormats/PatCandidates/interface/Muon.h | 2 +- DataFormats/PatCandidates/src/classes_def_objects.xml | 6 ++++-- PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc | 3 +++ PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc | 4 ++++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/DataFormats/PatCandidates/interface/Electron.h b/DataFormats/PatCandidates/interface/Electron.h index 8a689ae426a39..4de9719dd1f74 100644 --- a/DataFormats/PatCandidates/interface/Electron.h +++ b/DataFormats/PatCandidates/interface/Electron.h @@ -203,7 +203,7 @@ namespace pat { reco::CandidatePtr sourceCandidatePtr( size_type i ) const; // ---- embed various impact parameters with errors ---- - typedef enum IPTYPE { PV2D = 0, PV3D = 1, BS2D = 2, BS3D = 3, IpTypeSize = 4 } IpType; + typedef enum IPTYPE { PV2D = 0, PV3D = 1, BS2D = 2, BS3D = 3, PVDZ = 4, IpTypeSize = 5 } IpType; /// Impact parameter wrt primary vertex or beamspot double dB(IPTYPE type) const; /// Uncertainty on the corresponding impact parameter diff --git a/DataFormats/PatCandidates/interface/Muon.h b/DataFormats/PatCandidates/interface/Muon.h index 22db98798df6d..36f7f30ea9aab 100644 --- a/DataFormats/PatCandidates/interface/Muon.h +++ b/DataFormats/PatCandidates/interface/Muon.h @@ -229,7 +229,7 @@ namespace pat { // IpType defines the type of the impact parameter typedef enum IPTYPE { - PV2D = 0, PV3D = 1, BS2D = 2, BS3D = 3, IpTypeSize = 4 + PV2D = 0, PV3D = 1, BS2D = 2, BS3D = 3, PVDZ = 4, IpTypeSize = 5 } IpType; void initImpactParameters(void); // init IP defaults in a constructor double dB(IPTYPE type) const; diff --git a/DataFormats/PatCandidates/src/classes_def_objects.xml b/DataFormats/PatCandidates/src/classes_def_objects.xml index e0fc1e6b5fcac..d95408c6681ac 100644 --- a/DataFormats/PatCandidates/src/classes_def_objects.xml +++ b/DataFormats/PatCandidates/src/classes_def_objects.xml @@ -16,7 +16,8 @@ - + + @@ -59,7 +60,8 @@ - + + diff --git a/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc b/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc index 1d556b400cb80..fcb2580326faa 100755 --- a/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc @@ -1174,6 +1174,9 @@ void PATElectronProducer::embedHighLevel( pat::Electron & anElectron, d0_corr = result.second.value(); d0_err = beamspotIsValid ? result.second.error() : -1.0; anElectron.setDB( d0_corr, d0_err, pat::Electron::BS3D); + + // PVDZ + anElectron.setDB( track->dz(primaryVertex.position()), track->dzError(), pat::Electron::PVDZ ); } #include "FWCore/Framework/interface/MakerMacros.h" diff --git a/PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc b/PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc index cbddfa8849250..1a6d97500ea69 100755 --- a/PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc @@ -701,6 +701,10 @@ void PATMuonProducer::embedHighLevel( pat::Muon & aMuon, d0_corr = result.second.value(); d0_err = beamspotIsValid ? result.second.error() : -1.0; aMuon.setDB( d0_corr, d0_err, pat::Muon::BS3D); + + + // PVDZ + aMuon.setDB( track->dz(primaryVertex.position()), track->dzError(), pat::Muon::PVDZ ); } #include "FWCore/Framework/interface/MakerMacros.h" From 78b19b46ca9d360ffce90bd5559f07215ce97b03 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 4 Sep 2017 13:26:45 +0200 Subject: [PATCH 3/6] Add non-templated version of reduceMantissaToNbitsRounding and support for bulk conversion via std::transform --- .../PatCandidates/interface/libminifloat.h | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/DataFormats/PatCandidates/interface/libminifloat.h b/DataFormats/PatCandidates/interface/libminifloat.h index f814d4e1cd3fa..d75db00d408c4 100644 --- a/DataFormats/PatCandidates/interface/libminifloat.h +++ b/DataFormats/PatCandidates/interface/libminifloat.h @@ -2,6 +2,8 @@ #define libminifloat_h #include "FWCore/Utilities/interface/thread_safety_macros.h" #include +#include +#include // ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf class MiniFloatConverter { @@ -76,6 +78,44 @@ class MiniFloatConverter { return conv.flt; } + class ReduceMantissaToNbitsRounding { + public: + ReduceMantissaToNbitsRounding(int bits) : + shift(23-bits), mask((0xFFFFFFFF >> (shift)) << (shift)), + test(1 << (shift-1)), maxn((1<> shift; + if (mantissa < maxn) mantissa++; + conv.i32 = (conv.i32 & hi9) | (mantissa << shift); + } else { + conv.i32 &= mask; + } + return conv.flt; + } + private: + const int shift; + const uint32_t mask, test, maxn; + }; + + inline static float reduceMantissaToNbitsRounding(float f, int bits) + { + return ReduceMantissaToNbitsRounding(bits)(f); + } + + template + static void reduceMantissaToNbitsRounding(int bits, InItr begin, InItr end, OutItr out) + { + std::transform(begin, end, out, ReduceMantissaToNbitsRounding(bits)); + } + + inline static float max() { union { float flt; uint32_t i32; } conv; conv.i32 = 0x477fe000; // = mantissatable[offsettable[0x1e]+0x3ff]+exponenttable[0x1e] From 9f31d22ef866657ccd2f9701a6fe3061915edb48 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 4 Sep 2017 16:52:09 +0200 Subject: [PATCH 4/6] remove code duplication --- .../PatCandidates/interface/libminifloat.h | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/DataFormats/PatCandidates/interface/libminifloat.h b/DataFormats/PatCandidates/interface/libminifloat.h index d75db00d408c4..adf6b69831be7 100644 --- a/DataFormats/PatCandidates/interface/libminifloat.h +++ b/DataFormats/PatCandidates/interface/libminifloat.h @@ -56,28 +56,6 @@ class MiniFloatConverter { return conv.flt; } - template - inline static float reduceMantissaToNbitsRounding(const float &f) - { - static_assert(bits <= 23,"max mantissa size is 23 bits"); - constexpr int shift = (23-bits); // bits I throw away - constexpr uint32_t mask = (0xFFFFFFFF >> (shift)) << (shift); // mask for truncation - constexpr uint32_t test = 1 << (shift-1); // most significant bit I throw away - constexpr uint32_t low23 = (0x007FFFFF); // mask to keep lowest 23 bits = mantissa - constexpr uint32_t hi9 = (0xFF800000); // mask to keep highest 9 bits = the rest - constexpr uint32_t maxn = (1<> shift; - if (mantissa < maxn) mantissa++; - conv.i32 = (conv.i32 & hi9) | (mantissa << shift); - } else { - conv.i32 &= mask; - } - return conv.flt; - } - class ReduceMantissaToNbitsRounding { public: ReduceMantissaToNbitsRounding(int bits) : @@ -104,6 +82,15 @@ class MiniFloatConverter { const uint32_t mask, test, maxn; }; + template + inline static float reduceMantissaToNbitsRounding(const float &f) + { + static const ReduceMantissaToNbitsRounding reducer(bits); + return reducer(f); + } + + + inline static float reduceMantissaToNbitsRounding(float f, int bits) { return ReduceMantissaToNbitsRounding(bits)(f); From d5d893e28f273f0329bf1e9cbe2aef26e70475c3 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Tue, 5 Sep 2017 10:17:16 +0200 Subject: [PATCH 5/6] code-checks --- .../PatCandidates/interface/Electron.h | 16 +++++----- DataFormats/PatCandidates/interface/Lepton.h | 6 ++-- DataFormats/PatCandidates/interface/Muon.h | 32 +++++++++---------- .../PatAlgos/plugins/PATElectronProducer.cc | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/DataFormats/PatCandidates/interface/Electron.h b/DataFormats/PatCandidates/interface/Electron.h index 4de9719dd1f74..d70ea3c40d39c 100644 --- a/DataFormats/PatCandidates/interface/Electron.h +++ b/DataFormats/PatCandidates/interface/Electron.h @@ -64,22 +64,22 @@ namespace pat { /// constructor from a Ptr to a reco::GsfElectron Electron(const edm::Ptr & anElectronRef); /// destructor - virtual ~Electron(); + ~Electron() override; /// required reimplementation of the Candidate's clone method - virtual Electron * clone() const { return new Electron(*this); } + Electron * clone() const override { return new Electron(*this); } // ---- methods for content embedding ---- /// override the virtual reco::GsfElectron::core method, so that the embedded core can be used by GsfElectron client methods - virtual reco::GsfElectronCoreRef core() const; + reco::GsfElectronCoreRef core() const override; /// override the reco::GsfElectron::gsfTrack method, to access the internal storage of the supercluster - reco::GsfTrackRef gsfTrack() const; + reco::GsfTrackRef gsfTrack() const override; /// override the reco::GsfElectron::superCluster method, to access the internal storage of the supercluster - reco::SuperClusterRef superCluster() const; + reco::SuperClusterRef superCluster() const override; /// override the reco::GsfElectron::pflowSuperCluster method, to access the internal storage of the pflowSuperCluster reco::SuperClusterRef parentSuperCluster() const; /// returns nothing. Use either gsfTrack or closestCtfTrack - reco::TrackRef track() const; + reco::TrackRef track() const override; /// override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the track reco::TrackRef closestCtfTrackRef() const; /// direct access to the seed cluster @@ -196,11 +196,11 @@ namespace pat { /// embed the PFCandidate pointed to by pfCandidateRef_ void embedPFCandidate(); /// get the number of non-null PFCandidates - size_t numberOfSourceCandidatePtrs() const { + size_t numberOfSourceCandidatePtrs() const override { return (pfCandidateRef_.isNonnull() ? 1 : 0) + associatedPackedFCandidateIndices_.size(); } /// get the source candidate pointer with index i - reco::CandidatePtr sourceCandidatePtr( size_type i ) const; + reco::CandidatePtr sourceCandidatePtr( size_type i ) const override; // ---- embed various impact parameters with errors ---- typedef enum IPTYPE { PV2D = 0, PV3D = 1, BS2D = 2, BS3D = 3, PVDZ = 4, IpTypeSize = 5 } IpType; diff --git a/DataFormats/PatCandidates/interface/Lepton.h b/DataFormats/PatCandidates/interface/Lepton.h index 200cd78a4e233..fb2554122fbc6 100644 --- a/DataFormats/PatCandidates/interface/Lepton.h +++ b/DataFormats/PatCandidates/interface/Lepton.h @@ -36,9 +36,9 @@ namespace pat { Lepton(const LeptonType & aLepton); Lepton(const edm::RefToBase & aLeptonRef); Lepton(const edm::Ptr & aLeptonRef); - virtual ~Lepton(); + ~Lepton() override; - virtual Lepton * clone() const { return new Lepton(*this); } + Lepton * clone() const override { return new Lepton(*this); } const reco::GenParticle * genLepton() const { return PATObject::genParticle(); } @@ -169,7 +169,7 @@ namespace pat { { if (it->first == key) return & it->second; } - return 0; + return nullptr; } /// Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten. diff --git a/DataFormats/PatCandidates/interface/Muon.h b/DataFormats/PatCandidates/interface/Muon.h index 36f7f30ea9aab..d72d3d11799f3 100644 --- a/DataFormats/PatCandidates/interface/Muon.h +++ b/DataFormats/PatCandidates/interface/Muon.h @@ -59,31 +59,31 @@ namespace pat { /// constructor from a Ptr to a reco muon Muon(const edm::Ptr & aMuonRef); /// destructor - virtual ~Muon(); + ~Muon() override; /// required reimplementation of the Candidate's clone method - virtual Muon * clone() const { return new Muon(*this); } + Muon * clone() const override { return new Muon(*this); } // ---- methods for content embedding ---- /// reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) - reco::TrackRef track() const; + reco::TrackRef track() const override; using reco::RecoCandidate::track; // avoid hiding the base implementation /// reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) - reco::TrackRef innerTrack() const { return track(); } + reco::TrackRef innerTrack() const override { return track(); } /// reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) - reco::TrackRef standAloneMuon() const; + reco::TrackRef standAloneMuon() const override; /// reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) - reco::TrackRef outerTrack() const { return standAloneMuon(); } + reco::TrackRef outerTrack() const override { return standAloneMuon(); } /// reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) - reco::TrackRef combinedMuon() const; + reco::TrackRef combinedMuon() const override; /// reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) - reco::TrackRef globalTrack() const { return combinedMuon(); } + reco::TrackRef globalTrack() const override { return combinedMuon(); } /// Track selected to be the best measurement of the muon parameters (including PFlow global information) - const reco::Track * bestTrack() const { return muonBestTrack().get(); } + const reco::Track * bestTrack() const override { return muonBestTrack().get(); } /// Track selected to be the best measurement of the muon parameters (including PFlow global information) - reco::TrackRef muonBestTrack() const ; + reco::TrackRef muonBestTrack() const override ; /// Track selected to be the best measurement of the muon parameters (from muon information alone) - virtual reco::TrackRef tunePMuonBestTrack() const ; + reco::TrackRef tunePMuonBestTrack() const override ; /// set reference to Track selected to be the best measurement of the muon parameters (reimplemented from reco::Muon) /// if force == false, do not embed this track if it's embedded already (e.g. ig it's a tracker track, and that's already embedded) @@ -109,11 +109,11 @@ namespace pat { // ---- methods for TeV refit tracks ---- /// reference to Track reconstructed using hits in the tracker + "good" muon hits (reimplemented from reco::Muon) - reco::TrackRef pickyTrack() const; + reco::TrackRef pickyTrack() const override; /// reference to Track reconstructed using hits in the tracker + info from the first muon station that has hits (reimplemented from reco::Muon) - reco::TrackRef tpfmsTrack() const; + reco::TrackRef tpfmsTrack() const override; /// reference to Track reconstructed using DYT algorithm - reco::TrackRef dytTrack() const; + reco::TrackRef dytTrack() const override; /// Deprecated accessors to call the corresponding above two functions; no dytMuon since this naming is deprecated. reco::TrackRef pickyMuon() const { return pickyTrack(); } // JMTBAD gcc deprecated attribute? reco::TrackRef tpfmsMuon() const { return tpfmsTrack(); } // JMTBAD gcc deprecated attribute? @@ -135,14 +135,14 @@ namespace pat { /// embed the IsolatedPFCandidate pointed to by pfCandidateRef_ void embedPFCandidate(); /// get the number of non-null PF candidates - size_t numberOfSourceCandidatePtrs() const { + size_t numberOfSourceCandidatePtrs() const override { size_t res=0; if(pfCandidateRef_.isNonnull()) res++; if(refToOrig_.isNonnull()) res++; return res; } /// get the candidate pointer with index i - reco::CandidatePtr sourceCandidatePtr( size_type i ) const; + reco::CandidatePtr sourceCandidatePtr( size_type i ) const override; // ---- methods for accessing muon identification ---- /// accessor for the various muon id algorithms currently defined diff --git a/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc b/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc index fcb2580326faa..57b659d1ccaf7 100755 --- a/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc @@ -396,7 +396,7 @@ void PATElectronProducer::produce(edm::Event & iEvent, const edm::EventSetup & i // embed high level selection if ( embedHighLevelSelection_ ) { // get the global track - reco::GsfTrackRef track = PfTk; + const reco::GsfTrackRef& track = PfTk; // Make sure the collection it points to is there if ( track.isNonnull() && track.isAvailable() ) { From c5e1951c24d73e6a373271a73056146e01f4364b Mon Sep 17 00:00:00 2001 From: Giovanni Date: Wed, 6 Sep 2017 18:09:03 +0200 Subject: [PATCH 6/6] add in quadrature track dzError and PV zError --- PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc | 2 +- PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc b/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc index 57b659d1ccaf7..8c33ba0405503 100755 --- a/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATElectronProducer.cc @@ -1176,7 +1176,7 @@ void PATElectronProducer::embedHighLevel( pat::Electron & anElectron, anElectron.setDB( d0_corr, d0_err, pat::Electron::BS3D); // PVDZ - anElectron.setDB( track->dz(primaryVertex.position()), track->dzError(), pat::Electron::PVDZ ); + anElectron.setDB( track->dz(primaryVertex.position()), std::hypot(track->dzError(), primaryVertex.zError()), pat::Electron::PVDZ ); } #include "FWCore/Framework/interface/MakerMacros.h" diff --git a/PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc b/PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc index 1a6d97500ea69..74ac80b1855df 100755 --- a/PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATMuonProducer.cc @@ -704,7 +704,7 @@ void PATMuonProducer::embedHighLevel( pat::Muon & aMuon, // PVDZ - aMuon.setDB( track->dz(primaryVertex.position()), track->dzError(), pat::Muon::PVDZ ); + aMuon.setDB( track->dz(primaryVertex.position()), std::hypot(track->dzError(), primaryVertex.zError()), pat::Muon::PVDZ ); } #include "FWCore/Framework/interface/MakerMacros.h"