From 1e3b6294f88fcd2121db6cf07a551076ad6518f4 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Mon, 27 Mar 2023 19:33:23 +0200 Subject: [PATCH] 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