Project
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
AlpideResponse.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
12
13#include <boost/program_options.hpp>
15#include <TFile.h>
16#include <TSystem.h>
17#include <stdexcept>
18#include <cstdio>
19#include <cstddef>
20#include <fstream>
21#include <iostream>
22#include <string>
23
24void alpideResponse(const std::string& inpath, const std::string& outpath, const std::string& chip_name)
25{
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 }
35
37
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 }
48
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 }
57 file->WriteObjectAny(&resp1, "o2::itsmft::AlpideSimResponse", "response1");
58 file->Close();
59 delete file;
60}
61
62int main(int argc, const char* argv[])
63{
64 namespace bpo = boost::program_options;
65 bpo::variables_map vm;
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).");
68
69 try {
70 bpo::store(parse_command_line(argc, argv, options), vm);
71
72 if (vm.count("help")) {
73 std::cout << options << std::endl;
74 return 0;
75 }
76
77 bpo::notify(vm);
78 } catch (const bpo::error& e) {
79 std::cerr << e.what() << "\n\n";
80 std::cerr << "Error parsing command line arguments. Available options:\n";
81 std::cerr << options << std::endl;
82 return 2;
83 }
84
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 }
98
99 return 0;
100}
void alpideResponse(const std::string &inpath, const std::string &outpath, const std::string &chip_name)
Definition of the ITSMFT Alpide simulated response parametrization.
void setColMax(float v) noexcept
void initData(int tableNumber, std::string dataPath, const bool quiet=true)
void setRowMax(float v) noexcept
#define main