File indexing completed on 2025-12-15 09:25:35
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Utilities/Options.hpp"
0010
0011 #include <algorithm>
0012 #include <array>
0013 #include <bitset>
0014 #include <cmath>
0015 #include <exception>
0016 #include <iostream>
0017 #include <limits>
0018 #include <numbers>
0019 #include <optional>
0020 #include <sstream>
0021 #include <string>
0022 #include <vector>
0023
0024 #include <TApplication.h>
0025 #include <boost/program_options.hpp>
0026 #include <boost/timer/progress_display.hpp>
0027 #include <nlohmann/json.hpp>
0028
0029 #define BOOST_AVAILABLE 1
0030
0031 using progress_display = boost::timer::progress_display;
0032
0033 #define NLOHMANN_AVAILABLE 1
0034 #include "trackSummaryAnalysis.C"
0035
0036 using namespace boost::program_options;
0037
0038 using Interval = ActsExamples::Options::Interval;
0039 using VariableReals = ActsExamples::Options::VariableReals;
0040
0041 int main(int argc, char **argv) {
0042 std::cout << "*** ACTS Perigee parameters and Track summary plotting "
0043 << std::endl;
0044
0045 try {
0046 options_description description("*** Usage:");
0047
0048
0049 auto ao = description.add_options();
0050 ao("help,h", "Display this help message");
0051 ao("silent,s", bool_switch(), "Silent mode (without X-window/display).");
0052 ao("events,n", value<unsigned long>()->default_value(0),
0053 "(Optionally) limit number of events to be processed.");
0054 ao("peak-events,p", value<unsigned long>()->default_value(0),
0055 "(Optionally) limit number of events for the range peaking.");
0056 ao("input,i", value<std::vector<std::string>>()->required(),
0057 "Input ROOT file(s) containing the input TTree.");
0058 ao("tree,t", value<std::string>()->default_value("tracksummary"),
0059 "Input TTree/TChain name.");
0060 ao("output,o", value<std::string>()->default_value(""),
0061 "Output ROOT file with histograms");
0062 ao("hist-bins", value<unsigned int>()->default_value(61),
0063 "Number of bins for the residual/pull histograms");
0064 ao("pull-range", value<float>()->default_value(5.),
0065 "Number of sigmas for the pull range.");
0066 ao("eta-bins", value<unsigned int>()->default_value(10),
0067 "Number of bins in eta.");
0068 ao("eta-range",
0069 value<Interval>()->value_name("MIN:MAX")->default_value({-3.0, 3.0}),
0070 "Range for the eta bins.");
0071 ao("phi-bins", value<unsigned int>()->default_value(10),
0072 "Number of bins in phi.");
0073 ao("phi-range",
0074 value<Interval>()->value_name("MIN:MAX")->default_value(
0075 {-std::numbers::pi, std::numbers::pi}),
0076 "Range for the phi bins.");
0077 ao("pt-borders", value<VariableReals>()->required(),
0078 "Transverse momentum borders.");
0079 ao("config-output", value<std::string>()->default_value(""),
0080 "(Optional) output histogram configuration json file.");
0081 ao("config-input", value<std::string>()->default_value(""),
0082 "(Optional) input histogram configuration json file.");
0083
0084 ao("all", bool_switch(),
0085 "Process all residual/pull and auxiliary parameters");
0086
0087 std::vector<std::string> resPullPars = {"d0", "z0", "phi0", "theta0",
0088 "qop", "time", "pt"};
0089 for (const auto &rp : resPullPars) {
0090 ao(rp.c_str(), bool_switch(),
0091 (std::string("Residual/pulls for ") + rp).c_str());
0092 }
0093
0094 std::vector<std::string> auxPars = {"chi2ndf", "measurements", "holes",
0095 "outliers", "shared"};
0096 for (const auto &aux : auxPars) {
0097 ao(aux.c_str(), bool_switch(),
0098 (std::string("Auxiliary information for ") + aux).c_str());
0099 }
0100
0101
0102 variables_map vm;
0103 store(command_line_parser(argc, argv).options(description).run(), vm);
0104
0105 if (vm.contains("help")) {
0106 std::cout << description;
0107 return 1;
0108 }
0109
0110 notify(vm);
0111
0112
0113 unsigned long nEntries = vm["events"].as<unsigned long>();
0114 unsigned long nPeakEntries = vm["peak-events"].as<unsigned long>();
0115
0116
0117 auto iFiles = vm["input"].as<std::vector<std::string>>();
0118 auto iTree = vm["tree"].as<std::string>();
0119 auto oFile = vm["output"].as<std::string>();
0120
0121
0122 auto configInput = vm["config-input"].as<std::string>();
0123 auto configOutput = vm["config-output"].as<std::string>();
0124
0125 float pullRange = vm["pull-range"].as<float>();
0126 unsigned int nHistBins = vm["hist-bins"].as<unsigned int>();
0127 unsigned int nEtaBins = vm["eta-bins"].as<unsigned int>();
0128
0129 auto etaInterval = vm["eta-range"].as<Interval>();
0130 std::array<float, 2> etaRange = {
0131 static_cast<float>(etaInterval.lower.value_or(-3)),
0132 static_cast<float>(etaInterval.upper.value_or(3.))};
0133
0134 unsigned int nPhiBins = vm["phi-bins"].as<unsigned int>();
0135 auto phiInterval = vm["phi-range"].as<Interval>();
0136 std::array<float, 2> phiRange = {
0137 static_cast<float>(phiInterval.lower.value_or(-std::numbers::pi)),
0138 static_cast<float>(phiInterval.upper.value_or(std::numbers::pi))};
0139
0140 auto ptBorders = vm["pt-borders"].as<VariableReals>().values;
0141 if (ptBorders.empty()) {
0142 ptBorders = {0., std::numeric_limits<double>::infinity()};
0143 }
0144
0145 TApplication *tApp =
0146 vm["silent"].as<bool>()
0147 ? nullptr
0148 : new TApplication("TrackSummary", nullptr, nullptr);
0149
0150 std::bitset<7> residualPulls;
0151 std::bitset<5> auxiliaries;
0152 if (vm["all"].as<bool>()) {
0153 residualPulls = std::bitset<7>{"1111111"};
0154 auxiliaries = std::bitset<5>{"11111"};
0155 } else {
0156
0157 for (unsigned int iresp = 0; iresp < resPullPars.size(); ++iresp) {
0158 if (vm[resPullPars[iresp]].as<bool>()) {
0159 residualPulls.set(iresp);
0160 }
0161 }
0162
0163 for (unsigned int iaux = 0; iaux < auxPars.size(); ++iaux) {
0164 if (vm[auxPars[iaux]].as<bool>()) {
0165 auxiliaries.set(iaux);
0166 }
0167 }
0168 }
0169
0170
0171 switch (trackSummaryAnalysis(
0172 iFiles, iTree, oFile, configInput, configOutput, nEntries, nPeakEntries,
0173 pullRange, nHistBins, nPhiBins, phiRange, nEtaBins, etaRange, ptBorders,
0174 residualPulls, auxiliaries)) {
0175 case -1: {
0176 std::cout << "*** Input file could not be opened, check name/path."
0177 << std::endl;
0178 } break;
0179 case -2: {
0180 std::cout << "*** Input tree could not be found, check name."
0181 << std::endl;
0182 } break;
0183 default: {
0184 std::cout << "*** Successful run." << std::endl;
0185 };
0186 }
0187
0188 if (tApp != nullptr) {
0189 tApp->Run();
0190 }
0191
0192 } catch (std::exception &e) {
0193 std::cerr << e.what() << "\n";
0194 }
0195
0196 std::cout << "*** Done." << std::endl;
0197 return 1;
0198 }