Skip to content

Commit

Permalink
Moved some things out into a common library
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed Jul 16, 2024
1 parent 1d9b396 commit 9c87a88
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 116 deletions.
1 change: 1 addition & 0 deletions RecoTracker/LSTCore/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<use name="root"/>
<use name="HeterogeneousCore/AlpakaInterface"/>
<flags CXXFLAGS="-DCACHE_ALLOC -DT4FromT3 -DUSE_RZCHI2 -DUSE_T5_DNN -DPT_CUT=0.8 -DDUP_pLS -DDUP_T5 -DDUP_pT5 -DDUP_pT3 -DCrossclean_T5 -DCrossclean_pT3"/>
<use name="1" for="alpaka"/>
<flags ALPAKA_BACKENDS="1"/>
<export>
<lib name="1"/>
Expand Down
50 changes: 50 additions & 0 deletions RecoTracker/LSTCore/interface/Constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef RecoTracker_LSTCore_interface_Constants_h
#define RecoTracker_LSTCore_interface_Constants_h


namespace SDL {

// If a compile time flag does not define PT_CUT, default to 0.8 (GeV)
#ifndef PT_CUT
constexpr float PT_CUT = 0.8f;
#endif

constexpr unsigned int MAX_BLOCKS = 80;
constexpr unsigned int MAX_CONNECTED_MODULES = 40;

constexpr unsigned int N_MAX_PIXEL_SEGMENTS_PER_MODULE = 50000;

constexpr unsigned int N_MAX_PIXEL_MD_PER_MODULES = 2 * N_MAX_PIXEL_SEGMENTS_PER_MODULE;

constexpr unsigned int N_MAX_PIXEL_TRIPLETS = 5000;
constexpr unsigned int N_MAX_PIXEL_QUINTUPLETS = 15000;

constexpr unsigned int N_MAX_PIXEL_TRACK_CANDIDATES = 30000;
constexpr unsigned int N_MAX_NONPIXEL_TRACK_CANDIDATES = 1000;

constexpr unsigned int size_superbins = 45000;

//defining the constant host device variables right up here
// Currently pixel tracks treated as LSs with 2 double layers (IT layers 1+2 and 3+4) and 4 hits. To be potentially handled better in the future.
struct Params_pLS {
static constexpr int kLayers = 2, kHits = 4;
};
struct Params_LS {
static constexpr int kLayers = 2, kHits = 4;
};
struct Params_T3 {
static constexpr int kLayers = 3, kHits = 6;
};
struct Params_pT3 {
static constexpr int kLayers = 5, kHits = 10;
};
struct Params_T5 {
static constexpr int kLayers = 5, kHits = 10;
};
struct Params_pT5 {
static constexpr int kLayers = 7, kHits = 14;
};

} //namespace SDL

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef EndcapGeometry_h
#define EndcapGeometry_h
#ifndef RecoTracker_LSTCore_interface_EndcapGeometry_h
#define RecoTracker_LSTCore_interface_EndcapGeometry_h

#include <map>
#include <iostream>
Expand All @@ -9,13 +9,8 @@
#include <vector>
#include <stdexcept>

#include "RecoTracker/LSTCore/interface/alpaka/Constants.h"

namespace SDL {
template <typename>
class EndcapGeometry;
template <>
class EndcapGeometry<SDL::Dev> {
class EndcapGeometry {
private:
std::map<unsigned int, float> dxdy_slope_; // dx/dy slope
std::map<unsigned int, float> centroid_phis_; // centroid phi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef ModuleConnectionMap_h
#define ModuleConnectionMap_h
#ifndef RecoTracker_LSTCore_interface_ModuleConnectionMap_h
#define RecoTracker_LSTCore_interface_ModuleConnectionMap_h

#include <iostream>
#include <fstream>
Expand All @@ -8,14 +8,8 @@
#include <sstream>
#include <algorithm>

#include "RecoTracker/LSTCore/interface/alpaka/Constants.h"

namespace SDL {
//FIXME: move to non-alpaka single arch build
template <typename>
class ModuleConnectionMap;
template <>
class ModuleConnectionMap<SDL::Dev> {
class ModuleConnectionMap {
private:
std::map<unsigned int, std::vector<unsigned int>> moduleConnections_;

Expand All @@ -32,7 +26,7 @@ namespace SDL {
int size() const;
};

using MapPLStoLayer = std::array<std::array<ModuleConnectionMap<SDL::Dev>, 4>, 3>;
using MapPLStoLayer = std::array<std::array<ModuleConnectionMap, 4>, 3>;
} // namespace SDL

#endif
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#ifndef PixelMap_h
#define PixelMap_h
#ifndef RecoTracker_LSTCore_interface_PixelMap_h
#define RecoTracker_LSTCore_interface_PixelMap_h

#include <vector>
#include <cstdint>

#include "RecoTracker/LSTCore/interface/alpaka/Constants.h"
#include "RecoTracker/LSTCore/interface/Constants.h"

namespace SDL {
// PixelMap is never allocated on the device.
// This is also not passed to any of the kernels, so we can combine the structs.
struct pixelMap {
uint16_t pixelModuleIndex;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TiltedGeometry_h
#define TiltedGeometry_h
#ifndef RecoTracker_LSTCore_interface_TiltedGeometry_h
#define RecoTracker_LSTCore_interface_TiltedGeometry_h

#include <vector>
#include <map>
Expand All @@ -9,13 +9,8 @@
#include <string>
#include <stdexcept>

#include "RecoTracker/LSTCore/interface/alpaka/Constants.h"

namespace SDL {
template <typename>
class TiltedGeometry;
template <>
class TiltedGeometry<SDL::Dev> {
class TiltedGeometry {
private:
std::map<unsigned int, float> drdzs_; // dr/dz slope
std::map<unsigned int, float> dxdys_; // dx/dy slope
Expand Down
42 changes: 1 addition & 41 deletions RecoTracker/LSTCore/interface/alpaka/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <alpaka/alpaka.hpp>

#include "RecoTracker/LSTCore/interface/Constants.h"
#include "HeterogeneousCore/AlpakaInterface/interface/config.h"

#ifdef CACHE_ALLOC
Expand Down Expand Up @@ -99,47 +100,6 @@ namespace SDL {
return WorkDiv(adjustedBlocks, adjustedThreads, elementsPerThreadArg);
}

// If a compile time flag does not define PT_CUT, default to 0.8 (GeV)
#ifndef PT_CUT
constexpr float PT_CUT = 0.8f;
#endif

constexpr unsigned int MAX_BLOCKS = 80;
constexpr unsigned int MAX_CONNECTED_MODULES = 40;

constexpr unsigned int N_MAX_PIXEL_SEGMENTS_PER_MODULE = 50000;

constexpr unsigned int N_MAX_PIXEL_MD_PER_MODULES = 2 * N_MAX_PIXEL_SEGMENTS_PER_MODULE;

constexpr unsigned int N_MAX_PIXEL_TRIPLETS = 5000;
constexpr unsigned int N_MAX_PIXEL_QUINTUPLETS = 15000;

constexpr unsigned int N_MAX_PIXEL_TRACK_CANDIDATES = 30000;
constexpr unsigned int N_MAX_NONPIXEL_TRACK_CANDIDATES = 1000;

constexpr unsigned int size_superbins = 45000;

//defining the constant host device variables right up here
// Currently pixel tracks treated as LSs with 2 double layers (IT layers 1+2 and 3+4) and 4 hits. To be potentially handled better in the future.
struct Params_pLS {
static constexpr int kLayers = 2, kHits = 4;
};
struct Params_LS {
static constexpr int kLayers = 2, kHits = 4;
};
struct Params_T3 {
static constexpr int kLayers = 3, kHits = 6;
};
struct Params_pT3 {
static constexpr int kLayers = 5, kHits = 10;
};
struct Params_T5 {
static constexpr int kLayers = 5, kHits = 10;
};
struct Params_pT5 {
static constexpr int kLayers = 7, kHits = 14;
};

// 15 MeV constant from the approximate Bethe-Bloch formula
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float kMulsInGeV = 0.015;
ALPAKA_STATIC_ACC_MEM_GLOBAL constexpr float miniMulsPtScaleBarrel[6] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "EndcapGeometry.h"
#include "RecoTracker/LSTCore/interface/EndcapGeometry.h"

SDL::EndcapGeometry<SDL::Dev>::EndcapGeometry(std::string filename) { load(filename); }
SDL::EndcapGeometry::EndcapGeometry(std::string filename) { load(filename); }

void SDL::EndcapGeometry<SDL::Dev>::load(std::string filename) {
void SDL::EndcapGeometry::load(std::string filename) {
dxdy_slope_.clear();
centroid_phis_.clear();

Expand Down Expand Up @@ -34,7 +34,7 @@ void SDL::EndcapGeometry<SDL::Dev>::load(std::string filename) {
fillGeoMapArraysExplicit();
}

void SDL::EndcapGeometry<SDL::Dev>::fillGeoMapArraysExplicit() {
void SDL::EndcapGeometry::fillGeoMapArraysExplicit() {
nEndCapMap = centroid_phis_.size();

geoMapDetId_buf.reserve(nEndCapMap);
Expand All @@ -48,7 +48,7 @@ void SDL::EndcapGeometry<SDL::Dev>::fillGeoMapArraysExplicit() {
}
}

float SDL::EndcapGeometry<SDL::Dev>::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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "ModuleConnectionMap.h"
#include "RecoTracker/LSTCore/interface/ModuleConnectionMap.h"

SDL::ModuleConnectionMap<SDL::Dev>::ModuleConnectionMap() {}
SDL::ModuleConnectionMap::ModuleConnectionMap() {}

SDL::ModuleConnectionMap<SDL::Dev>::ModuleConnectionMap(std::string filename) { load(filename); }
SDL::ModuleConnectionMap::ModuleConnectionMap(std::string filename) { load(filename); }

SDL::ModuleConnectionMap<SDL::Dev>::~ModuleConnectionMap() {}
SDL::ModuleConnectionMap::~ModuleConnectionMap() {}

void SDL::ModuleConnectionMap<SDL::Dev>::load(std::string filename) {
void SDL::ModuleConnectionMap::load(std::string filename) {
moduleConnections_.clear();

std::ifstream ifile(filename, std::ios::binary);
Expand Down Expand Up @@ -49,7 +49,7 @@ void SDL::ModuleConnectionMap<SDL::Dev>::load(std::string filename) {
}
}

void SDL::ModuleConnectionMap<SDL::Dev>::add(std::string filename) {
void SDL::ModuleConnectionMap::add(std::string filename) {
std::ifstream ifile;
ifile.open(filename.c_str());
std::string line;
Expand Down Expand Up @@ -81,7 +81,7 @@ void SDL::ModuleConnectionMap<SDL::Dev>::add(std::string filename) {
}
}

void SDL::ModuleConnectionMap<SDL::Dev>::print() {
void SDL::ModuleConnectionMap::print() {
std::cout << "Printing ModuleConnectionMap" << std::endl;
for (auto& pair : moduleConnections_) {
unsigned int detid = pair.first;
Expand All @@ -93,9 +93,9 @@ void SDL::ModuleConnectionMap<SDL::Dev>::print() {
}
}

const std::vector<unsigned int>& SDL::ModuleConnectionMap<SDL::Dev>::getConnectedModuleDetIds(unsigned int detid) const {
const std::vector<unsigned int>& SDL::ModuleConnectionMap::getConnectedModuleDetIds(unsigned int detid) const {
static const std::vector<unsigned int> dummy;
auto const mList = moduleConnections_.find(detid);
return mList != moduleConnections_.end() ? mList->second : dummy;
}
int SDL::ModuleConnectionMap<SDL::Dev>::size() const { return moduleConnections_.size(); }
int SDL::ModuleConnectionMap::size() const { return moduleConnections_.size(); }
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "TiltedGeometry.h"
#include "RecoTracker/LSTCore/interface/TiltedGeometry.h"

SDL::TiltedGeometry<SDL::Dev>::TiltedGeometry(std::string filename) { load(filename); }
SDL::TiltedGeometry::TiltedGeometry(std::string filename) { load(filename); }

void SDL::TiltedGeometry<SDL::Dev>::load(std::string filename) {
void SDL::TiltedGeometry::load(std::string filename) {
drdzs_.clear();
dxdys_.clear();

Expand Down Expand Up @@ -32,15 +32,15 @@ void SDL::TiltedGeometry<SDL::Dev>::load(std::string filename) {
}
}

float SDL::TiltedGeometry<SDL::Dev>::getDrDz(unsigned int detid) const {
float SDL::TiltedGeometry::getDrDz(unsigned int detid) const {
if (drdzs_.find(detid) != drdzs_.end()) {
return drdzs_.at(detid);
} else {
return 0;
}
}

float SDL::TiltedGeometry<SDL::Dev>::getDxDy(unsigned int detid) const {
float SDL::TiltedGeometry::getDxDy(unsigned int detid) const {
if (dxdys_.find(detid) != dxdys_.end()) {
return dxdys_.at(detid);
} else {
Expand Down
26 changes: 13 additions & 13 deletions RecoTracker/LSTCore/src/alpaka/LSTESData.dev.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "RecoTracker/LSTCore/interface/alpaka/LSTESData.h"
#include "RecoTracker/LSTCore/interface/EndcapGeometry.h"
#include "RecoTracker/LSTCore/interface/ModuleConnectionMap.h"
#include "RecoTracker/LSTCore/interface/TiltedGeometry.h"
#include "RecoTracker/LSTCore/interface/PixelMap.h"

#include "EndcapGeometry.h"
#include "ModuleConnectionMap.h"
#include "TiltedGeometry.h"
#include "PixelMap.h"
#include "ModuleMethods.h"

namespace {
Expand Down Expand Up @@ -40,9 +40,9 @@ namespace {
}

void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer,
std::shared_ptr<SDL::EndcapGeometry<SDL::Dev>> endcapGeometry,
std::shared_ptr<SDL::TiltedGeometry<SDL::Dev>> tiltedGeometry,
std::shared_ptr<SDL::ModuleConnectionMap<SDL::Dev>> moduleConnectionMap) {
std::shared_ptr<SDL::EndcapGeometry> endcapGeometry,
std::shared_ptr<SDL::TiltedGeometry> tiltedGeometry,
std::shared_ptr<SDL::ModuleConnectionMap> 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");
Expand All @@ -66,13 +66,13 @@ namespace {
auto connectData = connects[i].data();

path = pLSMapDir + connectData + ".bin";
pLStoLayer[0][i] = SDL::ModuleConnectionMap<SDL::Dev>(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<SDL::Dev>(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<SDL::Dev>(get_absolute_path_after_check_file_exists(path));
pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path));
}
}
} // namespace
Expand All @@ -83,10 +83,10 @@ std::unique_ptr<SDL::LSTESData<SDL::DevHost>> SDL::loadAndFillESHost() {
unsigned int nPixels;
std::shared_ptr<SDL::modulesBuffer<SDL::DevHost>> modulesBuffers = nullptr;
auto pLStoLayer = std::make_shared<SDL::MapPLStoLayer>();
auto endcapGeometry = std::make_shared<SDL::EndcapGeometry<SDL::Dev>>();
auto tiltedGeometry = std::make_shared<SDL::TiltedGeometry<SDL::Dev>>();
auto endcapGeometry = std::make_shared<SDL::EndcapGeometry>();
auto tiltedGeometry = std::make_shared<SDL::TiltedGeometry>();
auto pixelMapping = std::make_shared<SDL::pixelMap>();
auto moduleConnectionMap = std::make_shared<SDL::ModuleConnectionMap<SDL::Dev>>();
auto moduleConnectionMap = std::make_shared<SDL::ModuleConnectionMap>();
::loadMapsHost(*pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap);

auto endcapGeometryBuffers =
Expand Down
2 changes: 1 addition & 1 deletion RecoTracker/LSTCore/src/alpaka/MiniDoublet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "RecoTracker/LSTCore/interface/alpaka/Constants.h"
#include "RecoTracker/LSTCore/interface/alpaka/Module.h"
#include "RecoTracker/LSTCore/interface/EndcapGeometry.h"

#include "EndcapGeometry.h"
#include "Hit.h"

namespace SDL {
Expand Down
Loading

0 comments on commit 9c87a88

Please sign in to comment.