From 3177a24e86052349915b7b9e930d6cdadb245d27 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Wed, 8 May 2024 13:28:15 -0700 Subject: [PATCH 01/23] Started removing globals --- SDL/Event.cc | 254 ++++++++++++++++++++++---------------------- SDL/Event.h | 11 +- SDL/LST.cc | 104 +++++++++--------- SDL/ModuleMethods.h | 19 ++-- 4 files changed, 197 insertions(+), 191 deletions(-) diff --git a/SDL/Event.cc b/SDL/Event.cc index 54aea9b3..34316d10 100644 --- a/SDL/Event.cc +++ b/SDL/Event.cc @@ -1,5 +1,4 @@ #include "Event.h" -#include "Globals.h" void SDL::Event::init(bool verbose) { addObjects = verbose; @@ -149,21 +148,18 @@ void SDL::Event::resetEvent() { } } -void SDL::Event::initModules(QueueAcc& queue, - const MapPLStoLayer& pLStoLayer, - const char* moduleMetaDataFilePath) { - // nModules gets filled here - loadModulesFromFile(Globals::modulesBuffers, - Globals::nModules, - Globals::nLowerModules, - *Globals::pixelMapping, - queue, - moduleMetaDataFilePath, - pLStoLayer); - - // hand over to the const access ("ES") - Globals::modulesBuffersES = Globals::modulesBuffers; -} +// void SDL::Event::initModules(QueueAcc& queue, +// const MapPLStoLayer& pLStoLayer, +// const char* moduleMetaDataFilePath) { +// // nModules gets filled here +// loadModulesFromFile(modulesBuffers, +// nModules, +// nLowerModules, +// *pixelMapping, +// queue, +// moduleMetaDataFilePath, +// pLStoLayer); +// } void SDL::Event::addHitToEvent(std::vector x, std::vector y, @@ -176,14 +172,14 @@ void SDL::Event::addHitToEvent(std::vector x, // Initialize space on device/host for next event. if (hitsInGPU == nullptr) { hitsInGPU = new SDL::hits(); - hitsBuffers = new SDL::hitsBuffer(Globals::nModules, nHits, devAcc, queue); + hitsBuffers = new SDL::hitsBuffer(nModules, nHits, devAcc, queue); hitsInGPU->setData(*hitsBuffers); } if (rangesInGPU == nullptr) { rangesInGPU = new SDL::objectRanges(); rangesBuffers = - new SDL::objectRangesBuffer(Globals::nModules, Globals::nLowerModules, devAcc, queue); + new SDL::objectRangesBuffer(nModules, nLowerModules, devAcc, queue); rangesInGPU->setData(*rangesBuffers); } @@ -209,11 +205,11 @@ void SDL::Event::addHitToEvent(std::vector x, hit_loop_kernel, Endcap, TwoS, - Globals::nModules, - SDL::Globals::endcapGeometry->nEndCapMap, - alpaka::getPtrNative(SDL::Globals::endcapGeometry->geoMapDetId_buf), - alpaka::getPtrNative(SDL::Globals::endcapGeometry->geoMapPhi_buf), - *Globals::modulesBuffersES->data(), + nModules, + endcapGeometry->nEndCapMap, + alpaka::getPtrNative(endcapGeometry->geoMapDetId_buf), + alpaka::getPtrNative(endcapGeometry->geoMapPhi_buf), + *modulesBuffers->data(), *hitsInGPU, nHits)); @@ -226,9 +222,9 @@ void SDL::Event::addHitToEvent(std::vector x, moduleRangesKernel module_ranges_kernel; auto const module_ranges_task(alpaka::createTaskKernel(module_ranges_workdiv, module_ranges_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *hitsInGPU, - Globals::nLowerModules)); + nLowerModules)); // Waiting isn't needed after second kernel call. Saves ~100 us. // This is because addPixelSegmentToEvent (which is run next) doesn't rely on hitsBuffers->hitrange variables. @@ -266,12 +262,12 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI } unsigned int mdSize = 2 * size; - uint16_t pixelModuleIndex = Globals::pixelMapping->pixelModuleIndex; + uint16_t pixelModuleIndex = pixelMapping->pixelModuleIndex; if (mdsInGPU == nullptr) { // Create a view for the element nLowerModules inside rangesBuffers->miniDoubletModuleOccupancy auto dst_view_miniDoubletModuleOccupancy = alpaka::createSubView( - rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)Globals::nLowerModules); + rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules); // Create a source view for the value to be set int value = N_MAX_PIXEL_MD_PER_MODULES; @@ -288,7 +284,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI SDL::createMDArrayRangesGPU createMDArrayRangesGPU_kernel; auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel(createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *rangesInGPU)); alpaka::enqueue(queue, createMDArrayRangesGPUTask); @@ -303,7 +299,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI nTotalMDs += N_MAX_PIXEL_MD_PER_MODULES; mdsInGPU = new SDL::miniDoublets(); - miniDoubletsBuffers = new SDL::miniDoubletsBuffer(nTotalMDs, Globals::nLowerModules, devAcc, queue); + miniDoubletsBuffers = new SDL::miniDoubletsBuffer(nTotalMDs, nLowerModules, devAcc, queue); mdsInGPU->setData(*miniDoubletsBuffers); alpaka::memcpy(queue, miniDoubletsBuffers->nMemoryLocations_buf, nTotalMDs_view); @@ -321,7 +317,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI SDL::createSegmentArrayRanges createSegmentArrayRanges_kernel; auto const createSegmentArrayRangesTask(alpaka::createTaskKernel(createSegmentArrayRanges_workDiv, createSegmentArrayRanges_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *rangesInGPU, *mdsInGPU)); @@ -337,7 +333,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI segmentsInGPU = new SDL::segments(); segmentsBuffers = new SDL::segmentsBuffer( - nTotalSegments, Globals::nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); + nTotalSegments, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); segmentsInGPU->setData(*segmentsBuffers); alpaka::memcpy(queue, segmentsBuffers->nMemoryLocations_buf, nTotalSegments_view); @@ -397,7 +393,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI addPixelSegmentToEventKernel addPixelSegmentToEvent_kernel; auto const addPixelSegmentToEvent_task(alpaka::createTaskKernel(addPixelSegmentToEvent_workdiv, addPixelSegmentToEvent_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *rangesInGPU, *hitsInGPU, *mdsInGPU, @@ -417,7 +413,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI void SDL::Event::createMiniDoublets() { // Create a view for the element nLowerModules inside rangesBuffers->miniDoubletModuleOccupancy auto dst_view_miniDoubletModuleOccupancy = alpaka::createSubView( - rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)Globals::nLowerModules); + rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules); // Create a source view for the value to be set int value = N_MAX_PIXEL_MD_PER_MODULES; @@ -434,7 +430,7 @@ void SDL::Event::createMiniDoublets() { SDL::createMDArrayRangesGPU createMDArrayRangesGPU_kernel; auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel(createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *rangesInGPU)); alpaka::enqueue(queue, createMDArrayRangesGPUTask); @@ -451,20 +447,20 @@ void SDL::Event::createMiniDoublets() { if (mdsInGPU == nullptr) { mdsInGPU = new SDL::miniDoublets(); - miniDoubletsBuffers = new SDL::miniDoubletsBuffer(nTotalMDs, Globals::nLowerModules, devAcc, queue); + miniDoubletsBuffers = new SDL::miniDoubletsBuffer(nTotalMDs, nLowerModules, devAcc, queue); mdsInGPU->setData(*miniDoubletsBuffers); } Vec const threadsPerBlockCreateMDInGPU = createVec(1, 16, 32); Vec const blocksPerGridCreateMDInGPU = - createVec(1, Globals::nLowerModules / threadsPerBlockCreateMDInGPU[1], 1); + createVec(1, nLowerModules / threadsPerBlockCreateMDInGPU[1], 1); WorkDiv const createMiniDoubletsInGPUv2_workDiv = createWorkDiv(blocksPerGridCreateMDInGPU, threadsPerBlockCreateMDInGPU, elementsPerThread); SDL::createMiniDoubletsInGPUv2 createMiniDoubletsInGPUv2_kernel; auto const createMiniDoubletsInGPUv2Task(alpaka::createTaskKernel(createMiniDoubletsInGPUv2_workDiv, createMiniDoubletsInGPUv2_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *hitsInGPU, *mdsInGPU, *rangesInGPU)); @@ -480,7 +476,7 @@ void SDL::Event::createMiniDoublets() { auto const addMiniDoubletRangesToEventExplicitTask( alpaka::createTaskKernel(addMiniDoubletRangesToEventExplicit_workDiv, addMiniDoubletRangesToEventExplicit_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *mdsInGPU, *rangesInGPU, *hitsInGPU)); @@ -497,19 +493,19 @@ void SDL::Event::createSegmentsWithModuleMap() { if (segmentsInGPU == nullptr) { segmentsInGPU = new SDL::segments(); segmentsBuffers = new SDL::segmentsBuffer( - nTotalSegments, Globals::nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); + nTotalSegments, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); segmentsInGPU->setData(*segmentsBuffers); } Vec const threadsPerBlockCreateSeg = createVec(1, 1, 64); - Vec const blocksPerGridCreateSeg = createVec(1, 1, Globals::nLowerModules); + Vec const blocksPerGridCreateSeg = createVec(1, 1, nLowerModules); WorkDiv const createSegmentsInGPUv2_workDiv = createWorkDiv(blocksPerGridCreateSeg, threadsPerBlockCreateSeg, elementsPerThread); SDL::createSegmentsInGPUv2 createSegmentsInGPUv2_kernel; auto const createSegmentsInGPUv2Task(alpaka::createTaskKernel(createSegmentsInGPUv2_workDiv, createSegmentsInGPUv2_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *mdsInGPU, *segmentsInGPU, *rangesInGPU)); @@ -525,7 +521,7 @@ void SDL::Event::createSegmentsWithModuleMap() { auto const addSegmentRangesToEventExplicitTask( alpaka::createTaskKernel(addSegmentRangesToEventExplicit_workDiv, addSegmentRangesToEventExplicit_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *segmentsInGPU, *rangesInGPU)); @@ -547,7 +543,7 @@ void SDL::Event::createTriplets() { SDL::createTripletArrayRanges createTripletArrayRanges_kernel; auto const createTripletArrayRangesTask(alpaka::createTaskKernel(createTripletArrayRanges_workDiv, createTripletArrayRanges_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *rangesInGPU, *segmentsInGPU)); @@ -562,7 +558,7 @@ void SDL::Event::createTriplets() { tripletsInGPU = new SDL::triplets(); tripletsBuffers = new SDL::tripletsBuffer( - *alpaka::getPtrNative(maxTriplets_buf), Globals::nLowerModules, devAcc, queue); + *alpaka::getPtrNative(maxTriplets_buf), nLowerModules, devAcc, queue); tripletsInGPU->setData(*tripletsBuffers); alpaka::memcpy(queue, tripletsBuffers->nMemoryLocations_buf, maxTriplets_buf); @@ -573,30 +569,30 @@ void SDL::Event::createTriplets() { unsigned int max_InnerSeg = 0; // Allocate host index - auto index_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto index_buf = allocBufWrapper(devHost, nLowerModules, queue); uint16_t* index = alpaka::getPtrNative(index_buf); // Allocate device index - auto index_gpu_buf = allocBufWrapper(devAcc, Globals::nLowerModules, queue); + auto index_gpu_buf = allocBufWrapper(devAcc, nLowerModules, queue); // Allocate and copy nSegments from device to host - auto nSegments_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); - alpaka::memcpy(queue, nSegments_buf, segmentsBuffers->nSegments_buf, Globals::nLowerModules); + auto nSegments_buf = allocBufWrapper(devHost, nLowerModules, queue); + alpaka::memcpy(queue, nSegments_buf, segmentsBuffers->nSegments_buf, nLowerModules); alpaka::wait(queue); unsigned int* nSegments = alpaka::getPtrNative(nSegments_buf); // Allocate and copy module_nConnectedModules from device to host - auto module_nConnectedModules_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto module_nConnectedModules_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy(queue, module_nConnectedModules_buf, - Globals::modulesBuffersES->nConnectedModules_buf, - Globals::nLowerModules); + modulesBuffers->nConnectedModules_buf, + nLowerModules); alpaka::wait(queue); uint16_t* module_nConnectedModules = alpaka::getPtrNative(module_nConnectedModules_buf); - for (uint16_t innerLowerModuleIndex = 0; innerLowerModuleIndex < Globals::nLowerModules; + for (uint16_t innerLowerModuleIndex = 0; innerLowerModuleIndex < nLowerModules; innerLowerModuleIndex++) { uint16_t nConnectedModules = module_nConnectedModules[innerLowerModuleIndex]; unsigned int nInnerSegments = nSegments[innerLowerModuleIndex]; @@ -619,7 +615,7 @@ void SDL::Event::createTriplets() { SDL::createTripletsInGPUv2 createTripletsInGPUv2_kernel; auto const createTripletsInGPUv2Task(alpaka::createTaskKernel(createTripletsInGPUv2_workDiv, createTripletsInGPUv2_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *mdsInGPU, *segmentsInGPU, *tripletsInGPU, @@ -638,7 +634,7 @@ void SDL::Event::createTriplets() { auto const addTripletRangesToEventExplicitTask( alpaka::createTaskKernel(addTripletRangesToEventExplicit_workDiv, addTripletRangesToEventExplicit_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *tripletsInGPU, *rangesInGPU)); @@ -672,7 +668,7 @@ void SDL::Event::createTrackCandidates() { SDL::crossCleanpT3 crossCleanpT3_kernel; auto const crossCleanpT3Task(alpaka::createTaskKernel(crossCleanpT3_workDiv, crossCleanpT3_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *rangesInGPU, *pixelTripletsInGPU, *segmentsInGPU, @@ -688,7 +684,7 @@ void SDL::Event::createTrackCandidates() { SDL::addpT3asTrackCandidatesInGPU addpT3asTrackCandidatesInGPU_kernel; auto const addpT3asTrackCandidatesInGPUTask(alpaka::createTaskKernel(addpT3asTrackCandidatesInGPU_workDiv, addpT3asTrackCandidatesInGPU_kernel, - Globals::nLowerModules, + nLowerModules, *pixelTripletsInGPU, *trackCandidatesInGPU, *segmentsInGPU, @@ -719,7 +715,7 @@ void SDL::Event::createTrackCandidates() { SDL::crossCleanT5 crossCleanT5_kernel; auto const crossCleanT5Task(alpaka::createTaskKernel(crossCleanT5_workDiv, crossCleanT5_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *quintupletsInGPU, *pixelQuintupletsInGPU, *pixelTripletsInGPU, @@ -735,7 +731,7 @@ void SDL::Event::createTrackCandidates() { SDL::addT5asTrackCandidateInGPU addT5asTrackCandidateInGPU_kernel; auto const addT5asTrackCandidateInGPUTask(alpaka::createTaskKernel(addT5asTrackCandidateInGPU_workDiv, addT5asTrackCandidateInGPU_kernel, - Globals::nLowerModules, + nLowerModules, *quintupletsInGPU, *trackCandidatesInGPU, *rangesInGPU)); @@ -750,7 +746,7 @@ void SDL::Event::createTrackCandidates() { SDL::checkHitspLS checkHitspLS_kernel; auto const checkHitspLSTask(alpaka::createTaskKernel( - checkHitspLS_workDiv, checkHitspLS_kernel, *Globals::modulesBuffersES->data(), *segmentsInGPU, true)); + checkHitspLS_workDiv, checkHitspLS_kernel, *modulesBuffers->data(), *segmentsInGPU, true)); alpaka::enqueue(queue, checkHitspLSTask); #endif @@ -763,7 +759,7 @@ void SDL::Event::createTrackCandidates() { SDL::crossCleanpLS crossCleanpLS_kernel; auto const crossCleanpLSTask(alpaka::createTaskKernel(crossCleanpLS_workDiv, crossCleanpLS_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *rangesInGPU, *pixelTripletsInGPU, *trackCandidatesInGPU, @@ -782,7 +778,7 @@ void SDL::Event::createTrackCandidates() { SDL::addpLSasTrackCandidateInGPU addpLSasTrackCandidateInGPU_kernel; auto const addpLSasTrackCandidateInGPUTask(alpaka::createTaskKernel(addpLSasTrackCandidateInGPU_workDiv, addpLSasTrackCandidateInGPU_kernel, - Globals::nLowerModules, + nLowerModules, *trackCandidatesInGPU, *segmentsInGPU)); @@ -825,7 +821,7 @@ void SDL::Event::createPixelTriplets() { auto nInnerSegments_src_view = alpaka::createView(devHost, &nInnerSegments, (size_t)1u); auto dev_view_nSegments = - alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)Globals::nLowerModules); + alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules); alpaka::memcpy(queue, nInnerSegments_src_view, dev_view_nSegments); alpaka::wait(queue); @@ -848,10 +844,10 @@ void SDL::Event::createPixelTriplets() { unsigned int* connectedPixelIndex_host = alpaka::getPtrNative(connectedPixelIndex_host_buf); alpaka::wait(queue); - int pixelIndexOffsetPos = Globals::pixelMapping->connectedPixelsIndex[size_superbins - 1] + - Globals::pixelMapping->connectedPixelsSizes[size_superbins - 1]; - int pixelIndexOffsetNeg = Globals::pixelMapping->connectedPixelsIndexPos[size_superbins - 1] + - Globals::pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + + int pixelIndexOffsetPos = pixelMapping->connectedPixelsIndex[size_superbins - 1] + + pixelMapping->connectedPixelsSizes[size_superbins - 1]; + int pixelIndexOffsetNeg = pixelMapping->connectedPixelsIndexPos[size_superbins - 1] + + pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos; // TODO: check if a map/reduction to just eligible pLSs would speed up the kernel @@ -868,19 +864,19 @@ void SDL::Event::createPixelTriplets() { // Used pixel type to select correct size-index arrays if (pixelType == 0) { connectedPixelSize_host[i] = - Globals::pixelMapping->connectedPixelsSizes[superbin]; // number of connected modules to this pixel - auto connectedIdxBase = Globals::pixelMapping->connectedPixelsIndex[superbin]; + pixelMapping->connectedPixelsSizes[superbin]; // number of connected modules to this pixel + auto connectedIdxBase = pixelMapping->connectedPixelsIndex[superbin]; connectedPixelIndex_host[i] = connectedIdxBase; // index to get start of connected modules for this superbin in map } else if (pixelType == 1) { connectedPixelSize_host[i] = - Globals::pixelMapping->connectedPixelsSizesPos[superbin]; // number of pixel connected modules - auto connectedIdxBase = Globals::pixelMapping->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; + pixelMapping->connectedPixelsSizesPos[superbin]; // number of pixel connected modules + auto connectedIdxBase = pixelMapping->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; connectedPixelIndex_host[i] = connectedIdxBase; // index to get start of connected pixel modules } else if (pixelType == 2) { connectedPixelSize_host[i] = - Globals::pixelMapping->connectedPixelsSizesNeg[superbin]; // number of pixel connected modules - auto connectedIdxBase = Globals::pixelMapping->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; + pixelMapping->connectedPixelsSizesNeg[superbin]; // number of pixel connected modules + auto connectedIdxBase = pixelMapping->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; connectedPixelIndex_host[i] = connectedIdxBase; // index to get start of connected pixel modules } } @@ -898,7 +894,7 @@ void SDL::Event::createPixelTriplets() { auto const createPixelTripletsInGPUFromMapv2Task( alpaka::createTaskKernel(createPixelTripletsInGPUFromMapv2_workDiv, createPixelTripletsInGPUFromMapv2_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *rangesInGPU, *mdsInGPU, *segmentsInGPU, @@ -945,7 +941,7 @@ void SDL::Event::createQuintuplets() { auto const createEligibleModulesListForQuintupletsGPUTask( alpaka::createTaskKernel(createEligibleModulesListForQuintupletsGPU_workDiv, createEligibleModulesListForQuintupletsGPU_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *tripletsInGPU, *rangesInGPU)); @@ -965,7 +961,7 @@ void SDL::Event::createQuintuplets() { if (quintupletsInGPU == nullptr) { quintupletsInGPU = new SDL::quintuplets(); quintupletsBuffers = - new SDL::quintupletsBuffer(nTotalQuintuplets, Globals::nLowerModules, devAcc, queue); + new SDL::quintupletsBuffer(nTotalQuintuplets, nLowerModules, devAcc, queue); quintupletsInGPU->setData(*quintupletsBuffers); alpaka::memcpy(queue, quintupletsBuffers->nMemoryLocations_buf, nTotalQuintuplets_buf); @@ -980,7 +976,7 @@ void SDL::Event::createQuintuplets() { SDL::createQuintupletsInGPUv2 createQuintupletsInGPUv2_kernel; auto const createQuintupletsInGPUv2Task(alpaka::createTaskKernel(createQuintupletsInGPUv2_workDiv, createQuintupletsInGPUv2_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *mdsInGPU, *segmentsInGPU, *tripletsInGPU, @@ -999,7 +995,7 @@ void SDL::Event::createQuintuplets() { auto const removeDupQuintupletsInGPUAfterBuildTask( alpaka::createTaskKernel(removeDupQuintupletsInGPUAfterBuild_workDiv, removeDupQuintupletsInGPUAfterBuild_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *quintupletsInGPU, *rangesInGPU)); @@ -1014,7 +1010,7 @@ void SDL::Event::createQuintuplets() { auto const addQuintupletRangesToEventExplicitTask( alpaka::createTaskKernel(addQuintupletRangesToEventExplicit_workDiv, addQuintupletRangesToEventExplicit_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *quintupletsInGPU, *rangesInGPU)); @@ -1035,7 +1031,7 @@ void SDL::Event::pixelLineSegmentCleaning() { SDL::checkHitspLS checkHitspLS_kernel; auto const checkHitspLSTask(alpaka::createTaskKernel( - checkHitspLS_workDiv, checkHitspLS_kernel, *Globals::modulesBuffersES->data(), *segmentsInGPU, false)); + checkHitspLS_workDiv, checkHitspLS_kernel, *modulesBuffers->data(), *segmentsInGPU, false)); alpaka::enqueue(queue, checkHitspLSTask); alpaka::wait(queue); @@ -1060,7 +1056,7 @@ void SDL::Event::createPixelQuintuplets() { // Create a sub-view for the device buffer auto dev_view_nSegments = - alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)Globals::nLowerModules); + alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules); alpaka::memcpy(queue, nInnerSegments_src_view, dev_view_nSegments); alpaka::wait(queue); @@ -1083,10 +1079,10 @@ void SDL::Event::createPixelQuintuplets() { unsigned int* connectedPixelIndex_host = alpaka::getPtrNative(connectedPixelIndex_host_buf); alpaka::wait(queue); - int pixelIndexOffsetPos = Globals::pixelMapping->connectedPixelsIndex[size_superbins - 1] + - Globals::pixelMapping->connectedPixelsSizes[size_superbins - 1]; - int pixelIndexOffsetNeg = Globals::pixelMapping->connectedPixelsIndexPos[size_superbins - 1] + - Globals::pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + + int pixelIndexOffsetPos = pixelMapping->connectedPixelsIndex[size_superbins - 1] + + pixelMapping->connectedPixelsSizes[size_superbins - 1]; + int pixelIndexOffsetNeg = pixelMapping->connectedPixelsIndexPos[size_superbins - 1] + + pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos; // Loop over # pLS @@ -1101,20 +1097,20 @@ void SDL::Event::createPixelQuintuplets() { // Used pixel type to select correct size-index arrays if (pixelType == 0) { connectedPixelSize_host[i] = - Globals::pixelMapping->connectedPixelsSizes[superbin]; //number of connected modules to this pixel - unsigned int connectedIdxBase = Globals::pixelMapping->connectedPixelsIndex[superbin]; + pixelMapping->connectedPixelsSizes[superbin]; //number of connected modules to this pixel + unsigned int connectedIdxBase = pixelMapping->connectedPixelsIndex[superbin]; connectedPixelIndex_host[i] = connectedIdxBase; } else if (pixelType == 1) { connectedPixelSize_host[i] = - Globals::pixelMapping->connectedPixelsSizesPos[superbin]; //number of pixel connected modules + pixelMapping->connectedPixelsSizesPos[superbin]; //number of pixel connected modules unsigned int connectedIdxBase = - Globals::pixelMapping->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; + pixelMapping->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; connectedPixelIndex_host[i] = connectedIdxBase; } else if (pixelType == 2) { connectedPixelSize_host[i] = - Globals::pixelMapping->connectedPixelsSizesNeg[superbin]; //number of pixel connected modules + pixelMapping->connectedPixelsSizesNeg[superbin]; //number of pixel connected modules unsigned int connectedIdxBase = - Globals::pixelMapping->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; + pixelMapping->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; connectedPixelIndex_host[i] = connectedIdxBase; } } @@ -1132,7 +1128,7 @@ void SDL::Event::createPixelQuintuplets() { auto const createPixelQuintupletsInGPUFromMapv2Task( alpaka::createTaskKernel(createPixelQuintupletsInGPUFromMapv2_workDiv, createPixelQuintupletsInGPUFromMapv2_kernel, - *Globals::modulesBuffersES->data(), + *modulesBuffers->data(), *mdsInGPU, *segmentsInGPU, *tripletsInGPU, @@ -1166,7 +1162,7 @@ void SDL::Event::createPixelQuintuplets() { SDL::addpT5asTrackCandidateInGPU addpT5asTrackCandidateInGPU_kernel; auto const addpT5asTrackCandidateInGPUTask(alpaka::createTaskKernel(addpT5asTrackCandidateInGPU_workDiv, addpT5asTrackCandidateInGPU_kernel, - Globals::nLowerModules, + nLowerModules, *pixelQuintupletsInGPU, *trackCandidatesInGPU, *segmentsInGPU, @@ -1186,19 +1182,19 @@ void SDL::Event::createPixelQuintuplets() { } void SDL::Event::addMiniDoubletsToEventExplicit() { - auto nMDsCPU_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); - alpaka::memcpy(queue, nMDsCPU_buf, miniDoubletsBuffers->nMDs_buf, Globals::nLowerModules); + auto nMDsCPU_buf = allocBufWrapper(devHost, nLowerModules, queue); + alpaka::memcpy(queue, nMDsCPU_buf, miniDoubletsBuffers->nMDs_buf, nLowerModules); - auto module_subdets_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy( - queue, module_subdets_buf, Globals::modulesBuffersES->subdets_buf, Globals::nLowerModules); + queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); - auto module_layers_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy( - queue, module_layers_buf, Globals::modulesBuffersES->layers_buf, Globals::nLowerModules); + queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); - auto module_hitRanges_buf = allocBufWrapper(devHost, Globals::nLowerModules * 2, queue); - alpaka::memcpy(queue, module_hitRanges_buf, hitsBuffers->hitRanges_buf, Globals::nLowerModules * 2u); + auto module_hitRanges_buf = allocBufWrapper(devHost, nLowerModules * 2, queue); + alpaka::memcpy(queue, module_hitRanges_buf, hitsBuffers->hitRanges_buf, nLowerModules * 2u); alpaka::wait(queue); @@ -1207,7 +1203,7 @@ void SDL::Event::addMiniDoubletsToEventExplicit() { short* module_layers = alpaka::getPtrNative(module_layers_buf); int* module_hitRanges = alpaka::getPtrNative(module_hitRanges_buf); - for (unsigned int i = 0; i < Globals::nLowerModules; i++) { + for (unsigned int i = 0; i < nLowerModules; i++) { if (!(nMDsCPU[i] == 0 or module_hitRanges[i * 2] == -1)) { if (module_subdets[i] == Barrel) { n_minidoublets_by_layer_barrel_[module_layers[i] - 1] += nMDsCPU[i]; @@ -1219,16 +1215,16 @@ void SDL::Event::addMiniDoubletsToEventExplicit() { } void SDL::Event::addSegmentsToEventExplicit() { - auto nSegmentsCPU_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); - alpaka::memcpy(queue, nSegmentsCPU_buf, segmentsBuffers->nSegments_buf, Globals::nLowerModules); + auto nSegmentsCPU_buf = allocBufWrapper(devHost, nLowerModules, queue); + alpaka::memcpy(queue, nSegmentsCPU_buf, segmentsBuffers->nSegments_buf, nLowerModules); - auto module_subdets_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy( - queue, module_subdets_buf, Globals::modulesBuffersES->subdets_buf, Globals::nLowerModules); + queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); - auto module_layers_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy( - queue, module_layers_buf, Globals::modulesBuffersES->layers_buf, Globals::nLowerModules); + queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); alpaka::wait(queue); @@ -1236,7 +1232,7 @@ void SDL::Event::addSegmentsToEventExplicit() { short* module_subdets = alpaka::getPtrNative(module_subdets_buf); short* module_layers = alpaka::getPtrNative(module_layers_buf); - for (unsigned int i = 0; i < Globals::nLowerModules; i++) { + for (unsigned int i = 0; i < nLowerModules; i++) { if (!(nSegmentsCPU[i] == 0)) { if (module_subdets[i] == Barrel) { n_segments_by_layer_barrel_[module_layers[i] - 1] += nSegmentsCPU[i]; @@ -1248,18 +1244,18 @@ void SDL::Event::addSegmentsToEventExplicit() { } void SDL::Event::addQuintupletsToEventExplicit() { - auto nQuintupletsCPU_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto nQuintupletsCPU_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy(queue, nQuintupletsCPU_buf, quintupletsBuffers->nQuintuplets_buf); - auto module_subdets_buf = allocBufWrapper(devHost, Globals::nModules, queue); + auto module_subdets_buf = allocBufWrapper(devHost, nModules, queue); alpaka::memcpy( - queue, module_subdets_buf, Globals::modulesBuffersES->subdets_buf, Globals::nModules); + queue, module_subdets_buf, modulesBuffers->subdets_buf, nModules); - auto module_layers_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy( - queue, module_layers_buf, Globals::modulesBuffersES->layers_buf, Globals::nLowerModules); + queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); - auto module_quintupletModuleIndices_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto module_quintupletModuleIndices_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy(queue, module_quintupletModuleIndices_buf, rangesBuffers->quintupletModuleIndices_buf); alpaka::wait(queue); @@ -1269,7 +1265,7 @@ void SDL::Event::addQuintupletsToEventExplicit() { short* module_layers = alpaka::getPtrNative(module_layers_buf); int* module_quintupletModuleIndices = alpaka::getPtrNative(module_quintupletModuleIndices_buf); - for (uint16_t i = 0; i < Globals::nLowerModules; i++) { + for (uint16_t i = 0; i < nLowerModules; i++) { if (!(nQuintupletsCPU[i] == 0 or module_quintupletModuleIndices[i] == -1)) { if (module_subdets[i] == Barrel) { n_quintuplets_by_layer_barrel_[module_layers[i] - 1] += nQuintupletsCPU[i]; @@ -1281,23 +1277,23 @@ void SDL::Event::addQuintupletsToEventExplicit() { } void SDL::Event::addTripletsToEventExplicit() { - auto nTripletsCPU_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto nTripletsCPU_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy(queue, nTripletsCPU_buf, tripletsBuffers->nTriplets_buf); - auto module_subdets_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy( - queue, module_subdets_buf, Globals::modulesBuffersES->subdets_buf, Globals::nLowerModules); + queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); - auto module_layers_buf = allocBufWrapper(devHost, Globals::nLowerModules, queue); + auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy( - queue, module_layers_buf, Globals::modulesBuffersES->layers_buf, Globals::nLowerModules); + queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); alpaka::wait(queue); unsigned int* nTripletsCPU = alpaka::getPtrNative(nTripletsCPU_buf); short* module_subdets = alpaka::getPtrNative(module_subdets_buf); short* module_layers = alpaka::getPtrNative(module_layers_buf); - for (uint16_t i = 0; i < Globals::nLowerModules; i++) { + for (uint16_t i = 0; i < nLowerModules; i++) { if (nTripletsCPU[i] != 0) { if (module_subdets[i] == Barrel) { n_triplets_by_layer_barrel_[module_layers[i] - 1] += nTripletsCPU[i]; @@ -1542,7 +1538,7 @@ SDL::hitsBuffer* SDL::Event::getHits() //std::shared_ alpaka::wait(queue); unsigned int nHits = *alpaka::getPtrNative(nHits_buf); - hitsInCPU = new SDL::hitsBuffer(Globals::nModules, nHits, devHost, queue); + hitsInCPU = new SDL::hitsBuffer(nModules, nHits, devHost, queue); hitsInCPU->setData(*hitsInCPU); *alpaka::getPtrNative(hitsInCPU->nHits_buf) = nHits; @@ -1564,7 +1560,7 @@ SDL::hitsBuffer* SDL::Event::getHitsInCMSSW() { alpaka::wait(queue); unsigned int nHits = *alpaka::getPtrNative(nHits_buf); - hitsInCPU = new SDL::hitsBuffer(Globals::nModules, nHits, devHost, queue); + hitsInCPU = new SDL::hitsBuffer(nModules, nHits, devHost, queue); hitsInCPU->setData(*hitsInCPU); *alpaka::getPtrNative(hitsInCPU->nHits_buf) = nHits; @@ -1577,7 +1573,7 @@ SDL::hitsBuffer* SDL::Event::getHitsInCMSSW() { SDL::objectRangesBuffer* SDL::Event::getRanges() { if (rangesInCPU == nullptr) { rangesInCPU = new SDL::objectRangesBuffer( - Globals::nModules, Globals::nLowerModules, devHost, queue); + nModules, nLowerModules, devHost, queue); rangesInCPU->setData(*rangesInCPU); alpaka::memcpy(queue, rangesInCPU->hitRanges_buf, rangesBuffers->hitRanges_buf); @@ -1598,7 +1594,7 @@ SDL::miniDoubletsBuffer* SDL::Event::getMiniDoublets() alpaka::wait(queue); unsigned int nMemHost = *alpaka::getPtrNative(nMemHost_buf); - mdsInCPU = new SDL::miniDoubletsBuffer(nMemHost, Globals::nLowerModules, devHost, queue); + mdsInCPU = new SDL::miniDoubletsBuffer(nMemHost, nLowerModules, devHost, queue); mdsInCPU->setData(*mdsInCPU); *alpaka::getPtrNative(mdsInCPU->nMemoryLocations_buf) = nMemHost; @@ -1621,7 +1617,7 @@ SDL::segmentsBuffer* SDL::Event::getSegments() { unsigned int nMemHost = *alpaka::getPtrNative(nMemHost_buf); segmentsInCPU = new SDL::segmentsBuffer( - nMemHost, Globals::nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devHost, queue); + nMemHost, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devHost, queue); segmentsInCPU->setData(*segmentsInCPU); *alpaka::getPtrNative(segmentsInCPU->nMemoryLocations_buf) = nMemHost; @@ -1656,7 +1652,7 @@ SDL::tripletsBuffer* SDL::Event::getTriplets() { alpaka::wait(queue); unsigned int nMemHost = *alpaka::getPtrNative(nMemHost_buf); - tripletsInCPU = new SDL::tripletsBuffer(nMemHost, Globals::nLowerModules, devHost, queue); + tripletsInCPU = new SDL::tripletsBuffer(nMemHost, nLowerModules, devHost, queue); tripletsInCPU->setData(*tripletsInCPU); *alpaka::getPtrNative(tripletsInCPU->nMemoryLocations_buf) = nMemHost; @@ -1691,7 +1687,7 @@ SDL::quintupletsBuffer* SDL::Event::getQuintuplets() { unsigned int nMemHost = *alpaka::getPtrNative(nMemHost_buf); quintupletsInCPU = - new SDL::quintupletsBuffer(nMemHost, Globals::nLowerModules, devHost, queue); + new SDL::quintupletsBuffer(nMemHost, nLowerModules, devHost, queue); quintupletsInCPU->setData(*quintupletsInCPU); *alpaka::getPtrNative(quintupletsInCPU->nMemoryLocations_buf) = nMemHost; @@ -1857,7 +1853,7 @@ SDL::modulesBuffer* SDL::Event::getModules(bool isFull // The last input here is just a small placeholder for the allocation. modulesInCPU = new SDL::modulesBuffer(devHost); - modulesInCPU->copyFromSrc(queue, *Globals::modulesBuffersES, isFull); + modulesInCPU->copyFromSrc(queue, *modulesBuffers, isFull); } return modulesInCPU; } diff --git a/SDL/Event.h b/SDL/Event.h index 7c799dcb..c4b1de6a 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -84,6 +84,15 @@ namespace SDL { int* superbinCPU; int8_t* pixelTypeCPU; + // Stuff that used to be global + std::shared_ptr> modulesBuffers; + std::shared_ptr pixelMapping; + std::shared_ptr> endcapGeometry; + std::shared_ptr> tiltedGeometry; + std::shared_ptr> moduleConnectionMap; + uint16_t nModules; + uint16_t nLowerModules; + public: // Constructor used for CMSSW integration. Uses an external queue. template @@ -185,7 +194,7 @@ namespace SDL { modulesBuffer* getModules(bool isFull = false); //read from file and init - static void initModules(QueueAcc& queue, const MapPLStoLayer& pLStoLayer, const char* moduleMetaDataFilePath); + //static void initModules(QueueAcc& queue, const MapPLStoLayer& pLStoLayer, const char* moduleMetaDataFilePath); }; } // namespace SDL diff --git a/SDL/LST.cc b/SDL/LST.cc index 776663ea..7fad02d8 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -5,7 +5,6 @@ #endif #include "Event.h" -#include "Globals.h" #include "Math/Vector3D.h" using XYZVector = ROOT::Math::XYZVector; @@ -34,67 +33,67 @@ namespace { return fullpath.string(); } - void loadMaps(SDL::Dev const& devAccIn, SDL::QueueAcc& queue, SDL::MapPLStoLayer& pLStoLayer) { - // Module orientation information (DrDz or phi angles) - auto endcap_geom = - get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); - auto tilted_geom = get_absolute_path_after_check_file_exists( - trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); - if (SDL::Globals::endcapGeometry == nullptr) { - SDL::Globals::endcapGeometry = - new SDL::EndcapGeometry(devAccIn, queue, endcap_geom); // centroid values added to the map - } + // void loadMaps(SDL::Dev const& devAccIn, SDL::QueueAcc& queue, SDL::MapPLStoLayer& pLStoLayer) { + // // Module orientation information (DrDz or phi angles) + // auto endcap_geom = + // get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); + // auto tilted_geom = get_absolute_path_after_check_file_exists( + // trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); + // if (SDL::Globals::endcapGeometry == nullptr) { + // SDL::Globals::endcapGeometry = + // new SDL::EndcapGeometry(devAccIn, queue, endcap_geom); // centroid values added to the map + // } - SDL::Globals::tiltedGeometry.load(tilted_geom); + // SDL::Globals::tiltedGeometry.load(tilted_geom); - // Module connection map (for line segment building) - auto mappath = get_absolute_path_after_check_file_exists( - trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); - SDL::Globals::moduleConnectionMap.load(mappath); + // // Module connection map (for line segment building) + // auto mappath = get_absolute_path_after_check_file_exists( + // trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); + // SDL::Globals::moduleConnectionMap.load(mappath); - auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map"; - const std::array connects{ - {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}}; - std::string path; + // auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map"; + // const std::array connects{ + // {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}}; + // std::string path; - static_assert(connects.size() == std::tuple_size>{}); - for (unsigned int i = 0; i < connects.size(); i++) { - auto connectData = connects[i].data(); + // static_assert(connects.size() == std::tuple_size>{}); + // for (unsigned int i = 0; i < connects.size(); i++) { + // auto connectData = connects[i].data(); - path = pLSMapDir + connectData + ".bin"; - pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + // path = pLSMapDir + connectData + ".bin"; + // pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - path = pLSMapDir + "_pos" + connectData + ".bin"; - pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + // path = pLSMapDir + "_pos" + connectData + ".bin"; + // pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - path = pLSMapDir + "_neg" + connectData + ".bin"; - pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - } - } + // path = pLSMapDir + "_neg" + connectData + ".bin"; + // pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + // } + // } } // namespace -void SDL::LST::loadAndFillES(SDL::QueueAcc& queue, struct modulesBuffer* modules) { - SDL::MapPLStoLayer pLStoLayer; - SDL::Dev const& devAccIn = alpaka::getDev(queue); - ::loadMaps(devAccIn, queue, pLStoLayer); - - auto path = - get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); - if (SDL::Globals::modulesBuffers == nullptr) { - SDL::Globals::modulesBuffers = new SDL::modulesBuffer(devAccIn); - } - if (SDL::Globals::pixelMapping == nullptr) { - SDL::Globals::pixelMapping = std::make_shared(); - } - SDL::loadModulesFromFile(modules, - SDL::Globals::nModules, - SDL::Globals::nLowerModules, - *SDL::Globals::pixelMapping, - queue, - path.c_str(), - pLStoLayer); -} +// void SDL::LST::loadAndFillES(SDL::QueueAcc& queue, struct modulesBuffer* modules) { +// SDL::MapPLStoLayer pLStoLayer; +// SDL::Dev const& devAccIn = alpaka::getDev(queue); +// ::loadMaps(devAccIn, queue, pLStoLayer); + +// auto path = +// get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); +// if (SDL::Globals::modulesBuffers == nullptr) { +// SDL::Globals::modulesBuffers = new SDL::modulesBuffer(devAccIn); +// } +// if (SDL::Globals::pixelMapping == nullptr) { +// SDL::Globals::pixelMapping = std::make_shared(); +// } +// SDL::loadModulesFromFile(modules, +// SDL::Globals::nModules, +// SDL::Globals::nLowerModules, +// *SDL::Globals::pixelMapping, +// queue, +// path.c_str(), +// pLStoLayer); +// } void SDL::LST::run(SDL::QueueAcc& queue, const SDL::modulesBuffer* modules, @@ -118,7 +117,6 @@ void SDL::LST::run(SDL::QueueAcc& queue, const std::vector ph2_x, const std::vector ph2_y, const std::vector ph2_z) { - SDL::Globals::modulesBuffersES = modules; auto event = SDL::Event(verbose, queue); prepareInput(see_px, see_py, diff --git a/SDL/ModuleMethods.h b/SDL/ModuleMethods.h index e7d781ec..162424c6 100644 --- a/SDL/ModuleMethods.h +++ b/SDL/ModuleMethods.h @@ -16,7 +16,6 @@ #include "EndcapGeometry.h" #include "ModuleConnectionMap.h" #include "PixelMap.h" -#include "Globals.h" #include "HeterogeneousCore/AlpakaInterface/interface/host.h" @@ -115,7 +114,8 @@ namespace SDL { inline void fillConnectedModuleArrayExplicit(struct modulesBuffer* modulesBuf, unsigned int nMod, TQueue queue, - struct ModuleMetaData& mmd) { + struct ModuleMetaData& mmd, + ModuleConnectionMap* moduleConnectionMap) { DevHost const& devHost = cms::alpakatools::host(); auto moduleMap_buf = allocBufWrapper(devHost, nMod * MAX_CONNECTED_MODULES); uint16_t* moduleMap = alpaka::getPtrNative(moduleMap_buf); @@ -126,7 +126,7 @@ namespace SDL { for (auto it = mmd.detIdToIndex.begin(); it != mmd.detIdToIndex.end(); ++it) { unsigned int detId = it->first; uint16_t index = it->second; - auto& connectedModules = Globals::moduleConnectionMap.getConnectedModuleDetIds(detId); + auto& connectedModules = moduleConnectionMap->getConnectedModuleDetIds(detId); nConnectedModules[index] = connectedModules.size(); for (uint16_t i = 0; i < nConnectedModules[index]; i++) { moduleMap[index * MAX_CONNECTED_MODULES + i] = mmd.detIdToIndex[connectedModules[i]]; @@ -239,7 +239,10 @@ namespace SDL { struct pixelMap& pixelMapping, TQueue& queue, const char* moduleMetaDataFilePath, - const MapPLStoLayer& pLStoLayer) { + const MapPLStoLayer& pLStoLayer, + EndcapGeometry* endcapGeometry, + TiltedGeometry* tiltedGeometry, + ModuleConnectionMap* moduleConnectionMap) { ModuleMetaData mmd; loadCentroidsFromFile(moduleMetaDataFilePath, mmd, nModules); @@ -359,9 +362,9 @@ namespace SDL { host_isAnchor[index] = false; } - host_dxdys[index] = (subdet == Endcap) ? Globals::endcapGeometry->getdxdy_slope(detId) - : Globals::tiltedGeometry.getDxDy(detId); - host_drdzs[index] = (subdet == Barrel) ? Globals::tiltedGeometry.getDrDz(detId) : 0; + host_dxdys[index] = (subdet == Endcap) ? endcapGeometry->getdxdy_slope(detId) + : tiltedGeometry->getDxDy(detId); + host_drdzs[index] = (subdet == Barrel) ? tiltedGeometry->getDrDz(detId) : 0; } host_sdlLayers[index] = @@ -412,7 +415,7 @@ namespace SDL { alpaka::memcpy(queue, modulesBuf->sdlLayers_buf, sdlLayers_buf); alpaka::wait(queue); - fillConnectedModuleArrayExplicit(modulesBuf, nModules, queue, mmd); + fillConnectedModuleArrayExplicit(modulesBuf, nModules, queue, mmd, moduleConnectionMap); fillMapArraysExplicit(modulesBuf, nModules, queue, mmd); fillPixelMap(modulesBuf, pixelMapping, queue, pLStoLayer, mmd); }; From d2822c93278e3a9020785c57d99ef6c5258bddaf Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 10 May 2024 16:54:29 -0400 Subject: [PATCH 02/23] Now it compiles, but needs to be fixed --- SDL/Event.cc | 34 +++++++++++------ SDL/Event.h | 11 +++++- SDL/Globals.cc | 27 ------------- SDL/Globals.h | 38 ------------------- SDL/ModuleMethods.h | 16 ++++---- bin/sdl.cc | 29 +++++++++++--- code/core/trkCore.cc | 90 ++++++++++++++++++++++++-------------------- code/core/trkCore.h | 10 ++++- 8 files changed, 122 insertions(+), 133 deletions(-) delete mode 100644 SDL/Globals.cc delete mode 100644 SDL/Globals.h diff --git a/SDL/Event.cc b/SDL/Event.cc index 34316d10..57e1fba0 100644 --- a/SDL/Event.cc +++ b/SDL/Event.cc @@ -148,18 +148,28 @@ void SDL::Event::resetEvent() { } } -// void SDL::Event::initModules(QueueAcc& queue, -// const MapPLStoLayer& pLStoLayer, -// const char* moduleMetaDataFilePath) { -// // nModules gets filled here -// loadModulesFromFile(modulesBuffers, -// nModules, -// nLowerModules, -// *pixelMapping, -// queue, -// moduleMetaDataFilePath, -// pLStoLayer); -// } +void SDL::Event::initModules(QueueAcc& queue, + const MapPLStoLayer& pLStoLayer, + const char* moduleMetaDataFilePath, + uint16_t& nModules, + uint16_t& nLowerModules, + struct modulesBuffer* modulesBuf, + struct pixelMap* pixelMapping, + EndcapGeometry* endcapGeometry, + TiltedGeometry* tiltedGeometry, + ModuleConnectionMap* moduleConnectionMap) { + // nModules gets filled here + loadModulesFromFile(queue, + pLStoLayer, + moduleMetaDataFilePath, + nModules, + nLowerModules, + modulesBuf, + pixelMapping, + endcapGeometry, + tiltedGeometry, + moduleConnectionMap); +} void SDL::Event::addHitToEvent(std::vector x, std::vector y, diff --git a/SDL/Event.h b/SDL/Event.h index c4b1de6a..cb673af2 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -194,7 +194,16 @@ namespace SDL { modulesBuffer* getModules(bool isFull = false); //read from file and init - //static void initModules(QueueAcc& queue, const MapPLStoLayer& pLStoLayer, const char* moduleMetaDataFilePath); + static void initModules(QueueAcc& queue, + const MapPLStoLayer& pLStoLayer, + const char* moduleMetaDataFilePath, + uint16_t& nModules, + uint16_t& nLowerModules, + struct modulesBuffer* modulesBuf, + struct pixelMap* pixelMapping, + EndcapGeometry* endcapGeometry, + TiltedGeometry* tiltedGeometry, + ModuleConnectionMap* moduleConnectionMap); }; } // namespace SDL diff --git a/SDL/Globals.cc b/SDL/Globals.cc deleted file mode 100644 index ab015d5b..00000000 --- a/SDL/Globals.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "Globals.h" - -SDL::modulesBuffer* SDL::Globals::modulesBuffers = nullptr; -SDL::modulesBuffer const* SDL::Globals::modulesBuffersES = nullptr; -std::shared_ptr SDL::Globals::pixelMapping = nullptr; -uint16_t SDL::Globals::nModules; -uint16_t SDL::Globals::nLowerModules; - -SDL::EndcapGeometry* SDL::Globals::endcapGeometry = nullptr; - -SDL::TiltedGeometry SDL::Globals::tiltedGeometry; -SDL::ModuleConnectionMap SDL::Globals::moduleConnectionMap; - -void SDL::Globals::freeEndcap() { - if (endcapGeometry != nullptr) { - delete endcapGeometry; - endcapGeometry = nullptr; - } -} - -// Temporary solution to the global variables. Should be freed with shared_ptr. -void SDL::Globals::freeModules() { - if (modulesBuffers != nullptr) { - delete modulesBuffers; - modulesBuffers = nullptr; - } -} diff --git a/SDL/Globals.h b/SDL/Globals.h deleted file mode 100644 index 9366405f..00000000 --- a/SDL/Globals.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef Globals_h -#define Globals_h - -#ifdef LST_IS_CMSSW_PACKAGE -#include "RecoTracker/LSTCore/interface/alpaka/Constants.h" -#include "RecoTracker/LSTCore/interface/alpaka/Module.h" -#else -#include "Constants.h" -#include "Module.h" -#endif - -#include "TiltedGeometry.h" -#include "EndcapGeometry.h" -#include "ModuleConnectionMap.h" -#include "PixelMap.h" - -namespace SDL { - template - struct Globals; - template <> - struct Globals { - static SDL::modulesBuffer* modulesBuffers; - static SDL::modulesBuffer const* modulesBuffersES; // not owned const buffers - static uint16_t nModules; - static uint16_t nLowerModules; - static std::shared_ptr pixelMapping; - - static EndcapGeometry* endcapGeometry; - static TiltedGeometry tiltedGeometry; - static ModuleConnectionMap moduleConnectionMap; - - static void freeEndcap(); - static void freeModules(); - }; - -} // namespace SDL - -#endif diff --git a/SDL/ModuleMethods.h b/SDL/ModuleMethods.h index 162424c6..11b44227 100644 --- a/SDL/ModuleMethods.h +++ b/SDL/ModuleMethods.h @@ -30,7 +30,7 @@ namespace SDL { }; template - inline void fillPixelMap(struct modulesBuffer* modulesBuf, + inline void fillPixelMap(struct modulesBuffer& modulesBuf, struct pixelMap& pixelMapping, TQueue queue, const MapPLStoLayer& pLStoLayer, @@ -106,7 +106,7 @@ namespace SDL { connectedPixels[icondet + totalSizes + totalSizes_pos] = mmd.detIdToIndex[connectedModuleDetIds_neg[icondet]]; } - alpaka::memcpy(queue, modulesBuf->connectedPixels_buf, connectedPixels_buf); + alpaka::memcpy(queue, modulesBuf.connectedPixels_buf, connectedPixels_buf); alpaka::wait(queue); }; @@ -233,13 +233,13 @@ namespace SDL { }; template - void loadModulesFromFile(struct modulesBuffer* modulesBuf, + void loadModulesFromFile(TQueue& queue, + const MapPLStoLayer& pLStoLayer, + const char* moduleMetaDataFilePath, uint16_t& nModules, uint16_t& nLowerModules, - struct pixelMap& pixelMapping, - TQueue& queue, - const char* moduleMetaDataFilePath, - const MapPLStoLayer& pLStoLayer, + struct modulesBuffer* modulesBuf, + struct pixelMap* pixelMapping, EndcapGeometry* endcapGeometry, TiltedGeometry* tiltedGeometry, ModuleConnectionMap* moduleConnectionMap) { @@ -417,7 +417,7 @@ namespace SDL { fillConnectedModuleArrayExplicit(modulesBuf, nModules, queue, mmd, moduleConnectionMap); fillMapArraysExplicit(modulesBuf, nModules, queue, mmd); - fillPixelMap(modulesBuf, pixelMapping, queue, pLStoLayer, mmd); + fillPixelMap(*modulesBuf, *pixelMapping, queue, pLStoLayer, mmd); }; } // namespace SDL #endif diff --git a/bin/sdl.cc b/bin/sdl.cc index 3c37053d..0e075585 100644 --- a/bin/sdl.cc +++ b/bin/sdl.cc @@ -303,11 +303,34 @@ void run_sdl() queues.push_back(SDL::QueueAcc(devAcc)); } + // Create objects that used to be global + uint16_t nModules; + uint16_t nLowerModules; + std::shared_ptr> modulesBuffers = std::make_shared>(devAcc); + std::shared_ptr pixelMapping = std::make_shared(); + std::shared_ptr> endcapGeometry = std::make_shared>(devAcc); + std::shared_ptr> tiltedGeometry = std::make_shared>(); + std::shared_ptr> moduleConnectionMap = std::make_shared>(); // Load various maps used in the SDL reconstruction TStopwatch full_timer; full_timer.Start(); - loadMaps(devAcc, queues[0]); + loadMaps(devAcc, + queues[0], + nModules, + nLowerModules, + modulesBuffers, + pixelMapping, + endcapGeometry, + tiltedGeometry, + moduleConnectionMap + ); float timeForMapLoading = full_timer.RealTime()*1000; + // tmp + void* address = static_cast(pixelMapping.get()); + std::cout << "Address: " << address << std::endl; + std::cout << "test" << std::endl; + return; + std::cout << "test2" << std::endl; if (ana.do_write_ntuple) { @@ -527,9 +550,5 @@ void run_sdl() delete events.at(s); } - SDL::Globals::freeModules(); - SDL::Globals::freeEndcap(); - delete ana.output_tfile; } - diff --git a/code/core/trkCore.cc b/code/core/trkCore.cc index 9104e3aa..95abfcb8 100644 --- a/code/core/trkCore.cc +++ b/code/core/trkCore.cc @@ -1,8 +1,15 @@ #include "trkCore.h" -#include "Globals.h" //___________________________________________________________________________________________________________________________________________________________________________________________ -void loadMaps(SDL::Dev& devAccIn, SDL::QueueAcc& queue) +void loadMaps(SDL::Dev& devAccIn, + SDL::QueueAcc& queue, + uint16_t& nModules, + uint16_t& nLowerModules, + std::shared_ptr> modulesBuffers, + std::shared_ptr pixelMapping, + std::shared_ptr> endcapGeometry, + std::shared_ptr> tiltedGeometry, + std::shared_ptr> moduleConnectionMap) { // From the environment variable figure out the main tracklooper absolute path TString TrackLooperDir = gSystem->Getenv("TRACKLOOPERDIR"); @@ -21,11 +28,9 @@ void loadMaps(SDL::Dev& devAccIn, SDL::QueueAcc& queue) std::cout << "pLS map: " << pLSMapDir << std::endl; std::cout << "centroid: " << centroid << std::endl; - if (SDL::Globals::endcapGeometry == nullptr) { - SDL::Globals::endcapGeometry = new SDL::EndcapGeometry(devAccIn, queue, endcap_geom.Data()); // centroid values added to the map - } - SDL::Globals::tiltedGeometry.load(tilted_geom.Data()); - SDL::Globals::moduleConnectionMap.load(mappath.Data()); + endcapGeometry->load(queue, endcap_geom.Data()); + tiltedGeometry->load(tilted_geom.Data()); + moduleConnectionMap->load(mappath.Data()); SDL::MapPLStoLayer pLStoLayer; const std::array pLSMapPath{{ "layer1_subdet5", "layer2_subdet5", "layer1_subdet4", "layer2_subdet4" }}; @@ -42,13 +47,16 @@ void loadMaps(SDL::Dev& devAccIn, SDL::QueueAcc& queue) } // WARNING: initModules must come after above load commands!! keep it at the last line here! - if (SDL::Globals::modulesBuffers == nullptr) { - SDL::Globals::modulesBuffers = new SDL::modulesBuffer(devAccIn); - } - if (SDL::Globals::pixelMapping == nullptr) { - SDL::Globals::pixelMapping = std::make_shared(); - } - SDL::Event::initModules(queue, pLStoLayer, centroid.Data()); + SDL::Event::initModules(queue, + pLStoLayer, + centroid.Data(), + nModules, + nLowerModules, + modulesBuffers.get(), + pixelMapping.get(), + endcapGeometry.get(), + tiltedGeometry.get(), + moduleConnectionMap.get()); } //___________________________________________________________________________________________________________________________________________________________________________________________ @@ -199,7 +207,7 @@ float runQuintuplet(SDL::Event* event) if (ana.verbose >= 2) std::cout << "# of Quintuplets produced endcap layer 5: " << event->getNumberOfQuintupletsByLayerEndcap(4) << std::endl; return t5_elapsed; - + } //___________________________________________________________________________________________________________________________________________________________________________________________ @@ -258,11 +266,11 @@ float runTrackCandidateTest_v2(SDL::Event* event) -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- @@ -497,11 +505,11 @@ int getDenomSimTrkType(std::vector simidxs) -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- @@ -610,11 +618,11 @@ TVector3 calculateR3FromPCA(const TVector3 &p3, const float dxy, const float dz) -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- @@ -1109,11 +1117,11 @@ void printTimingInformation(std::vector>& timing_information, -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- @@ -1202,11 +1210,11 @@ void writeMetaData() -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- -// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- +// ---------------------------------- =========================================== ---------------------------------------------- @@ -1244,7 +1252,7 @@ float addInputsToLineSegmentTracking(SDL::Event &event, bool useOMP) std::vector ptErr_vec; std::vector etaErr_vec; std::vector eta_vec; - std::vector phi_vec; + std::vector phi_vec; std::vector charge_vec; std::vector seedIdx_vec; std::vector deltaPhi_vec; diff --git a/code/core/trkCore.h b/code/core/trkCore.h index d236f22a..ebd23496 100644 --- a/code/core/trkCore.h +++ b/code/core/trkCore.h @@ -13,7 +13,15 @@ // --------------------- ======================== --------------------- -void loadMaps(SDL::Dev& devAccIn, SDL::QueueAcc& queue); +void loadMaps(SDL::Dev& devAccIn, + SDL::QueueAcc& queue, + uint16_t& nModules, + uint16_t& nLowerModules, + std::shared_ptr> modulesBuffers, + std::shared_ptr pixelMapping, + std::shared_ptr> endcapGeometry, + std::shared_ptr> tiltedGeometry, + std::shared_ptr> moduleConnectionMap); bool goodEvent(); float runMiniDoublet(SDL::Event* event, int evt); float runSegment(SDL::Event* event); From 562938c1885e310d5d5e9fc8057eeeb76fd87727 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 13 May 2024 10:33:38 -0400 Subject: [PATCH 03/23] Standalone now works without globals --- SDL/Event.h | 20 +- SDL/LST.cc | 820 ++++++++++++++++++++++++++-------------------------- SDL/LST.h | 50 ++-- bin/sdl.cc | 21 +- 4 files changed, 479 insertions(+), 432 deletions(-) diff --git a/SDL/Event.h b/SDL/Event.h index cb673af2..9fe12d2e 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -96,7 +96,25 @@ namespace SDL { public: // Constructor used for CMSSW integration. Uses an external queue. template - Event(bool verbose, TQueue const& q) : queue(q), devAcc(alpaka::getDev(q)), devHost(cms::alpakatools::host()) { + Event(bool verbose, + TQueue const& q, + uint16_t nModulesIn, + uint16_t nLowerModulesIn, + std::shared_ptr> modulesBuffersIn, + std::shared_ptr pixelMappingIn, + std::shared_ptr> endcapGeometryIn, + std::shared_ptr> tiltedGeometryIn, + std::shared_ptr> moduleConnectionMapIn + ) : queue(q), + devAcc(alpaka::getDev(q)), + devHost(cms::alpakatools::host()), + nModules(nModulesIn), + nLowerModules(nLowerModulesIn), + modulesBuffers(modulesBuffersIn), + pixelMapping(pixelMappingIn), + endcapGeometry(endcapGeometryIn), + tiltedGeometry(tiltedGeometryIn), + moduleConnectionMap(moduleConnectionMapIn) { init(verbose); } void resetEvent(); diff --git a/SDL/LST.cc b/SDL/LST.cc index 7fad02d8..01a9fdab 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -95,419 +95,435 @@ namespace { // pLStoLayer); // } -void SDL::LST::run(SDL::QueueAcc& queue, - const SDL::modulesBuffer* modules, - bool verbose, - const std::vector see_px, - const std::vector see_py, - const std::vector see_pz, - const std::vector see_dxy, - const std::vector see_dz, - const std::vector see_ptErr, - const std::vector see_etaErr, - const std::vector see_stateTrajGlbX, - const std::vector see_stateTrajGlbY, - const std::vector see_stateTrajGlbZ, - const std::vector see_stateTrajGlbPx, - const std::vector see_stateTrajGlbPy, - const std::vector see_stateTrajGlbPz, - const std::vector see_q, - const std::vector> see_hitIdx, - const std::vector ph2_detId, - const std::vector ph2_x, - const std::vector ph2_y, - const std::vector ph2_z) { - auto event = SDL::Event(verbose, queue); - prepareInput(see_px, - see_py, - see_pz, - see_dxy, - see_dz, - see_ptErr, - see_etaErr, - see_stateTrajGlbX, - see_stateTrajGlbY, - see_stateTrajGlbZ, - see_stateTrajGlbPx, - see_stateTrajGlbPy, - see_stateTrajGlbPz, - see_q, - see_hitIdx, - ph2_detId, - ph2_x, - ph2_y, - ph2_z); - - event.addHitToEvent(in_trkX_, in_trkY_, in_trkZ_, in_hitId_, in_hitIdxs_); - event.addPixelSegmentToEvent(in_hitIndices_vec0_, - in_hitIndices_vec1_, - in_hitIndices_vec2_, - in_hitIndices_vec3_, - in_deltaPhi_vec_, - in_ptIn_vec_, - in_ptErr_vec_, - in_px_vec_, - in_py_vec_, - in_pz_vec_, - in_eta_vec_, - in_etaErr_vec_, - in_phi_vec_, - in_charge_vec_, - in_seedIdx_vec_, - in_superbin_vec_, - in_pixelType_vec_, - in_isQuad_vec_); - event.createMiniDoublets(); - if (verbose) { - printf("# of Mini-doublets produced: %d\n", event.getNumberOfMiniDoublets()); - printf("# of Mini-doublets produced barrel layer 1: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(0)); - printf("# of Mini-doublets produced barrel layer 2: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(1)); - printf("# of Mini-doublets produced barrel layer 3: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(2)); - printf("# of Mini-doublets produced barrel layer 4: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(3)); - printf("# of Mini-doublets produced barrel layer 5: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(4)); - printf("# of Mini-doublets produced barrel layer 6: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(5)); - printf("# of Mini-doublets produced endcap layer 1: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(0)); - printf("# of Mini-doublets produced endcap layer 2: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(1)); - printf("# of Mini-doublets produced endcap layer 3: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(2)); - printf("# of Mini-doublets produced endcap layer 4: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(3)); - printf("# of Mini-doublets produced endcap layer 5: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(4)); - } +// void SDL::LST::run(SDL::QueueAcc& queue, +// uint16_t nModules, +// uint16_t nLowerModules, +// std::shared_ptr> modulesBuffers, +// std::shared_ptr pixelMapping, +// std::shared_ptr> endcapGeometry, +// std::shared_ptr> tiltedGeometry, +// std::shared_ptr> moduleConnectionMap, +// bool verbose, +// const std::vector see_px, +// const std::vector see_py, +// const std::vector see_pz, +// const std::vector see_dxy, +// const std::vector see_dz, +// const std::vector see_ptErr, +// const std::vector see_etaErr, +// const std::vector see_stateTrajGlbX, +// const std::vector see_stateTrajGlbY, +// const std::vector see_stateTrajGlbZ, +// const std::vector see_stateTrajGlbPx, +// const std::vector see_stateTrajGlbPy, +// const std::vector see_stateTrajGlbPz, +// const std::vector see_q, +// const std::vector> see_hitIdx, +// const std::vector ph2_detId, +// const std::vector ph2_x, +// const std::vector ph2_y, +// const std::vector ph2_z) { +// auto event = SDL::Event( +// verbose, +// queue, +// nModules, +// nLowerModules, +// modulesBuffers, +// pixelMapping, +// endcapGeometry, +// tiltedGeometry, +// moduleConnectionMap +// ); +// prepareInput(see_px, +// see_py, +// see_pz, +// see_dxy, +// see_dz, +// see_ptErr, +// see_etaErr, +// see_stateTrajGlbX, +// see_stateTrajGlbY, +// see_stateTrajGlbZ, +// see_stateTrajGlbPx, +// see_stateTrajGlbPy, +// see_stateTrajGlbPz, +// see_q, +// see_hitIdx, +// ph2_detId, +// ph2_x, +// ph2_y, +// ph2_z); + +// event.addHitToEvent(in_trkX_, in_trkY_, in_trkZ_, in_hitId_, in_hitIdxs_); +// event.addPixelSegmentToEvent(in_hitIndices_vec0_, +// in_hitIndices_vec1_, +// in_hitIndices_vec2_, +// in_hitIndices_vec3_, +// in_deltaPhi_vec_, +// in_ptIn_vec_, +// in_ptErr_vec_, +// in_px_vec_, +// in_py_vec_, +// in_pz_vec_, +// in_eta_vec_, +// in_etaErr_vec_, +// in_phi_vec_, +// in_charge_vec_, +// in_seedIdx_vec_, +// in_superbin_vec_, +// in_pixelType_vec_, +// in_isQuad_vec_); +// event.createMiniDoublets(); +// if (verbose) { +// printf("# of Mini-doublets produced: %d\n", event.getNumberOfMiniDoublets()); +// printf("# of Mini-doublets produced barrel layer 1: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(0)); +// printf("# of Mini-doublets produced barrel layer 2: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(1)); +// printf("# of Mini-doublets produced barrel layer 3: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(2)); +// printf("# of Mini-doublets produced barrel layer 4: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(3)); +// printf("# of Mini-doublets produced barrel layer 5: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(4)); +// printf("# of Mini-doublets produced barrel layer 6: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(5)); +// printf("# of Mini-doublets produced endcap layer 1: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(0)); +// printf("# of Mini-doublets produced endcap layer 2: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(1)); +// printf("# of Mini-doublets produced endcap layer 3: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(2)); +// printf("# of Mini-doublets produced endcap layer 4: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(3)); +// printf("# of Mini-doublets produced endcap layer 5: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(4)); +// } - event.createSegmentsWithModuleMap(); - if (verbose) { - printf("# of Segments produced: %d\n", event.getNumberOfSegments()); - printf("# of Segments produced layer 1-2: %d\n", event.getNumberOfSegmentsByLayerBarrel(0)); - printf("# of Segments produced layer 2-3: %d\n", event.getNumberOfSegmentsByLayerBarrel(1)); - printf("# of Segments produced layer 3-4: %d\n", event.getNumberOfSegmentsByLayerBarrel(2)); - printf("# of Segments produced layer 4-5: %d\n", event.getNumberOfSegmentsByLayerBarrel(3)); - printf("# of Segments produced layer 5-6: %d\n", event.getNumberOfSegmentsByLayerBarrel(4)); - printf("# of Segments produced endcap layer 1: %d\n", event.getNumberOfSegmentsByLayerEndcap(0)); - printf("# of Segments produced endcap layer 2: %d\n", event.getNumberOfSegmentsByLayerEndcap(1)); - printf("# of Segments produced endcap layer 3: %d\n", event.getNumberOfSegmentsByLayerEndcap(2)); - printf("# of Segments produced endcap layer 4: %d\n", event.getNumberOfSegmentsByLayerEndcap(3)); - printf("# of Segments produced endcap layer 5: %d\n", event.getNumberOfSegmentsByLayerEndcap(4)); - } +// event.createSegmentsWithModuleMap(); +// if (verbose) { +// printf("# of Segments produced: %d\n", event.getNumberOfSegments()); +// printf("# of Segments produced layer 1-2: %d\n", event.getNumberOfSegmentsByLayerBarrel(0)); +// printf("# of Segments produced layer 2-3: %d\n", event.getNumberOfSegmentsByLayerBarrel(1)); +// printf("# of Segments produced layer 3-4: %d\n", event.getNumberOfSegmentsByLayerBarrel(2)); +// printf("# of Segments produced layer 4-5: %d\n", event.getNumberOfSegmentsByLayerBarrel(3)); +// printf("# of Segments produced layer 5-6: %d\n", event.getNumberOfSegmentsByLayerBarrel(4)); +// printf("# of Segments produced endcap layer 1: %d\n", event.getNumberOfSegmentsByLayerEndcap(0)); +// printf("# of Segments produced endcap layer 2: %d\n", event.getNumberOfSegmentsByLayerEndcap(1)); +// printf("# of Segments produced endcap layer 3: %d\n", event.getNumberOfSegmentsByLayerEndcap(2)); +// printf("# of Segments produced endcap layer 4: %d\n", event.getNumberOfSegmentsByLayerEndcap(3)); +// printf("# of Segments produced endcap layer 5: %d\n", event.getNumberOfSegmentsByLayerEndcap(4)); +// } - event.createTriplets(); - if (verbose) { - printf("# of T3s produced: %d\n", event.getNumberOfTriplets()); - printf("# of T3s produced layer 1-2-3: %d\n", event.getNumberOfTripletsByLayerBarrel(0)); - printf("# of T3s produced layer 2-3-4: %d\n", event.getNumberOfTripletsByLayerBarrel(1)); - printf("# of T3s produced layer 3-4-5: %d\n", event.getNumberOfTripletsByLayerBarrel(2)); - printf("# of T3s produced layer 4-5-6: %d\n", event.getNumberOfTripletsByLayerBarrel(3)); - printf("# of T3s produced endcap layer 1-2-3: %d\n", event.getNumberOfTripletsByLayerEndcap(0)); - printf("# of T3s produced endcap layer 2-3-4: %d\n", event.getNumberOfTripletsByLayerEndcap(1)); - printf("# of T3s produced endcap layer 3-4-5: %d\n", event.getNumberOfTripletsByLayerEndcap(2)); - printf("# of T3s produced endcap layer 1: %d\n", event.getNumberOfTripletsByLayerEndcap(0)); - printf("# of T3s produced endcap layer 2: %d\n", event.getNumberOfTripletsByLayerEndcap(1)); - printf("# of T3s produced endcap layer 3: %d\n", event.getNumberOfTripletsByLayerEndcap(2)); - printf("# of T3s produced endcap layer 4: %d\n", event.getNumberOfTripletsByLayerEndcap(3)); - printf("# of T3s produced endcap layer 5: %d\n", event.getNumberOfTripletsByLayerEndcap(4)); - } +// event.createTriplets(); +// if (verbose) { +// printf("# of T3s produced: %d\n", event.getNumberOfTriplets()); +// printf("# of T3s produced layer 1-2-3: %d\n", event.getNumberOfTripletsByLayerBarrel(0)); +// printf("# of T3s produced layer 2-3-4: %d\n", event.getNumberOfTripletsByLayerBarrel(1)); +// printf("# of T3s produced layer 3-4-5: %d\n", event.getNumberOfTripletsByLayerBarrel(2)); +// printf("# of T3s produced layer 4-5-6: %d\n", event.getNumberOfTripletsByLayerBarrel(3)); +// printf("# of T3s produced endcap layer 1-2-3: %d\n", event.getNumberOfTripletsByLayerEndcap(0)); +// printf("# of T3s produced endcap layer 2-3-4: %d\n", event.getNumberOfTripletsByLayerEndcap(1)); +// printf("# of T3s produced endcap layer 3-4-5: %d\n", event.getNumberOfTripletsByLayerEndcap(2)); +// printf("# of T3s produced endcap layer 1: %d\n", event.getNumberOfTripletsByLayerEndcap(0)); +// printf("# of T3s produced endcap layer 2: %d\n", event.getNumberOfTripletsByLayerEndcap(1)); +// printf("# of T3s produced endcap layer 3: %d\n", event.getNumberOfTripletsByLayerEndcap(2)); +// printf("# of T3s produced endcap layer 4: %d\n", event.getNumberOfTripletsByLayerEndcap(3)); +// printf("# of T3s produced endcap layer 5: %d\n", event.getNumberOfTripletsByLayerEndcap(4)); +// } - event.createQuintuplets(); - if (verbose) { - printf("# of Quintuplets produced: %d\n", event.getNumberOfQuintuplets()); - printf("# of Quintuplets produced layer 1-2-3-4-5-6: %d\n", event.getNumberOfQuintupletsByLayerBarrel(0)); - printf("# of Quintuplets produced layer 2: %d\n", event.getNumberOfQuintupletsByLayerBarrel(1)); - printf("# of Quintuplets produced layer 3: %d\n", event.getNumberOfQuintupletsByLayerBarrel(2)); - printf("# of Quintuplets produced layer 4: %d\n", event.getNumberOfQuintupletsByLayerBarrel(3)); - printf("# of Quintuplets produced layer 5: %d\n", event.getNumberOfQuintupletsByLayerBarrel(4)); - printf("# of Quintuplets produced layer 6: %d\n", event.getNumberOfQuintupletsByLayerBarrel(5)); - printf("# of Quintuplets produced endcap layer 1: %d\n", event.getNumberOfQuintupletsByLayerEndcap(0)); - printf("# of Quintuplets produced endcap layer 2: %d\n", event.getNumberOfQuintupletsByLayerEndcap(1)); - printf("# of Quintuplets produced endcap layer 3: %d\n", event.getNumberOfQuintupletsByLayerEndcap(2)); - printf("# of Quintuplets produced endcap layer 4: %d\n", event.getNumberOfQuintupletsByLayerEndcap(3)); - printf("# of Quintuplets produced endcap layer 5: %d\n", event.getNumberOfQuintupletsByLayerEndcap(4)); - } +// event.createQuintuplets(); +// if (verbose) { +// printf("# of Quintuplets produced: %d\n", event.getNumberOfQuintuplets()); +// printf("# of Quintuplets produced layer 1-2-3-4-5-6: %d\n", event.getNumberOfQuintupletsByLayerBarrel(0)); +// printf("# of Quintuplets produced layer 2: %d\n", event.getNumberOfQuintupletsByLayerBarrel(1)); +// printf("# of Quintuplets produced layer 3: %d\n", event.getNumberOfQuintupletsByLayerBarrel(2)); +// printf("# of Quintuplets produced layer 4: %d\n", event.getNumberOfQuintupletsByLayerBarrel(3)); +// printf("# of Quintuplets produced layer 5: %d\n", event.getNumberOfQuintupletsByLayerBarrel(4)); +// printf("# of Quintuplets produced layer 6: %d\n", event.getNumberOfQuintupletsByLayerBarrel(5)); +// printf("# of Quintuplets produced endcap layer 1: %d\n", event.getNumberOfQuintupletsByLayerEndcap(0)); +// printf("# of Quintuplets produced endcap layer 2: %d\n", event.getNumberOfQuintupletsByLayerEndcap(1)); +// printf("# of Quintuplets produced endcap layer 3: %d\n", event.getNumberOfQuintupletsByLayerEndcap(2)); +// printf("# of Quintuplets produced endcap layer 4: %d\n", event.getNumberOfQuintupletsByLayerEndcap(3)); +// printf("# of Quintuplets produced endcap layer 5: %d\n", event.getNumberOfQuintupletsByLayerEndcap(4)); +// } - event.pixelLineSegmentCleaning(); +// event.pixelLineSegmentCleaning(); - event.createPixelQuintuplets(); - if (verbose) - printf("# of Pixel Quintuplets produced: %d\n", event.getNumberOfPixelQuintuplets()); +// event.createPixelQuintuplets(); +// if (verbose) +// printf("# of Pixel Quintuplets produced: %d\n", event.getNumberOfPixelQuintuplets()); - event.createPixelTriplets(); - if (verbose) - printf("# of Pixel T3s produced: %d\n", event.getNumberOfPixelTriplets()); +// event.createPixelTriplets(); +// if (verbose) +// printf("# of Pixel T3s produced: %d\n", event.getNumberOfPixelTriplets()); - event.createTrackCandidates(); - if (verbose) { - printf("# of TrackCandidates produced: %d\n", event.getNumberOfTrackCandidates()); - printf(" # of Pixel TrackCandidates produced: %d\n", event.getNumberOfPixelTrackCandidates()); - printf(" # of pT5 TrackCandidates produced: %d\n", event.getNumberOfPT5TrackCandidates()); - printf(" # of pT3 TrackCandidates produced: %d\n", event.getNumberOfPT3TrackCandidates()); - printf(" # of pLS TrackCandidates produced: %d\n", event.getNumberOfPLSTrackCandidates()); - printf(" # of T5 TrackCandidates produced: %d\n", event.getNumberOfT5TrackCandidates()); - } +// event.createTrackCandidates(); +// if (verbose) { +// printf("# of TrackCandidates produced: %d\n", event.getNumberOfTrackCandidates()); +// printf(" # of Pixel TrackCandidates produced: %d\n", event.getNumberOfPixelTrackCandidates()); +// printf(" # of pT5 TrackCandidates produced: %d\n", event.getNumberOfPT5TrackCandidates()); +// printf(" # of pT3 TrackCandidates produced: %d\n", event.getNumberOfPT3TrackCandidates()); +// printf(" # of pLS TrackCandidates produced: %d\n", event.getNumberOfPLSTrackCandidates()); +// printf(" # of T5 TrackCandidates produced: %d\n", event.getNumberOfT5TrackCandidates()); +// } - getOutput(event); +// getOutput(event); - event.resetEvent(); -} +// event.resetEvent(); +// } -namespace { - XYZVector calculateR3FromPCA(const XYZVector& p3, const float dxy, const float dz) { - const float pt = p3.rho(); - const float p = p3.r(); - const float vz = dz * pt * pt / p / p; - - const float vx = -dxy * p3.y() / pt - p3.x() / p * p3.z() / p * dz; - const float vy = dxy * p3.x() / pt - p3.y() / p * p3.z() / p * dz; - return {vx, vy, vz}; - } -} // namespace +// namespace { +// XYZVector calculateR3FromPCA(const XYZVector& p3, const float dxy, const float dz) { +// const float pt = p3.rho(); +// const float p = p3.r(); +// const float vz = dz * pt * pt / p / p; -void SDL::LST::prepareInput(const std::vector see_px, - const std::vector see_py, - const std::vector see_pz, - const std::vector see_dxy, - const std::vector see_dz, - const std::vector see_ptErr, - const std::vector see_etaErr, - const std::vector see_stateTrajGlbX, - const std::vector see_stateTrajGlbY, - const std::vector see_stateTrajGlbZ, - const std::vector see_stateTrajGlbPx, - const std::vector see_stateTrajGlbPy, - const std::vector see_stateTrajGlbPz, - const std::vector see_q, - const std::vector> see_hitIdx, - const std::vector ph2_detId, - const std::vector ph2_x, - const std::vector ph2_y, - const std::vector ph2_z) { - unsigned int count = 0; - auto n_see = see_stateTrajGlbPx.size(); - std::vector px_vec; - px_vec.reserve(n_see); - std::vector py_vec; - py_vec.reserve(n_see); - std::vector pz_vec; - pz_vec.reserve(n_see); - std::vector hitIndices_vec0; - hitIndices_vec0.reserve(n_see); - std::vector hitIndices_vec1; - hitIndices_vec1.reserve(n_see); - std::vector hitIndices_vec2; - hitIndices_vec2.reserve(n_see); - std::vector hitIndices_vec3; - hitIndices_vec3.reserve(n_see); - std::vector ptIn_vec; - ptIn_vec.reserve(n_see); - std::vector ptErr_vec; - ptErr_vec.reserve(n_see); - std::vector etaErr_vec; - etaErr_vec.reserve(n_see); - std::vector eta_vec; - eta_vec.reserve(n_see); - std::vector phi_vec; - phi_vec.reserve(n_see); - std::vector charge_vec; - charge_vec.reserve(n_see); - std::vector seedIdx_vec; - seedIdx_vec.reserve(n_see); - std::vector deltaPhi_vec; - deltaPhi_vec.reserve(n_see); - std::vector trkX = ph2_x; - std::vector trkY = ph2_y; - std::vector trkZ = ph2_z; - std::vector hitId = ph2_detId; - std::vector hitIdxs(ph2_detId.size()); - - std::vector superbin_vec; - std::vector pixelType_vec; - std::vector isQuad_vec; - std::iota(hitIdxs.begin(), hitIdxs.end(), 0); - const int hit_size = trkX.size(); - - for (size_t iSeed = 0; iSeed < n_see; iSeed++) { - XYZVector p3LH(see_stateTrajGlbPx[iSeed], see_stateTrajGlbPy[iSeed], see_stateTrajGlbPz[iSeed]); - XYZVector p3LH_helper(see_stateTrajGlbPx[iSeed], see_stateTrajGlbPy[iSeed], see_stateTrajGlbPz[iSeed]); - float ptIn = p3LH.rho(); - float eta = p3LH.eta(); - float ptErr = see_ptErr[iSeed]; - - if ((ptIn > 0.8 - 2 * ptErr)) { - XYZVector r3LH(see_stateTrajGlbX[iSeed], see_stateTrajGlbY[iSeed], see_stateTrajGlbZ[iSeed]); - XYZVector p3PCA(see_px[iSeed], see_py[iSeed], see_pz[iSeed]); - XYZVector r3PCA(calculateR3FromPCA(p3PCA, see_dxy[iSeed], see_dz[iSeed])); - - float pixelSegmentDeltaPhiChange = (r3LH - p3LH_helper).phi(); //FIXME: this looks like a bug - float etaErr = see_etaErr[iSeed]; - float px = p3LH.x(); - float py = p3LH.y(); - float pz = p3LH.z(); - - int charge = see_q[iSeed]; - int pixtype = -1; - - if (ptIn >= 2.0) - pixtype = 0; - else if (ptIn >= (0.8 - 2 * ptErr) and ptIn < 2.0) { - if (pixelSegmentDeltaPhiChange >= 0) - pixtype = 1; - else - pixtype = 2; - } else - continue; - - unsigned int hitIdx0 = hit_size + count; - count++; - unsigned int hitIdx1 = hit_size + count; - count++; - unsigned int hitIdx2 = hit_size + count; - count++; - unsigned int hitIdx3; - if (see_hitIdx[iSeed].size() <= 3) - hitIdx3 = hitIdx2; - else { - hitIdx3 = hit_size + count; - count++; - } - - trkX.push_back(r3PCA.x()); - trkY.push_back(r3PCA.y()); - trkZ.push_back(r3PCA.z()); - trkX.push_back(p3PCA.rho()); - float p3PCA_Eta = p3PCA.eta(); - trkY.push_back(p3PCA_Eta); - float p3PCA_Phi = p3PCA.phi(); - trkZ.push_back(p3PCA_Phi); - trkX.push_back(r3LH.x()); - trkY.push_back(r3LH.y()); - trkZ.push_back(r3LH.z()); - hitId.push_back(1); - hitId.push_back(1); - hitId.push_back(1); - if (see_hitIdx[iSeed].size() > 3) { - trkX.push_back(r3LH.x()); - trkY.push_back(see_dxy[iSeed]); - trkZ.push_back(see_dz[iSeed]); - hitId.push_back(1); - } - px_vec.push_back(px); - py_vec.push_back(py); - pz_vec.push_back(pz); - - hitIndices_vec0.push_back(hitIdx0); - hitIndices_vec1.push_back(hitIdx1); - hitIndices_vec2.push_back(hitIdx2); - hitIndices_vec3.push_back(hitIdx3); - ptIn_vec.push_back(ptIn); - ptErr_vec.push_back(ptErr); - etaErr_vec.push_back(etaErr); - eta_vec.push_back(eta); - float phi = p3LH.phi(); - phi_vec.push_back(phi); - charge_vec.push_back(charge); - seedIdx_vec.push_back(iSeed); - deltaPhi_vec.push_back(pixelSegmentDeltaPhiChange); - - hitIdxs.push_back(see_hitIdx[iSeed][0]); - hitIdxs.push_back(see_hitIdx[iSeed][1]); - hitIdxs.push_back(see_hitIdx[iSeed][2]); - char isQuad = false; - if (see_hitIdx[iSeed].size() > 3) { - isQuad = true; - hitIdxs.push_back(see_hitIdx[iSeed][3]); - } - float neta = 25.; - float nphi = 72.; - float nz = 25.; - int etabin = (p3PCA_Eta + 2.6) / ((2 * 2.6) / neta); - int phibin = (p3PCA_Phi + 3.14159265358979323846) / ((2. * 3.14159265358979323846) / nphi); - int dzbin = (see_dz[iSeed] + 30) / (2 * 30 / nz); - int isuperbin = (nz * nphi) * etabin + (nz)*phibin + dzbin; - superbin_vec.push_back(isuperbin); - pixelType_vec.push_back(pixtype); - isQuad_vec.push_back(isQuad); - } - } +// const float vx = -dxy * p3.y() / pt - p3.x() / p * p3.z() / p * dz; +// const float vy = dxy * p3.x() / pt - p3.y() / p * p3.z() / p * dz; +// return {vx, vy, vz}; +// } +// } // namespace + +// void SDL::LST::prepareInput(const std::vector see_px, +// const std::vector see_py, +// const std::vector see_pz, +// const std::vector see_dxy, +// const std::vector see_dz, +// const std::vector see_ptErr, +// const std::vector see_etaErr, +// const std::vector see_stateTrajGlbX, +// const std::vector see_stateTrajGlbY, +// const std::vector see_stateTrajGlbZ, +// const std::vector see_stateTrajGlbPx, +// const std::vector see_stateTrajGlbPy, +// const std::vector see_stateTrajGlbPz, +// const std::vector see_q, +// const std::vector> see_hitIdx, +// const std::vector ph2_detId, +// const std::vector ph2_x, +// const std::vector ph2_y, +// const std::vector ph2_z) { +// unsigned int count = 0; +// auto n_see = see_stateTrajGlbPx.size(); +// std::vector px_vec; +// px_vec.reserve(n_see); +// std::vector py_vec; +// py_vec.reserve(n_see); +// std::vector pz_vec; +// pz_vec.reserve(n_see); +// std::vector hitIndices_vec0; +// hitIndices_vec0.reserve(n_see); +// std::vector hitIndices_vec1; +// hitIndices_vec1.reserve(n_see); +// std::vector hitIndices_vec2; +// hitIndices_vec2.reserve(n_see); +// std::vector hitIndices_vec3; +// hitIndices_vec3.reserve(n_see); +// std::vector ptIn_vec; +// ptIn_vec.reserve(n_see); +// std::vector ptErr_vec; +// ptErr_vec.reserve(n_see); +// std::vector etaErr_vec; +// etaErr_vec.reserve(n_see); +// std::vector eta_vec; +// eta_vec.reserve(n_see); +// std::vector phi_vec; +// phi_vec.reserve(n_see); +// std::vector charge_vec; +// charge_vec.reserve(n_see); +// std::vector seedIdx_vec; +// seedIdx_vec.reserve(n_see); +// std::vector deltaPhi_vec; +// deltaPhi_vec.reserve(n_see); +// std::vector trkX = ph2_x; +// std::vector trkY = ph2_y; +// std::vector trkZ = ph2_z; +// std::vector hitId = ph2_detId; +// std::vector hitIdxs(ph2_detId.size()); + +// std::vector superbin_vec; +// std::vector pixelType_vec; +// std::vector isQuad_vec; +// std::iota(hitIdxs.begin(), hitIdxs.end(), 0); +// const int hit_size = trkX.size(); + +// for (size_t iSeed = 0; iSeed < n_see; iSeed++) { +// XYZVector p3LH(see_stateTrajGlbPx[iSeed], see_stateTrajGlbPy[iSeed], see_stateTrajGlbPz[iSeed]); +// XYZVector p3LH_helper(see_stateTrajGlbPx[iSeed], see_stateTrajGlbPy[iSeed], see_stateTrajGlbPz[iSeed]); +// float ptIn = p3LH.rho(); +// float eta = p3LH.eta(); +// float ptErr = see_ptErr[iSeed]; + +// if ((ptIn > 0.8 - 2 * ptErr)) { +// XYZVector r3LH(see_stateTrajGlbX[iSeed], see_stateTrajGlbY[iSeed], see_stateTrajGlbZ[iSeed]); +// XYZVector p3PCA(see_px[iSeed], see_py[iSeed], see_pz[iSeed]); +// XYZVector r3PCA(calculateR3FromPCA(p3PCA, see_dxy[iSeed], see_dz[iSeed])); + +// float pixelSegmentDeltaPhiChange = (r3LH - p3LH_helper).phi(); //FIXME: this looks like a bug +// float etaErr = see_etaErr[iSeed]; +// float px = p3LH.x(); +// float py = p3LH.y(); +// float pz = p3LH.z(); + +// int charge = see_q[iSeed]; +// int pixtype = -1; + +// if (ptIn >= 2.0) +// pixtype = 0; +// else if (ptIn >= (0.8 - 2 * ptErr) and ptIn < 2.0) { +// if (pixelSegmentDeltaPhiChange >= 0) +// pixtype = 1; +// else +// pixtype = 2; +// } else +// continue; + +// unsigned int hitIdx0 = hit_size + count; +// count++; +// unsigned int hitIdx1 = hit_size + count; +// count++; +// unsigned int hitIdx2 = hit_size + count; +// count++; +// unsigned int hitIdx3; +// if (see_hitIdx[iSeed].size() <= 3) +// hitIdx3 = hitIdx2; +// else { +// hitIdx3 = hit_size + count; +// count++; +// } + +// trkX.push_back(r3PCA.x()); +// trkY.push_back(r3PCA.y()); +// trkZ.push_back(r3PCA.z()); +// trkX.push_back(p3PCA.rho()); +// float p3PCA_Eta = p3PCA.eta(); +// trkY.push_back(p3PCA_Eta); +// float p3PCA_Phi = p3PCA.phi(); +// trkZ.push_back(p3PCA_Phi); +// trkX.push_back(r3LH.x()); +// trkY.push_back(r3LH.y()); +// trkZ.push_back(r3LH.z()); +// hitId.push_back(1); +// hitId.push_back(1); +// hitId.push_back(1); +// if (see_hitIdx[iSeed].size() > 3) { +// trkX.push_back(r3LH.x()); +// trkY.push_back(see_dxy[iSeed]); +// trkZ.push_back(see_dz[iSeed]); +// hitId.push_back(1); +// } +// px_vec.push_back(px); +// py_vec.push_back(py); +// pz_vec.push_back(pz); + +// hitIndices_vec0.push_back(hitIdx0); +// hitIndices_vec1.push_back(hitIdx1); +// hitIndices_vec2.push_back(hitIdx2); +// hitIndices_vec3.push_back(hitIdx3); +// ptIn_vec.push_back(ptIn); +// ptErr_vec.push_back(ptErr); +// etaErr_vec.push_back(etaErr); +// eta_vec.push_back(eta); +// float phi = p3LH.phi(); +// phi_vec.push_back(phi); +// charge_vec.push_back(charge); +// seedIdx_vec.push_back(iSeed); +// deltaPhi_vec.push_back(pixelSegmentDeltaPhiChange); + +// hitIdxs.push_back(see_hitIdx[iSeed][0]); +// hitIdxs.push_back(see_hitIdx[iSeed][1]); +// hitIdxs.push_back(see_hitIdx[iSeed][2]); +// char isQuad = false; +// if (see_hitIdx[iSeed].size() > 3) { +// isQuad = true; +// hitIdxs.push_back(see_hitIdx[iSeed][3]); +// } +// float neta = 25.; +// float nphi = 72.; +// float nz = 25.; +// int etabin = (p3PCA_Eta + 2.6) / ((2 * 2.6) / neta); +// int phibin = (p3PCA_Phi + 3.14159265358979323846) / ((2. * 3.14159265358979323846) / nphi); +// int dzbin = (see_dz[iSeed] + 30) / (2 * 30 / nz); +// int isuperbin = (nz * nphi) * etabin + (nz)*phibin + dzbin; +// superbin_vec.push_back(isuperbin); +// pixelType_vec.push_back(pixtype); +// isQuad_vec.push_back(isQuad); +// } +// } - in_trkX_ = trkX; - in_trkY_ = trkY; - in_trkZ_ = trkZ; - in_hitId_ = hitId; - in_hitIdxs_ = hitIdxs; - in_hitIndices_vec0_ = hitIndices_vec0; - in_hitIndices_vec1_ = hitIndices_vec1; - in_hitIndices_vec2_ = hitIndices_vec2; - in_hitIndices_vec3_ = hitIndices_vec3; - in_deltaPhi_vec_ = deltaPhi_vec; - in_ptIn_vec_ = ptIn_vec; - in_ptErr_vec_ = ptErr_vec; - in_px_vec_ = px_vec; - in_py_vec_ = py_vec; - in_pz_vec_ = pz_vec; - in_eta_vec_ = eta_vec; - in_etaErr_vec_ = etaErr_vec; - in_phi_vec_ = phi_vec; - in_charge_vec_ = charge_vec; - in_seedIdx_vec_ = seedIdx_vec; - in_superbin_vec_ = superbin_vec; - in_pixelType_vec_ = pixelType_vec; - in_isQuad_vec_ = isQuad_vec; -} - -void SDL::LST::getOutput(SDL::Event& event) { - std::vector> tc_hitIdxs; - std::vector tc_len; - std::vector tc_seedIdx; - std::vector tc_trackCandidateType; - - SDL::hitsBuffer& hitsInGPU = (*event.getHitsInCMSSW()); - SDL::trackCandidatesBuffer& trackCandidatesInGPU = (*event.getTrackCandidatesInCMSSW()); - - unsigned int nTrackCandidates = *trackCandidatesInGPU.nTrackCandidates; - for (unsigned int idx = 0; idx < nTrackCandidates; idx++) { - short trackCandidateType = trackCandidatesInGPU.trackCandidateType[idx]; - std::vector hit_idx = - getHitIdxs(trackCandidateType, idx, trackCandidatesInGPU.hitIndices, hitsInGPU.idxs); - - tc_hitIdxs.push_back(hit_idx); - tc_len.push_back(hit_idx.size()); - tc_seedIdx.push_back(trackCandidatesInGPU.pixelSeedIndex[idx]); - tc_trackCandidateType.push_back(trackCandidateType); - } +// in_trkX_ = trkX; +// in_trkY_ = trkY; +// in_trkZ_ = trkZ; +// in_hitId_ = hitId; +// in_hitIdxs_ = hitIdxs; +// in_hitIndices_vec0_ = hitIndices_vec0; +// in_hitIndices_vec1_ = hitIndices_vec1; +// in_hitIndices_vec2_ = hitIndices_vec2; +// in_hitIndices_vec3_ = hitIndices_vec3; +// in_deltaPhi_vec_ = deltaPhi_vec; +// in_ptIn_vec_ = ptIn_vec; +// in_ptErr_vec_ = ptErr_vec; +// in_px_vec_ = px_vec; +// in_py_vec_ = py_vec; +// in_pz_vec_ = pz_vec; +// in_eta_vec_ = eta_vec; +// in_etaErr_vec_ = etaErr_vec; +// in_phi_vec_ = phi_vec; +// in_charge_vec_ = charge_vec; +// in_seedIdx_vec_ = seedIdx_vec; +// in_superbin_vec_ = superbin_vec; +// in_pixelType_vec_ = pixelType_vec; +// in_isQuad_vec_ = isQuad_vec; +// } - out_tc_hitIdxs_ = tc_hitIdxs; - out_tc_len_ = tc_len; - out_tc_seedIdx_ = tc_seedIdx; - out_tc_trackCandidateType_ = tc_trackCandidateType; -} - -std::vector SDL::LST::getHitIdxs(const short trackCandidateType, - const unsigned int TCIdx, - const unsigned int* TCHitIndices, - const unsigned int* hitIndices) { - std::vector hits; - - unsigned int maxNHits = 0; - if (trackCandidateType == 7) - maxNHits = 14; // pT5 - else if (trackCandidateType == 5) - maxNHits = 10; // pT3 - else if (trackCandidateType == 4) - maxNHits = 10; // T5 - else if (trackCandidateType == 8) - maxNHits = 4; // pLS - - for (unsigned int i = 0; i < maxNHits; i++) { - unsigned int hitIdxInGPU = TCHitIndices[14 * TCIdx + i]; - unsigned int hitIdx = - (trackCandidateType == 8) - ? hitIdxInGPU - : hitIndices[hitIdxInGPU]; // Hit indices are stored differently in the standalone for pLS. - - // For p objects, the 3rd and 4th hit maybe the same, - // due to the way pLS hits are stored in the standalone. - // This is because pixel seeds can be either triplets or quadruplets. - if (trackCandidateType != 4 && hits.size() == 3 && hits.back() == hitIdx) // Remove duplicate 4th hits. - continue; - - hits.push_back(hitIdx); - } +// void SDL::LST::getOutput(SDL::Event& event) { +// std::vector> tc_hitIdxs; +// std::vector tc_len; +// std::vector tc_seedIdx; +// std::vector tc_trackCandidateType; + +// SDL::hitsBuffer& hitsInGPU = (*event.getHitsInCMSSW()); +// SDL::trackCandidatesBuffer& trackCandidatesInGPU = (*event.getTrackCandidatesInCMSSW()); + +// unsigned int nTrackCandidates = *trackCandidatesInGPU.nTrackCandidates; +// for (unsigned int idx = 0; idx < nTrackCandidates; idx++) { +// short trackCandidateType = trackCandidatesInGPU.trackCandidateType[idx]; +// std::vector hit_idx = +// getHitIdxs(trackCandidateType, idx, trackCandidatesInGPU.hitIndices, hitsInGPU.idxs); + +// tc_hitIdxs.push_back(hit_idx); +// tc_len.push_back(hit_idx.size()); +// tc_seedIdx.push_back(trackCandidatesInGPU.pixelSeedIndex[idx]); +// tc_trackCandidateType.push_back(trackCandidateType); +// } + +// out_tc_hitIdxs_ = tc_hitIdxs; +// out_tc_len_ = tc_len; +// out_tc_seedIdx_ = tc_seedIdx; +// out_tc_trackCandidateType_ = tc_trackCandidateType; +// } - return hits; -} +// std::vector SDL::LST::getHitIdxs(const short trackCandidateType, +// const unsigned int TCIdx, +// const unsigned int* TCHitIndices, +// const unsigned int* hitIndices) { +// std::vector hits; + +// unsigned int maxNHits = 0; +// if (trackCandidateType == 7) +// maxNHits = 14; // pT5 +// else if (trackCandidateType == 5) +// maxNHits = 10; // pT3 +// else if (trackCandidateType == 4) +// maxNHits = 10; // T5 +// else if (trackCandidateType == 8) +// maxNHits = 4; // pLS + +// for (unsigned int i = 0; i < maxNHits; i++) { +// unsigned int hitIdxInGPU = TCHitIndices[14 * TCIdx + i]; +// unsigned int hitIdx = +// (trackCandidateType == 8) +// ? hitIdxInGPU +// : hitIndices[hitIdxInGPU]; // Hit indices are stored differently in the standalone for pLS. + +// // For p objects, the 3rd and 4th hit maybe the same, +// // due to the way pLS hits are stored in the standalone. +// // This is because pixel seeds can be either triplets or quadruplets. +// if (trackCandidateType != 4 && hits.size() == 3 && hits.back() == hitIdx) // Remove duplicate 4th hits. +// continue; + +// hits.push_back(hitIdx); +// } + +// return hits; +// } diff --git a/SDL/LST.h b/SDL/LST.h index a0360932..4c434c2f 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -30,28 +30,34 @@ namespace SDL { static void loadAndFillES(SDL::QueueAcc& queue, struct modulesBuffer* modules); - void run(SDL::QueueAcc& queue, - const SDL::modulesBuffer* modules, - bool verbose, - const std::vector see_px, - const std::vector see_py, - const std::vector see_pz, - const std::vector see_dxy, - const std::vector see_dz, - const std::vector see_ptErr, - const std::vector see_etaErr, - const std::vector see_stateTrajGlbX, - const std::vector see_stateTrajGlbY, - const std::vector see_stateTrajGlbZ, - const std::vector see_stateTrajGlbPx, - const std::vector see_stateTrajGlbPy, - const std::vector see_stateTrajGlbPz, - const std::vector see_q, - const std::vector> see_hitIdx, - const std::vector ph2_detId, - const std::vector ph2_x, - const std::vector ph2_y, - const std::vector ph2_z); + // void run(SDL::QueueAcc& queue, + // uint16_t nModules, + // uint16_t nLowerModules, + // std::shared_ptr> modulesBuffers, + // std::shared_ptr pixelMapping, + // std::shared_ptr> endcapGeometry, + // std::shared_ptr> tiltedGeometry, + // std::shared_ptr> moduleConnectionMap, + // bool verbose, + // const std::vector see_px, + // const std::vector see_py, + // const std::vector see_pz, + // const std::vector see_dxy, + // const std::vector see_dz, + // const std::vector see_ptErr, + // const std::vector see_etaErr, + // const std::vector see_stateTrajGlbX, + // const std::vector see_stateTrajGlbY, + // const std::vector see_stateTrajGlbZ, + // const std::vector see_stateTrajGlbPx, + // const std::vector see_stateTrajGlbPy, + // const std::vector see_stateTrajGlbPz, + // const std::vector see_q, + // const std::vector> see_hitIdx, + // const std::vector ph2_detId, + // const std::vector ph2_x, + // const std::vector ph2_y, + // const std::vector ph2_z); std::vector> hits() { return out_tc_hitIdxs_; } std::vector len() { return out_tc_len_; } std::vector seedIdx() { return out_tc_seedIdx_; } diff --git a/bin/sdl.cc b/bin/sdl.cc index 0e075585..a12e1984 100644 --- a/bin/sdl.cc +++ b/bin/sdl.cc @@ -290,6 +290,9 @@ int main(int argc, char** argv) // Run the code run_sdl(); + + //tmp + std::cout << "test3" << std::endl; return 0; } @@ -325,12 +328,6 @@ void run_sdl() moduleConnectionMap ); float timeForMapLoading = full_timer.RealTime()*1000; - // tmp - void* address = static_cast(pixelMapping.get()); - std::cout << "Address: " << address << std::endl; - std::cout << "test" << std::endl; - return; - std::cout << "test2" << std::endl; if (ana.do_write_ntuple) { @@ -411,7 +408,17 @@ void run_sdl() std::vector*> events; for (int s = 0; s < ana.streams; s++) { - SDL::Event *event = new SDL::Event(ana.verbose>=2, queues[s]); + SDL::Event *event = new SDL::Event( + ana.verbose>=2, + queues[s], + nModules, + nLowerModules, + modulesBuffers, + pixelMapping, + endcapGeometry, + tiltedGeometry, + moduleConnectionMap + ); events.push_back(event); } float timeForEventCreation = full_timer.RealTime()*1000; From 0a8bf3610b4823215e6b3bea3c84fc61f4a55d35 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 13 May 2024 07:45:55 -0700 Subject: [PATCH 04/23] Format code --- SDL/Event.cc | 163 +++++++++++++++++--------------------------- SDL/Event.h | 22 +++--- SDL/ModuleMethods.h | 3 +- bin/sdl.cc | 6 +- 4 files changed, 77 insertions(+), 117 deletions(-) diff --git a/SDL/Event.cc b/SDL/Event.cc index 57e1fba0..0f3d3590 100644 --- a/SDL/Event.cc +++ b/SDL/Event.cc @@ -188,8 +188,7 @@ void SDL::Event::addHitToEvent(std::vector x, if (rangesInGPU == nullptr) { rangesInGPU = new SDL::objectRanges(); - rangesBuffers = - new SDL::objectRangesBuffer(nModules, nLowerModules, devAcc, queue); + rangesBuffers = new SDL::objectRangesBuffer(nModules, nLowerModules, devAcc, queue); rangesInGPU->setData(*rangesBuffers); } @@ -210,18 +209,17 @@ void SDL::Event::addHitToEvent(std::vector x, WorkDiv const hit_loop_workdiv = createWorkDiv(blocksPerGrid1, threadsPerBlock1, elementsPerThread); hitLoopKernel hit_loop_kernel; - auto const hit_loop_task( - alpaka::createTaskKernel(hit_loop_workdiv, - hit_loop_kernel, - Endcap, - TwoS, - nModules, - endcapGeometry->nEndCapMap, - alpaka::getPtrNative(endcapGeometry->geoMapDetId_buf), - alpaka::getPtrNative(endcapGeometry->geoMapPhi_buf), - *modulesBuffers->data(), - *hitsInGPU, - nHits)); + auto const hit_loop_task(alpaka::createTaskKernel(hit_loop_workdiv, + hit_loop_kernel, + Endcap, + TwoS, + nModules, + endcapGeometry->nEndCapMap, + alpaka::getPtrNative(endcapGeometry->geoMapDetId_buf), + alpaka::getPtrNative(endcapGeometry->geoMapPhi_buf), + *modulesBuffers->data(), + *hitsInGPU, + nHits)); alpaka::enqueue(queue, hit_loop_task); @@ -230,11 +228,8 @@ void SDL::Event::addHitToEvent(std::vector x, WorkDiv const module_ranges_workdiv = createWorkDiv(blocksPerGrid2, threadsPerBlock2, elementsPerThread); moduleRangesKernel module_ranges_kernel; - auto const module_ranges_task(alpaka::createTaskKernel(module_ranges_workdiv, - module_ranges_kernel, - *modulesBuffers->data(), - *hitsInGPU, - nLowerModules)); + auto const module_ranges_task(alpaka::createTaskKernel( + module_ranges_workdiv, module_ranges_kernel, *modulesBuffers->data(), *hitsInGPU, nLowerModules)); // Waiting isn't needed after second kernel call. Saves ~100 us. // This is because addPixelSegmentToEvent (which is run next) doesn't rely on hitsBuffers->hitrange variables. @@ -276,8 +271,8 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI if (mdsInGPU == nullptr) { // Create a view for the element nLowerModules inside rangesBuffers->miniDoubletModuleOccupancy - auto dst_view_miniDoubletModuleOccupancy = alpaka::createSubView( - rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules); + auto dst_view_miniDoubletModuleOccupancy = + alpaka::createSubView(rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules); // Create a source view for the value to be set int value = N_MAX_PIXEL_MD_PER_MODULES; @@ -292,10 +287,8 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI createWorkDiv(blocksPerGridCreateMD, threadsPerBlockCreateMD, elementsPerThread); SDL::createMDArrayRangesGPU createMDArrayRangesGPU_kernel; - auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel(createMDArrayRangesGPU_workDiv, - createMDArrayRangesGPU_kernel, - *modulesBuffers->data(), - *rangesInGPU)); + auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel( + createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers->data(), *rangesInGPU)); alpaka::enqueue(queue, createMDArrayRangesGPUTask); alpaka::wait(queue); @@ -342,8 +335,8 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI nTotalSegments += N_MAX_PIXEL_SEGMENTS_PER_MODULE; segmentsInGPU = new SDL::segments(); - segmentsBuffers = new SDL::segmentsBuffer( - nTotalSegments, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); + segmentsBuffers = + new SDL::segmentsBuffer(nTotalSegments, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); segmentsInGPU->setData(*segmentsBuffers); alpaka::memcpy(queue, segmentsBuffers->nMemoryLocations_buf, nTotalSegments_view); @@ -422,8 +415,8 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI void SDL::Event::createMiniDoublets() { // Create a view for the element nLowerModules inside rangesBuffers->miniDoubletModuleOccupancy - auto dst_view_miniDoubletModuleOccupancy = alpaka::createSubView( - rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules); + auto dst_view_miniDoubletModuleOccupancy = + alpaka::createSubView(rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules); // Create a source view for the value to be set int value = N_MAX_PIXEL_MD_PER_MODULES; @@ -438,10 +431,8 @@ void SDL::Event::createMiniDoublets() { createWorkDiv(blocksPerGridCreateMD, threadsPerBlockCreateMD, elementsPerThread); SDL::createMDArrayRangesGPU createMDArrayRangesGPU_kernel; - auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel(createMDArrayRangesGPU_workDiv, - createMDArrayRangesGPU_kernel, - *modulesBuffers->data(), - *rangesInGPU)); + auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel( + createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers->data(), *rangesInGPU)); alpaka::enqueue(queue, createMDArrayRangesGPUTask); alpaka::wait(queue); @@ -462,8 +453,7 @@ void SDL::Event::createMiniDoublets() { } Vec const threadsPerBlockCreateMDInGPU = createVec(1, 16, 32); - Vec const blocksPerGridCreateMDInGPU = - createVec(1, nLowerModules / threadsPerBlockCreateMDInGPU[1], 1); + Vec const blocksPerGridCreateMDInGPU = createVec(1, nLowerModules / threadsPerBlockCreateMDInGPU[1], 1); WorkDiv const createMiniDoubletsInGPUv2_workDiv = createWorkDiv(blocksPerGridCreateMDInGPU, threadsPerBlockCreateMDInGPU, elementsPerThread); @@ -502,8 +492,8 @@ void SDL::Event::createMiniDoublets() { void SDL::Event::createSegmentsWithModuleMap() { if (segmentsInGPU == nullptr) { segmentsInGPU = new SDL::segments(); - segmentsBuffers = new SDL::segmentsBuffer( - nTotalSegments, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); + segmentsBuffers = + new SDL::segmentsBuffer(nTotalSegments, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); segmentsInGPU->setData(*segmentsBuffers); } @@ -528,12 +518,11 @@ void SDL::Event::createSegmentsWithModuleMap() { createWorkDiv(blocksPerGridAddSeg, threadsPerBlockAddSeg, elementsPerThread); SDL::addSegmentRangesToEventExplicit addSegmentRangesToEventExplicit_kernel; - auto const addSegmentRangesToEventExplicitTask( - alpaka::createTaskKernel(addSegmentRangesToEventExplicit_workDiv, - addSegmentRangesToEventExplicit_kernel, - *modulesBuffers->data(), - *segmentsInGPU, - *rangesInGPU)); + auto const addSegmentRangesToEventExplicitTask(alpaka::createTaskKernel(addSegmentRangesToEventExplicit_workDiv, + addSegmentRangesToEventExplicit_kernel, + *modulesBuffers->data(), + *segmentsInGPU, + *rangesInGPU)); alpaka::enqueue(queue, addSegmentRangesToEventExplicitTask); alpaka::wait(queue); @@ -567,8 +556,8 @@ void SDL::Event::createTriplets() { alpaka::wait(queue); tripletsInGPU = new SDL::triplets(); - tripletsBuffers = new SDL::tripletsBuffer( - *alpaka::getPtrNative(maxTriplets_buf), nLowerModules, devAcc, queue); + tripletsBuffers = + new SDL::tripletsBuffer(*alpaka::getPtrNative(maxTriplets_buf), nLowerModules, devAcc, queue); tripletsInGPU->setData(*tripletsBuffers); alpaka::memcpy(queue, tripletsBuffers->nMemoryLocations_buf, maxTriplets_buf); @@ -594,16 +583,12 @@ void SDL::Event::createTriplets() { // Allocate and copy module_nConnectedModules from device to host auto module_nConnectedModules_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, - module_nConnectedModules_buf, - modulesBuffers->nConnectedModules_buf, - nLowerModules); + alpaka::memcpy(queue, module_nConnectedModules_buf, modulesBuffers->nConnectedModules_buf, nLowerModules); alpaka::wait(queue); uint16_t* module_nConnectedModules = alpaka::getPtrNative(module_nConnectedModules_buf); - for (uint16_t innerLowerModuleIndex = 0; innerLowerModuleIndex < nLowerModules; - innerLowerModuleIndex++) { + for (uint16_t innerLowerModuleIndex = 0; innerLowerModuleIndex < nLowerModules; innerLowerModuleIndex++) { uint16_t nConnectedModules = module_nConnectedModules[innerLowerModuleIndex]; unsigned int nInnerSegments = nSegments[innerLowerModuleIndex]; if (nConnectedModules != 0 and nInnerSegments != 0) { @@ -641,12 +626,11 @@ void SDL::Event::createTriplets() { createWorkDiv(blocksPerGridAddTrip, threadsPerBlockAddTrip, elementsPerThread); SDL::addTripletRangesToEventExplicit addTripletRangesToEventExplicit_kernel; - auto const addTripletRangesToEventExplicitTask( - alpaka::createTaskKernel(addTripletRangesToEventExplicit_workDiv, - addTripletRangesToEventExplicit_kernel, - *modulesBuffers->data(), - *tripletsInGPU, - *rangesInGPU)); + auto const addTripletRangesToEventExplicitTask(alpaka::createTaskKernel(addTripletRangesToEventExplicit_workDiv, + addTripletRangesToEventExplicit_kernel, + *modulesBuffers->data(), + *tripletsInGPU, + *rangesInGPU)); alpaka::enqueue(queue, addTripletRangesToEventExplicitTask); alpaka::wait(queue); @@ -830,8 +814,7 @@ void SDL::Event::createPixelTriplets() { unsigned int nInnerSegments; auto nInnerSegments_src_view = alpaka::createView(devHost, &nInnerSegments, (size_t)1u); - auto dev_view_nSegments = - alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules); + auto dev_view_nSegments = alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules); alpaka::memcpy(queue, nInnerSegments_src_view, dev_view_nSegments); alpaka::wait(queue); @@ -854,11 +837,10 @@ void SDL::Event::createPixelTriplets() { unsigned int* connectedPixelIndex_host = alpaka::getPtrNative(connectedPixelIndex_host_buf); alpaka::wait(queue); - int pixelIndexOffsetPos = pixelMapping->connectedPixelsIndex[size_superbins - 1] + - pixelMapping->connectedPixelsSizes[size_superbins - 1]; + int pixelIndexOffsetPos = + pixelMapping->connectedPixelsIndex[size_superbins - 1] + pixelMapping->connectedPixelsSizes[size_superbins - 1]; int pixelIndexOffsetNeg = pixelMapping->connectedPixelsIndexPos[size_superbins - 1] + - pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + - pixelIndexOffsetPos; + pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos; // TODO: check if a map/reduction to just eligible pLSs would speed up the kernel // the current selection still leaves a significant fraction of unmatchable pLSs @@ -970,8 +952,7 @@ void SDL::Event::createQuintuplets() { if (quintupletsInGPU == nullptr) { quintupletsInGPU = new SDL::quintuplets(); - quintupletsBuffers = - new SDL::quintupletsBuffer(nTotalQuintuplets, nLowerModules, devAcc, queue); + quintupletsBuffers = new SDL::quintupletsBuffer(nTotalQuintuplets, nLowerModules, devAcc, queue); quintupletsInGPU->setData(*quintupletsBuffers); alpaka::memcpy(queue, quintupletsBuffers->nMemoryLocations_buf, nTotalQuintuplets_buf); @@ -1065,8 +1046,7 @@ void SDL::Event::createPixelQuintuplets() { auto nInnerSegments_src_view = alpaka::createView(devHost, &nInnerSegments, (size_t)1u); // Create a sub-view for the device buffer - auto dev_view_nSegments = - alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules); + auto dev_view_nSegments = alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules); alpaka::memcpy(queue, nInnerSegments_src_view, dev_view_nSegments); alpaka::wait(queue); @@ -1089,11 +1069,10 @@ void SDL::Event::createPixelQuintuplets() { unsigned int* connectedPixelIndex_host = alpaka::getPtrNative(connectedPixelIndex_host_buf); alpaka::wait(queue); - int pixelIndexOffsetPos = pixelMapping->connectedPixelsIndex[size_superbins - 1] + - pixelMapping->connectedPixelsSizes[size_superbins - 1]; + int pixelIndexOffsetPos = + pixelMapping->connectedPixelsIndex[size_superbins - 1] + pixelMapping->connectedPixelsSizes[size_superbins - 1]; int pixelIndexOffsetNeg = pixelMapping->connectedPixelsIndexPos[size_superbins - 1] + - pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + - pixelIndexOffsetPos; + pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos; // Loop over # pLS for (unsigned int i = 0; i < nInnerSegments; i++) { @@ -1111,16 +1090,12 @@ void SDL::Event::createPixelQuintuplets() { unsigned int connectedIdxBase = pixelMapping->connectedPixelsIndex[superbin]; connectedPixelIndex_host[i] = connectedIdxBase; } else if (pixelType == 1) { - connectedPixelSize_host[i] = - pixelMapping->connectedPixelsSizesPos[superbin]; //number of pixel connected modules - unsigned int connectedIdxBase = - pixelMapping->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; + connectedPixelSize_host[i] = pixelMapping->connectedPixelsSizesPos[superbin]; //number of pixel connected modules + unsigned int connectedIdxBase = pixelMapping->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; connectedPixelIndex_host[i] = connectedIdxBase; } else if (pixelType == 2) { - connectedPixelSize_host[i] = - pixelMapping->connectedPixelsSizesNeg[superbin]; //number of pixel connected modules - unsigned int connectedIdxBase = - pixelMapping->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; + connectedPixelSize_host[i] = pixelMapping->connectedPixelsSizesNeg[superbin]; //number of pixel connected modules + unsigned int connectedIdxBase = pixelMapping->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; connectedPixelIndex_host[i] = connectedIdxBase; } } @@ -1196,12 +1171,10 @@ void SDL::Event::addMiniDoubletsToEventExplicit() { alpaka::memcpy(queue, nMDsCPU_buf, miniDoubletsBuffers->nMDs_buf, nLowerModules); auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy( - queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); + alpaka::memcpy(queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy( - queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); + alpaka::memcpy(queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); auto module_hitRanges_buf = allocBufWrapper(devHost, nLowerModules * 2, queue); alpaka::memcpy(queue, module_hitRanges_buf, hitsBuffers->hitRanges_buf, nLowerModules * 2u); @@ -1229,12 +1202,10 @@ void SDL::Event::addSegmentsToEventExplicit() { alpaka::memcpy(queue, nSegmentsCPU_buf, segmentsBuffers->nSegments_buf, nLowerModules); auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy( - queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); + alpaka::memcpy(queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy( - queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); + alpaka::memcpy(queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); alpaka::wait(queue); @@ -1258,12 +1229,10 @@ void SDL::Event::addQuintupletsToEventExplicit() { alpaka::memcpy(queue, nQuintupletsCPU_buf, quintupletsBuffers->nQuintuplets_buf); auto module_subdets_buf = allocBufWrapper(devHost, nModules, queue); - alpaka::memcpy( - queue, module_subdets_buf, modulesBuffers->subdets_buf, nModules); + alpaka::memcpy(queue, module_subdets_buf, modulesBuffers->subdets_buf, nModules); auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy( - queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); + alpaka::memcpy(queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); auto module_quintupletModuleIndices_buf = allocBufWrapper(devHost, nLowerModules, queue); alpaka::memcpy(queue, module_quintupletModuleIndices_buf, rangesBuffers->quintupletModuleIndices_buf); @@ -1291,12 +1260,10 @@ void SDL::Event::addTripletsToEventExplicit() { alpaka::memcpy(queue, nTripletsCPU_buf, tripletsBuffers->nTriplets_buf); auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy( - queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); + alpaka::memcpy(queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy( - queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); + alpaka::memcpy(queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); alpaka::wait(queue); unsigned int* nTripletsCPU = alpaka::getPtrNative(nTripletsCPU_buf); @@ -1582,8 +1549,7 @@ SDL::hitsBuffer* SDL::Event::getHitsInCMSSW() { SDL::objectRangesBuffer* SDL::Event::getRanges() { if (rangesInCPU == nullptr) { - rangesInCPU = new SDL::objectRangesBuffer( - nModules, nLowerModules, devHost, queue); + rangesInCPU = new SDL::objectRangesBuffer(nModules, nLowerModules, devHost, queue); rangesInCPU->setData(*rangesInCPU); alpaka::memcpy(queue, rangesInCPU->hitRanges_buf, rangesBuffers->hitRanges_buf); @@ -1696,8 +1662,7 @@ SDL::quintupletsBuffer* SDL::Event::getQuintuplets() { alpaka::wait(queue); unsigned int nMemHost = *alpaka::getPtrNative(nMemHost_buf); - quintupletsInCPU = - new SDL::quintupletsBuffer(nMemHost, nLowerModules, devHost, queue); + quintupletsInCPU = new SDL::quintupletsBuffer(nMemHost, nLowerModules, devHost, queue); quintupletsInCPU->setData(*quintupletsInCPU); *alpaka::getPtrNative(quintupletsInCPU->nMemoryLocations_buf) = nMemHost; diff --git a/SDL/Event.h b/SDL/Event.h index 9fe12d2e..336aa30e 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -104,17 +104,17 @@ namespace SDL { std::shared_ptr pixelMappingIn, std::shared_ptr> endcapGeometryIn, std::shared_ptr> tiltedGeometryIn, - std::shared_ptr> moduleConnectionMapIn - ) : queue(q), - devAcc(alpaka::getDev(q)), - devHost(cms::alpakatools::host()), - nModules(nModulesIn), - nLowerModules(nLowerModulesIn), - modulesBuffers(modulesBuffersIn), - pixelMapping(pixelMappingIn), - endcapGeometry(endcapGeometryIn), - tiltedGeometry(tiltedGeometryIn), - moduleConnectionMap(moduleConnectionMapIn) { + std::shared_ptr> moduleConnectionMapIn) + : queue(q), + devAcc(alpaka::getDev(q)), + devHost(cms::alpakatools::host()), + nModules(nModulesIn), + nLowerModules(nLowerModulesIn), + modulesBuffers(modulesBuffersIn), + pixelMapping(pixelMappingIn), + endcapGeometry(endcapGeometryIn), + tiltedGeometry(tiltedGeometryIn), + moduleConnectionMap(moduleConnectionMapIn) { init(verbose); } void resetEvent(); diff --git a/SDL/ModuleMethods.h b/SDL/ModuleMethods.h index 11b44227..401874b7 100644 --- a/SDL/ModuleMethods.h +++ b/SDL/ModuleMethods.h @@ -362,8 +362,7 @@ namespace SDL { host_isAnchor[index] = false; } - host_dxdys[index] = (subdet == Endcap) ? endcapGeometry->getdxdy_slope(detId) - : tiltedGeometry->getDxDy(detId); + host_dxdys[index] = (subdet == Endcap) ? endcapGeometry->getdxdy_slope(detId) : tiltedGeometry->getDxDy(detId); host_drdzs[index] = (subdet == Barrel) ? tiltedGeometry->getDrDz(detId) : 0; } diff --git a/bin/sdl.cc b/bin/sdl.cc index a12e1984..8c900e4a 100644 --- a/bin/sdl.cc +++ b/bin/sdl.cc @@ -290,9 +290,6 @@ int main(int argc, char** argv) // Run the code run_sdl(); - - //tmp - std::cout << "test3" << std::endl; return 0; } @@ -325,8 +322,7 @@ void run_sdl() pixelMapping, endcapGeometry, tiltedGeometry, - moduleConnectionMap - ); + moduleConnectionMap); float timeForMapLoading = full_timer.RealTime()*1000; if (ana.do_write_ntuple) From 4b91683e4e6b7fcdaeb2526d9afbec7a5d65d281 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 13 May 2024 11:57:20 -0400 Subject: [PATCH 05/23] Some progress on the CMSSW side --- SDL/Event.h | 4 +- SDL/LST.cc | 987 ++++++++++++++++++++++++++-------------------------- SDL/LST.h | 78 +++-- 3 files changed, 546 insertions(+), 523 deletions(-) diff --git a/SDL/Event.h b/SDL/Event.h index 336aa30e..a36aaa83 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -85,13 +85,13 @@ namespace SDL { int8_t* pixelTypeCPU; // Stuff that used to be global + uint16_t nModules; + uint16_t nLowerModules; std::shared_ptr> modulesBuffers; std::shared_ptr pixelMapping; std::shared_ptr> endcapGeometry; std::shared_ptr> tiltedGeometry; std::shared_ptr> moduleConnectionMap; - uint16_t nModules; - uint16_t nLowerModules; public: // Constructor used for CMSSW integration. Uses an external queue. diff --git a/SDL/LST.cc b/SDL/LST.cc index 01a9fdab..f66f7bcd 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -33,497 +33,502 @@ namespace { return fullpath.string(); } - // void loadMaps(SDL::Dev const& devAccIn, SDL::QueueAcc& queue, SDL::MapPLStoLayer& pLStoLayer) { - // // Module orientation information (DrDz or phi angles) - // auto endcap_geom = - // get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); - // auto tilted_geom = get_absolute_path_after_check_file_exists( - // trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); - // if (SDL::Globals::endcapGeometry == nullptr) { - // SDL::Globals::endcapGeometry = - // new SDL::EndcapGeometry(devAccIn, queue, endcap_geom); // centroid values added to the map - // } - - // SDL::Globals::tiltedGeometry.load(tilted_geom); - - // // Module connection map (for line segment building) - // auto mappath = get_absolute_path_after_check_file_exists( - // trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); - // SDL::Globals::moduleConnectionMap.load(mappath); - - // auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map"; - // const std::array connects{ - // {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}}; - // std::string path; - - // static_assert(connects.size() == std::tuple_size>{}); - // for (unsigned int i = 0; i < connects.size(); i++) { - // auto connectData = connects[i].data(); - - // path = pLSMapDir + connectData + ".bin"; - // pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - - // path = pLSMapDir + "_pos" + connectData + ".bin"; - // pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - - // path = pLSMapDir + "_neg" + connectData + ".bin"; - // pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - // } - // } + void loadMaps(SDL::Dev const& devAccIn, + SDL::QueueAcc& queue, + SDL::MapPLStoLayer& pLStoLayer, + std::shared_ptr> endcapGeometry, + std::shared_ptr> tiltedGeometry, + std::shared_ptr> moduleConnectionMap) { + // Module orientation information (DrDz or phi angles) + auto endcap_geom = + get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); + auto tilted_geom = get_absolute_path_after_check_file_exists( + trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); + // Module connection map (for line segment building) + auto mappath = get_absolute_path_after_check_file_exists( + trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); + + endcapGeometry->load(queue, endcap_geom); + tiltedGeometry->load(tilted_geom); + moduleConnectionMap->load(mappath); + + auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map"; + const std::array connects{ + {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}}; + std::string path; + + static_assert(connects.size() == std::tuple_size>{}); + for (unsigned int i = 0; i < connects.size(); i++) { + auto connectData = connects[i].data(); + + path = pLSMapDir + connectData + ".bin"; + pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + + path = pLSMapDir + "_pos" + connectData + ".bin"; + pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + + path = pLSMapDir + "_neg" + connectData + ".bin"; + pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + } + } + +} // namespace + +void SDL::LST::loadAndFillES(SDL::QueueAcc& queue, + uint16_t& nModules, + uint16_t& nLowerModules, + std::shared_ptr> modulesBuf, + std::shared_ptr pixelMapping, + std::shared_ptr> endcapGeometry, + std::shared_ptr> tiltedGeometry, + std::shared_ptr> moduleConnectionMap) { + SDL::MapPLStoLayer pLStoLayer; + SDL::Dev const& devAccIn = alpaka::getDev(queue); + ::loadMaps(devAccIn, queue, pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); + + auto path = + get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); + SDL::loadModulesFromFile(queue, + pLStoLayer, + path.c_str(), + nModules, + nLowerModules, + modulesBuf.get(), + pixelMapping.get(), + endcapGeometry.get(), + tiltedGeometry.get(), + moduleConnectionMap.get()); +} + +void SDL::LST::run(SDL::QueueAcc& queue, + uint16_t nModules, + uint16_t nLowerModules, + std::shared_ptr> modulesBuffers, + std::shared_ptr pixelMapping, + std::shared_ptr> endcapGeometry, + std::shared_ptr> tiltedGeometry, + std::shared_ptr> moduleConnectionMap, + bool verbose, + const std::vector see_px, + const std::vector see_py, + const std::vector see_pz, + const std::vector see_dxy, + const std::vector see_dz, + const std::vector see_ptErr, + const std::vector see_etaErr, + const std::vector see_stateTrajGlbX, + const std::vector see_stateTrajGlbY, + const std::vector see_stateTrajGlbZ, + const std::vector see_stateTrajGlbPx, + const std::vector see_stateTrajGlbPy, + const std::vector see_stateTrajGlbPz, + const std::vector see_q, + const std::vector> see_hitIdx, + const std::vector ph2_detId, + const std::vector ph2_x, + const std::vector ph2_y, + const std::vector ph2_z) { + auto event = SDL::Event( + verbose, + queue, + nModules, + nLowerModules, + modulesBuffers, + pixelMapping, + endcapGeometry, + tiltedGeometry, + moduleConnectionMap + ); + prepareInput(see_px, + see_py, + see_pz, + see_dxy, + see_dz, + see_ptErr, + see_etaErr, + see_stateTrajGlbX, + see_stateTrajGlbY, + see_stateTrajGlbZ, + see_stateTrajGlbPx, + see_stateTrajGlbPy, + see_stateTrajGlbPz, + see_q, + see_hitIdx, + ph2_detId, + ph2_x, + ph2_y, + ph2_z); + + event.addHitToEvent(in_trkX_, in_trkY_, in_trkZ_, in_hitId_, in_hitIdxs_); + event.addPixelSegmentToEvent(in_hitIndices_vec0_, + in_hitIndices_vec1_, + in_hitIndices_vec2_, + in_hitIndices_vec3_, + in_deltaPhi_vec_, + in_ptIn_vec_, + in_ptErr_vec_, + in_px_vec_, + in_py_vec_, + in_pz_vec_, + in_eta_vec_, + in_etaErr_vec_, + in_phi_vec_, + in_charge_vec_, + in_seedIdx_vec_, + in_superbin_vec_, + in_pixelType_vec_, + in_isQuad_vec_); + event.createMiniDoublets(); + if (verbose) { + printf("# of Mini-doublets produced: %d\n", event.getNumberOfMiniDoublets()); + printf("# of Mini-doublets produced barrel layer 1: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(0)); + printf("# of Mini-doublets produced barrel layer 2: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(1)); + printf("# of Mini-doublets produced barrel layer 3: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(2)); + printf("# of Mini-doublets produced barrel layer 4: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(3)); + printf("# of Mini-doublets produced barrel layer 5: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(4)); + printf("# of Mini-doublets produced barrel layer 6: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(5)); + printf("# of Mini-doublets produced endcap layer 1: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(0)); + printf("# of Mini-doublets produced endcap layer 2: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(1)); + printf("# of Mini-doublets produced endcap layer 3: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(2)); + printf("# of Mini-doublets produced endcap layer 4: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(3)); + printf("# of Mini-doublets produced endcap layer 5: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(4)); + } + + event.createSegmentsWithModuleMap(); + if (verbose) { + printf("# of Segments produced: %d\n", event.getNumberOfSegments()); + printf("# of Segments produced layer 1-2: %d\n", event.getNumberOfSegmentsByLayerBarrel(0)); + printf("# of Segments produced layer 2-3: %d\n", event.getNumberOfSegmentsByLayerBarrel(1)); + printf("# of Segments produced layer 3-4: %d\n", event.getNumberOfSegmentsByLayerBarrel(2)); + printf("# of Segments produced layer 4-5: %d\n", event.getNumberOfSegmentsByLayerBarrel(3)); + printf("# of Segments produced layer 5-6: %d\n", event.getNumberOfSegmentsByLayerBarrel(4)); + printf("# of Segments produced endcap layer 1: %d\n", event.getNumberOfSegmentsByLayerEndcap(0)); + printf("# of Segments produced endcap layer 2: %d\n", event.getNumberOfSegmentsByLayerEndcap(1)); + printf("# of Segments produced endcap layer 3: %d\n", event.getNumberOfSegmentsByLayerEndcap(2)); + printf("# of Segments produced endcap layer 4: %d\n", event.getNumberOfSegmentsByLayerEndcap(3)); + printf("# of Segments produced endcap layer 5: %d\n", event.getNumberOfSegmentsByLayerEndcap(4)); + } + + event.createTriplets(); + if (verbose) { + printf("# of T3s produced: %d\n", event.getNumberOfTriplets()); + printf("# of T3s produced layer 1-2-3: %d\n", event.getNumberOfTripletsByLayerBarrel(0)); + printf("# of T3s produced layer 2-3-4: %d\n", event.getNumberOfTripletsByLayerBarrel(1)); + printf("# of T3s produced layer 3-4-5: %d\n", event.getNumberOfTripletsByLayerBarrel(2)); + printf("# of T3s produced layer 4-5-6: %d\n", event.getNumberOfTripletsByLayerBarrel(3)); + printf("# of T3s produced endcap layer 1-2-3: %d\n", event.getNumberOfTripletsByLayerEndcap(0)); + printf("# of T3s produced endcap layer 2-3-4: %d\n", event.getNumberOfTripletsByLayerEndcap(1)); + printf("# of T3s produced endcap layer 3-4-5: %d\n", event.getNumberOfTripletsByLayerEndcap(2)); + printf("# of T3s produced endcap layer 1: %d\n", event.getNumberOfTripletsByLayerEndcap(0)); + printf("# of T3s produced endcap layer 2: %d\n", event.getNumberOfTripletsByLayerEndcap(1)); + printf("# of T3s produced endcap layer 3: %d\n", event.getNumberOfTripletsByLayerEndcap(2)); + printf("# of T3s produced endcap layer 4: %d\n", event.getNumberOfTripletsByLayerEndcap(3)); + printf("# of T3s produced endcap layer 5: %d\n", event.getNumberOfTripletsByLayerEndcap(4)); + } + + event.createQuintuplets(); + if (verbose) { + printf("# of Quintuplets produced: %d\n", event.getNumberOfQuintuplets()); + printf("# of Quintuplets produced layer 1-2-3-4-5-6: %d\n", event.getNumberOfQuintupletsByLayerBarrel(0)); + printf("# of Quintuplets produced layer 2: %d\n", event.getNumberOfQuintupletsByLayerBarrel(1)); + printf("# of Quintuplets produced layer 3: %d\n", event.getNumberOfQuintupletsByLayerBarrel(2)); + printf("# of Quintuplets produced layer 4: %d\n", event.getNumberOfQuintupletsByLayerBarrel(3)); + printf("# of Quintuplets produced layer 5: %d\n", event.getNumberOfQuintupletsByLayerBarrel(4)); + printf("# of Quintuplets produced layer 6: %d\n", event.getNumberOfQuintupletsByLayerBarrel(5)); + printf("# of Quintuplets produced endcap layer 1: %d\n", event.getNumberOfQuintupletsByLayerEndcap(0)); + printf("# of Quintuplets produced endcap layer 2: %d\n", event.getNumberOfQuintupletsByLayerEndcap(1)); + printf("# of Quintuplets produced endcap layer 3: %d\n", event.getNumberOfQuintupletsByLayerEndcap(2)); + printf("# of Quintuplets produced endcap layer 4: %d\n", event.getNumberOfQuintupletsByLayerEndcap(3)); + printf("# of Quintuplets produced endcap layer 5: %d\n", event.getNumberOfQuintupletsByLayerEndcap(4)); + } + + event.pixelLineSegmentCleaning(); + + event.createPixelQuintuplets(); + if (verbose) + printf("# of Pixel Quintuplets produced: %d\n", event.getNumberOfPixelQuintuplets()); + event.createPixelTriplets(); + if (verbose) + printf("# of Pixel T3s produced: %d\n", event.getNumberOfPixelTriplets()); + + event.createTrackCandidates(); + if (verbose) { + printf("# of TrackCandidates produced: %d\n", event.getNumberOfTrackCandidates()); + printf(" # of Pixel TrackCandidates produced: %d\n", event.getNumberOfPixelTrackCandidates()); + printf(" # of pT5 TrackCandidates produced: %d\n", event.getNumberOfPT5TrackCandidates()); + printf(" # of pT3 TrackCandidates produced: %d\n", event.getNumberOfPT3TrackCandidates()); + printf(" # of pLS TrackCandidates produced: %d\n", event.getNumberOfPLSTrackCandidates()); + printf(" # of T5 TrackCandidates produced: %d\n", event.getNumberOfT5TrackCandidates()); + } + + getOutput(event); + + event.resetEvent(); +} + +namespace { + XYZVector calculateR3FromPCA(const XYZVector& p3, const float dxy, const float dz) { + const float pt = p3.rho(); + const float p = p3.r(); + const float vz = dz * pt * pt / p / p; + + const float vx = -dxy * p3.y() / pt - p3.x() / p * p3.z() / p * dz; + const float vy = dxy * p3.x() / pt - p3.y() / p * p3.z() / p * dz; + return {vx, vy, vz}; + } } // namespace -// void SDL::LST::loadAndFillES(SDL::QueueAcc& queue, struct modulesBuffer* modules) { -// SDL::MapPLStoLayer pLStoLayer; -// SDL::Dev const& devAccIn = alpaka::getDev(queue); -// ::loadMaps(devAccIn, queue, pLStoLayer); - -// auto path = -// get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); -// if (SDL::Globals::modulesBuffers == nullptr) { -// SDL::Globals::modulesBuffers = new SDL::modulesBuffer(devAccIn); -// } -// if (SDL::Globals::pixelMapping == nullptr) { -// SDL::Globals::pixelMapping = std::make_shared(); -// } -// SDL::loadModulesFromFile(modules, -// SDL::Globals::nModules, -// SDL::Globals::nLowerModules, -// *SDL::Globals::pixelMapping, -// queue, -// path.c_str(), -// pLStoLayer); -// } - -// void SDL::LST::run(SDL::QueueAcc& queue, -// uint16_t nModules, -// uint16_t nLowerModules, -// std::shared_ptr> modulesBuffers, -// std::shared_ptr pixelMapping, -// std::shared_ptr> endcapGeometry, -// std::shared_ptr> tiltedGeometry, -// std::shared_ptr> moduleConnectionMap, -// bool verbose, -// const std::vector see_px, -// const std::vector see_py, -// const std::vector see_pz, -// const std::vector see_dxy, -// const std::vector see_dz, -// const std::vector see_ptErr, -// const std::vector see_etaErr, -// const std::vector see_stateTrajGlbX, -// const std::vector see_stateTrajGlbY, -// const std::vector see_stateTrajGlbZ, -// const std::vector see_stateTrajGlbPx, -// const std::vector see_stateTrajGlbPy, -// const std::vector see_stateTrajGlbPz, -// const std::vector see_q, -// const std::vector> see_hitIdx, -// const std::vector ph2_detId, -// const std::vector ph2_x, -// const std::vector ph2_y, -// const std::vector ph2_z) { -// auto event = SDL::Event( -// verbose, -// queue, -// nModules, -// nLowerModules, -// modulesBuffers, -// pixelMapping, -// endcapGeometry, -// tiltedGeometry, -// moduleConnectionMap -// ); -// prepareInput(see_px, -// see_py, -// see_pz, -// see_dxy, -// see_dz, -// see_ptErr, -// see_etaErr, -// see_stateTrajGlbX, -// see_stateTrajGlbY, -// see_stateTrajGlbZ, -// see_stateTrajGlbPx, -// see_stateTrajGlbPy, -// see_stateTrajGlbPz, -// see_q, -// see_hitIdx, -// ph2_detId, -// ph2_x, -// ph2_y, -// ph2_z); - -// event.addHitToEvent(in_trkX_, in_trkY_, in_trkZ_, in_hitId_, in_hitIdxs_); -// event.addPixelSegmentToEvent(in_hitIndices_vec0_, -// in_hitIndices_vec1_, -// in_hitIndices_vec2_, -// in_hitIndices_vec3_, -// in_deltaPhi_vec_, -// in_ptIn_vec_, -// in_ptErr_vec_, -// in_px_vec_, -// in_py_vec_, -// in_pz_vec_, -// in_eta_vec_, -// in_etaErr_vec_, -// in_phi_vec_, -// in_charge_vec_, -// in_seedIdx_vec_, -// in_superbin_vec_, -// in_pixelType_vec_, -// in_isQuad_vec_); -// event.createMiniDoublets(); -// if (verbose) { -// printf("# of Mini-doublets produced: %d\n", event.getNumberOfMiniDoublets()); -// printf("# of Mini-doublets produced barrel layer 1: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(0)); -// printf("# of Mini-doublets produced barrel layer 2: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(1)); -// printf("# of Mini-doublets produced barrel layer 3: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(2)); -// printf("# of Mini-doublets produced barrel layer 4: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(3)); -// printf("# of Mini-doublets produced barrel layer 5: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(4)); -// printf("# of Mini-doublets produced barrel layer 6: %d\n", event.getNumberOfMiniDoubletsByLayerBarrel(5)); -// printf("# of Mini-doublets produced endcap layer 1: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(0)); -// printf("# of Mini-doublets produced endcap layer 2: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(1)); -// printf("# of Mini-doublets produced endcap layer 3: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(2)); -// printf("# of Mini-doublets produced endcap layer 4: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(3)); -// printf("# of Mini-doublets produced endcap layer 5: %d\n", event.getNumberOfMiniDoubletsByLayerEndcap(4)); -// } - -// event.createSegmentsWithModuleMap(); -// if (verbose) { -// printf("# of Segments produced: %d\n", event.getNumberOfSegments()); -// printf("# of Segments produced layer 1-2: %d\n", event.getNumberOfSegmentsByLayerBarrel(0)); -// printf("# of Segments produced layer 2-3: %d\n", event.getNumberOfSegmentsByLayerBarrel(1)); -// printf("# of Segments produced layer 3-4: %d\n", event.getNumberOfSegmentsByLayerBarrel(2)); -// printf("# of Segments produced layer 4-5: %d\n", event.getNumberOfSegmentsByLayerBarrel(3)); -// printf("# of Segments produced layer 5-6: %d\n", event.getNumberOfSegmentsByLayerBarrel(4)); -// printf("# of Segments produced endcap layer 1: %d\n", event.getNumberOfSegmentsByLayerEndcap(0)); -// printf("# of Segments produced endcap layer 2: %d\n", event.getNumberOfSegmentsByLayerEndcap(1)); -// printf("# of Segments produced endcap layer 3: %d\n", event.getNumberOfSegmentsByLayerEndcap(2)); -// printf("# of Segments produced endcap layer 4: %d\n", event.getNumberOfSegmentsByLayerEndcap(3)); -// printf("# of Segments produced endcap layer 5: %d\n", event.getNumberOfSegmentsByLayerEndcap(4)); -// } - -// event.createTriplets(); -// if (verbose) { -// printf("# of T3s produced: %d\n", event.getNumberOfTriplets()); -// printf("# of T3s produced layer 1-2-3: %d\n", event.getNumberOfTripletsByLayerBarrel(0)); -// printf("# of T3s produced layer 2-3-4: %d\n", event.getNumberOfTripletsByLayerBarrel(1)); -// printf("# of T3s produced layer 3-4-5: %d\n", event.getNumberOfTripletsByLayerBarrel(2)); -// printf("# of T3s produced layer 4-5-6: %d\n", event.getNumberOfTripletsByLayerBarrel(3)); -// printf("# of T3s produced endcap layer 1-2-3: %d\n", event.getNumberOfTripletsByLayerEndcap(0)); -// printf("# of T3s produced endcap layer 2-3-4: %d\n", event.getNumberOfTripletsByLayerEndcap(1)); -// printf("# of T3s produced endcap layer 3-4-5: %d\n", event.getNumberOfTripletsByLayerEndcap(2)); -// printf("# of T3s produced endcap layer 1: %d\n", event.getNumberOfTripletsByLayerEndcap(0)); -// printf("# of T3s produced endcap layer 2: %d\n", event.getNumberOfTripletsByLayerEndcap(1)); -// printf("# of T3s produced endcap layer 3: %d\n", event.getNumberOfTripletsByLayerEndcap(2)); -// printf("# of T3s produced endcap layer 4: %d\n", event.getNumberOfTripletsByLayerEndcap(3)); -// printf("# of T3s produced endcap layer 5: %d\n", event.getNumberOfTripletsByLayerEndcap(4)); -// } - -// event.createQuintuplets(); -// if (verbose) { -// printf("# of Quintuplets produced: %d\n", event.getNumberOfQuintuplets()); -// printf("# of Quintuplets produced layer 1-2-3-4-5-6: %d\n", event.getNumberOfQuintupletsByLayerBarrel(0)); -// printf("# of Quintuplets produced layer 2: %d\n", event.getNumberOfQuintupletsByLayerBarrel(1)); -// printf("# of Quintuplets produced layer 3: %d\n", event.getNumberOfQuintupletsByLayerBarrel(2)); -// printf("# of Quintuplets produced layer 4: %d\n", event.getNumberOfQuintupletsByLayerBarrel(3)); -// printf("# of Quintuplets produced layer 5: %d\n", event.getNumberOfQuintupletsByLayerBarrel(4)); -// printf("# of Quintuplets produced layer 6: %d\n", event.getNumberOfQuintupletsByLayerBarrel(5)); -// printf("# of Quintuplets produced endcap layer 1: %d\n", event.getNumberOfQuintupletsByLayerEndcap(0)); -// printf("# of Quintuplets produced endcap layer 2: %d\n", event.getNumberOfQuintupletsByLayerEndcap(1)); -// printf("# of Quintuplets produced endcap layer 3: %d\n", event.getNumberOfQuintupletsByLayerEndcap(2)); -// printf("# of Quintuplets produced endcap layer 4: %d\n", event.getNumberOfQuintupletsByLayerEndcap(3)); -// printf("# of Quintuplets produced endcap layer 5: %d\n", event.getNumberOfQuintupletsByLayerEndcap(4)); -// } - -// event.pixelLineSegmentCleaning(); - -// event.createPixelQuintuplets(); -// if (verbose) -// printf("# of Pixel Quintuplets produced: %d\n", event.getNumberOfPixelQuintuplets()); - -// event.createPixelTriplets(); -// if (verbose) -// printf("# of Pixel T3s produced: %d\n", event.getNumberOfPixelTriplets()); - -// event.createTrackCandidates(); -// if (verbose) { -// printf("# of TrackCandidates produced: %d\n", event.getNumberOfTrackCandidates()); -// printf(" # of Pixel TrackCandidates produced: %d\n", event.getNumberOfPixelTrackCandidates()); -// printf(" # of pT5 TrackCandidates produced: %d\n", event.getNumberOfPT5TrackCandidates()); -// printf(" # of pT3 TrackCandidates produced: %d\n", event.getNumberOfPT3TrackCandidates()); -// printf(" # of pLS TrackCandidates produced: %d\n", event.getNumberOfPLSTrackCandidates()); -// printf(" # of T5 TrackCandidates produced: %d\n", event.getNumberOfT5TrackCandidates()); -// } - -// getOutput(event); - -// event.resetEvent(); -// } - -// namespace { -// XYZVector calculateR3FromPCA(const XYZVector& p3, const float dxy, const float dz) { -// const float pt = p3.rho(); -// const float p = p3.r(); -// const float vz = dz * pt * pt / p / p; - -// const float vx = -dxy * p3.y() / pt - p3.x() / p * p3.z() / p * dz; -// const float vy = dxy * p3.x() / pt - p3.y() / p * p3.z() / p * dz; -// return {vx, vy, vz}; -// } -// } // namespace - -// void SDL::LST::prepareInput(const std::vector see_px, -// const std::vector see_py, -// const std::vector see_pz, -// const std::vector see_dxy, -// const std::vector see_dz, -// const std::vector see_ptErr, -// const std::vector see_etaErr, -// const std::vector see_stateTrajGlbX, -// const std::vector see_stateTrajGlbY, -// const std::vector see_stateTrajGlbZ, -// const std::vector see_stateTrajGlbPx, -// const std::vector see_stateTrajGlbPy, -// const std::vector see_stateTrajGlbPz, -// const std::vector see_q, -// const std::vector> see_hitIdx, -// const std::vector ph2_detId, -// const std::vector ph2_x, -// const std::vector ph2_y, -// const std::vector ph2_z) { -// unsigned int count = 0; -// auto n_see = see_stateTrajGlbPx.size(); -// std::vector px_vec; -// px_vec.reserve(n_see); -// std::vector py_vec; -// py_vec.reserve(n_see); -// std::vector pz_vec; -// pz_vec.reserve(n_see); -// std::vector hitIndices_vec0; -// hitIndices_vec0.reserve(n_see); -// std::vector hitIndices_vec1; -// hitIndices_vec1.reserve(n_see); -// std::vector hitIndices_vec2; -// hitIndices_vec2.reserve(n_see); -// std::vector hitIndices_vec3; -// hitIndices_vec3.reserve(n_see); -// std::vector ptIn_vec; -// ptIn_vec.reserve(n_see); -// std::vector ptErr_vec; -// ptErr_vec.reserve(n_see); -// std::vector etaErr_vec; -// etaErr_vec.reserve(n_see); -// std::vector eta_vec; -// eta_vec.reserve(n_see); -// std::vector phi_vec; -// phi_vec.reserve(n_see); -// std::vector charge_vec; -// charge_vec.reserve(n_see); -// std::vector seedIdx_vec; -// seedIdx_vec.reserve(n_see); -// std::vector deltaPhi_vec; -// deltaPhi_vec.reserve(n_see); -// std::vector trkX = ph2_x; -// std::vector trkY = ph2_y; -// std::vector trkZ = ph2_z; -// std::vector hitId = ph2_detId; -// std::vector hitIdxs(ph2_detId.size()); - -// std::vector superbin_vec; -// std::vector pixelType_vec; -// std::vector isQuad_vec; -// std::iota(hitIdxs.begin(), hitIdxs.end(), 0); -// const int hit_size = trkX.size(); - -// for (size_t iSeed = 0; iSeed < n_see; iSeed++) { -// XYZVector p3LH(see_stateTrajGlbPx[iSeed], see_stateTrajGlbPy[iSeed], see_stateTrajGlbPz[iSeed]); -// XYZVector p3LH_helper(see_stateTrajGlbPx[iSeed], see_stateTrajGlbPy[iSeed], see_stateTrajGlbPz[iSeed]); -// float ptIn = p3LH.rho(); -// float eta = p3LH.eta(); -// float ptErr = see_ptErr[iSeed]; - -// if ((ptIn > 0.8 - 2 * ptErr)) { -// XYZVector r3LH(see_stateTrajGlbX[iSeed], see_stateTrajGlbY[iSeed], see_stateTrajGlbZ[iSeed]); -// XYZVector p3PCA(see_px[iSeed], see_py[iSeed], see_pz[iSeed]); -// XYZVector r3PCA(calculateR3FromPCA(p3PCA, see_dxy[iSeed], see_dz[iSeed])); - -// float pixelSegmentDeltaPhiChange = (r3LH - p3LH_helper).phi(); //FIXME: this looks like a bug -// float etaErr = see_etaErr[iSeed]; -// float px = p3LH.x(); -// float py = p3LH.y(); -// float pz = p3LH.z(); - -// int charge = see_q[iSeed]; -// int pixtype = -1; - -// if (ptIn >= 2.0) -// pixtype = 0; -// else if (ptIn >= (0.8 - 2 * ptErr) and ptIn < 2.0) { -// if (pixelSegmentDeltaPhiChange >= 0) -// pixtype = 1; -// else -// pixtype = 2; -// } else -// continue; - -// unsigned int hitIdx0 = hit_size + count; -// count++; -// unsigned int hitIdx1 = hit_size + count; -// count++; -// unsigned int hitIdx2 = hit_size + count; -// count++; -// unsigned int hitIdx3; -// if (see_hitIdx[iSeed].size() <= 3) -// hitIdx3 = hitIdx2; -// else { -// hitIdx3 = hit_size + count; -// count++; -// } - -// trkX.push_back(r3PCA.x()); -// trkY.push_back(r3PCA.y()); -// trkZ.push_back(r3PCA.z()); -// trkX.push_back(p3PCA.rho()); -// float p3PCA_Eta = p3PCA.eta(); -// trkY.push_back(p3PCA_Eta); -// float p3PCA_Phi = p3PCA.phi(); -// trkZ.push_back(p3PCA_Phi); -// trkX.push_back(r3LH.x()); -// trkY.push_back(r3LH.y()); -// trkZ.push_back(r3LH.z()); -// hitId.push_back(1); -// hitId.push_back(1); -// hitId.push_back(1); -// if (see_hitIdx[iSeed].size() > 3) { -// trkX.push_back(r3LH.x()); -// trkY.push_back(see_dxy[iSeed]); -// trkZ.push_back(see_dz[iSeed]); -// hitId.push_back(1); -// } -// px_vec.push_back(px); -// py_vec.push_back(py); -// pz_vec.push_back(pz); - -// hitIndices_vec0.push_back(hitIdx0); -// hitIndices_vec1.push_back(hitIdx1); -// hitIndices_vec2.push_back(hitIdx2); -// hitIndices_vec3.push_back(hitIdx3); -// ptIn_vec.push_back(ptIn); -// ptErr_vec.push_back(ptErr); -// etaErr_vec.push_back(etaErr); -// eta_vec.push_back(eta); -// float phi = p3LH.phi(); -// phi_vec.push_back(phi); -// charge_vec.push_back(charge); -// seedIdx_vec.push_back(iSeed); -// deltaPhi_vec.push_back(pixelSegmentDeltaPhiChange); - -// hitIdxs.push_back(see_hitIdx[iSeed][0]); -// hitIdxs.push_back(see_hitIdx[iSeed][1]); -// hitIdxs.push_back(see_hitIdx[iSeed][2]); -// char isQuad = false; -// if (see_hitIdx[iSeed].size() > 3) { -// isQuad = true; -// hitIdxs.push_back(see_hitIdx[iSeed][3]); -// } -// float neta = 25.; -// float nphi = 72.; -// float nz = 25.; -// int etabin = (p3PCA_Eta + 2.6) / ((2 * 2.6) / neta); -// int phibin = (p3PCA_Phi + 3.14159265358979323846) / ((2. * 3.14159265358979323846) / nphi); -// int dzbin = (see_dz[iSeed] + 30) / (2 * 30 / nz); -// int isuperbin = (nz * nphi) * etabin + (nz)*phibin + dzbin; -// superbin_vec.push_back(isuperbin); -// pixelType_vec.push_back(pixtype); -// isQuad_vec.push_back(isQuad); -// } -// } - -// in_trkX_ = trkX; -// in_trkY_ = trkY; -// in_trkZ_ = trkZ; -// in_hitId_ = hitId; -// in_hitIdxs_ = hitIdxs; -// in_hitIndices_vec0_ = hitIndices_vec0; -// in_hitIndices_vec1_ = hitIndices_vec1; -// in_hitIndices_vec2_ = hitIndices_vec2; -// in_hitIndices_vec3_ = hitIndices_vec3; -// in_deltaPhi_vec_ = deltaPhi_vec; -// in_ptIn_vec_ = ptIn_vec; -// in_ptErr_vec_ = ptErr_vec; -// in_px_vec_ = px_vec; -// in_py_vec_ = py_vec; -// in_pz_vec_ = pz_vec; -// in_eta_vec_ = eta_vec; -// in_etaErr_vec_ = etaErr_vec; -// in_phi_vec_ = phi_vec; -// in_charge_vec_ = charge_vec; -// in_seedIdx_vec_ = seedIdx_vec; -// in_superbin_vec_ = superbin_vec; -// in_pixelType_vec_ = pixelType_vec; -// in_isQuad_vec_ = isQuad_vec; -// } - -// void SDL::LST::getOutput(SDL::Event& event) { -// std::vector> tc_hitIdxs; -// std::vector tc_len; -// std::vector tc_seedIdx; -// std::vector tc_trackCandidateType; - -// SDL::hitsBuffer& hitsInGPU = (*event.getHitsInCMSSW()); -// SDL::trackCandidatesBuffer& trackCandidatesInGPU = (*event.getTrackCandidatesInCMSSW()); - -// unsigned int nTrackCandidates = *trackCandidatesInGPU.nTrackCandidates; -// for (unsigned int idx = 0; idx < nTrackCandidates; idx++) { -// short trackCandidateType = trackCandidatesInGPU.trackCandidateType[idx]; -// std::vector hit_idx = -// getHitIdxs(trackCandidateType, idx, trackCandidatesInGPU.hitIndices, hitsInGPU.idxs); - -// tc_hitIdxs.push_back(hit_idx); -// tc_len.push_back(hit_idx.size()); -// tc_seedIdx.push_back(trackCandidatesInGPU.pixelSeedIndex[idx]); -// tc_trackCandidateType.push_back(trackCandidateType); -// } - -// out_tc_hitIdxs_ = tc_hitIdxs; -// out_tc_len_ = tc_len; -// out_tc_seedIdx_ = tc_seedIdx; -// out_tc_trackCandidateType_ = tc_trackCandidateType; -// } - -// std::vector SDL::LST::getHitIdxs(const short trackCandidateType, -// const unsigned int TCIdx, -// const unsigned int* TCHitIndices, -// const unsigned int* hitIndices) { -// std::vector hits; - -// unsigned int maxNHits = 0; -// if (trackCandidateType == 7) -// maxNHits = 14; // pT5 -// else if (trackCandidateType == 5) -// maxNHits = 10; // pT3 -// else if (trackCandidateType == 4) -// maxNHits = 10; // T5 -// else if (trackCandidateType == 8) -// maxNHits = 4; // pLS - -// for (unsigned int i = 0; i < maxNHits; i++) { -// unsigned int hitIdxInGPU = TCHitIndices[14 * TCIdx + i]; -// unsigned int hitIdx = -// (trackCandidateType == 8) -// ? hitIdxInGPU -// : hitIndices[hitIdxInGPU]; // Hit indices are stored differently in the standalone for pLS. - -// // For p objects, the 3rd and 4th hit maybe the same, -// // due to the way pLS hits are stored in the standalone. -// // This is because pixel seeds can be either triplets or quadruplets. -// if (trackCandidateType != 4 && hits.size() == 3 && hits.back() == hitIdx) // Remove duplicate 4th hits. -// continue; - -// hits.push_back(hitIdx); -// } - -// return hits; -// } +void SDL::LST::prepareInput(const std::vector see_px, + const std::vector see_py, + const std::vector see_pz, + const std::vector see_dxy, + const std::vector see_dz, + const std::vector see_ptErr, + const std::vector see_etaErr, + const std::vector see_stateTrajGlbX, + const std::vector see_stateTrajGlbY, + const std::vector see_stateTrajGlbZ, + const std::vector see_stateTrajGlbPx, + const std::vector see_stateTrajGlbPy, + const std::vector see_stateTrajGlbPz, + const std::vector see_q, + const std::vector> see_hitIdx, + const std::vector ph2_detId, + const std::vector ph2_x, + const std::vector ph2_y, + const std::vector ph2_z) { + unsigned int count = 0; + auto n_see = see_stateTrajGlbPx.size(); + std::vector px_vec; + px_vec.reserve(n_see); + std::vector py_vec; + py_vec.reserve(n_see); + std::vector pz_vec; + pz_vec.reserve(n_see); + std::vector hitIndices_vec0; + hitIndices_vec0.reserve(n_see); + std::vector hitIndices_vec1; + hitIndices_vec1.reserve(n_see); + std::vector hitIndices_vec2; + hitIndices_vec2.reserve(n_see); + std::vector hitIndices_vec3; + hitIndices_vec3.reserve(n_see); + std::vector ptIn_vec; + ptIn_vec.reserve(n_see); + std::vector ptErr_vec; + ptErr_vec.reserve(n_see); + std::vector etaErr_vec; + etaErr_vec.reserve(n_see); + std::vector eta_vec; + eta_vec.reserve(n_see); + std::vector phi_vec; + phi_vec.reserve(n_see); + std::vector charge_vec; + charge_vec.reserve(n_see); + std::vector seedIdx_vec; + seedIdx_vec.reserve(n_see); + std::vector deltaPhi_vec; + deltaPhi_vec.reserve(n_see); + std::vector trkX = ph2_x; + std::vector trkY = ph2_y; + std::vector trkZ = ph2_z; + std::vector hitId = ph2_detId; + std::vector hitIdxs(ph2_detId.size()); + + std::vector superbin_vec; + std::vector pixelType_vec; + std::vector isQuad_vec; + std::iota(hitIdxs.begin(), hitIdxs.end(), 0); + const int hit_size = trkX.size(); + + for (size_t iSeed = 0; iSeed < n_see; iSeed++) { + XYZVector p3LH(see_stateTrajGlbPx[iSeed], see_stateTrajGlbPy[iSeed], see_stateTrajGlbPz[iSeed]); + XYZVector p3LH_helper(see_stateTrajGlbPx[iSeed], see_stateTrajGlbPy[iSeed], see_stateTrajGlbPz[iSeed]); + float ptIn = p3LH.rho(); + float eta = p3LH.eta(); + float ptErr = see_ptErr[iSeed]; + + if ((ptIn > 0.8 - 2 * ptErr)) { + XYZVector r3LH(see_stateTrajGlbX[iSeed], see_stateTrajGlbY[iSeed], see_stateTrajGlbZ[iSeed]); + XYZVector p3PCA(see_px[iSeed], see_py[iSeed], see_pz[iSeed]); + XYZVector r3PCA(calculateR3FromPCA(p3PCA, see_dxy[iSeed], see_dz[iSeed])); + + float pixelSegmentDeltaPhiChange = (r3LH - p3LH_helper).phi(); //FIXME: this looks like a bug + float etaErr = see_etaErr[iSeed]; + float px = p3LH.x(); + float py = p3LH.y(); + float pz = p3LH.z(); + + int charge = see_q[iSeed]; + int pixtype = -1; + + if (ptIn >= 2.0) + pixtype = 0; + else if (ptIn >= (0.8 - 2 * ptErr) and ptIn < 2.0) { + if (pixelSegmentDeltaPhiChange >= 0) + pixtype = 1; + else + pixtype = 2; + } else + continue; + + unsigned int hitIdx0 = hit_size + count; + count++; + unsigned int hitIdx1 = hit_size + count; + count++; + unsigned int hitIdx2 = hit_size + count; + count++; + unsigned int hitIdx3; + if (see_hitIdx[iSeed].size() <= 3) + hitIdx3 = hitIdx2; + else { + hitIdx3 = hit_size + count; + count++; + } + + trkX.push_back(r3PCA.x()); + trkY.push_back(r3PCA.y()); + trkZ.push_back(r3PCA.z()); + trkX.push_back(p3PCA.rho()); + float p3PCA_Eta = p3PCA.eta(); + trkY.push_back(p3PCA_Eta); + float p3PCA_Phi = p3PCA.phi(); + trkZ.push_back(p3PCA_Phi); + trkX.push_back(r3LH.x()); + trkY.push_back(r3LH.y()); + trkZ.push_back(r3LH.z()); + hitId.push_back(1); + hitId.push_back(1); + hitId.push_back(1); + if (see_hitIdx[iSeed].size() > 3) { + trkX.push_back(r3LH.x()); + trkY.push_back(see_dxy[iSeed]); + trkZ.push_back(see_dz[iSeed]); + hitId.push_back(1); + } + px_vec.push_back(px); + py_vec.push_back(py); + pz_vec.push_back(pz); + + hitIndices_vec0.push_back(hitIdx0); + hitIndices_vec1.push_back(hitIdx1); + hitIndices_vec2.push_back(hitIdx2); + hitIndices_vec3.push_back(hitIdx3); + ptIn_vec.push_back(ptIn); + ptErr_vec.push_back(ptErr); + etaErr_vec.push_back(etaErr); + eta_vec.push_back(eta); + float phi = p3LH.phi(); + phi_vec.push_back(phi); + charge_vec.push_back(charge); + seedIdx_vec.push_back(iSeed); + deltaPhi_vec.push_back(pixelSegmentDeltaPhiChange); + + hitIdxs.push_back(see_hitIdx[iSeed][0]); + hitIdxs.push_back(see_hitIdx[iSeed][1]); + hitIdxs.push_back(see_hitIdx[iSeed][2]); + char isQuad = false; + if (see_hitIdx[iSeed].size() > 3) { + isQuad = true; + hitIdxs.push_back(see_hitIdx[iSeed][3]); + } + float neta = 25.; + float nphi = 72.; + float nz = 25.; + int etabin = (p3PCA_Eta + 2.6) / ((2 * 2.6) / neta); + int phibin = (p3PCA_Phi + 3.14159265358979323846) / ((2. * 3.14159265358979323846) / nphi); + int dzbin = (see_dz[iSeed] + 30) / (2 * 30 / nz); + int isuperbin = (nz * nphi) * etabin + (nz)*phibin + dzbin; + superbin_vec.push_back(isuperbin); + pixelType_vec.push_back(pixtype); + isQuad_vec.push_back(isQuad); + } + } + + in_trkX_ = trkX; + in_trkY_ = trkY; + in_trkZ_ = trkZ; + in_hitId_ = hitId; + in_hitIdxs_ = hitIdxs; + in_hitIndices_vec0_ = hitIndices_vec0; + in_hitIndices_vec1_ = hitIndices_vec1; + in_hitIndices_vec2_ = hitIndices_vec2; + in_hitIndices_vec3_ = hitIndices_vec3; + in_deltaPhi_vec_ = deltaPhi_vec; + in_ptIn_vec_ = ptIn_vec; + in_ptErr_vec_ = ptErr_vec; + in_px_vec_ = px_vec; + in_py_vec_ = py_vec; + in_pz_vec_ = pz_vec; + in_eta_vec_ = eta_vec; + in_etaErr_vec_ = etaErr_vec; + in_phi_vec_ = phi_vec; + in_charge_vec_ = charge_vec; + in_seedIdx_vec_ = seedIdx_vec; + in_superbin_vec_ = superbin_vec; + in_pixelType_vec_ = pixelType_vec; + in_isQuad_vec_ = isQuad_vec; +} + +void SDL::LST::getOutput(SDL::Event& event) { + std::vector> tc_hitIdxs; + std::vector tc_len; + std::vector tc_seedIdx; + std::vector tc_trackCandidateType; + + SDL::hitsBuffer& hitsInGPU = (*event.getHitsInCMSSW()); + SDL::trackCandidatesBuffer& trackCandidatesInGPU = (*event.getTrackCandidatesInCMSSW()); + + unsigned int nTrackCandidates = *trackCandidatesInGPU.nTrackCandidates; + for (unsigned int idx = 0; idx < nTrackCandidates; idx++) { + short trackCandidateType = trackCandidatesInGPU.trackCandidateType[idx]; + std::vector hit_idx = + getHitIdxs(trackCandidateType, idx, trackCandidatesInGPU.hitIndices, hitsInGPU.idxs); + + tc_hitIdxs.push_back(hit_idx); + tc_len.push_back(hit_idx.size()); + tc_seedIdx.push_back(trackCandidatesInGPU.pixelSeedIndex[idx]); + tc_trackCandidateType.push_back(trackCandidateType); + } + + out_tc_hitIdxs_ = tc_hitIdxs; + out_tc_len_ = tc_len; + out_tc_seedIdx_ = tc_seedIdx; + out_tc_trackCandidateType_ = tc_trackCandidateType; +} + +std::vector SDL::LST::getHitIdxs(const short trackCandidateType, + const unsigned int TCIdx, + const unsigned int* TCHitIndices, + const unsigned int* hitIndices) { + std::vector hits; + + unsigned int maxNHits = 0; + if (trackCandidateType == 7) + maxNHits = 14; // pT5 + else if (trackCandidateType == 5) + maxNHits = 10; // pT3 + else if (trackCandidateType == 4) + maxNHits = 10; // T5 + else if (trackCandidateType == 8) + maxNHits = 4; // pLS + + for (unsigned int i = 0; i < maxNHits; i++) { + unsigned int hitIdxInGPU = TCHitIndices[14 * TCIdx + i]; + unsigned int hitIdx = + (trackCandidateType == 8) + ? hitIdxInGPU + : hitIndices[hitIdxInGPU]; // Hit indices are stored differently in the standalone for pLS. + + // For p objects, the 3rd and 4th hit maybe the same, + // due to the way pLS hits are stored in the standalone. + // This is because pixel seeds can be either triplets or quadruplets. + if (trackCandidateType != 4 && hits.size() == 3 && hits.back() == hitIdx) // Remove duplicate 4th hits. + continue; + + hits.push_back(hitIdx); + } + + return hits; +} diff --git a/SDL/LST.h b/SDL/LST.h index 4c434c2f..d5199cca 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -20,6 +20,17 @@ namespace SDL { template struct modulesBuffer; + struct pixelMap; + + template + class EndcapGeometry; + + template + class TiltedGeometry; + + template + class ModuleConnectionMap; + template class LST; @@ -28,36 +39,43 @@ namespace SDL { public: LST() = default; - static void loadAndFillES(SDL::QueueAcc& queue, struct modulesBuffer* modules); - - // void run(SDL::QueueAcc& queue, - // uint16_t nModules, - // uint16_t nLowerModules, - // std::shared_ptr> modulesBuffers, - // std::shared_ptr pixelMapping, - // std::shared_ptr> endcapGeometry, - // std::shared_ptr> tiltedGeometry, - // std::shared_ptr> moduleConnectionMap, - // bool verbose, - // const std::vector see_px, - // const std::vector see_py, - // const std::vector see_pz, - // const std::vector see_dxy, - // const std::vector see_dz, - // const std::vector see_ptErr, - // const std::vector see_etaErr, - // const std::vector see_stateTrajGlbX, - // const std::vector see_stateTrajGlbY, - // const std::vector see_stateTrajGlbZ, - // const std::vector see_stateTrajGlbPx, - // const std::vector see_stateTrajGlbPy, - // const std::vector see_stateTrajGlbPz, - // const std::vector see_q, - // const std::vector> see_hitIdx, - // const std::vector ph2_detId, - // const std::vector ph2_x, - // const std::vector ph2_y, - // const std::vector ph2_z); + static void loadAndFillES(SDL::QueueAcc& queue, + uint16_t& nModules, + uint16_t& nLowerModules, + std::shared_ptr> modulesBuffers, + std::shared_ptr pixelMapping, + std::shared_ptr> endcapGeometry, + std::shared_ptr> tiltedGeometry, + std::shared_ptr> moduleConnectionMap); + + void run(SDL::QueueAcc& queue, + uint16_t nModules, + uint16_t nLowerModules, + std::shared_ptr> modulesBuffers, + std::shared_ptr pixelMapping, + std::shared_ptr> endcapGeometry, + std::shared_ptr> tiltedGeometry, + std::shared_ptr> moduleConnectionMap, + bool verbose, + const std::vector see_px, + const std::vector see_py, + const std::vector see_pz, + const std::vector see_dxy, + const std::vector see_dz, + const std::vector see_ptErr, + const std::vector see_etaErr, + const std::vector see_stateTrajGlbX, + const std::vector see_stateTrajGlbY, + const std::vector see_stateTrajGlbZ, + const std::vector see_stateTrajGlbPx, + const std::vector see_stateTrajGlbPy, + const std::vector see_stateTrajGlbPz, + const std::vector see_q, + const std::vector> see_hitIdx, + const std::vector ph2_detId, + const std::vector ph2_x, + const std::vector ph2_y, + const std::vector ph2_z); std::vector> hits() { return out_tc_hitIdxs_; } std::vector len() { return out_tc_len_; } std::vector seedIdx() { return out_tc_seedIdx_; } From 3091b056cc1675da4eae537476c20676af4a2f4d Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 14 May 2024 07:51:23 -0700 Subject: [PATCH 06/23] Format code --- SDL/LST.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/SDL/LST.cc b/SDL/LST.cc index f66f7bcd..7593c7f4 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -128,17 +128,15 @@ void SDL::LST::run(SDL::QueueAcc& queue, const std::vector ph2_x, const std::vector ph2_y, const std::vector ph2_z) { - auto event = SDL::Event( - verbose, - queue, - nModules, - nLowerModules, - modulesBuffers, - pixelMapping, - endcapGeometry, - tiltedGeometry, - moduleConnectionMap - ); + auto event = SDL::Event(verbose, + queue, + nModules, + nLowerModules, + modulesBuffers, + pixelMapping, + endcapGeometry, + tiltedGeometry, + moduleConnectionMap); prepareInput(see_px, see_py, see_pz, From 35347852daaeff9b1718a5a39550af63fd1002b4 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 14 May 2024 16:10:59 -0400 Subject: [PATCH 07/23] Removed unnecessary templates --- SDL/Event.cc | 4 ++-- SDL/Event.h | 12 ++++++------ SDL/LST.cc | 18 +++++++++--------- SDL/LST.h | 10 ++++------ SDL/ModuleConnectionMap.cc | 16 ++++++++-------- SDL/ModuleConnectionMap.h | 8 ++------ SDL/ModuleMethods.h | 6 +++--- SDL/TiltedGeometry.cc | 8 ++++---- SDL/TiltedGeometry.h | 5 +---- bin/sdl.cc | 4 ++-- code/core/AnalysisConfig.h | 2 +- code/core/trkCore.cc | 4 ++-- code/core/trkCore.h | 4 ++-- 13 files changed, 46 insertions(+), 55 deletions(-) diff --git a/SDL/Event.cc b/SDL/Event.cc index 0f3d3590..939e6800 100644 --- a/SDL/Event.cc +++ b/SDL/Event.cc @@ -156,8 +156,8 @@ void SDL::Event::initModules(QueueAcc& queue, struct modulesBuffer* modulesBuf, struct pixelMap* pixelMapping, EndcapGeometry* endcapGeometry, - TiltedGeometry* tiltedGeometry, - ModuleConnectionMap* moduleConnectionMap) { + TiltedGeometry* tiltedGeometry, + ModuleConnectionMap* moduleConnectionMap) { // nModules gets filled here loadModulesFromFile(queue, pLStoLayer, diff --git a/SDL/Event.h b/SDL/Event.h index a36aaa83..c1836ff4 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -90,8 +90,8 @@ namespace SDL { std::shared_ptr> modulesBuffers; std::shared_ptr pixelMapping; std::shared_ptr> endcapGeometry; - std::shared_ptr> tiltedGeometry; - std::shared_ptr> moduleConnectionMap; + std::shared_ptr tiltedGeometry; + std::shared_ptr moduleConnectionMap; public: // Constructor used for CMSSW integration. Uses an external queue. @@ -103,8 +103,8 @@ namespace SDL { std::shared_ptr> modulesBuffersIn, std::shared_ptr pixelMappingIn, std::shared_ptr> endcapGeometryIn, - std::shared_ptr> tiltedGeometryIn, - std::shared_ptr> moduleConnectionMapIn) + std::shared_ptr tiltedGeometryIn, + std::shared_ptr moduleConnectionMapIn) : queue(q), devAcc(alpaka::getDev(q)), devHost(cms::alpakatools::host()), @@ -220,8 +220,8 @@ namespace SDL { struct modulesBuffer* modulesBuf, struct pixelMap* pixelMapping, EndcapGeometry* endcapGeometry, - TiltedGeometry* tiltedGeometry, - ModuleConnectionMap* moduleConnectionMap); + TiltedGeometry* tiltedGeometry, + ModuleConnectionMap* moduleConnectionMap); }; } // namespace SDL diff --git a/SDL/LST.cc b/SDL/LST.cc index 7593c7f4..573c8db1 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -37,8 +37,8 @@ namespace { SDL::QueueAcc& queue, SDL::MapPLStoLayer& pLStoLayer, std::shared_ptr> endcapGeometry, - std::shared_ptr> tiltedGeometry, - std::shared_ptr> moduleConnectionMap) { + std::shared_ptr tiltedGeometry, + std::shared_ptr moduleConnectionMap) { // Module orientation information (DrDz or phi angles) auto endcap_geom = get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); @@ -62,13 +62,13 @@ namespace { auto connectData = connects[i].data(); path = pLSMapDir + connectData + ".bin"; - pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); path = pLSMapDir + "_pos" + connectData + ".bin"; - pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); path = pLSMapDir + "_neg" + connectData + ".bin"; - pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); } } @@ -80,8 +80,8 @@ void SDL::LST::loadAndFillES(SDL::QueueAcc& queue, std::shared_ptr> modulesBuf, std::shared_ptr pixelMapping, std::shared_ptr> endcapGeometry, - std::shared_ptr> tiltedGeometry, - std::shared_ptr> moduleConnectionMap) { + std::shared_ptr tiltedGeometry, + std::shared_ptr moduleConnectionMap) { SDL::MapPLStoLayer pLStoLayer; SDL::Dev const& devAccIn = alpaka::getDev(queue); ::loadMaps(devAccIn, queue, pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); @@ -106,8 +106,8 @@ void SDL::LST::run(SDL::QueueAcc& queue, std::shared_ptr> modulesBuffers, std::shared_ptr pixelMapping, std::shared_ptr> endcapGeometry, - std::shared_ptr> tiltedGeometry, - std::shared_ptr> moduleConnectionMap, + std::shared_ptr tiltedGeometry, + std::shared_ptr moduleConnectionMap, bool verbose, const std::vector see_px, const std::vector see_py, diff --git a/SDL/LST.h b/SDL/LST.h index d5199cca..1560ed7f 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -25,10 +25,8 @@ namespace SDL { template class EndcapGeometry; - template class TiltedGeometry; - template class ModuleConnectionMap; template @@ -45,8 +43,8 @@ namespace SDL { std::shared_ptr> modulesBuffers, std::shared_ptr pixelMapping, std::shared_ptr> endcapGeometry, - std::shared_ptr> tiltedGeometry, - std::shared_ptr> moduleConnectionMap); + std::shared_ptr tiltedGeometry, + std::shared_ptr moduleConnectionMap); void run(SDL::QueueAcc& queue, uint16_t nModules, @@ -54,8 +52,8 @@ namespace SDL { std::shared_ptr> modulesBuffers, std::shared_ptr pixelMapping, std::shared_ptr> endcapGeometry, - std::shared_ptr> tiltedGeometry, - std::shared_ptr> moduleConnectionMap, + std::shared_ptr tiltedGeometry, + std::shared_ptr moduleConnectionMap, bool verbose, const std::vector see_px, const std::vector see_py, diff --git a/SDL/ModuleConnectionMap.cc b/SDL/ModuleConnectionMap.cc index 9a1ee2de..e866aa5e 100644 --- a/SDL/ModuleConnectionMap.cc +++ b/SDL/ModuleConnectionMap.cc @@ -1,12 +1,12 @@ #include "ModuleConnectionMap.h" -SDL::ModuleConnectionMap::ModuleConnectionMap() {} +SDL::ModuleConnectionMap::ModuleConnectionMap() {} -SDL::ModuleConnectionMap::ModuleConnectionMap(std::string filename) { load(filename); } +SDL::ModuleConnectionMap::ModuleConnectionMap(std::string filename) { load(filename); } -SDL::ModuleConnectionMap::~ModuleConnectionMap() {} +SDL::ModuleConnectionMap::~ModuleConnectionMap() {} -void SDL::ModuleConnectionMap::load(std::string filename) { +void SDL::ModuleConnectionMap::load(std::string filename) { moduleConnections_.clear(); std::ifstream ifile(filename, std::ios::binary); @@ -49,7 +49,7 @@ void SDL::ModuleConnectionMap::load(std::string filename) { } } -void SDL::ModuleConnectionMap::add(std::string filename) { +void SDL::ModuleConnectionMap::add(std::string filename) { std::ifstream ifile; ifile.open(filename.c_str()); std::string line; @@ -81,7 +81,7 @@ void SDL::ModuleConnectionMap::add(std::string filename) { } } -void SDL::ModuleConnectionMap::print() { +void SDL::ModuleConnectionMap::print() { std::cout << "Printing ModuleConnectionMap" << std::endl; for (auto& pair : moduleConnections_) { unsigned int detid = pair.first; @@ -93,9 +93,9 @@ void SDL::ModuleConnectionMap::print() { } } -const std::vector& SDL::ModuleConnectionMap::getConnectedModuleDetIds(unsigned int detid) const { +const std::vector& SDL::ModuleConnectionMap::getConnectedModuleDetIds(unsigned int detid) const { static const std::vector dummy; auto const mList = moduleConnections_.find(detid); return mList != moduleConnections_.end() ? mList->second : dummy; } -int SDL::ModuleConnectionMap::size() const { return moduleConnections_.size(); } +int SDL::ModuleConnectionMap::size() const { return moduleConnections_.size(); } diff --git a/SDL/ModuleConnectionMap.h b/SDL/ModuleConnectionMap.h index 45d629a7..57e1a871 100644 --- a/SDL/ModuleConnectionMap.h +++ b/SDL/ModuleConnectionMap.h @@ -15,11 +15,7 @@ #endif namespace SDL { - //FIXME: move to non-alpaka single arch build - template - class ModuleConnectionMap; - template <> - class ModuleConnectionMap { + class ModuleConnectionMap { private: std::map> moduleConnections_; @@ -36,7 +32,7 @@ namespace SDL { int size() const; }; - using MapPLStoLayer = std::array, 4>, 3>; + using MapPLStoLayer = std::array, 3>; } // namespace SDL #endif diff --git a/SDL/ModuleMethods.h b/SDL/ModuleMethods.h index 401874b7..3f297a6d 100644 --- a/SDL/ModuleMethods.h +++ b/SDL/ModuleMethods.h @@ -115,7 +115,7 @@ namespace SDL { unsigned int nMod, TQueue queue, struct ModuleMetaData& mmd, - ModuleConnectionMap* moduleConnectionMap) { + ModuleConnectionMap* moduleConnectionMap) { DevHost const& devHost = cms::alpakatools::host(); auto moduleMap_buf = allocBufWrapper(devHost, nMod * MAX_CONNECTED_MODULES); uint16_t* moduleMap = alpaka::getPtrNative(moduleMap_buf); @@ -241,8 +241,8 @@ namespace SDL { struct modulesBuffer* modulesBuf, struct pixelMap* pixelMapping, EndcapGeometry* endcapGeometry, - TiltedGeometry* tiltedGeometry, - ModuleConnectionMap* moduleConnectionMap) { + TiltedGeometry* tiltedGeometry, + ModuleConnectionMap* moduleConnectionMap) { ModuleMetaData mmd; loadCentroidsFromFile(moduleMetaDataFilePath, mmd, nModules); diff --git a/SDL/TiltedGeometry.cc b/SDL/TiltedGeometry.cc index abc94cfb..cbfefb29 100644 --- a/SDL/TiltedGeometry.cc +++ b/SDL/TiltedGeometry.cc @@ -1,8 +1,8 @@ #include "TiltedGeometry.h" -SDL::TiltedGeometry::TiltedGeometry(std::string filename) { load(filename); } +SDL::TiltedGeometry::TiltedGeometry(std::string filename) { load(filename); } -void SDL::TiltedGeometry::load(std::string filename) { +void SDL::TiltedGeometry::load(std::string filename) { drdzs_.clear(); dxdys_.clear(); @@ -32,7 +32,7 @@ void SDL::TiltedGeometry::load(std::string filename) { } } -float SDL::TiltedGeometry::getDrDz(unsigned int detid) { +float SDL::TiltedGeometry::getDrDz(unsigned int detid) { if (drdzs_.find(detid) != drdzs_.end()) { return drdzs_[detid]; } else { @@ -40,7 +40,7 @@ float SDL::TiltedGeometry::getDrDz(unsigned int detid) { } } -float SDL::TiltedGeometry::getDxDy(unsigned int detid) { +float SDL::TiltedGeometry::getDxDy(unsigned int detid) { if (dxdys_.find(detid) != dxdys_.end()) { return dxdys_[detid]; } else { diff --git a/SDL/TiltedGeometry.h b/SDL/TiltedGeometry.h index 578d2ca8..0e51591f 100644 --- a/SDL/TiltedGeometry.h +++ b/SDL/TiltedGeometry.h @@ -16,10 +16,7 @@ #endif namespace SDL { - template - class TiltedGeometry; - template <> - class TiltedGeometry { + class TiltedGeometry { private: std::map drdzs_; // dr/dz slope std::map dxdys_; // dx/dy slope diff --git a/bin/sdl.cc b/bin/sdl.cc index 8c900e4a..b8559a02 100644 --- a/bin/sdl.cc +++ b/bin/sdl.cc @@ -309,8 +309,8 @@ void run_sdl() std::shared_ptr> modulesBuffers = std::make_shared>(devAcc); std::shared_ptr pixelMapping = std::make_shared(); std::shared_ptr> endcapGeometry = std::make_shared>(devAcc); - std::shared_ptr> tiltedGeometry = std::make_shared>(); - std::shared_ptr> moduleConnectionMap = std::make_shared>(); + std::shared_ptr tiltedGeometry = std::make_shared(); + std::shared_ptr moduleConnectionMap = std::make_shared(); // Load various maps used in the SDL reconstruction TStopwatch full_timer; full_timer.Start(); diff --git a/code/core/AnalysisConfig.h b/code/core/AnalysisConfig.h index 34242659..a6e719dc 100644 --- a/code/core/AnalysisConfig.h +++ b/code/core/AnalysisConfig.h @@ -103,7 +103,7 @@ class AnalysisConfig std::map>> moduleSimHits; std::map modulePopulation; - SDL::ModuleConnectionMap moduleConnectiongMapLoose; + SDL::ModuleConnectionMap moduleConnectiongMapLoose; // Boolean to trigger whether to run cut_value_ntupling bool do_cut_value_ntuple; diff --git a/code/core/trkCore.cc b/code/core/trkCore.cc index 95abfcb8..66f371d9 100644 --- a/code/core/trkCore.cc +++ b/code/core/trkCore.cc @@ -8,8 +8,8 @@ void loadMaps(SDL::Dev& devAccIn, std::shared_ptr> modulesBuffers, std::shared_ptr pixelMapping, std::shared_ptr> endcapGeometry, - std::shared_ptr> tiltedGeometry, - std::shared_ptr> moduleConnectionMap) + std::shared_ptr tiltedGeometry, + std::shared_ptr moduleConnectionMap) { // From the environment variable figure out the main tracklooper absolute path TString TrackLooperDir = gSystem->Getenv("TRACKLOOPERDIR"); diff --git a/code/core/trkCore.h b/code/core/trkCore.h index ebd23496..942b894a 100644 --- a/code/core/trkCore.h +++ b/code/core/trkCore.h @@ -20,8 +20,8 @@ void loadMaps(SDL::Dev& devAccIn, std::shared_ptr> modulesBuffers, std::shared_ptr pixelMapping, std::shared_ptr> endcapGeometry, - std::shared_ptr> tiltedGeometry, - std::shared_ptr> moduleConnectionMap); + std::shared_ptr tiltedGeometry, + std::shared_ptr moduleConnectionMap); bool goodEvent(); float runMiniDoublet(SDL::Event* event, int evt); float runSegment(SDL::Event* event); From 07955322484ab7df9d135cb25b497cdc678b0824 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 16 May 2024 12:18:51 -0400 Subject: [PATCH 08/23] Consolidated loadmap functions --- SDL/Event.h | 3 --- SDL/LST.cc | 11 +++++---- SDL/LST.h | 1 - bin/sdl.cc | 18 ++++++-------- bin/sdl.h | 1 + code/core/trkCore.cc | 59 -------------------------------------------- code/core/trkCore.h | 9 ------- 7 files changed, 15 insertions(+), 87 deletions(-) diff --git a/SDL/Event.h b/SDL/Event.h index c1836ff4..b975de47 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -90,7 +90,6 @@ namespace SDL { std::shared_ptr> modulesBuffers; std::shared_ptr pixelMapping; std::shared_ptr> endcapGeometry; - std::shared_ptr tiltedGeometry; std::shared_ptr moduleConnectionMap; public: @@ -103,7 +102,6 @@ namespace SDL { std::shared_ptr> modulesBuffersIn, std::shared_ptr pixelMappingIn, std::shared_ptr> endcapGeometryIn, - std::shared_ptr tiltedGeometryIn, std::shared_ptr moduleConnectionMapIn) : queue(q), devAcc(alpaka::getDev(q)), @@ -113,7 +111,6 @@ namespace SDL { modulesBuffers(modulesBuffersIn), pixelMapping(pixelMappingIn), endcapGeometry(endcapGeometryIn), - tiltedGeometry(tiltedGeometryIn), moduleConnectionMap(moduleConnectionMapIn) { init(verbose); } diff --git a/SDL/LST.cc b/SDL/LST.cc index 573c8db1..76f46cf7 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -11,10 +11,13 @@ using XYZVector = ROOT::Math::XYZVector; namespace { std::string trackLooperDir() { - const char* path = std::getenv("LST_BASE"); + const char* path_lst_base = std::getenv("LST_BASE"); + const char* path_tracklooperdir = std::getenv("TRACKLOOPERDIR"); std::string path_str; - if (path != nullptr) { - path_str = path; + if (path_lst_base != nullptr) { + path_str = path_lst_base; + } else if (path_tracklooperdir != nullptr) { + path_str = path_tracklooperdir; } else { // FIXME: temporary solution, will need to pass a value from FileInPath or CMSSW search path // in the `LSTProducer` or a related ES producer @@ -106,7 +109,6 @@ void SDL::LST::run(SDL::QueueAcc& queue, std::shared_ptr> modulesBuffers, std::shared_ptr pixelMapping, std::shared_ptr> endcapGeometry, - std::shared_ptr tiltedGeometry, std::shared_ptr moduleConnectionMap, bool verbose, const std::vector see_px, @@ -135,7 +137,6 @@ void SDL::LST::run(SDL::QueueAcc& queue, modulesBuffers, pixelMapping, endcapGeometry, - tiltedGeometry, moduleConnectionMap); prepareInput(see_px, see_py, diff --git a/SDL/LST.h b/SDL/LST.h index 1560ed7f..cd9efe9e 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -52,7 +52,6 @@ namespace SDL { std::shared_ptr> modulesBuffers, std::shared_ptr pixelMapping, std::shared_ptr> endcapGeometry, - std::shared_ptr tiltedGeometry, std::shared_ptr moduleConnectionMap, bool verbose, const std::vector see_px, diff --git a/bin/sdl.cc b/bin/sdl.cc index b8559a02..5aebb160 100644 --- a/bin/sdl.cc +++ b/bin/sdl.cc @@ -314,15 +314,14 @@ void run_sdl() // Load various maps used in the SDL reconstruction TStopwatch full_timer; full_timer.Start(); - loadMaps(devAcc, - queues[0], - nModules, - nLowerModules, - modulesBuffers, - pixelMapping, - endcapGeometry, - tiltedGeometry, - moduleConnectionMap); + SDL::LST::loadAndFillES(queues[0], + nModules, + nLowerModules, + modulesBuffers, + pixelMapping, + endcapGeometry, + tiltedGeometry, + moduleConnectionMap); float timeForMapLoading = full_timer.RealTime()*1000; if (ana.do_write_ntuple) @@ -412,7 +411,6 @@ void run_sdl() modulesBuffers, pixelMapping, endcapGeometry, - tiltedGeometry, moduleConnectionMap ); events.push_back(event); diff --git a/bin/sdl.h b/bin/sdl.h index dec3f980..c97f331d 100644 --- a/bin/sdl.h +++ b/bin/sdl.h @@ -19,6 +19,7 @@ #include "SDL/EndcapGeometry.h" // SDL::EndcapGeometr #include "SDL/ModuleConnectionMap.h" // SDL::ModuleConnectionMap #include "SDL/Event.h" +#include "SDL/LST.h" // Efficiency study modules #include "AnalysisConfig.h" diff --git a/code/core/trkCore.cc b/code/core/trkCore.cc index 66f371d9..90a01759 100644 --- a/code/core/trkCore.cc +++ b/code/core/trkCore.cc @@ -1,64 +1,5 @@ #include "trkCore.h" -//___________________________________________________________________________________________________________________________________________________________________________________________ -void loadMaps(SDL::Dev& devAccIn, - SDL::QueueAcc& queue, - uint16_t& nModules, - uint16_t& nLowerModules, - std::shared_ptr> modulesBuffers, - std::shared_ptr pixelMapping, - std::shared_ptr> endcapGeometry, - std::shared_ptr tiltedGeometry, - std::shared_ptr moduleConnectionMap) -{ - // From the environment variable figure out the main tracklooper absolute path - TString TrackLooperDir = gSystem->Getenv("TRACKLOOPERDIR"); - - // Module orientation information (DrDz or phi angles) - TString endcap_geom = get_absolute_path_after_check_file_exists(TString::Format("%s/data/OT800_IT615_pt0.8/endcap_orientation.bin", TrackLooperDir.Data()).Data()); - TString tilted_geom = get_absolute_path_after_check_file_exists(TString::Format("%s/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin", TrackLooperDir.Data()).Data()); - TString mappath = get_absolute_path_after_check_file_exists(TString::Format("%s/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin", TrackLooperDir.Data()).Data()); - TString centroid = get_absolute_path_after_check_file_exists(TString::Format("%s/data/OT800_IT615_pt0.8/sensor_centroids.bin", gSystem->Getenv("TRACKLOOPERDIR")).Data()).Data(); - TString pLSMapDir = TrackLooperDir+"/data/OT800_IT615_pt0.8/pixelmap"; - - std::cout << "============ CMSSW_12_2_0_pre2 geometry ===========" << std::endl; - std::cout << "endcap geometry: " << endcap_geom << std::endl; - std::cout << "tilted geometry: " << tilted_geom << std::endl; - std::cout << "module map: " << mappath << std::endl; - std::cout << "pLS map: " << pLSMapDir << std::endl; - std::cout << "centroid: " << centroid << std::endl; - - endcapGeometry->load(queue, endcap_geom.Data()); - tiltedGeometry->load(tilted_geom.Data()); - moduleConnectionMap->load(mappath.Data()); - - SDL::MapPLStoLayer pLStoLayer; - const std::array pLSMapPath{{ "layer1_subdet5", "layer2_subdet5", "layer1_subdet4", "layer2_subdet4" }}; - static_assert(pLStoLayer[0].size() == pLSMapPath.size()); - for (unsigned int i=0; i::initModules(queue, - pLStoLayer, - centroid.Data(), - nModules, - nLowerModules, - modulesBuffers.get(), - pixelMapping.get(), - endcapGeometry.get(), - tiltedGeometry.get(), - moduleConnectionMap.get()); -} - //___________________________________________________________________________________________________________________________________________________________________________________________ bool goodEvent() { diff --git a/code/core/trkCore.h b/code/core/trkCore.h index 942b894a..e45ad4dc 100644 --- a/code/core/trkCore.h +++ b/code/core/trkCore.h @@ -13,15 +13,6 @@ // --------------------- ======================== --------------------- -void loadMaps(SDL::Dev& devAccIn, - SDL::QueueAcc& queue, - uint16_t& nModules, - uint16_t& nLowerModules, - std::shared_ptr> modulesBuffers, - std::shared_ptr pixelMapping, - std::shared_ptr> endcapGeometry, - std::shared_ptr tiltedGeometry, - std::shared_ptr moduleConnectionMap); bool goodEvent(); float runMiniDoublet(SDL::Event* event, int evt); float runSegment(SDL::Event* event); From d274610747bcab9562e05c9e927525bc853a2a21 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 16 May 2024 17:29:53 -0400 Subject: [PATCH 09/23] Started separating host and device ES products --- SDL/Constants.h | 7 ---- SDL/EndcapGeometry.cc | 36 +++++++-------------- SDL/EndcapGeometry.h | 32 +++++++++++++------ SDL/Event.cc | 25 +-------------- SDL/Event.h | 18 +++-------- SDL/LST.cc | 59 +++++++++++++++++++++------------- SDL/LST.h | 74 ++++++++++++++++++++++++++++++++++--------- SDL/Module.h | 6 ++-- SDL/ModuleMethods.h | 48 +++++++++++++--------------- 9 files changed, 162 insertions(+), 143 deletions(-) diff --git a/SDL/Constants.h b/SDL/Constants.h index 75ff589a..25fd4314 100644 --- a/SDL/Constants.h +++ b/SDL/Constants.h @@ -119,13 +119,6 @@ namespace SDL { const unsigned int size_superbins = 45000; - // Temporary fix for endcap buffer allocation. - const unsigned int endcap_size = 9104; - - // Temporary fix for module buffer allocation. - const unsigned int modules_size = 26401; - const unsigned int pix_tot = 1795336; - //defining the constant host device variables right up here ALPAKA_STATIC_ACC_MEM_GLOBAL const float miniMulsPtScaleBarrel[6] = {0.0052, 0.0038, 0.0034, 0.0034, 0.0032, 0.0034}; ALPAKA_STATIC_ACC_MEM_GLOBAL const float miniMulsPtScaleEndcap[5] = {0.006, 0.006, 0.006, 0.006, 0.006}; diff --git a/SDL/EndcapGeometry.cc b/SDL/EndcapGeometry.cc index 6a150e46..647a2535 100644 --- a/SDL/EndcapGeometry.cc +++ b/SDL/EndcapGeometry.cc @@ -1,19 +1,16 @@ #include "EndcapGeometry.h" -SDL::EndcapGeometry::EndcapGeometry(SDL::Dev const& devAccIn, unsigned int sizef) - : geoMapDetId_buf(allocBufWrapper(devAccIn, sizef)), - geoMapPhi_buf(allocBufWrapper(devAccIn, sizef)) {} - -SDL::EndcapGeometry::EndcapGeometry(SDL::Dev const& devAccIn, - SDL::QueueAcc& queue, - std::string filename, - unsigned int sizef) - : geoMapDetId_buf(allocBufWrapper(devAccIn, sizef)), - geoMapPhi_buf(allocBufWrapper(devAccIn, sizef)) { - load(queue, filename); +SDL::EndcapGeometry::EndcapGeometry(SDL::Dev const& devAccIn, + SDL::QueueAcc& queue, + SDL::EndcapGeometry const& endcapGeometryIn) + : geoMapDetId_buf(allocBufWrapper(devAccIn, endcapGeometryIn.centroid_phis_.size())), + geoMapPhi_buf(allocBufWrapper(devAccIn, endcapGeometryIn.centroid_phis_.size())) { + dxdy_slope_ = endcapGeometryIn.dxdy_slope_; + centroid_phis_ = endcapGeometryIn.centroid_phis_; + fillGeoMapArraysExplicit(queue); } -void SDL::EndcapGeometry::load(SDL::QueueAcc& queue, std::string filename) { +void SDL::EndcapGeometry::load(std::string filename) { dxdy_slope_.clear(); centroid_phis_.clear(); @@ -41,21 +38,11 @@ void SDL::EndcapGeometry::load(SDL::QueueAcc& queue, std::string filen } } } - - fillGeoMapArraysExplicit(queue); } -void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc& queue) { +void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc& queue) { unsigned int phi_size = centroid_phis_.size(); - // Temporary check for endcap initialization. - if (phi_size != endcap_size) { - std::cerr << "\nError: phi_size and endcap_size are not equal.\n"; - std::cerr << "phi_size: " << phi_size << ", endcap_size: " << endcap_size << "\n"; - std::cerr << "Please change endcap_size in Constants.h to make it equal to phi_size.\n"; - throw std::runtime_error("Mismatched sizes"); - } - // Allocate buffers on host SDL::DevHost const& devHost = cms::alpakatools::host(); auto mapPhi_host_buf = allocBufWrapper(devHost, phi_size); @@ -82,4 +69,5 @@ void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc& queu alpaka::wait(queue); } -float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) { return dxdy_slope_[detid]; } +float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) { return dxdy_slope_[detid]; } +float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) { return dxdy_slope_[detid]; } diff --git a/SDL/EndcapGeometry.h b/SDL/EndcapGeometry.h index 61ae01fc..db1fc4da 100644 --- a/SDL/EndcapGeometry.h +++ b/SDL/EndcapGeometry.h @@ -18,26 +18,40 @@ #include "HeterogeneousCore/AlpakaInterface/interface/host.h" namespace SDL { - template - class EndcapGeometry {}; + + // Only the full one contains alpaka buffers + template + class EndcapGeometry; + + template <> + class EndcapGeometry { + + public: + std::map dxdy_slope_; // dx/dy slope + std::map centroid_phis_; // centroid phi + + EndcapGeometry() = default; + ~EndcapGeometry() = default; + + void load(std::string); + float getdxdy_slope(unsigned int detid); + }; + template <> - class EndcapGeometry { + class EndcapGeometry { private: std::map dxdy_slope_; // dx/dy slope std::map centroid_phis_; // centroid phi public: - Buf geoMapDetId_buf; - Buf geoMapPhi_buf; + Buf geoMapDetId_buf; + Buf geoMapPhi_buf; unsigned int nEndCapMap; - EndcapGeometry(Dev const& devAccIn, unsigned int sizef = endcap_size); - EndcapGeometry(Dev const& devAccIn, QueueAcc& queue, std::string filename, unsigned int sizef = endcap_size); + EndcapGeometry(Dev const& devAccIn, QueueAcc& queue, SDL::EndcapGeometry const& endcapGeometryIn); ~EndcapGeometry() = default; - void load(QueueAcc& queue, std::string); - void fillGeoMapArraysExplicit(QueueAcc& queue); float getdxdy_slope(unsigned int detid); }; diff --git a/SDL/Event.cc b/SDL/Event.cc index 939e6800..2d7e9cc1 100644 --- a/SDL/Event.cc +++ b/SDL/Event.cc @@ -148,29 +148,6 @@ void SDL::Event::resetEvent() { } } -void SDL::Event::initModules(QueueAcc& queue, - const MapPLStoLayer& pLStoLayer, - const char* moduleMetaDataFilePath, - uint16_t& nModules, - uint16_t& nLowerModules, - struct modulesBuffer* modulesBuf, - struct pixelMap* pixelMapping, - EndcapGeometry* endcapGeometry, - TiltedGeometry* tiltedGeometry, - ModuleConnectionMap* moduleConnectionMap) { - // nModules gets filled here - loadModulesFromFile(queue, - pLStoLayer, - moduleMetaDataFilePath, - nModules, - nLowerModules, - modulesBuf, - pixelMapping, - endcapGeometry, - tiltedGeometry, - moduleConnectionMap); -} - void SDL::Event::addHitToEvent(std::vector x, std::vector y, std::vector z, @@ -1826,7 +1803,7 @@ SDL::trackCandidatesBuffer* SDL::Event::getTrackCandid SDL::modulesBuffer* SDL::Event::getModules(bool isFull) { if (modulesInCPU == nullptr) { // The last input here is just a small placeholder for the allocation. - modulesInCPU = new SDL::modulesBuffer(devHost); + modulesInCPU = new SDL::modulesBuffer(devHost, nModules, nPixels); modulesInCPU->copyFromSrc(queue, *modulesBuffers, isFull); } diff --git a/SDL/Event.h b/SDL/Event.h index b975de47..5804aed2 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -87,9 +87,10 @@ namespace SDL { // Stuff that used to be global uint16_t nModules; uint16_t nLowerModules; + unsigned int nPixels; std::shared_ptr> modulesBuffers; std::shared_ptr pixelMapping; - std::shared_ptr> endcapGeometry; + std::shared_ptr> endcapGeometry; std::shared_ptr moduleConnectionMap; public: @@ -99,15 +100,17 @@ namespace SDL { TQueue const& q, uint16_t nModulesIn, uint16_t nLowerModulesIn, + unsigned int nPixelsIn, std::shared_ptr> modulesBuffersIn, std::shared_ptr pixelMappingIn, - std::shared_ptr> endcapGeometryIn, + std::shared_ptr> endcapGeometryIn, std::shared_ptr moduleConnectionMapIn) : queue(q), devAcc(alpaka::getDev(q)), devHost(cms::alpakatools::host()), nModules(nModulesIn), nLowerModules(nLowerModulesIn), + nPixels(nPixelsIn), modulesBuffers(modulesBuffersIn), pixelMapping(pixelMappingIn), endcapGeometry(endcapGeometryIn), @@ -208,17 +211,6 @@ namespace SDL { pixelQuintupletsBuffer* getPixelQuintuplets(); modulesBuffer* getModules(bool isFull = false); - //read from file and init - static void initModules(QueueAcc& queue, - const MapPLStoLayer& pLStoLayer, - const char* moduleMetaDataFilePath, - uint16_t& nModules, - uint16_t& nLowerModules, - struct modulesBuffer* modulesBuf, - struct pixelMap* pixelMapping, - EndcapGeometry* endcapGeometry, - TiltedGeometry* tiltedGeometry, - ModuleConnectionMap* moduleConnectionMap); }; } // namespace SDL diff --git a/SDL/LST.cc b/SDL/LST.cc index 76f46cf7..09df458f 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -36,12 +36,10 @@ namespace { return fullpath.string(); } - void loadMaps(SDL::Dev const& devAccIn, - SDL::QueueAcc& queue, - SDL::MapPLStoLayer& pLStoLayer, - std::shared_ptr> endcapGeometry, - std::shared_ptr tiltedGeometry, - std::shared_ptr moduleConnectionMap) { + void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer, + std::shared_ptr> endcapGeometry, + std::shared_ptr tiltedGeometry, + std::shared_ptr moduleConnectionMap) { // Module orientation information (DrDz or phi angles) auto endcap_geom = get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); @@ -51,7 +49,7 @@ namespace { auto mappath = get_absolute_path_after_check_file_exists( trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); - endcapGeometry->load(queue, endcap_geom); + endcapGeometry->load(endcap_geom); tiltedGeometry->load(tilted_geom); moduleConnectionMap->load(mappath); @@ -77,38 +75,54 @@ namespace { } // namespace -void SDL::LST::loadAndFillES(SDL::QueueAcc& queue, - uint16_t& nModules, - uint16_t& nLowerModules, - std::shared_ptr> modulesBuf, - std::shared_ptr pixelMapping, - std::shared_ptr> endcapGeometry, - std::shared_ptr tiltedGeometry, - std::shared_ptr moduleConnectionMap) { - SDL::MapPLStoLayer pLStoLayer; - SDL::Dev const& devAccIn = alpaka::getDev(queue); - ::loadMaps(devAccIn, queue, pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); +std::unique_ptr SDL::loadAndFillESHost() { + std::shared_ptr pLStoLayer; + std::shared_ptr> endcapGeometry = std::make_shared>(); + std::shared_ptr tiltedGeometry = std::make_shared(); + std::shared_ptr moduleConnectionMap = std::make_shared(); + ::loadMapsHost(*pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); + return std::make_unique(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); +} +std::unique_ptr> SDL::loadAndFillESDevice(SDL::QueueAcc& queue, LSTESHostData* hostData) { + SDL::Dev const& devAccIn = alpaka::getDev(queue); + uint16_t nModules; + uint16_t nLowerModules; + unsigned int nPixels; + std::shared_ptr> modulesBuffers = nullptr; + std::shared_ptr> endcapGeometry = std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); + std::shared_ptr pixelMapping = std::make_shared(); + std::shared_ptr moduleConnectionMap = hostData->moduleConnectionMap; + auto path = get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); SDL::loadModulesFromFile(queue, - pLStoLayer, + hostData->mapPLStoLayer.get(), path.c_str(), nModules, nLowerModules, - modulesBuf.get(), + nPixels, + modulesBuffers, pixelMapping.get(), endcapGeometry.get(), - tiltedGeometry.get(), + hostData->tiltedGeometry.get(), moduleConnectionMap.get()); + return std::make_unique>(nModules, + nLowerModules, + nPixels, + modulesBuffers, + endcapGeometry, + pixelMapping, + moduleConnectionMap); } void SDL::LST::run(SDL::QueueAcc& queue, uint16_t nModules, uint16_t nLowerModules, + unsigned int nPixels, std::shared_ptr> modulesBuffers, std::shared_ptr pixelMapping, - std::shared_ptr> endcapGeometry, + std::shared_ptr> endcapGeometry, std::shared_ptr moduleConnectionMap, bool verbose, const std::vector see_px, @@ -134,6 +148,7 @@ void SDL::LST::run(SDL::QueueAcc& queue, queue, nModules, nLowerModules, + nPixels, modulesBuffers, pixelMapping, endcapGeometry, diff --git a/SDL/LST.h b/SDL/LST.h index cd9efe9e..db320acb 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -17,41 +17,85 @@ namespace SDL { template class Event; - template - struct modulesBuffer; - struct pixelMap; + class TiltedGeometry; + class ModuleConnectionMap; + using MapPLStoLayer = std::array, 3>; template + struct modulesBuffer; + + template class EndcapGeometry; - class TiltedGeometry; + struct LSTESHostData { + std::shared_ptr const mapPLStoLayer; + std::shared_ptr> const endcapGeometry; + std::shared_ptr const tiltedGeometry; + std::shared_ptr const moduleConnectionMap; + + LSTESHostData(std::shared_ptr mapPLStoLayerIn, + std::shared_ptr> endcapGeometryIn, + std::shared_ptr tiltedGeometryIn, + std::shared_ptr moduleConnectionMapIn) + : mapPLStoLayer(mapPLStoLayerIn), + endcapGeometry(endcapGeometryIn), + tiltedGeometry(tiltedGeometryIn), + moduleConnectionMap(moduleConnectionMapIn) {} + }; - class ModuleConnectionMap; + template + struct LSTESDeviceData; + + template <> + struct LSTESDeviceData { + uint16_t const nModules; + uint16_t const nLowerModules; + unsigned int nPixels; + std::shared_ptr> const modulesBuffers; + std::shared_ptr> const endcapGeometry; + std::shared_ptr const pixelMapping; + std::shared_ptr const moduleConnectionMap; + + LSTESDeviceData(uint16_t nModulesIn, + uint16_t nLowerModulesIn, + unsigned int nPixelsIn, + std::shared_ptr> modulesBuffersIn, + std::shared_ptr> endcapGeometryIn, + std::shared_ptr pixelMappingIn, + std::shared_ptr moduleConnectionMapIn) + : nModules(nModulesIn), + nLowerModules(nLowerModulesIn), + nPixels(nPixelsIn), + modulesBuffers(modulesBuffersIn), + endcapGeometry(endcapGeometryIn), + pixelMapping(pixelMappingIn), + moduleConnectionMap(moduleConnectionMapIn) {} + }; + + std::unique_ptr loadAndFillESHost(); + std::unique_ptr> loadAndFillESDevice(SDL::QueueAcc& queue, LSTESHostData* hostData); template class LST; + template <> + class LST { + + }; + template <> class LST { public: LST() = default; - static void loadAndFillES(SDL::QueueAcc& queue, - uint16_t& nModules, - uint16_t& nLowerModules, - std::shared_ptr> modulesBuffers, - std::shared_ptr pixelMapping, - std::shared_ptr> endcapGeometry, - std::shared_ptr tiltedGeometry, - std::shared_ptr moduleConnectionMap); - void run(SDL::QueueAcc& queue, uint16_t nModules, uint16_t nLowerModules, + unsigned int nPixels, std::shared_ptr> modulesBuffers, std::shared_ptr pixelMapping, - std::shared_ptr> endcapGeometry, + std::shared_ptr> endcapGeometry, std::shared_ptr moduleConnectionMap, bool verbose, const std::vector see_px, diff --git a/SDL/Module.h b/SDL/Module.h index a6b86e78..d99e6f0b 100644 --- a/SDL/Module.h +++ b/SDL/Module.h @@ -288,7 +288,7 @@ namespace SDL { Buf sdlLayers_buf; Buf connectedPixels_buf; - modulesBuffer(TDev const& dev, unsigned int nMod = modules_size, unsigned int nPixs = pix_tot) + modulesBuffer(TDev const& dev, unsigned int nMod, unsigned int nPixs) : detIds_buf(allocBufWrapper(dev, nMod)), moduleMap_buf(allocBufWrapper(dev, nMod * MAX_CONNECTED_MODULES)), mapdetId_buf(allocBufWrapper(dev, nMod)), @@ -362,8 +362,8 @@ namespace SDL { template modulesBuffer(TQueue queue, const modulesBuffer& src, - unsigned int nMod = modules_size, - unsigned int nPixs = pix_tot) + unsigned int nMod, + unsigned int nPixs) : modulesBuffer(alpaka::getDev(queue), nMod, nPixs) { copyFromSrc(queue, src); } diff --git a/SDL/ModuleMethods.h b/SDL/ModuleMethods.h index 3f297a6d..cee4715a 100644 --- a/SDL/ModuleMethods.h +++ b/SDL/ModuleMethods.h @@ -29,9 +29,11 @@ namespace SDL { // https://github.com/cms-sw/cmssw/blob/5e809e8e0a625578aa265dc4b128a93830cb5429/Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h#L29 }; - template - inline void fillPixelMap(struct modulesBuffer& modulesBuf, - struct pixelMap& pixelMapping, + template + inline void fillPixelMap(std::shared_ptr>& modulesBuf, + uint16_t nModules, + unsigned int& nPixels, + pixelMap& pixelMapping, TQueue queue, const MapPLStoLayer& pLStoLayer, struct ModuleMetaData& mmd) { @@ -83,13 +85,12 @@ namespace SDL { } unsigned int connectedPix_size = totalSizes + totalSizes_pos + totalSizes_neg; + nPixels = connectedPix_size; - // Temporary check for module initialization. - if (pix_tot != connectedPix_size) { - std::cerr << "\nError: pix_tot and connectedPix_size are not equal.\n"; - std::cerr << "pix_tot: " << pix_tot << ", connectedPix_size: " << connectedPix_size << "\n"; - std::cerr << "Please change pix_tot in Constants.h to make it equal to connectedPix_size.\n"; - throw std::runtime_error("Mismatched sizes"); + // Now we can initialize modulesBuf + if (modulesBuf == nullptr) { + SDL::Dev const& devAcc = alpaka::getDev(queue); + modulesBuf = std::make_shared>(devAcc, nModules, nPixels); } DevHost const& devHost = cms::alpakatools::host(); @@ -106,7 +107,7 @@ namespace SDL { connectedPixels[icondet + totalSizes + totalSizes_pos] = mmd.detIdToIndex[connectedModuleDetIds_neg[icondet]]; } - alpaka::memcpy(queue, modulesBuf.connectedPixels_buf, connectedPixels_buf); + alpaka::memcpy(queue, modulesBuf->connectedPixels_buf, connectedPixels_buf); alpaka::wait(queue); }; @@ -222,25 +223,18 @@ namespace SDL { mmd.detIdToIndex[1] = counter; //pixel module is the last module in the module list counter++; nModules = counter; - - // Temporary check for module initialization. - if (modules_size != nModules) { - std::cerr << "\nError: modules_size and nModules are not equal.\n"; - std::cerr << "modules_size: " << modules_size << ", nModules: " << nModules << "\n"; - std::cerr << "Please change modules_size in Constants.h to make it equal to nModules.\n"; - throw std::runtime_error("Mismatched sizes"); - } }; - template + template void loadModulesFromFile(TQueue& queue, - const MapPLStoLayer& pLStoLayer, + const MapPLStoLayer* pLStoLayer, const char* moduleMetaDataFilePath, uint16_t& nModules, uint16_t& nLowerModules, - struct modulesBuffer* modulesBuf, - struct pixelMap* pixelMapping, - EndcapGeometry* endcapGeometry, + unsigned int& nPixels, + std::shared_ptr>& modulesBuf, + pixelMap* pixelMapping, + EndcapGeometry* endcapGeometry, TiltedGeometry* tiltedGeometry, ModuleConnectionMap* moduleConnectionMap) { ModuleMetaData mmd; @@ -387,6 +381,9 @@ namespace SDL { } } + // modulesBuf is initialized in fillPixelMap since both nModules and nPix will be known + fillPixelMap(modulesBuf, nModules, nPixels, *pixelMapping, queue, *pLStoLayer, mmd); + auto src_view_nModules = alpaka::createView(devHost, &nModules, (Idx)1u); alpaka::memcpy(queue, modulesBuf->nModules_buf, src_view_nModules); @@ -414,9 +411,8 @@ namespace SDL { alpaka::memcpy(queue, modulesBuf->sdlLayers_buf, sdlLayers_buf); alpaka::wait(queue); - fillConnectedModuleArrayExplicit(modulesBuf, nModules, queue, mmd, moduleConnectionMap); - fillMapArraysExplicit(modulesBuf, nModules, queue, mmd); - fillPixelMap(*modulesBuf, *pixelMapping, queue, pLStoLayer, mmd); + fillConnectedModuleArrayExplicit(modulesBuf.get(), nModules, queue, mmd, moduleConnectionMap); + fillMapArraysExplicit(modulesBuf.get(), nModules, queue, mmd); }; } // namespace SDL #endif From b2c814b3c54535246ab84e7ae21f10f93897c3a3 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 17 May 2024 09:55:08 -0400 Subject: [PATCH 10/23] Now things compile, but it still doesn't work --- SDL/Event.h | 24 ++++++++++-------------- SDL/LST.cc | 16 ++-------------- SDL/LST.h | 10 ++-------- bin/sdl.cc | 25 +++---------------------- 4 files changed, 17 insertions(+), 58 deletions(-) diff --git a/SDL/Event.h b/SDL/Event.h index 5804aed2..620e8296 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -4,9 +4,11 @@ #ifdef LST_IS_CMSSW_PACKAGE #include "RecoTracker/LSTCore/interface/alpaka/Constants.h" #include "RecoTracker/LSTCore/interface/alpaka/Module.h" +#include "RecoTracker/LSTCore/interface/alpaka/LST.h" #else #include "Constants.h" #include "Module.h" +#include "LST.h" #endif #include "Hit.h" @@ -98,23 +100,17 @@ namespace SDL { template Event(bool verbose, TQueue const& q, - uint16_t nModulesIn, - uint16_t nLowerModulesIn, - unsigned int nPixelsIn, - std::shared_ptr> modulesBuffersIn, - std::shared_ptr pixelMappingIn, - std::shared_ptr> endcapGeometryIn, - std::shared_ptr moduleConnectionMapIn) + const LSTESDeviceData* deviceESData) : queue(q), devAcc(alpaka::getDev(q)), devHost(cms::alpakatools::host()), - nModules(nModulesIn), - nLowerModules(nLowerModulesIn), - nPixels(nPixelsIn), - modulesBuffers(modulesBuffersIn), - pixelMapping(pixelMappingIn), - endcapGeometry(endcapGeometryIn), - moduleConnectionMap(moduleConnectionMapIn) { + nModules(deviceESData->nModules), + nLowerModules(deviceESData->nLowerModules), + nPixels(deviceESData->nPixels), + modulesBuffers(deviceESData->modulesBuffers), + pixelMapping(deviceESData->pixelMapping), + endcapGeometry(deviceESData->endcapGeometry), + moduleConnectionMap(deviceESData->moduleConnectionMap) { init(verbose); } void resetEvent(); diff --git a/SDL/LST.cc b/SDL/LST.cc index 09df458f..933ff226 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -117,14 +117,8 @@ std::unique_ptr> SDL::loadAndFillESDevice(SDL::Qu } void SDL::LST::run(SDL::QueueAcc& queue, - uint16_t nModules, - uint16_t nLowerModules, - unsigned int nPixels, - std::shared_ptr> modulesBuffers, - std::shared_ptr pixelMapping, - std::shared_ptr> endcapGeometry, - std::shared_ptr moduleConnectionMap, bool verbose, + const LSTESDeviceData* deviceESData, const std::vector see_px, const std::vector see_py, const std::vector see_pz, @@ -146,13 +140,7 @@ void SDL::LST::run(SDL::QueueAcc& queue, const std::vector ph2_z) { auto event = SDL::Event(verbose, queue, - nModules, - nLowerModules, - nPixels, - modulesBuffers, - pixelMapping, - endcapGeometry, - moduleConnectionMap); + deviceESData); prepareInput(see_px, see_py, see_pz, diff --git a/SDL/LST.h b/SDL/LST.h index db320acb..e0a3e166 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -89,15 +89,9 @@ namespace SDL { public: LST() = default; - void run(SDL::QueueAcc& queue, - uint16_t nModules, - uint16_t nLowerModules, - unsigned int nPixels, - std::shared_ptr> modulesBuffers, - std::shared_ptr pixelMapping, - std::shared_ptr> endcapGeometry, - std::shared_ptr moduleConnectionMap, + void run(QueueAcc& queue, bool verbose, + const LSTESDeviceData* deviceESData, const std::vector see_px, const std::vector see_py, const std::vector see_pz, diff --git a/bin/sdl.cc b/bin/sdl.cc index 5aebb160..b4f52d13 100644 --- a/bin/sdl.cc +++ b/bin/sdl.cc @@ -303,25 +303,11 @@ void run_sdl() queues.push_back(SDL::QueueAcc(devAcc)); } - // Create objects that used to be global - uint16_t nModules; - uint16_t nLowerModules; - std::shared_ptr> modulesBuffers = std::make_shared>(devAcc); - std::shared_ptr pixelMapping = std::make_shared(); - std::shared_ptr> endcapGeometry = std::make_shared>(devAcc); - std::shared_ptr tiltedGeometry = std::make_shared(); - std::shared_ptr moduleConnectionMap = std::make_shared(); // Load various maps used in the SDL reconstruction TStopwatch full_timer; full_timer.Start(); - SDL::LST::loadAndFillES(queues[0], - nModules, - nLowerModules, - modulesBuffers, - pixelMapping, - endcapGeometry, - tiltedGeometry, - moduleConnectionMap); + auto hostESData = SDL::loadAndFillESHost(); + auto deviceESData = SDL::loadAndFillESDevice(queues[0], hostESData.get()); float timeForMapLoading = full_timer.RealTime()*1000; if (ana.do_write_ntuple) @@ -406,12 +392,7 @@ void run_sdl() SDL::Event *event = new SDL::Event( ana.verbose>=2, queues[s], - nModules, - nLowerModules, - modulesBuffers, - pixelMapping, - endcapGeometry, - moduleConnectionMap + deviceESData.get() ); events.push_back(event); } From e01f6b98b90b56661979b5ea0361b02e8a406c23 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 17 May 2024 11:31:33 -0400 Subject: [PATCH 11/23] Made ES data const --- SDL/EndcapGeometry.cc | 4 ++-- SDL/EndcapGeometry.h | 4 ++-- SDL/Event.h | 14 +++++++------- SDL/Hit.h | 4 ++-- SDL/LST.cc | 14 +++++++------- SDL/LST.h | 38 +++++++++++++++++++------------------- SDL/ModuleMethods.h | 8 ++++---- SDL/TiltedGeometry.cc | 8 ++++---- SDL/TiltedGeometry.h | 4 ++-- 9 files changed, 49 insertions(+), 49 deletions(-) diff --git a/SDL/EndcapGeometry.cc b/SDL/EndcapGeometry.cc index 647a2535..a24c49f5 100644 --- a/SDL/EndcapGeometry.cc +++ b/SDL/EndcapGeometry.cc @@ -69,5 +69,5 @@ void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc alpaka::wait(queue); } -float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) { return dxdy_slope_[detid]; } -float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) { return dxdy_slope_[detid]; } +float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { return (detid < dxdy_slope_.size() ? dxdy_slope_.at(detid) : 0); } // FIXME: It was reading data out of bounds +float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { return (detid < dxdy_slope_.size() ? dxdy_slope_.at(detid) : 0); } diff --git a/SDL/EndcapGeometry.h b/SDL/EndcapGeometry.h index db1fc4da..4d5109e8 100644 --- a/SDL/EndcapGeometry.h +++ b/SDL/EndcapGeometry.h @@ -34,7 +34,7 @@ namespace SDL { ~EndcapGeometry() = default; void load(std::string); - float getdxdy_slope(unsigned int detid); + float getdxdy_slope(unsigned int detid) const; }; template <> @@ -53,7 +53,7 @@ namespace SDL { ~EndcapGeometry() = default; void fillGeoMapArraysExplicit(QueueAcc& queue); - float getdxdy_slope(unsigned int detid); + float getdxdy_slope(unsigned int detid) const; }; } // namespace SDL diff --git a/SDL/Event.h b/SDL/Event.h index 620e8296..6b204990 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -87,13 +87,13 @@ namespace SDL { int8_t* pixelTypeCPU; // Stuff that used to be global - uint16_t nModules; - uint16_t nLowerModules; - unsigned int nPixels; - std::shared_ptr> modulesBuffers; - std::shared_ptr pixelMapping; - std::shared_ptr> endcapGeometry; - std::shared_ptr moduleConnectionMap; + const uint16_t nModules; + const uint16_t nLowerModules; + const unsigned int nPixels; + const std::shared_ptr> modulesBuffers; + const std::shared_ptr pixelMapping; + const std::shared_ptr> endcapGeometry; + const std::shared_ptr moduleConnectionMap; public: // Constructor used for CMSSW integration. Uses an external queue. diff --git a/SDL/Hit.h b/SDL/Hit.h index 22699955..1cc75e04 100644 --- a/SDL/Hit.h +++ b/SDL/Hit.h @@ -221,8 +221,8 @@ namespace SDL { uint16_t TwoS, // Integer corresponding to TwoS in moduleType unsigned int nModules, // Number of modules unsigned int nEndCapMap, // Number of elements in endcap map - unsigned int* geoMapDetId, // DetId's from endcap map - float* geoMapPhi, // Phi values from endcap map + const unsigned int* geoMapDetId, // DetId's from endcap map + const float* geoMapPhi, // Phi values from endcap map struct SDL::modules modulesInGPU, struct SDL::hits hitsInGPU, unsigned int const& nHits) const // Total number of hits in event diff --git a/SDL/LST.cc b/SDL/LST.cc index 933ff226..d5a59b41 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -76,10 +76,10 @@ namespace { } // namespace std::unique_ptr SDL::loadAndFillESHost() { - std::shared_ptr pLStoLayer; - std::shared_ptr> endcapGeometry = std::make_shared>(); - std::shared_ptr tiltedGeometry = std::make_shared(); - std::shared_ptr moduleConnectionMap = std::make_shared(); + auto pLStoLayer = std::make_shared(); + auto endcapGeometry = std::make_shared>(); + auto tiltedGeometry = std::make_shared(); + auto moduleConnectionMap = std::make_shared(); ::loadMapsHost(*pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); return std::make_unique(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); } @@ -90,9 +90,9 @@ std::unique_ptr> SDL::loadAndFillESDevice(SDL::Qu uint16_t nLowerModules; unsigned int nPixels; std::shared_ptr> modulesBuffers = nullptr; - std::shared_ptr> endcapGeometry = std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); - std::shared_ptr pixelMapping = std::make_shared(); - std::shared_ptr moduleConnectionMap = hostData->moduleConnectionMap; + auto endcapGeometry = std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); + auto pixelMapping = std::make_shared(); + auto moduleConnectionMap = hostData->moduleConnectionMap; auto path = get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); diff --git a/SDL/LST.h b/SDL/LST.h index e0a3e166..3e29c27d 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -29,19 +29,19 @@ namespace SDL { class EndcapGeometry; struct LSTESHostData { - std::shared_ptr const mapPLStoLayer; - std::shared_ptr> const endcapGeometry; - std::shared_ptr const tiltedGeometry; - std::shared_ptr const moduleConnectionMap; + const std::shared_ptr mapPLStoLayer; + const std::shared_ptr> endcapGeometry; + const std::shared_ptr tiltedGeometry; + const std::shared_ptr moduleConnectionMap; LSTESHostData(std::shared_ptr mapPLStoLayerIn, std::shared_ptr> endcapGeometryIn, std::shared_ptr tiltedGeometryIn, std::shared_ptr moduleConnectionMapIn) - : mapPLStoLayer(mapPLStoLayerIn), - endcapGeometry(endcapGeometryIn), - tiltedGeometry(tiltedGeometryIn), - moduleConnectionMap(moduleConnectionMapIn) {} + : mapPLStoLayer(std::const_pointer_cast(mapPLStoLayerIn)), + endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), + tiltedGeometry(std::const_pointer_cast(tiltedGeometryIn)), + moduleConnectionMap(std::const_pointer_cast(moduleConnectionMapIn)) {} }; template @@ -49,13 +49,13 @@ namespace SDL { template <> struct LSTESDeviceData { - uint16_t const nModules; - uint16_t const nLowerModules; - unsigned int nPixels; - std::shared_ptr> const modulesBuffers; - std::shared_ptr> const endcapGeometry; - std::shared_ptr const pixelMapping; - std::shared_ptr const moduleConnectionMap; + const uint16_t nModules; + const uint16_t nLowerModules; + const unsigned int nPixels; + const std::shared_ptr> modulesBuffers; + const std::shared_ptr> endcapGeometry; + const std::shared_ptr pixelMapping; + const std::shared_ptr moduleConnectionMap; LSTESDeviceData(uint16_t nModulesIn, uint16_t nLowerModulesIn, @@ -63,13 +63,13 @@ namespace SDL { std::shared_ptr> modulesBuffersIn, std::shared_ptr> endcapGeometryIn, std::shared_ptr pixelMappingIn, - std::shared_ptr moduleConnectionMapIn) + std::shared_ptr moduleConnectionMapIn) : nModules(nModulesIn), nLowerModules(nLowerModulesIn), nPixels(nPixelsIn), - modulesBuffers(modulesBuffersIn), - endcapGeometry(endcapGeometryIn), - pixelMapping(pixelMappingIn), + modulesBuffers(std::const_pointer_cast>(modulesBuffersIn)), + endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), + pixelMapping(std::const_pointer_cast(pixelMappingIn)), moduleConnectionMap(moduleConnectionMapIn) {} }; diff --git a/SDL/ModuleMethods.h b/SDL/ModuleMethods.h index cee4715a..fc8625b6 100644 --- a/SDL/ModuleMethods.h +++ b/SDL/ModuleMethods.h @@ -116,7 +116,7 @@ namespace SDL { unsigned int nMod, TQueue queue, struct ModuleMetaData& mmd, - ModuleConnectionMap* moduleConnectionMap) { + const ModuleConnectionMap* moduleConnectionMap) { DevHost const& devHost = cms::alpakatools::host(); auto moduleMap_buf = allocBufWrapper(devHost, nMod * MAX_CONNECTED_MODULES); uint16_t* moduleMap = alpaka::getPtrNative(moduleMap_buf); @@ -234,9 +234,9 @@ namespace SDL { unsigned int& nPixels, std::shared_ptr>& modulesBuf, pixelMap* pixelMapping, - EndcapGeometry* endcapGeometry, - TiltedGeometry* tiltedGeometry, - ModuleConnectionMap* moduleConnectionMap) { + const EndcapGeometry* endcapGeometry, + const TiltedGeometry* tiltedGeometry, + const ModuleConnectionMap* moduleConnectionMap) { ModuleMetaData mmd; loadCentroidsFromFile(moduleMetaDataFilePath, mmd, nModules); diff --git a/SDL/TiltedGeometry.cc b/SDL/TiltedGeometry.cc index cbfefb29..598c73cd 100644 --- a/SDL/TiltedGeometry.cc +++ b/SDL/TiltedGeometry.cc @@ -32,17 +32,17 @@ void SDL::TiltedGeometry::load(std::string filename) { } } -float SDL::TiltedGeometry::getDrDz(unsigned int detid) { +float SDL::TiltedGeometry::getDrDz(unsigned int detid) const { if (drdzs_.find(detid) != drdzs_.end()) { - return drdzs_[detid]; + return drdzs_.at(detid); } else { return 0; } } -float SDL::TiltedGeometry::getDxDy(unsigned int detid) { +float SDL::TiltedGeometry::getDxDy(unsigned int detid) const { if (dxdys_.find(detid) != dxdys_.end()) { - return dxdys_[detid]; + return dxdys_.at(detid); } else { return 0; } diff --git a/SDL/TiltedGeometry.h b/SDL/TiltedGeometry.h index 0e51591f..15204391 100644 --- a/SDL/TiltedGeometry.h +++ b/SDL/TiltedGeometry.h @@ -28,8 +28,8 @@ namespace SDL { void load(std::string); - float getDrDz(unsigned int detid); - float getDxDy(unsigned int detid); + float getDrDz(unsigned int detid) const; + float getDxDy(unsigned int detid) const; }; } // namespace SDL From 4863476fa0be1904fd8c072a93db16a96daa0e76 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 17 May 2024 11:37:00 -0400 Subject: [PATCH 12/23] Removed unnecessary moduleConnectionMap --- SDL/Event.h | 4 +--- SDL/LST.cc | 3 +-- SDL/LST.h | 7 ++----- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/SDL/Event.h b/SDL/Event.h index 6b204990..20b619a3 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -93,7 +93,6 @@ namespace SDL { const std::shared_ptr> modulesBuffers; const std::shared_ptr pixelMapping; const std::shared_ptr> endcapGeometry; - const std::shared_ptr moduleConnectionMap; public: // Constructor used for CMSSW integration. Uses an external queue. @@ -109,8 +108,7 @@ namespace SDL { nPixels(deviceESData->nPixels), modulesBuffers(deviceESData->modulesBuffers), pixelMapping(deviceESData->pixelMapping), - endcapGeometry(deviceESData->endcapGeometry), - moduleConnectionMap(deviceESData->moduleConnectionMap) { + endcapGeometry(deviceESData->endcapGeometry) { init(verbose); } void resetEvent(); diff --git a/SDL/LST.cc b/SDL/LST.cc index d5a59b41..e9e1515d 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -112,8 +112,7 @@ std::unique_ptr> SDL::loadAndFillESDevice(SDL::Qu nPixels, modulesBuffers, endcapGeometry, - pixelMapping, - moduleConnectionMap); + pixelMapping); } void SDL::LST::run(SDL::QueueAcc& queue, diff --git a/SDL/LST.h b/SDL/LST.h index 3e29c27d..aa9a4ba5 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -55,22 +55,19 @@ namespace SDL { const std::shared_ptr> modulesBuffers; const std::shared_ptr> endcapGeometry; const std::shared_ptr pixelMapping; - const std::shared_ptr moduleConnectionMap; LSTESDeviceData(uint16_t nModulesIn, uint16_t nLowerModulesIn, unsigned int nPixelsIn, std::shared_ptr> modulesBuffersIn, std::shared_ptr> endcapGeometryIn, - std::shared_ptr pixelMappingIn, - std::shared_ptr moduleConnectionMapIn) + std::shared_ptr pixelMappingIn) : nModules(nModulesIn), nLowerModules(nLowerModulesIn), nPixels(nPixelsIn), modulesBuffers(std::const_pointer_cast>(modulesBuffersIn)), endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), - pixelMapping(std::const_pointer_cast(pixelMappingIn)), - moduleConnectionMap(moduleConnectionMapIn) {} + pixelMapping(std::const_pointer_cast(pixelMappingIn)) {} }; std::unique_ptr loadAndFillESHost(); From ab01f7ef003dc63562f0b6b6e269ad9040dd3518 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 17 May 2024 08:40:18 -0700 Subject: [PATCH 13/23] Format code --- SDL/EndcapGeometry.cc | 12 ++++++++---- SDL/EndcapGeometry.h | 1 - SDL/Event.h | 5 +---- SDL/Hit.h | 8 ++++---- SDL/LST.cc | 20 ++++++++------------ SDL/LST.h | 36 +++++++++++++++++------------------- SDL/Module.h | 5 +---- 7 files changed, 39 insertions(+), 48 deletions(-) diff --git a/SDL/EndcapGeometry.cc b/SDL/EndcapGeometry.cc index a24c49f5..2c25566f 100644 --- a/SDL/EndcapGeometry.cc +++ b/SDL/EndcapGeometry.cc @@ -1,8 +1,8 @@ #include "EndcapGeometry.h" SDL::EndcapGeometry::EndcapGeometry(SDL::Dev const& devAccIn, - SDL::QueueAcc& queue, - SDL::EndcapGeometry const& endcapGeometryIn) + SDL::QueueAcc& queue, + SDL::EndcapGeometry const& endcapGeometryIn) : geoMapDetId_buf(allocBufWrapper(devAccIn, endcapGeometryIn.centroid_phis_.size())), geoMapPhi_buf(allocBufWrapper(devAccIn, endcapGeometryIn.centroid_phis_.size())) { dxdy_slope_ = endcapGeometryIn.dxdy_slope_; @@ -69,5 +69,9 @@ void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc alpaka::wait(queue); } -float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { return (detid < dxdy_slope_.size() ? dxdy_slope_.at(detid) : 0); } // FIXME: It was reading data out of bounds -float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { return (detid < dxdy_slope_.size() ? dxdy_slope_.at(detid) : 0); } +float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { + return (detid < dxdy_slope_.size() ? dxdy_slope_.at(detid) : 0); +} // FIXME: It was reading data out of bounds +float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { + return (detid < dxdy_slope_.size() ? dxdy_slope_.at(detid) : 0); +} diff --git a/SDL/EndcapGeometry.h b/SDL/EndcapGeometry.h index 4d5109e8..970a558a 100644 --- a/SDL/EndcapGeometry.h +++ b/SDL/EndcapGeometry.h @@ -25,7 +25,6 @@ namespace SDL { template <> class EndcapGeometry { - public: std::map dxdy_slope_; // dx/dy slope std::map centroid_phis_; // centroid phi diff --git a/SDL/Event.h b/SDL/Event.h index 20b619a3..4c499b0a 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -97,9 +97,7 @@ namespace SDL { public: // Constructor used for CMSSW integration. Uses an external queue. template - Event(bool verbose, - TQueue const& q, - const LSTESDeviceData* deviceESData) + Event(bool verbose, TQueue const& q, const LSTESDeviceData* deviceESData) : queue(q), devAcc(alpaka::getDev(q)), devHost(cms::alpakatools::host()), @@ -204,7 +202,6 @@ namespace SDL { pixelTripletsBuffer* getPixelTriplets(); pixelQuintupletsBuffer* getPixelQuintuplets(); modulesBuffer* getModules(bool isFull = false); - }; } // namespace SDL diff --git a/SDL/Hit.h b/SDL/Hit.h index 1cc75e04..dfe9c4c5 100644 --- a/SDL/Hit.h +++ b/SDL/Hit.h @@ -217,10 +217,10 @@ namespace SDL { struct hitLoopKernel { template ALPAKA_FN_ACC void operator()(TAcc const& acc, - uint16_t Endcap, // Integer corresponding to endcap in module subdets - uint16_t TwoS, // Integer corresponding to TwoS in moduleType - unsigned int nModules, // Number of modules - unsigned int nEndCapMap, // Number of elements in endcap map + uint16_t Endcap, // Integer corresponding to endcap in module subdets + uint16_t TwoS, // Integer corresponding to TwoS in moduleType + unsigned int nModules, // Number of modules + unsigned int nEndCapMap, // Number of elements in endcap map const unsigned int* geoMapDetId, // DetId's from endcap map const float* geoMapPhi, // Phi values from endcap map struct SDL::modules modulesInGPU, diff --git a/SDL/LST.cc b/SDL/LST.cc index e9e1515d..9d9c2c83 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -84,16 +84,18 @@ std::unique_ptr SDL::loadAndFillESHost() { return std::make_unique(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); } -std::unique_ptr> SDL::loadAndFillESDevice(SDL::QueueAcc& queue, LSTESHostData* hostData) { +std::unique_ptr> SDL::loadAndFillESDevice(SDL::QueueAcc& queue, + LSTESHostData* hostData) { SDL::Dev const& devAccIn = alpaka::getDev(queue); uint16_t nModules; uint16_t nLowerModules; unsigned int nPixels; std::shared_ptr> modulesBuffers = nullptr; - auto endcapGeometry = std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); + auto endcapGeometry = + std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); auto pixelMapping = std::make_shared(); auto moduleConnectionMap = hostData->moduleConnectionMap; - + auto path = get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); SDL::loadModulesFromFile(queue, @@ -107,12 +109,8 @@ std::unique_ptr> SDL::loadAndFillESDevice(SDL::Qu endcapGeometry.get(), hostData->tiltedGeometry.get(), moduleConnectionMap.get()); - return std::make_unique>(nModules, - nLowerModules, - nPixels, - modulesBuffers, - endcapGeometry, - pixelMapping); + return std::make_unique>( + nModules, nLowerModules, nPixels, modulesBuffers, endcapGeometry, pixelMapping); } void SDL::LST::run(SDL::QueueAcc& queue, @@ -137,9 +135,7 @@ void SDL::LST::run(SDL::QueueAcc& queue, const std::vector ph2_x, const std::vector ph2_y, const std::vector ph2_z) { - auto event = SDL::Event(verbose, - queue, - deviceESData); + auto event = SDL::Event(verbose, queue, deviceESData); prepareInput(see_px, see_py, see_pz, diff --git a/SDL/LST.h b/SDL/LST.h index aa9a4ba5..82805fce 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -38,15 +38,15 @@ namespace SDL { std::shared_ptr> endcapGeometryIn, std::shared_ptr tiltedGeometryIn, std::shared_ptr moduleConnectionMapIn) - : mapPLStoLayer(std::const_pointer_cast(mapPLStoLayerIn)), - endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), - tiltedGeometry(std::const_pointer_cast(tiltedGeometryIn)), - moduleConnectionMap(std::const_pointer_cast(moduleConnectionMapIn)) {} + : mapPLStoLayer(std::const_pointer_cast(mapPLStoLayerIn)), + endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), + tiltedGeometry(std::const_pointer_cast(tiltedGeometryIn)), + moduleConnectionMap(std::const_pointer_cast(moduleConnectionMapIn)) {} }; template struct LSTESDeviceData; - + template <> struct LSTESDeviceData { const uint16_t nModules; @@ -57,17 +57,17 @@ namespace SDL { const std::shared_ptr pixelMapping; LSTESDeviceData(uint16_t nModulesIn, - uint16_t nLowerModulesIn, - unsigned int nPixelsIn, - std::shared_ptr> modulesBuffersIn, - std::shared_ptr> endcapGeometryIn, - std::shared_ptr pixelMappingIn) - : nModules(nModulesIn), - nLowerModules(nLowerModulesIn), - nPixels(nPixelsIn), - modulesBuffers(std::const_pointer_cast>(modulesBuffersIn)), - endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), - pixelMapping(std::const_pointer_cast(pixelMappingIn)) {} + uint16_t nLowerModulesIn, + unsigned int nPixelsIn, + std::shared_ptr> modulesBuffersIn, + std::shared_ptr> endcapGeometryIn, + std::shared_ptr pixelMappingIn) + : nModules(nModulesIn), + nLowerModules(nLowerModulesIn), + nPixels(nPixelsIn), + modulesBuffers(std::const_pointer_cast>(modulesBuffersIn)), + endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), + pixelMapping(std::const_pointer_cast(pixelMappingIn)) {} }; std::unique_ptr loadAndFillESHost(); @@ -77,9 +77,7 @@ namespace SDL { class LST; template <> - class LST { - - }; + class LST {}; template <> class LST { diff --git a/SDL/Module.h b/SDL/Module.h index d99e6f0b..0a269eaa 100644 --- a/SDL/Module.h +++ b/SDL/Module.h @@ -360,10 +360,7 @@ namespace SDL { } template - modulesBuffer(TQueue queue, - const modulesBuffer& src, - unsigned int nMod, - unsigned int nPixs) + modulesBuffer(TQueue queue, const modulesBuffer& src, unsigned int nMod, unsigned int nPixs) : modulesBuffer(alpaka::getDev(queue), nMod, nPixs) { copyFromSrc(queue, src); } From 33747ff7599b9634f71fef8a8d6125cdc0db373f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 17 May 2024 11:49:08 -0400 Subject: [PATCH 14/23] Fixed typo --- SDL/LST.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDL/LST.cc b/SDL/LST.cc index 9d9c2c83..6efdee4c 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -37,7 +37,7 @@ namespace { } void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer, - std::shared_ptr> endcapGeometry, + std::shared_ptr> endcapGeometry, std::shared_ptr tiltedGeometry, std::shared_ptr moduleConnectionMap) { // Module orientation information (DrDz or phi angles) From 32c3f6c1ab85722ca796faab75ee71b81544a66d Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Fri, 17 May 2024 12:25:24 -0400 Subject: [PATCH 15/23] dxdy_slope_ was a map, not a vector --- SDL/EndcapGeometry.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/SDL/EndcapGeometry.cc b/SDL/EndcapGeometry.cc index 2c25566f..55f89ef1 100644 --- a/SDL/EndcapGeometry.cc +++ b/SDL/EndcapGeometry.cc @@ -70,8 +70,16 @@ void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc } float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { - return (detid < dxdy_slope_.size() ? dxdy_slope_.at(detid) : 0); -} // FIXME: It was reading data out of bounds + if (dxdy_slope_.find(detid) != dxdy_slope_.end()) { + return dxdy_slope_.at(detid); + } else { + return 0; + } +} float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { - return (detid < dxdy_slope_.size() ? dxdy_slope_.at(detid) : 0); + if (dxdy_slope_.find(detid) != dxdy_slope_.end()) { + return dxdy_slope_.at(detid); + } else { + return 0; + } } From fb9528d81cb4e5e129ede15d0ec55bce7032fee2 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 20 May 2024 14:39:15 -0400 Subject: [PATCH 16/23] Minor tweaks --- SDL/LST.cc | 2 +- SDL/LST.h | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/SDL/LST.cc b/SDL/LST.cc index 6efdee4c..aa98fb3a 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -85,7 +85,7 @@ std::unique_ptr SDL::loadAndFillESHost() { } std::unique_ptr> SDL::loadAndFillESDevice(SDL::QueueAcc& queue, - LSTESHostData* hostData) { + const LSTESHostData* hostData) { SDL::Dev const& devAccIn = alpaka::getDev(queue); uint16_t nModules; uint16_t nLowerModules; diff --git a/SDL/LST.h b/SDL/LST.h index 82805fce..e1c9cfba 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -45,33 +45,30 @@ namespace SDL { }; template - struct LSTESDeviceData; - - template <> - struct LSTESDeviceData { + struct LSTESDeviceData { const uint16_t nModules; const uint16_t nLowerModules; const unsigned int nPixels; - const std::shared_ptr> modulesBuffers; - const std::shared_ptr> endcapGeometry; + const std::shared_ptr> modulesBuffers; + const std::shared_ptr> endcapGeometry; const std::shared_ptr pixelMapping; LSTESDeviceData(uint16_t nModulesIn, uint16_t nLowerModulesIn, unsigned int nPixelsIn, - std::shared_ptr> modulesBuffersIn, - std::shared_ptr> endcapGeometryIn, + std::shared_ptr> modulesBuffersIn, + std::shared_ptr> endcapGeometryIn, std::shared_ptr pixelMappingIn) : nModules(nModulesIn), nLowerModules(nLowerModulesIn), nPixels(nPixelsIn), - modulesBuffers(std::const_pointer_cast>(modulesBuffersIn)), - endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), + modulesBuffers(std::const_pointer_cast>(modulesBuffersIn)), + endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), pixelMapping(std::const_pointer_cast(pixelMappingIn)) {} }; std::unique_ptr loadAndFillESHost(); - std::unique_ptr> loadAndFillESDevice(SDL::QueueAcc& queue, LSTESHostData* hostData); + std::unique_ptr> loadAndFillESDevice(SDL::QueueAcc& queue, const LSTESHostData* hostData); template class LST; From e627d4980cbad53fe7f94fdd681f03fd9a22d8f0 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Mon, 20 May 2024 15:35:05 -0400 Subject: [PATCH 17/23] Added underscore suffix to new Event data members --- SDL/Event.cc | 224 +++++++++++++++++++++++++-------------------------- SDL/Event.h | 24 +++--- 2 files changed, 124 insertions(+), 124 deletions(-) diff --git a/SDL/Event.cc b/SDL/Event.cc index 2d7e9cc1..7039f787 100644 --- a/SDL/Event.cc +++ b/SDL/Event.cc @@ -159,13 +159,13 @@ void SDL::Event::addHitToEvent(std::vector x, // Initialize space on device/host for next event. if (hitsInGPU == nullptr) { hitsInGPU = new SDL::hits(); - hitsBuffers = new SDL::hitsBuffer(nModules, nHits, devAcc, queue); + hitsBuffers = new SDL::hitsBuffer(nModules_, nHits, devAcc, queue); hitsInGPU->setData(*hitsBuffers); } if (rangesInGPU == nullptr) { rangesInGPU = new SDL::objectRanges(); - rangesBuffers = new SDL::objectRangesBuffer(nModules, nLowerModules, devAcc, queue); + rangesBuffers = new SDL::objectRangesBuffer(nModules_, nLowerModules_, devAcc, queue); rangesInGPU->setData(*rangesBuffers); } @@ -190,11 +190,11 @@ void SDL::Event::addHitToEvent(std::vector x, hit_loop_kernel, Endcap, TwoS, - nModules, - endcapGeometry->nEndCapMap, - alpaka::getPtrNative(endcapGeometry->geoMapDetId_buf), - alpaka::getPtrNative(endcapGeometry->geoMapPhi_buf), - *modulesBuffers->data(), + nModules_, + endcapGeometry_->nEndCapMap, + alpaka::getPtrNative(endcapGeometry_->geoMapDetId_buf), + alpaka::getPtrNative(endcapGeometry_->geoMapPhi_buf), + *modulesBuffers_->data(), *hitsInGPU, nHits)); @@ -206,7 +206,7 @@ void SDL::Event::addHitToEvent(std::vector x, moduleRangesKernel module_ranges_kernel; auto const module_ranges_task(alpaka::createTaskKernel( - module_ranges_workdiv, module_ranges_kernel, *modulesBuffers->data(), *hitsInGPU, nLowerModules)); + module_ranges_workdiv, module_ranges_kernel, *modulesBuffers_->data(), *hitsInGPU, nLowerModules_)); // Waiting isn't needed after second kernel call. Saves ~100 us. // This is because addPixelSegmentToEvent (which is run next) doesn't rely on hitsBuffers->hitrange variables. @@ -244,12 +244,12 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI } unsigned int mdSize = 2 * size; - uint16_t pixelModuleIndex = pixelMapping->pixelModuleIndex; + uint16_t pixelModuleIndex = pixelMapping_->pixelModuleIndex; if (mdsInGPU == nullptr) { - // Create a view for the element nLowerModules inside rangesBuffers->miniDoubletModuleOccupancy + // Create a view for the element nLowerModules_ inside rangesBuffers->miniDoubletModuleOccupancy auto dst_view_miniDoubletModuleOccupancy = - alpaka::createSubView(rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules); + alpaka::createSubView(rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules_); // Create a source view for the value to be set int value = N_MAX_PIXEL_MD_PER_MODULES; @@ -265,7 +265,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI SDL::createMDArrayRangesGPU createMDArrayRangesGPU_kernel; auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel( - createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers->data(), *rangesInGPU)); + createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers_->data(), *rangesInGPU)); alpaka::enqueue(queue, createMDArrayRangesGPUTask); alpaka::wait(queue); @@ -279,7 +279,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI nTotalMDs += N_MAX_PIXEL_MD_PER_MODULES; mdsInGPU = new SDL::miniDoublets(); - miniDoubletsBuffers = new SDL::miniDoubletsBuffer(nTotalMDs, nLowerModules, devAcc, queue); + miniDoubletsBuffers = new SDL::miniDoubletsBuffer(nTotalMDs, nLowerModules_, devAcc, queue); mdsInGPU->setData(*miniDoubletsBuffers); alpaka::memcpy(queue, miniDoubletsBuffers->nMemoryLocations_buf, nTotalMDs_view); @@ -297,7 +297,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI SDL::createSegmentArrayRanges createSegmentArrayRanges_kernel; auto const createSegmentArrayRangesTask(alpaka::createTaskKernel(createSegmentArrayRanges_workDiv, createSegmentArrayRanges_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *rangesInGPU, *mdsInGPU)); @@ -313,7 +313,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI segmentsInGPU = new SDL::segments(); segmentsBuffers = - new SDL::segmentsBuffer(nTotalSegments, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); + new SDL::segmentsBuffer(nTotalSegments, nLowerModules_, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); segmentsInGPU->setData(*segmentsBuffers); alpaka::memcpy(queue, segmentsBuffers->nMemoryLocations_buf, nTotalSegments_view); @@ -373,7 +373,7 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI addPixelSegmentToEventKernel addPixelSegmentToEvent_kernel; auto const addPixelSegmentToEvent_task(alpaka::createTaskKernel(addPixelSegmentToEvent_workdiv, addPixelSegmentToEvent_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *rangesInGPU, *hitsInGPU, *mdsInGPU, @@ -391,9 +391,9 @@ void SDL::Event::addPixelSegmentToEvent(std::vector hitI } void SDL::Event::createMiniDoublets() { - // Create a view for the element nLowerModules inside rangesBuffers->miniDoubletModuleOccupancy + // Create a view for the element nLowerModules_ inside rangesBuffers->miniDoubletModuleOccupancy auto dst_view_miniDoubletModuleOccupancy = - alpaka::createSubView(rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules); + alpaka::createSubView(rangesBuffers->miniDoubletModuleOccupancy_buf, (Idx)1u, (Idx)nLowerModules_); // Create a source view for the value to be set int value = N_MAX_PIXEL_MD_PER_MODULES; @@ -409,7 +409,7 @@ void SDL::Event::createMiniDoublets() { SDL::createMDArrayRangesGPU createMDArrayRangesGPU_kernel; auto const createMDArrayRangesGPUTask(alpaka::createTaskKernel( - createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers->data(), *rangesInGPU)); + createMDArrayRangesGPU_workDiv, createMDArrayRangesGPU_kernel, *modulesBuffers_->data(), *rangesInGPU)); alpaka::enqueue(queue, createMDArrayRangesGPUTask); alpaka::wait(queue); @@ -425,19 +425,19 @@ void SDL::Event::createMiniDoublets() { if (mdsInGPU == nullptr) { mdsInGPU = new SDL::miniDoublets(); - miniDoubletsBuffers = new SDL::miniDoubletsBuffer(nTotalMDs, nLowerModules, devAcc, queue); + miniDoubletsBuffers = new SDL::miniDoubletsBuffer(nTotalMDs, nLowerModules_, devAcc, queue); mdsInGPU->setData(*miniDoubletsBuffers); } Vec const threadsPerBlockCreateMDInGPU = createVec(1, 16, 32); - Vec const blocksPerGridCreateMDInGPU = createVec(1, nLowerModules / threadsPerBlockCreateMDInGPU[1], 1); + Vec const blocksPerGridCreateMDInGPU = createVec(1, nLowerModules_ / threadsPerBlockCreateMDInGPU[1], 1); WorkDiv const createMiniDoubletsInGPUv2_workDiv = createWorkDiv(blocksPerGridCreateMDInGPU, threadsPerBlockCreateMDInGPU, elementsPerThread); SDL::createMiniDoubletsInGPUv2 createMiniDoubletsInGPUv2_kernel; auto const createMiniDoubletsInGPUv2Task(alpaka::createTaskKernel(createMiniDoubletsInGPUv2_workDiv, createMiniDoubletsInGPUv2_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *hitsInGPU, *mdsInGPU, *rangesInGPU)); @@ -453,7 +453,7 @@ void SDL::Event::createMiniDoublets() { auto const addMiniDoubletRangesToEventExplicitTask( alpaka::createTaskKernel(addMiniDoubletRangesToEventExplicit_workDiv, addMiniDoubletRangesToEventExplicit_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *mdsInGPU, *rangesInGPU, *hitsInGPU)); @@ -470,19 +470,19 @@ void SDL::Event::createSegmentsWithModuleMap() { if (segmentsInGPU == nullptr) { segmentsInGPU = new SDL::segments(); segmentsBuffers = - new SDL::segmentsBuffer(nTotalSegments, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); + new SDL::segmentsBuffer(nTotalSegments, nLowerModules_, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devAcc, queue); segmentsInGPU->setData(*segmentsBuffers); } Vec const threadsPerBlockCreateSeg = createVec(1, 1, 64); - Vec const blocksPerGridCreateSeg = createVec(1, 1, nLowerModules); + Vec const blocksPerGridCreateSeg = createVec(1, 1, nLowerModules_); WorkDiv const createSegmentsInGPUv2_workDiv = createWorkDiv(blocksPerGridCreateSeg, threadsPerBlockCreateSeg, elementsPerThread); SDL::createSegmentsInGPUv2 createSegmentsInGPUv2_kernel; auto const createSegmentsInGPUv2Task(alpaka::createTaskKernel(createSegmentsInGPUv2_workDiv, createSegmentsInGPUv2_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *mdsInGPU, *segmentsInGPU, *rangesInGPU)); @@ -497,7 +497,7 @@ void SDL::Event::createSegmentsWithModuleMap() { SDL::addSegmentRangesToEventExplicit addSegmentRangesToEventExplicit_kernel; auto const addSegmentRangesToEventExplicitTask(alpaka::createTaskKernel(addSegmentRangesToEventExplicit_workDiv, addSegmentRangesToEventExplicit_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *segmentsInGPU, *rangesInGPU)); @@ -519,7 +519,7 @@ void SDL::Event::createTriplets() { SDL::createTripletArrayRanges createTripletArrayRanges_kernel; auto const createTripletArrayRangesTask(alpaka::createTaskKernel(createTripletArrayRanges_workDiv, createTripletArrayRanges_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *rangesInGPU, *segmentsInGPU)); @@ -534,7 +534,7 @@ void SDL::Event::createTriplets() { tripletsInGPU = new SDL::triplets(); tripletsBuffers = - new SDL::tripletsBuffer(*alpaka::getPtrNative(maxTriplets_buf), nLowerModules, devAcc, queue); + new SDL::tripletsBuffer(*alpaka::getPtrNative(maxTriplets_buf), nLowerModules_, devAcc, queue); tripletsInGPU->setData(*tripletsBuffers); alpaka::memcpy(queue, tripletsBuffers->nMemoryLocations_buf, maxTriplets_buf); @@ -545,27 +545,27 @@ void SDL::Event::createTriplets() { unsigned int max_InnerSeg = 0; // Allocate host index - auto index_buf = allocBufWrapper(devHost, nLowerModules, queue); + auto index_buf = allocBufWrapper(devHost, nLowerModules_, queue); uint16_t* index = alpaka::getPtrNative(index_buf); // Allocate device index - auto index_gpu_buf = allocBufWrapper(devAcc, nLowerModules, queue); + auto index_gpu_buf = allocBufWrapper(devAcc, nLowerModules_, queue); // Allocate and copy nSegments from device to host - auto nSegments_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, nSegments_buf, segmentsBuffers->nSegments_buf, nLowerModules); + auto nSegments_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, nSegments_buf, segmentsBuffers->nSegments_buf, nLowerModules_); alpaka::wait(queue); unsigned int* nSegments = alpaka::getPtrNative(nSegments_buf); // Allocate and copy module_nConnectedModules from device to host - auto module_nConnectedModules_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, module_nConnectedModules_buf, modulesBuffers->nConnectedModules_buf, nLowerModules); + auto module_nConnectedModules_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, module_nConnectedModules_buf, modulesBuffers_->nConnectedModules_buf, nLowerModules_); alpaka::wait(queue); uint16_t* module_nConnectedModules = alpaka::getPtrNative(module_nConnectedModules_buf); - for (uint16_t innerLowerModuleIndex = 0; innerLowerModuleIndex < nLowerModules; innerLowerModuleIndex++) { + for (uint16_t innerLowerModuleIndex = 0; innerLowerModuleIndex < nLowerModules_; innerLowerModuleIndex++) { uint16_t nConnectedModules = module_nConnectedModules[innerLowerModuleIndex]; unsigned int nInnerSegments = nSegments[innerLowerModuleIndex]; if (nConnectedModules != 0 and nInnerSegments != 0) { @@ -587,7 +587,7 @@ void SDL::Event::createTriplets() { SDL::createTripletsInGPUv2 createTripletsInGPUv2_kernel; auto const createTripletsInGPUv2Task(alpaka::createTaskKernel(createTripletsInGPUv2_workDiv, createTripletsInGPUv2_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *mdsInGPU, *segmentsInGPU, *tripletsInGPU, @@ -605,7 +605,7 @@ void SDL::Event::createTriplets() { SDL::addTripletRangesToEventExplicit addTripletRangesToEventExplicit_kernel; auto const addTripletRangesToEventExplicitTask(alpaka::createTaskKernel(addTripletRangesToEventExplicit_workDiv, addTripletRangesToEventExplicit_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *tripletsInGPU, *rangesInGPU)); @@ -639,7 +639,7 @@ void SDL::Event::createTrackCandidates() { SDL::crossCleanpT3 crossCleanpT3_kernel; auto const crossCleanpT3Task(alpaka::createTaskKernel(crossCleanpT3_workDiv, crossCleanpT3_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *rangesInGPU, *pixelTripletsInGPU, *segmentsInGPU, @@ -655,7 +655,7 @@ void SDL::Event::createTrackCandidates() { SDL::addpT3asTrackCandidatesInGPU addpT3asTrackCandidatesInGPU_kernel; auto const addpT3asTrackCandidatesInGPUTask(alpaka::createTaskKernel(addpT3asTrackCandidatesInGPU_workDiv, addpT3asTrackCandidatesInGPU_kernel, - nLowerModules, + nLowerModules_, *pixelTripletsInGPU, *trackCandidatesInGPU, *segmentsInGPU, @@ -686,7 +686,7 @@ void SDL::Event::createTrackCandidates() { SDL::crossCleanT5 crossCleanT5_kernel; auto const crossCleanT5Task(alpaka::createTaskKernel(crossCleanT5_workDiv, crossCleanT5_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *quintupletsInGPU, *pixelQuintupletsInGPU, *pixelTripletsInGPU, @@ -702,7 +702,7 @@ void SDL::Event::createTrackCandidates() { SDL::addT5asTrackCandidateInGPU addT5asTrackCandidateInGPU_kernel; auto const addT5asTrackCandidateInGPUTask(alpaka::createTaskKernel(addT5asTrackCandidateInGPU_workDiv, addT5asTrackCandidateInGPU_kernel, - nLowerModules, + nLowerModules_, *quintupletsInGPU, *trackCandidatesInGPU, *rangesInGPU)); @@ -717,7 +717,7 @@ void SDL::Event::createTrackCandidates() { SDL::checkHitspLS checkHitspLS_kernel; auto const checkHitspLSTask(alpaka::createTaskKernel( - checkHitspLS_workDiv, checkHitspLS_kernel, *modulesBuffers->data(), *segmentsInGPU, true)); + checkHitspLS_workDiv, checkHitspLS_kernel, *modulesBuffers_->data(), *segmentsInGPU, true)); alpaka::enqueue(queue, checkHitspLSTask); #endif @@ -730,7 +730,7 @@ void SDL::Event::createTrackCandidates() { SDL::crossCleanpLS crossCleanpLS_kernel; auto const crossCleanpLSTask(alpaka::createTaskKernel(crossCleanpLS_workDiv, crossCleanpLS_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *rangesInGPU, *pixelTripletsInGPU, *trackCandidatesInGPU, @@ -749,7 +749,7 @@ void SDL::Event::createTrackCandidates() { SDL::addpLSasTrackCandidateInGPU addpLSasTrackCandidateInGPU_kernel; auto const addpLSasTrackCandidateInGPUTask(alpaka::createTaskKernel(addpLSasTrackCandidateInGPU_workDiv, addpLSasTrackCandidateInGPU_kernel, - nLowerModules, + nLowerModules_, *trackCandidatesInGPU, *segmentsInGPU)); @@ -791,7 +791,7 @@ void SDL::Event::createPixelTriplets() { unsigned int nInnerSegments; auto nInnerSegments_src_view = alpaka::createView(devHost, &nInnerSegments, (size_t)1u); - auto dev_view_nSegments = alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules); + auto dev_view_nSegments = alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules_); alpaka::memcpy(queue, nInnerSegments_src_view, dev_view_nSegments); alpaka::wait(queue); @@ -815,9 +815,9 @@ void SDL::Event::createPixelTriplets() { alpaka::wait(queue); int pixelIndexOffsetPos = - pixelMapping->connectedPixelsIndex[size_superbins - 1] + pixelMapping->connectedPixelsSizes[size_superbins - 1]; - int pixelIndexOffsetNeg = pixelMapping->connectedPixelsIndexPos[size_superbins - 1] + - pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos; + pixelMapping_->connectedPixelsIndex[size_superbins - 1] + pixelMapping_->connectedPixelsSizes[size_superbins - 1]; + int pixelIndexOffsetNeg = pixelMapping_->connectedPixelsIndexPos[size_superbins - 1] + + pixelMapping_->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos; // TODO: check if a map/reduction to just eligible pLSs would speed up the kernel // the current selection still leaves a significant fraction of unmatchable pLSs @@ -833,19 +833,19 @@ void SDL::Event::createPixelTriplets() { // Used pixel type to select correct size-index arrays if (pixelType == 0) { connectedPixelSize_host[i] = - pixelMapping->connectedPixelsSizes[superbin]; // number of connected modules to this pixel - auto connectedIdxBase = pixelMapping->connectedPixelsIndex[superbin]; + pixelMapping_->connectedPixelsSizes[superbin]; // number of connected modules to this pixel + auto connectedIdxBase = pixelMapping_->connectedPixelsIndex[superbin]; connectedPixelIndex_host[i] = connectedIdxBase; // index to get start of connected modules for this superbin in map } else if (pixelType == 1) { connectedPixelSize_host[i] = - pixelMapping->connectedPixelsSizesPos[superbin]; // number of pixel connected modules - auto connectedIdxBase = pixelMapping->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; + pixelMapping_->connectedPixelsSizesPos[superbin]; // number of pixel connected modules + auto connectedIdxBase = pixelMapping_->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; connectedPixelIndex_host[i] = connectedIdxBase; // index to get start of connected pixel modules } else if (pixelType == 2) { connectedPixelSize_host[i] = - pixelMapping->connectedPixelsSizesNeg[superbin]; // number of pixel connected modules - auto connectedIdxBase = pixelMapping->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; + pixelMapping_->connectedPixelsSizesNeg[superbin]; // number of pixel connected modules + auto connectedIdxBase = pixelMapping_->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; connectedPixelIndex_host[i] = connectedIdxBase; // index to get start of connected pixel modules } } @@ -863,7 +863,7 @@ void SDL::Event::createPixelTriplets() { auto const createPixelTripletsInGPUFromMapv2Task( alpaka::createTaskKernel(createPixelTripletsInGPUFromMapv2_workDiv, createPixelTripletsInGPUFromMapv2_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *rangesInGPU, *mdsInGPU, *segmentsInGPU, @@ -910,7 +910,7 @@ void SDL::Event::createQuintuplets() { auto const createEligibleModulesListForQuintupletsGPUTask( alpaka::createTaskKernel(createEligibleModulesListForQuintupletsGPU_workDiv, createEligibleModulesListForQuintupletsGPU_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *tripletsInGPU, *rangesInGPU)); @@ -929,7 +929,7 @@ void SDL::Event::createQuintuplets() { if (quintupletsInGPU == nullptr) { quintupletsInGPU = new SDL::quintuplets(); - quintupletsBuffers = new SDL::quintupletsBuffer(nTotalQuintuplets, nLowerModules, devAcc, queue); + quintupletsBuffers = new SDL::quintupletsBuffer(nTotalQuintuplets, nLowerModules_, devAcc, queue); quintupletsInGPU->setData(*quintupletsBuffers); alpaka::memcpy(queue, quintupletsBuffers->nMemoryLocations_buf, nTotalQuintuplets_buf); @@ -944,7 +944,7 @@ void SDL::Event::createQuintuplets() { SDL::createQuintupletsInGPUv2 createQuintupletsInGPUv2_kernel; auto const createQuintupletsInGPUv2Task(alpaka::createTaskKernel(createQuintupletsInGPUv2_workDiv, createQuintupletsInGPUv2_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *mdsInGPU, *segmentsInGPU, *tripletsInGPU, @@ -963,7 +963,7 @@ void SDL::Event::createQuintuplets() { auto const removeDupQuintupletsInGPUAfterBuildTask( alpaka::createTaskKernel(removeDupQuintupletsInGPUAfterBuild_workDiv, removeDupQuintupletsInGPUAfterBuild_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *quintupletsInGPU, *rangesInGPU)); @@ -978,7 +978,7 @@ void SDL::Event::createQuintuplets() { auto const addQuintupletRangesToEventExplicitTask( alpaka::createTaskKernel(addQuintupletRangesToEventExplicit_workDiv, addQuintupletRangesToEventExplicit_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *quintupletsInGPU, *rangesInGPU)); @@ -999,7 +999,7 @@ void SDL::Event::pixelLineSegmentCleaning() { SDL::checkHitspLS checkHitspLS_kernel; auto const checkHitspLSTask(alpaka::createTaskKernel( - checkHitspLS_workDiv, checkHitspLS_kernel, *modulesBuffers->data(), *segmentsInGPU, false)); + checkHitspLS_workDiv, checkHitspLS_kernel, *modulesBuffers_->data(), *segmentsInGPU, false)); alpaka::enqueue(queue, checkHitspLSTask); alpaka::wait(queue); @@ -1023,7 +1023,7 @@ void SDL::Event::createPixelQuintuplets() { auto nInnerSegments_src_view = alpaka::createView(devHost, &nInnerSegments, (size_t)1u); // Create a sub-view for the device buffer - auto dev_view_nSegments = alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules); + auto dev_view_nSegments = alpaka::createSubView(segmentsBuffers->nSegments_buf, (Idx)1u, (Idx)nLowerModules_); alpaka::memcpy(queue, nInnerSegments_src_view, dev_view_nSegments); alpaka::wait(queue); @@ -1047,9 +1047,9 @@ void SDL::Event::createPixelQuintuplets() { alpaka::wait(queue); int pixelIndexOffsetPos = - pixelMapping->connectedPixelsIndex[size_superbins - 1] + pixelMapping->connectedPixelsSizes[size_superbins - 1]; - int pixelIndexOffsetNeg = pixelMapping->connectedPixelsIndexPos[size_superbins - 1] + - pixelMapping->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos; + pixelMapping_->connectedPixelsIndex[size_superbins - 1] + pixelMapping_->connectedPixelsSizes[size_superbins - 1]; + int pixelIndexOffsetNeg = pixelMapping_->connectedPixelsIndexPos[size_superbins - 1] + + pixelMapping_->connectedPixelsSizesPos[size_superbins - 1] + pixelIndexOffsetPos; // Loop over # pLS for (unsigned int i = 0; i < nInnerSegments; i++) { @@ -1063,16 +1063,16 @@ void SDL::Event::createPixelQuintuplets() { // Used pixel type to select correct size-index arrays if (pixelType == 0) { connectedPixelSize_host[i] = - pixelMapping->connectedPixelsSizes[superbin]; //number of connected modules to this pixel - unsigned int connectedIdxBase = pixelMapping->connectedPixelsIndex[superbin]; + pixelMapping_->connectedPixelsSizes[superbin]; //number of connected modules to this pixel + unsigned int connectedIdxBase = pixelMapping_->connectedPixelsIndex[superbin]; connectedPixelIndex_host[i] = connectedIdxBase; } else if (pixelType == 1) { - connectedPixelSize_host[i] = pixelMapping->connectedPixelsSizesPos[superbin]; //number of pixel connected modules - unsigned int connectedIdxBase = pixelMapping->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; + connectedPixelSize_host[i] = pixelMapping_->connectedPixelsSizesPos[superbin]; //number of pixel connected modules + unsigned int connectedIdxBase = pixelMapping_->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; connectedPixelIndex_host[i] = connectedIdxBase; } else if (pixelType == 2) { - connectedPixelSize_host[i] = pixelMapping->connectedPixelsSizesNeg[superbin]; //number of pixel connected modules - unsigned int connectedIdxBase = pixelMapping->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; + connectedPixelSize_host[i] = pixelMapping_->connectedPixelsSizesNeg[superbin]; //number of pixel connected modules + unsigned int connectedIdxBase = pixelMapping_->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; connectedPixelIndex_host[i] = connectedIdxBase; } } @@ -1090,7 +1090,7 @@ void SDL::Event::createPixelQuintuplets() { auto const createPixelQuintupletsInGPUFromMapv2Task( alpaka::createTaskKernel(createPixelQuintupletsInGPUFromMapv2_workDiv, createPixelQuintupletsInGPUFromMapv2_kernel, - *modulesBuffers->data(), + *modulesBuffers_->data(), *mdsInGPU, *segmentsInGPU, *tripletsInGPU, @@ -1124,7 +1124,7 @@ void SDL::Event::createPixelQuintuplets() { SDL::addpT5asTrackCandidateInGPU addpT5asTrackCandidateInGPU_kernel; auto const addpT5asTrackCandidateInGPUTask(alpaka::createTaskKernel(addpT5asTrackCandidateInGPU_workDiv, addpT5asTrackCandidateInGPU_kernel, - nLowerModules, + nLowerModules_, *pixelQuintupletsInGPU, *trackCandidatesInGPU, *segmentsInGPU, @@ -1144,17 +1144,17 @@ void SDL::Event::createPixelQuintuplets() { } void SDL::Event::addMiniDoubletsToEventExplicit() { - auto nMDsCPU_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, nMDsCPU_buf, miniDoubletsBuffers->nMDs_buf, nLowerModules); + auto nMDsCPU_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, nMDsCPU_buf, miniDoubletsBuffers->nMDs_buf, nLowerModules_); - auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); + auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, module_subdets_buf, modulesBuffers_->subdets_buf, nLowerModules_); - auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); + auto module_layers_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, module_layers_buf, modulesBuffers_->layers_buf, nLowerModules_); - auto module_hitRanges_buf = allocBufWrapper(devHost, nLowerModules * 2, queue); - alpaka::memcpy(queue, module_hitRanges_buf, hitsBuffers->hitRanges_buf, nLowerModules * 2u); + auto module_hitRanges_buf = allocBufWrapper(devHost, nLowerModules_ * 2, queue); + alpaka::memcpy(queue, module_hitRanges_buf, hitsBuffers->hitRanges_buf, nLowerModules_ * 2u); alpaka::wait(queue); @@ -1163,7 +1163,7 @@ void SDL::Event::addMiniDoubletsToEventExplicit() { short* module_layers = alpaka::getPtrNative(module_layers_buf); int* module_hitRanges = alpaka::getPtrNative(module_hitRanges_buf); - for (unsigned int i = 0; i < nLowerModules; i++) { + for (unsigned int i = 0; i < nLowerModules_; i++) { if (!(nMDsCPU[i] == 0 or module_hitRanges[i * 2] == -1)) { if (module_subdets[i] == Barrel) { n_minidoublets_by_layer_barrel_[module_layers[i] - 1] += nMDsCPU[i]; @@ -1175,14 +1175,14 @@ void SDL::Event::addMiniDoubletsToEventExplicit() { } void SDL::Event::addSegmentsToEventExplicit() { - auto nSegmentsCPU_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, nSegmentsCPU_buf, segmentsBuffers->nSegments_buf, nLowerModules); + auto nSegmentsCPU_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, nSegmentsCPU_buf, segmentsBuffers->nSegments_buf, nLowerModules_); - auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); + auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, module_subdets_buf, modulesBuffers_->subdets_buf, nLowerModules_); - auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); + auto module_layers_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, module_layers_buf, modulesBuffers_->layers_buf, nLowerModules_); alpaka::wait(queue); @@ -1190,7 +1190,7 @@ void SDL::Event::addSegmentsToEventExplicit() { short* module_subdets = alpaka::getPtrNative(module_subdets_buf); short* module_layers = alpaka::getPtrNative(module_layers_buf); - for (unsigned int i = 0; i < nLowerModules; i++) { + for (unsigned int i = 0; i < nLowerModules_; i++) { if (!(nSegmentsCPU[i] == 0)) { if (module_subdets[i] == Barrel) { n_segments_by_layer_barrel_[module_layers[i] - 1] += nSegmentsCPU[i]; @@ -1202,16 +1202,16 @@ void SDL::Event::addSegmentsToEventExplicit() { } void SDL::Event::addQuintupletsToEventExplicit() { - auto nQuintupletsCPU_buf = allocBufWrapper(devHost, nLowerModules, queue); + auto nQuintupletsCPU_buf = allocBufWrapper(devHost, nLowerModules_, queue); alpaka::memcpy(queue, nQuintupletsCPU_buf, quintupletsBuffers->nQuintuplets_buf); - auto module_subdets_buf = allocBufWrapper(devHost, nModules, queue); - alpaka::memcpy(queue, module_subdets_buf, modulesBuffers->subdets_buf, nModules); + auto module_subdets_buf = allocBufWrapper(devHost, nModules_, queue); + alpaka::memcpy(queue, module_subdets_buf, modulesBuffers_->subdets_buf, nModules_); - auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); + auto module_layers_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, module_layers_buf, modulesBuffers_->layers_buf, nLowerModules_); - auto module_quintupletModuleIndices_buf = allocBufWrapper(devHost, nLowerModules, queue); + auto module_quintupletModuleIndices_buf = allocBufWrapper(devHost, nLowerModules_, queue); alpaka::memcpy(queue, module_quintupletModuleIndices_buf, rangesBuffers->quintupletModuleIndices_buf); alpaka::wait(queue); @@ -1221,7 +1221,7 @@ void SDL::Event::addQuintupletsToEventExplicit() { short* module_layers = alpaka::getPtrNative(module_layers_buf); int* module_quintupletModuleIndices = alpaka::getPtrNative(module_quintupletModuleIndices_buf); - for (uint16_t i = 0; i < nLowerModules; i++) { + for (uint16_t i = 0; i < nLowerModules_; i++) { if (!(nQuintupletsCPU[i] == 0 or module_quintupletModuleIndices[i] == -1)) { if (module_subdets[i] == Barrel) { n_quintuplets_by_layer_barrel_[module_layers[i] - 1] += nQuintupletsCPU[i]; @@ -1233,21 +1233,21 @@ void SDL::Event::addQuintupletsToEventExplicit() { } void SDL::Event::addTripletsToEventExplicit() { - auto nTripletsCPU_buf = allocBufWrapper(devHost, nLowerModules, queue); + auto nTripletsCPU_buf = allocBufWrapper(devHost, nLowerModules_, queue); alpaka::memcpy(queue, nTripletsCPU_buf, tripletsBuffers->nTriplets_buf); - auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, module_subdets_buf, modulesBuffers->subdets_buf, nLowerModules); + auto module_subdets_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, module_subdets_buf, modulesBuffers_->subdets_buf, nLowerModules_); - auto module_layers_buf = allocBufWrapper(devHost, nLowerModules, queue); - alpaka::memcpy(queue, module_layers_buf, modulesBuffers->layers_buf, nLowerModules); + auto module_layers_buf = allocBufWrapper(devHost, nLowerModules_, queue); + alpaka::memcpy(queue, module_layers_buf, modulesBuffers_->layers_buf, nLowerModules_); alpaka::wait(queue); unsigned int* nTripletsCPU = alpaka::getPtrNative(nTripletsCPU_buf); short* module_subdets = alpaka::getPtrNative(module_subdets_buf); short* module_layers = alpaka::getPtrNative(module_layers_buf); - for (uint16_t i = 0; i < nLowerModules; i++) { + for (uint16_t i = 0; i < nLowerModules_; i++) { if (nTripletsCPU[i] != 0) { if (module_subdets[i] == Barrel) { n_triplets_by_layer_barrel_[module_layers[i] - 1] += nTripletsCPU[i]; @@ -1492,7 +1492,7 @@ SDL::hitsBuffer* SDL::Event::getHits() //std::shared_ alpaka::wait(queue); unsigned int nHits = *alpaka::getPtrNative(nHits_buf); - hitsInCPU = new SDL::hitsBuffer(nModules, nHits, devHost, queue); + hitsInCPU = new SDL::hitsBuffer(nModules_, nHits, devHost, queue); hitsInCPU->setData(*hitsInCPU); *alpaka::getPtrNative(hitsInCPU->nHits_buf) = nHits; @@ -1514,7 +1514,7 @@ SDL::hitsBuffer* SDL::Event::getHitsInCMSSW() { alpaka::wait(queue); unsigned int nHits = *alpaka::getPtrNative(nHits_buf); - hitsInCPU = new SDL::hitsBuffer(nModules, nHits, devHost, queue); + hitsInCPU = new SDL::hitsBuffer(nModules_, nHits, devHost, queue); hitsInCPU->setData(*hitsInCPU); *alpaka::getPtrNative(hitsInCPU->nHits_buf) = nHits; @@ -1526,7 +1526,7 @@ SDL::hitsBuffer* SDL::Event::getHitsInCMSSW() { SDL::objectRangesBuffer* SDL::Event::getRanges() { if (rangesInCPU == nullptr) { - rangesInCPU = new SDL::objectRangesBuffer(nModules, nLowerModules, devHost, queue); + rangesInCPU = new SDL::objectRangesBuffer(nModules_, nLowerModules_, devHost, queue); rangesInCPU->setData(*rangesInCPU); alpaka::memcpy(queue, rangesInCPU->hitRanges_buf, rangesBuffers->hitRanges_buf); @@ -1547,7 +1547,7 @@ SDL::miniDoubletsBuffer* SDL::Event::getMiniDoublets() alpaka::wait(queue); unsigned int nMemHost = *alpaka::getPtrNative(nMemHost_buf); - mdsInCPU = new SDL::miniDoubletsBuffer(nMemHost, nLowerModules, devHost, queue); + mdsInCPU = new SDL::miniDoubletsBuffer(nMemHost, nLowerModules_, devHost, queue); mdsInCPU->setData(*mdsInCPU); *alpaka::getPtrNative(mdsInCPU->nMemoryLocations_buf) = nMemHost; @@ -1570,7 +1570,7 @@ SDL::segmentsBuffer* SDL::Event::getSegments() { unsigned int nMemHost = *alpaka::getPtrNative(nMemHost_buf); segmentsInCPU = new SDL::segmentsBuffer( - nMemHost, nLowerModules, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devHost, queue); + nMemHost, nLowerModules_, N_MAX_PIXEL_SEGMENTS_PER_MODULE, devHost, queue); segmentsInCPU->setData(*segmentsInCPU); *alpaka::getPtrNative(segmentsInCPU->nMemoryLocations_buf) = nMemHost; @@ -1605,7 +1605,7 @@ SDL::tripletsBuffer* SDL::Event::getTriplets() { alpaka::wait(queue); unsigned int nMemHost = *alpaka::getPtrNative(nMemHost_buf); - tripletsInCPU = new SDL::tripletsBuffer(nMemHost, nLowerModules, devHost, queue); + tripletsInCPU = new SDL::tripletsBuffer(nMemHost, nLowerModules_, devHost, queue); tripletsInCPU->setData(*tripletsInCPU); *alpaka::getPtrNative(tripletsInCPU->nMemoryLocations_buf) = nMemHost; @@ -1639,7 +1639,7 @@ SDL::quintupletsBuffer* SDL::Event::getQuintuplets() { alpaka::wait(queue); unsigned int nMemHost = *alpaka::getPtrNative(nMemHost_buf); - quintupletsInCPU = new SDL::quintupletsBuffer(nMemHost, nLowerModules, devHost, queue); + quintupletsInCPU = new SDL::quintupletsBuffer(nMemHost, nLowerModules_, devHost, queue); quintupletsInCPU->setData(*quintupletsInCPU); *alpaka::getPtrNative(quintupletsInCPU->nMemoryLocations_buf) = nMemHost; @@ -1803,9 +1803,9 @@ SDL::trackCandidatesBuffer* SDL::Event::getTrackCandid SDL::modulesBuffer* SDL::Event::getModules(bool isFull) { if (modulesInCPU == nullptr) { // The last input here is just a small placeholder for the allocation. - modulesInCPU = new SDL::modulesBuffer(devHost, nModules, nPixels); + modulesInCPU = new SDL::modulesBuffer(devHost, nModules_, nPixels_); - modulesInCPU->copyFromSrc(queue, *modulesBuffers, isFull); + modulesInCPU->copyFromSrc(queue, *modulesBuffers_, isFull); } return modulesInCPU; } diff --git a/SDL/Event.h b/SDL/Event.h index 4c499b0a..f7581a12 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -87,12 +87,12 @@ namespace SDL { int8_t* pixelTypeCPU; // Stuff that used to be global - const uint16_t nModules; - const uint16_t nLowerModules; - const unsigned int nPixels; - const std::shared_ptr> modulesBuffers; - const std::shared_ptr pixelMapping; - const std::shared_ptr> endcapGeometry; + const uint16_t nModules_; + const uint16_t nLowerModules_; + const unsigned int nPixels_; + const std::shared_ptr> modulesBuffers_; + const std::shared_ptr pixelMapping_; + const std::shared_ptr> endcapGeometry_; public: // Constructor used for CMSSW integration. Uses an external queue. @@ -101,12 +101,12 @@ namespace SDL { : queue(q), devAcc(alpaka::getDev(q)), devHost(cms::alpakatools::host()), - nModules(deviceESData->nModules), - nLowerModules(deviceESData->nLowerModules), - nPixels(deviceESData->nPixels), - modulesBuffers(deviceESData->modulesBuffers), - pixelMapping(deviceESData->pixelMapping), - endcapGeometry(deviceESData->endcapGeometry) { + nModules_(deviceESData->nModules), + nLowerModules_(deviceESData->nLowerModules), + nPixels_(deviceESData->nPixels), + modulesBuffers_(deviceESData->modulesBuffers), + pixelMapping_(deviceESData->pixelMapping), + endcapGeometry_(deviceESData->endcapGeometry) { init(verbose); } void resetEvent(); From bb35daf335c5170eab9fc9dbf6ed18d4bfef9670 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 21 May 2024 13:51:45 -0400 Subject: [PATCH 18/23] Added CopyToDevice implementation for LSTESHostData --- SDL/LST.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/SDL/LST.h b/SDL/LST.h index e1c9cfba..a35b0c03 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -1,6 +1,8 @@ #ifndef LST_H #define LST_H +#include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h" + #ifdef LST_IS_CMSSW_PACKAGE #include "RecoTracker/LSTCore/interface/alpaka/Constants.h" #else @@ -167,4 +169,14 @@ namespace SDL { } // namespace SDL +namespace cms::alpakatools { + template <> + struct CopyToDevice { + template + static auto copyAsync(TQueue& queue, SDL::LSTESHostData const& hostData) { + return std::make_unique(hostData); + } + }; +} + #endif From 430818272ac833ef0df9277f8286dd795be6ab53 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 21 May 2024 16:09:52 -0400 Subject: [PATCH 19/23] Revert to using templates and clean up --- SDL/EndcapGeometry.cc | 14 ++--- SDL/EndcapGeometry.h | 24 ++++---- SDL/Event.h | 2 +- SDL/LST.cc | 103 ---------------------------------- SDL/LST.h | 71 +---------------------- SDL/LSTESData.cc | 112 +++++++++++++++++++++++++++++++++++++ SDL/LSTESData.h | 90 +++++++++++++++++++++++++++++ SDL/ModuleConnectionMap.cc | 16 +++--- SDL/ModuleConnectionMap.h | 8 ++- SDL/ModuleMethods.h | 8 +-- SDL/TiltedGeometry.cc | 8 +-- SDL/TiltedGeometry.h | 5 +- code/core/AnalysisConfig.h | 2 +- 13 files changed, 253 insertions(+), 210 deletions(-) create mode 100644 SDL/LSTESData.cc create mode 100644 SDL/LSTESData.h diff --git a/SDL/EndcapGeometry.cc b/SDL/EndcapGeometry.cc index 55f89ef1..2b5be62e 100644 --- a/SDL/EndcapGeometry.cc +++ b/SDL/EndcapGeometry.cc @@ -1,8 +1,8 @@ #include "EndcapGeometry.h" -SDL::EndcapGeometry::EndcapGeometry(SDL::Dev const& devAccIn, - SDL::QueueAcc& queue, - SDL::EndcapGeometry const& endcapGeometryIn) +SDL::EndcapGeometry::EndcapGeometry(SDL::Dev const& devAccIn, + SDL::QueueAcc& queue, + SDL::EndcapGeometryHost const& endcapGeometryIn) : geoMapDetId_buf(allocBufWrapper(devAccIn, endcapGeometryIn.centroid_phis_.size())), geoMapPhi_buf(allocBufWrapper(devAccIn, endcapGeometryIn.centroid_phis_.size())) { dxdy_slope_ = endcapGeometryIn.dxdy_slope_; @@ -10,7 +10,7 @@ SDL::EndcapGeometry::EndcapGeometry(SDL::Dev const& devAccIn, fillGeoMapArraysExplicit(queue); } -void SDL::EndcapGeometry::load(std::string filename) { +void SDL::EndcapGeometryHost::load(std::string filename) { dxdy_slope_.clear(); centroid_phis_.clear(); @@ -40,7 +40,7 @@ void SDL::EndcapGeometry::load(std::string filename) { } } -void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc& queue) { +void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc& queue) { unsigned int phi_size = centroid_phis_.size(); // Allocate buffers on host @@ -69,14 +69,14 @@ void SDL::EndcapGeometry::fillGeoMapArraysExplicit(SDL::QueueAcc alpaka::wait(queue); } -float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { +float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { if (dxdy_slope_.find(detid) != dxdy_slope_.end()) { return dxdy_slope_.at(detid); } else { return 0; } } -float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) const { +float SDL::EndcapGeometryHost::getdxdy_slope(unsigned int detid) const { if (dxdy_slope_.find(detid) != dxdy_slope_.end()) { return dxdy_slope_.at(detid); } else { diff --git a/SDL/EndcapGeometry.h b/SDL/EndcapGeometry.h index 970a558a..93da945c 100644 --- a/SDL/EndcapGeometry.h +++ b/SDL/EndcapGeometry.h @@ -19,36 +19,40 @@ namespace SDL { - // Only the full one contains alpaka buffers - template - class EndcapGeometry; + // FIXME: Need to separate this better into host and device classes + // This is only needed for host, but we template it to avoid symbol conflicts + template + class EndcapGeometryHost; template <> - class EndcapGeometry { + class EndcapGeometryHost { public: std::map dxdy_slope_; // dx/dy slope std::map centroid_phis_; // centroid phi - EndcapGeometry() = default; - ~EndcapGeometry() = default; + EndcapGeometryHost() = default; + ~EndcapGeometryHost() = default; void load(std::string); float getdxdy_slope(unsigned int detid) const; }; + template + class EndcapGeometry; + template <> - class EndcapGeometry { + class EndcapGeometry { private: std::map dxdy_slope_; // dx/dy slope std::map centroid_phis_; // centroid phi public: - Buf geoMapDetId_buf; - Buf geoMapPhi_buf; + Buf geoMapDetId_buf; + Buf geoMapPhi_buf; unsigned int nEndCapMap; - EndcapGeometry(Dev const& devAccIn, QueueAcc& queue, SDL::EndcapGeometry const& endcapGeometryIn); + EndcapGeometry(Dev const& devAccIn, QueueAcc& queue, SDL::EndcapGeometryHost const& endcapGeometryIn); ~EndcapGeometry() = default; void fillGeoMapArraysExplicit(QueueAcc& queue); diff --git a/SDL/Event.h b/SDL/Event.h index f7581a12..3d301c2c 100644 --- a/SDL/Event.h +++ b/SDL/Event.h @@ -92,7 +92,7 @@ namespace SDL { const unsigned int nPixels_; const std::shared_ptr> modulesBuffers_; const std::shared_ptr pixelMapping_; - const std::shared_ptr> endcapGeometry_; + const std::shared_ptr> endcapGeometry_; public: // Constructor used for CMSSW integration. Uses an external queue. diff --git a/SDL/LST.cc b/SDL/LST.cc index aa98fb3a..9f916d12 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -9,109 +9,6 @@ #include "Math/Vector3D.h" using XYZVector = ROOT::Math::XYZVector; -namespace { - std::string trackLooperDir() { - const char* path_lst_base = std::getenv("LST_BASE"); - const char* path_tracklooperdir = std::getenv("TRACKLOOPERDIR"); - std::string path_str; - if (path_lst_base != nullptr) { - path_str = path_lst_base; - } else if (path_tracklooperdir != nullptr) { - path_str = path_tracklooperdir; - } else { - // FIXME: temporary solution, will need to pass a value from FileInPath or CMSSW search path - // in the `LSTProducer` or a related ES producer - path_str = std::getenv("CMSSW_BASE"); - path_str += "/src/RecoTracker/LSTCore/TrackLooper"; - } - return path_str; - } - - std::string get_absolute_path_after_check_file_exists(const std::string name) { - std::filesystem::path fullpath = std::filesystem::absolute(name.c_str()); - if (not std::filesystem::exists(fullpath)) { - std::cout << "ERROR: Could not find the file = " << fullpath << std::endl; - exit(2); - } - return fullpath.string(); - } - - void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer, - std::shared_ptr> endcapGeometry, - std::shared_ptr tiltedGeometry, - std::shared_ptr moduleConnectionMap) { - // Module orientation information (DrDz or phi angles) - auto endcap_geom = - get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); - auto tilted_geom = get_absolute_path_after_check_file_exists( - trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); - // Module connection map (for line segment building) - auto mappath = get_absolute_path_after_check_file_exists( - trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); - - endcapGeometry->load(endcap_geom); - tiltedGeometry->load(tilted_geom); - moduleConnectionMap->load(mappath); - - auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map"; - const std::array connects{ - {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}}; - std::string path; - - static_assert(connects.size() == std::tuple_size>{}); - for (unsigned int i = 0; i < connects.size(); i++) { - auto connectData = connects[i].data(); - - path = pLSMapDir + connectData + ".bin"; - pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - - path = pLSMapDir + "_pos" + connectData + ".bin"; - pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - - path = pLSMapDir + "_neg" + connectData + ".bin"; - pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - } - } - -} // namespace - -std::unique_ptr SDL::loadAndFillESHost() { - auto pLStoLayer = std::make_shared(); - auto endcapGeometry = std::make_shared>(); - auto tiltedGeometry = std::make_shared(); - auto moduleConnectionMap = std::make_shared(); - ::loadMapsHost(*pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); - return std::make_unique(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); -} - -std::unique_ptr> SDL::loadAndFillESDevice(SDL::QueueAcc& queue, - const LSTESHostData* hostData) { - SDL::Dev const& devAccIn = alpaka::getDev(queue); - uint16_t nModules; - uint16_t nLowerModules; - unsigned int nPixels; - std::shared_ptr> modulesBuffers = nullptr; - auto endcapGeometry = - std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); - auto pixelMapping = std::make_shared(); - auto moduleConnectionMap = hostData->moduleConnectionMap; - - auto path = - get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); - SDL::loadModulesFromFile(queue, - hostData->mapPLStoLayer.get(), - path.c_str(), - nModules, - nLowerModules, - nPixels, - modulesBuffers, - pixelMapping.get(), - endcapGeometry.get(), - hostData->tiltedGeometry.get(), - moduleConnectionMap.get()); - return std::make_unique>( - nModules, nLowerModules, nPixels, modulesBuffers, endcapGeometry, pixelMapping); -} void SDL::LST::run(SDL::QueueAcc& queue, bool verbose, diff --git a/SDL/LST.h b/SDL/LST.h index a35b0c03..7d9d1174 100644 --- a/SDL/LST.h +++ b/SDL/LST.h @@ -1,15 +1,14 @@ #ifndef LST_H #define LST_H -#include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h" - #ifdef LST_IS_CMSSW_PACKAGE #include "RecoTracker/LSTCore/interface/alpaka/Constants.h" +#include "RecoTracker/LSTCore/interface/alpaka/LSTESData.h" #else #include "Constants.h" +#include "LSTESData.h" #endif -#include #include #include #include @@ -19,65 +18,9 @@ namespace SDL { template class Event; - struct pixelMap; - class TiltedGeometry; - class ModuleConnectionMap; - using MapPLStoLayer = std::array, 3>; - - template - struct modulesBuffer; - - template - class EndcapGeometry; - - struct LSTESHostData { - const std::shared_ptr mapPLStoLayer; - const std::shared_ptr> endcapGeometry; - const std::shared_ptr tiltedGeometry; - const std::shared_ptr moduleConnectionMap; - - LSTESHostData(std::shared_ptr mapPLStoLayerIn, - std::shared_ptr> endcapGeometryIn, - std::shared_ptr tiltedGeometryIn, - std::shared_ptr moduleConnectionMapIn) - : mapPLStoLayer(std::const_pointer_cast(mapPLStoLayerIn)), - endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), - tiltedGeometry(std::const_pointer_cast(tiltedGeometryIn)), - moduleConnectionMap(std::const_pointer_cast(moduleConnectionMapIn)) {} - }; - - template - struct LSTESDeviceData { - const uint16_t nModules; - const uint16_t nLowerModules; - const unsigned int nPixels; - const std::shared_ptr> modulesBuffers; - const std::shared_ptr> endcapGeometry; - const std::shared_ptr pixelMapping; - - LSTESDeviceData(uint16_t nModulesIn, - uint16_t nLowerModulesIn, - unsigned int nPixelsIn, - std::shared_ptr> modulesBuffersIn, - std::shared_ptr> endcapGeometryIn, - std::shared_ptr pixelMappingIn) - : nModules(nModulesIn), - nLowerModules(nLowerModulesIn), - nPixels(nPixelsIn), - modulesBuffers(std::const_pointer_cast>(modulesBuffersIn)), - endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), - pixelMapping(std::const_pointer_cast(pixelMappingIn)) {} - }; - - std::unique_ptr loadAndFillESHost(); - std::unique_ptr> loadAndFillESDevice(SDL::QueueAcc& queue, const LSTESHostData* hostData); - template class LST; - template <> - class LST {}; - template <> class LST { public: @@ -169,14 +112,4 @@ namespace SDL { } // namespace SDL -namespace cms::alpakatools { - template <> - struct CopyToDevice { - template - static auto copyAsync(TQueue& queue, SDL::LSTESHostData const& hostData) { - return std::make_unique(hostData); - } - }; -} - #endif diff --git a/SDL/LSTESData.cc b/SDL/LSTESData.cc new file mode 100644 index 00000000..7586f95f --- /dev/null +++ b/SDL/LSTESData.cc @@ -0,0 +1,112 @@ +#ifdef LST_IS_CMSSW_PACKAGE +#include "RecoTracker/LSTCore/interface/alpaka/LSTESData.h" +#else +#include "LSTESData.h" +#endif + +#include "EndcapGeometry.h" +#include "ModuleConnectionMap.h" +#include "TiltedGeometry.h" +#include "PixelMap.h" +#include "ModuleMethods.h" + +std::string trackLooperDir() { + const char* path_lst_base = std::getenv("LST_BASE"); + const char* path_tracklooperdir = std::getenv("TRACKLOOPERDIR"); + std::string path_str; + if (path_lst_base != nullptr) { + path_str = path_lst_base; + } else if (path_tracklooperdir != nullptr) { + path_str = path_tracklooperdir; + } else { + // FIXME: temporary solution, will need to pass a value from FileInPath or CMSSW search path + // in the `LSTProducer` or a related ES producer + path_str = std::getenv("CMSSW_BASE"); + path_str += "/src/RecoTracker/LSTCore/TrackLooper"; + } + return path_str; +} + +std::string get_absolute_path_after_check_file_exists(const std::string name) { + std::filesystem::path fullpath = std::filesystem::absolute(name.c_str()); + if (not std::filesystem::exists(fullpath)) { + std::cout << "ERROR: Could not find the file = " << fullpath << std::endl; + exit(2); + } + return fullpath.string(); +} + +void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer, + std::shared_ptr> endcapGeometry, + std::shared_ptr> tiltedGeometry, + std::shared_ptr> moduleConnectionMap) { + // Module orientation information (DrDz or phi angles) + auto endcap_geom = + get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); + auto tilted_geom = get_absolute_path_after_check_file_exists( + trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); + // Module connection map (for line segment building) + auto mappath = get_absolute_path_after_check_file_exists( + trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); + + endcapGeometry->load(endcap_geom); + tiltedGeometry->load(tilted_geom); + moduleConnectionMap->load(mappath); + + auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map"; + const std::array connects{ + {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}}; + std::string path; + + static_assert(connects.size() == std::tuple_size>{}); + for (unsigned int i = 0; i < connects.size(); i++) { + auto connectData = connects[i].data(); + + path = pLSMapDir + connectData + ".bin"; + pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + + path = pLSMapDir + "_pos" + connectData + ".bin"; + pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + + path = pLSMapDir + "_neg" + connectData + ".bin"; + pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + } +} + +std::unique_ptr> SDL::loadAndFillESHost() { + auto pLStoLayer = std::make_shared(); + auto endcapGeometry = std::make_shared>(); + auto tiltedGeometry = std::make_shared>(); + auto moduleConnectionMap = std::make_shared>(); + loadMapsHost(*pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); + return std::make_unique>(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); +} + +std::unique_ptr> SDL::loadAndFillESDevice(SDL::QueueAcc& queue, + const LSTESHostData* hostData) { + SDL::Dev const& devAccIn = alpaka::getDev(queue); + uint16_t nModules; + uint16_t nLowerModules; + unsigned int nPixels; + std::shared_ptr> modulesBuffers = nullptr; + auto endcapGeometry = + std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); + auto pixelMapping = std::make_shared(); + auto moduleConnectionMap = hostData->moduleConnectionMap; + + auto path = + get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin"); + SDL::loadModulesFromFile(queue, + hostData->mapPLStoLayer.get(), + path.c_str(), + nModules, + nLowerModules, + nPixels, + modulesBuffers, + pixelMapping.get(), + endcapGeometry.get(), + hostData->tiltedGeometry.get(), + moduleConnectionMap.get()); + return std::make_unique>( + nModules, nLowerModules, nPixels, modulesBuffers, endcapGeometry, pixelMapping); +} \ No newline at end of file diff --git a/SDL/LSTESData.h b/SDL/LSTESData.h new file mode 100644 index 00000000..6a47cdd9 --- /dev/null +++ b/SDL/LSTESData.h @@ -0,0 +1,90 @@ +#ifndef LSTESData_H +#define LSTESData_H + +#ifdef LST_IS_CMSSW_PACKAGE +#include "RecoTracker/LSTCore/interface/alpaka/Constants.h" +#else +#include "Constants.h" +#endif + +#include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h" + +#include +#include + +namespace SDL { + + struct pixelMap; + + template + class TiltedGeometry; + + template + class ModuleConnectionMap; + using MapPLStoLayer = std::array, 4>, 3>; + + template + struct modulesBuffer; + + template + class EndcapGeometryHost; + + template + class EndcapGeometry; + + template + struct LSTESHostData { + const std::shared_ptr mapPLStoLayer; + const std::shared_ptr> endcapGeometry; + const std::shared_ptr> tiltedGeometry; + const std::shared_ptr> moduleConnectionMap; + + LSTESHostData(std::shared_ptr mapPLStoLayerIn, + std::shared_ptr> endcapGeometryIn, + std::shared_ptr> tiltedGeometryIn, + std::shared_ptr> moduleConnectionMapIn) + : mapPLStoLayer(std::const_pointer_cast(mapPLStoLayerIn)), + endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), + tiltedGeometry(std::const_pointer_cast>(tiltedGeometryIn)), + moduleConnectionMap(std::const_pointer_cast>(moduleConnectionMapIn)) {} + }; + + template + struct LSTESDeviceData { + const uint16_t nModules; + const uint16_t nLowerModules; + const unsigned int nPixels; + const std::shared_ptr> modulesBuffers; + const std::shared_ptr> endcapGeometry; + const std::shared_ptr pixelMapping; + + LSTESDeviceData(uint16_t nModulesIn, + uint16_t nLowerModulesIn, + unsigned int nPixelsIn, + std::shared_ptr> modulesBuffersIn, + std::shared_ptr> endcapGeometryIn, + std::shared_ptr pixelMappingIn) + : nModules(nModulesIn), + nLowerModules(nLowerModulesIn), + nPixels(nPixelsIn), + modulesBuffers(std::const_pointer_cast>(modulesBuffersIn)), + endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), + pixelMapping(std::const_pointer_cast(pixelMappingIn)) {} + }; + + std::unique_ptr> loadAndFillESHost(); + std::unique_ptr> loadAndFillESDevice(SDL::QueueAcc& queue, const LSTESHostData* hostData); + +} // namespace SDL + +namespace cms::alpakatools { + template <> + struct CopyToDevice> { + template + static auto copyAsync(TQueue& queue, SDL::LSTESHostData const& hostData) { + return std::make_unique>(hostData); + } + }; +} // namespace cms::alpakatools + +#endif diff --git a/SDL/ModuleConnectionMap.cc b/SDL/ModuleConnectionMap.cc index e866aa5e..9a1ee2de 100644 --- a/SDL/ModuleConnectionMap.cc +++ b/SDL/ModuleConnectionMap.cc @@ -1,12 +1,12 @@ #include "ModuleConnectionMap.h" -SDL::ModuleConnectionMap::ModuleConnectionMap() {} +SDL::ModuleConnectionMap::ModuleConnectionMap() {} -SDL::ModuleConnectionMap::ModuleConnectionMap(std::string filename) { load(filename); } +SDL::ModuleConnectionMap::ModuleConnectionMap(std::string filename) { load(filename); } -SDL::ModuleConnectionMap::~ModuleConnectionMap() {} +SDL::ModuleConnectionMap::~ModuleConnectionMap() {} -void SDL::ModuleConnectionMap::load(std::string filename) { +void SDL::ModuleConnectionMap::load(std::string filename) { moduleConnections_.clear(); std::ifstream ifile(filename, std::ios::binary); @@ -49,7 +49,7 @@ void SDL::ModuleConnectionMap::load(std::string filename) { } } -void SDL::ModuleConnectionMap::add(std::string filename) { +void SDL::ModuleConnectionMap::add(std::string filename) { std::ifstream ifile; ifile.open(filename.c_str()); std::string line; @@ -81,7 +81,7 @@ void SDL::ModuleConnectionMap::add(std::string filename) { } } -void SDL::ModuleConnectionMap::print() { +void SDL::ModuleConnectionMap::print() { std::cout << "Printing ModuleConnectionMap" << std::endl; for (auto& pair : moduleConnections_) { unsigned int detid = pair.first; @@ -93,9 +93,9 @@ void SDL::ModuleConnectionMap::print() { } } -const std::vector& SDL::ModuleConnectionMap::getConnectedModuleDetIds(unsigned int detid) const { +const std::vector& SDL::ModuleConnectionMap::getConnectedModuleDetIds(unsigned int detid) const { static const std::vector dummy; auto const mList = moduleConnections_.find(detid); return mList != moduleConnections_.end() ? mList->second : dummy; } -int SDL::ModuleConnectionMap::size() const { return moduleConnections_.size(); } +int SDL::ModuleConnectionMap::size() const { return moduleConnections_.size(); } diff --git a/SDL/ModuleConnectionMap.h b/SDL/ModuleConnectionMap.h index 57e1a871..45d629a7 100644 --- a/SDL/ModuleConnectionMap.h +++ b/SDL/ModuleConnectionMap.h @@ -15,7 +15,11 @@ #endif namespace SDL { - class ModuleConnectionMap { + //FIXME: move to non-alpaka single arch build + template + class ModuleConnectionMap; + template <> + class ModuleConnectionMap { private: std::map> moduleConnections_; @@ -32,7 +36,7 @@ namespace SDL { int size() const; }; - using MapPLStoLayer = std::array, 3>; + using MapPLStoLayer = std::array, 4>, 3>; } // namespace SDL #endif diff --git a/SDL/ModuleMethods.h b/SDL/ModuleMethods.h index fc8625b6..dc0eb0fc 100644 --- a/SDL/ModuleMethods.h +++ b/SDL/ModuleMethods.h @@ -116,7 +116,7 @@ namespace SDL { unsigned int nMod, TQueue queue, struct ModuleMetaData& mmd, - const ModuleConnectionMap* moduleConnectionMap) { + const ModuleConnectionMap* moduleConnectionMap) { DevHost const& devHost = cms::alpakatools::host(); auto moduleMap_buf = allocBufWrapper(devHost, nMod * MAX_CONNECTED_MODULES); uint16_t* moduleMap = alpaka::getPtrNative(moduleMap_buf); @@ -234,9 +234,9 @@ namespace SDL { unsigned int& nPixels, std::shared_ptr>& modulesBuf, pixelMap* pixelMapping, - const EndcapGeometry* endcapGeometry, - const TiltedGeometry* tiltedGeometry, - const ModuleConnectionMap* moduleConnectionMap) { + const EndcapGeometry* endcapGeometry, + const TiltedGeometry* tiltedGeometry, + const ModuleConnectionMap* moduleConnectionMap) { ModuleMetaData mmd; loadCentroidsFromFile(moduleMetaDataFilePath, mmd, nModules); diff --git a/SDL/TiltedGeometry.cc b/SDL/TiltedGeometry.cc index 598c73cd..862155ab 100644 --- a/SDL/TiltedGeometry.cc +++ b/SDL/TiltedGeometry.cc @@ -1,8 +1,8 @@ #include "TiltedGeometry.h" -SDL::TiltedGeometry::TiltedGeometry(std::string filename) { load(filename); } +SDL::TiltedGeometry::TiltedGeometry(std::string filename) { load(filename); } -void SDL::TiltedGeometry::load(std::string filename) { +void SDL::TiltedGeometry::load(std::string filename) { drdzs_.clear(); dxdys_.clear(); @@ -32,7 +32,7 @@ void SDL::TiltedGeometry::load(std::string filename) { } } -float SDL::TiltedGeometry::getDrDz(unsigned int detid) const { +float SDL::TiltedGeometry::getDrDz(unsigned int detid) const { if (drdzs_.find(detid) != drdzs_.end()) { return drdzs_.at(detid); } else { @@ -40,7 +40,7 @@ float SDL::TiltedGeometry::getDrDz(unsigned int detid) const { } } -float SDL::TiltedGeometry::getDxDy(unsigned int detid) const { +float SDL::TiltedGeometry::getDxDy(unsigned int detid) const { if (dxdys_.find(detid) != dxdys_.end()) { return dxdys_.at(detid); } else { diff --git a/SDL/TiltedGeometry.h b/SDL/TiltedGeometry.h index 15204391..51481762 100644 --- a/SDL/TiltedGeometry.h +++ b/SDL/TiltedGeometry.h @@ -16,7 +16,10 @@ #endif namespace SDL { - class TiltedGeometry { + template + class TiltedGeometry; + template <> + class TiltedGeometry { private: std::map drdzs_; // dr/dz slope std::map dxdys_; // dx/dy slope diff --git a/code/core/AnalysisConfig.h b/code/core/AnalysisConfig.h index a6e719dc..34242659 100644 --- a/code/core/AnalysisConfig.h +++ b/code/core/AnalysisConfig.h @@ -103,7 +103,7 @@ class AnalysisConfig std::map>> moduleSimHits; std::map modulePopulation; - SDL::ModuleConnectionMap moduleConnectiongMapLoose; + SDL::ModuleConnectionMap moduleConnectiongMapLoose; // Boolean to trigger whether to run cut_value_ntupling bool do_cut_value_ntuple; From f0d23d00268191d51f8cd613d69f007e31f2c4c3 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 21 May 2024 17:04:02 -0400 Subject: [PATCH 20/23] Fixed CMSSW compilation --- SDL/LSTESData.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/SDL/LSTESData.h b/SDL/LSTESData.h index 6a47cdd9..2c2b9f69 100644 --- a/SDL/LSTESData.h +++ b/SDL/LSTESData.h @@ -33,20 +33,24 @@ namespace SDL { class EndcapGeometry; template - struct LSTESHostData { + struct LSTESHostData; + + // FIXME: This shouldn't be a templated struct + template <> + struct LSTESHostData { const std::shared_ptr mapPLStoLayer; - const std::shared_ptr> endcapGeometry; - const std::shared_ptr> tiltedGeometry; - const std::shared_ptr> moduleConnectionMap; + const std::shared_ptr> endcapGeometry; + const std::shared_ptr> tiltedGeometry; + const std::shared_ptr> moduleConnectionMap; LSTESHostData(std::shared_ptr mapPLStoLayerIn, - std::shared_ptr> endcapGeometryIn, - std::shared_ptr> tiltedGeometryIn, - std::shared_ptr> moduleConnectionMapIn) + std::shared_ptr> endcapGeometryIn, + std::shared_ptr> tiltedGeometryIn, + std::shared_ptr> moduleConnectionMapIn) : mapPLStoLayer(std::const_pointer_cast(mapPLStoLayerIn)), - endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), - tiltedGeometry(std::const_pointer_cast>(tiltedGeometryIn)), - moduleConnectionMap(std::const_pointer_cast>(moduleConnectionMapIn)) {} + endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), + tiltedGeometry(std::const_pointer_cast>(tiltedGeometryIn)), + moduleConnectionMap(std::const_pointer_cast>(moduleConnectionMapIn)) {} }; template From 7c919b980a187509fa2128aaf8fcbb3be5af61d7 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Tue, 21 May 2024 14:24:41 -0700 Subject: [PATCH 21/23] Format code --- SDL/Event.cc | 6 ++++-- SDL/LST.cc | 1 - SDL/LSTESData.cc | 7 +++---- SDL/LSTESData.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SDL/Event.cc b/SDL/Event.cc index 7039f787..2eb98b58 100644 --- a/SDL/Event.cc +++ b/SDL/Event.cc @@ -1067,11 +1067,13 @@ void SDL::Event::createPixelQuintuplets() { unsigned int connectedIdxBase = pixelMapping_->connectedPixelsIndex[superbin]; connectedPixelIndex_host[i] = connectedIdxBase; } else if (pixelType == 1) { - connectedPixelSize_host[i] = pixelMapping_->connectedPixelsSizesPos[superbin]; //number of pixel connected modules + connectedPixelSize_host[i] = + pixelMapping_->connectedPixelsSizesPos[superbin]; //number of pixel connected modules unsigned int connectedIdxBase = pixelMapping_->connectedPixelsIndexPos[superbin] + pixelIndexOffsetPos; connectedPixelIndex_host[i] = connectedIdxBase; } else if (pixelType == 2) { - connectedPixelSize_host[i] = pixelMapping_->connectedPixelsSizesNeg[superbin]; //number of pixel connected modules + connectedPixelSize_host[i] = + pixelMapping_->connectedPixelsSizesNeg[superbin]; //number of pixel connected modules unsigned int connectedIdxBase = pixelMapping_->connectedPixelsIndexNeg[superbin] + pixelIndexOffsetNeg; connectedPixelIndex_host[i] = connectedIdxBase; } diff --git a/SDL/LST.cc b/SDL/LST.cc index 9f916d12..9eb11503 100644 --- a/SDL/LST.cc +++ b/SDL/LST.cc @@ -9,7 +9,6 @@ #include "Math/Vector3D.h" using XYZVector = ROOT::Math::XYZVector; - void SDL::LST::run(SDL::QueueAcc& queue, bool verbose, const LSTESDeviceData* deviceESData, diff --git a/SDL/LSTESData.cc b/SDL/LSTESData.cc index 7586f95f..5d2237c4 100644 --- a/SDL/LSTESData.cc +++ b/SDL/LSTESData.cc @@ -43,8 +43,8 @@ void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer, // Module orientation information (DrDz or phi angles) auto endcap_geom = get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); - auto tilted_geom = get_absolute_path_after_check_file_exists( - trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); + auto tilted_geom = get_absolute_path_after_check_file_exists(trackLooperDir() + + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); // Module connection map (for line segment building) auto mappath = get_absolute_path_after_check_file_exists( trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); @@ -89,8 +89,7 @@ std::unique_ptr> SDL::loadAndFillESDevice(SDL::Qu uint16_t nLowerModules; unsigned int nPixels; std::shared_ptr> modulesBuffers = nullptr; - auto endcapGeometry = - std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); + auto endcapGeometry = std::make_shared>(devAccIn, queue, *hostData->endcapGeometry); auto pixelMapping = std::make_shared(); auto moduleConnectionMap = hostData->moduleConnectionMap; diff --git a/SDL/LSTESData.h b/SDL/LSTESData.h index 2c2b9f69..193e343d 100644 --- a/SDL/LSTESData.h +++ b/SDL/LSTESData.h @@ -89,6 +89,6 @@ namespace cms::alpakatools { return std::make_unique>(hostData); } }; -} // namespace cms::alpakatools +} // namespace cms::alpakatools #endif From 7bc7a71252f73a913fda83afea6500eaae7a693f Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 23 May 2024 10:43:57 -0700 Subject: [PATCH 22/23] const members were overkill --- SDL/LSTESData.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/SDL/LSTESData.h b/SDL/LSTESData.h index 193e343d..29ae19a5 100644 --- a/SDL/LSTESData.h +++ b/SDL/LSTESData.h @@ -38,29 +38,29 @@ namespace SDL { // FIXME: This shouldn't be a templated struct template <> struct LSTESHostData { - const std::shared_ptr mapPLStoLayer; - const std::shared_ptr> endcapGeometry; - const std::shared_ptr> tiltedGeometry; - const std::shared_ptr> moduleConnectionMap; + std::shared_ptr mapPLStoLayer; + std::shared_ptr> endcapGeometry; + std::shared_ptr> tiltedGeometry; + std::shared_ptr> moduleConnectionMap; LSTESHostData(std::shared_ptr mapPLStoLayerIn, std::shared_ptr> endcapGeometryIn, std::shared_ptr> tiltedGeometryIn, std::shared_ptr> moduleConnectionMapIn) - : mapPLStoLayer(std::const_pointer_cast(mapPLStoLayerIn)), - endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), - tiltedGeometry(std::const_pointer_cast>(tiltedGeometryIn)), - moduleConnectionMap(std::const_pointer_cast>(moduleConnectionMapIn)) {} + : mapPLStoLayer(mapPLStoLayerIn), + endcapGeometry(endcapGeometryIn), + tiltedGeometry(tiltedGeometryIn), + moduleConnectionMap(moduleConnectionMapIn) {} }; template struct LSTESDeviceData { - const uint16_t nModules; - const uint16_t nLowerModules; - const unsigned int nPixels; - const std::shared_ptr> modulesBuffers; - const std::shared_ptr> endcapGeometry; - const std::shared_ptr pixelMapping; + uint16_t nModules; + uint16_t nLowerModules; + unsigned int nPixels; + std::shared_ptr> modulesBuffers; + std::shared_ptr> endcapGeometry; + std::shared_ptr pixelMapping; LSTESDeviceData(uint16_t nModulesIn, uint16_t nLowerModulesIn, @@ -71,9 +71,9 @@ namespace SDL { : nModules(nModulesIn), nLowerModules(nLowerModulesIn), nPixels(nPixelsIn), - modulesBuffers(std::const_pointer_cast>(modulesBuffersIn)), - endcapGeometry(std::const_pointer_cast>(endcapGeometryIn)), - pixelMapping(std::const_pointer_cast(pixelMappingIn)) {} + modulesBuffers(modulesBuffersIn), + endcapGeometry(endcapGeometryIn), + pixelMapping(pixelMappingIn) {} }; std::unique_ptr> loadAndFillESHost(); From f8f31c9a0a42687941d0659774cc9fbde8ba2269 Mon Sep 17 00:00:00 2001 From: Andres Rios Tascon Date: Thu, 23 May 2024 12:12:50 -0700 Subject: [PATCH 23/23] Move load functions back into an unnamed namespace --- SDL/LSTESData.cc | 108 ++++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/SDL/LSTESData.cc b/SDL/LSTESData.cc index 5d2237c4..06dd4463 100644 --- a/SDL/LSTESData.cc +++ b/SDL/LSTESData.cc @@ -10,75 +10,77 @@ #include "PixelMap.h" #include "ModuleMethods.h" -std::string trackLooperDir() { - const char* path_lst_base = std::getenv("LST_BASE"); - const char* path_tracklooperdir = std::getenv("TRACKLOOPERDIR"); - std::string path_str; - if (path_lst_base != nullptr) { - path_str = path_lst_base; - } else if (path_tracklooperdir != nullptr) { - path_str = path_tracklooperdir; - } else { - // FIXME: temporary solution, will need to pass a value from FileInPath or CMSSW search path - // in the `LSTProducer` or a related ES producer - path_str = std::getenv("CMSSW_BASE"); - path_str += "/src/RecoTracker/LSTCore/TrackLooper"; +namespace { + std::string trackLooperDir() { + const char* path_lst_base = std::getenv("LST_BASE"); + const char* path_tracklooperdir = std::getenv("TRACKLOOPERDIR"); + std::string path_str; + if (path_lst_base != nullptr) { + path_str = path_lst_base; + } else if (path_tracklooperdir != nullptr) { + path_str = path_tracklooperdir; + } else { + // FIXME: temporary solution, will need to pass a value from FileInPath or CMSSW search path + // in the `LSTProducer` or a related ES producer + path_str = std::getenv("CMSSW_BASE"); + path_str += "/src/RecoTracker/LSTCore/TrackLooper"; + } + return path_str; } - return path_str; -} -std::string get_absolute_path_after_check_file_exists(const std::string name) { - std::filesystem::path fullpath = std::filesystem::absolute(name.c_str()); - if (not std::filesystem::exists(fullpath)) { - std::cout << "ERROR: Could not find the file = " << fullpath << std::endl; - exit(2); + std::string get_absolute_path_after_check_file_exists(const std::string name) { + std::filesystem::path fullpath = std::filesystem::absolute(name.c_str()); + if (not std::filesystem::exists(fullpath)) { + std::cout << "ERROR: Could not find the file = " << fullpath << std::endl; + exit(2); + } + return fullpath.string(); } - return fullpath.string(); -} -void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer, - std::shared_ptr> endcapGeometry, - std::shared_ptr> tiltedGeometry, - std::shared_ptr> moduleConnectionMap) { - // Module orientation information (DrDz or phi angles) - auto endcap_geom = - get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); - auto tilted_geom = get_absolute_path_after_check_file_exists(trackLooperDir() + - "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); - // Module connection map (for line segment building) - auto mappath = get_absolute_path_after_check_file_exists( - trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); + void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer, + std::shared_ptr> endcapGeometry, + std::shared_ptr> tiltedGeometry, + std::shared_ptr> moduleConnectionMap) { + // Module orientation information (DrDz or phi angles) + auto endcap_geom = + get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin"); + auto tilted_geom = get_absolute_path_after_check_file_exists( + trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin"); + // Module connection map (for line segment building) + auto mappath = get_absolute_path_after_check_file_exists( + trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin"); - endcapGeometry->load(endcap_geom); - tiltedGeometry->load(tilted_geom); - moduleConnectionMap->load(mappath); + endcapGeometry->load(endcap_geom); + tiltedGeometry->load(tilted_geom); + moduleConnectionMap->load(mappath); - auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map"; - const std::array connects{ - {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}}; - std::string path; + auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map"; + const std::array connects{ + {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}}; + std::string path; - static_assert(connects.size() == std::tuple_size>{}); - for (unsigned int i = 0; i < connects.size(); i++) { - auto connectData = connects[i].data(); + static_assert(connects.size() == std::tuple_size>{}); + for (unsigned int i = 0; i < connects.size(); i++) { + auto connectData = connects[i].data(); - path = pLSMapDir + connectData + ".bin"; - pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + path = pLSMapDir + connectData + ".bin"; + pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - path = pLSMapDir + "_pos" + connectData + ".bin"; - pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + path = pLSMapDir + "_pos" + connectData + ".bin"; + pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); - path = pLSMapDir + "_neg" + connectData + ".bin"; - pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + path = pLSMapDir + "_neg" + connectData + ".bin"; + pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path)); + } } -} +} // namespace std::unique_ptr> SDL::loadAndFillESHost() { auto pLStoLayer = std::make_shared(); auto endcapGeometry = std::make_shared>(); auto tiltedGeometry = std::make_shared>(); auto moduleConnectionMap = std::make_shared>(); - loadMapsHost(*pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); + ::loadMapsHost(*pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); return std::make_unique>(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap); } @@ -108,4 +110,4 @@ std::unique_ptr> SDL::loadAndFillESDevice(SDL::Qu moduleConnectionMap.get()); return std::make_unique>( nModules, nLowerModules, nPixels, modulesBuffers, endcapGeometry, pixelMapping); -} \ No newline at end of file +}