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 3 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 @@ -145,7 +145,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 @@ -14,19 +14,28 @@ void SDL::EndcapGeometry<SDL::Dev>::load(std::string filename) {
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 binary data.");
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions SDL/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ namespace SDL {
modulesBuffer<alpaka::DevCpu>* getModules(bool isFull = false);

//read from file and init
static void initModules(const MapPLStoLayer& pLStoLayer,
const char* moduleMetaDataFilePath = "data/OT800_IT615_pt0.8/sensor_centroids.txt");
static void initModules(const MapPLStoLayer& pLStoLayer, const char* moduleMetaDataFilePath);
};

} // namespace SDL
Expand Down
14 changes: 7 additions & 7 deletions SDL/LST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ namespace {
void loadMaps(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");
SDL::Globals<SDL::Dev>::endcapGeometry->load(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 @@ -40,13 +40,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 @@ -58,7 +58,7 @@ void SDL::LST<SDL::Acc>::loadAndFillES(alpaka::QueueCpuBlocking& queue, struct m
::loadMaps(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>(SDL::devAcc);
}
Expand Down
43 changes: 28 additions & 15 deletions SDL/ModuleConnectionMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,39 @@ 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;
std::ifstream ifile(filename, std::ios::binary);
if (!ifile.is_open()) {
throw std::runtime_error("Unable to open file: " + filename);
}

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

std::stringstream ss(line);

ss >> detid >> number_of_connections;
// Read data until end of file or a read fails
while (ifile.read(reinterpret_cast<char*>(&detid), sizeof(detid)) &&
ifile.read(reinterpret_cast<char*>(&number_of_connections), sizeof(number_of_connections))) {
std::vector<unsigned int> connected_detids;

for (int ii = 0; ii < number_of_connections; ++ii) {
ss >> connected_detid;
connected_detids.push_back(connected_detid);
for (unsigned int ii = 0; ii < number_of_connections; ++ii) {
unsigned int connected_detid;
if (ifile.read(reinterpret_cast<char*>(&connected_detid), sizeof(connected_detid))) {
connected_detids.push_back(connected_detid);
} else {
// Proper handling of read failure
if (ifile.eof()) {
break; // Break the inner loop on EOF
} else {
throw std::runtime_error("Failed to read connection data for detid " + std::to_string(detid));
}
}
}

moduleConnections_[detid] = connected_detids;
if (ifile.eof())
break; // Check if EOF is reached after reading all connections for a detid
}

if (ifile.fail() && !ifile.eof()) {
throw std::runtime_error("Unexpected error during file read.");
}
}

Expand Down
76 changes: 37 additions & 39 deletions SDL/ModuleMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,51 +176,36 @@ 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;
return;
}
std::string line;

uint16_t counter = 0;
unsigned int temp_detId;
float module_x, module_y, module_z;
int module_type;

while (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) { // Check if all reads were successful
std::cout << "Failed to read data for detId: " << temp_detId << std::endl;
continue;
}

while (std::getline(ifile, line)) {
std::stringstream ss(line);
std::string token;
int count_number = 0;
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;

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++;
}
count_number++;
if (count_number > 4)
break;
}
counter++;
}

mmd.detIdToIndex[1] = counter; //pixel module is the last module in the module list
Expand All @@ -234,6 +219,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);

auto detIds_buf = allocBufWrapper<unsigned int>(devHost, nModules);
auto layers_buf = allocBufWrapper<short>(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 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()
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 @@ -29,13 +29,13 @@ void loadMaps()
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