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
[Backport] Track-gen matching passing through TrackingParticle #33996
Merged
cmsbuild
merged 18 commits into
cms-sw:CMSSW_10_6_X
from
elusian:track-gen-matching-by-tp_10_6_X
Jun 13, 2021
Merged
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ea8ed79
Add plugin to prune the tracking particle and simlink collection base…
beba2ef
Add plugin to propagate a track-gen association from AOD to miniAOD
4687e52
code format
714e15e
apply suggestions
ebe10be
add configuration changes
a55b35f
reapply code format
f57419d
add modifiers for fastsim and add code for when the trackToGen associ…
63dfbc0
code format
0625714
add configurable switch to decide whether to throw or not when a coll…
58564eb
code format
d0514d3
add missing configuration for track association with phase2 tracker
bceee93
adapt code for 10_6 and add bParking modifier
6763355
typo
8ac560f
add missing early return
41687ec
move the first use of trackingParticle after the validity check in MC…
c3d3275
add check for empty association in miniAOD in case of old RAWSIM
e777773
add modification for step2 in the workflow 1304.181 in runthematrix.py
8fa15fc
change dfault behaviour when pruned collections are missing from the …
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
from SimMuon.MCTruth.muonSimClassificationByHits_cff import * | ||
from SimTracker.TrackAssociation.trackPrunedMCMatchTask_cff import * | ||
|
||
recosim = cms.Task( muonSimClassificationByHitsTask ) | ||
recosim = cms.Task( muonSimClassificationByHitsTask, trackPrunedMCMatchTask ) |
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
12 changes: 12 additions & 0 deletions
12
PhysicsTools/PatAlgos/python/slimming/genParticleAssociation_cff.py
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,12 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
packedPFCandidateToGenAssociation = cms.EDProducer("PackedCandidateGenAssociationProducer", | ||
trackToGenAssoc = cms.InputTag("prunedTrackMCMatch"), | ||
) | ||
|
||
lostTracksToGenAssociation = cms.EDProducer("PackedCandidateGenAssociationProducer", | ||
trackToGenAssoc = cms.InputTag("prunedTrackMCMatch"), | ||
trackToPackedCandidatesAssoc = cms.InputTag("lostTracks") | ||
) | ||
|
||
packedCandidateToGenAssociationTask = cms.Task(packedPFCandidateToGenAssociation,lostTracksToGenAssociation) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
from SimTracker.TrackAssociation.trackingParticlePrunerByGen_cfi import * | ||
from SimTracker.TrackAssociation.digiSimLinkPruner_cfi import * | ||
|
||
from Configuration.Eras.Modifier_fastSim_cff import fastSim | ||
from Configuration.Eras.Modifier_bParking_cff import bParking | ||
|
||
tpPruningTask = cms.Task() | ||
|
||
|
||
_bParking_tpPruningTask = cms.Task(prunedTrackingParticles,prunedDigiSimLinks) | ||
bParking.toReplaceWith(tpPruningTask,_bParking_tpPruningTask) | ||
|
||
(fastSim & bParking).toModify(tpPruningTask, lambda x: x.remove(prunedDigiSimLinks)) |
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
161 changes: 161 additions & 0 deletions
161
SimTracker/TrackAssociation/plugins/DigiSimLinkPruner.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,161 @@ | ||
// -*- C++ -*- | ||
// | ||
// Package: SimTracker/TrackAssociation | ||
// Class: DigiSimLinkPruner | ||
// | ||
/**\class DigiSimLinkPruner DigiSimLinkPruner.cc SimTracker/TrackAssociation/plugins/DigiSimLinkPruner.cc | ||
|
||
Description: Produce a pruned version of the DigiSimLinks collection based on the association to a collection of TrackingParticles | ||
|
||
Implementation: | ||
[Notes on implementation] | ||
*/ | ||
// | ||
// Original Author: Enrico Lusiani | ||
// Created: Fri, 14 May 2021 08:46:10 GMT | ||
// | ||
// | ||
|
||
// system include files | ||
#include <memory> | ||
|
||
// user include files | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/global/EDProducer.h" | ||
|
||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
|
||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/Utilities/interface/StreamID.h" | ||
|
||
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" | ||
#include "DataFormats/Common/interface/DetSetVector.h" | ||
#include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h" | ||
#include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h" | ||
|
||
#include <unordered_set> | ||
|
||
namespace { | ||
|
||
template <typename T> | ||
std::vector<edm::DetSet<T>> pruneByTpAssoc(const edm::DetSetVector<T>& simLinkColl, | ||
const std::set<std::pair<uint32_t, EncodedEventId>>& selectedIds) { | ||
std::vector<edm::DetSet<T>> linkVector; | ||
|
||
for (auto&& detSet : simLinkColl) { | ||
edm::DetSet<T> newDetSet(detSet.detId()); | ||
|
||
for (auto&& simLink : detSet) { | ||
std::pair<uint32_t, EncodedEventId> trkid(simLink.SimTrackId(), simLink.eventId()); | ||
if (selectedIds.count(trkid) > 0) { | ||
newDetSet.push_back(simLink); | ||
} | ||
} | ||
|
||
linkVector.push_back(std::move(newDetSet)); | ||
} | ||
|
||
return linkVector; | ||
} | ||
|
||
} // namespace | ||
|
||
// | ||
// class declaration | ||
// | ||
|
||
class DigiSimLinkPruner : public edm::global::EDProducer<> { | ||
public: | ||
explicit DigiSimLinkPruner(const edm::ParameterSet&); | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); | ||
|
||
private: | ||
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; | ||
|
||
// ----------member data --------------------------- | ||
edm::EDGetTokenT<TrackingParticleCollection> trackingParticleToken_; | ||
edm::EDGetTokenT<edm::DetSetVector<PixelDigiSimLink>> sipixelSimLinksToken_; | ||
edm::EDGetTokenT<edm::DetSetVector<StripDigiSimLink>> sistripSimLinksToken_; | ||
edm::EDGetTokenT<edm::DetSetVector<PixelDigiSimLink>> siphase2OTSimLinksToken_; | ||
}; | ||
|
||
DigiSimLinkPruner::DigiSimLinkPruner(const edm::ParameterSet& iConfig) | ||
: trackingParticleToken_( | ||
consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticles"))), | ||
sipixelSimLinksToken_( | ||
consumes<edm::DetSetVector<PixelDigiSimLink>>(iConfig.getParameter<edm::InputTag>("pixelSimLinkSrc"))) { | ||
produces<edm::DetSetVector<PixelDigiSimLink>>("siPixel"); | ||
|
||
if (iConfig.existsAs<edm::InputTag>("stripSimLinkSrc")) { | ||
sistripSimLinksToken_ = | ||
consumes<edm::DetSetVector<StripDigiSimLink>>(iConfig.getParameter<edm::InputTag>("stripSimLinkSrc")); | ||
produces<edm::DetSetVector<StripDigiSimLink>>("siStrip"); | ||
} | ||
|
||
if (iConfig.existsAs<edm::InputTag>("phase2OTSimLinkSrc")) { | ||
siphase2OTSimLinksToken_ = | ||
consumes<edm::DetSetVector<PixelDigiSimLink>>(iConfig.getParameter<edm::InputTag>("phase2OTSimLinkSrc")); | ||
produces<edm::DetSetVector<PixelDigiSimLink>>("siphase2OT"); | ||
} | ||
} | ||
|
||
// ------------ method called to produce the data ------------ | ||
void DigiSimLinkPruner::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { | ||
using namespace edm; | ||
|
||
auto const& tpColl = iEvent.get(trackingParticleToken_); | ||
|
||
std::set<std::pair<uint32_t, EncodedEventId>> selectedIds; | ||
for (TrackingParticleCollection::size_type itp = 0; itp < tpColl.size(); ++itp) { | ||
auto const& trackingParticle = tpColl[itp]; | ||
|
||
// SimTracks inside TrackingParticle | ||
|
||
EncodedEventId eid(trackingParticle.eventId()); | ||
|
||
for (auto const& trk : trackingParticle.g4Tracks()) { | ||
selectedIds.emplace(trk.trackId(), eid); | ||
} | ||
} | ||
|
||
auto const& sipixelLinkColl = iEvent.get(sipixelSimLinksToken_); | ||
|
||
auto sipixelLinkVector = pruneByTpAssoc(sipixelLinkColl, selectedIds); | ||
|
||
auto sipixelOut = std::make_unique<edm::DetSetVector<PixelDigiSimLink>>(sipixelLinkVector); | ||
iEvent.put(std::move(sipixelOut), "siPixel"); | ||
|
||
if (not sistripSimLinksToken_.isUninitialized()) { | ||
auto const& sistripLinkColl = iEvent.get(sistripSimLinksToken_); | ||
|
||
auto sistripLinkVector = pruneByTpAssoc(sistripLinkColl, selectedIds); | ||
|
||
auto sistripOut = std::make_unique<edm::DetSetVector<StripDigiSimLink>>(sistripLinkVector); | ||
iEvent.put(std::move(sistripOut), "siStrip"); | ||
} | ||
|
||
if (not siphase2OTSimLinksToken_.isUninitialized()) { | ||
auto const& siphase2OTLinkColl = iEvent.get(siphase2OTSimLinksToken_); | ||
|
||
auto siphase2OTLinkVector = pruneByTpAssoc(siphase2OTLinkColl, selectedIds); | ||
|
||
auto siphase2OTOut = std::make_unique<edm::DetSetVector<PixelDigiSimLink>>(siphase2OTLinkVector); | ||
iEvent.put(std::move(siphase2OTOut), "siphase2OT"); | ||
} | ||
} | ||
|
||
// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ | ||
void DigiSimLinkPruner::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<edm::InputTag>("trackingParticles"); | ||
desc.add<edm::InputTag>("pixelSimLinkSrc", edm::InputTag("simSiPixelDigis")); | ||
desc.addOptional<edm::InputTag>("stripSimLinkSrc"); | ||
desc.addOptional<edm::InputTag>("phase2OTSimLinkSrc"); | ||
|
||
descriptions.add("digiSimLinkPrunerDefault", desc); | ||
} | ||
|
||
//define this as a plug-in | ||
DEFINE_FWK_MODULE(DigiSimLinkPruner); |
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
Oops, something went wrong.
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.