Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-05 02:48:06

0001 #ifndef RecoTracker_LSTCore_src_alpaka_LSTEvent_h
0002 #define RecoTracker_LSTCore_src_alpaka_LSTEvent_h
0003 
0004 #include <optional>
0005 
0006 #include "RecoTracker/LSTCore/interface/HitsHostCollection.h"
0007 #include "RecoTracker/LSTCore/interface/MiniDoubletsHostCollection.h"
0008 #include "RecoTracker/LSTCore/interface/PixelQuintupletsHostCollection.h"
0009 #include "RecoTracker/LSTCore/interface/PixelTripletsHostCollection.h"
0010 #include "RecoTracker/LSTCore/interface/QuintupletsHostCollection.h"
0011 #include "RecoTracker/LSTCore/interface/SegmentsHostCollection.h"
0012 #include "RecoTracker/LSTCore/interface/TrackCandidatesHostCollection.h"
0013 #include "RecoTracker/LSTCore/interface/TripletsHostCollection.h"
0014 #include "RecoTracker/LSTCore/interface/ObjectRangesHostCollection.h"
0015 #include "RecoTracker/LSTCore/interface/ModulesHostCollection.h"
0016 #include "RecoTracker/LSTCore/interface/alpaka/Common.h"
0017 #include "RecoTracker/LSTCore/interface/alpaka/LST.h"
0018 #include "RecoTracker/LSTCore/interface/alpaka/MiniDoubletsDeviceCollection.h"
0019 #include "RecoTracker/LSTCore/interface/alpaka/PixelQuintupletsDeviceCollection.h"
0020 #include "RecoTracker/LSTCore/interface/alpaka/PixelTripletsDeviceCollection.h"
0021 #include "RecoTracker/LSTCore/interface/alpaka/QuintupletsDeviceCollection.h"
0022 #include "RecoTracker/LSTCore/interface/alpaka/SegmentsDeviceCollection.h"
0023 #include "RecoTracker/LSTCore/interface/alpaka/TrackCandidatesDeviceCollection.h"
0024 #include "RecoTracker/LSTCore/interface/alpaka/TripletsDeviceCollection.h"
0025 #include "RecoTracker/LSTCore/interface/alpaka/ModulesDeviceCollection.h"
0026 #include "RecoTracker/LSTCore/interface/alpaka/ObjectRangesDeviceCollection.h"
0027 #include "RecoTracker/LSTCore/interface/alpaka/EndcapGeometryDevDeviceCollection.h"
0028 
0029 #include "Hit.h"
0030 #include "Kernels.h"
0031 
0032 #include "HeterogeneousCore/AlpakaInterface/interface/host.h"
0033 
0034 namespace ALPAKA_ACCELERATOR_NAMESPACE::lst {
0035 
0036   class LSTEvent {
0037   private:
0038     Queue& queue_;
0039     const float ptCut_;
0040 
0041     std::array<unsigned int, 6> n_minidoublets_by_layer_barrel_{};
0042     std::array<unsigned int, 5> n_minidoublets_by_layer_endcap_{};
0043     std::array<unsigned int, 6> n_segments_by_layer_barrel_{};
0044     std::array<unsigned int, 5> n_segments_by_layer_endcap_{};
0045     std::array<unsigned int, 6> n_triplets_by_layer_barrel_{};
0046     std::array<unsigned int, 5> n_triplets_by_layer_endcap_{};
0047     std::array<unsigned int, 6> n_quintuplets_by_layer_barrel_{};
0048     std::array<unsigned int, 5> n_quintuplets_by_layer_endcap_{};
0049     unsigned int nTotalSegments_;
0050 
0051     //Device stuff
0052     std::optional<ObjectRangesDeviceCollection> rangesDC_;
0053     std::optional<HitsDeviceCollection> hitsDC_;
0054     std::optional<MiniDoubletsDeviceCollection> miniDoubletsDC_;
0055     std::optional<SegmentsDeviceCollection> segmentsDC_;
0056     std::optional<TripletsDeviceCollection> tripletsDC_;
0057     std::optional<QuintupletsDeviceCollection> quintupletsDC_;
0058     std::optional<TrackCandidatesDeviceCollection> trackCandidatesDC_;
0059     std::optional<PixelTripletsDeviceCollection> pixelTripletsDC_;
0060     std::optional<PixelQuintupletsDeviceCollection> pixelQuintupletsDC_;
0061 
0062     //CPU interface stuff
0063     std::optional<ObjectRangesHostCollection> rangesHC_;
0064     std::optional<HitsHostCollection> hitsHC_;
0065     std::optional<MiniDoubletsHostCollection> miniDoubletsHC_;
0066     std::optional<SegmentsHostCollection> segmentsHC_;
0067     std::optional<TripletsHostCollection> tripletsHC_;
0068     std::optional<TrackCandidatesHostCollection> trackCandidatesHC_;
0069     std::optional<ModulesHostCollection> modulesHC_;
0070     std::optional<QuintupletsHostCollection> quintupletsHC_;
0071     std::optional<PixelTripletsHostCollection> pixelTripletsHC_;
0072     std::optional<PixelQuintupletsHostCollection> pixelQuintupletsHC_;
0073 
0074     const uint16_t nModules_;
0075     const uint16_t nLowerModules_;
0076     const unsigned int nPixels_;
0077     const unsigned int nEndCapMap_;
0078     ModulesDeviceCollection const& modules_;
0079     PixelMap const& pixelMapping_;
0080     EndcapGeometryDevDeviceCollection const& endcapGeometry_;
0081     bool addObjects_;
0082 
0083   public:
0084     // Constructor used for CMSSW integration. Uses an external queue.
0085     LSTEvent(bool verbose, const float pt_cut, Queue& q, const LSTESData<Device>* deviceESData)
0086         : queue_(q),
0087           ptCut_(pt_cut),
0088           nModules_(deviceESData->nModules),
0089           nLowerModules_(deviceESData->nLowerModules),
0090           nPixels_(deviceESData->nPixels),
0091           nEndCapMap_(deviceESData->nEndCapMap),
0092           modules_(*deviceESData->modules),
0093           pixelMapping_(*deviceESData->pixelMapping),
0094           endcapGeometry_(*deviceESData->endcapGeometry),
0095           addObjects_(verbose) {
0096       if (pt_cut < 0.6f) {
0097         throw std::invalid_argument("Minimum pT cut must be at least 0.6 GeV. Provided value: " +
0098                                     std::to_string(pt_cut));
0099       }
0100     }
0101     void initSync();        // synchronizes, for standalone usage
0102     void resetEventSync();  // synchronizes, for standalone usage
0103     void wait() const { alpaka::wait(queue_); }
0104 
0105     // Calls the appropriate hit function, then increments the counter
0106     void addHitToEvent(std::vector<float> const& x,
0107                        std::vector<float> const& y,
0108                        std::vector<float> const& z,
0109                        std::vector<unsigned int> const& detId,
0110                        std::vector<unsigned int> const& idxInNtuple);
0111     void addPixelSegmentToEvent(std::vector<unsigned int> const& hitIndices0,
0112                                 std::vector<unsigned int> const& hitIndices1,
0113                                 std::vector<unsigned int> const& hitIndices2,
0114                                 std::vector<unsigned int> const& hitIndices3,
0115                                 std::vector<float> const& dPhiChange,
0116                                 std::vector<float> const& ptIn,
0117                                 std::vector<float> const& ptErr,
0118                                 std::vector<float> const& px,
0119                                 std::vector<float> const& py,
0120                                 std::vector<float> const& pz,
0121                                 std::vector<float> const& eta,
0122                                 std::vector<float> const& etaErr,
0123                                 std::vector<float> const& phi,
0124                                 std::vector<int> const& charge,
0125                                 std::vector<unsigned int> const& seedIdx,
0126                                 std::vector<int> const& superbin,
0127                                 std::vector<PixelType> const& pixelType,
0128                                 std::vector<char> const& isQuad);
0129 
0130     void createMiniDoublets();
0131     void createSegmentsWithModuleMap();
0132     void createTriplets();
0133     void createTrackCandidates(bool no_pls_dupclean, bool tc_pls_triplets);
0134     void createPixelTriplets();
0135     void createQuintuplets();
0136     void pixelLineSegmentCleaning(bool no_pls_dupclean);
0137     void createPixelQuintuplets();
0138 
0139     // functions that map the objects to the appropriate modules
0140     void addMiniDoubletsToEventExplicit();
0141     void addSegmentsToEventExplicit();
0142     void addQuintupletsToEventExplicit();
0143     void addTripletsToEventExplicit();
0144     void resetObjectsInModule();
0145 
0146     unsigned int getNumberOfMiniDoublets();
0147     unsigned int getNumberOfMiniDoubletsByLayerBarrel(unsigned int layer);
0148     unsigned int getNumberOfMiniDoubletsByLayerEndcap(unsigned int layer);
0149 
0150     unsigned int getNumberOfSegments();
0151     unsigned int getNumberOfSegmentsByLayerBarrel(unsigned int layer);
0152     unsigned int getNumberOfSegmentsByLayerEndcap(unsigned int layer);
0153 
0154     unsigned int getNumberOfTriplets();
0155     unsigned int getNumberOfTripletsByLayerBarrel(unsigned int layer);
0156     unsigned int getNumberOfTripletsByLayerEndcap(unsigned int layer);
0157 
0158     int getNumberOfPixelTriplets();
0159     int getNumberOfPixelQuintuplets();
0160 
0161     unsigned int getNumberOfQuintuplets();
0162     unsigned int getNumberOfQuintupletsByLayerBarrel(unsigned int layer);
0163     unsigned int getNumberOfQuintupletsByLayerEndcap(unsigned int layer);
0164 
0165     int getNumberOfTrackCandidates();
0166     int getNumberOfPT5TrackCandidates();
0167     int getNumberOfPT3TrackCandidates();
0168     int getNumberOfPLSTrackCandidates();
0169     int getNumberOfPixelTrackCandidates();
0170     int getNumberOfT5TrackCandidates();
0171 
0172     // sync adds alpaka::wait at the end of filling a buffer during lazy fill
0173     // (has no effect on repeated calls)
0174     // set to false may allow faster operation with concurrent calls of get*
0175     // HANDLE WITH CARE
0176     template <typename TSoA, typename TDev = Device>
0177     typename TSoA::ConstView getHits(bool inCMSSW = false, bool sync = true);
0178     template <typename TDev = Device>
0179     ObjectRangesConst getRanges(bool sync = true);
0180     template <typename TSoA, typename TDev = Device>
0181     typename TSoA::ConstView getMiniDoublets(bool sync = true);
0182     template <typename TSoA, typename TDev = Device>
0183     typename TSoA::ConstView getSegments(bool sync = true);
0184     template <typename TSoA, typename TDev = Device>
0185     typename TSoA::ConstView getTriplets(bool sync = true);
0186     template <typename TSoA, typename TDev = Device>
0187     typename TSoA::ConstView getQuintuplets(bool sync = true);
0188     template <typename TDev = Device>
0189     PixelTripletsConst getPixelTriplets(bool sync = true);
0190     template <typename TDev = Device>
0191     PixelQuintupletsConst getPixelQuintuplets(bool sync = true);
0192     const TrackCandidatesConst& getTrackCandidates(bool inCMSSW = false, bool sync = true);
0193     template <typename TSoA, typename TDev = Device>
0194     typename TSoA::ConstView getModules(bool sync = true);
0195   };
0196 
0197 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE::lst
0198 #endif