diff --git a/RecoTracker/LSTCore/interface/Circle.h b/RecoTracker/LSTCore/interface/Circle.h new file mode 100644 index 0000000000000..ec25174294aa3 --- /dev/null +++ b/RecoTracker/LSTCore/interface/Circle.h @@ -0,0 +1,46 @@ +#ifndef RecoTracker_LSTCore_interface_Circle_h +#define RecoTracker_LSTCore_interface_Circle_h + +#include + +#include "HeterogeneousCore/AlpakaInterface/interface/config.h" + +namespace lst { + + template + ALPAKA_FN_ACC ALPAKA_FN_INLINE std::tuple computeRadiusFromThreeAnchorHits( + TAcc const& acc, float x1, float y1, float x2, float y2, float x3, float y3) { + float radius = 0.f; + + //first anchor hit - (x1,y1), second anchor hit - (x2,y2), third anchor hit - (x3, y3) + + float denomInv = 1.0f / ((y1 - y3) * (x2 - x3) - (x1 - x3) * (y2 - y3)); + + float xy1sqr = x1 * x1 + y1 * y1; + + float xy2sqr = x2 * x2 + y2 * y2; + + float xy3sqr = x3 * x3 + y3 * y3; + + float regressionCenterX = 0.5f * ((y3 - y2) * xy1sqr + (y1 - y3) * xy2sqr + (y2 - y1) * xy3sqr) * denomInv; + + float regressionCenterY = 0.5f * ((x2 - x3) * xy1sqr + (x3 - x1) * xy2sqr + (x1 - x2) * xy3sqr) * denomInv; + + float c = ((x2 * y3 - x3 * y2) * xy1sqr + (x3 * y1 - x1 * y3) * xy2sqr + (x1 * y2 - x2 * y1) * xy3sqr) * denomInv; + + if (((y1 - y3) * (x2 - x3) - (x1 - x3) * (y2 - y3) == 0) || + (regressionCenterX * regressionCenterX + regressionCenterY * regressionCenterY - c < 0)) { +#ifdef WARNINGS + printf("three collinear points or FATAL! r^2 < 0!\n"); +#endif + radius = -1.f; + } else + radius = + alpaka::math::sqrt(acc, regressionCenterX * regressionCenterX + regressionCenterY * regressionCenterY - c); + + return std::make_tuple(radius, regressionCenterX, regressionCenterY); + } + +} //namespace lst + +#endif diff --git a/RecoTracker/LSTCore/src/alpaka/LSTEvent.dev.cc b/RecoTracker/LSTCore/src/alpaka/LSTEvent.dev.cc index 531cef3765612..94410a5fb7975 100644 --- a/RecoTracker/LSTCore/src/alpaka/LSTEvent.dev.cc +++ b/RecoTracker/LSTCore/src/alpaka/LSTEvent.dev.cc @@ -3,6 +3,8 @@ #include "LSTEvent.h" +#include "Hit.h" +#include "Kernels.h" #include "MiniDoublet.h" #include "PixelQuintuplet.h" #include "PixelTriplet.h" diff --git a/RecoTracker/LSTCore/src/alpaka/LSTEvent.h b/RecoTracker/LSTCore/src/alpaka/LSTEvent.h index a883436a11266..7b36c011265a8 100644 --- a/RecoTracker/LSTCore/src/alpaka/LSTEvent.h +++ b/RecoTracker/LSTCore/src/alpaka/LSTEvent.h @@ -15,6 +15,7 @@ #include "RecoTracker/LSTCore/interface/ModulesHostCollection.h" #include "RecoTracker/LSTCore/interface/alpaka/Common.h" #include "RecoTracker/LSTCore/interface/alpaka/LST.h" +#include "RecoTracker/LSTCore/interface/alpaka/HitsDeviceCollection.h" #include "RecoTracker/LSTCore/interface/alpaka/MiniDoubletsDeviceCollection.h" #include "RecoTracker/LSTCore/interface/alpaka/PixelQuintupletsDeviceCollection.h" #include "RecoTracker/LSTCore/interface/alpaka/PixelTripletsDeviceCollection.h" @@ -26,9 +27,6 @@ #include "RecoTracker/LSTCore/interface/alpaka/ObjectRangesDeviceCollection.h" #include "RecoTracker/LSTCore/interface/alpaka/EndcapGeometryDevDeviceCollection.h" -#include "Hit.h" -#include "Kernels.h" - #include "HeterogeneousCore/AlpakaInterface/interface/host.h" namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { diff --git a/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h b/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h index cb9d3e50e955b..369b0865c0d8a 100644 --- a/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h +++ b/RecoTracker/LSTCore/src/alpaka/MiniDoublet.h @@ -5,14 +5,13 @@ #include "FWCore/Utilities/interface/isFinite.h" #include "RecoTracker/LSTCore/interface/alpaka/Common.h" +#include "RecoTracker/LSTCore/interface/HitsSoA.h" #include "RecoTracker/LSTCore/interface/MiniDoubletsSoA.h" #include "RecoTracker/LSTCore/interface/alpaka/MiniDoubletsDeviceCollection.h" #include "RecoTracker/LSTCore/interface/ModulesSoA.h" #include "RecoTracker/LSTCore/interface/EndcapGeometry.h" #include "RecoTracker/LSTCore/interface/ObjectRangesSoA.h" -#include "Hit.h" - namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { template ALPAKA_FN_ACC ALPAKA_FN_INLINE void addMDToMemory(TAcc const& acc, diff --git a/RecoTracker/LSTCore/src/alpaka/PixelQuintuplet.h b/RecoTracker/LSTCore/src/alpaka/PixelQuintuplet.h index defca4119ebab..9b38844828129 100644 --- a/RecoTracker/LSTCore/src/alpaka/PixelQuintuplet.h +++ b/RecoTracker/LSTCore/src/alpaka/PixelQuintuplet.h @@ -2,6 +2,7 @@ #define RecoTracker_LSTCore_src_alpaka_PixelQuintuplet_h #include "RecoTracker/LSTCore/interface/alpaka/Common.h" +#include "RecoTracker/LSTCore/interface/HitsSoA.h" #include "RecoTracker/LSTCore/interface/ModulesSoA.h" #include "RecoTracker/LSTCore/interface/ObjectRangesSoA.h" #include "RecoTracker/LSTCore/interface/MiniDoubletsSoA.h" @@ -10,7 +11,7 @@ #include "RecoTracker/LSTCore/interface/SegmentsSoA.h" #include "RecoTracker/LSTCore/interface/TripletsSoA.h" -#include "Hit.h" +#include "Quintuplet.h" #include "PixelTriplet.h" namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { diff --git a/RecoTracker/LSTCore/src/alpaka/Quintuplet.h b/RecoTracker/LSTCore/src/alpaka/Quintuplet.h index ef14d8fd92a8e..162e26f8014ab 100644 --- a/RecoTracker/LSTCore/src/alpaka/Quintuplet.h +++ b/RecoTracker/LSTCore/src/alpaka/Quintuplet.h @@ -13,10 +13,9 @@ #include "RecoTracker/LSTCore/interface/ModulesSoA.h" #include "RecoTracker/LSTCore/interface/EndcapGeometry.h" #include "RecoTracker/LSTCore/interface/ObjectRangesSoA.h" +#include "RecoTracker/LSTCore/interface/Circle.h" #include "NeuralNetwork.h" -#include "Hit.h" -#include "Triplet.h" // FIXME: need to refactor common functions to a common place namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { ALPAKA_FN_ACC ALPAKA_FN_INLINE void addQuintupletToMemory(TripletsConst triplets, @@ -1502,7 +1501,7 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { float g, f; outerRadius = triplets.radius()[outerTripletIndex]; - bridgeRadius = computeRadiusFromThreeAnchorHits(acc, x2, y2, x3, y3, x4, y4, g, f); + std::tie(bridgeRadius, g, f) = computeRadiusFromThreeAnchorHits(acc, x2, y2, x3, y3, x4, y4); innerRadius = triplets.radius()[innerTripletIndex]; bool inference = lst::t5dnn::runInference(acc, diff --git a/RecoTracker/LSTCore/src/alpaka/Segment.h b/RecoTracker/LSTCore/src/alpaka/Segment.h index 3309100529900..071795eba7371 100644 --- a/RecoTracker/LSTCore/src/alpaka/Segment.h +++ b/RecoTracker/LSTCore/src/alpaka/Segment.h @@ -9,12 +9,11 @@ #include "RecoTracker/LSTCore/interface/SegmentsSoA.h" #include "RecoTracker/LSTCore/interface/alpaka/SegmentsDeviceCollection.h" #include "RecoTracker/LSTCore/interface/ModulesSoA.h" +#include "RecoTracker/LSTCore/interface/HitsSoA.h" +#include "RecoTracker/LSTCore/interface/MiniDoubletsSoA.h" #include "RecoTracker/LSTCore/interface/EndcapGeometry.h" #include "RecoTracker/LSTCore/interface/ObjectRangesSoA.h" -#include "MiniDoublet.h" -#include "Hit.h" - namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { ALPAKA_FN_ACC ALPAKA_FN_INLINE bool isTighterTiltedModules_seg(ModulesConst modules, unsigned int moduleIndex) { diff --git a/RecoTracker/LSTCore/src/alpaka/TrackCandidate.h b/RecoTracker/LSTCore/src/alpaka/TrackCandidate.h index 7f016af17199c..59f9c2347d945 100644 --- a/RecoTracker/LSTCore/src/alpaka/TrackCandidate.h +++ b/RecoTracker/LSTCore/src/alpaka/TrackCandidate.h @@ -5,6 +5,7 @@ #include "RecoTracker/LSTCore/interface/alpaka/Common.h" #include "RecoTracker/LSTCore/interface/ModulesSoA.h" +#include "RecoTracker/LSTCore/interface/HitsSoA.h" #include "RecoTracker/LSTCore/interface/MiniDoubletsSoA.h" #include "RecoTracker/LSTCore/interface/PixelQuintupletsSoA.h" #include "RecoTracker/LSTCore/interface/PixelTripletsSoA.h" @@ -13,8 +14,6 @@ #include "RecoTracker/LSTCore/interface/TrackCandidatesSoA.h" #include "RecoTracker/LSTCore/interface/TripletsSoA.h" -#include "Hit.h" - namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { ALPAKA_FN_ACC ALPAKA_FN_INLINE void addpLSTrackCandidateToMemory(TrackCandidates& cands, unsigned int trackletIndex, diff --git a/RecoTracker/LSTCore/src/alpaka/Triplet.h b/RecoTracker/LSTCore/src/alpaka/Triplet.h index e84fa06a2372c..b0fd46bd8b374 100644 --- a/RecoTracker/LSTCore/src/alpaka/Triplet.h +++ b/RecoTracker/LSTCore/src/alpaka/Triplet.h @@ -8,10 +8,7 @@ #include "RecoTracker/LSTCore/interface/ModulesSoA.h" #include "RecoTracker/LSTCore/interface/ObjectRangesSoA.h" #include "RecoTracker/LSTCore/interface/TripletsSoA.h" - -#include "Segment.h" -#include "MiniDoublet.h" -#include "Hit.h" +#include "RecoTracker/LSTCore/interface/Circle.h" namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { @@ -628,39 +625,6 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { return false; // failsafe } - template - ALPAKA_FN_ACC ALPAKA_FN_INLINE float computeRadiusFromThreeAnchorHits( - TAcc const& acc, float x1, float y1, float x2, float y2, float x3, float y3, float& g, float& f) { - float radius = 0.f; - - //(g,f) -> center - //first anchor hit - (x1,y1), second anchor hit - (x2,y2), third anchor hit - (x3, y3) - - float denomInv = 1.0f / ((y1 - y3) * (x2 - x3) - (x1 - x3) * (y2 - y3)); - - float xy1sqr = x1 * x1 + y1 * y1; - - float xy2sqr = x2 * x2 + y2 * y2; - - float xy3sqr = x3 * x3 + y3 * y3; - - g = 0.5f * ((y3 - y2) * xy1sqr + (y1 - y3) * xy2sqr + (y2 - y1) * xy3sqr) * denomInv; - - f = 0.5f * ((x2 - x3) * xy1sqr + (x3 - x1) * xy2sqr + (x1 - x2) * xy3sqr) * denomInv; - - float c = ((x2 * y3 - x3 * y2) * xy1sqr + (x3 * y1 - x1 * y3) * xy2sqr + (x1 * y2 - x2 * y1) * xy3sqr) * denomInv; - - if (((y1 - y3) * (x2 - x3) - (x1 - x3) * (y2 - y3) == 0) || (g * g + f * f - c < 0)) { -#ifdef WARNINGS - printf("three collinear points or FATAL! r^2 < 0!\n"); -#endif - radius = -1.f; - } else - radius = alpaka::math::sqrt(acc, g * g + f * f - c); - - return radius; - } - template ALPAKA_FN_ACC ALPAKA_FN_INLINE bool runTripletConstraintsAndAlgo(TAcc const& acc, ModulesConst modules, @@ -694,7 +658,8 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::lst { float y2 = mds.anchorY()[secondMDIndex]; float y3 = mds.anchorY()[thirdMDIndex]; - circleRadius = computeRadiusFromThreeAnchorHits(acc, x1, y1, x2, y2, x3, y3, circleCenterX, circleCenterY); + std::tie(circleRadius, circleCenterX, circleCenterY) = + computeRadiusFromThreeAnchorHits(acc, x1, y1, x2, y2, x3, y3); if (not passRZConstraint(acc, modules, diff --git a/RecoTracker/LSTCore/standalone/code/core/write_lst_ntuple.cc b/RecoTracker/LSTCore/standalone/code/core/write_lst_ntuple.cc index deed88f833a00..2c52c88e6ccbd 100644 --- a/RecoTracker/LSTCore/standalone/code/core/write_lst_ntuple.cc +++ b/RecoTracker/LSTCore/standalone/code/core/write_lst_ntuple.cc @@ -1,6 +1,5 @@ -// to use computeRadiusFromThreeAnchorHits #include "LSTEvent.h" -#include "Triplet.h" +#include "Circle.h" #include "write_lst_ntuple.h" @@ -672,17 +671,15 @@ void fillT5DNNBranches(LSTEvent* event, unsigned int iT3) { ana.tx->pushbackToBranch("t5_t3_" + idx + "_moduleType", modules.moduleType()[module]); } - float g, f; + float radius; auto const& devHost = cms::alpakatools::host(); - float radius = computeRadiusFromThreeAnchorHits(devHost, - hitObjects[0].x(), - hitObjects[0].y(), - hitObjects[1].x(), - hitObjects[1].y(), - hitObjects[2].x(), - hitObjects[2].y(), - g, - f); + std::tie(radius, std::ignore, std::ignore) = computeRadiusFromThreeAnchorHits(devHost, + hitObjects[0].x(), + hitObjects[0].y(), + hitObjects[1].x(), + hitObjects[1].y(), + hitObjects[2].x(), + hitObjects[2].y()); ana.tx->pushbackToBranch("t5_t3_pt", k2Rinv1GeVf * 2 * radius); // Angles