Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "RecoTracker/LSTCore/interface/LSTESData.h"
0002 #include "RecoTracker/LSTCore/interface/EndcapGeometry.h"
0003 #include "RecoTracker/LSTCore/interface/ModuleConnectionMap.h"
0004 #include "RecoTracker/LSTCore/interface/TiltedGeometry.h"
0005 #include "RecoTracker/LSTCore/interface/PixelMap.h"
0006 
0007 #include "ModuleMethods.h"
0008 
0009 #include <filesystem>
0010 
0011 namespace {
0012   std::string geometryDataDir() {
0013     std::string path_str, path;
0014     const char* path_tracklooperdir = std::getenv("TRACKLOOPERDIR");
0015     std::stringstream search_path;
0016     search_path << std::getenv("CMSSW_SEARCH_PATH");
0017 
0018     while (std::getline(search_path, path, ':')) {
0019       if (std::filesystem::exists(path + "/RecoTracker/LSTCore/data")) {
0020         path_str = path;
0021         break;
0022       }
0023     }
0024 
0025     if (path_str.empty()) {
0026       path_str = path_tracklooperdir;
0027       path_str += "/..";
0028     } else {
0029       path_str += "/RecoTracker/LSTCore";
0030     }
0031 
0032     return path_str;
0033   }
0034 
0035   std::string get_absolute_path_after_check_file_exists(std::string const& name) {
0036     std::filesystem::path fullpath = std::filesystem::absolute(name);
0037     if (not std::filesystem::exists(fullpath)) {
0038       throw std::runtime_error("Could not find the file = " + fullpath.string());
0039     }
0040     return fullpath.string();
0041   }
0042 
0043   void loadMapsHost(lst::MapPLStoLayer& pLStoLayer,
0044                     lst::EndcapGeometry& endcapGeometry,
0045                     lst::TiltedGeometry& tiltedGeometry,
0046                     lst::ModuleConnectionMap& moduleConnectionMap,
0047                     std::string& ptCutLabel) {
0048     // Module orientation information (DrDz or phi angles)
0049     auto endcap_geom = get_absolute_path_after_check_file_exists(geometryDataDir() + "/data/OT800_IT615_pt" +
0050                                                                  ptCutLabel + "/endcap_orientation.bin");
0051     auto tilted_geom = get_absolute_path_after_check_file_exists(geometryDataDir() + "/data/OT800_IT615_pt" +
0052                                                                  ptCutLabel + "/tilted_barrel_orientation.bin");
0053     // Module connection map (for line segment building)
0054     auto mappath = get_absolute_path_after_check_file_exists(geometryDataDir() + "/data/OT800_IT615_pt" + ptCutLabel +
0055                                                              "/module_connection_tracing_merged.bin");
0056 
0057     endcapGeometry.load(endcap_geom);
0058     tiltedGeometry.load(tilted_geom);
0059     moduleConnectionMap.load(mappath);
0060 
0061     auto pLSMapDir = geometryDataDir() + "/data/OT800_IT615_pt" + ptCutLabel + "/pixelmap/pLS_map";
0062     const std::array<std::string, 4> connects{
0063         {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}};
0064     std::string path;
0065 
0066     static_assert(connects.size() == std::tuple_size<std::decay_t<decltype(pLStoLayer[0])>>{});
0067     for (unsigned int i = 0; i < connects.size(); i++) {
0068       auto connectData = connects[i].data();
0069 
0070       path = pLSMapDir + connectData + ".bin";
0071       pLStoLayer[0][i] = lst::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path));
0072 
0073       path = pLSMapDir + "_pos" + connectData + ".bin";
0074       pLStoLayer[1][i] = lst::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path));
0075 
0076       path = pLSMapDir + "_neg" + connectData + ".bin";
0077       pLStoLayer[2][i] = lst::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path));
0078     }
0079   }
0080 }  // namespace
0081 
0082 std::unique_ptr<lst::LSTESData<alpaka_common::DevHost>> lst::loadAndFillESHost(std::string& ptCutLabel) {
0083   uint16_t nModules;
0084   uint16_t nLowerModules;
0085   unsigned int nPixels;
0086   MapPLStoLayer pLStoLayer;
0087   EndcapGeometry endcapGeometry;
0088   TiltedGeometry tiltedGeometry;
0089   PixelMap pixelMapping;
0090   ModuleConnectionMap moduleConnectionMap;
0091   ::loadMapsHost(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap, ptCutLabel);
0092 
0093   auto endcapGeometryDev =
0094       std::make_shared<EndcapGeometryDevHostCollection>(endcapGeometry.nEndCapMap, cms::alpakatools::host());
0095   std::memcpy(endcapGeometryDev->view().geoMapDetId(),
0096               endcapGeometry.geoMapDetId_buf.data(),
0097               endcapGeometry.nEndCapMap * sizeof(unsigned int));
0098   std::memcpy(endcapGeometryDev->view().geoMapPhi(),
0099               endcapGeometry.geoMapPhi_buf.data(),
0100               endcapGeometry.nEndCapMap * sizeof(float));
0101 
0102   auto path = get_absolute_path_after_check_file_exists(geometryDataDir() + "/data/OT800_IT615_pt" + ptCutLabel +
0103                                                         "/sensor_centroids.bin");
0104   auto modulesBuffers = lst::loadModulesFromFile(pLStoLayer,
0105                                                  path.c_str(),
0106                                                  nModules,
0107                                                  nLowerModules,
0108                                                  nPixels,
0109                                                  pixelMapping,
0110                                                  endcapGeometry,
0111                                                  tiltedGeometry,
0112                                                  moduleConnectionMap);
0113   auto pixelMappingPtr = std::make_shared<PixelMap>(std::move(pixelMapping));
0114   return std::make_unique<LSTESData<alpaka_common::DevHost>>(nModules,
0115                                                              nLowerModules,
0116                                                              nPixels,
0117                                                              endcapGeometry.nEndCapMap,
0118                                                              std::move(modulesBuffers),
0119                                                              std::move(endcapGeometryDev),
0120                                                              pixelMappingPtr);
0121 }