Skip to content

Commit 46380fc

Browse files
authored
AlpideResponse adjust for APTS (#13929)
Signed-off-by: Chunzheng Wang <chunzheng.wang@cern.ch>
1 parent dffee58 commit 46380fc

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

Detectors/ITSMFT/common/data/AlpideResponseData/AlpideResponse.cxx

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,87 @@
1414
#include "ITSMFTSimulation/AlpideSimResponse.h"
1515
#include <TFile.h>
1616
#include <TSystem.h>
17+
#include <stdexcept>
1718
#include <cstdio>
1819
#include <cstddef>
1920
#include <fstream>
2021
#include <iostream>
2122
#include <string>
2223

23-
void alpideResponse(const std::string& inpath = "./",
24-
const std::string& outpath = "./",
25-
const std::string& response_file = "AlpideResponseData.root")
24+
void alpideResponse(const std::string& inpath, const std::string& outpath, const std::string& chip_name)
2625
{
26+
// Check input path validity
27+
if (gSystem->AccessPathName(inpath.c_str())) {
28+
throw std::invalid_argument("Input path does not exist or is inaccessible: " + inpath);
29+
}
30+
31+
// Check output path validity
32+
if (gSystem->AccessPathName(outpath.c_str(), kWritePermission)) {
33+
throw std::invalid_argument("Output path is not writable: " + outpath);
34+
}
2735

2836
o2::itsmft::AlpideSimResponse resp0, resp1;
2937

30-
resp0.initData(0, inpath.data());
31-
resp1.initData(1, inpath.data());
38+
if (chip_name == "Alpide") {
39+
resp0.initData(0, inpath.c_str());
40+
resp1.initData(1, inpath.c_str());
41+
} else if (chip_name == "APTS") {
42+
resp1.setColMax(1.5e-4);
43+
resp1.setRowMax(1.5e-4);
44+
resp1.initData(1, inpath.c_str());
45+
} else {
46+
throw std::invalid_argument("Unknown chip name: " + chip_name);
47+
}
3248

33-
auto file = TFile::Open((outpath + response_file).data(), "recreate");
34-
file->WriteObjectAny(&resp0, "o2::itsmft::AlpideSimResponse", "response0");
49+
std::string output_file = outpath + "/" + chip_name + "ResponseData.root";
50+
auto file = TFile::Open(output_file.c_str(), "recreate");
51+
52+
if (!file || file->IsZombie()) {
53+
throw std::runtime_error("Failed to create output file: " + output_file);
54+
} else if (chip_name == "Alpide") {
55+
file->WriteObjectAny(&resp0, "o2::itsmft::AlpideSimResponse", "response0");
56+
}
3557
file->WriteObjectAny(&resp1, "o2::itsmft::AlpideSimResponse", "response1");
3658
file->Close();
59+
delete file;
3760
}
3861

3962
int main(int argc, const char* argv[])
4063
{
4164
namespace bpo = boost::program_options;
4265
bpo::variables_map vm;
43-
bpo::options_description options("Alpide reponse generator options");
44-
options.add_options()(
45-
"inputdir,i", bpo::value<std::string>()->default_value("./"), "Path where Vbb-0.0V and Vbb-3.0V are located.")(
46-
"outputdir,o", bpo::value<std::string>()->default_value("./"), "Path where to store the output.")(
47-
"name,n", bpo::value<std::string>()->default_value("AlpideResponseData.root"), "Output file name.");
66+
bpo::options_description options("Alpide response generator options");
67+
options.add_options()("inputdir,i", bpo::value<std::string>()->default_value("./"), "Path where Vbb-0.0V and Vbb-3.0V are located.")("outputdir,o", bpo::value<std::string>()->default_value("./"), "Path where to store the output.")("chip,c", bpo::value<std::string>()->default_value("Alpide"), "Chip name (Alpide or APTS).");
4868

4969
try {
5070
bpo::store(parse_command_line(argc, argv, options), vm);
71+
5172
if (vm.count("help")) {
5273
std::cout << options << std::endl;
53-
return 1;
74+
return 0;
5475
}
76+
5577
bpo::notify(vm);
5678
} catch (const bpo::error& e) {
5779
std::cerr << e.what() << "\n\n";
5880
std::cerr << "Error parsing command line arguments. Available options:\n";
59-
6081
std::cerr << options << std::endl;
6182
return 2;
6283
}
6384

64-
std::cout << "Generating " << vm["inputdir"].as<std::string>() + vm["name"].as<std::string>() << std::endl;
65-
alpideResponse(vm["inputdir"].as<std::string>(), vm["outputdir"].as<std::string>(), vm["name"].as<std::string>());
85+
try {
86+
std::cout << "Generating response for chip: " << vm["chip"].as<std::string>() << std::endl;
87+
std::cout << "Input directory: " << vm["inputdir"].as<std::string>() << std::endl;
88+
std::cout << "Output directory: " << vm["outputdir"].as<std::string>() << std::endl;
89+
90+
alpideResponse(vm["inputdir"].as<std::string>(),
91+
vm["outputdir"].as<std::string>(),
92+
vm["chip"].as<std::string>());
93+
std::cout << "Response file generated successfully." << std::endl;
94+
} catch (const std::exception& e) {
95+
std::cerr << "Error: " << e.what() << std::endl;
96+
return 1;
97+
}
6698

6799
return 0;
68-
}
100+
}

Detectors/ITSMFT/common/simulation/include/ITSMFTSimulation/AlpideSimResponse.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class AlpideSimResponse
132132
float getStepCol() const { return mStepInvCol ? 1. / mStepInvCol : 0.f; }
133133
float getStepRow() const { return mStepInvRow ? 1. / mStepInvRow : 0.f; }
134134
float getStepDepth() const { return mStepInvDpt ? 1. / mStepInvDpt : 0.f; }
135+
void setColMax(float v) noexcept { mColMax = v; }
136+
void setRowMax(float v) noexcept { mRowMax = v; }
135137
void setDataPath(const std::string pth) { mDataPath = pth; }
136138
void setGridColName(const std::string nm) { mGridColName = nm; }
137139
void setGridRowName(const std::string nm) { mGridRowName = nm; }
@@ -142,7 +144,7 @@ class AlpideSimResponse
142144
const std::string& getColRowDataFmt() const { return mColRowDataFmt; }
143145
void print() const;
144146

145-
ClassDefNV(AlpideSimResponse, 1);
147+
ClassDefNV(AlpideSimResponse, 2);
146148
};
147149

148150
//-----------------------------------------------------

0 commit comments

Comments
 (0)