diff --git a/Detectors/ITSMFT/common/data/AlpideResponseData/AlpideResponse.cxx b/Detectors/ITSMFT/common/data/AlpideResponseData/AlpideResponse.cxx index f4c71d85df24e..86ffb24b239ed 100644 --- a/Detectors/ITSMFT/common/data/AlpideResponseData/AlpideResponse.cxx +++ b/Detectors/ITSMFT/common/data/AlpideResponseData/AlpideResponse.cxx @@ -14,55 +14,87 @@ #include "ITSMFTSimulation/AlpideSimResponse.h" #include #include +#include #include #include #include #include #include -void alpideResponse(const std::string& inpath = "./", - const std::string& outpath = "./", - const std::string& response_file = "AlpideResponseData.root") +void alpideResponse(const std::string& inpath, const std::string& outpath, const std::string& chip_name) { + // Check input path validity + if (gSystem->AccessPathName(inpath.c_str())) { + throw std::invalid_argument("Input path does not exist or is inaccessible: " + inpath); + } + + // Check output path validity + if (gSystem->AccessPathName(outpath.c_str(), kWritePermission)) { + throw std::invalid_argument("Output path is not writable: " + outpath); + } o2::itsmft::AlpideSimResponse resp0, resp1; - resp0.initData(0, inpath.data()); - resp1.initData(1, inpath.data()); + if (chip_name == "Alpide") { + resp0.initData(0, inpath.c_str()); + resp1.initData(1, inpath.c_str()); + } else if (chip_name == "APTS") { + resp1.setColMax(1.5e-4); + resp1.setRowMax(1.5e-4); + resp1.initData(1, inpath.c_str()); + } else { + throw std::invalid_argument("Unknown chip name: " + chip_name); + } - auto file = TFile::Open((outpath + response_file).data(), "recreate"); - file->WriteObjectAny(&resp0, "o2::itsmft::AlpideSimResponse", "response0"); + std::string output_file = outpath + "/" + chip_name + "ResponseData.root"; + auto file = TFile::Open(output_file.c_str(), "recreate"); + + if (!file || file->IsZombie()) { + throw std::runtime_error("Failed to create output file: " + output_file); + } else if (chip_name == "Alpide") { + file->WriteObjectAny(&resp0, "o2::itsmft::AlpideSimResponse", "response0"); + } file->WriteObjectAny(&resp1, "o2::itsmft::AlpideSimResponse", "response1"); file->Close(); + delete file; } int main(int argc, const char* argv[]) { namespace bpo = boost::program_options; bpo::variables_map vm; - bpo::options_description options("Alpide reponse generator options"); - options.add_options()( - "inputdir,i", bpo::value()->default_value("./"), "Path where Vbb-0.0V and Vbb-3.0V are located.")( - "outputdir,o", bpo::value()->default_value("./"), "Path where to store the output.")( - "name,n", bpo::value()->default_value("AlpideResponseData.root"), "Output file name."); + bpo::options_description options("Alpide response generator options"); + options.add_options()("inputdir,i", bpo::value()->default_value("./"), "Path where Vbb-0.0V and Vbb-3.0V are located.")("outputdir,o", bpo::value()->default_value("./"), "Path where to store the output.")("chip,c", bpo::value()->default_value("Alpide"), "Chip name (Alpide or APTS)."); try { bpo::store(parse_command_line(argc, argv, options), vm); + if (vm.count("help")) { std::cout << options << std::endl; - return 1; + return 0; } + bpo::notify(vm); } catch (const bpo::error& e) { std::cerr << e.what() << "\n\n"; std::cerr << "Error parsing command line arguments. Available options:\n"; - std::cerr << options << std::endl; return 2; } - std::cout << "Generating " << vm["inputdir"].as() + vm["name"].as() << std::endl; - alpideResponse(vm["inputdir"].as(), vm["outputdir"].as(), vm["name"].as()); + try { + std::cout << "Generating response for chip: " << vm["chip"].as() << std::endl; + std::cout << "Input directory: " << vm["inputdir"].as() << std::endl; + std::cout << "Output directory: " << vm["outputdir"].as() << std::endl; + + alpideResponse(vm["inputdir"].as(), + vm["outputdir"].as(), + vm["chip"].as()); + std::cout << "Response file generated successfully." << std::endl; + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + return 1; + } return 0; -} \ No newline at end of file +} diff --git a/Detectors/ITSMFT/common/simulation/include/ITSMFTSimulation/AlpideSimResponse.h b/Detectors/ITSMFT/common/simulation/include/ITSMFTSimulation/AlpideSimResponse.h index 0462115d3bfc6..92656a16257a1 100644 --- a/Detectors/ITSMFT/common/simulation/include/ITSMFTSimulation/AlpideSimResponse.h +++ b/Detectors/ITSMFT/common/simulation/include/ITSMFTSimulation/AlpideSimResponse.h @@ -132,6 +132,8 @@ class AlpideSimResponse float getStepCol() const { return mStepInvCol ? 1. / mStepInvCol : 0.f; } float getStepRow() const { return mStepInvRow ? 1. / mStepInvRow : 0.f; } float getStepDepth() const { return mStepInvDpt ? 1. / mStepInvDpt : 0.f; } + void setColMax(float v) noexcept { mColMax = v; } + void setRowMax(float v) noexcept { mRowMax = v; } void setDataPath(const std::string pth) { mDataPath = pth; } void setGridColName(const std::string nm) { mGridColName = nm; } void setGridRowName(const std::string nm) { mGridRowName = nm; } @@ -142,7 +144,7 @@ class AlpideSimResponse const std::string& getColRowDataFmt() const { return mColRowDataFmt; } void print() const; - ClassDefNV(AlpideSimResponse, 1); + ClassDefNV(AlpideSimResponse, 2); }; //-----------------------------------------------------