From e702f55854fb61205ee5b51590f8ddb848972189 Mon Sep 17 00:00:00 2001 From: abaty Date: Tue, 7 Jul 2020 00:31:09 +0200 Subject: [PATCH 1/9] added chi2 map for packedPFCandidates --- .../PackedCandidateTrackChi2Producer.cc | 115 ++++++++++++++++++ .../python/slimming/MicroEventContent_cff.py | 5 +- .../PatAlgos/python/slimming/slimming_cff.py | 6 +- 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc diff --git a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc new file mode 100644 index 0000000000000..f0e8a6576e3c4 --- /dev/null +++ b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc @@ -0,0 +1,115 @@ +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/PatCandidates/interface/PackedCandidate.h" + +namespace pat { + + class PackedCandidateTrackChi2Producer : public edm::stream::EDProducer<> { + + typedef edm::ValueMap FloatMap; + + public: + + explicit PackedCandidateTrackChi2Producer(const edm::ParameterSet & iConfig): + candidateToken_(consumes >(iConfig.getParameter("candidates"))), + trackToken_(consumes>(iConfig.getParameter("trackCollection"))), + doLostTracks_(iConfig.getParameter("doLostTracks")) + { + if(doLostTracks_){ + track2LostTrackToken_ = consumes >( iConfig.getParameter("candidates")); + } + else{ + candidate2PFToken_ = consumes >( iConfig.getParameter("candidates")); + } + + produces(); + } + ~PackedCandidateTrackChi2Producer() override {}; + + void produce(edm::Event&, const edm::EventSetup&) override; + + static void fillDescriptions(edm::ConfigurationDescriptions&); + + private: + + edm::EDGetTokenT > candidateToken_; + edm::EDGetTokenT > candidate2PFToken_; + edm::EDGetTokenT > track2LostTrackToken_; + edm::EDGetTokenT> trackToken_; + bool doLostTracks_; + + }; + +} + +void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + edm::Handle > candidates; + iEvent.getByToken(candidateToken_, candidates); + + edm::Handle< edm::Association > candidate2PF; + if(!doLostTracks_){ + iEvent.getByToken(candidate2PFToken_, candidate2PF); + } + + edm::Handle< edm::Association > tracks2LT; + edm::Handle> trks; + if(doLostTracks_){ + iEvent.getByToken(track2LostTrackToken_, tracks2LT); + iEvent.getByToken(trackToken_, trks); + } + + + const auto& nCand = candidates->size(); + std::vector< float > trkChi2Map(nCand, 0); + + for (size_t i = 0; i < nCand; i++) { + const auto& cand = candidates->refAt(i); + float nChi2 = 0; + + // ignore neutral candidates or without track + if (cand->charge()==0 || !cand->hasTrackDetails()) continue; + + if(doLostTracks_){ //for Lost tracks we don't have references to PFCands, so we must loop over tracks and check keys... + for(size_t j = 0; jsize(); j++){ + const auto& trk = trks->refAt(j); + const auto& lostTrack = (*tracks2LT)[trk]; + if (lostTrack.isNonnull() && (cand.id() == lostTrack.id()) && (cand.key() == lostTrack.key()) ){ + nChi2 = trk->normalizedChi2(); + break; + } + } + } + else{ //for the regular PackedPFCands we have direct references... + const auto& candTrack = (*candidate2PF)[cand]->trackRef(); + nChi2 = candTrack->normalizedChi2(); + } + + trkChi2Map.at(i) = nChi2; + } + + // fill the value maps + std::unique_ptr valueMap(new FloatMap()); + FloatMap::Filler filler(*valueMap); + filler.insert(candidates, trkChi2Map.begin(), trkChi2Map.end()); + filler.fill(); + iEvent.put(std::move(valueMap),""); +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void pat::PackedCandidateTrackChi2Producer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("candidates", edm::InputTag("packedPFCandidates"))->setComment("packed candidate input collection"); + desc.add("trackCollection", edm::InputTag("generalTracks"))->setComment("track input collection"); + desc.add("doLostTracks", false); + descriptions.add("packedPFCandidateTrackChi2", desc); +} + +#include "FWCore/Framework/interface/MakerMacros.h" +using namespace pat; +DEFINE_FWK_MODULE(PackedCandidateTrackChi2Producer); diff --git a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py index dc7a34c735e6a..38296977b7c8f 100644 --- a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py @@ -134,7 +134,10 @@ run3_common.toModify(MicroEventContent, outputCommands = MicroEventContent.outputCommands + _run3_common_extraCommands) # --- -_pp_on_AA_extraCommands = ['keep *_packedCandidateMuonID_*_*'] +_pp_on_AA_extraCommands = [ + 'keep *_packedCandidateMuonID_*_*', + 'keep floatedmValueMap_*TrackChi2_*_*' +] from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018 from Configuration.Eras.Modifier_pp_on_PbPb_run3_cff import pp_on_PbPb_run3 (pp_on_AA_2018 | pp_on_PbPb_run3).toModify(MicroEventContent, outputCommands = MicroEventContent.outputCommands + _pp_on_AA_extraCommands) diff --git a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py index c6cf5ef282286..f73a9b30d499b 100644 --- a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py @@ -64,7 +64,11 @@ from Configuration.Eras.Modifier_pp_on_PbPb_run3_cff import pp_on_PbPb_run3 from PhysicsTools.PatAlgos.packedCandidateMuonID_cfi import packedCandidateMuonID -(pp_on_AA_2018 | pp_on_PbPb_run3).toReplaceWith(slimmingTask, cms.Task(slimmingTask.copy(), packedCandidateMuonID)) +from PhysicsTools.PatAlgos.packedPFCandidateTrackChi2_cfi import packedPFCandidateTrackChi2 +lostTrackChi2 = packedPFCandidateTrackChi2.clone(candidates = cms.InputTag("lostTracks"), doLostTracks = cms.bool(True)) +(pp_on_AA_2018 | pp_on_PbPb_run3).toReplaceWith(slimmingTask, cms.Task(slimmingTask.copy(), packedCandidateMuonID, packedPFCandidateTrackChi2, lostTrackChi2)) + + from Configuration.Eras.Modifier_phase2_timing_cff import phase2_timing _phase2_timing_slimmingTask = cms.Task(slimmingTask.copy(), From 99b9c449ecf9aab62531bdcd4a7c943fa3a1a3cd Mon Sep 17 00:00:00 2001 From: abaty Date: Wed, 8 Jul 2020 19:23:31 +0200 Subject: [PATCH 2/9] added code style patch --- .../PackedCandidateTrackChi2Producer.cc | 90 +++++++++---------- 1 file changed, 43 insertions(+), 47 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc index f0e8a6576e3c4..a083bfb087710 100644 --- a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc +++ b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc @@ -11,86 +11,81 @@ namespace pat { class PackedCandidateTrackChi2Producer : public edm::stream::EDProducer<> { - typedef edm::ValueMap FloatMap; - public: - - explicit PackedCandidateTrackChi2Producer(const edm::ParameterSet & iConfig): - candidateToken_(consumes >(iConfig.getParameter("candidates"))), + public: + explicit PackedCandidateTrackChi2Producer(const edm::ParameterSet& iConfig) + : candidateToken_(consumes>(iConfig.getParameter("candidates"))), trackToken_(consumes>(iConfig.getParameter("trackCollection"))), - doLostTracks_(iConfig.getParameter("doLostTracks")) - { - if(doLostTracks_){ - track2LostTrackToken_ = consumes >( iConfig.getParameter("candidates")); - } - else{ - candidate2PFToken_ = consumes >( iConfig.getParameter("candidates")); - } - - produces(); + doLostTracks_(iConfig.getParameter("doLostTracks")) { + if (doLostTracks_) { + track2LostTrackToken_ = consumes>( + iConfig.getParameter("candidates")); + } else { + candidate2PFToken_ = + consumes>(iConfig.getParameter("candidates")); } - ~PackedCandidateTrackChi2Producer() override {}; - - void produce(edm::Event&, const edm::EventSetup&) override; - static void fillDescriptions(edm::ConfigurationDescriptions&); + produces(); + } + ~PackedCandidateTrackChi2Producer() override{}; - private: + void produce(edm::Event&, const edm::EventSetup&) override; - edm::EDGetTokenT > candidateToken_; - edm::EDGetTokenT > candidate2PFToken_; - edm::EDGetTokenT > track2LostTrackToken_; - edm::EDGetTokenT> trackToken_; - bool doLostTracks_; + static void fillDescriptions(edm::ConfigurationDescriptions&); + private: + edm::EDGetTokenT> candidateToken_; + edm::EDGetTokenT> candidate2PFToken_; + edm::EDGetTokenT> track2LostTrackToken_; + edm::EDGetTokenT> trackToken_; + bool doLostTracks_; }; -} +} // namespace pat void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - edm::Handle > candidates; + edm::Handle> candidates; iEvent.getByToken(candidateToken_, candidates); - edm::Handle< edm::Association > candidate2PF; - if(!doLostTracks_){ + edm::Handle> candidate2PF; + if (!doLostTracks_) { iEvent.getByToken(candidate2PFToken_, candidate2PF); } - edm::Handle< edm::Association > tracks2LT; + edm::Handle> tracks2LT; edm::Handle> trks; - if(doLostTracks_){ + if (doLostTracks_) { iEvent.getByToken(track2LostTrackToken_, tracks2LT); iEvent.getByToken(trackToken_, trks); } - const auto& nCand = candidates->size(); - std::vector< float > trkChi2Map(nCand, 0); + std::vector trkChi2Map(nCand, 0); for (size_t i = 0; i < nCand; i++) { const auto& cand = candidates->refAt(i); - float nChi2 = 0; + float nChi2 = 0; // ignore neutral candidates or without track - if (cand->charge()==0 || !cand->hasTrackDetails()) continue; + if (cand->charge() == 0 || !cand->hasTrackDetails()) + continue; - if(doLostTracks_){ //for Lost tracks we don't have references to PFCands, so we must loop over tracks and check keys... - for(size_t j = 0; jsize(); j++){ + if (doLostTracks_) { //for Lost tracks we don't have references to PFCands, so we must loop over tracks and check keys... + for (size_t j = 0; j < trks->size(); j++) { const auto& trk = trks->refAt(j); const auto& lostTrack = (*tracks2LT)[trk]; - if (lostTrack.isNonnull() && (cand.id() == lostTrack.id()) && (cand.key() == lostTrack.key()) ){ - nChi2 = trk->normalizedChi2(); + if (lostTrack.isNonnull() && (cand.id() == lostTrack.id()) && (cand.key() == lostTrack.key())) { + nChi2 = trk->normalizedChi2(); break; } } - } - else{ //for the regular PackedPFCands we have direct references... + } else { //for the regular PackedPFCands we have direct references... const auto& candTrack = (*candidate2PF)[cand]->trackRef(); nChi2 = candTrack->normalizedChi2(); } - - trkChi2Map.at(i) = nChi2; + + trkChi2Map.at(i) = nChi2; } // fill the value maps @@ -98,15 +93,16 @@ void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const ed FloatMap::Filler filler(*valueMap); filler.insert(candidates, trkChi2Map.begin(), trkChi2Map.end()); filler.fill(); - iEvent.put(std::move(valueMap),""); + iEvent.put(std::move(valueMap), ""); } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ void pat::PackedCandidateTrackChi2Producer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("candidates", edm::InputTag("packedPFCandidates"))->setComment("packed candidate input collection"); - desc.add("trackCollection", edm::InputTag("generalTracks"))->setComment("track input collection"); - desc.add("doLostTracks", false); + desc.add("candidates", edm::InputTag("packedPFCandidates")) + ->setComment("packed candidate input collection"); + desc.add("trackCollection", edm::InputTag("generalTracks"))->setComment("track input collection"); + desc.add("doLostTracks", false); descriptions.add("packedPFCandidateTrackChi2", desc); } From 368a1043e4c0b04d49803985342d2285d2a6b079 Mon Sep 17 00:00:00 2001 From: abaty Date: Fri, 10 Jul 2020 23:29:08 +0200 Subject: [PATCH 3/9] some changes based on code reviews --- .../PackedCandidateTrackChi2Producer.cc | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc index a083bfb087710..ed912ea90850d 100644 --- a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc +++ b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc @@ -7,6 +7,7 @@ #include "DataFormats/PatCandidates/interface/Muon.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/PatCandidates/interface/PackedCandidate.h" +#include "DataFormats/Math/interface/libminifloat.h" namespace pat { @@ -28,18 +29,17 @@ namespace pat { produces(); } - ~PackedCandidateTrackChi2Producer() override{}; void produce(edm::Event&, const edm::EventSetup&) override; static void fillDescriptions(edm::ConfigurationDescriptions&); private: - edm::EDGetTokenT> candidateToken_; + const edm::EDGetTokenT> candidateToken_; edm::EDGetTokenT> candidate2PFToken_; edm::EDGetTokenT> track2LostTrackToken_; - edm::EDGetTokenT> trackToken_; - bool doLostTracks_; + const edm::EDGetTokenT> trackToken_; + const bool doLostTracks_; }; } // namespace pat @@ -48,48 +48,51 @@ void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const ed edm::Handle> candidates; iEvent.getByToken(candidateToken_, candidates); - edm::Handle> candidate2PF; + const edm::Association* candidate2PF = nullptr; if (!doLostTracks_) { - iEvent.getByToken(candidate2PFToken_, candidate2PF); + candidate2PF = &iEvent.get(candidate2PFToken_); } - edm::Handle> tracks2LT; + const edm::Association* tracks2LT = nullptr; edm::Handle> trks; if (doLostTracks_) { - iEvent.getByToken(track2LostTrackToken_, tracks2LT); + tracks2LT = &iEvent.get(track2LostTrackToken_); iEvent.getByToken(trackToken_, trks); } - const auto& nCand = candidates->size(); + const auto nCand = candidates->size(); std::vector trkChi2Map(nCand, 0); - for (size_t i = 0; i < nCand; i++) { - const auto& cand = candidates->refAt(i); - float nChi2 = 0; - - // ignore neutral candidates or without track - if (cand->charge() == 0 || !cand->hasTrackDetails()) - continue; - - if (doLostTracks_) { //for Lost tracks we don't have references to PFCands, so we must loop over tracks and check keys... - for (size_t j = 0; j < trks->size(); j++) { - const auto& trk = trks->refAt(j); - const auto& lostTrack = (*tracks2LT)[trk]; - if (lostTrack.isNonnull() && (cand.id() == lostTrack.id()) && (cand.key() == lostTrack.key())) { - nChi2 = trk->normalizedChi2(); - break; - } + + if (doLostTracks_) { //for Lost tracks we don't have references to PFCands, so we must loop over tracks and check keys... + for (size_t i = 0; i < trks->size(); i++) { + float nChi2 = 0; + const auto& trk = trks->refAt(i); + const auto& lostTrack = (*tracks2LT)[trk]; + //if (lostTrack.isNonnull() && (cand.id() == lostTrack.id()) && (cand.key() == lostTrack.key())) { + if (lostTrack.isNonnull()) { + nChi2 = trk->normalizedChi2(); + trkChi2Map.at(lostTrack.key()) = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(nChi2); } - } else { //for the regular PackedPFCands we have direct references... + } + } else { //for the regular PackedPFCands we have direct references... + for (size_t i = 0; i < nCand; i++) { + const auto& cand = candidates->refAt(i); + float nChi2 = 0; + + // ignore neutral candidates or without track + if (cand->charge() == 0 || !cand->hasTrackDetails()) + continue; + const auto& candTrack = (*candidate2PF)[cand]->trackRef(); nChi2 = candTrack->normalizedChi2(); - } - trkChi2Map.at(i) = nChi2; + trkChi2Map.at(i) = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(nChi2); + } } // fill the value maps - std::unique_ptr valueMap(new FloatMap()); + std::unique_ptr valueMap = std::make_unique(); FloatMap::Filler filler(*valueMap); filler.insert(candidates, trkChi2Map.begin(), trkChi2Map.end()); filler.fill(); From 624bebc2c058257017978d0b81e2e9fef766bcba Mon Sep 17 00:00:00 2001 From: abaty Date: Sat, 11 Jul 2020 00:50:06 +0200 Subject: [PATCH 4/9] changes based on code review --- .../PackedCandidateTrackChi2Producer.cc | 18 +++++++++--------- .../python/slimming/MicroEventContent_cff.py | 3 ++- .../PatAlgos/python/slimming/slimming_cff.py | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc index ed912ea90850d..b7206243635ce 100644 --- a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc +++ b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc @@ -16,8 +16,8 @@ namespace pat { public: explicit PackedCandidateTrackChi2Producer(const edm::ParameterSet& iConfig) - : candidateToken_(consumes>(iConfig.getParameter("candidates"))), - trackToken_(consumes>(iConfig.getParameter("trackCollection"))), + : candidateToken_(consumes(iConfig.getParameter("candidates"))), + trackToken_(consumes(iConfig.getParameter("trackCollection"))), doLostTracks_(iConfig.getParameter("doLostTracks")) { if (doLostTracks_) { track2LostTrackToken_ = consumes>( @@ -35,17 +35,17 @@ namespace pat { static void fillDescriptions(edm::ConfigurationDescriptions&); private: - const edm::EDGetTokenT> candidateToken_; + const edm::EDGetTokenT candidateToken_; edm::EDGetTokenT> candidate2PFToken_; edm::EDGetTokenT> track2LostTrackToken_; - const edm::EDGetTokenT> trackToken_; + const edm::EDGetTokenT trackToken_; const bool doLostTracks_; }; } // namespace pat void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - edm::Handle> candidates; + edm::Handle candidates; iEvent.getByToken(candidateToken_, candidates); const edm::Association* candidate2PF = nullptr; @@ -54,7 +54,7 @@ void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const ed } const edm::Association* tracks2LT = nullptr; - edm::Handle> trks; + edm::Handle trks; if (doLostTracks_) { tracks2LT = &iEvent.get(track2LostTrackToken_); iEvent.getByToken(trackToken_, trks); @@ -67,9 +67,9 @@ void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const ed if (doLostTracks_) { //for Lost tracks we don't have references to PFCands, so we must loop over tracks and check keys... for (size_t i = 0; i < trks->size(); i++) { float nChi2 = 0; - const auto& trk = trks->refAt(i); + //const auto& trk = trks->refAt(i); + const auto& trk = reco::TrackRef(trks,i); const auto& lostTrack = (*tracks2LT)[trk]; - //if (lostTrack.isNonnull() && (cand.id() == lostTrack.id()) && (cand.key() == lostTrack.key())) { if (lostTrack.isNonnull()) { nChi2 = trk->normalizedChi2(); trkChi2Map.at(lostTrack.key()) = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(nChi2); @@ -77,7 +77,7 @@ void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const ed } } else { //for the regular PackedPFCands we have direct references... for (size_t i = 0; i < nCand; i++) { - const auto& cand = candidates->refAt(i); + const auto& cand = pat::PackedCandidateRef(candidates,i); float nChi2 = 0; // ignore neutral candidates or without track diff --git a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py index 38296977b7c8f..ad7dfefd861ea 100644 --- a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py @@ -136,7 +136,8 @@ _pp_on_AA_extraCommands = [ 'keep *_packedCandidateMuonID_*_*', - 'keep floatedmValueMap_*TrackChi2_*_*' + 'keep floatedmValueMap_packedPFCandidateTrackChi2_*_*' + 'keep floatedmValueMap_lostTrackChi2_*_*' ] from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018 from Configuration.Eras.Modifier_pp_on_PbPb_run3_cff import pp_on_PbPb_run3 diff --git a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py index f73a9b30d499b..8ac50390a0682 100644 --- a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py @@ -65,7 +65,7 @@ from Configuration.Eras.Modifier_pp_on_PbPb_run3_cff import pp_on_PbPb_run3 from PhysicsTools.PatAlgos.packedCandidateMuonID_cfi import packedCandidateMuonID from PhysicsTools.PatAlgos.packedPFCandidateTrackChi2_cfi import packedPFCandidateTrackChi2 -lostTrackChi2 = packedPFCandidateTrackChi2.clone(candidates = cms.InputTag("lostTracks"), doLostTracks = cms.bool(True)) +lostTrackChi2 = packedPFCandidateTrackChi2.clone(candidates = "lostTracks", doLostTracks = True) (pp_on_AA_2018 | pp_on_PbPb_run3).toReplaceWith(slimmingTask, cms.Task(slimmingTask.copy(), packedCandidateMuonID, packedPFCandidateTrackChi2, lostTrackChi2)) From 8a323e49ce1ccbfea40569f227095f1ed0111907 Mon Sep 17 00:00:00 2001 From: abaty Date: Sat, 11 Jul 2020 00:59:06 +0200 Subject: [PATCH 5/9] forgot a comma --- PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py index ad7dfefd861ea..bab23a4e51cc9 100644 --- a/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/MicroEventContent_cff.py @@ -136,7 +136,7 @@ _pp_on_AA_extraCommands = [ 'keep *_packedCandidateMuonID_*_*', - 'keep floatedmValueMap_packedPFCandidateTrackChi2_*_*' + 'keep floatedmValueMap_packedPFCandidateTrackChi2_*_*', 'keep floatedmValueMap_lostTrackChi2_*_*' ] from Configuration.Eras.Modifier_pp_on_AA_2018_cff import pp_on_AA_2018 From 0b4036eebcd0332471b73c2910a8845ef9b2477d Mon Sep 17 00:00:00 2001 From: abaty Date: Tue, 14 Jul 2020 01:20:12 +0200 Subject: [PATCH 6/9] added code formatting --- .../PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc index b7206243635ce..11080cc8b4b2b 100644 --- a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc +++ b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc @@ -63,12 +63,11 @@ void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const ed const auto nCand = candidates->size(); std::vector trkChi2Map(nCand, 0); - if (doLostTracks_) { //for Lost tracks we don't have references to PFCands, so we must loop over tracks and check keys... for (size_t i = 0; i < trks->size(); i++) { float nChi2 = 0; //const auto& trk = trks->refAt(i); - const auto& trk = reco::TrackRef(trks,i); + const auto& trk = reco::TrackRef(trks, i); const auto& lostTrack = (*tracks2LT)[trk]; if (lostTrack.isNonnull()) { nChi2 = trk->normalizedChi2(); @@ -77,7 +76,7 @@ void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const ed } } else { //for the regular PackedPFCands we have direct references... for (size_t i = 0; i < nCand; i++) { - const auto& cand = pat::PackedCandidateRef(candidates,i); + const auto& cand = pat::PackedCandidateRef(candidates, i); float nChi2 = 0; // ignore neutral candidates or without track From 0c885df71252cf2ee8af8e510f977136bbe82407 Mon Sep 17 00:00:00 2001 From: abaty Date: Thu, 16 Jul 2020 03:49:13 +0200 Subject: [PATCH 7/9] reduced chi2 precision futher --- .../plugins/PackedCandidateTrackChi2Producer.cc | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc index 11080cc8b4b2b..b7e60efc5e046 100644 --- a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc +++ b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc @@ -40,13 +40,13 @@ namespace pat { edm::EDGetTokenT> track2LostTrackToken_; const edm::EDGetTokenT trackToken_; const bool doLostTracks_; + static const uint8_t roundingPrecision = 8; }; } // namespace pat void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - edm::Handle candidates; - iEvent.getByToken(candidateToken_, candidates); + auto const candidates = iEvent.getHandle(candidateToken_); const edm::Association* candidate2PF = nullptr; if (!doLostTracks_) { @@ -65,28 +65,25 @@ void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const ed if (doLostTracks_) { //for Lost tracks we don't have references to PFCands, so we must loop over tracks and check keys... for (size_t i = 0; i < trks->size(); i++) { - float nChi2 = 0; - //const auto& trk = trks->refAt(i); const auto& trk = reco::TrackRef(trks, i); const auto& lostTrack = (*tracks2LT)[trk]; if (lostTrack.isNonnull()) { - nChi2 = trk->normalizedChi2(); - trkChi2Map.at(lostTrack.key()) = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(nChi2); + const float nChi2 = trk->normalizedChi2(); + trkChi2Map.at(lostTrack.key()) = MiniFloatConverter::reduceMantissaToNbitsRounding(nChi2); } } } else { //for the regular PackedPFCands we have direct references... for (size_t i = 0; i < nCand; i++) { const auto& cand = pat::PackedCandidateRef(candidates, i); - float nChi2 = 0; // ignore neutral candidates or without track if (cand->charge() == 0 || !cand->hasTrackDetails()) continue; const auto& candTrack = (*candidate2PF)[cand]->trackRef(); - nChi2 = candTrack->normalizedChi2(); + const float nChi2 = candTrack->normalizedChi2(); - trkChi2Map.at(i) = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(nChi2); + trkChi2Map.at(i) = MiniFloatConverter::reduceMantissaToNbitsRounding(nChi2); } } From b133b57bc05d8bbed8e5e0210971b430c4277ede Mon Sep 17 00:00:00 2001 From: abaty Date: Thu, 16 Jul 2020 23:09:52 +0200 Subject: [PATCH 8/9] fixed bug with null pointer refernece --- .../PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc index b7e60efc5e046..748502d054165 100644 --- a/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc +++ b/PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc @@ -81,9 +81,12 @@ void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const ed continue; const auto& candTrack = (*candidate2PF)[cand]->trackRef(); - const float nChi2 = candTrack->normalizedChi2(); - trkChi2Map.at(i) = MiniFloatConverter::reduceMantissaToNbitsRounding(nChi2); + if (candTrack.isNonnull()) { + const float nChi2 = candTrack->normalizedChi2(); + + trkChi2Map.at(i) = MiniFloatConverter::reduceMantissaToNbitsRounding(nChi2); + } } } From 0cf27e88ebcd952ac3e484c2fa5e808fd5cf527f Mon Sep 17 00:00:00 2001 From: abaty Date: Fri, 17 Jul 2020 22:07:15 +0200 Subject: [PATCH 9/9] small python formatting change for pp_on_AA --- PhysicsTools/PatAlgos/python/slimming/slimming_cff.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py index 67e2d9828692f..348465377611a 100644 --- a/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py +++ b/PhysicsTools/PatAlgos/python/slimming/slimming_cff.py @@ -69,7 +69,9 @@ from PhysicsTools.PatAlgos.packedCandidateMuonID_cfi import packedCandidateMuonID from PhysicsTools.PatAlgos.packedPFCandidateTrackChi2_cfi import packedPFCandidateTrackChi2 lostTrackChi2 = packedPFCandidateTrackChi2.clone(candidates = "lostTracks", doLostTracks = True) -(pp_on_AA_2018 | pp_on_PbPb_run3).toReplaceWith(slimmingTask, cms.Task(slimmingTask.copy(), packedCandidateMuonID, packedPFCandidateTrackChi2, lostTrackChi2)) +(pp_on_AA_2018 | pp_on_PbPb_run3).toReplaceWith(slimmingTask, + cms.Task(slimmingTask.copy(), packedCandidateMuonID, + packedPFCandidateTrackChi2, lostTrackChi2))