/
githubmirror
/
cmssw
Обзор
Документация
Войти
/
githubmirror
/
cmssw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
RecoTracker/MeasurementDet/plugins/doubleMatch.icc
163 строки
6 KB
Kevin Pedro
use branchless 'and' in tracker hit matching
11 апр 2025, 17:15
11 апр 2025, 17:15
9760658
Код
Авторство
О чём код?
namespace { template <typename Collector> struct CollectorHelper { Collector& m_collector; GlobalVector const& glbDir; CollectorHelper(Collector& i_collector, GlobalVector const& i_glbDir) : m_collector(i_collector), glbDir(i_glbDir) {} inline static SiStripRecHit2D const& monoHit(TkGluedMeasurementDet::RecHitContainer::const_iterator monoHit) { return *reinterpret_cast<const SiStripRecHit2D*>((**monoHit).hit()); } inline static SiStripRecHit2D const& monoHit(std::vector<SiStripRecHit2D>::const_iterator iter) { return *iter; } inline static SiStripRecHit2D const& stereoHit(std::vector<SiStripRecHit2D>::const_iterator iter) { return *iter; } inline static SiStripRecHit2D const& stereoHit(TkGluedMeasurementDet::RecHitContainer::const_iterator hit) { return *reinterpret_cast<const SiStripRecHit2D*>((**hit).hit()); } typename Collector::Collector& collector() { return m_collector.collector(); } inline void closure(TkGluedMeasurementDet::RecHitContainer::const_iterator monoHit) { if (m_collector.hasNewMatchedHits()) { m_collector.clearNewMatchedHitsFlag(); } else { m_collector.addProjected(**monoHit, glbDir); } } inline void closure(std::vector<SiStripRecHit2D>::const_iterator monoHit) { if (m_collector.hasNewMatchedHits()) { m_collector.clearNewMatchedHitsFlag(); } else { m_collector.addProjected(*monoHit, glbDir); } } }; } // namespace #include "RecHitPropagator.h" #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" #include "DataFormats/GeometrySurface/interface/LocalError.h" #include "DataFormats/Math/interface/logic.h" namespace { inline void print(const char* where, const TrajectoryStateOnSurface& t1, const TrajectoryStateOnSurface& t2) { std::cout << where << std::endl; std::cout << t1.localParameters().vector() << std::endl; std::cout << t1.localError().positionError() << std::endl; std::cout << t2.localParameters().vector() << std::endl; std::cout << t2.localError().positionError() << std::endl; } } // namespace template <typename Collector> void TkGluedMeasurementDet::doubleMatch(const TrajectoryStateOnSurface& ts, const MeasurementTrackerEvent& data, Collector& collector) const { GlobalVector glbDir = (ts.isValid() ? ts.globalMomentum() : position() - GlobalPoint(0, 0, 0)); // static SiStripRecHitMatcher::SimpleHitCollection vsStereoHits; // vsStereoHits.resize(simpleSteroHitsByValue.size()); //std::transform(simpleSteroHitsByValue.begin(), simpleSteroHitsByValue.end(), vsStereoHits.begin(), take_address()); std::vector<SiStripRecHit2D> monoHits; std::vector<SiStripRecHit2D> stereoHits; auto mf = monoHits.size(); auto sf = stereoHits.size(); bool emptyMono = false; bool emptyStereo = false; // FIXME clean this and optimize the rest of the code once understood and validated if (true) { // collector.filter()) { emptyMono = theMonoDet->empty(data); if LIKELY (!emptyMono) { // mono does require "projection" for precise estimate TrajectoryStateOnSurface mts = fastProp(ts, geomDet().surface(), theMonoDet->geomDet().surface()); if LIKELY (mts.isValid()) theMonoDet->simpleRecHits(mts, collector.estimator(), data, monoHits); } // print("mono", mts,ts); mf = monoHits.size(); } else { theMonoDet->simpleRecHits(ts, data, monoHits); emptyMono = monoHits.empty(); } // stereo requires "projection" for precision and change in coordinates if (collector.filter()) { emptyStereo = theStereoDet->empty(data); if LIKELY (!emptyStereo) { TrajectoryStateOnSurface pts = fastProp(ts, geomDet().surface(), theStereoDet->geomDet().surface()); if LIKELY (pts.isValid()) theStereoDet->simpleRecHits(pts, collector.estimator(), data, stereoHits); // print("stereo", pts,ts); } sf = stereoHits.size(); } else { theStereoDet->simpleRecHits(ts, data, stereoHits); emptyStereo = stereoHits.empty(); } if (collector.filter()) { auto mh = monoHits.size(); auto sh = stereoHits.size(); stat(mh, sh, mf, sf); } if UNLIKELY (emptyMono & emptyStereo) return; if UNLIKELY (emptyStereo) { // make mono TTRHs and project them projectOnGluedDet(collector, monoHits, glbDir); return; } if UNLIKELY (emptyMono) { // make stereo TTRHs and project them projectOnGluedDet(collector, stereoHits, glbDir); return; } if (reco::branchless_and(!monoHits.empty(), !stereoHits.empty())) { const GluedGeomDet* gluedDet = &specificGeomDet(); LocalVector trdir = (ts.isValid() ? ts.localDirection() : surface().toLocal(position() - GlobalPoint(0, 0, 0))); CollectorHelper<Collector> chelper(collector, glbDir); theMatcher->doubleMatch( monoHits.begin(), monoHits.end(), stereoHits.begin(), stereoHits.end(), gluedDet, trdir, chelper); } if (ts.globalMomentum().perp2() > collector.estimator().minPt2ForHitRecoveryInGluedDet()) { // if no match found try add mon than try to add stereo... if (0 == collector.size()) projectOnGluedDet(collector, monoHits, glbDir); if (0 == collector.size()) projectOnGluedDet(collector, stereoHits, glbDir); } /* // recover hits outside if ( collector.filter() && 0==collector.size()) { auto inoutM = reinterpret_cast<RectangularPlaneBounds const&>(theMonoDet->surface().bounds()).inout(ts.localPosition(), ts.localError().positionError() ,3.f); auto inoutS = reinterpret_cast<RectangularPlaneBounds const&>(theStereoDet->surface().bounds()).inout(pts.localPosition(), pts.localError().positionError() ,3.f); if (inoutM.first&&inoutS.second) projectOnGluedDet( collector, monoHits, glbDir); if (inoutM.second&&inoutS.first) projectOnGluedDet( collector, stereoHits, glbDir); } */ if (collector.filter()) { stat.match(collector.size()); } }