From 3b0b0500480ad7ddb2c7fb4b7d274aa910d2756b Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 23 Jul 2020 03:31:20 +0200 Subject: [PATCH 01/15] event.get* modernised --- .../plugins/TrackExtenderWithMTD.cc | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 1ab77232ef44d..5c408e9816650 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -487,32 +487,28 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: std::vector sigmatmtdOrigTrkRaw; std::vector assocOrigTrkRaw; - edm::Handle tracksH; - ev.getByToken(tracksToken_, tracksH); + auto const tracksH = ev.getHandle(tracksToken_); const auto& tracks = *tracksH; - edm::Handle hitsH; - ev.getByToken(hitsToken_, hitsH); - const auto& hits = *hitsH; + //MTD hits DetSet + const auto& hits = ev.get(hitsToken_); - edm::Handle bsH; - ev.getByToken(bsToken_, bsH); - const auto& bs = *bsH; + //beam spot + const auto& bs = ev.get(bsToken_); const Vertex* pv = nullptr; if (useVertex_ && !useSimVertex_) { - edm::Handle vtxH; - ev.getByToken(vtxToken_, vtxH); - if (!vtxH.product()->empty()) - pv = &(vtxH.product()->at(0)); + auto const& vtxs = ev.get(vtxToken_); + if (!vtxs.empty()) + pv = &vtxs[0]; } std::unique_ptr genPV(nullptr); if (useVertex_ && useSimVertex_) { - const auto& genVtxPositionHandle = ev.getHandle(genVtxPositionToken_); - const auto& genVtxTimeHandle = ev.getHandle(genVtxTimeToken_); + const auto& genVtxPosition = ev.get(genVtxPositionToken_); + const auto& genVtxTime = ev.get(genVtxTimeToken_); genPV = std::make_unique( - genVtxPositionHandle->x(), genVtxPositionHandle->y(), genVtxPositionHandle->z(), *(genVtxTimeHandle)); + genVtxPosition.x(), genVtxPosition.y(), genVtxPosition.z(), genVtxTime); } double vtxTime = 0.; From d83591e045c42bb65e3d9b9e5b1d77ffac7deee2 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 23 Jul 2020 03:46:12 +0200 Subject: [PATCH 02/15] local names trailing _ --- .../plugins/TrackExtenderWithMTD.cc | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 5c408e9816650..434d19078b630 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -259,8 +259,8 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { RefitDirection::GeometricalDirection checkRecHitsOrdering( TransientTrackingRecHit::ConstRecHitContainer const& recHits) const { if (!recHits.empty()) { - GlobalPoint first = gtg->idToDet(recHits.front()->geographicalId())->position(); - GlobalPoint last = gtg->idToDet(recHits.back()->geographicalId())->position(); + GlobalPoint first = gtg_->idToDet(recHits.front()->geographicalId())->position(); + GlobalPoint last = gtg_->idToDet(recHits.back()->geographicalId())->position(); // maybe perp2? auto rFirst = first.mag2(); @@ -316,10 +316,9 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { const std::string mtdRecHitBuilder_, propagator_, transientTrackBuilder_; std::unique_ptr theEstimator; std::unique_ptr theTransformer; - edm::ESHandle builder; - edm::ESHandle hitbuilder; - edm::ESHandle gtg; - edm::ESHandle prop; + edm::ESHandle builder_; + edm::ESHandle hitbuilder_; + edm::ESHandle gtg_; const float estMaxChi2_; const float estMaxNSigma_; @@ -449,7 +448,7 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: TrackingRecHitRefProd hitsRefProd = ev.getRefBeforePut(); reco::TrackExtraRefProd extrasRefProd = ev.getRefBeforePut(); - es.get().get(gtg); + es.get().get(gtg_); edm::ESHandle geo; es.get().get(geo); @@ -457,8 +456,8 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: edm::ESHandle magfield; es.get().get(magfield); - es.get().get(transientTrackBuilder_, builder); - es.get().get(mtdRecHitBuilder_, hitbuilder); + es.get().get(transientTrackBuilder_, builder_); + es.get().get(mtdRecHitBuilder_, hitbuilder_); edm::ESHandle prop; es.get().get(propagator_, prop); @@ -535,7 +534,7 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: trackVtxTime = vtxTime; } - reco::TransientTrack ttrack(track, magfield.product(), gtg); + reco::TransientTrack ttrack(track, magfield.product(), gtg_); const auto& trajs = theTransformer->transform(track); auto thits = theTransformer->getTransientRecHits(ttrack); TransientTrackingRecHit::ConstRecHitContainer mtdthits; @@ -820,7 +819,7 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT& layers = geo->allBTLLayers(); - auto tTrack = builder->build(track); + auto tTrack = builder_->build(track); // get the outermost trajectory point on the track TrajectoryStateOnSurface tsos = tTrack.outermostMeasurementState(); @@ -845,7 +844,7 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT& layers = geo->allETLLayers(); - auto tTrack = builder->build(track); + auto tTrack = builder_->build(track); // get the outermost trajectory point on the track TrajectoryStateOnSurface tsos = tTrack.outermostMeasurementState(); @@ -901,7 +900,7 @@ void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il //check hits to pass minimum quality matching requirements if (hitsInLayer.begin()->estChi2 < etlChi2Cut_ && hitsInLayer.begin()->timeChi2 < etlTimeChi2Cut_) { hitMatched = true; - output.push_back(hitbuilder->build(hitsInLayer.begin()->hit)); + output.push_back(hitbuilder_->build(hitsInLayer.begin()->hit)); if (*(hitsInLayer.begin()) < bestHit) bestHit = *(hitsInLayer.begin()); } @@ -915,7 +914,7 @@ void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il if (hitsInLayer.begin()->timeChi2 < etlTimeChi2Cut_) { if (hitsInLayer.begin()->estChi2 < etlChi2Cut_) { hitMatched = true; - output.push_back(hitbuilder->build(hitsInLayer.begin()->hit)); + output.push_back(hitbuilder_->build(hitsInLayer.begin()->hit)); if ((*hitsInLayer.begin()) < bestHit) bestHit = *(hitsInLayer.begin()); } @@ -1041,7 +1040,7 @@ reco::TrackExtra TrackExtenderWithMTDT::buildTrackExtra(const T } else LogError(metname) << "Wrong propagation direction!"; - const GeomDet* outerDet = gtg->idToDet(outerDetId); + const GeomDet* outerDet = gtg_->idToDet(outerDetId); GlobalPoint outerTSOSPos = outerTSOS.globalParameters().position(); bool inside = outerDet->surface().bounds().inside(outerDet->toLocal(outerTSOSPos)); From aed29b1c77bb6dd2920564dde9938b212baee3eb Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 23 Jul 2020 03:52:41 +0200 Subject: [PATCH 03/15] try{E,B}TLLayers needs only the outer tsos --- .../plugins/TrackExtenderWithMTD.cc | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 434d19078b630..8ddedb4554c70 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -223,7 +223,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - TransientTrackingRecHit::ConstRecHitContainer tryBTLLayers(const TrackType&, + TransientTrackingRecHit::ConstRecHitContainer tryBTLLayers(const TrajectoryStateOnSurface&, const Trajectory& traj, const MTDTrackingDetSetVector&, const MTDDetLayerGeometry*, @@ -234,7 +234,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { const bool matchVertex, MTDHitMatchingInfo& bestHit) const; - TransientTrackingRecHit::ConstRecHitContainer tryETLLayers(const TrackType&, + TransientTrackingRecHit::ConstRecHitContainer tryETLLayers(const TrajectoryStateOnSurface&, const Trajectory& traj, const MTDTrackingDetSetVector&, const MTDDetLayerGeometry*, @@ -540,7 +540,10 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: TransientTrackingRecHit::ConstRecHitContainer mtdthits; MTDHitMatchingInfo mBTL, mETL; if (!trajs.empty()) { - const auto& btlhits = tryBTLLayers(track, + // get the outermost trajectory point on the track + TrajectoryStateOnSurface tsos = builder_->build(track).outermostMeasurementState(); + + const auto& btlhits = tryBTLLayers(tsos, trajs.front(), hits, geo.product(), @@ -554,7 +557,7 @@ void TrackExtenderWithMTDT::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(track, + const auto& etlhits = tryETLLayers(tsos, trajs.front(), hits, geo.product(), @@ -807,7 +810,7 @@ namespace { template TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT::tryBTLLayers( - const TrackType& track, + const TrajectoryStateOnSurface& tsos, const Trajectory& traj, const MTDTrackingDetSetVector& hits, const MTDDetLayerGeometry* geo, @@ -819,10 +822,6 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT& layers = geo->allBTLLayers(); - auto tTrack = builder_->build(track); - // get the outermost trajectory point on the track - TrajectoryStateOnSurface tsos = tTrack.outermostMeasurementState(); - TransientTrackingRecHit::ConstRecHitContainer output; bestHit = MTDHitMatchingInfo(); for (const DetLayer* ilay : layers) @@ -832,7 +831,7 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT::tryETLLayers( - const TrackType& track, + const TrajectoryStateOnSurface& tsos, const Trajectory& traj, const MTDTrackingDetSetVector& hits, const MTDDetLayerGeometry* geo, @@ -844,10 +843,6 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT& layers = geo->allETLLayers(); - auto tTrack = builder_->build(track); - // get the outermost trajectory point on the track - TrajectoryStateOnSurface tsos = tTrack.outermostMeasurementState(); - TransientTrackingRecHit::ConstRecHitContainer output; bestHit = MTDHitMatchingInfo(); for (const DetLayer* ilay : layers) { From f9b503ff60e83979dc7fcc853a06639513536d51 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Thu, 23 Jul 2020 19:39:15 +0200 Subject: [PATCH 04/15] move out common computation of TSCBL into a single call --- .../plugins/TrackExtenderWithMTD.cc | 122 ++++++++++-------- 1 file changed, 66 insertions(+), 56 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 8ddedb4554c70..5db97153014e6 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -207,7 +207,30 @@ namespace { } return tofpid; } + + bool getTrajectoryStateClosestToBeamLine(const Trajectory& traj, + const reco::BeamSpot& bs, + const Propagator* thePropagator, + TrajectoryStateClosestToBeamLine& tscbl) { + // get the state closest to the beamline + TrajectoryStateOnSurface stateForProjectionToBeamLineOnSurface = + traj.closestMeasurement(GlobalPoint(bs.x0(), bs.y0(), bs.z0())).updatedState(); + + if (!stateForProjectionToBeamLineOnSurface.isValid()) { + edm::LogError("CannotPropagateToBeamLine") << "the state on the closest measurement isnot valid. skipping track."; + return false; + } + + const FreeTrajectoryState& stateForProjectionToBeamLine = *stateForProjectionToBeamLineOnSurface.freeState(); + + TSCBLBuilderWithPropagator tscblBuilder(*thePropagator); + tscbl = tscblBuilder(stateForProjectionToBeamLine, bs); + + return tscbl.isValid(); + } + } // namespace + template class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { public: @@ -225,6 +248,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { TransientTrackingRecHit::ConstRecHitContainer tryBTLLayers(const TrajectoryStateOnSurface&, const Trajectory& traj, + const TrajectoryStateClosestToBeamLine&, const MTDTrackingDetSetVector&, const MTDDetLayerGeometry*, const MagneticField* field, @@ -236,6 +260,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { TransientTrackingRecHit::ConstRecHitContainer tryETLLayers(const TrajectoryStateOnSurface&, const Trajectory& traj, + const TrajectoryStateClosestToBeamLine&, const MTDTrackingDetSetVector&, const MTDDetLayerGeometry*, const MagneticField* field, @@ -248,6 +273,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { void fillMatchingHits(const DetLayer*, const TrajectoryStateOnSurface&, const Trajectory&, + const TrajectoryStateClosestToBeamLine&, const MTDTrackingDetSetVector&, const Propagator*, const reco::BeamSpot&, @@ -542,33 +568,39 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: if (!trajs.empty()) { // get the outermost trajectory point on the track TrajectoryStateOnSurface tsos = builder_->build(track).outermostMeasurementState(); - - const auto& btlhits = tryBTLLayers(tsos, - trajs.front(), - hits, - geo.product(), - magfield.product(), - prop.product(), - bs, - trackVtxTime, - trackVtxTime != 0., - mBTL); - mtdthits.insert(mtdthits.end(), btlhits.begin(), btlhits.end()); - - // 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(), - hits, - geo.product(), - magfield.product(), - prop.product(), - bs, - trackVtxTime, - trackVtxTime != 0., - mETL); - mtdthits.insert(mtdthits.end(), etlhits.begin(), etlhits.end()); - } + TrajectoryStateClosestToBeamLine tscbl; + bool tscbl_status = getTrajectoryStateClosestToBeamLine(trajs.front(), bs, prop.product(), tscbl); + + if (tscbl_status) { + const auto& btlhits = tryBTLLayers(tsos, + trajs.front(), + tscbl, + hits, + geo.product(), + magfield.product(), + prop.product(), + bs, + trackVtxTime, + trackVtxTime != 0., + mBTL); + mtdthits.insert(mtdthits.end(), btlhits.begin(), btlhits.end()); + + // 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(), + tscbl, + hits, + geo.product(), + magfield.product(), + prop.product(), + bs, + trackVtxTime, + trackVtxTime != 0., + mETL); + mtdthits.insert(mtdthits.end(), etlhits.begin(), etlhits.end()); + } + }//!trajs.empty() auto ordering = checkRecHitsOrdering(thits); if (ordering == RefitDirection::insideOut) { @@ -674,27 +706,6 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: namespace { bool cmp_for_detset(const unsigned one, const unsigned two) { return one < two; }; - bool getTrajectoryStateClosestToBeamLine(const Trajectory& traj, - const reco::BeamSpot& bs, - const Propagator* thePropagator, - TrajectoryStateClosestToBeamLine& tscbl) { - // get the state closest to the beamline - TrajectoryStateOnSurface stateForProjectionToBeamLineOnSurface = - traj.closestMeasurement(GlobalPoint(bs.x0(), bs.y0(), bs.z0())).updatedState(); - - if (!stateForProjectionToBeamLineOnSurface.isValid()) { - edm::LogError("CannotPropagateToBeamLine") << "the state on the closest measurement isnot valid. skipping track."; - return false; - } - - const FreeTrajectoryState& stateForProjectionToBeamLine = *stateForProjectionToBeamLineOnSurface.freeState(); - - TSCBLBuilderWithPropagator tscblBuilder(*thePropagator); - tscbl = tscblBuilder(stateForProjectionToBeamLine, bs); - - return tscbl.isValid(); - } - bool trackPathLength(const Trajectory& traj, const reco::BeamSpot& bs, const Propagator* thePropagator, @@ -747,6 +758,7 @@ namespace { const Trajectory& traj, const DetLayer* layer, const TrajectoryStateOnSurface& tsos, + const TrajectoryStateClosestToBeamLine& tscbl, const double vtxTime, const reco::BeamSpot& bs, const float bsTimeSpread, @@ -754,12 +766,6 @@ namespace { const std::unique_ptr& theEstimator, bool useVtxConstraint, std::set& out) { - TrajectoryStateClosestToBeamLine tscbl; - bool tscbl_status = getTrajectoryStateClosestToBeamLine(traj, bs, prop, tscbl); - - if (!tscbl_status) - return; - GlobalVector p = tscbl.trackStateAtPCA().momentum(); double pathlength; @@ -812,6 +818,7 @@ template TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT::tryBTLLayers( const TrajectoryStateOnSurface& tsos, const Trajectory& traj, + const TrajectoryStateClosestToBeamLine& tscbl, const MTDTrackingDetSetVector& hits, const MTDDetLayerGeometry* geo, const MagneticField* field, @@ -825,7 +832,7 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT::tryETLLayers( const TrajectoryStateOnSurface& tsos, const Trajectory& traj, + const TrajectoryStateClosestToBeamLine& tscbl, const MTDTrackingDetSetVector& hits, const MTDDetLayerGeometry* geo, const MagneticField* field, @@ -852,7 +860,7 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* ilay, const TrajectoryStateOnSurface& tsos, const Trajectory& traj, + const TrajectoryStateClosestToBeamLine& tscbl, const MTDTrackingDetSetVector& hits, const Propagator* prop, const reco::BeamSpot& bs, @@ -877,6 +886,7 @@ void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il traj, ilay, tsos, + tscbl, _1, bs, bsTimeSpread_, From 3c21ddd8617e8af19001727afc9beffee6a4dd93 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 24 Jul 2020 01:47:45 +0200 Subject: [PATCH 05/15] factor out trackPathLength where tscbl is known, to avoid recomputation --- .../plugins/TrackExtenderWithMTD.cc | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 5db97153014e6..cf7ebac3fa8eb 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -707,17 +707,11 @@ namespace { bool cmp_for_detset(const unsigned one, const unsigned two) { return one < two; }; bool trackPathLength(const Trajectory& traj, - const reco::BeamSpot& bs, + const TrajectoryStateClosestToBeamLine& tscbl, const Propagator* thePropagator, double& pathlength) { pathlength = 0.; - TrajectoryStateClosestToBeamLine tscbl; - bool tscbl_status = getTrajectoryStateClosestToBeamLine(traj, bs, thePropagator, tscbl); - - if (!tscbl_status) - return false; - bool validpropagation = true; double pathlength1 = 0.; double pathlength2 = 0.; @@ -754,6 +748,21 @@ namespace { return validpropagation; } + bool trackPathLength(const Trajectory& traj, + const reco::BeamSpot& bs, + const Propagator* thePropagator, + double& pathlength) { + pathlength = 0.; + + TrajectoryStateClosestToBeamLine tscbl; + bool tscbl_status = getTrajectoryStateClosestToBeamLine(traj, bs, thePropagator, tscbl); + + if (!tscbl_status) + return false; + + return trackPathLength(traj, tscbl, thePropagator, pathlength); + } + void find_hits_in_dets(const MTDTrackingDetSetVector& hits, const Trajectory& traj, const DetLayer* layer, @@ -769,7 +778,7 @@ namespace { GlobalVector p = tscbl.trackStateAtPCA().momentum(); double pathlength; - trackPathLength(traj, bs, prop, pathlength); + trackPathLength(traj, tscbl, prop, pathlength); pair comp = layer->compatible(tsos, *prop, *theEstimator); if (comp.first) { From 28ad759b983827061cabe415540c9becd85c1e6d Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 24 Jul 2020 02:36:07 +0200 Subject: [PATCH 06/15] reduce recomputations in find_hits_in_dets --- .../plugins/TrackExtenderWithMTD.cc | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index cf7ebac3fa8eb..68c4b7ced702d 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -775,42 +775,47 @@ namespace { const std::unique_ptr& theEstimator, bool useVtxConstraint, std::set& out) { - GlobalVector p = tscbl.trackStateAtPCA().momentum(); + const auto pmag2 = tscbl.trackStateAtPCA().momentum().mag2(); double pathlength; trackPathLength(traj, tscbl, prop, pathlength); pair comp = layer->compatible(tsos, *prop, *theEstimator); if (comp.first) { - vector compDets = layer->compatibleDets(tsos, *prop, *theEstimator); + const vector compDets = layer->compatibleDets(tsos, *prop, *theEstimator); if (!compDets.empty()) { for (const auto& detWithState : compDets) { auto range = hits.equal_range(detWithState.first->geographicalId(), cmp_for_detset); - for (auto detitr = range.first; detitr != range.second; ++detitr) { - for (auto itr = detitr->begin(); itr != detitr->end(); ++itr) { - auto est = theEstimator->estimate(detWithState.second, *itr); - auto pl = prop->propagateWithPath(tsos, detWithState.second.surface()); + if (range.first == range.second) + continue; - if (!est.first || std::abs(pl.second) == 0.) - continue; + auto pl = prop->propagateWithPath(tsos, detWithState.second.surface()); + if (pl.second == 0.) + continue; + + const double tot_pl = pathlength + std::abs(pl.second); + const double t_vtx = useVtxConstraint ? vtxTime : 0.; - double tot_pl = pathlength + std::abs(pl.second); - double t_vtx = useVtxConstraint ? vtxTime : 0.; + constexpr double vtx_res = 0.008; + const double t_vtx_err = useVtxConstraint ? vtx_res : bsTimeSpread; - constexpr double vtx_res = 0.008; - double t_vtx_err = useVtxConstraint ? vtx_res : bsTimeSpread; + constexpr double t_res_manual = 0.035; - constexpr double t_res_manual = 0.035; + for (auto detitr = range.first; detitr != range.second; ++detitr) { + for (const auto& hit : *detitr) { + auto est = theEstimator->estimate(detWithState.second, hit); + if (!est.first) + continue; - TrackTofPidInfo tof = computeTrackTofPidInfo(p.mag2(), + TrackTofPidInfo tof = computeTrackTofPidInfo(pmag2, tot_pl, - itr->time(), + hit.time(), t_res_manual, //put hit error by hand for the moment t_vtx, t_vtx_err, //put vtx error by hand for the moment false); MTDHitMatchingInfo mi; - mi.hit = &(*itr); + mi.hit = &hit; mi.estChi2 = est.second; mi.timeChi2 = tof.dtchi2_best; //use the chi2 for the best matching hypothesis From 380bdb3ae0117888215b7de1c1f84c68facdba8e Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 24 Jul 2020 02:50:51 +0200 Subject: [PATCH 07/15] precompute original track trackPathLength --- .../plugins/TrackExtenderWithMTD.cc | 149 ++++++++++-------- 1 file changed, 80 insertions(+), 69 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 68c4b7ced702d..07c114403cea9 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -229,6 +229,63 @@ namespace { return tscbl.isValid(); } + bool trackPathLength(const Trajectory& traj, + const TrajectoryStateClosestToBeamLine& tscbl, + const Propagator* thePropagator, + double& pathlength) { + pathlength = 0.; + + bool validpropagation = true; + double pathlength1 = 0.; + double pathlength2 = 0.; + + //add pathlength layer by layer + for (auto it = traj.measurements().begin(); it != traj.measurements().end() - 1; ++it) { + const auto& propresult = thePropagator->propagateWithPath(it->updatedState(), (it + 1)->updatedState().surface()); + double layerpathlength = std::abs(propresult.second); + if (layerpathlength == 0.) { + validpropagation = false; + } + pathlength1 += layerpathlength; + } + + //add distance from bs to first measurement + if (traj.direction() == alongMomentum) { + const auto& propresult2 = + thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), traj.firstMeasurement().updatedState().surface()); + pathlength2 = propresult2.second; + if (pathlength2 == 0.) { + validpropagation = false; + } + pathlength = pathlength1 + pathlength2; + } else { + const auto& propresult2 = + thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), traj.lastMeasurement().updatedState().surface()); + pathlength2 = propresult2.second; + if (pathlength2 == 0.) { + validpropagation = false; + } + pathlength = pathlength1 + pathlength2; + } + + return validpropagation; + } + + bool trackPathLength(const Trajectory& traj, + const reco::BeamSpot& bs, + const Propagator* thePropagator, + double& pathlength) { + pathlength = 0.; + + TrajectoryStateClosestToBeamLine tscbl; + bool tscbl_status = getTrajectoryStateClosestToBeamLine(traj, bs, thePropagator, tscbl); + + if (!tscbl_status) + return false; + + return trackPathLength(traj, tscbl, thePropagator, pathlength); + } + } // namespace template @@ -249,6 +306,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { TransientTrackingRecHit::ConstRecHitContainer tryBTLLayers(const TrajectoryStateOnSurface&, const Trajectory& traj, const TrajectoryStateClosestToBeamLine&, + const double, const MTDTrackingDetSetVector&, const MTDDetLayerGeometry*, const MagneticField* field, @@ -261,6 +319,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { TransientTrackingRecHit::ConstRecHitContainer tryETLLayers(const TrajectoryStateOnSurface&, const Trajectory& traj, const TrajectoryStateClosestToBeamLine&, + const double, const MTDTrackingDetSetVector&, const MTDDetLayerGeometry*, const MagneticField* field, @@ -274,6 +333,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { const TrajectoryStateOnSurface&, const Trajectory&, const TrajectoryStateClosestToBeamLine&, + const double, const MTDTrackingDetSetVector&, const Propagator*, const reco::BeamSpot&, @@ -485,8 +545,9 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: es.get().get(transientTrackBuilder_, builder_); es.get().get(mtdRecHitBuilder_, hitbuilder_); - edm::ESHandle prop; - es.get().get(propagator_, prop); + edm::ESHandle propH; + es.get().get(propagator_, propH); + const Propagator* prop = propH.product(); edm::ESHandle httopo; es.get().get(httopo); @@ -569,16 +630,20 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: // get the outermost trajectory point on the track TrajectoryStateOnSurface tsos = builder_->build(track).outermostMeasurementState(); TrajectoryStateClosestToBeamLine tscbl; - bool tscbl_status = getTrajectoryStateClosestToBeamLine(trajs.front(), bs, prop.product(), tscbl); + bool tscbl_status = getTrajectoryStateClosestToBeamLine(trajs.front(), bs, prop, tscbl); if (tscbl_status) { + double pathlength0; + trackPathLength(trajs.front(), tscbl, prop, pathlength0); + const auto& btlhits = tryBTLLayers(tsos, trajs.front(), tscbl, + pathlength0, hits, geo.product(), magfield.product(), - prop.product(), + prop, bs, trackVtxTime, trackVtxTime != 0., @@ -590,10 +655,11 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: const auto& etlhits = tryETLLayers(tsos, trajs.front(), tscbl, + pathlength0, hits, geo.product(), magfield.product(), - prop.product(), + prop, bs, trackVtxTime, trackVtxTime != 0., @@ -624,7 +690,7 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: trj, bs, magfield.product(), - prop.product(), + prop, !trajwithmtd.empty() && !mtdthits.empty(), pathLength, tmtd, @@ -706,68 +772,12 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: namespace { bool cmp_for_detset(const unsigned one, const unsigned two) { return one < two; }; - bool trackPathLength(const Trajectory& traj, - const TrajectoryStateClosestToBeamLine& tscbl, - const Propagator* thePropagator, - double& pathlength) { - pathlength = 0.; - - bool validpropagation = true; - double pathlength1 = 0.; - double pathlength2 = 0.; - - //add pathlength layer by layer - for (auto it = traj.measurements().begin(); it != traj.measurements().end() - 1; ++it) { - const auto& propresult = thePropagator->propagateWithPath(it->updatedState(), (it + 1)->updatedState().surface()); - double layerpathlength = std::abs(propresult.second); - if (layerpathlength == 0.) { - validpropagation = false; - } - pathlength1 += layerpathlength; - } - - //add distance from bs to first measurement - if (traj.direction() == alongMomentum) { - const auto& propresult2 = - thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), traj.firstMeasurement().updatedState().surface()); - pathlength2 = propresult2.second; - if (pathlength2 == 0.) { - validpropagation = false; - } - pathlength = pathlength1 + pathlength2; - } else { - const auto& propresult2 = - thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), traj.lastMeasurement().updatedState().surface()); - pathlength2 = propresult2.second; - if (pathlength2 == 0.) { - validpropagation = false; - } - pathlength = pathlength1 + pathlength2; - } - - return validpropagation; - } - - bool trackPathLength(const Trajectory& traj, - const reco::BeamSpot& bs, - const Propagator* thePropagator, - double& pathlength) { - pathlength = 0.; - - TrajectoryStateClosestToBeamLine tscbl; - bool tscbl_status = getTrajectoryStateClosestToBeamLine(traj, bs, thePropagator, tscbl); - - if (!tscbl_status) - return false; - - return trackPathLength(traj, tscbl, thePropagator, pathlength); - } - void find_hits_in_dets(const MTDTrackingDetSetVector& hits, const Trajectory& traj, const DetLayer* layer, const TrajectoryStateOnSurface& tsos, const TrajectoryStateClosestToBeamLine& tscbl, + const double pathlength0, const double vtxTime, const reco::BeamSpot& bs, const float bsTimeSpread, @@ -777,9 +787,6 @@ namespace { std::set& out) { const auto pmag2 = tscbl.trackStateAtPCA().momentum().mag2(); - double pathlength; - trackPathLength(traj, tscbl, prop, pathlength); - pair comp = layer->compatible(tsos, *prop, *theEstimator); if (comp.first) { const vector compDets = layer->compatibleDets(tsos, *prop, *theEstimator); @@ -793,7 +800,7 @@ namespace { if (pl.second == 0.) continue; - const double tot_pl = pathlength + std::abs(pl.second); + const double tot_pl = pathlength0 + std::abs(pl.second); const double t_vtx = useVtxConstraint ? vtxTime : 0.; constexpr double vtx_res = 0.008; @@ -833,6 +840,7 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il const TrajectoryStateOnSurface& tsos, const Trajectory& traj, const TrajectoryStateClosestToBeamLine& tscbl, + const double pathlength0, const MTDTrackingDetSetVector& hits, const Propagator* prop, const reco::BeamSpot& bs, @@ -901,6 +911,7 @@ void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il ilay, tsos, tscbl, + pathlength0, _1, bs, bsTimeSpread_, From 7b05d99cf7d7e1129ef691a47ae0bd9bea3c1b0c Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 24 Jul 2020 02:58:12 +0200 Subject: [PATCH 08/15] PCA p.mag2 is enough, do not carry TSCBL --- .../plugins/TrackExtenderWithMTD.cc | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 07c114403cea9..b03d9e0a93c62 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -305,7 +305,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { TransientTrackingRecHit::ConstRecHitContainer tryBTLLayers(const TrajectoryStateOnSurface&, const Trajectory& traj, - const TrajectoryStateClosestToBeamLine&, + const double, const double, const MTDTrackingDetSetVector&, const MTDDetLayerGeometry*, @@ -318,7 +318,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { TransientTrackingRecHit::ConstRecHitContainer tryETLLayers(const TrajectoryStateOnSurface&, const Trajectory& traj, - const TrajectoryStateClosestToBeamLine&, + const double, const double, const MTDTrackingDetSetVector&, const MTDDetLayerGeometry*, @@ -332,7 +332,7 @@ class TrackExtenderWithMTDT : public edm::stream::EDProducer<> { void fillMatchingHits(const DetLayer*, const TrajectoryStateOnSurface&, const Trajectory&, - const TrajectoryStateClosestToBeamLine&, + const double, const double, const MTDTrackingDetSetVector&, const Propagator*, @@ -633,12 +633,13 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: bool tscbl_status = getTrajectoryStateClosestToBeamLine(trajs.front(), bs, prop, tscbl); if (tscbl_status) { + double pmag2 = tscbl.trackStateAtPCA().momentum().mag2(); double pathlength0; trackPathLength(trajs.front(), tscbl, prop, pathlength0); const auto& btlhits = tryBTLLayers(tsos, trajs.front(), - tscbl, + pmag2, pathlength0, hits, geo.product(), @@ -654,7 +655,7 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: // for now it is ok const auto& etlhits = tryETLLayers(tsos, trajs.front(), - tscbl, + pmag2, pathlength0, hits, geo.product(), @@ -776,7 +777,7 @@ namespace { const Trajectory& traj, const DetLayer* layer, const TrajectoryStateOnSurface& tsos, - const TrajectoryStateClosestToBeamLine& tscbl, + const double pmag2, const double pathlength0, const double vtxTime, const reco::BeamSpot& bs, @@ -785,8 +786,6 @@ namespace { const std::unique_ptr& theEstimator, bool useVtxConstraint, std::set& out) { - const auto pmag2 = tscbl.trackStateAtPCA().momentum().mag2(); - pair comp = layer->compatible(tsos, *prop, *theEstimator); if (comp.first) { const vector compDets = layer->compatibleDets(tsos, *prop, *theEstimator); @@ -839,7 +838,7 @@ template TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT::tryBTLLayers( const TrajectoryStateOnSurface& tsos, const Trajectory& traj, - const TrajectoryStateClosestToBeamLine& tscbl, + const double pmag2, const double pathlength0, const MTDTrackingDetSetVector& hits, const MTDDetLayerGeometry* geo, @@ -854,7 +853,7 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT::tryETLLayers( const TrajectoryStateOnSurface& tsos, const Trajectory& traj, - const TrajectoryStateClosestToBeamLine& tscbl, + const double pmag2, const double pathlength0, const MTDTrackingDetSetVector& hits, const MTDDetLayerGeometry* geo, @@ -883,7 +882,7 @@ TransientTrackingRecHit::ConstRecHitContainer TrackExtenderWithMTDT void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* ilay, const TrajectoryStateOnSurface& tsos, const Trajectory& traj, - const TrajectoryStateClosestToBeamLine& tscbl, + const double pmag2, const double pathlength0, const MTDTrackingDetSetVector& hits, const Propagator* prop, @@ -910,7 +909,7 @@ void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il traj, ilay, tsos, - tscbl, + pmag2, pathlength0, _1, bs, From f369d29aeb518436537bf2aa900eeb836bcf70d9 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 24 Jul 2020 03:08:36 +0200 Subject: [PATCH 09/15] use a temp for readability --- .../plugins/TrackExtenderWithMTD.cc | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index b03d9e0a93c62..d28cef2ff6839 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -927,11 +927,12 @@ void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il //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 - if (hitsInLayer.begin()->estChi2 < etlChi2Cut_ && hitsInLayer.begin()->timeChi2 < etlTimeChi2Cut_) { + auto const& firstHit = *hitsInLayer.begin(); + if (firstHit.estChi2 < etlChi2Cut_ && firstHit.timeChi2 < etlTimeChi2Cut_) { hitMatched = true; - output.push_back(hitbuilder_->build(hitsInLayer.begin()->hit)); - if (*(hitsInLayer.begin()) < bestHit) - bestHit = *(hitsInLayer.begin()); + output.push_back(hitbuilder_->build(firstHit.hit)); + if (firstHit < bestHit) + bestHit = firstHit; } } @@ -940,12 +941,13 @@ void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il hitsInLayer.clear(); find_hits(0, false); if (!hitsInLayer.empty()) { - if (hitsInLayer.begin()->timeChi2 < etlTimeChi2Cut_) { - if (hitsInLayer.begin()->estChi2 < etlChi2Cut_) { + auto const& firstHit = *hitsInLayer.begin(); + if (firstHit.timeChi2 < etlTimeChi2Cut_) { + if (firstHit.estChi2 < etlChi2Cut_) { hitMatched = true; - output.push_back(hitbuilder_->build(hitsInLayer.begin()->hit)); - if ((*hitsInLayer.begin()) < bestHit) - bestHit = *(hitsInLayer.begin()); + output.push_back(hitbuilder_->build(firstHit.hit)); + if (firstHit < bestHit) + bestHit = firstHit; } } } From 17efbf58696e20e39ffb41aca149a95d2c1e4f60 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 24 Jul 2020 07:58:17 +0200 Subject: [PATCH 10/15] keep theEstimator only for the member name --- .../TrackExtender/plugins/TrackExtenderWithMTD.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index d28cef2ff6839..3f27cc3e9244b 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -783,12 +783,12 @@ namespace { const reco::BeamSpot& bs, const float bsTimeSpread, const Propagator* prop, - const std::unique_ptr& theEstimator, + const MeasurementEstimator* estimator, bool useVtxConstraint, std::set& out) { - pair comp = layer->compatible(tsos, *prop, *theEstimator); + pair comp = layer->compatible(tsos, *prop, *estimator); if (comp.first) { - const vector compDets = layer->compatibleDets(tsos, *prop, *theEstimator); + const vector compDets = layer->compatibleDets(tsos, *prop, *estimator); if (!compDets.empty()) { for (const auto& detWithState : compDets) { auto range = hits.equal_range(detWithState.first->geographicalId(), cmp_for_detset); @@ -809,7 +809,7 @@ namespace { for (auto detitr = range.first; detitr != range.second; ++detitr) { for (const auto& hit : *detitr) { - auto est = theEstimator->estimate(detWithState.second, hit); + auto est = estimator->estimate(detWithState.second, hit); if (!est.first) continue; @@ -915,9 +915,9 @@ void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il bs, bsTimeSpread_, prop, - std::ref(theEstimator), + theEstimator.get(), _2, - std::ref(hitsInLayer)); + hitsInLayer); if (useVertex_ && matchVertex) find_hits(vtxTime, true); From 376a0992c5d0d77e46e92fbcfd1018d93dba72e3 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 24 Jul 2020 08:32:02 +0200 Subject: [PATCH 11/15] cref and ref in std::bind --- RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 3f27cc3e9244b..0bdecb6578ca0 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -905,19 +905,19 @@ void TrackExtenderWithMTDT::fillMatchingHits(const DetLayer* il using namespace std::placeholders; auto find_hits = std::bind(find_hits_in_dets, - hits, - traj, + std::cref(hits), + std::cref(traj), ilay, - tsos, + std::cref(tsos), pmag2, pathlength0, _1, - bs, + std::cref(bs), bsTimeSpread_, prop, theEstimator.get(), _2, - hitsInLayer); + std::ref(hitsInLayer)); if (useVertex_ && matchVertex) find_hits(vtxTime, true); From 9ac0a7683b02fe659406d1c81272da6a62ffff07 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 24 Jul 2020 16:53:50 +0200 Subject: [PATCH 12/15] do not remake trajectories if no mtdhits were added --- RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 0bdecb6578ca0..d037f00ab1acb 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -678,7 +678,7 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: thits.swap(mtdthits); } - const auto& trajwithmtd = theTransformer->transform(ttrack, thits); + const auto& trajwithmtd = mtdthits.empty() ? 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; int iMap = -1; From 8a377979915c15993c56a5466b444444c19d9d09 Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Fri, 24 Jul 2020 19:04:30 +0200 Subject: [PATCH 13/15] code-checks --- RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index d037f00ab1acb..6d4749937f7a6 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -650,7 +650,7 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: trackVtxTime != 0., mBTL); mtdthits.insert(mtdthits.end(), btlhits.begin(), btlhits.end()); - + // in the future this should include an intermediate refit before propagating to the ETL // for now it is ok const auto& etlhits = tryETLLayers(tsos, @@ -667,7 +667,7 @@ void TrackExtenderWithMTDT::produce(edm::Event& ev, const edm:: mETL); mtdthits.insert(mtdthits.end(), etlhits.begin(), etlhits.end()); } - }//!trajs.empty() + } //!trajs.empty() auto ordering = checkRecHitsOrdering(thits); if (ordering == RefitDirection::insideOut) { From 92e14d17deeccec3892bc7a726d8233c6dfde0cb Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 25 Jul 2020 17:45:46 +0200 Subject: [PATCH 14/15] common lines outside of if-else --- .../TrackExtender/plugins/TrackExtenderWithMTD.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index 6d4749937f7a6..a9d3fe9d36c33 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -254,19 +254,15 @@ namespace { const auto& propresult2 = thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), traj.firstMeasurement().updatedState().surface()); pathlength2 = propresult2.second; - if (pathlength2 == 0.) { - validpropagation = false; - } - pathlength = pathlength1 + pathlength2; } else { const auto& propresult2 = thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), traj.lastMeasurement().updatedState().surface()); pathlength2 = propresult2.second; - if (pathlength2 == 0.) { - validpropagation = false; - } - pathlength = pathlength1 + pathlength2; } + if (pathlength2 == 0.) { + validpropagation = false; + } + pathlength = pathlength1 + pathlength2; return validpropagation; } From 6f27f6dae7e59c469e3540aa011e544b778ec80a Mon Sep 17 00:00:00 2001 From: Slava Krutelyov Date: Sat, 25 Jul 2020 17:58:57 +0200 Subject: [PATCH 15/15] elide if-else by using a ternary --- .../TrackExtender/plugins/TrackExtenderWithMTD.cc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc index a9d3fe9d36c33..426eb04bce2ae 100644 --- a/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc +++ b/RecoMTD/TrackExtender/plugins/TrackExtenderWithMTD.cc @@ -250,15 +250,10 @@ namespace { } //add distance from bs to first measurement - if (traj.direction() == alongMomentum) { - const auto& propresult2 = - thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), traj.firstMeasurement().updatedState().surface()); - pathlength2 = propresult2.second; - } else { - const auto& propresult2 = - thePropagator->propagateWithPath(tscbl.trackStateAtPCA(), traj.lastMeasurement().updatedState().surface()); - pathlength2 = propresult2.second; - } + auto const& tscblPCA = tscbl.trackStateAtPCA(); + auto const& aSurface = traj.direction() == alongMomentum ? traj.firstMeasurement().updatedState().surface() + : traj.lastMeasurement().updatedState().surface(); + pathlength2 = thePropagator->propagateWithPath(tscblPCA, aSurface).second; if (pathlength2 == 0.) { validpropagation = false; }