Skip to content
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

Track-gen matching passing through TrackingParticle #33774

Merged
merged 15 commits into from Jun 13, 2021
Merged
Expand Up @@ -35,7 +35,7 @@
workflows[1302.18] = ['', ['ProdTTbar_13UP18','DIGIUP18PROD1','RECOPRODUP18','MINIAODMCUP18','NANOPRODUP18']]
#workflows[1303.18] = ['', ['ProdQCD_Pt_3000_3500_13UP18','DIGIUP18PROD1','RECOPRODUP18']]
workflows[1304.18] = ['', ['ProdZEE_13UP18','DIGIUP18PROD1','RECOPRODUP18','MINIAODMCUP18','NANOPRODUP18']]
workflows[1304.182] = ['', ['ProdZEE_13UP18','DIGIUP18PROD1','RECOPRODUP18bParking','MINIAODMCUP18bParking']]
workflows[1304.182] = ['', ['ProdZEE_13UP18','DIGIUP18PROD1bParking','RECOPRODUP18bParking','MINIAODMCUP18bParking']]
#workflows.addOverride(1303.17,overridesEv5)

#####Prod2018 with concurrentlumi
Expand Down
1 change: 1 addition & 0 deletions Configuration/PyReleaseValidation/python/relval_steps.py
Expand Up @@ -1667,6 +1667,7 @@ def lhegensim2018ml(fragment,howMuch):
steps['DIGIUP18']=merge([step2Upg2018Defaults])
steps['DIGIUP17PROD1']=merge([{'-s':'DIGI,L1,DIGI2RAW,HLT:@relval2017','--eventcontent':'RAWSIM','--datatier':'GEN-SIM-RAW'},step2Upg2017Defaults])
steps['DIGIUP18PROD1']=merge([{'-s':'DIGI,L1,DIGI2RAW,HLT:@relval2018','--eventcontent':'RAWSIM','--datatier':'GEN-SIM-RAW'},step2Upg2018Defaults])
steps['DIGIUP18PROD1bParking']=merge([{'-s':'DIGI,L1,DIGI2RAW,HLT:@relval2018','--eventcontent':'RAWSIM','--datatier':'GEN-SIM-RAW','--era' :'Run2_2018,bParking'},step2Upg2018Defaults])
steps['DIGIUP17_PU25']=merge([PU25UP17,step2Upg2017Defaults])
steps['DIGIUP18_PU25']=merge([PU25UP18,step2Upg2018Defaults])

Expand Down
4 changes: 3 additions & 1 deletion Configuration/StandardSequences/python/Digi_cff.py
Expand Up @@ -29,6 +29,8 @@
#
from SimGeneral.Configuration.SimGeneral_cff import *

from SimTracker.Configuration.SimTrackerLinks_cff import *

# add updating the GEN information by default
from Configuration.StandardSequences.Generator_cff import *
from GeneratorInterface.Core.generatorSmeared_cfi import *
Expand All @@ -42,7 +44,7 @@
# premixing stage2 runs addPileupInfo after PreMixingModule (configured in DataMixerPreMix_cff)
premix_stage2.toReplaceWith(pdigiTask_nogen, pdigiTask_nogen.copyAndExclude([addPileupInfo]))

pdigiTask = cms.Task(pdigiTask_nogen, fixGenInfoTask)
pdigiTask = cms.Task(pdigiTask_nogen, fixGenInfoTask, tpPruningTask)

doAllDigi = cms.Sequence(doAllDigiTask)
pdigi = cms.Sequence(pdigiTask)
Expand Down
3 changes: 2 additions & 1 deletion Configuration/StandardSequences/python/RecoSim_cff.py
@@ -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 )
Expand Up @@ -100,6 +100,8 @@
outputCommands = cms.untracked.vstring(
'keep patPackedGenParticles_packedGenParticles_*_*',
'keep recoGenParticles_prunedGenParticles_*_*',
'keep *_packedPFCandidateToGenAssociation_*_*',
'keep *_lostTracksToGenAssociation_*_*',
'keep LHEEventProduct_*_*_*',
'keep GenFilterInfo_*_*_*',
'keep GenLumiInfoHeader_generator_*_*',
Expand Down
@@ -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)
2 changes: 2 additions & 0 deletions PhysicsTools/PatAlgos/python/slimming/slimming_cff.py
Expand Up @@ -8,6 +8,7 @@
from PhysicsTools.PatAlgos.slimming.offlineSlimmedPrimaryVerticesWithBS_cfi import *
from PhysicsTools.PatAlgos.slimming.primaryVertexAssociation_cfi import *
from PhysicsTools.PatAlgos.slimming.genParticles_cff import *
from PhysicsTools.PatAlgos.slimming.genParticleAssociation_cff import *
from PhysicsTools.PatAlgos.slimming.selectedPatTrigger_cfi import *
from PhysicsTools.PatAlgos.slimming.slimmedPatTrigger_cfi import *
from PhysicsTools.PatAlgos.slimming.slimmedJets_cfi import *
Expand Down Expand Up @@ -39,6 +40,7 @@
primaryVertexAssociation,
primaryVertexWithBSAssociation,
genParticlesTask,
packedCandidateToGenAssociationTask,
selectedPatTrigger,
slimmedPatTrigger,
slimmedCaloJets,
Expand Down
11 changes: 11 additions & 0 deletions SimTracker/Configuration/python/SimTrackerLinks_cff.py
@@ -0,0 +1,11 @@
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


tpPruningTask = cms.Task(prunedTrackingParticles,prunedDigiSimLinks)

fastSim.toModify(tpPruningTask, lambda x: x.remove(prunedDigiSimLinks))
13 changes: 10 additions & 3 deletions SimTracker/Configuration/python/SimTracker_EventContent_cff.py
Expand Up @@ -37,15 +37,22 @@
)
#RAW content
SimTrackerRAW = cms.PSet(
outputCommands = cms.untracked.vstring('keep *_allTrackMCMatch_*_*')
outputCommands = cms.untracked.vstring(
'keep *_allTrackMCMatch_*_*',
'keep *_prunedTrackingParticles_*_*',
'keep *_prunedDigiSimLinks_*_*')
)
#RECO content
SimTrackerRECO = cms.PSet(
outputCommands = cms.untracked.vstring('keep *_allTrackMCMatch_*_*')
outputCommands = cms.untracked.vstring(
'keep *_allTrackMCMatch_*_*',
'keep *_prunedTrackMCMatch_*_*')
)
#AOD content
SimTrackerAOD = cms.PSet(
outputCommands = cms.untracked.vstring('keep *_allTrackMCMatch_*_*')
outputCommands = cms.untracked.vstring(
'keep *_allTrackMCMatch_*_*',
'keep *_prunedTrackMCMatch_*_*')
)

# Event content for premixing library
Expand Down
1 change: 1 addition & 0 deletions SimTracker/TrackAssociation/plugins/BuildFile.xml
Expand Up @@ -6,6 +6,7 @@
<use name="SimDataFormats/TrackerDigiSimLink"/>
<use name="SimDataFormats/TrackingAnalysis"/>
<use name="TrackingTools/TransientTrack"/>
<use name="PhysicsTools/HepMCCandAlgos"/>
<library name="SimTrackerTrackAssociation_plugins" file="*.cc">
<flags EDM_PLUGIN="1"/>
</library>
163 changes: 163 additions & 0 deletions SimTracker/TrackAssociation/plugins/DigiSimLinkPruner.cc
@@ -0,0 +1,163 @@
// -*- 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 "SimDataFormats/Track/interface/UniqueSimTrackId.h"

#include <unordered_set>

namespace {

template <typename T>
std::vector<edm::DetSet<T>> pruneByTpAssoc(
const edm::DetSetVector<T>& simLinkColl,
const std::unordered_set<UniqueSimTrackId, UniqueSimTrackIdHash>& selectedIds) {
std::vector<edm::DetSet<T>> linkVector;

for (auto&& detSet : simLinkColl) {
edm::DetSet<T> newDetSet(detSet.detId());

for (auto&& simLink : detSet) {
UniqueSimTrackId 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::unordered_set<UniqueSimTrackId, UniqueSimTrackIdHash> 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);
12 changes: 9 additions & 3 deletions SimTracker/TrackAssociation/plugins/MCTrackMatcher.cc
Expand Up @@ -31,6 +31,7 @@ class MCTrackMatcher : public edm::global::EDProducer<> {
edm::EDGetTokenT<GenParticleCollection> genParticles_;
edm::EDGetTokenT<std::vector<int>> genParticleInts_;
edm::EDGetTokenT<TrackingParticleCollection> trackingParticles_;
bool throwOnMissingTPCollection_;
typedef edm::Association<reco::GenParticleCollection> GenParticleMatch;
};

Expand All @@ -45,7 +46,8 @@ MCTrackMatcher::MCTrackMatcher(const ParameterSet &p)
tracks_(consumes<edm::View<reco::Track>>(p.getParameter<InputTag>("tracks"))),
genParticles_(consumes<GenParticleCollection>(p.getParameter<InputTag>("genParticles"))),
genParticleInts_(consumes<std::vector<int>>(p.getParameter<InputTag>("genParticles"))),
trackingParticles_(consumes<TrackingParticleCollection>(p.getParameter<InputTag>("trackingParticles"))) {
trackingParticles_(consumes<TrackingParticleCollection>(p.getParameter<InputTag>("trackingParticles"))),
throwOnMissingTPCollection_(p.getParameter<bool>("throwOnMissingTPCollection")) {
produces<GenParticleMatch>();
}

Expand All @@ -56,13 +58,17 @@ void MCTrackMatcher::produce(edm::StreamID, Event &evt, const EventSetup &es) co
Handle<View<Track>> tracks;
evt.getByToken(tracks_, tracks);
Handle<TrackingParticleCollection> trackingParticles;
evt.getByToken(trackingParticles_, trackingParticles);
auto trackingParticlesFound = evt.getByToken(trackingParticles_, trackingParticles);
Handle<vector<int>> barCodes;
evt.getByToken(genParticleInts_, barCodes);
Handle<GenParticleCollection> genParticles;
evt.getByToken(genParticles_, genParticles);
RecoToSimCollection associations = associator->associateRecoToSim(tracks, trackingParticles);
unique_ptr<GenParticleMatch> match(new GenParticleMatch(GenParticleRefProd(genParticles)));
if (not throwOnMissingTPCollection_ and not trackingParticlesFound) {
evt.put(std::move(match));
return;
}
RecoToSimCollection associations = associator->associateRecoToSim(tracks, trackingParticles);
GenParticleMatch::Filler filler(*match);
size_t n = tracks->size();
vector<int> indices(n, -1);
Expand Down