Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Move Maps to CSV Based Method #374

Merged
merged 7 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SDL/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ namespace SDL {
const unsigned int size_superbins = 45000;

// Temporary fix for endcap buffer allocation.
const unsigned int endcap_size = 9105;
const unsigned int endcap_size = 9104;
VourMa marked this conversation as resolved.
Show resolved Hide resolved

// Temporary fix for module buffer allocation.
const unsigned int modules_size = 26401;
const unsigned int pix_tot = 1796504;
const unsigned int pix_tot = 1794686;
VourMa marked this conversation as resolved.
Show resolved Hide resolved

//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};
Expand Down
61 changes: 13 additions & 48 deletions SDL/EndcapGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,23 @@ SDL::EndcapGeometry::EndcapGeometry(std::string filename, unsigned int sizef)
SDL::EndcapGeometry::~EndcapGeometry() {}

void SDL::EndcapGeometry::load(std::string filename) {
avgr2s_.clear();
yls_.clear();
sls_.clear();
yus_.clear();
sus_.clear();
centroid_rs_.clear();
dxdy_slope_.clear();
centroid_phis_.clear();
centroid_zs_.clear();

std::ifstream ifile;
ifile.open(filename.c_str());
std::string line;
std::ifstream ifile(filename);

std::string line;
while (std::getline(ifile, line)) {
std::istringstream ss(line);
unsigned int detid;
float avgr2;
float yl;
float sl;
float yh;
float sh;
float cr;
float cp;
float cz;

std::stringstream ss(line);

ss >> detid >> avgr2 >> yl >> sl >> yh >> sh >> cr >> cp >> cz;

// std::cout << " detid: " << detid << " avgr2: " << avgr2 << " yl: " << yl << " sl: " << sl << " yh: " << yh << " sh: " << sh << std::endl;

avgr2s_[detid] = avgr2;
yls_[detid] = yl;
sls_[detid] = sl;
yus_[detid] = yh;
sus_[detid] = sh;
centroid_rs_[detid] = cp;
centroid_phis_[detid] = cr;
centroid_zs_[detid] = cz;
float dxdy_slope, centroid_phi;

if (ss >> detid >> dxdy_slope >> centroid_phi) {
dxdy_slope_[detid] = dxdy_slope;
centroid_phis_[detid] = centroid_phi;
} else {
throw std::runtime_error("Failed to parse line: " + line);
}
}

fillGeoMapArraysExplicit();
Expand Down Expand Up @@ -103,18 +82,4 @@ void SDL::EndcapGeometry::fillGeoMapArraysExplicit() {
alpaka::wait(queue);
}

float SDL::EndcapGeometry::getAverageR2(unsigned int detid) { return avgr2s_[detid]; }

float SDL::EndcapGeometry::getYInterceptLower(unsigned int detid) { return yls_[detid]; }

float SDL::EndcapGeometry::getSlopeLower(unsigned int detid) { return sls_[detid]; }

float SDL::EndcapGeometry::getYInterceptUpper(unsigned int detid) { return yus_[detid]; }

float SDL::EndcapGeometry::getSlopeUpper(unsigned int detid) { return sus_[detid]; }

float SDL::EndcapGeometry::getCentroidR(unsigned int detid) { return centroid_rs_[detid]; }

float SDL::EndcapGeometry::getCentroidPhi(unsigned int detid) { return centroid_phis_[detid]; }

float SDL::EndcapGeometry::getCentroidZ(unsigned int detid) { return centroid_zs_[detid]; }
float SDL::EndcapGeometry::getdxdy_slope(unsigned int detid) { return dxdy_slope_[detid]; }
19 changes: 3 additions & 16 deletions SDL/EndcapGeometry.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
#ifndef EndcapGeometry_h
#define EndcapGeometry_h

#include <vector>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <stdexcept>

#include "Constants.h"

namespace SDL {
class EndcapGeometry {
private:
std::map<unsigned int, float> avgr2s_;
std::map<unsigned int, float> yls_; // lower hits
std::map<unsigned int, float> sls_; // lower slope
std::map<unsigned int, float> yus_; // upper hits
std::map<unsigned int, float> sus_; // upper slope
std::map<unsigned int, float> centroid_rs_; // centroid r
std::map<unsigned int, float> dxdy_slope_; // dx/dy slope
std::map<unsigned int, float> centroid_phis_; // centroid phi
std::map<unsigned int, float> centroid_zs_; // centroid z

public:
Buf<SDL::Dev, unsigned int> geoMapDetId_buf;
Expand All @@ -37,14 +31,7 @@ namespace SDL {

void fillGeoMapArraysExplicit();
void CreateGeoMapArraysExplicit();
float getAverageR2(unsigned int detid);
float getYInterceptLower(unsigned int detid);
float getSlopeLower(unsigned int detid);
float getYInterceptUpper(unsigned int detid);
float getSlopeUpper(unsigned int detid);
float getCentroidR(unsigned int detid);
float getCentroidPhi(unsigned int detid);
float getCentroidZ(unsigned int detid);
float getdxdy_slope(unsigned int detid);
};
void freeEndcap();
extern EndcapGeometry* endcapGeometry;
Expand Down
2 changes: 1 addition & 1 deletion SDL/Event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ SDL::modulesBuffer<alpaka::DevCpu>* SDL::Event::getFullModules() {
queue, modulesInCPUFull->moduleMap_buf, modulesBuffersES->moduleMap_buf, MAX_CONNECTED_MODULES * nModules);
alpaka::memcpy(queue, modulesInCPUFull->nConnectedModules_buf, modulesBuffersES->nConnectedModules_buf, nModules);
alpaka::memcpy(queue, modulesInCPUFull->drdzs_buf, modulesBuffersES->drdzs_buf, nModules);
alpaka::memcpy(queue, modulesInCPUFull->slopes_buf, modulesBuffersES->slopes_buf, nModules);
alpaka::memcpy(queue, modulesInCPUFull->dxdys_buf, modulesBuffersES->dxdys_buf, nModules);
alpaka::memcpy(queue, modulesInCPUFull->nLowerModules_buf, modulesBuffersES->nLowerModules_buf, 1);
alpaka::memcpy(queue, modulesInCPUFull->nModules_buf, modulesBuffersES->nModules_buf, 1);
alpaka::memcpy(queue, modulesInCPUFull->layers_buf, modulesBuffersES->layers_buf, nModules);
Expand Down
3 changes: 2 additions & 1 deletion SDL/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ namespace SDL {
extern SDL::modulesBuffer<Dev> const* modulesBuffersES; // not owned const buffers
extern uint16_t nModules;
extern uint16_t nLowerModules;
void initModules(const char* moduleMetaDataFilePath = "data/centroid.txt"); //read from file and init
void initModules(
const char* moduleMetaDataFilePath = "data/OT800_IT615_pt0.8/sensor_centroids.txt"); //read from file and init
void freeModules();
void initModulesHost(); //read from file and init
extern std::shared_ptr<SDL::pixelMap> pixelMapping;
Expand Down
5 changes: 1 addition & 4 deletions SDL/Hit.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ namespace SDL {

if (modulesInGPU.subdets[lastModuleIndex] == Endcap && modulesInGPU.moduleType[lastModuleIndex] == TwoS) {
found_index = binary_search(geoMapDetId, iDetId, nEndCapMap);
float phi = 0;
// Unclear why these are not in map, but CPU map returns phi = 0 for all exceptions.
if (found_index != -1)
phi = geoMapPhi[found_index];
float phi = geoMapPhi[found_index];
float cos_phi = alpaka::math::cos(acc, phi);
hitsInGPU.highEdgeXs[ihit] = ihit_x + 2.5f * cos_phi;
hitsInGPU.lowEdgeXs[ihit] = ihit_x - 2.5f * cos_phi;
Expand Down
10 changes: 5 additions & 5 deletions SDL/LST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ namespace {
void loadMaps() {
// Module orientation information (DrDz or phi angles)
TString endcap_geom = get_absolute_path_after_check_file_exists(
TString::Format("%s/data/endcap_orientation_data_CMSSW_12_2_0_pre2.txt", trackLooperDir().Data()).Data());
TString::Format("%s/data/OT800_IT615_pt0.8/endcap_orientation.txt", trackLooperDir().Data()).Data());
TString tilted_geom = get_absolute_path_after_check_file_exists(
TString::Format("%s/data/tilted_orientation_data_CMSSW_12_2_0_pre2.txt", trackLooperDir().Data()).Data());
TString::Format("%s/data/OT800_IT615_pt0.8/tilted_barrel_orientation.txt", trackLooperDir().Data()).Data());
SDL::endcapGeometry->load(endcap_geom.Data()); // centroid values added to the map
SDL::tiltedGeometry.load(tilted_geom.Data());

// Module connection map (for line segment building)
TString mappath = get_absolute_path_after_check_file_exists(
TString::Format("%s/data/module_connection_tracing_CMSSW_12_2_0_pre2_merged.txt", trackLooperDir().Data())
TString::Format("%s/data/OT800_IT615_pt0.8/module_connection_tracing_merged.txt", trackLooperDir().Data())
.Data());
SDL::moduleConnectionMap.load(mappath.Data());

TString pLSMapDir = trackLooperDir() + "/data/pixelmaps_CMSSW_12_2_0_pre2_0p8minPt/pLS_map";
TString pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map";
std::string connects[] = {"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"};
TString path;

Expand All @@ -54,7 +54,7 @@ void SDL::LST::loadAndFillES(alpaka::QueueCpuBlocking& queue, struct modulesBuff
::loadMaps();

TString path = get_absolute_path_after_check_file_exists(
TString::Format("%s/data/centroid_CMSSW_12_2_0_pre2.txt", trackLooperDir().Data()).Data());
TString::Format("%s/data/OT800_IT615_pt0.8/sensor_centroids.txt", trackLooperDir().Data()).Data());
SDL::loadModulesFromFile(modules, SDL::nModules, SDL::nLowerModules, *SDL::pixelMapping, queue, path.Data());
}

Expand Down
2 changes: 1 addition & 1 deletion SDL/MiniDoublet.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ namespace SDL {
float drprime_x; // x-component of drprime
float drprime_y; // y-component of drprime
const float& slope =
modulesInGPU.slopes[lowerModuleIndex]; // The slope of the possible strip hits for a given module in x-y plane
modulesInGPU.dxdys[lowerModuleIndex]; // The slope of the possible strip hits for a given module in x-y plane
float absArctanSlope;
float angleM; // the angle M is the angle of rotation of the module in x-y plane if the possible strip hits are along the x-axis, then angleM = 0, and if the possible strip hits are along y-axis angleM = 90 degrees
float absdzprime; // The distance between the two points after shifting
Expand Down
10 changes: 5 additions & 5 deletions SDL/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace SDL {
const uint16_t* mapIdx;
const uint16_t* nConnectedModules;
const float* drdzs;
const float* slopes;
const float* dxdys;
const uint16_t* nModules;
const uint16_t* nLowerModules;
const uint16_t* partnerModuleIndices;
Expand Down Expand Up @@ -231,7 +231,7 @@ namespace SDL {
mapIdx = alpaka::getPtrNative(modulesbuf.mapIdx_buf);
nConnectedModules = alpaka::getPtrNative(modulesbuf.nConnectedModules_buf);
drdzs = alpaka::getPtrNative(modulesbuf.drdzs_buf);
slopes = alpaka::getPtrNative(modulesbuf.slopes_buf);
dxdys = alpaka::getPtrNative(modulesbuf.dxdys_buf);
nModules = alpaka::getPtrNative(modulesbuf.nModules_buf);
nLowerModules = alpaka::getPtrNative(modulesbuf.nLowerModules_buf);
partnerModuleIndices = alpaka::getPtrNative(modulesbuf.partnerModuleIndices_buf);
Expand Down Expand Up @@ -262,7 +262,7 @@ namespace SDL {
Buf<TDev, uint16_t> mapIdx_buf;
Buf<TDev, uint16_t> nConnectedModules_buf;
Buf<TDev, float> drdzs_buf;
Buf<TDev, float> slopes_buf;
Buf<TDev, float> dxdys_buf;
Buf<TDev, uint16_t> nModules_buf;
Buf<TDev, uint16_t> nLowerModules_buf;
Buf<TDev, uint16_t> partnerModuleIndices_buf;
Expand Down Expand Up @@ -291,7 +291,7 @@ namespace SDL {
mapIdx_buf(allocBufWrapper<uint16_t>(devAccIn, nMod)),
nConnectedModules_buf(allocBufWrapper<uint16_t>(devAccIn, nMod)),
drdzs_buf(allocBufWrapper<float>(devAccIn, nMod)),
slopes_buf(allocBufWrapper<float>(devAccIn, nMod)),
dxdys_buf(allocBufWrapper<float>(devAccIn, nMod)),
nModules_buf(allocBufWrapper<uint16_t>(devAccIn, 1)),
nLowerModules_buf(allocBufWrapper<uint16_t>(devAccIn, 1)),
partnerModuleIndices_buf(allocBufWrapper<uint16_t>(devAccIn, nMod)),
Expand Down Expand Up @@ -320,7 +320,7 @@ namespace SDL {
alpaka::memcpy(queue, mapIdx_buf, src.mapIdx_buf);
alpaka::memcpy(queue, nConnectedModules_buf, src.nConnectedModules_buf);
alpaka::memcpy(queue, drdzs_buf, src.drdzs_buf);
alpaka::memcpy(queue, slopes_buf, src.slopes_buf);
alpaka::memcpy(queue, dxdys_buf, src.dxdys_buf);
alpaka::memcpy(queue, nModules_buf, src.nModules_buf);
alpaka::memcpy(queue, nLowerModules_buf, src.nLowerModules_buf);
alpaka::memcpy(queue, partnerModuleIndices_buf, src.partnerModuleIndices_buf);
Expand Down
14 changes: 7 additions & 7 deletions SDL/ModuleMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace SDL {
auto isAnchor_buf = allocBufWrapper<bool>(devHost, nModules);
auto moduleType_buf = allocBufWrapper<ModuleType>(devHost, nModules);
auto moduleLayerType_buf = allocBufWrapper<ModuleLayerType>(devHost, nModules);
auto slopes_buf = allocBufWrapper<float>(devHost, nModules);
auto dxdys_buf = allocBufWrapper<float>(devHost, nModules);
auto drdzs_buf = allocBufWrapper<float>(devHost, nModules);
auto partnerModuleIndices_buf = allocBufWrapper<uint16_t>(devHost, nModules);
auto sdlLayers_buf = allocBufWrapper<int>(devHost, nModules);
Expand All @@ -294,7 +294,7 @@ namespace SDL {
bool* host_isAnchor = alpaka::getPtrNative(isAnchor_buf);
ModuleType* host_moduleType = alpaka::getPtrNative(moduleType_buf);
ModuleLayerType* host_moduleLayerType = alpaka::getPtrNative(moduleLayerType_buf);
float* host_slopes = alpaka::getPtrNative(slopes_buf);
float* host_dxdys = alpaka::getPtrNative(dxdys_buf);
float* host_drdzs = alpaka::getPtrNative(drdzs_buf);
uint16_t* host_partnerModuleIndices = alpaka::getPtrNative(partnerModuleIndices_buf);
int* host_sdlLayers = alpaka::getPtrNative(sdlLayers_buf);
Expand Down Expand Up @@ -359,7 +359,7 @@ namespace SDL {
if (detId == 1) {
host_moduleType[index] = PixelModule;
host_moduleLayerType[index] = SDL::InnerPixelLayer;
host_slopes[index] = 0;
host_dxdys[index] = 0;
host_drdzs[index] = 0;
host_isAnchor[index] = false;
} else {
Expand All @@ -374,7 +374,7 @@ namespace SDL {
host_isAnchor[index] = false;
}

host_slopes[index] = (subdet == Endcap) ? endcapGeometry->getSlopeLower(detId) : tiltedGeometry.getSlope(detId);
host_dxdys[index] = (subdet == Endcap) ? endcapGeometry->getdxdy_slope(detId) : tiltedGeometry.getDxDy(detId);
host_drdzs[index] = (subdet == Barrel) ? tiltedGeometry.getDrDz(detId) : 0;
}

Expand All @@ -393,8 +393,8 @@ namespace SDL {
if (host_drdzs[index] == 0) {
host_drdzs[index] = host_drdzs[host_partnerModuleIndices[index]];
}
if (host_slopes[index] == 0) {
host_slopes[index] = host_slopes[host_partnerModuleIndices[index]];
if (host_dxdys[index] == 0) {
host_dxdys[index] = host_dxdys[host_partnerModuleIndices[index]];
}
}
}
Expand All @@ -420,7 +420,7 @@ namespace SDL {
alpaka::memcpy(queue, modulesBuf->isInverted_buf, isInverted_buf);
alpaka::memcpy(queue, modulesBuf->isLower_buf, isLower_buf);
alpaka::memcpy(queue, modulesBuf->isAnchor_buf, isAnchor_buf);
alpaka::memcpy(queue, modulesBuf->slopes_buf, slopes_buf);
alpaka::memcpy(queue, modulesBuf->dxdys_buf, dxdys_buf);
alpaka::memcpy(queue, modulesBuf->drdzs_buf, drdzs_buf);
alpaka::memcpy(queue, modulesBuf->partnerModuleIndices_buf, partnerModuleIndices_buf);
alpaka::memcpy(queue, modulesBuf->sdlLayers_buf, sdlLayers_buf);
Expand Down
4 changes: 2 additions & 2 deletions SDL/PixelTriplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ namespace SDL {
short moduleSubdet = modulesInGPU.subdets[lowerModuleIndices[i]];
short moduleSide = modulesInGPU.sides[lowerModuleIndices[i]];
float drdz = modulesInGPU.drdzs[lowerModuleIndices[i]];
slopes[i] = modulesInGPU.slopes[lowerModuleIndices[i]];
slopes[i] = modulesInGPU.dxdys[lowerModuleIndices[i]];
//category 1 - barrel PS flat
if (moduleSubdet == Barrel and moduleType == PS and moduleSide == Center) {
delta1[i] = inv1;
Expand Down Expand Up @@ -2308,7 +2308,7 @@ namespace SDL {
moduleSubdet = modulesInGPU.subdets[lowerModuleIndices[i]];
moduleSide = modulesInGPU.sides[lowerModuleIndices[i]];
const float& drdz = modulesInGPU.drdzs[lowerModuleIndices[i]];
slopes[i] = modulesInGPU.slopes[lowerModuleIndices[i]];
slopes[i] = modulesInGPU.dxdys[lowerModuleIndices[i]];
//category 1 - barrel PS flat
if (moduleSubdet == Barrel and moduleType == PS and moduleSide == Center) {
delta1[i] = inv1;
Expand Down
2 changes: 1 addition & 1 deletion SDL/Quintuplet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ namespace SDL {
moduleSubdet = modulesInGPU.subdets[lowerModuleIndices[i]];
moduleSide = modulesInGPU.sides[lowerModuleIndices[i]];
const float& drdz = modulesInGPU.drdzs[lowerModuleIndices[i]];
slopes[i] = modulesInGPU.slopes[lowerModuleIndices[i]];
slopes[i] = modulesInGPU.dxdys[lowerModuleIndices[i]];
//category 1 - barrel PS flat
if (moduleSubdet == Barrel and moduleType == PS and moduleSide == Center) {
delta1[i] = inv1;
Expand Down
25 changes: 13 additions & 12 deletions SDL/TiltedGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ SDL::TiltedGeometry::~TiltedGeometry() {}

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

std::ifstream ifile;
ifile.open(filename.c_str());
std::string line;
std::ifstream ifile(filename);

std::string line;
while (std::getline(ifile, line)) {
unsigned int detid;
float drdz;
float slope;
float dxdy;

std::stringstream ss(line);

ss >> detid >> drdz >> slope;

drdzs_[detid] = drdz;
slopes_[detid] = slope;
if (ss >> detid >> drdz >> dxdy) {
drdzs_[detid] = drdz;
dxdys_[detid] = dxdy;
} else {
throw std::runtime_error("Failed to parse line: " + line);
}
}
}

Expand All @@ -38,9 +39,9 @@ float SDL::TiltedGeometry::getDrDz(unsigned int detid) {
}
}

float SDL::TiltedGeometry::getSlope(unsigned int detid) {
if (slopes_.find(detid) != slopes_.end()) {
return slopes_[detid];
float SDL::TiltedGeometry::getDxDy(unsigned int detid) {
if (dxdys_.find(detid) != dxdys_.end()) {
return dxdys_[detid];
} else {
return 0;
}
Expand Down
Loading