From 8f215aa58ac0a4ed119dd8f179fadc311588b6af Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 25 Mar 2023 01:08:56 +0100 Subject: [PATCH 1/4] add track algo and originalAlgo to PackedCandidates --- DataFormats/PatCandidates/interface/PackedCandidate.h | 10 ++++++++++ DataFormats/PatCandidates/src/classes_def_objects.xml | 3 ++- PhysicsTools/PatAlgos/plugins/PATLostTracks.cc | 2 ++ .../PatAlgos/plugins/PATPackedCandidateProducer.cc | 2 ++ .../plugins/DeepBoostedJetTagInfoProducer.cc | 2 ++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/DataFormats/PatCandidates/interface/PackedCandidate.h b/DataFormats/PatCandidates/interface/PackedCandidate.h index d214746f93d1f..4a20f29a6d792 100644 --- a/DataFormats/PatCandidates/interface/PackedCandidate.h +++ b/DataFormats/PatCandidates/interface/PackedCandidate.h @@ -837,6 +837,12 @@ namespace pat { /// Return first hit from HitPattern for tracks with high level details uint16_t firstHit() const { return firstHit_; } + /// Set/get track algo + void setTrkAlgo(uint8_t algo) { trkAlgo_ = algo; } + void setTrkOriginalAlgo(uint8_t algo) { trkOriginalAlgo_ = algo; } + uint8_t trkAlgo() const { return trkAlgo_; } + uint8_t trkOriginalAlgo() const { return trkOriginalAlgo_; } + void setMuonID(bool isStandAlone, bool isGlobal) { int16_t muonFlags = isStandAlone | (2 * isGlobal); qualityFlags_ = (qualityFlags_ & ~muonFlagsMask) | ((muonFlags << muonFlagsShift) & muonFlagsMask); @@ -1111,6 +1117,10 @@ namespace pat { /// details (hit pattern) of the first hit on track uint16_t firstHit_; + /// track algorithm details + uint8_t trkAlgo_ = 0; + uint8_t trkOriginalAlgo_ = 0; + /// check overlap with another Candidate bool overlap(const reco::Candidate &) const override; template diff --git a/DataFormats/PatCandidates/src/classes_def_objects.xml b/DataFormats/PatCandidates/src/classes_def_objects.xml index 88fb44593ba8d..883694c1c14da 100644 --- a/DataFormats/PatCandidates/src/classes_def_objects.xml +++ b/DataFormats/PatCandidates/src/classes_def_objects.xml @@ -333,7 +333,8 @@ - + + diff --git a/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc b/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc index a0eab7ae1e23a..f9c20b4ec0b59 100644 --- a/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc +++ b/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc @@ -311,6 +311,8 @@ void pat::PATLostTracks::addPackedCandidate(std::vector& c cands.back().setTrackHighPurity(trk->quality(reco::TrackBase::highPurity)); cands.back().setCovarianceVersion(covarianceVersion_); cands.back().setLostInnerHits(lostHits); + cands.back().setTrkAlgo(static_cast(trk->algo())); + cands.back().setTrkOriginalAlgo(static_cast(trk->originalAlgo())); if (trk->pt() > minPtToStoreProps_ || trkStatus == TrkStatus::VTX) { if (useLegacySetup_ || std::abs(id) == 11 || trkStatus == TrkStatus::VTX) { cands.back().setTrackProperties(*trk, covariancePackingSchemas_[4], covarianceVersion_); diff --git a/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc b/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc index b6b1e9209b29a..0517186a21051 100644 --- a/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc @@ -290,6 +290,8 @@ void pat::PATPackedCandidateProducer::produce(edm::StreamID, edm::Event &iEvent, } // properties of the best track outPtrP->back().setLostInnerHits(lostHits); + outPtrP->back().setTrkAlgo(static_cast(ctrack->algo())); + outPtrP->back().setTrkOriginalAlgo(static_cast(ctrack->originalAlgo())); if (outPtrP->back().pt() > minPtForTrackProperties_ || outPtrP->back().ptTrk() > minPtForTrackProperties_ || whiteList.find(ic) != whiteList.end() || (cand.trackRef().isNonnull() && whiteListTk.find(cand.trackRef()) != whiteListTk.end())) { diff --git a/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc index f04ce9e473caa..fc95565960c80 100644 --- a/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc +++ b/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc @@ -647,6 +647,8 @@ void DeepBoostedJetTagInfoProducer::fillParticleFeatures(DeepBoostedJetFeatures } else lostHits = (nlost == 1 ? pat::PackedCandidate::oneLostInnerHit : pat::PackedCandidate::moreLostInnerHits); candidate.setLostInnerHits(lostHits); + candidate.setTrkAlgo(static_cast(track->algo())); + candidate.setTrkOriginalAlgo(static_cast(track->originalAlgo())); if (useTrackProperties(reco_cand) or std::find(whiteListSV.begin(), whiteListSV.end(), icand) != whiteListSV.end() or From e6cbe22c98edbf995ff58082c6b5b8013c3d83c6 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sun, 26 Mar 2023 18:42:33 +0200 Subject: [PATCH 2/4] add trk algo to copy methods as well --- .../PatCandidates/interface/PackedCandidate.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/DataFormats/PatCandidates/interface/PackedCandidate.h b/DataFormats/PatCandidates/interface/PackedCandidate.h index 4a20f29a6d792..dd3fd3b6b769a 100644 --- a/DataFormats/PatCandidates/interface/PackedCandidate.h +++ b/DataFormats/PatCandidates/interface/PackedCandidate.h @@ -221,7 +221,9 @@ namespace pat { normalizedChi2_(iOther.normalizedChi2_), covarianceVersion_(iOther.covarianceVersion_), covarianceSchema_(iOther.covarianceSchema_), - firstHit_(iOther.firstHit_) {} + firstHit_(iOther.firstHit_), + trkAlgo_(iOther.trkAlgo_), + trkOriginalAlgo_(iOther.trkOriginalAlgo_) {} PackedCandidate(PackedCandidate &&iOther) : packedPt_(iOther.packedPt_), @@ -262,7 +264,9 @@ namespace pat { normalizedChi2_(iOther.normalizedChi2_), covarianceVersion_(iOther.covarianceVersion_), covarianceSchema_(iOther.covarianceSchema_), - firstHit_(iOther.firstHit_) {} + firstHit_(iOther.firstHit_), + trkAlgo_(iOther.trkAlgo_), + trkOriginalAlgo_(iOther.trkOriginalAlgo_) {} PackedCandidate &operator=(const PackedCandidate &iOther) { if (this == &iOther) { @@ -339,6 +343,8 @@ namespace pat { covarianceVersion_ = iOther.covarianceVersion_; covarianceSchema_ = iOther.covarianceSchema_; firstHit_ = iOther.firstHit_; + trkAlgo_ = iOther.trkAlgo_; + trkOriginalAlgo_ = iOther.trkOriginalAlgo_; return *this; } @@ -385,6 +391,8 @@ namespace pat { covarianceVersion_ = iOther.covarianceVersion_; covarianceSchema_ = iOther.covarianceSchema_; firstHit_ = iOther.firstHit_; + trkAlgo_ = iOther.trkAlgo_; + trkOriginalAlgo_ = iOther.trkOriginalAlgo_; return *this; } From da0cb6d37a70c95e8523b4a54f3c5412d9403e6d Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sun, 26 Mar 2023 23:20:56 +0200 Subject: [PATCH 3/4] save trk algo only for better tracks (minPtForTrackProp) --- PhysicsTools/PatAlgos/plugins/PATLostTracks.cc | 4 ++-- PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc b/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc index f9c20b4ec0b59..8e0e4877d83bf 100644 --- a/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc +++ b/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc @@ -311,9 +311,9 @@ void pat::PATLostTracks::addPackedCandidate(std::vector& c cands.back().setTrackHighPurity(trk->quality(reco::TrackBase::highPurity)); cands.back().setCovarianceVersion(covarianceVersion_); cands.back().setLostInnerHits(lostHits); - cands.back().setTrkAlgo(static_cast(trk->algo())); - cands.back().setTrkOriginalAlgo(static_cast(trk->originalAlgo())); if (trk->pt() > minPtToStoreProps_ || trkStatus == TrkStatus::VTX) { + cands.back().setTrkAlgo(static_cast(trk->algo())); + cands.back().setTrkOriginalAlgo(static_cast(trk->originalAlgo())); if (useLegacySetup_ || std::abs(id) == 11 || trkStatus == TrkStatus::VTX) { cands.back().setTrackProperties(*trk, covariancePackingSchemas_[4], covarianceVersion_); } else { diff --git a/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc b/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc index 0517186a21051..17ff078191a2a 100644 --- a/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc @@ -290,11 +290,11 @@ void pat::PATPackedCandidateProducer::produce(edm::StreamID, edm::Event &iEvent, } // properties of the best track outPtrP->back().setLostInnerHits(lostHits); - outPtrP->back().setTrkAlgo(static_cast(ctrack->algo())); - outPtrP->back().setTrkOriginalAlgo(static_cast(ctrack->originalAlgo())); if (outPtrP->back().pt() > minPtForTrackProperties_ || outPtrP->back().ptTrk() > minPtForTrackProperties_ || whiteList.find(ic) != whiteList.end() || (cand.trackRef().isNonnull() && whiteListTk.find(cand.trackRef()) != whiteListTk.end())) { + outPtrP->back().setTrkAlgo(static_cast(ctrack->algo())); + outPtrP->back().setTrkOriginalAlgo(static_cast(ctrack->originalAlgo())); outPtrP->back().setFirstHit(ctrack->hitPattern().getHitPattern(reco::HitPattern::TRACK_HITS, 0)); if (abs(outPtrP->back().pdgId()) == 22) { outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[4], covarianceVersion_); From 1e3b6294f88fcd2121db6cf07a551076ad6518f4 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Mon, 27 Mar 2023 19:33:23 +0200 Subject: [PATCH 4/4] pack algo and originalAlgo to a uint16_t, original saved in the upper 8 bits only if algo!=original --- .../PatCandidates/interface/PackedCandidate.h | 26 +++++++++---------- .../PatCandidates/src/classes_def_objects.xml | 2 +- .../PatAlgos/plugins/PATLostTracks.cc | 3 +-- .../plugins/PATPackedCandidateProducer.cc | 3 +-- .../plugins/DeepBoostedJetTagInfoProducer.cc | 3 +-- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/DataFormats/PatCandidates/interface/PackedCandidate.h b/DataFormats/PatCandidates/interface/PackedCandidate.h index dd3fd3b6b769a..da0f6745d85b1 100644 --- a/DataFormats/PatCandidates/interface/PackedCandidate.h +++ b/DataFormats/PatCandidates/interface/PackedCandidate.h @@ -222,8 +222,7 @@ namespace pat { covarianceVersion_(iOther.covarianceVersion_), covarianceSchema_(iOther.covarianceSchema_), firstHit_(iOther.firstHit_), - trkAlgo_(iOther.trkAlgo_), - trkOriginalAlgo_(iOther.trkOriginalAlgo_) {} + trkAlgoPacked_(iOther.trkAlgoPacked_) {} PackedCandidate(PackedCandidate &&iOther) : packedPt_(iOther.packedPt_), @@ -265,8 +264,7 @@ namespace pat { covarianceVersion_(iOther.covarianceVersion_), covarianceSchema_(iOther.covarianceSchema_), firstHit_(iOther.firstHit_), - trkAlgo_(iOther.trkAlgo_), - trkOriginalAlgo_(iOther.trkOriginalAlgo_) {} + trkAlgoPacked_(iOther.trkAlgoPacked_) {} PackedCandidate &operator=(const PackedCandidate &iOther) { if (this == &iOther) { @@ -343,8 +341,7 @@ namespace pat { covarianceVersion_ = iOther.covarianceVersion_; covarianceSchema_ = iOther.covarianceSchema_; firstHit_ = iOther.firstHit_; - trkAlgo_ = iOther.trkAlgo_; - trkOriginalAlgo_ = iOther.trkOriginalAlgo_; + trkAlgoPacked_ = iOther.trkAlgoPacked_; return *this; } @@ -391,8 +388,7 @@ namespace pat { covarianceVersion_ = iOther.covarianceVersion_; covarianceSchema_ = iOther.covarianceSchema_; firstHit_ = iOther.firstHit_; - trkAlgo_ = iOther.trkAlgo_; - trkOriginalAlgo_ = iOther.trkOriginalAlgo_; + trkAlgoPacked_ = iOther.trkAlgoPacked_; return *this; } @@ -846,10 +842,13 @@ namespace pat { uint16_t firstHit() const { return firstHit_; } /// Set/get track algo - void setTrkAlgo(uint8_t algo) { trkAlgo_ = algo; } - void setTrkOriginalAlgo(uint8_t algo) { trkOriginalAlgo_ = algo; } - uint8_t trkAlgo() const { return trkAlgo_; } - uint8_t trkOriginalAlgo() const { return trkOriginalAlgo_; } + void setTrkAlgo(uint8_t algo, uint8_t original) { + trkAlgoPacked_ = algo | ((algo == original ? 0 : original) << 8); + } + uint8_t trkAlgo() const { return trkAlgoPacked_ & 0xff; } + uint8_t trkOriginalAlgo() const { + return (trkAlgoPacked_ & 0xff00) == 0 ? trkAlgo() : ((trkAlgoPacked_ >> 8) & 0xff); + } void setMuonID(bool isStandAlone, bool isGlobal) { int16_t muonFlags = isStandAlone | (2 * isGlobal); @@ -1126,8 +1125,7 @@ namespace pat { uint16_t firstHit_; /// track algorithm details - uint8_t trkAlgo_ = 0; - uint8_t trkOriginalAlgo_ = 0; + uint16_t trkAlgoPacked_ = 0; /// check overlap with another Candidate bool overlap(const reco::Candidate &) const override; diff --git a/DataFormats/PatCandidates/src/classes_def_objects.xml b/DataFormats/PatCandidates/src/classes_def_objects.xml index 883694c1c14da..ec313ac77a3dc 100644 --- a/DataFormats/PatCandidates/src/classes_def_objects.xml +++ b/DataFormats/PatCandidates/src/classes_def_objects.xml @@ -334,7 +334,7 @@ - + diff --git a/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc b/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc index 8e0e4877d83bf..fa875f631edd4 100644 --- a/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc +++ b/PhysicsTools/PatAlgos/plugins/PATLostTracks.cc @@ -312,8 +312,7 @@ void pat::PATLostTracks::addPackedCandidate(std::vector& c cands.back().setCovarianceVersion(covarianceVersion_); cands.back().setLostInnerHits(lostHits); if (trk->pt() > minPtToStoreProps_ || trkStatus == TrkStatus::VTX) { - cands.back().setTrkAlgo(static_cast(trk->algo())); - cands.back().setTrkOriginalAlgo(static_cast(trk->originalAlgo())); + cands.back().setTrkAlgo(static_cast(trk->algo()), static_cast(trk->originalAlgo())); if (useLegacySetup_ || std::abs(id) == 11 || trkStatus == TrkStatus::VTX) { cands.back().setTrackProperties(*trk, covariancePackingSchemas_[4], covarianceVersion_); } else { diff --git a/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc b/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc index 17ff078191a2a..f0d2f7c4bad7f 100644 --- a/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc +++ b/PhysicsTools/PatAlgos/plugins/PATPackedCandidateProducer.cc @@ -293,8 +293,7 @@ void pat::PATPackedCandidateProducer::produce(edm::StreamID, edm::Event &iEvent, if (outPtrP->back().pt() > minPtForTrackProperties_ || outPtrP->back().ptTrk() > minPtForTrackProperties_ || whiteList.find(ic) != whiteList.end() || (cand.trackRef().isNonnull() && whiteListTk.find(cand.trackRef()) != whiteListTk.end())) { - outPtrP->back().setTrkAlgo(static_cast(ctrack->algo())); - outPtrP->back().setTrkOriginalAlgo(static_cast(ctrack->originalAlgo())); + outPtrP->back().setTrkAlgo(static_cast(ctrack->algo()), static_cast(ctrack->originalAlgo())); outPtrP->back().setFirstHit(ctrack->hitPattern().getHitPattern(reco::HitPattern::TRACK_HITS, 0)); if (abs(outPtrP->back().pdgId()) == 22) { outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[4], covarianceVersion_); diff --git a/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc b/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc index fc95565960c80..71ebc0a1538f2 100644 --- a/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc +++ b/RecoBTag/FeatureTools/plugins/DeepBoostedJetTagInfoProducer.cc @@ -647,8 +647,7 @@ void DeepBoostedJetTagInfoProducer::fillParticleFeatures(DeepBoostedJetFeatures } else lostHits = (nlost == 1 ? pat::PackedCandidate::oneLostInnerHit : pat::PackedCandidate::moreLostInnerHits); candidate.setLostInnerHits(lostHits); - candidate.setTrkAlgo(static_cast(track->algo())); - candidate.setTrkOriginalAlgo(static_cast(track->originalAlgo())); + candidate.setTrkAlgo(static_cast(track->algo()), static_cast(track->originalAlgo())); if (useTrackProperties(reco_cand) or std::find(whiteListSV.begin(), whiteListSV.end(), icand) != whiteListSV.end() or