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

MTD reconstruction: speed up TrackExtenderWithMTD #36793

Merged
merged 5 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from RecoTracker.Configuration.customiseEarlyDeleteForSeeding import customiseEarlyDeleteForSeeding
from RecoTracker.Configuration.customiseEarlyDeleteForMkFit import customiseEarlyDeleteForMkFit
from RecoTracker.Configuration.customiseEarlyDeleteForCKF import customiseEarlyDeleteForCKF
from CommonTools.ParticleFlow.Isolation.customiseEarlyDeleteForCandIsoDeposits import customiseEarlyDeleteForCandIsoDeposits

def _hasInputTagModuleLabel(process, pset, psetModLabel, moduleLabels, result):
Expand Down Expand Up @@ -45,6 +46,7 @@ def customiseEarlyDelete(process):

products = customiseEarlyDeleteForSeeding(process, products)
products = customiseEarlyDeleteForMkFit(process, products)
products = customiseEarlyDeleteForCKF(process, products)

products = customiseEarlyDeleteForCandIsoDeposits(process, products)

Expand Down
57 changes: 35 additions & 22 deletions RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "Geometry/CommonTopologies/interface/PixelTopology.h"

#include "TrackingTools/PatternTools/interface/Trajectory.h"
#include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"

#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
Expand Down Expand Up @@ -446,7 +447,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> {
return RefitDirection::undetermined;
}

reco::Track buildTrack(const reco::Track&,
reco::Track buildTrack(const reco::TrackRef&,
const Trajectory&,
const Trajectory&,
const reco::BeamSpot&,
Expand Down Expand Up @@ -483,6 +484,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> {
edm::EDPutToken assocOrigTrkToken_;

edm::EDGetTokenT<InputCollection> tracksToken_;
edm::EDGetTokenT<TrajTrackAssociationCollection> trajTrackAToken_;
edm::EDGetTokenT<MTDTrackingDetSetVector> hitsToken_;
edm::EDGetTokenT<reco::BeamSpot> bsToken_;
edm::EDGetTokenT<GlobalPoint> genVtxPositionToken_;
Expand Down Expand Up @@ -521,6 +523,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> {
template <class TrackCollection>
TrackExtenderWithMTDT<TrackCollection>::TrackExtenderWithMTDT(const ParameterSet& iConfig)
: tracksToken_(consumes<InputCollection>(iConfig.getParameter<edm::InputTag>("tracksSrc"))),
trajTrackAToken_(consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trjtrkAssSrc"))),
hitsToken_(consumes<MTDTrackingDetSetVector>(iConfig.getParameter<edm::InputTag>("hitsSrc"))),
bsToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotSrc"))),
updateTraj_(iConfig.getParameter<bool>("updateTrackTrajectory")),
Expand Down Expand Up @@ -586,6 +589,7 @@ template <class TrackCollection>
void TrackExtenderWithMTDT<TrackCollection>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc, transDesc;
desc.add<edm::InputTag>("tracksSrc", edm::InputTag("generalTracks"));
desc.add<edm::InputTag>("trjtrkAssSrc", edm::InputTag("generalTracks"));
desc.add<edm::InputTag>("hitsSrc", edm::InputTag("mtdTrackingRecHits"));
desc.add<edm::InputTag>("beamSpotSrc", edm::InputTag("offlineBeamSpot"));
desc.add<edm::InputTag>("genVtxPositionSrc", edm::InputTag("genParticles:xyz0"));
Expand Down Expand Up @@ -682,7 +686,9 @@ void TrackExtenderWithMTDT<TrackCollection>::produce(edm::Event& ev, const edm::
std::vector<int> assocOrigTrkRaw;

auto const tracksH = ev.getHandle(tracksToken_);
const auto& tracks = *tracksH;

auto const trjtrkH = ev.getHandle(trajTrackAToken_);
const auto& trjtrks = *trjtrkH;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto const trjtrkH = ev.getHandle(trajTrackAToken_);
const auto& trjtrks = *trjtrkH;
const auto& trjtrks = ev.get(trajTrackAToken_);

also a few lines above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tracksH is then used by the fillValueMap, if you refer to this in your comment


//MTD hits DetSet
const auto& hits = ev.get(hitsToken_);
Expand Down Expand Up @@ -716,38 +722,41 @@ void TrackExtenderWithMTDT<TrackCollection>::produce(edm::Event& ev, const edm::
std::vector<unsigned> track_indices;
unsigned itrack = 0;

for (const auto& track : tracks) {
for (const auto& trjtrk : trjtrks) {
const Trajectory& trajs = *trjtrk.key;
const reco::TrackRef& track = trjtrk.val;

float trackVtxTime = 0.f;
if (useVertex_) {
float dz;
if (useSimVertex_)
dz = std::abs(track.dz(math::XYZPoint(*genPV)));
dz = std::abs(track->dz(math::XYZPoint(*genPV)));
else
dz = std::abs(track.dz(pv->position()));
dz = std::abs(track->dz(pv->position()));

if (dz < dzCut_)
trackVtxTime = vtxTime;
}

reco::TransientTrack ttrack(track, magfield.product(), gtg_);
const auto& trajs = theTransformer->transform(track);
auto thits = theTransformer->getTransientRecHits(ttrack);
TransientTrackingRecHit::ConstRecHitContainer mtdthits;
MTDHitMatchingInfo mBTL, mETL;
if (!trajs.empty()) {

if (trajs.isValid()) {
// get the outermost trajectory point on the track
TrajectoryStateOnSurface tsos = builder_->build(track).outermostMeasurementState();
TrajectoryStateClosestToBeamLine tscbl;
bool tscbl_status = getTrajectoryStateClosestToBeamLine(trajs.front(), bs, prop, tscbl);
bool tscbl_status = getTrajectoryStateClosestToBeamLine(trajs, bs, prop, tscbl);

if (tscbl_status) {
float pmag2 = tscbl.trackStateAtPCA().momentum().mag2();
float pathlength0;
TrackSegments trs0;
trackPathLength(trajs.front(), tscbl, prop, pathlength0, trs0);
trackPathLength(trajs, tscbl, prop, pathlength0, trs0);

const auto& btlhits = tryBTLLayers(tsos,
trajs.front(),
trajs,
pmag2,
pathlength0,
trs0,
Expand All @@ -764,7 +773,7 @@ void TrackExtenderWithMTDT<TrackCollection>::produce(edm::Event& ev, const edm::
// in the future this should include an intermediate refit before propagating to the ETL
// for now it is ok
const auto& etlhits = tryETLLayers(tsos,
trajs.front(),
trajs,
pmag2,
pathlength0,
trs0,
Expand All @@ -778,7 +787,7 @@ void TrackExtenderWithMTDT<TrackCollection>::produce(edm::Event& ev, const edm::
mETL);
mtdthits.insert(mtdthits.end(), etlhits.begin(), etlhits.end());
}
} //!trajs.empty()
}

auto ordering = checkRecHitsOrdering(thits);
if (ordering == RefitDirection::insideOut) {
Expand All @@ -789,16 +798,17 @@ void TrackExtenderWithMTDT<TrackCollection>::produce(edm::Event& ev, const edm::
thits.swap(mtdthits);
}

const auto& trajwithmtd = mtdthits.empty() ? trajs : theTransformer->transform(ttrack, thits);
const auto& trajwithmtd =
mtdthits.empty() ? std::vector<Trajectory>(1, trajs) : theTransformer->transform(ttrack, thits);
float pMap = 0.f, betaMap = 0.f, t0Map = 0.f, sigmat0Map = -1.f, pathLengthMap = -1.f, tmtdMap = 0.f,
sigmatmtdMap = -1.f, tofpiMap = 0.f, tofkMap = 0.f, tofpMap = 0.f;
int iMap = -1;

for (const auto& trj : trajwithmtd) {
const auto& thetrj = (updateTraj_ ? trj : trajs.front());
const auto& thetrj = (updateTraj_ ? trj : trajs);
float pathLength = 0.f, tmtd = 0.f, sigmatmtd = -1.f, tofpi = 0.f, tofk = 0.f, tofp = 0.f;
LogTrace("TrackExtenderWithMTD") << "Refit track " << itrack << " p/pT = " << track.p() << " " << track.pt()
<< " eta = " << track.eta();
LogTrace("TrackExtenderWithMTD") << "Refit track " << itrack << " p/pT = " << track->p() << " " << track->pt()
<< " eta = " << track->eta();
reco::Track result = buildTrack(track,
thetrj,
trj,
Expand Down Expand Up @@ -845,7 +855,7 @@ void TrackExtenderWithMTDT<TrackCollection>::produce(edm::Event& ev, const edm::
tofkMap = tofk;
tofpMap = tofp;
reco::TrackExtraRef extraRef(extrasRefProd, extras->size() - 1);
backtrack.setExtra((updateExtra_ ? extraRef : track.extra()));
backtrack.setExtra((updateExtra_ ? extraRef : track->extra()));
for (unsigned ihit = hitsstart; ihit < hitsend; ++ihit) {
backtrack.appendHitPattern((*outhits)[ihit], ttopo);
}
Expand Down Expand Up @@ -1074,11 +1084,14 @@ void TrackExtenderWithMTDT<TrackCollection>::fillMatchingHits(const DetLayer* il
else
find_hits(0, false);

float spaceChi2Cut = ilay->isBarrel() ? btlChi2Cut_ : etlChi2Cut_;
float timeChi2Cut = ilay->isBarrel() ? btlTimeChi2Cut_ : etlTimeChi2Cut_;

//just take the first hit because the hits are sorted on their matching quality
if (!hitsInLayer.empty()) {
//check hits to pass minimum quality matching requirements
auto const& firstHit = *hitsInLayer.begin();
if (firstHit.estChi2 < etlChi2Cut_ && firstHit.timeChi2 < etlTimeChi2Cut_) {
if (firstHit.estChi2 < spaceChi2Cut && firstHit.timeChi2 < timeChi2Cut) {
hitMatched = true;
output.push_back(hitbuilder_->build(firstHit.hit));
if (firstHit < bestHit)
Expand All @@ -1092,8 +1105,8 @@ void TrackExtenderWithMTDT<TrackCollection>::fillMatchingHits(const DetLayer* il
find_hits(0, false);
if (!hitsInLayer.empty()) {
auto const& firstHit = *hitsInLayer.begin();
if (firstHit.timeChi2 < etlTimeChi2Cut_) {
if (firstHit.estChi2 < etlChi2Cut_) {
if (firstHit.timeChi2 < timeChi2Cut) {
if (firstHit.estChi2 < spaceChi2Cut) {
hitMatched = true;
output.push_back(hitbuilder_->build(firstHit.hit));
if (firstHit < bestHit)
Expand All @@ -1107,7 +1120,7 @@ void TrackExtenderWithMTDT<TrackCollection>::fillMatchingHits(const DetLayer* il
//below is unfortunately ripped from other places but
//since track producer doesn't know about MTD we have to do this
template <class TrackCollection>
reco::Track TrackExtenderWithMTDT<TrackCollection>::buildTrack(const reco::Track& orig,
reco::Track TrackExtenderWithMTDT<TrackCollection>::buildTrack(const reco::TrackRef& orig,
const Trajectory& traj,
const Trajectory& trajWithMtd,
const reco::BeamSpot& bs,
Expand Down Expand Up @@ -1148,7 +1161,7 @@ reco::Track TrackExtenderWithMTDT<TrackCollection>::buildTrack(const reco::Track
mom,
tscbl.trackStateAtPCA().charge(),
tscbl.trackStateAtPCA().curvilinearError(),
orig.algo(),
orig->algo(),
reco::TrackBase::undefQuality,
t0,
betaOut,
Expand Down
24 changes: 24 additions & 0 deletions RecoTracker/Configuration/python/customiseEarlyDeleteForCKF.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import FWCore.ParameterSet.Config as cms

import collections

def customiseEarlyDeleteForCKF(process, products):

if "trackExtenderWithMTD" not in process.producerNames():
return products

def _branchName(productType, moduleLabel, instanceLabel=""):
return "%s_%s_%s_%s" % (productType, moduleLabel, instanceLabel, process.name_())

for name, module in process.producers_().items():
cppType = module._TypedParameterizable__type
if cppType == "TrackProducer":
if module.TrajectoryInEvent:
products[name].append(_branchName("Trajectorys", name))
products[name].append(_branchName("TrajectorysToOnerecoTracksAssociation", name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to explain a bit more, these lines "declare" data products produced by this module that will be deleted early. The machinery in earlyDeleteSettings_cff.py then adds the necessary configuration parameters (to tell the early deletion system that the product needs to be kept alive until that module has been run) to all modules whose configuration contain cms.InputTag referring to it.

(and thus any module that has a hardcoded InputTag, or InputTag parameter getting added in the configuration validation step would break it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the only issue is in case one of these products should be made persistent, am I correct? Is there any built-in cross check to prevent conflicts in this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the only issue is in case one of these products should be made persistent, am I correct? Is there any built-in cross check to prevent conflicts in this case?

By quick read on the code data products consumed by output modules are not deleted early.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, according to your last sentence persistency seems not the only possible issue...

elif cppType == "DuplicateListMerger":
if module.copyTrajectories:
products[name].append(_branchName("Trajectorys", name))
products[name].append(_branchName("TrajectorysToOnerecoTracksAssociation", name))

return products
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ def _fastSimGeneralTracks(process):
copyExtras = True,
makeReKeyedSeeds = cms.untracked.bool(False),
)

from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
phase2_timing_layer.toModify(mergedDuplicateTracks, TrajectoryInEvent = True)
phase2_timing_layer.toModify(generalTracks, copyTrajectories = True)
3 changes: 3 additions & 0 deletions RecoTracker/IterativeTracking/python/DetachedQuadStep_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@
)
fastSim.toModify(detachedQuadStepTracks,TTRHBuilder = 'WithoutRefit')

from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
phase2_timing_layer.toModify(detachedQuadStepTracks, TrajectoryInEvent = True)

# TRACK SELECTION AND QUALITY FLAG SETTING.
from RecoTracker.FinalTrackSelectors.TrackMVAClassifierDetached_cfi import *
detachedQuadStep = TrackMVAClassifierDetached.clone(
Expand Down
3 changes: 3 additions & 0 deletions RecoTracker/IterativeTracking/python/HighPtTripletStep_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@
)
fastSim.toModify(highPtTripletStepTracks,TTRHBuilder = 'WithoutRefit')

from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
phase2_timing_layer.toModify(highPtTripletStepTracks, TrajectoryInEvent = True)

# Final selection
from RecoTracker.FinalTrackSelectors.TrackMVAClassifierPrompt_cfi import *
highPtTripletStep = TrackMVAClassifierPrompt.clone(
Expand Down
3 changes: 3 additions & 0 deletions RecoTracker/IterativeTracking/python/InitialStep_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@
)
fastSim.toModify(initialStepTracks, TTRHBuilder = 'WithoutRefit')

from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
phase2_timing_layer.toModify(initialStepTracks, TrajectoryInEvent = True)

#vertices
from RecoVertex.PrimaryVertexProducer.OfflinePrimaryVertices_cfi import offlinePrimaryVertices as _offlinePrimaryVertices
firstStepPrimaryVerticesUnsorted = _offlinePrimaryVertices.clone(
Expand Down
2 changes: 2 additions & 0 deletions RecoTracker/IterativeTracking/python/LowPtQuadStep_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@
)
fastSim.toModify(lowPtQuadStepTracks,TTRHBuilder = 'WithoutRefit')

from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
phase2_timing_layer.toModify(lowPtQuadStepTracks, TrajectoryInEvent = True)

# Final selection
from RecoTracker.FinalTrackSelectors.TrackMVAClassifierPrompt_cfi import *
Expand Down
3 changes: 3 additions & 0 deletions RecoTracker/IterativeTracking/python/LowPtTripletStep_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@
)
fastSim.toModify(lowPtTripletStepTracks, TTRHBuilder = 'WithoutRefit')

from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
phase2_timing_layer.toModify(lowPtTripletStepTracks, TrajectoryInEvent = True)

from TrackingTools.TrajectoryCleaning.TrajectoryCleanerBySharedHits_cfi import trajectoryCleanerBySharedHits
lowPtTripletStepTrajectoryCleanerBySharedHits = trajectoryCleanerBySharedHits.clone(
ComponentName = 'lowPtTripletStepTrajectoryCleanerBySharedHits',
Expand Down
5 changes: 5 additions & 0 deletions RecoTracker/IterativeTracking/python/MuonSeededStep_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@
muonSeededStepCore = cms.Sequence(muonSeededStepCoreTask)
#Phase2 : just muon Seed InOut is used in this moment
#trackingPhase2PU140.toReplaceWith(muonSeededStepCore, muonSeededStepCoreInOut)

from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
phase2_timing_layer.toModify(muonSeededTracksInOut, TrajectoryInEvent = True)
phase2_timing_layer.toModify(muonSeededTracksOutIn, TrajectoryInEvent = True)

muonSeededStepExtraInOutTask = cms.Task(
muonSeededTracksInOutClassifier
)
Expand Down
3 changes: 3 additions & 0 deletions RecoTracker/IterativeTracking/python/PixelPairStep_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@
)
fastSim.toModify(pixelPairStepTracks, TTRHBuilder = 'WithoutRefit')

from Configuration.Eras.Modifier_phase2_timing_layer_cff import phase2_timing_layer
phase2_timing_layer.toModify(pixelPairStepTracks, TrajectoryInEvent = True)

# Final selection
from RecoTracker.FinalTrackSelectors.TrackMVAClassifierPrompt_cfi import *
pixelPairStep = TrackMVAClassifierPrompt.clone(
Expand Down