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

Move to Binary Data Files + Include 0.6 pT Maps #391

Merged
merged 7 commits into from
Apr 24, 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
2 changes: 1 addition & 1 deletion SDL/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace SDL {

// Temporary fix for module buffer allocation.
const unsigned int modules_size = 26401;
const unsigned int pix_tot = 1794686;
const unsigned int pix_tot = 1795336;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/SegmentLinking/LSTGeometry/blob/15f482747748e89632fbef65989355ddbb8d94d7/Constants.py#L17

I'm pretty sure this small change comes from my last PR on LSTGeometry where I consolidated the constants and changed B to be 3.8112 from 3.8 to keep it consistent with the Tracklooper definition.


//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
21 changes: 15 additions & 6 deletions SDL/EndcapGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@ void SDL::EndcapGeometry<SDL::Dev>::load(SDL::QueueAcc& queue, std::string filen
dxdy_slope_.clear();
centroid_phis_.clear();

std::ifstream ifile(filename);
std::ifstream ifile(filename, std::ios::binary);
if (!ifile.is_open()) {
throw std::runtime_error("Unable to open file: " + filename);
}

std::string line;
while (std::getline(ifile, line)) {
std::istringstream ss(line);
while (!ifile.eof()) {
unsigned int detid;
float dxdy_slope, centroid_phi;

if (ss >> detid >> dxdy_slope >> centroid_phi) {
// Read the detid, dxdy_slope, and centroid_phi from binary file
ifile.read(reinterpret_cast<char*>(&detid), sizeof(detid));
ifile.read(reinterpret_cast<char*>(&dxdy_slope), sizeof(dxdy_slope));
ifile.read(reinterpret_cast<char*>(&centroid_phi), sizeof(centroid_phi));

if (ifile) {
dxdy_slope_[detid] = dxdy_slope;
centroid_phis_[detid] = centroid_phi;
} else {
throw std::runtime_error("Failed to parse line: " + line);
// End of file or read failed
if (!ifile.eof()) {
throw std::runtime_error("Failed to read Endcap Geometry binary data.");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion SDL/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace SDL {
//read from file and init
static void initModules(QueueAcc& queue,
const MapPLStoLayer& pLStoLayer,
const char* moduleMetaDataFilePath = "data/OT800_IT615_pt0.8/sensor_centroids.txt");
const char* moduleMetaDataFilePath);
};

} // namespace SDL
Expand Down
15 changes: 8 additions & 7 deletions SDL/LST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ namespace {
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.txt");
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.txt");
trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin");
if (SDL::Globals<SDL::Dev>::endcapGeometry == nullptr) {
SDL::Globals<SDL::Dev>::endcapGeometry =
new SDL::EndcapGeometry<SDL::Dev>(devAccIn, queue, endcap_geom); // centroid values added to the map
}

SDL::Globals<SDL::Dev>::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.txt");
trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin");
SDL::Globals<SDL::Dev>::moduleConnectionMap.load(mappath);

auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map";
Expand All @@ -43,13 +44,13 @@ namespace {
for (unsigned int i = 0; i < connects.size(); i++) {
auto connectData = connects[i].data();

path = pLSMapDir + connectData + ".txt";
path = pLSMapDir + connectData + ".bin";
pLStoLayer[0][i] = SDL::ModuleConnectionMap<SDL::Dev>(get_absolute_path_after_check_file_exists(path));

path = pLSMapDir + "_pos" + connectData + ".txt";
path = pLSMapDir + "_pos" + connectData + ".bin";
pLStoLayer[1][i] = SDL::ModuleConnectionMap<SDL::Dev>(get_absolute_path_after_check_file_exists(path));

path = pLSMapDir + "_neg" + connectData + ".txt";
path = pLSMapDir + "_neg" + connectData + ".bin";
pLStoLayer[2][i] = SDL::ModuleConnectionMap<SDL::Dev>(get_absolute_path_after_check_file_exists(path));
}
}
Expand All @@ -62,7 +63,7 @@ void SDL::LST<SDL::Acc>::loadAndFillES(SDL::QueueAcc& queue, struct modulesBuffe
::loadMaps(devAccIn, queue, pLStoLayer);

auto path =
get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.txt");
get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin");
if (SDL::Globals<SDL::Dev>::modulesBuffers == nullptr) {
SDL::Globals<SDL::Dev>::modulesBuffers = new SDL::modulesBuffer<SDL::Dev>(devAccIn);
}
Expand Down
53 changes: 35 additions & 18 deletions SDL/ModuleConnectionMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,43 @@ SDL::ModuleConnectionMap<SDL::Dev>::~ModuleConnectionMap() {}
void SDL::ModuleConnectionMap<SDL::Dev>::load(std::string filename) {
moduleConnections_.clear();

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

while (std::getline(ifile, line)) {
unsigned int detid;
int number_of_connections;
std::vector<unsigned int> connected_detids;
unsigned int connected_detid;

std::stringstream ss(line);

ss >> detid >> number_of_connections;
std::ifstream ifile(filename, std::ios::binary);
if (!ifile.is_open()) {
throw std::runtime_error("Unable to open file: " + filename);
}

for (int ii = 0; ii < number_of_connections; ++ii) {
ss >> connected_detid;
connected_detids.push_back(connected_detid);
while (!ifile.eof()) {
unsigned int detid, number_of_connections;

// Read the detid and the number of connections from the binary file
ifile.read(reinterpret_cast<char*>(&detid), sizeof(detid));
ifile.read(reinterpret_cast<char*>(&number_of_connections), sizeof(number_of_connections));

if (ifile) {
std::vector<unsigned int> connected_detids;

// Read the connections for the given detid
for (unsigned int i = 0; i < number_of_connections; ++i) {
unsigned int connected_detid;
ifile.read(reinterpret_cast<char*>(&connected_detid), sizeof(connected_detid));
if (ifile) {
connected_detids.push_back(connected_detid);
} else {
if (!ifile.eof()) {
throw std::runtime_error("Failed to read connection data.");
}
break; // Exit loop on read failure that's not EOF
}
}

if (ifile) {
moduleConnections_[detid] = connected_detids;
}
} else {
if (!ifile.eof()) {
throw std::runtime_error("Failed to read module connection binary data.");
}
}

moduleConnections_[detid] = connected_detids;
}
}

Expand Down
76 changes: 37 additions & 39 deletions SDL/ModuleMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,50 +181,35 @@ namespace SDL {
eta = ((m_z > 0) - (m_z < 0)) * std::acosh(r / std::sqrt(m_x * m_x + m_y * m_y));
};

template <typename TQueue, typename TDev>
void loadModulesFromFile(struct modulesBuffer<TDev>* modulesBuf,
uint16_t& nModules,
uint16_t& nLowerModules,
struct pixelMap& pixelMapping,
TQueue& queue,
const char* moduleMetaDataFilePath,
const MapPLStoLayer& pLStoLayer) {
ModuleMetaData mmd;

/* Load the whole text file into the map first*/

std::ifstream ifile;
ifile.open(moduleMetaDataFilePath);
inline void loadCentroidsFromFile(const char* filePath, ModuleMetaData& mmd, uint16_t& nModules) {
std::ifstream ifile(filePath, std::ios::binary);
if (!ifile.is_open()) {
std::cout << "ERROR! module list file not present!" << std::endl;
throw std::runtime_error("Unable to open file: " + std::string(filePath));
}
std::string line;
uint16_t counter = 0;

while (std::getline(ifile, line)) {
std::stringstream ss(line);
std::string token;
int count_number = 0;

uint16_t counter = 0;
while (!ifile.eof()) {
unsigned int temp_detId;
while (std::getline(ss, token, ',')) {
if (count_number == 0) {
temp_detId = stoi(token);
mmd.detIdToIndex[temp_detId] = counter;
}
if (count_number == 1)
mmd.module_x[temp_detId] = std::stof(token);
if (count_number == 2)
mmd.module_y[temp_detId] = std::stof(token);
if (count_number == 3)
mmd.module_z[temp_detId] = std::stof(token);
if (count_number == 4) {
mmd.module_type[temp_detId] = std::stoi(token);
counter++;
float module_x, module_y, module_z;
int module_type;

ifile.read(reinterpret_cast<char*>(&temp_detId), sizeof(temp_detId));
ifile.read(reinterpret_cast<char*>(&module_x), sizeof(module_x));
ifile.read(reinterpret_cast<char*>(&module_y), sizeof(module_y));
ifile.read(reinterpret_cast<char*>(&module_z), sizeof(module_z));
ifile.read(reinterpret_cast<char*>(&module_type), sizeof(module_type));

if (ifile) {
mmd.detIdToIndex[temp_detId] = counter;
mmd.module_x[temp_detId] = module_x;
mmd.module_y[temp_detId] = module_y;
mmd.module_z[temp_detId] = module_z;
mmd.module_type[temp_detId] = module_type;
counter++;
} else {
if (!ifile.eof()) {
throw std::runtime_error("Failed to read data for detId: " + std::to_string(temp_detId));
}
count_number++;
if (count_number > 4)
break;
}
}

Expand All @@ -239,6 +224,19 @@ namespace SDL {
std::cerr << "Please change modules_size in Constants.h to make it equal to nModules.\n";
throw std::runtime_error("Mismatched sizes");
}
};

template <typename TQueue, typename TDev>
void loadModulesFromFile(struct modulesBuffer<TDev>* modulesBuf,
uint16_t& nModules,
uint16_t& nLowerModules,
struct pixelMap& pixelMapping,
TQueue& queue,
const char* moduleMetaDataFilePath,
const MapPLStoLayer& pLStoLayer) {
ModuleMetaData mmd;

loadCentroidsFromFile(moduleMetaDataFilePath, mmd, nModules);

DevHost const& devHost = cms::alpakatools::host();
auto detIds_buf = allocBufWrapper<unsigned int>(devHost, nModules);
Expand Down
23 changes: 15 additions & 8 deletions SDL/TiltedGeometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ void SDL::TiltedGeometry<SDL::Dev>::load(std::string filename) {
drdzs_.clear();
dxdys_.clear();

std::ifstream ifile(filename);
std::ifstream ifile(filename, std::ios::binary);
if (!ifile.is_open()) {
throw std::runtime_error("Unable to open file: " + filename);
}

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

std::stringstream ss(line);
// Read the detid, drdz, and dxdy from binary file
ifile.read(reinterpret_cast<char*>(&detid), sizeof(detid));
ifile.read(reinterpret_cast<char*>(&drdz), sizeof(drdz));
ifile.read(reinterpret_cast<char*>(&dxdy), sizeof(dxdy));

if (ss >> detid >> drdz >> dxdy) {
if (ifile) {
drdzs_[detid] = drdz;
dxdys_[detid] = dxdy;
} else {
throw std::runtime_error("Failed to parse line: " + line);
// End of file or read failed
if (!ifile.eof()) {
throw std::runtime_error("Failed to read Tilted Geometry binary data.");
}
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions code/core/trkCore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ void loadMaps(SDL::Dev& devAccIn, SDL::QueueAcc& queue)
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.txt", TrackLooperDir.Data()).Data());
TString tilted_geom = get_absolute_path_after_check_file_exists(TString::Format("%s/data/OT800_IT615_pt0.8/tilted_barrel_orientation.txt", TrackLooperDir.Data()).Data());
TString mappath = get_absolute_path_after_check_file_exists(TString::Format("%s/data/OT800_IT615_pt0.8/module_connection_tracing_merged.txt", TrackLooperDir.Data()).Data());
TString centroid = get_absolute_path_after_check_file_exists(TString::Format("%s/data/OT800_IT615_pt0.8/sensor_centroids.txt", gSystem->Getenv("TRACKLOOPERDIR")).Data()).Data();
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;
Expand All @@ -31,13 +31,13 @@ void loadMaps(SDL::Dev& devAccIn, SDL::QueueAcc& queue)
const std::array<string, 4> pLSMapPath{{ "layer1_subdet5", "layer2_subdet5", "layer1_subdet4", "layer2_subdet4" }};
static_assert(pLStoLayer[0].size() == pLSMapPath.size());
for (unsigned int i=0; i<pLSMapPath.size(); i++) {
TString path = TString::Format("%s/pLS_map_%s.txt", pLSMapDir.Data(), pLSMapPath[i].c_str()).Data();
TString path = TString::Format("%s/pLS_map_%s.bin", pLSMapDir.Data(), pLSMapPath[i].c_str()).Data();
pLStoLayer[0][i].load( get_absolute_path_after_check_file_exists( path.Data() ).Data() );

path = TString::Format("%s/pLS_map_pos_%s.txt", pLSMapDir.Data(), pLSMapPath[i].c_str()).Data();
path = TString::Format("%s/pLS_map_pos_%s.bin", pLSMapDir.Data(), pLSMapPath[i].c_str()).Data();
pLStoLayer[1][i].load( get_absolute_path_after_check_file_exists( path.Data() ).Data() );

path = TString::Format("%s/pLS_map_neg_%s.txt", pLSMapDir.Data(), pLSMapPath[i].c_str()).Data();
path = TString::Format("%s/pLS_map_neg_%s.bin", pLSMapDir.Data(), pLSMapPath[i].c_str()).Data();
pLStoLayer[2][i].load( get_absolute_path_after_check_file_exists( path.Data() ).Data() );
}

Expand Down
Binary file added data/OT800_IT615_pt0.6/endcap_orientation.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added data/OT800_IT615_pt0.6/sensor_centroids.bin
Binary file not shown.
Binary file not shown.
Binary file added data/OT800_IT615_pt0.8/endcap_orientation.bin
Binary file not shown.
Loading