-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Addition of packedCandidates track chi2 information to pp_on_AA miniAOD #30566
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e702f55
added chi2 map for packedPFCandidates
abaty 99b9c44
added code style patch
abaty 368a104
some changes based on code reviews
abaty 624bebc
changes based on code review
abaty 8a323e4
forgot a comma
abaty 0b4036e
added code formatting
abaty 8bc215d
Merge branch 'master' into Chi2MapMaster
abaty 0c885df
reduced chi2 precision futher
abaty b133b57
fixed bug with null pointer refernece
abaty 0cf27e8
small python formatting change for pp_on_AA
abaty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
PhysicsTools/PatAlgos/plugins/PackedCandidateTrackChi2Producer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#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" | ||
#include "DataFormats/Math/interface/libminifloat.h" | ||
|
||
namespace pat { | ||
|
||
class PackedCandidateTrackChi2Producer : public edm::stream::EDProducer<> { | ||
typedef edm::ValueMap<float> FloatMap; | ||
|
||
public: | ||
explicit PackedCandidateTrackChi2Producer(const edm::ParameterSet& iConfig) | ||
: candidateToken_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("candidates"))), | ||
trackToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trackCollection"))), | ||
doLostTracks_(iConfig.getParameter<bool>("doLostTracks")) { | ||
if (doLostTracks_) { | ||
track2LostTrackToken_ = consumes<edm::Association<pat::PackedCandidateCollection>>( | ||
iConfig.getParameter<edm::InputTag>("candidates")); | ||
} else { | ||
candidate2PFToken_ = | ||
consumes<edm::Association<reco::PFCandidateCollection>>(iConfig.getParameter<edm::InputTag>("candidates")); | ||
} | ||
|
||
produces<FloatMap>(); | ||
} | ||
|
||
void produce(edm::Event&, const edm::EventSetup&) override; | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions&); | ||
|
||
private: | ||
const edm::EDGetTokenT<pat::PackedCandidateCollection> candidateToken_; | ||
edm::EDGetTokenT<edm::Association<reco::PFCandidateCollection>> candidate2PFToken_; | ||
edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>> track2LostTrackToken_; | ||
const edm::EDGetTokenT<reco::TrackCollection> trackToken_; | ||
const bool doLostTracks_; | ||
static const uint8_t roundingPrecision = 8; | ||
}; | ||
|
||
} // namespace pat | ||
|
||
void pat::PackedCandidateTrackChi2Producer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { | ||
auto const candidates = iEvent.getHandle(candidateToken_); | ||
|
||
const edm::Association<reco::PFCandidateCollection>* candidate2PF = nullptr; | ||
if (!doLostTracks_) { | ||
candidate2PF = &iEvent.get(candidate2PFToken_); | ||
} | ||
|
||
const edm::Association<pat::PackedCandidateCollection>* tracks2LT = nullptr; | ||
edm::Handle<reco::TrackCollection> trks; | ||
if (doLostTracks_) { | ||
tracks2LT = &iEvent.get(track2LostTrackToken_); | ||
iEvent.getByToken(trackToken_, trks); | ||
} | ||
|
||
const auto nCand = candidates->size(); | ||
std::vector<float> 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++) { | ||
const auto& trk = reco::TrackRef(trks, i); | ||
const auto& lostTrack = (*tracks2LT)[trk]; | ||
if (lostTrack.isNonnull()) { | ||
const float nChi2 = trk->normalizedChi2(); | ||
trkChi2Map.at(lostTrack.key()) = MiniFloatConverter::reduceMantissaToNbitsRounding<roundingPrecision>(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); | ||
|
||
// ignore neutral candidates or without track | ||
if (cand->charge() == 0 || !cand->hasTrackDetails()) | ||
continue; | ||
|
||
const auto& candTrack = (*candidate2PF)[cand]->trackRef(); | ||
|
||
if (candTrack.isNonnull()) { | ||
const float nChi2 = candTrack->normalizedChi2(); | ||
|
||
trkChi2Map.at(i) = MiniFloatConverter::reduceMantissaToNbitsRounding<roundingPrecision>(nChi2); | ||
} | ||
} | ||
} | ||
|
||
// fill the value maps | ||
std::unique_ptr<FloatMap> valueMap = std::make_unique<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<edm::InputTag>("candidates", edm::InputTag("packedPFCandidates")) | ||
->setComment("packed candidate input collection"); | ||
desc.add<edm::InputTag>("trackCollection", edm::InputTag("generalTracks"))->setComment("track input collection"); | ||
desc.add<bool>("doLostTracks", false); | ||
descriptions.add("packedPFCandidateTrackChi2", desc); | ||
} | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
using namespace pat; | ||
DEFINE_FWK_MODULE(PackedCandidateTrackChi2Producer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -67,7 +67,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 = "lostTracks", doLostTracks = True) | ||||||||||
(pp_on_AA_2018 | pp_on_PbPb_run3).toReplaceWith(slimmingTask, cms.Task(slimmingTask.copy(), packedCandidateMuonID, packedPFCandidateTrackChi2, lostTrackChi2)) | ||||||||||
|
||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
not required, but something to make the update a bit more readable |
||||||||||
|
||||||||||
from Configuration.Eras.Modifier_phase2_timing_cff import phase2_timing | ||||||||||
_phase2_timing_slimmingTask = cms.Task(slimmingTask.copy(), | ||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for isNonnull here.